Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add existing module Code

  • Loading branch information
Chris Wiegman
Chris Wiegman committed Sep 7, 2012
1 parent 5568c18 commit 4c77b0474aa9ac02242b5ec4ec79640286c4e773
Showing with 198 additions and 0 deletions.
  1. +4 −0 youtuberotate.info
  2. +46 −0 youtuberotate.install
  3. +148 −0 youtuberotate.module
@@ -0,0 +1,4 @@
; $Id$
name = "YouTube Movie Rotator"
description = "Creates a block displaying a single random YouTube video from a user-provided list."
core = 6.x
@@ -0,0 +1,46 @@
<?php
// $Id$

/**
* @file
* Implement CCK's install/uninstall hooks.
*/

/**
* Implementation of hook_install().
*/
function youtuberotate_install() {
variable_set('youtuberotate_height', "238");
variable_set('youtuberotate_width', "296");
drupal_load('module', 'content');
content_notify('install', 'youtuberotate');
}

/**
* Implementation of hook_uninstall().
*/
function youtuberotate_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE 'youtuberotate_%'");
drupal_load('module', 'content');
content_notify('uninstall', 'youtuberotate');
}

/**
* Implementation of hook_enable().
*
* Notify content module when this module is enabled.
*/
function youtuberotate_enable() {
drupal_load('module', 'content');
content_notify('enable', 'youtuberotate');
}

/**
* Implementation of hook_disable().
*
* Notify content module when this module is disabled.
*/
function youtuberotate_disable() {
drupal_load('module', 'content');
content_notify('disable', 'youtuberotate');
}
@@ -0,0 +1,148 @@
<?php
// $Id$

/**
* @file
* Creates block selecting a random YouTube video from a given list
*/

/**
* Valid permissions for this module
* @return array An array of valid permissions for the youtuberotate module
*/
function youtuberotate_perm() {
return array('access youtube rotator content', 'administer youtube rotator');
}

/**
*Create the admin form
*/
function youtuberotate_admin() {
$form = array();

$form['settings']['youtuberotate_account'] = array(
'#type' => 'textfield',
'#title' => t('YouTube UserName'),
'#default_value' => variable_get('youtuberotate_account'),
'#size' => 20,
'#description' => t("Enter the YouTube username for a link back to the YouTube page. This is used only for the url and will not be displayed to the user."),
'#required' => FALSE,
);

$form['settings']['youtuberotate_displayname'] = array(
'#type' => 'textfield',
'#title' => t('YouTube Display Name'),
'#default_value' => variable_get('youtuberotate_displayname'),
'#size' => 20,
'#description' => t("Enter the name of the YouTube account you would like it displayed to the user."),
'#required' => FALSE,
);

$form['settings']['youtuberotate_height'] = array(
'#type' => 'textfield',
'#title' => t('Video Height'),
'#default_value' => variable_get('youtuberotate_height'),
'#size' => 4,
'#description' => t("Enter the height of the video in pixels."),
'#required' => TRUE,
);

$form['settings']['youtuberotate_width'] = array(
'#type' => 'textfield',
'#title' => t('Video Width'),
'#default_value' => variable_get('youtuberotate_width'),
'#size' => 4,
'#description' => t("Enter the width of the video in pixels."),
'#required' => TRUE,
);

$form['youtuberotate_movieids'] = array(
'#type' => 'textarea',
'#title' => t('List of YouTube Movie URLs'),
'#default_value' => variable_get('youtuberotate_movieids'),
'#cols' => 60,
'#rows' => 10,
'#resizable' => TRUE,
'#description' => t("Enter the list of YouTube movie URLs (1 per line)."),
'#required' => TRUE,
);

return system_settings_form($form);
}

/**
*Create the menu item for the menu page
*/
function youtuberotate_menu() {

$items = array();

$items['admin/settings/youtuberotate'] = array(
'title' => 'YouTube Rotator Settings',
'description' => 'Administer YouTube Rotator Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('youtuberotate_admin'),
'access arguments' => array('administer youtube rotator'),
'type' => MENU_NORMAL_ITEM,
);

return $items;
}

/**
*Validate user input
*/
function youtuberotate_admin_validate($form, &$form_state) {
$movieStr = explode("\n",$form_state['values']['youtuberotate_movieids']);
$ct = 1;
foreach ($movieStr as &$value) {
$value = substr($value,0,strlen($value)-1);
if (!valid_url($value,TRUE) || !strstr($value,'youtube.com')) {
form_set_error('youtuberotate_movieids', t('The Movie <em>' . $value . '</em> on line ' . $ct . ' does not appear to be a valid YouTube movie.'));
}
$ct++;
}
}

/**
*Create a block for displaying the videos
*/
function youtuberotate_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('YouTube Rotator');
return $blocks;
break;
case 'view':
$blocks['subject'] = t('YouTube Video Rotator');
$blocks['content'] = youtuberotate_content();
return $blocks;
break;
}
}

/**
*Display the video in the block
*/
function youtuberotate_content() {

$movieStr = explode("\n",variable_get('youtuberotate_movieids',0));
$chosen = array_rand($movieStr,1);
$movieUrl = $movieStr[$chosen];
if (strstr($movieUrl, "watch")) {
$eSign = strpos($movieUrl,"=") + 1;
$movieUrl = substr($movieUrl,$eSign,strlen($movieUrl));
} else {
$eSign = strrpos($movieUrl,"/") + 1;
$movieUrl = substr($movieUrl,$eSign,strlen($movieUrl));
}

if (strlen(variable_get('youtuberotate_account',0)) > 1) {
$ytMoreLink = '<a href="http://www.youtube.com/thesiucaviation" target="_blank">View all ' . variable_get('youtuberotate_displayname',"our") . ' videos</a>';
}

return '<object data="http://www.youtube.com/v/' . $movieUrl . '?rel=0" style="width: ' . variable_get('youtuberotate_width',0) . 'px; height: ' . variable_get('youtuberotate_height',0) . 'px;" type="application/x-shockwave-flash"><param name="movie" value="http://www.youtube.com/v/' . $movieUrl . '?rel=0" />
<span>It appears you do not have the <a href="http://www.adobe.com/products/flashplayer/" title="Flash Plugin" rel="external">Flash</a> plugin installed. Flash is required to view this SIUC Aviation video.</span> </object>' . $ytMoreLink;


}

0 comments on commit 4c77b04

Please sign in to comment.
You can’t perform that action at this time.