| 1 |
|
<?php |
| 2 |
|
// $Id: content_slider.module,v 1.1.2.4 2008/12/14 19:24:45 ebizondrupalservices Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
|
/** |
| 6 |
|
* @file |
| 7 |
|
* Display content in 'featured content' block using jQuery. |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
/** |
| 11 |
|
* Implementation of hook_help(). |
| 12 |
|
*/ |
| 13 |
|
function content_slider_help($section) { |
| 14 |
|
switch ($section) { |
| 15 |
|
case 'admin/help#content_slider': |
| 16 |
|
$output = "The content_slider module: Display content and image in Slide show mode using jQuery."; |
| 17 |
|
return $output; |
| 18 |
|
|
| 19 |
|
case 'admin/modules#description': |
| 20 |
|
return 'The content_slider module: Display content and image in Slide show mode using jQuery.'; |
| 21 |
|
} |
| 22 |
|
} |
| 23 |
|
|
| 24 |
|
/** |
| 25 |
|
* Implementation of hook_perm |
| 26 |
|
*/ |
| 27 |
|
function content_slider_perm() { |
| 28 |
|
return array('access content_slider', 'administer content_slider'); |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
function content_slider_menu() { |
| 32 |
|
$items = array(); |
| 33 |
|
|
| 34 |
|
$items['admin/settings/content_slider'] = array( |
| 35 |
|
'title' => 'Content Slider', |
| 36 |
|
'description' => t('Setting Content Slider.'), |
| 37 |
|
'page callback' => 'drupal_get_form', |
| 38 |
|
'page arguments' => array('content_slider_admin_settings'), |
| 39 |
|
'access arguments' => array('administer site configuration'), |
| 40 |
|
); |
| 41 |
|
$items[] = array( |
| 42 |
|
'path' => 'content_slider/list/'. arg(2), |
| 43 |
|
'title' => t('Content Slider'), |
| 44 |
|
'page callback' => 'content_slider_page_list', |
| 45 |
|
'page arguments' => array(arg(2)), |
| 46 |
|
'access arguments' => array('access content_slider'), |
| 47 |
|
'type' => MENU_CALLBACK, |
| 48 |
|
); |
| 49 |
|
return $items; |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
function content_slider_admin_settings() { |
| 53 |
|
|
| 54 |
|
// only administrators can access this function |
| 55 |
|
// Generate the form - settings applying to all patterns first |
| 56 |
|
$form['content_slider_settings'] = array( |
| 57 |
|
'#type' => 'fieldset', |
| 58 |
|
'#weight' => -20, |
| 59 |
|
'#title' => t('Basic settings'), |
| 60 |
|
'#collapsible' => TRUE, |
| 61 |
|
'#collapsed' => FALSE, |
| 62 |
|
); |
| 63 |
|
|
| 64 |
|
$form['content_slider_settings']['content_slider_auto'] = array( |
| 65 |
|
'#type' => 'checkbox', |
| 66 |
|
'#title' => t('Auto rotate contents'), |
| 67 |
|
'#default_value' => variable_get('content_slider_auto', 1), |
| 68 |
|
'#description' => t("Display content without mouse click."), |
| 69 |
|
'#maxlength' => '1', '#size' => '1', |
| 70 |
|
); |
| 71 |
|
|
| 72 |
|
$form['content_slider_settings']['content_slider_speed'] = array( |
| 73 |
|
'#type' => 'textfield', |
| 74 |
|
'#title' => t('Glide animation duration (in milliseconds)'), |
| 75 |
|
'#default_value' => variable_get('content_slider_speed', 1000), |
| 76 |
|
); |
| 77 |
|
|
| 78 |
|
$form['content_slider_settings']['content_slider_direction'] = array( |
| 79 |
|
'#type' => 'textfield', |
| 80 |
|
'#title' => t('Set direction of glide'), |
| 81 |
|
'#default_value' => variable_get('content_slider_direction', 'leftright'), |
| 82 |
|
'#description' => 'Available value: "updown", "downup", "leftright", or "rightleft"', |
| 83 |
|
); |
| 84 |
|
|
| 85 |
|
// set direction of glide: "updown", "downup", "leftright", or "rightleft"' |
| 86 |
|
//$output_body .= 'direction: "downup", |
| 87 |
|
|
| 88 |
|
$form['content_slider_source'] = array( |
| 89 |
|
'#type' => 'fieldset', |
| 90 |
|
'#weight' => -20, |
| 91 |
|
'#title' => t('Slider content source (based on Drupal content-type)'), |
| 92 |
|
'#collapsible' => TRUE, |
| 93 |
|
'#collapsed' => FALSE, |
| 94 |
|
); |
| 95 |
|
|
| 96 |
|
$form['content_slider_source']['content_slider_source_1'] = array( |
| 97 |
|
'#type' => 'textfield', |
| 98 |
|
'#title' => t('Content type for Slider 1'), |
| 99 |
|
'#default_value' => variable_get('content_slider_source_1', 'page'), |
| 100 |
|
); |
| 101 |
|
|
| 102 |
|
$form['content_slider_source']['content_slider_source_2'] = array( |
| 103 |
|
'#type' => 'textfield', |
| 104 |
|
'#title' => t('Content type for Slider 2'), |
| 105 |
|
'#default_value' => variable_get('content_slider_source_2', 'story'), |
| 106 |
|
); |
| 107 |
|
|
| 108 |
|
$form['content_slider_source']['content_slider_source_3'] = array( |
| 109 |
|
'#type' => 'textfield', |
| 110 |
|
'#title' => t('Content type for Slider 3'), |
| 111 |
|
'#default_value' => variable_get('content_slider_source_3', 'featured'), |
| 112 |
|
); |
| 113 |
|
|
| 114 |
|
return system_settings_form($form); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
/** |
| 118 |
|
* Implementation of hook_block(). |
| 119 |
|
* |
| 120 |
|
*/ |
| 121 |
|
function content_slider_block($op = 'list', $delta = 0) { |
| 122 |
|
$content_slider_auto = variable_get("content_slider_auto", 1); |
| 123 |
|
$content_slider_speed = variable_get("content_slider_speed", 1000); |
| 124 |
|
$content_slider_direction = variable_get("content_slider_direction", 'leftright'); |
| 125 |
|
|
| 126 |
|
$content_slider_source_1 = variable_get("content_slider_source_1","page"); |
| 127 |
|
$content_slider_source_2 = variable_get("content_slider_source_2","story"); |
| 128 |
|
$content_slider_source_3 = variable_get("content_slider_source_3","featured"); |
| 129 |
|
|
| 130 |
|
global $base_url; |
| 131 |
|
$ajax_base_path = $base_url; |
| 132 |
|
|
| 133 |
|
if ($op == 'list') { |
| 134 |
|
$blocks[0]['info'] = 'Content Slider 1'; |
| 135 |
|
$blocks[1]['info'] = 'Content Slider 2'; |
| 136 |
|
$blocks[2]['info'] = 'Content Slider 3'; |
| 137 |
|
return $blocks; |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
if ($op == 'view') { |
| 141 |
|
|
| 142 |
|
global $base_url; |
| 143 |
|
|
| 144 |
|
drupal_add_css(drupal_get_path('module', 'content_slider') . '/contentslider.css'); |
| 145 |
|
drupal_add_js(drupal_get_path('module', 'content_slider'). '/contentslider.js'); |
| 146 |
|
|
| 147 |
|
$output_body = ""; |
| 148 |
|
//Text |
| 149 |
|
$output_head = ''."\n"; |
| 150 |
|
$output_head .= '/***********************************************'."\n"; |
| 151 |
|
$output_head .= '* Featured Content Slider script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)'."\n"; |
| 152 |
|
$output_head .= '* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts'."\n"; |
| 153 |
|
$output_head .= '* This notice must stay intact for legal use'."\n"; |
| 154 |
|
$output_head .= '***********************************************/'."\n"; |
| 155 |
|
//drupal_add_js($output_head,'inline'); |
| 156 |
|
|
| 157 |
|
$slider_id = $delta + 1; |
| 158 |
|
switch ($delta) { |
| 159 |
|
case 0: |
| 160 |
|
$content_type = $content_slider_source_1; |
| 161 |
|
$block['subject'] = 'Content Slider 1'; |
| 162 |
|
$block['content'] = outbody_of_block($content_type,$delta); |
| 163 |
|
break; |
| 164 |
|
|
| 165 |
|
case 1: |
| 166 |
|
$content_type = $content_slider_source_2; |
| 167 |
|
$block['subject'] = 'Content Slider 2'; |
| 168 |
|
$block['content'] = outbody_of_block($content_type,$delta); |
| 169 |
|
|
| 170 |
|
break; |
| 171 |
|
|
| 172 |
|
case 2: |
| 173 |
|
$content_type = $content_slider_source_3; |
| 174 |
|
$block['subject'] = 'Content Slider 3'; |
| 175 |
|
$block['content'] = outbody_of_block($content_type,$delta); |
| 176 |
|
|
| 177 |
|
break; |
| 178 |
|
} |
| 179 |
|
return $block; |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
function outbody_of_block($content_type,$delta) |
| 183 |
|
{ |
| 184 |
|
$output_body = ''; |
| 185 |
|
$sql = " SELECT n.nid, teaser FROM {node} n INNER JOIN {node_revisions} r ON n.nid=r.nid "." WHERE n.status=1 AND n.type='".$content_type."' ORDER BY n.changed DESC LIMIT 5"; |
| 186 |
|
$results = db_query($sql); |
| 187 |
|
|
| 188 |
|
$output_body .= '<div id="slider'.$delta.'" class="sliderwrapper">'."\n"; |
| 189 |
|
while ($data = db_fetch_object($results)) { |
| 190 |
|
$slider_nid = $data->nid; |
| 191 |
|
$output_body .= '<div class="contentdiv">'."\n"; |
| 192 |
|
$output_body .= "<a href='".$base_url."/node/".$slider_nid."'>". node_view(node_load($data->nid), 1) ."</a>"; |
| 193 |
|
if ($slider_nid == 1) { |
| 194 |
|
$output_body .= '<p></p><a href="javascript:featuredcontentslider.jumpTo(\'slider1\', 3)">'; |
| 195 |
|
} |
| 196 |
|
$output_body .= '</div>'; |
| 197 |
|
} |
| 198 |
|
$output_body .= '</div>'; |
| 199 |
|
$output_body .= '<div id="paginate-slider'.$delta.'" class="pagination">'."\n"; |
| 200 |
|
$output_body .= '</div>'; |
| 201 |
|
|
| 202 |
|
$output_body .= '<script type="text/javascript">'; |
| 203 |
|
|
| 204 |
|
$output_body .= 'featuredcontentslider.init({'."\n"; |
| 205 |
|
$output_body .= 'id: "slider'.$delta.'",//id of main slider DIV'."\n"; |
| 206 |
|
$output_body .= 'contentsource: ["inline", ""], //Valid values: ["inline", ""] or ["ajax", "path_to_file"]'."\n"; |
| 207 |
|
$output_body .= 'toc: "#increment", //Valid values: "#increment", "markup", ["label1", "label2", etc]'."\n"; |
| 208 |
|
$output_body .= 'nextprev: ["Previous", "Next"], //labels for "prev" and "next" links. Set to "" to hide.'."\n"; |
| 209 |
|
$output_body .= 'revealtype: "click", //Behavior of pagination links to reveal the slides: "click" or "mouseover"'."\n"; |
| 210 |
|
$output_body .= 'enablefade: [true, 0.2], //[true/false, fadedegree]'."\n"; |
| 211 |
|
$output_body .= 'autorotate: [true, 3000], //[true/false, pausetime]'."\n"; |
| 212 |
|
$output_body .= 'onChange: function(previndex, curindex){ //event handler fired whenever script changes slide'."\n"; |
| 213 |
|
$output_body .= '//previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)'."\n"; |
| 214 |
|
$output_body .= '//curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)'."\n"; |
| 215 |
|
$output_body .= '}'; |
| 216 |
|
$output_body .= '})'; |
| 217 |
|
|
| 218 |
|
$output_body .= '</script>'; |
| 219 |
|
return $output_body; |
| 220 |
|
|
| 221 |
|
//$output_body .= '</div>'; |
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
function content_slider_page_list($i) { |
| 225 |
|
$content_slider_item = variable_get("content_slider_item", 10); |
| 226 |
|
|
| 227 |
|
$dse_news_total = db_query(" SELECT count(*) AS total FROM {node} n WHERE n.type='slider".$i."' AND n.status=1"); |
| 228 |
|
$row_news = db_fetch_object($dse_news_total); |
| 229 |
|
$news_total = $row_news->total; |
| 230 |
|
$sql_counts = "SELECT $news_total"; |
| 231 |
|
|
| 232 |
|
$sql = " SELECT n.nid, n.title, r.teaser FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid WHERE n.type = 'slider$i' AND n.status=1 ORDER BY n.created DESC"; |
| 233 |
|
$sql = db_rewrite_sql($sql); |
| 234 |
|
|
| 235 |
|
$results = pager_query($sql, $content_slider_item, 0, $sql_counts); |
| 236 |
|
|
| 237 |
|
$output = "<div id='content_slider$i'>"; |
| 238 |
|
|
| 239 |
|
while ($node = db_fetch_object($results)) { |
| 240 |
|
$output .= node_view(node_load($node->nid), 1); |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
$output .= theme('pager', NULL, $content_slider_item, 0); |
| 244 |
|
$output .= '</div>'; |
| 245 |
|
|
| 246 |
|
return $output; |
| 247 |
|
} |
| 248 |
|
|