Advertisement
Guest User

news ticker

a guest
Apr 12th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.57 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Plugin Name: News-Ticker
  6.  
  7. Plugin URI: http://18elements.com/tools/news-ticker-for-wordpress
  8.  
  9. Description: Inserts a fading or sliding text banner with Posts, Entries or Comments RSS feeds
  10.  
  11. Author: Daniel Sachs
  12.  
  13. Author URI: http://18elements.com/
  14.  
  15. Version: 2.1.2
  16.  
  17. */
  18.  
  19. /*  
  20.  
  21. Copyright 2009-2013 18elements.com  (email: hello@18elements.com)
  22.  
  23.  
  24.  
  25. This program is free software; you can redistribute it and/or modify
  26.  
  27. it under the terms of the GNU General Public License as published by
  28.  
  29. the Free Software Foundation; either version 2 of the License, or
  30.  
  31. (at your option) any later version.
  32.  
  33.  
  34.  
  35. This program is distributed in the hope that it will be useful,
  36.  
  37. but WITHOUT ANY WARRANTY; without even the implied warranty of
  38.  
  39. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  40.  
  41. GNU General Public License for more details.
  42.  
  43.  
  44.  
  45. You should have received a copy of the GNU General Public License
  46.  
  47. along with this program; if not, write to the Free Software
  48.  
  49. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  50.  
  51. */
  52.  
  53. define('TICKER_VERSION', '2.1.2');
  54.  
  55. define('TICKER_MAX_INT', defined('PHP_INT_MAX') ? PHP_INT_MAX : 32767);
  56.  
  57. define('PHPREQ',5);
  58.  
  59.  
  60.  
  61. $phpver=phpversion();$phpmaj=$phpver[0];
  62.  
  63.  
  64.  
  65. if($phpmaj>=PHPREQ){
  66.  
  67.     require_once('rss.php');
  68.  
  69. }
  70.  
  71.  
  72.  
  73. require_once('news-ticker_wpml.php');
  74.  
  75.  
  76.  
  77. register_activation_hook( __FILE__, 'ticker_activate' );
  78.  
  79. register_deactivation_hook( __FILE__, 'ticker_deactivate' );
  80.  
  81. add_action('switch_theme', 'ticker_activate');
  82.  
  83. add_action('admin_menu', 'ticker_add_pages');
  84.  
  85. add_action('wp_print_scripts','ticker_js');
  86.  
  87.  
  88.  
  89. function ticker_js(){  
  90.  
  91. if(!is_admin()){
  92.  
  93.     wp_enqueue_script ('jquery');  
  94.  
  95.     wp_enqueue_script ('ticker_pack', '/' . PLUGINDIR . '/news-ticker/cycle.js', array('jquery'));
  96.  
  97. }
  98.  
  99. }
  100.  
  101. function insert_newsticker(){
  102.  
  103.   $tickerspeed=get_option('ticker_speed');
  104.  
  105.   $tickertimeout=get_option('ticker_timeout');
  106.  
  107.   $tickeranimation=get_option('ticker_anim');
  108.  
  109.   $tickerheight=get_option('ticker_ht');
  110.  
  111.   ?>
  112.  
  113. <!-- START TICKER VER <?php echo TICKER_VERSION; ?> -->
  114.  
  115. <script type="text/javascript" language="javascript">
  116.  
  117. jQuery(document).ready(function(){
  118.  
  119.   jQuery('#news-ticker').cycle({
  120.  
  121.      speed: <?php echo $tickerspeed; ?>000,
  122.  
  123.      timeout: <?php echo $tickertimeout; ?>000,
  124.  
  125.      <?php if ($tickerheight == '') { ?>
  126.  
  127.          height: 'auto',         
  128.  
  129.      <?php } else { ?>
  130.  
  131.          height: <?php echo $tickerheight; ?>,
  132.  
  133.     <?php } ?>
  134.  
  135.      
  136.  
  137.      fx: '<?php echo $tickeranimation; ?>',
  138.  
  139.      pause: 1,
  140.  
  141.      containerResize: 1
  142.  
  143.   });
  144.  
  145. });
  146.  
  147. </script>
  148.  
  149. <ul id="news-ticker" style="overflow:hidden;">
  150.  
  151.   <?php ticker_content($content); ?>
  152.  
  153. </ul>
  154.  
  155. <!-- END TICKER -->
  156.  
  157. <?php
  158.  
  159. }
  160.  
  161.  
  162.  
  163. function ticker_content(){
  164.  
  165.  $phpver=phpversion();$phpmaj=$phpver[0];
  166.  
  167.  if($phpmaj<PHPREQ){
  168.  
  169.    $postorcomment=get_option('ticker_rss');
  170.  
  171.    update_option('ticker_rss','norss');
  172.  
  173.  }
  174.  
  175.  $site_url = get_option('siteurl');
  176.  
  177.  
  178.  
  179.  $rss_opt_val = get_option('ticker_rss');
  180.  
  181.  
  182.  
  183.  $images_opt_val = get_option('ticker_images');
  184.  
  185.  $dates_opt_val = get_option('ticker_dates');
  186.  
  187.  $content_opt_val = get_option('ticker_content');
  188.  
  189.  
  190.  
  191.  $type_opt_val = get_option('ticker_type');
  192.  
  193.  if($type_opt_val=='recent-comments' && $rss_opt_val=='norss'){
  194.  
  195.    $posts = ticker_recent_comments(
  196.  
  197.                  get_option('ticker_num_posts'),
  198.  
  199.                  get_option('ticker_auto_excerpt_length')
  200.  
  201.                  );
  202.  
  203.    
  204.  
  205.  }else{
  206.  
  207.    switch($rss_opt_val){
  208.  
  209.    case 'external':
  210.  
  211.      include_once(ABSPATH.WPINC.'/rss.php');
  212.  
  213.      $namenum = get_option('ext_rss');
  214.  
  215.      $maxnum = get_option('ext_rss_num');
  216.  
  217.      $feed = fetch_rss($namenum);
  218.  
  219.      $items = array_slice($feed->items, 0, $maxnum);
  220.  
  221.      break;
  222.  
  223.    case 'comments':
  224.  
  225.      $posts = ticker_use_rss(get_bloginfo('comments_rss2_url'));
  226.  
  227.      break;
  228.  
  229.    case 'entries':
  230.  
  231.      $posts = ticker_use_rss(get_bloginfo('rss2_url'));
  232.  
  233.      break;
  234.  
  235.    case 'norss':
  236.  
  237.      $posts = ticker_get_posts(
  238.  
  239.                    get_option('ticker_type'),
  240.  
  241.                    get_option('ticker_category_filter'),
  242.  
  243.                    get_option('ticker_num_posts'),
  244.  
  245.                    get_option('ticker_user_specified_posts')
  246.  
  247.                    );
  248.  
  249.      break;
  250.  
  251.    case 'norss-comments':
  252.  
  253.      break;
  254.  
  255.    default:
  256.  
  257.      $posts = ticker_get_posts(
  258.  
  259.                    get_option('ticker_type'),
  260.  
  261.                    get_option('ticker_category_filter'),
  262.  
  263.                    get_option('ticker_num_posts'),
  264.  
  265.                    get_option('ticker_user_specified_posts')
  266.  
  267.                    );
  268.  
  269.      break;
  270.  
  271.    }
  272.  
  273.  }
  274.  
  275.  
  276.  
  277. if ($rss_opt_val=='external') {
  278.  
  279.     if (!empty($items)) :
  280.  
  281.           foreach ($items as $item) : ?>
  282.  
  283.                 <li><span class="tickerDate"><?php $pubdate = substr($item['pubdate'], 4, 12); echo $pubdate; ?></span> - <span class="tickerLink"><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></b></span></li>
  284.  
  285.     <?php endforeach;
  286.  
  287.     endif;
  288.  
  289. } else {  
  290.  
  291.  
  292.  
  293.  foreach ($posts as $post_id => $post){
  294.  
  295.    $title   = $posts[$post_id]['post_title'];
  296.  
  297.    $excerpt = $posts[$post_id]['post_excerpt'];
  298.  
  299.    $link    = $posts[$post_id]['url'];
  300.  
  301.    $date    = $posts[$post_id]['post_human_date'];
  302.  
  303.    $image   = $posts[$post_id]['_thumbnail_id'];
  304.  
  305. ?>
  306.  
  307.    
  308.  
  309. <li>
  310.  
  311. <?php if($images_opt_val=='checked') { ?>
  312.  
  313.     <span class="tickerImg">
  314.  
  315.          <?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?>
  316.  
  317.     </span>
  318.  
  319. <?php } ?>
  320.  
  321. <?php if($dates_opt_val=='checked') { ?><span class="tickerDate"><?php echo $date; ?></span> - <?php } ?><span class="tickerLink"><a href="<?php echo $link;  ?>"><?php echo $title;?></a></span><?php if($content_opt_val=='checked') { ?> - <span class="tickerText"><?php echo $excerpt; ?>... <a href="<?php echo $link; ?>">More &rarr;</a></span><?php } ?></li>
  322.  
  323.  
  324.  
  325. <?php
  326.  
  327. }
  328.  
  329. }
  330.  
  331. }
  332.  
  333.  
  334.  
  335. /**
  336.  
  337.  * Get an array of recent comments
  338.  
  339.  * Adapted from simple_recent_comments http://www.g-loaded.eu/2006/01/15/simple-recent-comments-wordpress-plugin/
  340.  
  341.  */
  342.  
  343. function ticker_recent_comments($src_count, $src_length) {
  344.  
  345.     global $wpdb;
  346.  
  347.    
  348.  
  349.     $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,
  350.  
  351.             SUBSTRING(comment_content,1,$src_length) AS com_excerpt
  352.  
  353.             FROM $wpdb->comments
  354.  
  355.             LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
  356.  
  357.             WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
  358.  
  359.             ORDER BY comment_date_gmt DESC
  360.  
  361.             LIMIT $src_count";
  362.  
  363.     $sql = apply_filters('ticker-recent-comments',$sql);
  364.  
  365.     $comments = $wpdb->get_results($sql);
  366.  
  367.  
  368.  
  369.     foreach($comments as $comment){
  370.  
  371.       $title="Comment on ".$comment->post_title." by ".$comment->comment_author;
  372.  
  373.       $link =get_permalink($comment->ID);
  374.  
  375.       $description=$comment->com_excerpt;
  376.  
  377.  
  378.  
  379.       $posts[$comment->comment_ID]['post_title']=ticker_html_to_text($title);
  380.  
  381.       $posts[$comment->comment_ID]['post_excerpt']=ticker_html_to_text($description);
  382.  
  383.       $posts[$comment->comment_ID]['url']=$link;
  384.  
  385.     }
  386.  
  387. return $posts;
  388.  
  389. }
  390.  
  391.  
  392.  
  393. function ticker_get_posts($type, $cat_filter, $n, $post_list=null){
  394.  
  395.     switch($type){
  396.  
  397.         case 'popular':
  398.  
  399.             $days = get_option('ticker_popular_days');
  400.  
  401.             $popular_posts = stats_get_csv('postviews', "days=$days&limit=0");
  402.  
  403.            
  404.  
  405.             $post_list = '';
  406.  
  407.             foreach ($popular_posts as $post) {
  408.  
  409.                 if($post_list!='')
  410.  
  411.                     $post_list .= ', ';
  412.  
  413.                    
  414.  
  415.                 $post_list .= $post['post_id'];
  416.  
  417.             }
  418.  
  419.            
  420.  
  421.             return ticker_get_posts('userspecified', $cat_filter, $n, $post_list);
  422.  
  423.             break;
  424.  
  425.  
  426.  
  427.         case 'recent':
  428.  
  429.             $posts = get_posts(
  430.  
  431.                 array(
  432.  
  433.                     'numberposts' => TICKER_MAX_INT,
  434.  
  435.                     'orderby' => 'post_date',
  436.  
  437.                     'suppress_filters' => 0,
  438.  
  439.                 )
  440.  
  441.             );
  442.  
  443.            
  444.  
  445.             break;
  446.  
  447.  
  448.  
  449.         case 'commented':
  450.  
  451.             $posts = get_posts(
  452.  
  453.                 array(
  454.  
  455.                     'numberposts' => TICKER_MAX_INT,
  456.  
  457.                     'orderby' => 'comment_count',
  458.  
  459.                     'suppress_filters' => 0,
  460.  
  461.                 )
  462.  
  463.             );
  464.  
  465.             break;
  466.  
  467.  
  468.  
  469.         case 'userspecified':
  470.  
  471.             $posts_tmp = get_posts(
  472.  
  473.                 array(
  474.  
  475.                     'numberposts' => TICKER_MAX_INT,
  476.  
  477.                     'include' => $post_list,
  478.  
  479.                     'suppress_filters' => 0,
  480.  
  481.                 )
  482.  
  483.             );
  484.  
  485.            
  486.  
  487.             $posts = array();
  488.  
  489.             $post_list_arr = preg_split('/[\s,]+/', $post_list);
  490.  
  491.            
  492.  
  493.             foreach($post_list_arr as $post_id) {
  494.  
  495.                 foreach($posts_tmp as $post) {
  496.  
  497.                     if($post->ID==$post_id) {
  498.  
  499.                         $posts[] = $post;
  500.  
  501.                         break;
  502.  
  503.                     }
  504.  
  505.                 }
  506.  
  507.             }
  508.  
  509.             break;
  510.  
  511.  
  512.  
  513.         default:
  514.  
  515.             $posts = null;
  516.  
  517.             break;
  518.  
  519.     }
  520.  
  521.    
  522.  
  523.     $cat_filter = apply_filters('category-filter', $cat_filter);
  524.  
  525.     if($cat_filter==null || sizeof($cat_filter)<1)
  526.  
  527.         $do_category_filter = false;
  528.  
  529.     else
  530.  
  531.         $do_category_filter = true;
  532.  
  533.        
  534.  
  535.     $posts_fixed = array();
  536.  
  537.     if($posts!=null && sizeof($posts)>0 && is_object($posts[0])) {
  538.  
  539.         foreach($posts as $k => $v){
  540.  
  541.             if(sizeof($posts_fixed)==$n)
  542.  
  543.                 break;
  544.  
  545.             $post_categories = wp_get_post_categories($v->ID);
  546.  
  547.             if(!$do_category_filter || ($do_category_filter && sizeof(array_intersect($cat_filter, $post_categories))>0))
  548.  
  549.                 $posts_fixed[$v->ID] = (array) $v;
  550.  
  551.         }
  552.  
  553.     }
  554.  
  555.     ticker_get_posts_categories($posts_fixed);
  556.  
  557.     ticker_get_posts_tags($posts_fixed);
  558.  
  559.     ticker_get_posts_meta($posts_fixed);
  560.  
  561.     ticker_get_posts_tweak($posts_fixed);
  562.  
  563.    
  564.  
  565.     return $posts_fixed;
  566.  
  567. }
  568.  
  569.  
  570.  
  571. function ticker_get_posts_categories(&$posts) {
  572.  
  573.     foreach ($posts as $post_id => $post) {
  574.  
  575.         $cats = wp_get_post_categories($post_id);
  576.  
  577.         $categories = '';
  578.  
  579.         $cat_num = 1;
  580.  
  581.         foreach ($cats as $cat_id) {
  582.  
  583.             $cat = get_category($cat_id);
  584.  
  585.             if($categories!='')
  586.  
  587.                 $categories .= ', ';
  588.  
  589.             $categories .= $cat->name;
  590.  
  591.             $posts[$post_id]["category_$cat_num"] = $cat->name;
  592.  
  593.             $cat_num++;
  594.  
  595.         }
  596.  
  597.         $posts[$post_id]['categories'] = $categories;
  598.  
  599.     }
  600.  
  601. }
  602.  
  603.  
  604.  
  605. function ticker_get_posts_tags(&$posts) {
  606.  
  607.     foreach ($posts as $post_id => $post) {
  608.  
  609.         $tags = get_the_tags($post_id);
  610.  
  611.         $tags_str = '';
  612.  
  613.         if($tags!=null && sizeof($tags)>0) {
  614.  
  615.             $tag_num = 1;
  616.  
  617.             foreach ($tags as $tag) {
  618.  
  619.                 if($tags_str!='')
  620.  
  621.                     $tags_str .= ', ';
  622.  
  623.                 $tags_str .= $tag->name;
  624.  
  625.                 $posts[$post_id]["tag_$tag_num"] = $tag->name;
  626.  
  627.                 $tag_num++;
  628.  
  629.             }
  630.  
  631.         }
  632.  
  633.         $posts[$post_id]['tags'] = $tags_str;
  634.  
  635.     }
  636.  
  637. }
  638.  
  639.  
  640.  
  641. function ticker_get_posts_meta(&$posts) {
  642.  
  643.     foreach ($posts as $post_id => $post) {
  644.  
  645.         $custom_fields = get_post_custom($post_id);
  646.  
  647.         foreach ($custom_fields as $k => $v) {
  648.  
  649.             $posts[$post_id][$k] = $v[0];
  650.  
  651.         }
  652.  
  653.     }
  654.  
  655. }
  656.  
  657.  
  658.  
  659. function ticker_get_posts_tweak(&$posts) { 
  660.  
  661.     $date_chars = array('d', 'D', 'j', 'l', 'N', 'S', 'w', 'z', 'W', 'F', 'm', 'M', 'n', 't', 'L', 'o', 'Y', 'y', 'a', 'A', 'B', 'g', 'G', 'h', 'H', 'i', 's', 'u', 'e', 'I', 'O', 'P', 'T', 'Z', 'c', 'r', 'U');
  662.  
  663.  
  664.  
  665.     foreach ($posts as $post_id => $post) {
  666.  
  667.         $date_str = $post['post_date'];
  668.  
  669.         $date = ticker_parse_date($date_str);
  670.  
  671.         $posts[$post_id]['post_human_date'] = ticker_date_to_human_date($date);
  672.  
  673.         $posts[$post_id]['post_long_human_date'] = ticker_date_to_long_human_date($date);
  674.  
  675.         $posts[$post_id]['post_slashed_date'] = ticker_date_to_slashed_date($date);
  676.  
  677.         $posts[$post_id]['post_dotted_date'] = ticker_date_to_dotted_date($date);
  678.  
  679.         $posts[$post_id]['post_human_time'] = ticker_date_to_human_time($date);
  680.  
  681.         $posts[$post_id]['post_long_human_time'] = ticker_date_to_long_human_time($date);
  682.  
  683.         $posts[$post_id]['post_military_time'] = ticker_date_to_military_time($date);
  684.  
  685.        
  686.  
  687.         foreach($date_chars as $dc)
  688.  
  689.             $posts[$post_id]["post_date_$dc"] = date($dc, $date);
  690.  
  691.  
  692.  
  693.         $date_str = $post['post_modified'];
  694.  
  695.         $date = ticker_parse_date($date_str);
  696.  
  697.         $posts[$post_id]['post_modified_human_date'] = ticker_date_to_human_date($date);
  698.  
  699.         $posts[$post_id]['post_modified_long_human_date'] = ticker_date_to_long_human_date($date);
  700.  
  701.         $posts[$post_id]['post_modified_slashed_date'] = ticker_date_to_slashed_date($date);
  702.  
  703.         $posts[$post_id]['post_modified_dotted_date'] = ticker_date_to_dotted_date($date);
  704.  
  705.         $posts[$post_id]['post_modified_human_time'] = ticker_date_to_human_time($date);
  706.  
  707.         $posts[$post_id]['post_modified_long_human_time'] = ticker_date_to_long_human_time($date);
  708.  
  709.         $posts[$post_id]['post_modified_military_time'] = ticker_date_to_military_time($date);
  710.  
  711.  
  712.  
  713.         foreach($date_chars as $dc)
  714.  
  715.             $posts[$post_id]["post_modified_date_$dc"] = date($dc, $date);     
  716.  
  717.  
  718.  
  719.         $posts[$post_id]['post_content'] = $post['post_content'];
  720.  
  721.  
  722.  
  723.         if(function_exists('do_shortcode'))
  724.  
  725.             $posts[$post_id]['post_content'] = do_shortcode($posts[$post_id]['post_content']);
  726.  
  727.  
  728.  
  729.         $posts[$post_id]['post_content'] =
  730.  
  731.             ticker_html_to_text(       
  732.  
  733.                 str_replace("\xC2\xA0", '',
  734.  
  735.                     $posts[$post_id]['post_content']
  736.  
  737.                 )
  738.  
  739.             );
  740.  
  741.  
  742.  
  743.         if($posts[$post_id]['post_excerpt']==null || $posts[$post_id]['post_excerpt']=='') {
  744.  
  745.             $auto_excerpt_chars = get_option('ticker_auto_excerpt_length');
  746.  
  747.             $s = $posts[$post_id]['post_content'];
  748.  
  749.             $s = substr($s, 0, $auto_excerpt_chars);
  750.  
  751.             $s = substr($s, 0, strrpos($s, ' '));
  752.  
  753.            
  754.  
  755.             $posts[$post_id]['post_excerpt'] = $s;
  756.  
  757.         }
  758.  
  759.         else {
  760.  
  761.             $posts[$post_id]['post_excerpt'] = ticker_html_to_text($posts[$post_id]['post_excerpt']);
  762.  
  763.         }
  764.  
  765.  
  766.  
  767.         $posts[$post_id]['nickname'] = get_usermeta($post['post_author'], 'nickname');
  768.  
  769.         $posts[$post_id]['url'] = apply_filters('the_permalink', get_permalink($post_id));
  770.  
  771.     }
  772.  
  773. }
  774.  
  775.  
  776.  
  777. function ticker_html_to_text($html) {
  778.  
  779.     $html = preg_replace('/<style[^>]*>.*?<\/style[^>]*>/si','',$html);
  780.  
  781.  
  782.  
  783.     $html = preg_replace('/<script[^>]*>.*?<\/script[^>]*>/si','',$html);
  784.  
  785.  
  786.  
  787.   $tags = array (
  788.  
  789.       0 => '/<(\/)?h[123][^>]*>/si',
  790.  
  791.       1 => '/<(\/)?h[456][^>]*>/si',
  792.  
  793.       2 => '/<(\/)?table[^>]*>/si',
  794.  
  795.       3 => '/<(\/)?tr[^>]*>/si',
  796.  
  797.       4 => '/<(\/)?li[^>]*>/si',
  798.  
  799.       5 => '/<(\/)?br[^>]*>/si',
  800.  
  801.       6 => '/<(\/)?p[^>]*>/si',
  802.  
  803.       7 => '/<(\/)?div[^>]*>/si',
  804.  
  805.   );
  806.  
  807.   $html = preg_replace($tags, "\n", $html);
  808.  
  809.  
  810.  
  811.     $html = preg_replace('/<[^>]+>/s', '', $html);
  812.  
  813.     $html = preg_replace('/\&nbsp;/', ' ', $html);
  814.  
  815.     $html = preg_replace('/ +/s', ' ', $html);
  816.  
  817.     $html = preg_replace('/^\s+/m', '', $html);
  818.  
  819.     $html = preg_replace('/\s+$/m', '', $html);
  820.  
  821.     $html = preg_replace('/\n+/s', '-!Line Break123!-', $html);
  822.  
  823.     $html = preg_replace('/(-!Line Break123!-)+/s', ' - ', $html);
  824.  
  825.     $html = preg_replace('/ +/s', ' ', $html);
  826.  
  827.     $html = preg_replace('/^\s+/m', '', $html);
  828.  
  829.     $html = preg_replace('/\s+$/m', '', $html);
  830.  
  831.  
  832.  
  833.     return $html;
  834.  
  835. }
  836.  
  837.  
  838.  
  839. function ticker_date_to_human_date($date) {
  840.  
  841.   return date('F j, Y', $date);
  842.  
  843. }
  844.  
  845. function ticker_date_to_long_human_date($date) {
  846.  
  847.   return date('l jS \of F Y', $date);
  848.  
  849. }
  850.  
  851. function ticker_date_to_slashed_date($date) {
  852.  
  853.   return date('m/d/y', $date);
  854.  
  855. }
  856.  
  857. function ticker_date_to_dotted_date($date) {
  858.  
  859.   return date('m.d.y', $date);
  860.  
  861. }
  862.  
  863. function ticker_date_to_human_time($date) {
  864.  
  865.   return date('g:i a', $date);
  866.  
  867. }
  868.  
  869. function ticker_date_to_long_human_time($date) {
  870.  
  871.   return date('g:i:s a', $date);
  872.  
  873. }
  874.  
  875. function ticker_date_to_military_time($date) {
  876.  
  877.   return date('H:i:s', $date);
  878.  
  879. }
  880.  
  881. function ticker_parse_date($string) {
  882.  
  883.   preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
  884.  
  885.   return mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
  886.  
  887. }
  888.  
  889.  
  890.  
  891.  
  892.  
  893. function ticker_activate()
  894.  
  895. {
  896.  
  897.   ticker_set_default_options();
  898.  
  899. }
  900.  
  901. function ticker_deactivate()
  902.  
  903. {
  904.  
  905.   //echo('Deactivating News-Ticker');
  906.  
  907.   //ticker_delete_options();
  908.  
  909. }
  910.  
  911.  
  912.  
  913.  
  914.  
  915. function ticker_set_default_options() {
  916.  
  917.   if(get_option('ticker_images')===false)                       add_option('ticker_images', '');
  918.  
  919.   if(get_option('ticker_dates')===false)                        add_option('ticker_dates', '');
  920.  
  921.   if(get_option('ticker_content')===false)                      add_option('ticker_content', '');
  922.  
  923.   if(get_option('ticker_type')===false)                         add_option('ticker_type', 'commented');
  924.  
  925.   if(get_option('ticker_category_filter')===false)              add_option('ticker_category_filter', array());
  926.  
  927.   if(get_option('ticker_user_specified_posts')===false)         add_option('ticker_user_specified_posts', '');
  928.  
  929.   if(get_option('ticker_num_posts')===false)                    add_option('ticker_num_posts', 5);
  930.  
  931.   if(get_option('ticker_popular_days')===false)                 add_option('ticker_popular_days', 90);
  932.  
  933.   if(get_option('ticker_auto_excerpt_length')===false)          add_option('ticker_auto_excerpt_length', 110);
  934.  
  935.   if(get_option('ticker_admin_messages_to_show_once')===false)  add_option('ticker_admin_messages_to_show_once', array());
  936.  
  937.   if(get_option('ticker_rss')===false)                          add_option('ticker_rss', 'norss');
  938.  
  939.   if(get_option('ext_rss')===false)                             add_option('ext_rss', '');
  940.  
  941.   if(get_option('ext_rss_num')===false)                         add_option('ext_rss_num', '');
  942.  
  943.   if(get_option('ticker_speed')===false)                        add_option('ticker_speed', 1);
  944.  
  945.   if(get_option('ticker_timeout')===false)                      add_option('ticker_timeout', 2);
  946.  
  947.   if(get_option('ticker_anim')===false)                         add_option('ticker_anim', 'fade');
  948.  
  949.   if(get_option('ticker_ht')===false)                           add_option('ticker_ht', 20);
  950.  
  951. }
  952.  
  953. function ticker_delete_options() {
  954.  
  955.     delete_option('ticker_images');
  956.  
  957.     delete_option('ticker_dates');
  958.  
  959.     delete_option('ticker_content');
  960.  
  961.     delete_option('ticker_type');
  962.  
  963.     delete_option('ticker_category_filter');
  964.  
  965.     delete_option('ticker_user_specified_posts');
  966.  
  967.     delete_option('ticker_num_posts');
  968.  
  969.     delete_option('ticker_popular_days');
  970.  
  971.     delete_option('ticker_auto_excerpt_length');
  972.  
  973.     delete_option('ticker_admin_messages_to_show_once');
  974.  
  975.     delete_option('ticker_rss');
  976.  
  977.     delete_option('ext_rss');
  978.  
  979.     delete_option('ext_rss_num');
  980.  
  981.     delete_option('ticker_speed');
  982.  
  983.     delete_option('ticker_timeout');
  984.  
  985.     delete_option('ticker_anim');
  986.  
  987.     delete_option('ticker_ht');
  988.  
  989. }
  990.  
  991. function ticker_add_pages() {
  992.  
  993.     add_options_page('News Ticker', 'News Ticker', 8, 'tickeroptions', 'ticker_options_page');
  994.  
  995. }
  996.  
  997.  
  998.  
  999. function ticker_options_page() {
  1000.  
  1001.     $hidden_field_name = 'ticker_submit_hidden';
  1002.  
  1003.  
  1004.  
  1005.     $images_opt_name = 'ticker_images';
  1006.  
  1007.     $dates_opt_name = 'ticker_dates';
  1008.  
  1009.     $content_opt_name = 'ticker_content';
  1010.  
  1011.     $type_opt_name = 'ticker_type';
  1012.  
  1013.     $category_filter_opt_name = 'ticker_category_filter';
  1014.  
  1015.     $user_specified_posts_opt_name = 'ticker_user_specified_posts';
  1016.  
  1017.     $num_posts_opt_name = 'ticker_num_posts';
  1018.  
  1019.     $popular_days_opt_name = 'ticker_popular_days';
  1020.  
  1021.     $auto_excerpt_length_opt_name = 'ticker_auto_excerpt_length';
  1022.  
  1023.     $rss_opt_name = 'ticker_rss';
  1024.  
  1025.     $ext_rss_name = 'ext_rss';
  1026.  
  1027.     $ext_rss_num_name = 'ext_rss_num';
  1028.  
  1029.     $ticker_speed_opt_name = 'ticker_speed';
  1030.  
  1031.     $ticker_timeout_opt_name = 'ticker_timeout';
  1032.  
  1033.     $ticker_anim_opt_name = 'ticker_anim';
  1034.  
  1035.     $ticker_ht_opt_name = 'ticker_ht';
  1036.  
  1037.    
  1038.  
  1039.     $images_opt_val = get_option($images_opt_name);
  1040.  
  1041.     $dates_opt_val = get_option($dates_opt_name);
  1042.  
  1043.     $content_opt_val = get_option($content_opt_name);
  1044.  
  1045.     $type_opt_val = get_option($type_opt_name);
  1046.  
  1047.     $category_filter_val = get_option($category_filter_opt_name);
  1048.  
  1049.     $user_specified_posts_opt_val = get_option($user_specified_posts_opt_name);
  1050.  
  1051.     $num_posts_opt_val = get_option($num_posts_opt_name);
  1052.  
  1053.     $popular_days_opt_val = get_option($popular_days_opt_name);
  1054.  
  1055.     $auto_excerpt_length_opt_val = get_option($auto_excerpt_length_opt_name);
  1056.  
  1057.     $rss_opt_val = get_option($rss_opt_name);
  1058.  
  1059.     $ext_rss_val = get_option($ext_rss_name);
  1060.  
  1061.     $ext_rss_num_val = get_option($ext_rss_num_name);
  1062.  
  1063.     $ticker_speed_opt_val = get_option($ticker_speed_opt_name);
  1064.  
  1065.     $ticker_timeout_opt_val = get_option($ticker_timeout_opt_name);
  1066.  
  1067.     $ticker_anim_opt_val = get_option($ticker_anim_opt_name);
  1068.  
  1069.     $ticker_ht_opt_val = get_option($ticker_ht_opt_name);
  1070.  
  1071.    
  1072.  
  1073.     if( $_POST[ $hidden_field_name ] == 'Y' ) {
  1074.  
  1075.         $images_opt_val = $_POST[$images_opt_name];
  1076.  
  1077.         $dates_opt_val = $_POST[$dates_opt_name];
  1078.  
  1079.         $content_opt_val = $_POST[$content_opt_name];
  1080.  
  1081.         $type_opt_val = $_POST[$type_opt_name];
  1082.  
  1083.         $category_filter_val = $_POST[$category_filter_opt_name];
  1084.  
  1085.         $user_specified_posts_opt_val = $_POST[$user_specified_posts_opt_name];
  1086.  
  1087.         $frequency_opt_val = $_POST[$frequency_opt_name];
  1088.  
  1089.         if($_POST[$frequency_opt_name]==null || $_POST[$frequency_opt_name]=='' || $_POST[$frequency_opt_name]<1)
  1090.  
  1091.             $frequency_opt_val = 10;
  1092.  
  1093.  
  1094.  
  1095.         $num_posts_opt_val = $_POST[$num_posts_opt_name];
  1096.  
  1097.         $popular_days_opt_val = $_POST[$popular_days_opt_name];
  1098.  
  1099.         $auto_excerpt_length_opt_val = $_POST[$auto_excerpt_length_opt_name];
  1100.  
  1101.         $rss_opt_val = $_POST[$rss_opt_name];
  1102.  
  1103.         $ext_rss_val = $_POST[$ext_rss_name];
  1104.  
  1105.         $ext_rss_num_val = $_POST[$ext_rss_num_name];
  1106.  
  1107.         $ticker_speed_opt_val = $_POST[$ticker_speed_opt_name];
  1108.  
  1109.         $ticker_timeout_opt_val = $_POST[$ticker_timeout_opt_name];
  1110.  
  1111.         $ticker_anim_opt_val = $_POST[$ticker_anim_opt_name];
  1112.  
  1113.         $ticker_ht_opt_val = $_POST[$ticker_ht_opt_name];
  1114.  
  1115.         if($type_opt_val=='popular' && !function_exists('stats_get_csv')) {
  1116.  
  1117.             echo "<div class='updated' style='background-color:#f66;'><p><a href='options-general.php?page=tickeroptions'>Ticker for Wordpress</a> needs attention: please install the <a href='http://wordpress.org/extend/plugins/stats/'>Wordpress.com Stats</a> plugin to use the 'Most popular' post selection type.  Until the plugin is installed, consider using the 'Most commented' post selection type instead.</p></div>";
  1118.  
  1119.             $type_opt_val = 'commented';
  1120.  
  1121.         }
  1122.  
  1123.  
  1124.  
  1125.         update_option($images_opt_name, $images_opt_val);
  1126.  
  1127.         update_option($dates_opt_name, $dates_opt_val);
  1128.  
  1129.         update_option($content_opt_name, $content_opt_val);
  1130.  
  1131.         update_option($type_opt_name, $type_opt_val);
  1132.  
  1133.         update_option($category_filter_opt_name, $category_filter_val);
  1134.  
  1135.         update_option($user_specified_posts_opt_name, $user_specified_posts_opt_val);
  1136.  
  1137.         update_option($num_posts_opt_name, $num_posts_opt_val);
  1138.  
  1139.         update_option($popular_days_opt_name, $popular_days_opt_val);
  1140.  
  1141.         update_option($auto_excerpt_length_opt_name, $auto_excerpt_length_opt_val);
  1142.  
  1143.         update_option($rss_opt_name, $rss_opt_val);
  1144.  
  1145.         update_option($ext_rss_name, $ext_rss_val);
  1146.  
  1147.         update_option($ext_rss_num_name, $ext_rss_num_val);
  1148.  
  1149.         update_option($ticker_speed_opt_name, $ticker_speed_opt_val);
  1150.  
  1151.         update_option($ticker_timeout_opt_name, $ticker_timeout_opt_val);
  1152.  
  1153.         update_option($ticker_anim_opt_name, $ticker_anim_opt_val);
  1154.  
  1155.         update_option($ticker_ht_opt_name, $ticker_ht_opt_val);
  1156.  
  1157.        
  1158.  
  1159.         echo '<div class="updated"><p><strong>Options saved.</strong></p></div>';
  1160.  
  1161.     }
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.     $stats_installed_str = function_exists('stats_get_csv')?'<font color="#00cc00">is installed</font>':'<font color="#ff0000">is not installed</font>';
  1168.  
  1169.     $plugin_directory = ticker_get_plugin_root();
  1170.  
  1171.  
  1172.  
  1173.     ?>
  1174.  
  1175.    
  1176.  
  1177.    
  1178.  
  1179.    
  1180.  
  1181.    
  1182.  
  1183.    
  1184.  
  1185.    
  1186.  
  1187. <div class="wrap">
  1188.  
  1189. <script type="text/javascript">
  1190.  
  1191. jQuery(document).ready(function($) {
  1192.  
  1193.     $(".external-extra").hide("fast");
  1194.  
  1195.     $(".ruler").click(function(){
  1196.  
  1197.         if($(this).val()==="norss") $(".post-extra").show("fast"); else $(".post-extra").hide("fast");
  1198.  
  1199.     });
  1200.  
  1201.     $(".ruler").click(function(){
  1202.  
  1203.         if($(this).val()==="external") $(".external-extra").show("fast"); else $(".external-extra").hide("fast");
  1204.  
  1205.     });
  1206.  
  1207. });
  1208.  
  1209. </script>
  1210.  
  1211. <style>
  1212.  
  1213.  
  1214.  
  1215. tr.gre {
  1216.  
  1217.     background:#f9f9f9;
  1218.  
  1219. }
  1220.  
  1221. </style>
  1222.  
  1223.   <div class="icon32" id="icon-options-general"><br></div>
  1224.  
  1225.         <h2><?php _e( 'News Ticker Options',  'news-ticker' ); ?></h2>
  1226.  
  1227.         <p></p>
  1228.  
  1229.         <hr />
  1230.  
  1231.  
  1232.  
  1233.   <form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
  1234.  
  1235.     <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
  1236.  
  1237.    
  1238.  
  1239.    
  1240.  
  1241.     <table class="form-table">
  1242.  
  1243.         <tr class="header" valign="top"><th scope="row"><h3><?php _e( 'Content Setup',  'news-ticker' ); ?></h3></th></tr>
  1244.  
  1245.        
  1246.  
  1247.         <tr class="gre" valign="top">
  1248.  
  1249.         <th scope="row"><?php _e( 'Content Source',  'news-ticker' ); ?></th>
  1250.  
  1251.         <td>
  1252.  
  1253.           <?php $phpver=phpversion();$phpmaj=$phpver[0];
  1254.  
  1255.   if($phpmaj<PHPREQ){ ?>
  1256.  
  1257.           <?php _e( 'Use of these options currently requires php version ', 'news-ticker' ); ?><?php echo PHPREQ; ?>.
  1258.  
  1259.           <?php _e( 'Your current version is ', 'news-ticker' ); ?><?php echo $phpver;?>.<br /></td>
  1260.  
  1261.         <?php
  1262.  
  1263.  } else {
  1264.  
  1265. ?>
  1266.  
  1267.        
  1268.  
  1269.         <input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='norss' <?php if($rss_opt_val=='norss'){echo 'checked';} ?> > <?php _e( '
  1270.  
  1271.        Blog Posts',  'news-ticker' ); ?><br/>
  1272.  
  1273.         <input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='entries' <?php if($rss_opt_val=='entries'){echo 'checked';} ?>>
  1274.  
  1275.         <?php _e( 'Local Entries RSS feed',  'news-ticker' ); ?> <br/>
  1276.  
  1277.         <input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='comments' <?php if($rss_opt_val=='comments'){echo 'checked';} ?>>
  1278.  
  1279.         <?php _e( 'Local Comments RSS feed',  'news-ticker' ); ?><br/>
  1280.  
  1281.         <input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='external' <?php if($rss_opt_val=='external'){echo 'checked';} ?>>
  1282.  
  1283.         <?php _e( 'External RSS feed',  'news-ticker' ); ?><br/>
  1284.  
  1285.         <div class="external-extra">
  1286.  
  1287.         <?php _e( 'External RSS Feed Url:',  'news-ticker' ); ?>        <input type="text" name="<?php echo $ext_rss_name; ?>" value="<?php echo $ext_rss_val; ?>" size="50" /><br/>
  1288.  
  1289.         <?php _e( 'Number of entries to display:',  'news-ticker' ); ?> <input type="text" name="<?php echo $ext_rss_num_name; ?>" value="<?php echo $ext_rss_num_val; ?>" size="2" />
  1290.  
  1291.         </div>
  1292.  
  1293.  
  1294.  
  1295.         </td>
  1296.  
  1297.         <?php } ?>
  1298.  
  1299.       </tr>
  1300.  
  1301.        
  1302.  
  1303.        
  1304.  
  1305.        
  1306.  
  1307.        
  1308.  
  1309.      
  1310.  
  1311.      
  1312.  
  1313.       <tr valign="top" class="post-extra">
  1314.  
  1315.         <th scope="row"><?php _e( 'Category Filter:',  'news-ticker' ); ?></th>
  1316.  
  1317.         <td> <?php _e( 'Select the categories to include.  Select one or more categories to restrict post selection to those categories.',  'news-ticker' ); ?><br />
  1318.  
  1319.           <?php _e( 'If no category is selected, all categories are included  (Multiple selection)',  'news-ticker' ); ?><br />
  1320.  
  1321.           <select style="height: auto;" name="<?php echo $category_filter_opt_name; ?>[]" multiple="multiple">
  1322.  
  1323.             <?php
  1324.  
  1325.             $categories =  get_categories(array('hide_empty' => false));
  1326.  
  1327.             if($categories!=null) {
  1328.  
  1329.                 foreach ($categories as $cat) {
  1330.  
  1331.                     if(in_array($cat->cat_ID, $category_filter_val))
  1332.  
  1333.                         $selected = 'selected="selected"';
  1334.  
  1335.                     else
  1336.  
  1337.                         $selected = '';
  1338.  
  1339.  
  1340.  
  1341.                     $option = '<option value="'.$cat->cat_ID.'" '.$selected.'>';
  1342.  
  1343.                     $option .= $cat->cat_name;
  1344.  
  1345.                     $option .= ' ('.$cat->category_count.')';
  1346.  
  1347.                     $option .= '</option>';
  1348.  
  1349.                     echo $option;
  1350.  
  1351.                 }
  1352.  
  1353.             }
  1354.  
  1355.     ?>
  1356.  
  1357.           </select></td>
  1358.  
  1359.       </tr>
  1360.  
  1361.      
  1362.  
  1363.      
  1364.  
  1365.      
  1366.  
  1367.       <tr valign="top" class="post-extra gre">
  1368.  
  1369.         <th scope="row"><?php _e( 'Post Selection:',  'news-ticker' ); ?></th>
  1370.  
  1371.         <td><input type="radio" name="<?php echo $type_opt_name; ?>" value='popular' <?php if($type_opt_val=='popular') { echo 'checked'; } ?>>
  1372.  
  1373.           <?php _e( 'Most Popular Posts over the last',  'news-ticker' ); ?>
  1374.  
  1375.           <input type="text" name="<?php echo $popular_days_opt_name; ?>" value="<?php echo $popular_days_opt_val; ?>" size="2">
  1376.  
  1377.           <?php _e( 'days',  'news-ticker' ); ?> (<a href='http://wordpress.org/extend/plugins/stats/'>Wordpress.com Stats Plugin</a> <?php echo $stats_installed_str; ?>)<br/>
  1378.  
  1379.           <input type="radio" name="<?php echo $type_opt_name; ?>" value='commented' <?php if($type_opt_val=='commented') { echo 'checked'; } ?>>
  1380.  
  1381.          <?php _e( 'Most Commented Posts',  'news-ticker' ); ?><br/>
  1382.  
  1383.           <input type="radio" name="<?php echo $type_opt_name; ?>" value='recent' <?php if($type_opt_val=='recent') { echo 'checked'; } ?>>
  1384.  
  1385.           <?php _e( 'Recent Posts',  'news-ticker' ); ?><br/>
  1386.  
  1387.           <input type="radio" name="<?php echo $type_opt_name; ?>" value='recent-comments' <?php if($type_opt_val=='recent-comments') { echo 'checked'; } ?>>
  1388.  
  1389.           <?php _e( 'Recent Comments',  'news-ticker' ); ?><br/>
  1390.  
  1391.           <input type="radio" name="<?php echo $type_opt_name; ?>" value='userspecified' <?php if($type_opt_val=='userspecified') { echo 'checked'; } ?>>
  1392.  
  1393.           <?php _e( 'Specific Posts:',  'news-ticker' ); ?>
  1394.  
  1395.           <input type="text" name="<?php echo $user_specified_posts_opt_name; ?>" value="<?php echo $user_specified_posts_opt_val; ?>" size="20">
  1396.  
  1397.           (comma separated, for example: "1, 2, 43, 17")<br/></td>
  1398.  
  1399.       </tr>
  1400.  
  1401.      
  1402.  
  1403.      
  1404.  
  1405.      
  1406.  
  1407.      
  1408.  
  1409.      
  1410.  
  1411.      
  1412.  
  1413.      
  1414.  
  1415.      
  1416.  
  1417.      
  1418.  
  1419.       <tr class="header" valign="top"><th scope="row"><h3><?php _e( 'Ticker Setup',  'news-ticker' ); ?></h3></th></tr>
  1420.  
  1421.  
  1422.  
  1423.       <tr valign="top" class="post-extra gre">
  1424.  
  1425.         <th scope="row"><?php _e( 'News Ticker Contents',  'news-ticker' ); ?></th>
  1426.  
  1427.         <td>
  1428.  
  1429.           <?php _e( 'The title of the post is displayed by default. Add more elements',  'news-ticker' ); ?><br />
  1430.  
  1431.           <input type="checkbox" name="<?php echo $images_opt_name; ?>" <?php if (isset($images_opt_name)) { echo 'value="checked"'; }?> <?php if($images_opt_val=='checked') { echo 'checked'; } ?>>
  1432.  
  1433.           <?php _e( 'Show Images',  'news-ticker' ); ?><br/>
  1434.  
  1435.           <input type="checkbox" name="<?php echo $dates_opt_name; ?>" <?php if (isset($dates_opt_name)) { echo 'value="checked"'; }?> <?php if($dates_opt_val=='checked') { echo 'checked'; } ?>>
  1436.  
  1437.           <?php _e( 'Show Dates',  'news-ticker' ); ?><br/>
  1438.  
  1439.           <input type="checkbox" name="<?php echo $content_opt_name; ?>" <?php if (isset($content_opt_name)) { echo 'value="checked"'; }?> <?php if($content_opt_val=='checked') { echo 'checked'; } ?>>
  1440.  
  1441.           <?php _e( 'Show Excerpts',  'news-ticker' ); ?><br/>
  1442.  
  1443.           </td>
  1444.  
  1445.       </tr>
  1446.  
  1447.  
  1448.  
  1449.      
  1450.  
  1451.      
  1452.  
  1453.       <tr valign="top">
  1454.  
  1455.         <th scope="row"><?php _e( 'Number of Posts:',  'news-ticker' ); ?></th>
  1456.  
  1457.         <td><input type="text" name="<?php echo $num_posts_opt_name; ?>" value="<?php echo $num_posts_opt_val; ?>" size="2">
  1458.  
  1459.           posts </td>
  1460.  
  1461.       </tr>
  1462.  
  1463.      
  1464.  
  1465.      
  1466.  
  1467.      
  1468.  
  1469.       <tr valign="top" class="gre">
  1470.  
  1471.         <th scope="row"><?php _e( 'Ticker Length:',  'news-ticker' ); ?></th>
  1472.  
  1473.         <td> <?php _e( 'When an excerpt is not set for a post, an excerpt is generated by News-Ticker.',  'news-ticker' ); ?><br />
  1474.  
  1475.           <?php _e( 'Enter how many characters long the auto-excerpt should be.',  'news-ticker' ); ?><br />
  1476.  
  1477.           <?php _e( 'First',  'news-ticker' ); ?>
  1478.  
  1479.           <input type="text" name="<?php echo $auto_excerpt_length_opt_name; ?>" value="<?php echo $auto_excerpt_length_opt_val; ?>" size="3">
  1480.  
  1481.           <?php _e( 'characters',  'news-ticker' ); ?> </td>
  1482.  
  1483.       </tr>
  1484.  
  1485.      
  1486.  
  1487.      
  1488.  
  1489.      
  1490.  
  1491.      
  1492.  
  1493.       <tr valign="top">
  1494.  
  1495.         <th scope="row"><?php _e( 'Ticker Speed:',  'news-ticker' ); ?></th>
  1496.  
  1497.         <td><?php _e( 'The speed of ticker transition',  'news-ticker' ); ?>.<br />
  1498.  
  1499.           <select name="<?php echo $ticker_speed_opt_name; ?>" value="<?php echo $ticker_speed_opt_val; ?>">
  1500.  
  1501.             <?php for($j="1"; $j<="10";$j++){
  1502.  
  1503.                if($j==$ticker_speed_opt_val){
  1504.  
  1505.          echo "<option value='$j' selected='selected'>$j</option>";
  1506.  
  1507.            }else{
  1508.  
  1509.          echo "<option value='$j'>$j</option>";
  1510.  
  1511.            }
  1512.  
  1513.        }?>
  1514.  
  1515.           </select> <?php _e( '(Seconds)',  'news-ticker' ); ?></td>
  1516.  
  1517.       </tr>
  1518.  
  1519.      
  1520.  
  1521.      
  1522.  
  1523.      
  1524.  
  1525.       <tr valign="top" class="gre">
  1526.  
  1527.         <th scope="row"><?php _e( 'Ticker Timeout:',  'news-ticker' ); ?></th>
  1528.  
  1529.         <td><?php _e( 'The time between ticker transitions',  'news-ticker' ); ?>.<br />
  1530.  
  1531.           <select name="<?php echo $ticker_timeout_opt_name; ?>" value="<?php echo $ticker_timeout_opt_val; ?>">
  1532.  
  1533.             <?php for($i="1"; $i<="10";$i++){
  1534.  
  1535.                if($i==$ticker_timeout_opt_val){
  1536.  
  1537.          echo "<option value='$i' selected='selected'>$i</option>";
  1538.  
  1539.            }else{
  1540.  
  1541.          echo "<option value='$i'>$i</option>";
  1542.  
  1543.            }
  1544.  
  1545.        }?>
  1546.  
  1547.           </select> <?php _e( '(Seconds)',  'news-ticker' ); ?></td>
  1548.  
  1549.       </tr>
  1550.  
  1551.      
  1552.  
  1553.      
  1554.  
  1555.      
  1556.  
  1557.       <tr valign="top">
  1558.  
  1559.         <th scope="row"><?php _e( 'Ticker Animation:',  'news-ticker' ); ?></th>
  1560.  
  1561.         <td> <?php _e( 'Select the ticker animation',  'news-ticker' ); ?>.<br />
  1562.  
  1563.           <select name="<?php echo $ticker_anim_opt_name; ?>" value="<?php echo $ticker_anim_opt_val; ?>">
  1564.  
  1565.             <option value="fade" <?php if($ticker_anim_opt_val=='fade'){echo "selected='selected'";} ?>><?php _e( 'Fade',  'news-ticker' ); ?></option>
  1566.  
  1567.             <option value="fadeZoom" <?php if($ticker_anim_opt_val=='fadeZoom'){echo "selected='selected'";} ?>><?php _e( 'Fade and Expand',  'news-ticker' ); ?></option>
  1568.  
  1569.             <option value="scrollUp" <?php if($ticker_anim_opt_val=='scrollUp'){echo "selected='selected'";} ?>><?php _e( 'Scroll up',  'news-ticker' ); ?></option>
  1570.  
  1571.             <option value="scrollDown" <?php if($ticker_anim_opt_val=='scrollDown'){echo "selected='selected'";} ?>><?php _e( 'Scroll down',  'news-ticker' ); ?></option>
  1572.  
  1573.             <option value="scrollLeft" <?php if($ticker_anim_opt_val=='scrollLeft'){echo "selected='selected'";} ?>><?php _e( 'Scroll left',  'news-ticker' ); ?></option>
  1574.  
  1575.             <option value="scrollRight" <?php if($ticker_anim_opt_val=='scrollRight'){echo "selected='selected'";} ?>><?php _e( 'Scroll right',  'news-ticker' ); ?></option>
  1576.  
  1577.           </select></td>
  1578.  
  1579.       </tr>
  1580.  
  1581.      
  1582.  
  1583.      
  1584.  
  1585.       <tr valign="top" class="gre">
  1586.  
  1587.         <th scope="row"><?php _e( 'Ticker Height:',  'news-ticker' ); ?></th>
  1588.  
  1589.         <td> <?php _e( 'Enter the ticker height in pixels. Leave empty to allow container resizing according to the <i>heighest content element</i>',  'news-ticker' ); ?><br />
  1590.  
  1591.           <input type="text" name="<?php echo $ticker_ht_opt_name; ?>" value="<?php echo $ticker_ht_opt_val; ?>" size="3">
  1592.  
  1593.           </td>
  1594.  
  1595.       </tr>
  1596.  
  1597.     </table>
  1598.  
  1599.     <hr />
  1600.  
  1601.     <p class="submit">
  1602.  
  1603.       <input type="submit" name="Submit" value="<?php _e('Update Options', 'news-ticker' ) ?>" />
  1604.  
  1605.     </p>
  1606.  
  1607.   </form>
  1608.  
  1609. </div>
  1610.  
  1611. <?php
  1612.  
  1613.  
  1614.  
  1615. }
  1616.  
  1617.  
  1618.  
  1619. function ticker_get_plugin_root() {
  1620.  
  1621.     return dirname(__FILE__).'/';
  1622.  
  1623. }
  1624.  
  1625. function ticker_get_plugin_web_root(){
  1626.  
  1627.     $site_url = get_option('siteurl');
  1628.  
  1629.  
  1630.  
  1631.     $pos = ticker_strpos_nth(3, $site_url, '/');
  1632.  
  1633.     $plugin_root = ticker_get_plugin_root();
  1634.  
  1635.     //PHP 5 only
  1636.  
  1637.     //$plugin_dir_name = substr($plugin_root, strrpos($plugin_root, '/', -2)+1); //-2 to skip the trailing '/' on $plugin_root
  1638.  
  1639.     //PHP 4 workaround
  1640.  
  1641.     $plugin_dir_name = substr($plugin_root, strrpos(substr($plugin_root, 0, strlen($plugin_root)-2), DIRECTORY_SEPARATOR)+1); //-2 to skip the trailing '/' on $plugin_root
  1642.  
  1643.     if($pos===false)
  1644.  
  1645.         $web_root = substr($site_url, strlen($site_url));
  1646.  
  1647.     else
  1648.  
  1649.         $web_root = '/' . substr($site_url, $pos);
  1650.  
  1651.     if($web_root[strlen($web_root)-1]!='/')
  1652.  
  1653.         $web_root .= '/';
  1654.  
  1655.     $web_root .= 'wp-content/plugins/' . $plugin_dir_name;
  1656.  
  1657.     return $web_root;
  1658.  
  1659. }
  1660.  
  1661.  
  1662.  
  1663. function ticker_strpos_nth($n, $haystack, $needle, $offset=0){
  1664.  
  1665.     $needle_len = strlen($needle);
  1666.  
  1667.     $hits = 0;
  1668.  
  1669.     while($hits!=$n) {
  1670.  
  1671.         $offset = strpos($haystack, $needle, $offset);
  1672.  
  1673.         if($offset===false)
  1674.  
  1675.             return false;
  1676.  
  1677.         $offset += $needle_len;
  1678.  
  1679.         $hits++;
  1680.  
  1681.     }
  1682.  
  1683.     return $offset;
  1684.  
  1685. }
  1686.  
  1687.  
  1688.  
  1689. function ticker_plugin_action_links( $links, $file ) {
  1690.  
  1691.  
  1692.  
  1693.     if ( $file == plugin_basename( __FILE__ ) ) {
  1694.  
  1695.         $igr_links = '<a href="'.get_admin_url().'options-general.php?page=tickeroptions">'.__('Settings').'</a>';
  1696.  
  1697.         array_unshift( $links, $igr_links );
  1698.  
  1699.     }
  1700.  
  1701.  
  1702.  
  1703.     return $links;
  1704.  
  1705. }
  1706.  
  1707. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement