| 1 |
<?php
|
| 2 |
// $Id: scrolltext.module,v 1.x-dev 2008/04/19 15:45:36 thenicespider Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* This module used for scrolling text from node title
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
|
| 13 |
function scrolltext_help($section) {
|
| 14 |
switch ($section) {
|
| 15 |
case 'admin/help#scrolltext':
|
| 16 |
case 'admin/modules#description':
|
| 17 |
return "This module used for scrolling text from node title.";
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_perm
|
| 23 |
*/
|
| 24 |
function scrolltext_perm() {
|
| 25 |
return array('access scrolltext','administer scrolltext');
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Menu callback. Prints a listing of active nodes on the site.
|
| 30 |
*/
|
| 31 |
function scrolltext_menu() {
|
| 32 |
$items = array();
|
| 33 |
|
| 34 |
$items['admin/settings/scrolltext'] = array(
|
| 35 |
'title' => t('ScrollText'),
|
| 36 |
'page callback' => 'drupal_get_form',
|
| 37 |
'page arguments' => array('scrolltext_settings_form'),
|
| 38 |
'access arguments' => array('administer scrolltext'),
|
| 39 |
'type' => MENU_NORMAL_ITEM,
|
| 40 |
'description' => t("ScrollText settings")
|
| 41 |
);
|
| 42 |
|
| 43 |
return $items;
|
| 44 |
}
|
| 45 |
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Implementation of hook_theme()
|
| 49 |
*/
|
| 50 |
function scrolltext_theme() {
|
| 51 |
return array(
|
| 52 |
'scrolltext_node' => array(
|
| 53 |
'arguments' => array('form' => NULL),
|
| 54 |
),
|
| 55 |
);
|
| 56 |
}
|
| 57 |
|
| 58 |
|
| 59 |
/**
|
| 60 |
*/
|
| 61 |
function scrolltext_settings_form() {
|
| 62 |
$form['scrolltext_general'] = array(
|
| 63 |
'#type' => 'fieldset',
|
| 64 |
'#title' => t('General settings'),
|
| 65 |
'#collapsible' => TRUE,
|
| 66 |
'#collapsed' => FALSE,
|
| 67 |
'#description' => t('Remember to enable the ScrollText on Drupal !blocks . CSS id is "scrolltext" to theming ScrollText.', array('!blocks'=>l('blocks', 'admin/build/block')))
|
| 68 |
);
|
| 69 |
$form['scrolltext_general']['scrolltext_direction'] = array(
|
| 70 |
'#type' => 'select',
|
| 71 |
'#title' => t('Scroll Direction'),
|
| 72 |
'#default_value' => variable_get('scrolltext_direction', 'Left'),
|
| 73 |
'#options' => array('Left'=>'Left','Right'=>'Right','Up'=>'Up','Down'=>'Down')
|
| 74 |
);
|
| 75 |
$form['scrolltext_general']['scrolltext_behavior'] = array(
|
| 76 |
'#type' => 'select',
|
| 77 |
'#title' => t('Scroll Type'),
|
| 78 |
'#default_value' => variable_get('scrolltext_behavior', 'Scroll'),
|
| 79 |
'#options' => array('Scroll'=>'Scroll','Slide'=>'Slide','Alternate'=>'Bouncing'),
|
| 80 |
'#description' => t('Bouncing will not run if scrol text wider than scroll width.')
|
| 81 |
);
|
| 82 |
$form['scrolltext_general']['scrolltext_speed'] = array(
|
| 83 |
'#type' => 'textfield',
|
| 84 |
'#title' => t('Scroll Speed'),
|
| 85 |
'#default_value' => variable_get('scrolltext_speed', '10')
|
| 86 |
);
|
| 87 |
$form['scrolltext_general']['scrolltext_delay'] = array(
|
| 88 |
'#type' => 'textfield',
|
| 89 |
'#title' => t('Scroll Delay (milisecond)'),
|
| 90 |
'#default_value' => variable_get('scrolltext_delay', '100')
|
| 91 |
);
|
| 92 |
|
| 93 |
$form['scrolltext_general']['scrolltext_width'] = array(
|
| 94 |
'#type' => 'textfield',
|
| 95 |
'#title' => t('Scroll Width'),
|
| 96 |
'#default_value' => variable_get('scrolltext_width', '100%')
|
| 97 |
);
|
| 98 |
|
| 99 |
$form['scrolltext_general']['scrolltext_height'] = array(
|
| 100 |
'#type' => 'textfield',
|
| 101 |
'#title' => t('Scroll Height'),
|
| 102 |
'#default_value' => variable_get('scrolltext_height', '0'),
|
| 103 |
'#description' => t('HEIGHT depends on scroll text length, try use 0 if the ScrollText DIRECTION does not work!')
|
| 104 |
);
|
| 105 |
|
| 106 |
$form['scrolltext_general']['scrolltext_format'] = array(
|
| 107 |
'#type' => 'textfield',
|
| 108 |
'#title' => t('Scroll Format'),
|
| 109 |
'#default_value' => variable_get('scrolltext_format', ''),
|
| 110 |
'#description' => t('Format of the text including size and color, style information')
|
| 111 |
);
|
| 112 |
|
| 113 |
$form['scrolltext_source'] = array(
|
| 114 |
'#type' => 'fieldset',
|
| 115 |
'#title' => t('Source settings'),
|
| 116 |
'#collapsible' => TRUE,
|
| 117 |
'#collapsed' => FALSE
|
| 118 |
);
|
| 119 |
$form['scrolltext_source']['scrolltext_nodetype'] = array(
|
| 120 |
'#type' => 'textfield',
|
| 121 |
'#title' => t('Node Type'),
|
| 122 |
'#default_value' => variable_get('scrolltext_nodetype', "'page','story'"),
|
| 123 |
'#description' => t("<p>Get title from certain node type, i.e: 'page','story'</p>")
|
| 124 |
);
|
| 125 |
|
| 126 |
$form['scrolltext_source']['scrolltext_count'] = array(
|
| 127 |
'#type' => 'textfield',
|
| 128 |
'#title' => t('Title Count'),
|
| 129 |
'#default_value' => variable_get('scrolltext_count', '10'),
|
| 130 |
'#description' => t('<p>How many new title would you like to scrol? NOTE: greater number will cause you website slowly!</p>')
|
| 131 |
);
|
| 132 |
|
| 133 |
return system_settings_form($form);
|
| 134 |
}
|
| 135 |
|
| 136 |
/**
|
| 137 |
* Implementation of hook_block().
|
| 138 |
*
|
| 139 |
*/
|
| 140 |
function scrolltext_block($op = 'list', $delta = 0) {
|
| 141 |
global $user;
|
| 142 |
if ($op == 'list')
|
| 143 |
{
|
| 144 |
$blocks[0]['info'] = 'ScrollText';
|
| 145 |
|
| 146 |
|
| 147 |
return $blocks;
|
| 148 |
}
|
| 149 |
|
| 150 |
if ($op == 'view')
|
| 151 |
{
|
| 152 |
switch($delta) {
|
| 153 |
case 0:
|
| 154 |
$block['subject'] = t('<none>');
|
| 155 |
$block['content'] = '';
|
| 156 |
|
| 157 |
$scrolltext_direction= variable_get('scrolltext_direction', 'Left');
|
| 158 |
$scrolltext_behavior = variable_get('scrolltext_behavior', 'Scroll');
|
| 159 |
$scrolltext_width = variable_get('scrolltext_width', '100%');
|
| 160 |
$scrolltext_height = variable_get('scrolltext_height', '0');
|
| 161 |
$scrolltext_format = variable_get('scrolltext_format', '');
|
| 162 |
$scrolltext_speed = variable_get('scrolltext_speed', '10');
|
| 163 |
$scrolltext_delay = variable_get('scrolltext_delay', '100');
|
| 164 |
|
| 165 |
$scrolltext_nodetype = variable_get('scrolltext_nodetype', "'page','story'");
|
| 166 |
$scrolltext_count = variable_get('scrolltext_count', '10');
|
| 167 |
|
| 168 |
$sql = "SELECT n.title, n.nid FROM {node} n WHERE n.status = 1 and n.type IN ($scrolltext_nodetype) "
|
| 169 |
."ORDER BY n.created DESC LIMIT $scrolltext_count";
|
| 170 |
$results = db_query($sql);
|
| 171 |
|
| 172 |
if ($results)
|
| 173 |
{
|
| 174 |
|
| 175 |
$block['content'] = "<DIV ID='scrolltext'>"
|
| 176 |
."<MARQUEE DIRECTION='$scrolltext_direction' "
|
| 177 |
."BEHAVIOR='$scrolltext_behavior' "
|
| 178 |
."WIDTH='$scrolltext_width' ";
|
| 179 |
if (strcmp ($scrolltext_height, '0') !== 0)
|
| 180 |
{
|
| 181 |
$block['content'] .= "HEIGHT='$scrolltext_height' ";
|
| 182 |
}
|
| 183 |
$block['content'] .= "SCROLLAMOUNT='$scrolltext_speed' "
|
| 184 |
."SCROLLDELAY='$scrolltext_delay' "
|
| 185 |
.">";
|
| 186 |
while ( $data = db_fetch_object($results) )
|
| 187 |
{
|
| 188 |
$block['content'] .= "<font style='$scrolltext_format'>$data->title</font>";
|
| 189 |
$block['content'] .= l(" Read more","node/$data->nid"). str_repeat(' ',5);
|
| 190 |
if ($scrolltext_direction == 'Up' or $scrolltext_direction == 'Down') $block['content'] .= "<br />\n";
|
| 191 |
}
|
| 192 |
|
| 193 |
$block['content'] .= '</MARQUEE></DIV>';
|
| 194 |
}
|
| 195 |
break;
|
| 196 |
}
|
| 197 |
return $block;
|
| 198 |
}
|
| 199 |
}
|