aboutsummaryrefslogtreecommitdiff
path: root/plugins/video_image/video_image.module
blob: 9664523599304cfbe2b91d2768252ef26da77996 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
// $Id$

/**
 * @file
 * Enable image support for video module.
 *
 * @author Fabio Varesano <fvaresano at yahoo dot it>
 */


/**
 * Implementation of hook_help().
 */
function video_image_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Enable thumbnails support for video module.');
  }
}


/**
 * Implementation of hook_form_alter()
 */
function video_image_form_alter($form_id, &$form) {

  if($form_id == 'video_node_form' && isset($form['video'])) {

    $form['image'] = array('#type' => 'fieldset', '#title' => t('Image thumbnails'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => -17, '#description' => t('Use this form to upload an image.'));


      if (function_exists('_image_check_settings')) {
        _image_check_settings();
        $node = $form['#node'];
        $form['#attributes'] = array("enctype" => "multipart/form-data");

        if ($node->iid) {
          $image = node_load($node->iid);
          $form['image']['image_thumbnail'] = array('#type' => 'item', '#title' => t('Thumbnail'), '#value' => image_display($image, 'thumbnail'));
        }
        $value = ($node->new_image) ? '#value' : '#default_value';
        $form['image']['iid'] = array('#type' => 'hidden' , $value => $node->iid);
        $form['image']['image'] = array('#type' => 'file', '#title' => t('Image'));
        $form['image']['image_title'] = array('#type' => 'textfield', '#title' => t('Image title'), '#default_value' => '');
      }
  }

}


/**
 * Implementation of hook_nodeapi()
 */
function video_image_nodeapi(&$node, $op, $teaser) {
  if($node->type == 'video') {
    switch ($op) {
      case 'load': 
        $output['iid'] = $node->serial_data['iid'];
        return $output;
      case 'submit':
        $node->serial_data['iid'] = $node->iid;
      break;
      case 'prepare':
        // check that image.module is actived
        if ( !module_exist("image")) {
          db_query("UPDATE {system} SET status = 0 WHERE name ='video_image' AND type = 'module' LIMIT 1");
          drupal_set_message(t('video_image module requires the %module module.<br />To prevent system errors video_image module has been disabled.<br />Please install the image module and then reactivate the video_image module.', array('%module' => l('image', 'http://drupal.org/project/image'))), 'error');
          break;
        }
        $image->title = $_POST['edit']['image_title'];
        $image->uid = $node->uid;
        $image->name = $node->name;
        $image->created = $node->created;
        $image->type = 'image';
        image_prepare($image, 'image');
        if ($image->images) {
          node_validate($image);
          if (!form_get_errors()) {
            $image = node_submit($image);
            node_save($image);
            $node->iid = $image->nid;
            $node->new_image = TRUE;
          }
        }
        elseif ($_POST['edit']['iid']) {
          $node->iid = $_POST['edit']['iid'];
        }
      break;

      case 'view':
        if($teaser) {
          if ($node->serial_data['image_teaser'] || $node->serial_data['iid']) { //If we are dealing with a teaser.
            $node->teaser = theme('video_image_teaser', $node);
          }
        }
        else {
          if ($node->serial_data['image_view'] || $node->serial_data['iid']) {
            $node->body = theme('video_image_body', $node) . $node->body;
          }
        }
        break;
    }
  }
}


/**
 * Render the output for the node teaser.
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_image_teaser($node) {
  if($node->serial_data['iid']) {
    $image = node_load($node->serial_data['iid']);
    $image = image_display($image, 'thumbnail', array('class' => 'video_image_teaser'));
  }
  else { // only for backward compatibility
    $image = theme('image', $node->serial_data['image_teaser'], $node->title, $node->title, array('class' => 'video_image_teaser'), FALSE);
  }
  $output .= l($image, "node/$node->nid", array(), NULL, NULL, FALSE, TRUE); //Create a link with an image in it.
  $output .= $node->teaser . '<br class="video_image_clear" />';
  return $output;
}


/**
 * Generates the image HTML displayed in the Node body.
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_image_body($node) {
  if($node->serial_data['iid']) {
    $image = node_load($node->serial_data['iid']);
    $image = image_display($image, 'thumbnail');
  }
  else { // only for backward compatibility
    $image = theme('image', $node->serial_data['image_view'], $node->title, $node->title, array('class' => 'video_image_view'), FALSE); //Create image HTML
  }
  $output = l($image, "node/$node->nid/play", array('title' => t('play') . ' ' . $node->title), NULL, NULL, FALSE, TRUE); //Create link HTML with image in it.

  return $output;
}

?>