aboutsummaryrefslogtreecommitdiff
path: root/includes/filesystem.inc
blob: 3041ee58523aed9ff63df7f3d6632f3b7d7f1fbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

//$Id$
/*
 * @file
 * Class file used to store video in the filesyetm as CDN or local.
 *
 */

class video_filesystem {

  private $filesystem;

  public function __construct($filesystem = null) {
    //get our configured transcoder.
    if (!isset($filesystem))
      $filesystem = variable_get('vid_filesystem', 'drupal');
    if (!module_load_include('inc', 'video', '/filesystem/' . $filesystem)) {
      $modules = module_list();
      foreach ($modules as $module) {
        $mobule_files = array();
        $module_path = drupal_get_path('module', $module) . '/filesystem';
        $mobule_files = file_scan_directory($module_path, '^.*\.inc$');
        if (is_array($mobule_files)) {
          foreach ($mobule_files as $file) {
            if ($file->name == $filesystem)
              require_once $file->filename;
          }
        }
      }
    }
    if (class_exists($filesystem)) {
      $this->filesystem = new $filesystem;
    } else {
      drupal_set_message(t('The filesystem is not configured properly.'), 'error');
    }
  }

  public function save_file($video) {
    return $this->filesystem->save_file($video);
  }

  public function prepare_file($video) {
    return $this->filesystem->prepare_file($video);
  }

  public function load_file(&$video) {
    return $this->filesystem->load_file($video);
  }

  public function admin_settings() {
    $form = array();
    $options = $this->_filesystem();
    $form['vid_filesystem'] = array(
      '#type' => 'radios',
      '#title' => t('Video Filesystem'),
      '#default_value' => variable_get('vid_filesystem', 'drupal'),
      '#options' => $options['radios'],
      '#description' => t('!list', array('!list' => theme('item_list', $options['help']))),
      '#prefix' => '<div id="filesystem-radios">',
      '#suffix' => '</div>',
    );
    $form = $form + $options['admin_settings'];
    return $form;
  }

  private function _filesystem() {
    $files = array();
    // Lets find our transcoder classes and build our radio options
    // We do this by scanning our transcoders folder
    $form = array('radios' => array(), 'help' => array(), 'admin_settings' => array());
    $path = drupal_get_path('module', 'video') . '/filesystem';
    $files = file_scan_directory($path, '^.*\.inc$');
    // check inside sub modules
    $modules = module_list();
    foreach ($modules as $module) {
      $mobule_files = array();
      $module_path = drupal_get_path('module', $module) . '/filesystem';
      $mobule_files = file_scan_directory($module_path, '^.*\.inc$');
      $files = array_merge($files, $mobule_files);
    }

    foreach ($files as $file) {
      if (!module_load_include('inc', 'video', '/filesystem/' . $file->name))
        require_once $file->filename;
      $focus = new $file->name;
      $form['radios'][$focus->get_value()] = $focus->get_name();
      $form['help'][] = $focus->get_help();
      // creating div for each option
      $form['video_' . $focus->get_value() . '_start'] = array(
        'video_' . $focus->get_value() . '_start' => array(
          '#type' => 'markup',
          '#value' => '<div id="' . $focus->get_value() . '">',
        ),
      );
      $form['video_' . $focus->get_value() . '_end'] = array(
        'video_' . $focus->get_value() . '_end' => array(
          '#type' => 'markup',
          '#value' => '</div>',
        ),
      );

      $form['admin_settings'] = $form['admin_settings'] + $form['video_' . $focus->get_value() . '_start'] + $focus->admin_settings() + $form['video_' . $focus->get_value() . '_end'];
    }
    return $form;
  }

  public function admin_settings_validate(&$form, &$form_state) {
    return $this->filesystem->admin_settings_validate($form, $form_state);
  }

}

interface filesystem_interface {

  public function save_file($video);

  public function prepare_file($video);

  public function load_file($video);

  public function get_name();

  public function get_help();

  public function admin_settings();

  public function admin_settings_validate($form, &$form_state);
}