/[drupal]/contributions/modules/ajax_newsflash/ajax_newsflash.module
ViewVC logotype

Contents of /contributions/modules/ajax_newsflash/ajax_newsflash.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download) (as text)
Sat Aug 30 10:41:33 2008 UTC (14 months, 3 weeks ago) by thenicespider
Branch: MAIN
CVS Tags: DRUPAL-5--1-15
Changes since 1.12: +142 -33 lines
File MIME type: text/x-php
5.x-1.15: New: add setting page
          New: add 'more' link on the block and set how many items per page
          New: show newsflash items on table format, you can set how many columns
1 <?php
2 // $Id: ajax_newsflash.module,v 1.12 2008/08/30 08:07:32 thenicespider Exp $
3
4 /**
5 * @file
6 * The ajax_newsflash module used for displaying Newsflash using AJAX.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function ajax_newsflash_help($section) {
13 switch ($section) {
14 case 'admin/help#ajax_newsflash':
15 $output = "The ajax_newsflash module used for displaying Newsflash using AJAX.";
16 return $output;
17 case 'admin/modules#description':
18 return 'The ajax_newsflash module used for displaying Newsflash using AJAX';
19 }
20 }
21
22 /**
23 * Implementation of hook_perm
24 */
25 function ajax_newsflash_perm() {
26 return array('access ajax_newsflash', 'administer ajax_newsflash');
27 }
28
29 function ajax_newsflash_menu($may_cache) {
30
31 $items = array();
32
33 $items[] = array(
34 'path' => 'admin/settings/ajax_newsflash',
35 'title' => 'Ajax Newsflash',
36 'description' => t('Setting Ajax Newsflash.'),
37 'callback' => 'drupal_get_form',
38 'callback arguments' => array('ajax_newsflash_admin_settings'),
39 'access' => user_access('administer ajax_newsflash'),
40 'type' => MENU_NORMAL_ITEM);
41
42 $items[] = array(
43 'path' => 'ajax_newsflash/list/'.arg(2),
44 'title' => t('Ajax Newsflash'),
45 'callback' => 'ajax_newsflash_page_list',
46 'callback arguments' => array(arg(2)),
47 'access' => user_access('access ajax_newsflash'),
48 'type' => MENU_CALLBACK);
49
50 return $items;
51 }
52
53 function ajax_newsflash_admin_settings() {
54
55 // only administrators can access this function
56
57 // Generate the form - settings applying to all patterns first
58 $form['ajax_newsflash_settings'] = array(
59 '#type' => 'fieldset',
60 '#weight' => -20,
61 '#title' => t('Basic settings'),
62 '#collapsible' => TRUE,
63 '#collapsed' => FALSE
64 );
65
66 $form['ajax_newsflash_settings']['ajax_newsflash_more'] = array(
67 '#type' => 'checkbox',
68 '#title' => t('Show "more" link.'),
69 '#default_value' => variable_get('ajax_newsflash_more', 1),
70 '#description' => t("Display 'more' link below the Newsflash content on the block."),
71 '#maxlength' => '1', '#size' => '1');
72
73 $form['ajax_newsflash_settings']['ajax_newsflash_item'] = array(
74 '#type' => 'textfield',
75 '#title' => t('Number of Newsflash per page'),
76 '#default_value' => variable_get('ajax_newsflash_item', 10),
77 '#description' => t("How many content displayed on the page."),
78 '#maxlength' => '5', '#size' => '5');
79 $form['ajax_newsflash_settings']['ajax_newsflash_column'] = array(
80 '#type' => 'textfield',
81 '#title' => t('Number of columns when displayed on page'),
82 '#default_value' => variable_get('ajax_newsflash_column', 1),
83 '#description' => t("How many column when newsflash displayed on the page. Page only can access if u enable 'Show more link' option."),
84 '#maxlength' => '5', '#size' => '5');
85
86 return system_settings_form($form);
87 }
88
89 /**
90 * Implementation of hook_block().
91 *
92 */
93 function ajax_newsflash_block($op = 'list', $delta = 0) {
94 $ajax_newsflash_more = variable_get("ajax_newsflash_more", 1);
95
96 if ($op == 'list')
97 {
98 $blocks[0]['info'] = 'Ajax Newsflash 1';
99 $blocks[1]['info'] = 'Ajax Newsflash 2';
100 $blocks[2]['info'] = 'Ajax Newsflash 3';
101 return $blocks;
102 }
103
104 if ($op == 'view') {
105 drupal_add_css(drupal_get_path('module', 'ajax_newsflash') . '/ajax_newsflash.css');
106 drupal_add_js(drupal_get_path('module', 'ajax_newsflash'). '/ajaxticker.js', 'module');
107 //Text
108 $output_head =''."\n";
109 $output_head .= '/***********************************************'."\n";
110 $output_head .= '* Ajax Ticker script (txt file source)- (c) Dynamic Drive (www.dynamicdrive.com)'."\n";
111 $output_head .= '* This notice MUST stay intact for legal use'."\n";
112 $output_head .= '* Visit http://www.dynamicdrive.com/ for this script and 100s more.'."\n";
113 $output_head .= '***********************************************/'."\n";
114 drupal_add_js($output_head,'inline');
115
116 global $base_url;
117 $ajax_base_path = $base_url;
118
119 switch($delta) {
120 case 0:
121 $output_body = '';
122 $output_body .= '<script type="text/javascript">';
123 $output_body .= 'var xmlfile= "'.$ajax_base_path.'/'.file_directory_path().'/tickercontent1.txt"' . "\n";
124 $output_body .= 'new ajax_ticker(xmlfile, "ajaxticker1", "someclass", 3500, "fade") ';
125 $output_body .= '</script>';
126
127 if ($ajax_newsflash_more) { $output_body .= '<div class="more-link">'.l(t("more"), "ajax_newsflash/list/1").'</div>'; }
128
129 $block['subject'] = 'Newsflash 1';
130 $block['content'] = $output_body;
131
132 break;
133
134 case 1:
135 $output_body = '';
136 $output_body .= '<script type="text/javascript">';
137 $output_body .= 'var xmlfile= "'.$ajax_base_path.'/'.file_directory_path().'/tickercontent2.txt"' . "\n";
138 $output_body .= 'new ajax_ticker(xmlfile, "ajaxticker2", "someclass", 3500, "fade") ';
139 $output_body .= '</script>';
140 if ($ajax_newsflash_more) { $output_body .= '<div class="more-link">'.l(t("more"), "ajax_newsflash/list/2").'</div>'; }
141
142 $block['subject'] = 'Newsflash 2';
143 $block['content'] = $output_body;
144 break;
145
146 case 2:
147 $output_body = '';
148 $output_body .= '<script type="text/javascript">';
149 $output_body .= 'var xmlfile= "'.$ajax_base_path.'/'.file_directory_path().'/tickercontent3.txt"' . "\n";
150 $output_body .= 'new ajax_ticker(xmlfile, "ajaxticker3", "someclass", 3500, "fade") ';
151 $output_body .= '</script>';
152 if ($ajax_newsflash_more) { $output_body .= '<div class="more-link">'.l(t("more"), "ajax_newsflash/list/3").'</div>'; }
153
154 $block['subject'] = 'Newsflash 3';
155 $block['content'] = $output_body;
156 break;
157 }
158
159 return $block;
160 }
161 }
162
163 function ajax_newsflash_page_list($i) {
164 $ajax_newsflash_item = variable_get("ajax_newsflash_item", 10);
165 $ajax_newsflash_column = variable_get('ajax_newsflash_column', 1);
166
167 $dse_news_total = db_query(" SELECT count(*) AS total FROM {node} n WHERE n.type='newsflash$i' AND n.status=1");
168 $row_news = db_fetch_object($dse_news_total);
169 $news_total = $row_news->total;
170 $sql_counts = "SELECT $news_total";
171
172 $sql = " SELECT n.nid, n.title, r.teaser FROM {node} n "
173 ." INNER JOIN {node_revisions} r ON r.nid = n.nid "
174 ." WHERE n.type = 'newsflash$i' AND n.status=1 "
175 ." ORDER BY n.created DESC";
176 $sql = db_rewrite_sql($sql);
177
178 $results = pager_query($sql, $ajax_newsflash_item, 0, $sql_counts);
179
180 $output = "<div id='ajax_newsflash$i'>";
181
182 if ($ajax_newsflash_column == 1) {
183 while ($node = db_fetch_object($results)) {
184 $output .= node_view(node_load($node->nid), 1);
185 }
186 } else {
187 $col = 0;
188 $output .= "<table>";
189 $output .= "<tr>";
190 while ($node = db_fetch_object($results)) {
191 $col++;
192 $output .= "<td>" .node_view(node_load($node->nid), 1)."</td>";
193 if ($col % $ajax_newsflash_column == 0 ) {
194 $output .= "</tr><tr/>";
195 }
196 }
197 $output .= "</tr>";
198 $output .="</table>";
199 }
200
201 //$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
202 $output .= theme('pager', NULL, $ajax_newsflash_item, 0);
203 $output .= '</div>';
204
205 return $output;
206 }
207
208 function ajax_newsflash_nodeapi(&$node, $op) {
209 if ( ($op != 'insert') && ($op != 'update') ) return;
210 $type = 'newsflash';
211 if ( substr($node->type,0,9) != 'newsflash' ) return;
212 //form_set_error("coba", "$type: coba aja");
213
214 //Repair first
215 if (db_table_exists("{content_type_newsflash}") && !db_table_exists("{content_type_newsflash1}")) {
216 db_query("ALTER TABLE {content_type_newsflash} RENAME {content_type_newsflash1}");
217 db_query("UPDATE {node_type} SET type='newsflash1' where type='newsflash'");
218 db_query("UPDATE {node_type} SET name='News Flash 1' where name='News Flash'");
219 db_query("UPDATE {node} SET type='newsflash1' WHERE type='newsflash'");
220 db_query("UPDATE {variable} SET name='node_options_newsflash1' WHERE name = 'node_options_newsflash'");
221 db_query("DELETE FROM {variable} WHERE name='node_options_newsflash' ");
222 }
223
224 if (db_table_exists("{content_type_newsflash}") && db_table_exists("{content_type_newsflash1}")) {
225 db_query("DELETE FROM {node_type} where type='newsflash'");
226 db_query("UPDATE {node} SET type='newsflash1' WHERE type='newsflash'");
227 db_query("DELETE FROM {variable} WHERE name='node_options_newsflash' ");
228 db_query("DROP TABLE IF EXISTS {content_type_newsflash} ");
229 }
230
231 for ($i=1;$i<=3;$i++) {
232 if (!db_table_exists("{content_type_newsflash$i}")) {
233 db_query("CREATE TABLE {content_type_newsflash$i} (
234 `vid` int(10) NOT NULL default '0',
235 `nid` int(10) NOT NULL default '0',
236 PRIMARY KEY (vid)
237 ) /*!40100 DEFAULT CHARACTER SET utf8 */");
238 }
239
240 $results_check_type = db_query("SELECT * from {node_type} WHERE type='newsflash$i'");
241 if (!db_num_rows($results_check_type)) {
242 db_query("INSERT INTO {node_type} (type,name,module,description, has_title,title_label, has_body, body_label, locked) "
243 ."VALUES ('newsflash$i','News Flash $i','node', 'News Flash $i',1,'Title', 1, 'Body', 0)");
244 }
245 variable_set("node_options_newsflash$i", array('status', FALSE));
246 }
247
248 //Update File
249 for ($i=1;$i<=3;$i++) {
250 //Check database
251 $sql = " SELECT n.nid, teaser FROM {node} n INNER JOIN {node_revisions} r ON n.nid=r.nid "
252 ." WHERE n.status=1 AND n.type='newsflash$i'";
253 $results = db_query($sql);
254
255 $file = '';
256 while ($data = db_fetch_object($results)) {
257 $newsflash_nid = $data->nid;
258 $file .="<div class=\"message\">";
259 $file .= "<a href='/node/$newsflash_nid'>".$data->teaser ."</a>";
260 $file .="</div>";
261 }
262
263 $myfile = file_directory_path()."/tickercontent$i.txt";
264 if (!($fh = fopen($myfile, 'w'))) {
265 watchdog('error',"Can't open file : $myfile");
266 return;
267 }
268 $stringData = $file;
269 fwrite($fh, $stringData);
270 fclose($fh);
271 }
272 }
273
274
275
276 ?>

  ViewVC Help
Powered by ViewVC 1.1.2