aboutsummaryrefslogtreecommitdiff
path: root/plugins/video_customfields/video_customfields.module
diff options
context:
space:
mode:
authorFabio Varesano <fax8@13637.no-reply.drupal.org>2006-06-18 14:41:32 +0000
committerFabio Varesano <fax8@13637.no-reply.drupal.org>2006-06-18 14:41:32 +0000
commitbff6fafe62a4201c99bdba20144313276d654bca (patch)
tree3f58c4adad06446274c6e842f9f9fb6155ba4b34 /plugins/video_customfields/video_customfields.module
parent2540b23c26f79ed8b223d6ec8b00ca4bfc76e7ef (diff)
downloadvideo-bff6fafe62a4201c99bdba20144313276d654bca.tar.gz
video-bff6fafe62a4201c99bdba20144313276d654bca.tar.bz2
List of changes:
Pluginization: Video.module file was too big and complex. I isolated each different feature which was not excencial and removed from the video.module file. Those features are now added by helper modules called plugins under the directory "plugins". The download has been separed from multidownload. There is now a separated plugin called video_multidownload which add multidownload feature. There are also some hooks being defined. See file hooks.php for details. XHTML Compliace: I worked hard to remove unvalid code from video module. Now the code generated by the module validates on W3C validator. This will probæbly generate some problems with uncommon browsers we will try to solve them as soon as reported. Thanks a lot to Karl Rudd who point me to the right direction towards compliace. Thumbnailing: There is plugin called video_image.module which add thumbnails support for the video module. Thumbnails are uploaded throught the video creation form and a image node is created with it. Video file Uploads: There is a plugin called video_upload.module which add a file upload field to the node creation form. The uploaded file is automatically set as path of the video. Then usable for plays/downloads. NOTE ON BUGS: I tryed to test new features the most as possible but I can't guarantee that all this code is bugfree. Video module is becaming too big to be tested by only one person (me). Hope you guys will be able to help with debugging. Fabio
Diffstat (limited to 'plugins/video_customfields/video_customfields.module')
-rw-r--r--plugins/video_customfields/video_customfields.module225
1 files changed, 225 insertions, 0 deletions
diff --git a/plugins/video_customfields/video_customfields.module b/plugins/video_customfields/video_customfields.module
new file mode 100644
index 0000000..f6b2e50
--- /dev/null
+++ b/plugins/video_customfields/video_customfields.module
@@ -0,0 +1,225 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Enable addition of custom fileds on video nodes created by video module.
+ *
+ * @author Fabio Varesano <fvaresano at yahoo dot it>
+ */
+
+
+/**
+ * Implementation of hook_help().
+ */
+function video_customfields_help($section) {
+ switch ($section) {
+ case 'admin/modules#description':
+ return t('Enable addition of custom fileds on video nodes created by video module.');
+ }
+}
+
+
+/**
+ * Implementation of hook_perm().
+ */
+function video_customfields_perm() {
+ return array('insert custom fields');
+}
+
+
+/**
+ * Settings Hook
+ *
+ * @return
+ * string of form content or error message
+ */
+function video_customfields_settings() {
+ //Must have "administer site configuration" and "administer video" privilages.
+ if (!user_access('administer video')) {
+ drupal_access_denied();
+ }
+
+ $form['customfields'] = array(
+ '#type' => 'fieldset',
+ '#weight' => -1,
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#title' => t('Custom display fields'),
+ '#description' => t('Creates custom fields. Fields only show up if you give them a name.')
+ );
+ $form['customfields']['video_customfieldtitle'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field group title'),
+ '#default_value' => variable_get('video_customfieldtitle', ''),
+ '#description' => t('Title of the group of all custom fields.'));
+ $form['customfields']['video_customfield1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 1 title'),
+ '#default_value' => variable_get('video_customfield1', ''));
+ $form['customfields']['video_customfield2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 2 title'),
+ '#default_value' => variable_get('video_customfield2', ''));
+ $form['customfields']['video_customfield3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 3 title'),
+ '#default_value' => variable_get('video_customfield3', ''));
+ $form['customfields']['video_customfield4'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 4 title'),
+ '#default_value' => variable_get('video_customfield4', ''));
+ $form['customfields']['video_customfield5'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 5 title'),
+ '#default_value' => variable_get('video_customfield5', ''));
+ $form['customfields']['video_customfield6'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Custom field 6 title'),
+ '#default_value' => variable_get('video_customfield6', ''));
+
+
+ $options = array(1 => 'Yes', 0 => 'No');
+
+ $form['customfields']['video_customgroupcollapsed'] = array(
+ '#type' => 'radios',
+ '#title' => t('Start group initially collapsed'),
+ '#options' => $options,
+ '#default_value' => variable_get('video_customgroupcollapsed', 1),
+ '#description' => t('Should the custom fields group be initially collapsed when creating and editing video nodes?')
+ );
+ return $form;
+}
+
+
+
+/**
+ * Implementation of hook_form_alter()
+ * We use this to add some custom fields to the video creation form.
+ * Fields will be displayed only if field title is set on settings page.
+ */
+function video_customfileds_form_alter($form_id, &$form) {
+
+ if($form_id == 'video_node_form' && isset($form['video']) && user_access('insert custom fields')) {
+
+ $title1 = variable_get('video_customfield1', '');
+ $title2 = variable_get('video_customfield2', '');
+ $title3 = variable_get('video_customfield3', '');
+ $title4 = variable_get('video_customfield4', '');
+ $title5 = variable_get('video_customfield5', '');
+ $title6 = variable_get('video_customfield6', '');
+ //Only display the custom fields group if atleast one field has a title.
+ if ($title1 . $title2 . $title3 . $title4 . $title5 . $title6 != '') {
+ $form['customfields'] = array('#type' => 'fieldset', '#title' => variable_get('video_customfieldtitle', 'Custom Fields'), '#collapsible' => TRUE, '#collapsed' => variable_get('video_customgroupcollapsed', FALSE), '#weight' => -17);
+ //If the custom field title is not blank, then display it.
+ if ($title1 != '') {
+ $form['customfields']['custom_field_1'] = array(
+ '#type' => 'textfield', '#title' => $title1, '#maxlength' => 250, '#default_value' => $node->custom_field_1);
+ }
+ if ($title2 != '') {
+ $form['customfields']['custom_field_2'] = array(
+ '#type' => 'textfield', '#title' => $title2, '#maxlength' => 250, '#default_value' => $node->custom_field_2);
+ }
+ if ($title3 != '') {
+ $form['customfields']['custom_field_3'] = array(
+ '#type' => 'textfield', '#title' => $title3, '#maxlength' => 250, '#default_value' => $node->custom_field_3);
+ }
+ if ($title4 != '') {
+ $form['customfields']['custom_field_4'] = array(
+ '#type' => 'textfield', '#title' => $title4, '#maxlength' => 250, '#default_value' => $node->custom_field_4);
+ }
+ if ($title5 != '') {
+ $form['customfields']['custom_field_5'] = array(
+ '#type' => 'textarea', '#title' => $title5, '#rows' => 4, '#default_value' => $node->custom_field_5);
+ }
+ if ($title6 != '') {
+ $form['customfields']['custom_field_6'] = array(
+ '#type' => 'textarea', '#title' => $title6, '#rows' => 4, '#default_value' => $node->custom_field_6);
+ }
+ }
+ }
+}
+
+
+/**
+ * Implementation of hook_nodeapi()
+ */
+function video_customfields_nodeapi(&$node, $op, $teaser) {
+ if($node->type == 'video') {
+ switch ($op) {
+ case 'view':
+ //If the main node view is being displayed then add the extra video information.
+ if ($teaser == FALSE) {
+
+ if (($node->custom_field_1 . $node->custom_field_2 . $node->custom_field_3 . $node->custom_field_4 . $node->custom_field_5 . $node->custom_field_6) != '') { //Make sure there is data to display.
+ //Add the HTML formatted output of the custom fields to the bottom.
+ $node->body .= theme('video_customfields', $node);
+ }
+ }
+ break;
+ }
+ }
+}
+
+
+/**
+ * Display custom fields on the view page.
+ *
+ * @param $node
+ * object with node information
+ *
+ * @return
+ * string of content to display
+ */
+function theme_video_customfields($node) {
+ //Adds the custom fields.
+ $group_title = variable_get('video_customfieldtitle', ''); //Title of the custom fields.
+ $title1 = variable_get('video_customfield1', '');
+ $title2 = variable_get('video_customfield2', '');
+ $title3 = variable_get('video_customfield3', '');
+ $title4 = variable_get('video_customfield4', '');
+ $title5 = variable_get('video_customfield5', '');
+ $title6 = variable_get('video_customfield6', '');
+ //Run the fields through the input filter set for the node, then remove paragraphs.
+ //Removes the <p> and </p> tags from the filter pass return. This allows each field to be on one line.
+ //A better system might be to remove only the first and last <p></P> tags.
+ $field1 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_1, $node->format, FALSE));
+ $field2 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_2, $node->format, FALSE));
+ $field3 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_3, $node->format, FALSE));
+ $field4 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_4, $node->format, FALSE));
+ $field5 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_5, $node->format, FALSE));
+ $field6 = str_replace(array('<p>', '</p>'), '', check_markup($node->custom_field_6, $node->format, FALSE));
+
+ $output = '';
+ //Make sure all the titles are not blank, if not then display them.
+ if (($title1 . $title2 . $title3 . $title4 . $title5 . $title6) != '') {
+ $output = '<div class="videofields">'; //Enclose all output in "videofields" div class.
+ if ($group_title != '') {
+ $output .= '<div class="title"><h2>' . $group_title . '</h2></div>' . "\n";
+ }
+ if ($title1 != '' and $node->custom_field_1 != '') {
+ $fields[] = array('title' => $title1, 'body' => $field1);
+ }
+ if ($title2 != '' and $node->custom_field_2 != '') {
+ $fields[] = array('title' => $title2, 'body' => $field2);
+ }
+ if ($title3 != '' and $node->custom_field_3 != '') {
+ $fields[] = array('title' => $title3, 'body' => $field3);
+ }
+ if ($title4 != '' and $node->custom_field_4 != '') {
+ $fields[] = array('title' => $title4, 'body' => $field4);
+ }
+ if ($title5 != '' and $node->custom_field_5 != '') {
+ $fields[] = array('title' => $title5, 'body' => $field5);
+ }
+ if ($title6 != '' and $node->custom_field_6 != '') {
+ $fields[] = array('title' => $title6, 'body' => $field6);
+ }
+ $output .= theme('video_fields', $fields); //Generate all the fields HTML.
+
+ $output .= '</div><br />'; //Close the "videofields" class div.
+ }
+ return $output;
+}
+
+