1. <?php
  2.  
  3. /*
  4. Plugin Name: Horizontal scrolling announcement
  5. Plugin URI: http://www.gopiplus.com/work/2010/07/18/horizontal-scrolling-announcement/
  6. Description: This horizontal scrolling announcement wordpress plug-in let's scroll the content from one end to another end like reel.
  7. Version: 4.0
  8. Author: Gopi.R
  9. Author URI: http://www.gopiplus.com/work/2010/07/18/horizontal-scrolling-announcement/
  10. Donate link: http://www.gopiplus.com/work/2010/07/18/horizontal-scrolling-announcement/
  11. */
  12.  
  13. global $wpdb, $wp_version;
  14. define("WP_HSA_TABLE", $wpdb->prefix . "hsa_plugin");
  15.  
  16. function horizontal_scrolling_announcement()
  17. {
  18. global $wpdb;
  19. $data = $wpdb->get_results("select hsa_text,hsa_link from ".WP_HSA_TABLE." where hsa_status='YES' ORDER BY hsa_order");
  20. if ( ! empty($data) )
  21. {
  22. $cnt = 0;
  23. foreach ( $data as $data )
  24. {
  25. @$link = $data->hsa_link;
  26. if($cnt==0)
  27. {
  28. // KM 111124 initialize hsa
  29. if (!isset($hsa)) {$hsa = '';}
  30. if($link != "") { $hsa = $hsa . "<a href='".$link."'>"; }
  31. $hsa = $hsa . stripslashes($data->hsa_text);
  32. if($link != "") { $hsa = $hsa . "</a>"; }
  33. }
  34. else
  35. {
  36. $hsa = $hsa . " - ";
  37. if($link != "") { $hsa = $hsa . "<a href='".$link."'>"; }
  38. $hsa = $hsa . stripslashes($data->hsa_text);
  39. if($link != "") { $hsa = $hsa . "</a>"; }
  40. }
  41. $cnt = $cnt + 1;
  42. }
  43. }
  44. $hsa_title = get_option('hsa_title');
  45. $hsa_scrollamount = get_option('hsa_scrollamount');
  46. $hsa_scrolldelay = get_option('hsa_scrolldelay');
  47. $hsa_direction = get_option('hsa_direction');
  48. $hsa_style = get_option('hsa_style');
  49.  
  50. // KM 111124 initialize what_marquee
  51. if (!isset($what_marquee)) {$what_marquee = '';}
  52. $what_marquee = $what_marquee . "<div style='padding:3px;'>";
  53. $what_marquee = $what_marquee . "<marquee style='$hsa_style' scrollamount='$hsa_scrollamount' scrolldelay='$hsa_scrolldelay' direction='$hsa_direction' onmouseover='this.stop()' onmouseout='this.start()'>";
  54. $what_marquee = $what_marquee . $hsa;
  55. $what_marquee = $what_marquee . "</marquee>";
  56. $what_marquee = $what_marquee . "</div>";
  57. echo $what_marquee;
  58. }
  59.  
  60. //if (function_exists (horizontal_scrolling_announcement)) horizontal_scrolling_announcement();
  61.  
  62.  
  63. add_filter('the_content','HSA_show_filter');
  64.  
  65. function HSA_show_filter($content)
  66. {
  67. return preg_replace_callback('/\[HORIZONTAL-SCROLLING(.*?)\]/sim','HSA_show_filter_callback',$content);
  68. }
  69.  
  70. function HSA_show_filter_callback($matches)
  71. {
  72. global $wpdb;
  73. $data = $wpdb->get_results("select hsa_text,hsa_link from ".WP_HSA_TABLE." where hsa_status='YES' ORDER BY hsa_order");
  74. if ( ! empty($data) )
  75. {
  76. $cnt = 0;
  77. foreach ( $data as $data )
  78. {
  79. @$link = $data->hsa_link;
  80. if($cnt==0)
  81. {
  82. if($link != "") { $hsa = $hsa . "<a href='".$link."'>"; }
  83. $hsa = $hsa . stripslashes($data->hsa_text);
  84. if($link != "") { $hsa = $hsa . "</a>"; }
  85. }
  86. else
  87. {
  88. $hsa = $hsa . " - ";
  89. if($link != "") { $hsa = $hsa . "<a href='".$link."'>"; }
  90. $hsa = $hsa . stripslashes($data->hsa_text);
  91. if($link != "") { $hsa = $hsa . "</a>"; }
  92. }
  93. $cnt = $cnt + 1;
  94. }
  95. }
  96.  
  97. $hsa_title = get_option('hsa_title');
  98. $hsa_scrollamount = get_option('hsa_scrollamount');
  99. $hsa_scrolldelay = get_option('hsa_scrolldelay');
  100. $hsa_direction = get_option('hsa_direction');
  101. $hsa_style = get_option('hsa_style');
  102. $what_marquee = $what_marquee . "<div style='padding:3px;'>";
  103. $what_marquee = $what_marquee . "<marquee style='$hsa_style' scrollamount='$hsa_scrollamount' scrolldelay='$hsa_scrolldelay' direction='$hsa_direction' onmouseover='this.stop()' onmouseout='this.start()'>";
  104. $what_marquee = $what_marquee . $hsa;
  105. $what_marquee = $what_marquee . "</marquee>";
  106. $what_marquee = $what_marquee . "</div>";
  107. return $what_marquee;
  108. }
  109.  
  110. function HSA_deactivate()
  111. {
  112. delete_option('hsa_title');
  113. delete_option('hsa_scrollamount');
  114. delete_option('hsa_scrolldelay');
  115. delete_option('hsa_direction');
  116. delete_option('hsa_style');
  117. }
  118.  
  119. function HSA_activation()
  120. {
  121. global $wpdb;
  122.  
  123. if($wpdb->get_var("show tables like '". WP_HSA_TABLE . "'") != WP_HSA_TABLE)
  124. {
  125. $wpdb->query("
  126. CREATE TABLE IF NOT EXISTS `". WP_HSA_TABLE . "` (
  127. `hsa_id` int(11) NOT NULL auto_increment,
  128. `hsa_text` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  129. `hsa_order` int(11) NOT NULL default '0',
  130. `hsa_status` char(3) NOT NULL default 'No',
  131. `hsa_date` datetime NOT NULL default '0000-00-00 00:00:00',
  132. PRIMARY KEY (`hsa_id`) )
  133. ");
  134. $sSql = "INSERT INTO `". WP_HSA_TABLE . "` (`hsa_text`, `hsa_order`, `hsa_status`, `hsa_date`)";
  135. $sSql = $sSql . "VALUES ('This is sample text for horizontal scrolling announcement.', '1', 'YES', '0000-00-00 00:00:00');";
  136. $wpdb->query($sSql);
  137. }
  138. $sSql = "ALTER TABLE `". WP_HSA_TABLE . "` ADD `hsa_link` VARCHAR( 1024 ) NOT NULL ";
  139. $wpdb->query($sSql);
  140.  
  141. add_option('hsa_title', "Announcement");
  142. add_option('hsa_scrollamount', "2");
  143. add_option('hsa_scrolldelay', "5");
  144. add_option('hsa_direction', "left");
  145. add_option('hsa_style', "color:#FF0000;font:Arial;");
  146. }
  147.  
  148. function HSA_admin_options()
  149. {
  150. global $wpdb;
  151. ?>
  152.  
  153. <div class="wrap">
  154. <?php
  155. $title = __('Horizontal scrolling announcement');
  156. $mainurl = get_option('siteurl')."/wp-admin/options-general.php?page=horizontal-scrolling-announcement/horizontal-scrolling-announcement.php";
  157.  
  158. $DID=@$_GET["DID"];
  159. $AC=@$_GET["AC"];
  160. $submittext = "Insert Message";
  161.  
  162. // KM 25 NOV 11 Added initialization of $_POST['has_text']
  163. if (!isset($_POST['hsa_text'])) {$_POST['hsa_text'] = '';}
  164. if($AC <> "DEL" and trim($_POST['hsa_text']) <>"")
  165. {
  166. if($_POST['hsa_id'] == "" )
  167. {
  168. $sql = "insert into ".WP_HSA_TABLE.""
  169. . " set `hsa_text` = '" . mysql_real_escape_string(trim($_POST['hsa_text']))
  170. . "', `hsa_order` = '" . $_POST['hsa_order']
  171. . "', `hsa_status` = '" . $_POST['hsa_status']
  172. . "', `hsa_link` = '" . $_POST['hsa_link']
  173. . "'";
  174. }
  175. else
  176. {
  177. $sql = "update ".WP_HSA_TABLE.""
  178. . " set `hsa_text` = '" . mysql_real_escape_string(trim($_POST['hsa_text']))
  179. . "', `hsa_order` = '" . $_POST['hsa_order']
  180. . "', `hsa_status` = '" . $_POST['hsa_status']
  181. . "', `hsa_link` = '" . $_POST['hsa_link']
  182. . "' where `hsa_id` = '" . $_POST['hsa_id']
  183. . "'";
  184. }
  185. $wpdb->get_results($sql);
  186. }
  187.  
  188. if($AC=="DEL" && $DID > 0)
  189. {
  190. $wpdb->get_results("delete from ".WP_HSA_TABLE." where hsa_id=".$DID);
  191. }
  192.  
  193. if($DID<>"" and $AC <> "DEL")
  194. {
  195. //select query
  196. $data = $wpdb->get_results("select * from ".WP_HSA_TABLE." where hsa_id=$DID limit 1");
  197.  
  198. //bad feedback
  199. if ( empty($data) )
  200. {
  201. echo "<div id='message' class='error'><p>No data available! use below form to create!</p></div>";
  202. return;
  203. }
  204.  
  205. $data = $data[0];
  206.  
  207. //encode strings
  208. if ( !empty($data) ) $hsa_id_x = htmlspecialchars(stripslashes($data->hsa_id));
  209. if ( !empty($data) ) $hsa_text_x = htmlspecialchars(stripslashes($data->hsa_text));
  210. if ( !empty($data) ) $hsa_status_x = htmlspecialchars(stripslashes($data->hsa_status));
  211. if ( !empty($data) ) $hsa_link_x = htmlspecialchars(stripslashes($data->hsa_link));
  212. if ( !empty($data) ) $hsa_order_x = htmlspecialchars(stripslashes($data->hsa_order));
  213.  
  214. $submittext = "Update Message";
  215. }
  216. ?>
  217. <?php include_once("button.php"); ?>
  218. <h2><?php echo wp_specialchars( $title ); ?></h2>
  219. <script language="JavaScript" src="<?php echo get_option('siteurl'); ?>/wp-content/plugins/horizontal-scrolling-announcement/horizontal-scrolling-announcement.js"></script>
  220. <form name="form_hsa" method="post" action="<?php echo $mainurl; ?>" onsubmit="return has_submit()" >
  221. <table width="100%">
  222. <tr>
  223. <td colspan="2" align="left" valign="middle">Enter the message:</td>
  224. </tr>
  225. <tr>
  226. <?php //KM 25 Nov 11 added initialization ?>
  227. <?php if (!isset($hsa_text_x)) {$hsa_text_x = '';} ?>
  228. <td colspan="2" align="left" valign="middle"><textarea name="hsa_text" cols="70" rows="8" id="hsa_text"><?php echo $hsa_text_x; ?></textarea></td>
  229. </tr>
  230. <tr>
  231. <td colspan="2" align="left" valign="middle">Enter the hyperlink:</td>
  232. </tr>
  233. <tr>
  234. <?php
  235. // KM 25 NOV 11 added initialization
  236. if (!isset($hsa_link_x)) {$hsa_link_x = '';}
  237. ?>
  238. <td colspan="2" align="left" valign="middle"><input name="hsa_link" type="text" id="hsa_link" size="100" value="<?php echo $hsa_link_x; ?>" maxlength="1024" /></td>
  239. </tr>
  240. <tr>
  241. <td align="left" valign="middle">Display Status:</td>
  242. <td align="left" valign="middle">Display Order:</td>
  243. </tr>
  244. <tr>
  245. <td width="20%" align="left" valign="middle"><select name="hsa_status" id="hsa_status">
  246. <option value="">Select</option>
  247. <option value='YES' <?php if($hsa_status_x=='YES') { echo 'selected' ; } ?>>Yes</option>
  248. <option value='NO' <?php if($hsa_status_x=='NO') { echo 'selected' ; } ?>>No</option>
  249. </select> </td>
  250. <?php
  251. // KM 25 NOV 11 Added initialization of Order variable
  252. if (!isset($hsa_order_x)) {$hsa_order_x = '';}
  253. ?>
  254. <td width="40%" align="left" valign="middle"><input name="hsa_order" type="text" id="hsa_order" size="10" value="<?php echo $hsa_order_x; ?>" maxlength="3" /></td>
  255. </tr>
  256. <tr>
  257. <td height="35" colspan="2" align="left" valign="bottom">
  258. <input name="publish" lang="publish" class="button-primary" value="<?php echo $submittext?>" type="submit" />
  259. <input name="publish" lang="publish" class="button-primary" onclick="_hsa_redirect()" value="Cancel" type="button" /></td>
  260. </tr>
  261. <?php // KM 25 NOV 11 initialize hsa_id_x ?>
  262. <?php if(!isset($hsa_id_x)) {$hsa_id_x = '';} ?>
  263. <input name="hsa_id" id="hsa_id" type="hidden" value="<?php echo $hsa_id_x; ?>">
  264. </table>
  265. </form>
  266. <div class="tool-box">
  267. <?php
  268. $data = $wpdb->get_results("select * from ".WP_HSA_TABLE." order by hsa_order");
  269. if ( empty($data) )
  270. {
  271. echo "<div id='message' class='error'>No data available! use below form to create!</div>";
  272. return;
  273. }
  274. ?>
  275. <form name="frm_hsa" method="post">
  276. <table width="100%" class="widefat" id="straymanage">
  277. <thead>
  278. <tr>
  279. <th width="3%" align="left" scope="col">ID</td>
  280. <th align="left" scope="col">Message</td>
  281. <th width="7%" align="left" scope="col"> Order
  282. </td>
  283. <th width="7%" align="left" scope="col">Display</td>
  284. <th width="8%" align="left" scope="col">Action</td>
  285. </tr>
  286. </thead>
  287. <?php
  288. $i = 0;
  289. foreach ( $data as $data ) {
  290. if($data->hsa_status=='YES') { $displayisthere="True"; }
  291. ?>
  292. <tbody>
  293. <tr class="<?php if ($i&1) { echo'alternate'; } else { echo ''; }?>">
  294. <td align="left" valign="middle"><?php echo(stripslashes($data->hsa_id)); ?></td>
  295. <td align="left" valign="middle"><a href='<?php echo $data->hsa_link; ?>'><?php echo(stripslashes($data->hsa_text)); ?></a></td>
  296. <td align="left" valign="middle"><?php echo(stripslashes($data->hsa_order)); ?></td>
  297. <td align="left" valign="middle"><?php echo(stripslashes($data->hsa_status)); ?></td>
  298. <td align="left" valign="middle"><a href="options-general.php?page=horizontal-scrolling-announcement/horizontal-scrolling-announcement.php&DID=<?php echo($data->hsa_id); ?>">Edit</a> &nbsp; <a onClick="javascript:_hsadelete('<?php echo($data->hsa_id); ?>')" href="javascript:void(0);">Delete</a> </td>
  299. </tr>
  300. </tbody>
  301. <?php $i = $i+1; } ?>
  302. <?php if($displayisthere<>"True") { ?>
  303. <tr>
  304. <td colspan="5" align="center" style="color:#FF0000" valign="middle">No Announcement available with display status 'Yes'!' </td>
  305. </tr>
  306. <?php } ?>
  307. </table>
  308. </form>
  309. <?php
  310. include_once("help.php");
  311. // KM 25 NOV 11 Added single quotes around help
  312. if (function_exists ('help')) help();
  313. ?>
  314. </div>
  315. </div>
  316. <?php
  317. }
  318.  
  319. function HSA_add_to_menu()
  320. {
  321. add_options_page('Horizontal scrolling announcement', 'Horizontal Scrolling', 'manage_options', __FILE__, 'HSA_admin_options' );
  322. add_options_page('Horizontal scrolling announcement', '', 'manage_options', "horizontal-scrolling-announcement/horizontal-scrolling-setting.php",'' );
  323. }
  324.  
  325. function HSA_widget_init()
  326. {
  327. register_sidebar_widget(__('Horizontal Scrolling'), 'HSA_widget');
  328.  
  329. if(function_exists('register_sidebar_widget'))
  330. {
  331. register_sidebar_widget('Horizontal Scrolling', 'HSA_widget');
  332. }
  333.  
  334. if(function_exists('register_widget_control'))
  335. {
  336. register_widget_control(array('Horizontal Scrolling', 'widgets'), 'HSA_control');
  337. }
  338. }
  339.  
  340. function HSA_control()
  341. {
  342. echo "Horizontal scrolling announcement";
  343. }
  344.  
  345.  
  346. function HSA_widget($args)
  347. {
  348. extract($args);
  349. $hsa_title = get_option('hsa_title');
  350. if($hsa_title <> "")
  351. {
  352. echo $before_widget . $before_title;
  353. echo get_option('hsa_title');
  354. echo $after_title;
  355. }
  356. else
  357. {
  358. echo "<div style='padding-top:10px;padding-bottom:10px;'>";
  359. }
  360. horizontal_scrolling_announcement();
  361. if($hsa_title <> "")
  362. {
  363. echo $after_widget;
  364. }
  365. else
  366. {
  367. echo "</div>";
  368. }
  369. }
  370.  
  371. add_action("plugins_loaded", "HSA_widget_init");
  372. register_activation_hook(__FILE__, 'HSA_activation');
  373. add_action('admin_menu', 'HSA_add_to_menu');
  374. register_deactivation_hook( __FILE__, 'HSA_deactivate' );
  375. add_action('init', 'HSA_widget_init');
  376. ?>