Advertisement
macmiller1

V1horizontal-scrolling-announcement.php

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