Repository navigation
Expand file tree
/
Copy pathticker.php
More file actions
854 lines (726 loc) · 33.1 KB
/
Copy pathticker.php
File metadata and controls
854 lines (726 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<?php
/*
Plugin Name: News-Ticker
Plugin URI: http://18elements.com/tools/news-ticker-for-wordpress
Description: Inserts a fading or sliding text banner with Posts, Entries or Comments RSS feeds
Author: Daniel Sachs
Author URI: http://18elements.com/
Version: 2.1.2
*/
/*
Copyright 2009-2013 18elements.com (email: hello@18elements.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define('TICKER_VERSION', '2.1.2');
define('TICKER_MAX_INT', defined('PHP_INT_MAX') ? PHP_INT_MAX : 32767);
define('PHPREQ',5);
$phpver=phpversion();$phpmaj=$phpver[0];
if($phpmaj>=PHPREQ){
require_once('rss.php');
}
require_once('news-ticker_wpml.php');
register_activation_hook( __FILE__, 'ticker_activate' );
register_deactivation_hook( __FILE__, 'ticker_deactivate' );
add_action('switch_theme', 'ticker_activate');
add_action('admin_menu', 'ticker_add_pages');
add_action('wp_print_scripts','ticker_js');
function ticker_js(){
if(!is_admin()){
wp_enqueue_script ('jquery');
wp_enqueue_script ('ticker_pack', '/' . PLUGINDIR . '/news-ticker/cycle.js', array('jquery'));
}
}
function insert_newsticker(){
$tickerspeed=get_option('ticker_speed');
$tickertimeout=get_option('ticker_timeout');
$tickeranimation=get_option('ticker_anim');
$tickerheight=get_option('ticker_ht');
?>
<!-- START TICKER VER <?php echo TICKER_VERSION; ?> -->
<script type="text/javascript" language="javascript">
jQuery(document).ready(function(){
jQuery('#news-ticker').cycle({
speed: <?php echo $tickerspeed; ?>000,
timeout: <?php echo $tickertimeout; ?>000,
<?php if ($tickerheight == '') { ?>
height: 'auto',
<?php } else { ?>
height: <?php echo $tickerheight; ?>,
<?php } ?>
fx: '<?php echo $tickeranimation; ?>',
pause: 1,
containerResize: 1
});
});
</script>
<ul id="news-ticker" style="overflow:hidden;">
<?php ticker_content($content); // check why this line breaks wordpress after 3.4 ?>
</ul>
<!-- END TICKER -->
<?php
}
function ticker_content(){
$phpver=phpversion();$phpmaj=$phpver[0];
if($phpmaj<PHPREQ){
$postorcomment=get_option('ticker_rss');
update_option('ticker_rss','norss');
}
$site_url = get_option('siteurl');
$rss_opt_val = get_option('ticker_rss');
$images_opt_val = get_option('ticker_images');
$dates_opt_val = get_option('ticker_dates');
$content_opt_val = get_option('ticker_content');
$type_opt_val = get_option('ticker_type');
if($type_opt_val=='recent-comments' && $rss_opt_val=='norss'){
$posts = ticker_recent_comments(
get_option('ticker_num_posts'),
get_option('ticker_auto_excerpt_length')
);
}else{
switch($rss_opt_val){
case 'external':
include_once(ABSPATH.WPINC.'/rss.php');
$namenum = get_option('ext_rss');
$maxnum = get_option('ext_rss_num');
$feed = fetch_rss($namenum);
$items = array_slice($feed->items, 0, $maxnum);
break;
case 'comments':
$posts = ticker_use_rss(get_bloginfo('comments_rss2_url'));
break;
case 'entries':
$posts = ticker_use_rss(get_bloginfo('rss2_url'));
break;
case 'norss':
$posts = ticker_get_posts(
get_option('ticker_type'),
get_option('ticker_category_filter'),
get_option('ticker_num_posts'),
get_option('ticker_user_specified_posts')
);
break;
case 'norss-comments':
break;
default:
$posts = ticker_get_posts(
get_option('ticker_type'),
get_option('ticker_category_filter'),
get_option('ticker_num_posts'),
get_option('ticker_user_specified_posts')
);
break;
}
}
if ($rss_opt_val=='external') {
if (!empty($items)) :
foreach ($items as $item) : ?>
<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>
<?php endforeach;
endif;
} else {
foreach ($posts as $post_id => $post){
$title = $posts[$post_id]['post_title'];
$excerpt = $posts[$post_id]['post_excerpt'];
$link = $posts[$post_id]['url'];
$date = $posts[$post_id]['post_human_date'];
$image = $posts[$post_id]['_thumbnail_id'];
?>
<li>
<?php if($images_opt_val=='checked') { ?>
<span class="tickerImg">
<?php echo wp_get_attachment_image( $image, 'thumbnail' ); ?>
</span>
<?php } ?>
<?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 →</a></span><?php } ?></li>
<?php
}
}
}
/**
* Get an array of recent comments
* Adapted from simple_recent_comments http://www.g-loaded.eu/2006/01/15/simple-recent-comments-wordpress-plugin/
*/
function ticker_recent_comments($src_count, $src_length) {
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,
SUBSTRING(comment_content,1,$src_length) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT $src_count";
$sql = apply_filters('ticker-recent-comments',$sql);
$comments = $wpdb->get_results($sql);
foreach($comments as $comment){
$title="Comment on ".$comment->post_title." by ".$comment->comment_author;
$link =get_permalink($comment->ID);
$description=$comment->com_excerpt;
$posts[$comment->comment_ID]['post_title']=ticker_html_to_text($title);
$posts[$comment->comment_ID]['post_excerpt']=ticker_html_to_text($description);
$posts[$comment->comment_ID]['url']=$link;
}
return $posts;
}
function ticker_get_posts($type, $cat_filter, $n, $post_list=null){
switch($type){
case 'popular':
$days = get_option('ticker_popular_days');
$popular_posts = stats_get_csv('postviews', "days=$days&limit=0");
$post_list = '';
foreach ($popular_posts as $post) {
if($post_list!='')
$post_list .= ', ';
$post_list .= $post['post_id'];
}
return ticker_get_posts('userspecified', $cat_filter, $n, $post_list);
break;
case 'recent':
$posts = get_posts(
array(
'numberposts' => TICKER_MAX_INT,
'orderby' => 'post_date',
'suppress_filters' => 0,
)
);
break;
case 'commented':
$posts = get_posts(
array(
'numberposts' => TICKER_MAX_INT,
'orderby' => 'comment_count',
'suppress_filters' => 0,
)
);
break;
case 'userspecified':
$posts_tmp = get_posts(
array(
'numberposts' => TICKER_MAX_INT,
'include' => $post_list,
'suppress_filters' => 0,
)
);
$posts = array();
$post_list_arr = preg_split('/[\s,]+/', $post_list);
foreach($post_list_arr as $post_id) {
foreach($posts_tmp as $post) {
if($post->ID==$post_id) {
$posts[] = $post;
break;
}
}
}
break;
default:
$posts = null;
break;
}
$cat_filter = apply_filters('category-filter', $cat_filter);
if($cat_filter==null || sizeof($cat_filter)<1)
$do_category_filter = false;
else
$do_category_filter = true;
$posts_fixed = array();
if($posts!=null && sizeof($posts)>0 && is_object($posts[0])) {
foreach($posts as $k => $v){
if(sizeof($posts_fixed)==$n)
break;
$post_categories = wp_get_post_categories($v->ID);
if(!$do_category_filter || ($do_category_filter && sizeof(array_intersect($cat_filter, $post_categories))>0))
$posts_fixed[$v->ID] = (array) $v;
}
}
ticker_get_posts_categories($posts_fixed);
ticker_get_posts_tags($posts_fixed);
ticker_get_posts_meta($posts_fixed);
ticker_get_posts_tweak($posts_fixed);
return $posts_fixed;
}
function ticker_get_posts_categories(&$posts) {
foreach ($posts as $post_id => $post) {
$cats = wp_get_post_categories($post_id);
$categories = '';
$cat_num = 1;
foreach ($cats as $cat_id) {
$cat = get_category($cat_id);
if($categories!='')
$categories .= ', ';
$categories .= $cat->name;
$posts[$post_id]["category_$cat_num"] = $cat->name;
$cat_num++;
}
$posts[$post_id]['categories'] = $categories;
}
}
function ticker_get_posts_tags(&$posts) {
foreach ($posts as $post_id => $post) {
$tags = get_the_tags($post_id);
$tags_str = '';
if($tags!=null && sizeof($tags)>0) {
$tag_num = 1;
foreach ($tags as $tag) {
if($tags_str!='')
$tags_str .= ', ';
$tags_str .= $tag->name;
$posts[$post_id]["tag_$tag_num"] = $tag->name;
$tag_num++;
}
}
$posts[$post_id]['tags'] = $tags_str;
}
}
function ticker_get_posts_meta(&$posts) {
foreach ($posts as $post_id => $post) {
$custom_fields = get_post_custom($post_id);
foreach ($custom_fields as $k => $v) {
$posts[$post_id][$k] = $v[0];
}
}
}
function ticker_get_posts_tweak(&$posts) {
$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');
foreach ($posts as $post_id => $post) {
$date_str = $post['post_date'];
$date = ticker_parse_date($date_str);
$posts[$post_id]['post_human_date'] = ticker_date_to_human_date($date);
$posts[$post_id]['post_long_human_date'] = ticker_date_to_long_human_date($date);
$posts[$post_id]['post_slashed_date'] = ticker_date_to_slashed_date($date);
$posts[$post_id]['post_dotted_date'] = ticker_date_to_dotted_date($date);
$posts[$post_id]['post_human_time'] = ticker_date_to_human_time($date);
$posts[$post_id]['post_long_human_time'] = ticker_date_to_long_human_time($date);
$posts[$post_id]['post_military_time'] = ticker_date_to_military_time($date);
foreach($date_chars as $dc)
$posts[$post_id]["post_date_$dc"] = date($dc, $date);
$date_str = $post['post_modified'];
$date = ticker_parse_date($date_str);
$posts[$post_id]['post_modified_human_date'] = ticker_date_to_human_date($date);
$posts[$post_id]['post_modified_long_human_date'] = ticker_date_to_long_human_date($date);
$posts[$post_id]['post_modified_slashed_date'] = ticker_date_to_slashed_date($date);
$posts[$post_id]['post_modified_dotted_date'] = ticker_date_to_dotted_date($date);
$posts[$post_id]['post_modified_human_time'] = ticker_date_to_human_time($date);
$posts[$post_id]['post_modified_long_human_time'] = ticker_date_to_long_human_time($date);
$posts[$post_id]['post_modified_military_time'] = ticker_date_to_military_time($date);
foreach($date_chars as $dc)
$posts[$post_id]["post_modified_date_$dc"] = date($dc, $date);
$posts[$post_id]['post_content'] = $post['post_content'];
if(function_exists('do_shortcode'))
$posts[$post_id]['post_content'] = do_shortcode($posts[$post_id]['post_content']);
$posts[$post_id]['post_content'] =
ticker_html_to_text(
str_replace("\xC2\xA0", '',
$posts[$post_id]['post_content']
)
);
if($posts[$post_id]['post_excerpt']==null || $posts[$post_id]['post_excerpt']=='') {
$auto_excerpt_chars = get_option('ticker_auto_excerpt_length');
$s = $posts[$post_id]['post_content'];
$s = substr($s, 0, $auto_excerpt_chars);
$s = substr($s, 0, strrpos($s, ' '));
$posts[$post_id]['post_excerpt'] = $s;
}
else {
$posts[$post_id]['post_excerpt'] = ticker_html_to_text($posts[$post_id]['post_excerpt']);
}
$posts[$post_id]['nickname'] = get_usermeta($post['post_author'], 'nickname');
$posts[$post_id]['url'] = apply_filters('the_permalink', get_permalink($post_id));
}
}
function ticker_html_to_text($html) {
$html = preg_replace('/<style[^>]*>.*?<\/style[^>]*>/si','',$html);
$html = preg_replace('/<script[^>]*>.*?<\/script[^>]*>/si','',$html);
$tags = array (
0 => '/<(\/)?h[123][^>]*>/si',
1 => '/<(\/)?h[456][^>]*>/si',
2 => '/<(\/)?table[^>]*>/si',
3 => '/<(\/)?tr[^>]*>/si',
4 => '/<(\/)?li[^>]*>/si',
5 => '/<(\/)?br[^>]*>/si',
6 => '/<(\/)?p[^>]*>/si',
7 => '/<(\/)?div[^>]*>/si',
);
$html = preg_replace($tags, "\n", $html);
$html = preg_replace('/<[^>]+>/s', '', $html);
$html = preg_replace('/\ /', ' ', $html);
$html = preg_replace('/ +/s', ' ', $html);
$html = preg_replace('/^\s+/m', '', $html);
$html = preg_replace('/\s+$/m', '', $html);
$html = preg_replace('/\n+/s', '-!Line Break123!-', $html);
$html = preg_replace('/(-!Line Break123!-)+/s', ' - ', $html);
$html = preg_replace('/ +/s', ' ', $html);
$html = preg_replace('/^\s+/m', '', $html);
$html = preg_replace('/\s+$/m', '', $html);
return $html;
}
function ticker_date_to_human_date($date) {
return date_i18n('F j, Y', $date);
}
function ticker_date_to_long_human_date($date) {
return date_i18n('l jS \of F Y', $date);
}
function ticker_date_to_slashed_date($date) {
return date_i18n('m/d/y', $date);
}
function ticker_date_to_dotted_date($date) {
return date_i18n('m.d.y', $date);
}
function ticker_date_to_human_time($date) {
return date_i18n('g:i a', $date);
}
function ticker_date_to_long_human_time($date) {
return date_i18n('g:i:s a', $date);
}
function ticker_date_to_military_time($date) {
return date_i18n('H:i:s', $date);
}
function ticker_parse_date($string) {
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);
return mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
}
function ticker_activate()
{
ticker_set_default_options();
}
function ticker_deactivate()
{
//echo('Deactivating News-Ticker');
//ticker_delete_options();
}
function ticker_set_default_options() {
if(get_option('ticker_images')===false) add_option('ticker_images', '');
if(get_option('ticker_dates')===false) add_option('ticker_dates', '');
if(get_option('ticker_content')===false) add_option('ticker_content', '');
if(get_option('ticker_type')===false) add_option('ticker_type', 'commented');
if(get_option('ticker_category_filter')===false) add_option('ticker_category_filter', array());
if(get_option('ticker_user_specified_posts')===false) add_option('ticker_user_specified_posts', '');
if(get_option('ticker_num_posts')===false) add_option('ticker_num_posts', 5);
if(get_option('ticker_popular_days')===false) add_option('ticker_popular_days', 90);
if(get_option('ticker_auto_excerpt_length')===false) add_option('ticker_auto_excerpt_length', 110);
if(get_option('ticker_admin_messages_to_show_once')===false) add_option('ticker_admin_messages_to_show_once', array());
if(get_option('ticker_rss')===false) add_option('ticker_rss', 'norss');
if(get_option('ext_rss')===false) add_option('ext_rss', '');
if(get_option('ext_rss_num')===false) add_option('ext_rss_num', '');
if(get_option('ticker_speed')===false) add_option('ticker_speed', 1);
if(get_option('ticker_timeout')===false) add_option('ticker_timeout', 2);
if(get_option('ticker_anim')===false) add_option('ticker_anim', 'fade');
if(get_option('ticker_ht')===false) add_option('ticker_ht', 20);
}
function ticker_delete_options() {
delete_option('ticker_images');
delete_option('ticker_dates');
delete_option('ticker_content');
delete_option('ticker_type');
delete_option('ticker_category_filter');
delete_option('ticker_user_specified_posts');
delete_option('ticker_num_posts');
delete_option('ticker_popular_days');
delete_option('ticker_auto_excerpt_length');
delete_option('ticker_admin_messages_to_show_once');
delete_option('ticker_rss');
delete_option('ext_rss');
delete_option('ext_rss_num');
delete_option('ticker_speed');
delete_option('ticker_timeout');
delete_option('ticker_anim');
delete_option('ticker_ht');
}
function ticker_add_pages() {
add_options_page('News Ticker', 'News Ticker', 8, 'tickeroptions', 'ticker_options_page');
}
function ticker_options_page() {
$hidden_field_name = 'ticker_submit_hidden';
$images_opt_name = 'ticker_images';
$dates_opt_name = 'ticker_dates';
$content_opt_name = 'ticker_content';
$type_opt_name = 'ticker_type';
$category_filter_opt_name = 'ticker_category_filter';
$user_specified_posts_opt_name = 'ticker_user_specified_posts';
$num_posts_opt_name = 'ticker_num_posts';
$popular_days_opt_name = 'ticker_popular_days';
$auto_excerpt_length_opt_name = 'ticker_auto_excerpt_length';
$rss_opt_name = 'ticker_rss';
$ext_rss_name = 'ext_rss';
$ext_rss_num_name = 'ext_rss_num';
$ticker_speed_opt_name = 'ticker_speed';
$ticker_timeout_opt_name = 'ticker_timeout';
$ticker_anim_opt_name = 'ticker_anim';
$ticker_ht_opt_name = 'ticker_ht';
$images_opt_val = get_option($images_opt_name);
$dates_opt_val = get_option($dates_opt_name);
$content_opt_val = get_option($content_opt_name);
$type_opt_val = get_option($type_opt_name);
$category_filter_val = get_option($category_filter_opt_name);
$user_specified_posts_opt_val = get_option($user_specified_posts_opt_name);
$num_posts_opt_val = get_option($num_posts_opt_name);
$popular_days_opt_val = get_option($popular_days_opt_name);
$auto_excerpt_length_opt_val = get_option($auto_excerpt_length_opt_name);
$rss_opt_val = get_option($rss_opt_name);
$ext_rss_val = get_option($ext_rss_name);
$ext_rss_num_val = get_option($ext_rss_num_name);
$ticker_speed_opt_val = get_option($ticker_speed_opt_name);
$ticker_timeout_opt_val = get_option($ticker_timeout_opt_name);
$ticker_anim_opt_val = get_option($ticker_anim_opt_name);
$ticker_ht_opt_val = get_option($ticker_ht_opt_name);
if( $_POST[ $hidden_field_name ] == 'Y' ) {
$images_opt_val = $_POST[$images_opt_name];
$dates_opt_val = $_POST[$dates_opt_name];
$content_opt_val = $_POST[$content_opt_name];
$type_opt_val = $_POST[$type_opt_name];
$category_filter_val = $_POST[$category_filter_opt_name];
$user_specified_posts_opt_val = $_POST[$user_specified_posts_opt_name];
$frequency_opt_val = $_POST[$frequency_opt_name];
if($_POST[$frequency_opt_name]==null || $_POST[$frequency_opt_name]=='' || $_POST[$frequency_opt_name]<1)
$frequency_opt_val = 10;
$num_posts_opt_val = $_POST[$num_posts_opt_name];
$popular_days_opt_val = $_POST[$popular_days_opt_name];
$auto_excerpt_length_opt_val = $_POST[$auto_excerpt_length_opt_name];
$rss_opt_val = $_POST[$rss_opt_name];
$ext_rss_val = $_POST[$ext_rss_name];
$ext_rss_num_val = $_POST[$ext_rss_num_name];
$ticker_speed_opt_val = $_POST[$ticker_speed_opt_name];
$ticker_timeout_opt_val = $_POST[$ticker_timeout_opt_name];
$ticker_anim_opt_val = $_POST[$ticker_anim_opt_name];
$ticker_ht_opt_val = $_POST[$ticker_ht_opt_name];
if($type_opt_val=='popular' && !function_exists('stats_get_csv')) {
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>";
$type_opt_val = 'commented';
}
update_option($images_opt_name, $images_opt_val);
update_option($dates_opt_name, $dates_opt_val);
update_option($content_opt_name, $content_opt_val);
update_option($type_opt_name, $type_opt_val);
update_option($category_filter_opt_name, $category_filter_val);
update_option($user_specified_posts_opt_name, $user_specified_posts_opt_val);
update_option($num_posts_opt_name, $num_posts_opt_val);
update_option($popular_days_opt_name, $popular_days_opt_val);
update_option($auto_excerpt_length_opt_name, $auto_excerpt_length_opt_val);
update_option($rss_opt_name, $rss_opt_val);
update_option($ext_rss_name, $ext_rss_val);
update_option($ext_rss_num_name, $ext_rss_num_val);
update_option($ticker_speed_opt_name, $ticker_speed_opt_val);
update_option($ticker_timeout_opt_name, $ticker_timeout_opt_val);
update_option($ticker_anim_opt_name, $ticker_anim_opt_val);
update_option($ticker_ht_opt_name, $ticker_ht_opt_val);
echo '<div class="updated"><p><strong>Options saved.</strong></p></div>';
}
$stats_installed_str = function_exists('stats_get_csv')?'<font color="#00cc00">is installed</font>':'<font color="#ff0000">is not installed</font>';
$plugin_directory = ticker_get_plugin_root();
?>
<div class="wrap">
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".external-extra").hide("fast");
$(".ruler").click(function(){
if($(this).val()==="norss") $(".post-extra").show("fast"); else $(".post-extra").hide("fast");
});
$(".ruler").click(function(){
if($(this).val()==="external") $(".external-extra").show("fast"); else $(".external-extra").hide("fast");
});
});
</script>
<style>
tr.gre {
background:#f9f9f9;
}
</style>
<div class="icon32" id="icon-options-general"><br></div>
<h2><?php _e( 'News Ticker Options', 'news-ticker' ); ?></h2>
<p></p>
<hr />
<form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
<table class="form-table">
<tr class="header" valign="top"><th scope="row"><h3><?php _e( 'Content Setup', 'news-ticker' ); ?></h3></th></tr>
<tr class="gre" valign="top">
<th scope="row"><?php _e( 'Content Source', 'news-ticker' ); ?></th>
<td>
<?php $phpver=phpversion();$phpmaj=$phpver[0];
if($phpmaj<PHPREQ){ ?>
<?php _e( 'Use of these options currently requires php version ', 'news-ticker' ); ?><?php echo PHPREQ; ?>.
<?php _e( 'Your current version is ', 'news-ticker' ); ?><?php echo $phpver;?>.<br /></td>
<?php
} else {
?>
<input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='norss' <?php if($rss_opt_val=='norss'){echo 'checked';} ?> > <?php _e( '
Blog Posts', 'news-ticker' ); ?><br/>
<input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='entries' <?php if($rss_opt_val=='entries'){echo 'checked';} ?>>
<?php _e( 'Local Entries RSS feed', 'news-ticker' ); ?> <br/>
<input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='comments' <?php if($rss_opt_val=='comments'){echo 'checked';} ?>>
<?php _e( 'Local Comments RSS feed', 'news-ticker' ); ?><br/>
<input class="ruler" type="radio" name="<?php echo $rss_opt_name; ?>" value='external' <?php if($rss_opt_val=='external'){echo 'checked';} ?>>
<?php _e( 'External RSS feed', 'news-ticker' ); ?><br/>
<div class="external-extra">
<?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/>
<?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" />
</div>
</td>
<?php } ?>
</tr>
<tr valign="top" class="post-extra">
<th scope="row"><?php _e( 'Category Filter:', 'news-ticker' ); ?></th>
<td> <?php _e( 'Select the categories to include. Select one or more categories to restrict post selection to those categories.', 'news-ticker' ); ?><br />
<?php _e( 'If no category is selected, all categories are included (Multiple selection)', 'news-ticker' ); ?><br />
<select style="height: auto;" name="<?php echo $category_filter_opt_name; ?>[]" multiple="multiple">
<?php
$categories = get_categories(array('hide_empty' => false));
if($categories!=null) {
foreach ($categories as $cat) {
if(in_array($cat->cat_ID, $category_filter_val))
$selected = 'selected="selected"';
else
$selected = '';
$option = '<option value="'.$cat->cat_ID.'" '.$selected.'>';
$option .= $cat->cat_name;
$option .= ' ('.$cat->category_count.')';
$option .= '</option>';
echo $option;
}
}
?>
</select></td>
</tr>
<tr valign="top" class="post-extra gre">
<th scope="row"><?php _e( 'Post Selection:', 'news-ticker' ); ?></th>
<td><input type="radio" name="<?php echo $type_opt_name; ?>" value='popular' <?php if($type_opt_val=='popular') { echo 'checked'; } ?>>
<?php _e( 'Most Popular Posts over the last', 'news-ticker' ); ?>
<input type="text" name="<?php echo $popular_days_opt_name; ?>" value="<?php echo $popular_days_opt_val; ?>" size="2">
<?php _e( 'days', 'news-ticker' ); ?> (<a href='http://wordpress.org/extend/plugins/stats/'>Wordpress.com Stats Plugin</a> <?php echo $stats_installed_str; ?>)<br/>
<input type="radio" name="<?php echo $type_opt_name; ?>" value='commented' <?php if($type_opt_val=='commented') { echo 'checked'; } ?>>
<?php _e( 'Most Commented Posts', 'news-ticker' ); ?><br/>
<input type="radio" name="<?php echo $type_opt_name; ?>" value='recent' <?php if($type_opt_val=='recent') { echo 'checked'; } ?>>
<?php _e( 'Recent Posts', 'news-ticker' ); ?><br/>
<input type="radio" name="<?php echo $type_opt_name; ?>" value='recent-comments' <?php if($type_opt_val=='recent-comments') { echo 'checked'; } ?>>
<?php _e( 'Recent Comments', 'news-ticker' ); ?><br/>
<input type="radio" name="<?php echo $type_opt_name; ?>" value='userspecified' <?php if($type_opt_val=='userspecified') { echo 'checked'; } ?>>
<?php _e( 'Specific Posts:', 'news-ticker' ); ?>
<input type="text" name="<?php echo $user_specified_posts_opt_name; ?>" value="<?php echo $user_specified_posts_opt_val; ?>" size="20">
(comma separated, for example: "1, 2, 43, 17")<br/></td>
</tr>
<tr class="header" valign="top"><th scope="row"><h3><?php _e( 'Ticker Setup', 'news-ticker' ); ?></h3></th></tr>
<tr valign="top" class="post-extra gre">
<th scope="row"><?php _e( 'News Ticker Contents', 'news-ticker' ); ?></th>
<td>
<?php _e( 'The title of the post is displayed by default. Add more elements', 'news-ticker' ); ?><br />
<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'; } ?>>
<?php _e( 'Show Images', 'news-ticker' ); ?><br/>
<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'; } ?>>
<?php _e( 'Show Dates', 'news-ticker' ); ?><br/>
<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'; } ?>>
<?php _e( 'Show Excerpts', 'news-ticker' ); ?><br/>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Number of Posts:', 'news-ticker' ); ?></th>
<td><input type="text" name="<?php echo $num_posts_opt_name; ?>" value="<?php echo $num_posts_opt_val; ?>" size="2">
posts </td>
</tr>
<tr valign="top" class="gre">
<th scope="row"><?php _e( 'Ticker Length:', 'news-ticker' ); ?></th>
<td> <?php _e( 'When an excerpt is not set for a post, an excerpt is generated by News-Ticker.', 'news-ticker' ); ?><br />
<?php _e( 'Enter how many characters long the auto-excerpt should be.', 'news-ticker' ); ?><br />
<?php _e( 'First', 'news-ticker' ); ?>
<input type="text" name="<?php echo $auto_excerpt_length_opt_name; ?>" value="<?php echo $auto_excerpt_length_opt_val; ?>" size="3">
<?php _e( 'characters', 'news-ticker' ); ?> </td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Ticker Speed:', 'news-ticker' ); ?></th>
<td><?php _e( 'The speed of ticker transition', 'news-ticker' ); ?>.<br />
<select name="<?php echo $ticker_speed_opt_name; ?>" value="<?php echo $ticker_speed_opt_val; ?>">
<?php for($j="1"; $j<="10";$j++){
if($j==$ticker_speed_opt_val){
echo "<option value='$j' selected='selected'>$j</option>";
}else{
echo "<option value='$j'>$j</option>";
}
}?>
</select> <?php _e( '(Seconds)', 'news-ticker' ); ?></td>
</tr>
<tr valign="top" class="gre">
<th scope="row"><?php _e( 'Ticker Timeout:', 'news-ticker' ); ?></th>
<td><?php _e( 'The time between ticker transitions', 'news-ticker' ); ?>.<br />
<select name="<?php echo $ticker_timeout_opt_name; ?>" value="<?php echo $ticker_timeout_opt_val; ?>">
<?php for($i="1"; $i<="10";$i++){
if($i==$ticker_timeout_opt_val){
echo "<option value='$i' selected='selected'>$i</option>";
}else{
echo "<option value='$i'>$i</option>";
}
}?>
</select> <?php _e( '(Seconds)', 'news-ticker' ); ?></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Ticker Animation:', 'news-ticker' ); ?></th>
<td> <?php _e( 'Select the ticker animation', 'news-ticker' ); ?>.<br />
<select name="<?php echo $ticker_anim_opt_name; ?>" value="<?php echo $ticker_anim_opt_val; ?>">
<option value="fade" <?php if($ticker_anim_opt_val=='fade'){echo "selected='selected'";} ?>><?php _e( 'Fade', 'news-ticker' ); ?></option>
<option value="fadeZoom" <?php if($ticker_anim_opt_val=='fadeZoom'){echo "selected='selected'";} ?>><?php _e( 'Fade and Expand', 'news-ticker' ); ?></option>
<option value="scrollUp" <?php if($ticker_anim_opt_val=='scrollUp'){echo "selected='selected'";} ?>><?php _e( 'Scroll up', 'news-ticker' ); ?></option>
<option value="scrollDown" <?php if($ticker_anim_opt_val=='scrollDown'){echo "selected='selected'";} ?>><?php _e( 'Scroll down', 'news-ticker' ); ?></option>
<option value="scrollLeft" <?php if($ticker_anim_opt_val=='scrollLeft'){echo "selected='selected'";} ?>><?php _e( 'Scroll left', 'news-ticker' ); ?></option>
<option value="scrollRight" <?php if($ticker_anim_opt_val=='scrollRight'){echo "selected='selected'";} ?>><?php _e( 'Scroll right', 'news-ticker' ); ?></option>
</select></td>
</tr>
<tr valign="top" class="gre">
<th scope="row"><?php _e( 'Ticker Height:', 'news-ticker' ); ?></th>
<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 />
<input type="text" name="<?php echo $ticker_ht_opt_name; ?>" value="<?php echo $ticker_ht_opt_val; ?>" size="3">
</td>
</tr>
</table>
<hr />
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update Options', 'news-ticker' ) ?>" />
</p>
</form>
</div>
<?php
}
function ticker_get_plugin_root() {
return dirname(__FILE__).'/';
}
function ticker_get_plugin_web_root(){
$site_url = get_option('siteurl');
$pos = ticker_strpos_nth(3, $site_url, '/');
$plugin_root = ticker_get_plugin_root();
//PHP 5 only
//$plugin_dir_name = substr($plugin_root, strrpos($plugin_root, '/', -2)+1); //-2 to skip the trailing '/' on $plugin_root
//PHP 4 workaround
$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
if($pos===false)
$web_root = substr($site_url, strlen($site_url));
else
$web_root = '/' . substr($site_url, $pos);
if($web_root[strlen($web_root)-1]!='/')
$web_root .= '/';
$web_root .= 'wp-content/plugins/' . $plugin_dir_name;
return $web_root;
}
function ticker_strpos_nth($n, $haystack, $needle, $offset=0){
$needle_len = strlen($needle);
$hits = 0;
while($hits!=$n) {
$offset = strpos($haystack, $needle, $offset);
if($offset===false)
return false;
$offset += $needle_len;
$hits++;
}
return $offset;
}
function ticker_plugin_action_links( $links, $file ) {
if ( $file == plugin_basename( __FILE__ ) ) {
$igr_links = '<a href="'.get_admin_url().'options-general.php?page=tickeroptions">'.__('Settings').'</a>';
array_unshift( $links, $igr_links );
}
return $links;
}
?>