source: trunk/www.guidonia.net/wp/wp-content/plugins/lexi/lexi.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 22.5 KB
Line 
1<?php
2/*
3Plugin Name: Lexi
4Plugin URI: http://www.sebaxtian.com/acerca-de/lexi
5Description: An RSS feeder using ajax to show contents after the page has been loaded.
6Version: 0.7.95
7Author: Juan Sebastián Echeverry
8Author URI: http://www.sebaxtian.com
9*/
10
11/* Copyright 2007-2009 Juan Sebastián Echeverry (email : sebaxtian@gawab.com)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26*/
27
28define('CONF_CACHE', 1);
29define('CONF_SHOWCONTENT', 2);
30define('CONF_SHOWHEADER', 4);
31define('CONF_TARGETBLANK', 8);
32
33$db_version=get_option('lexi_db_version');
34
35add_action('init', 'lexi_addbuttons');
36add_action('init', 'lexi_textdomain');
37add_action('wp_head', 'lexi_header');
38add_filter('the_content', 'lexi_content');
39add_action('admin_menu', 'lexi_manage');
40add_action('activate_lexi/lexi.php', 'lexi_activate');
41
42/**
43 * Function to use i18n
44 *
45 * @access public
46 */
47
48function lexi_textdomain() {
49 load_plugin_textdomain('lexi', 'wp-content/plugins/lexi/lang');
50}
51
52/**
53 * Function to add Lexi's css
54 *
55 * @access public
56 */
57
58function lexi_header() {
59 $css = lexi_plugin_url("/css/lexi.css");
60 echo "\n<link rel='stylesheet' href='$css' type='text/css' media='screen' />";
61}
62
63
64/**
65 * Returns plugin's path.
66 *
67 * @param string str Path to append
68 * @return string
69 * @access public
70 */
71
72function lexi_plugin_url($str = '')
73{
74 $dir_name = '/wp-content/plugins/lexi';
75 $url=get_bloginfo('wpurl');
76 return $url . $dir_name . $str;
77}
78
79
80/**
81 * Function to create the database and to add options into WordPress
82 *
83 * @access public
84 */
85
86function lexi_activate()
87{
88 global $wpdb;
89 global $db_version;
90
91 $table_name = $wpdb->prefix . "lexi";
92 if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
93 $sql = "CREATE TABLE $table_name(
94 id bigint(1) NOT NULL AUTO_INCREMENT,
95 name tinytext NOT NULL,
96 position int,
97 rss text NOT NULL,
98 items int NOT NULL,
99 showcontent tinyint NOT NULL,
100 cached tinyint NOT NULL,
101 PRIMARY KEY (id)
102 );";
103
104 require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
105 dbDelta($sql);
106 add_option('lexi_db_version', 1);
107 }
108}
109
110
111/**
112 * Function to edit feed's data.
113 *
114 * @param int id Feed's id
115 * @param string name Feed's name
116 * @param string rss Feed's URL
117 * @param int items Items to show
118 * @param bool showcontent Show contents in Widget?
119 * @param bool cache Record Rss content in cache?
120 * @access public
121 */
122
123function lexi_editfeed($id, $name, $rss, $items=5, $showcontent=false, $cached=true)
124{
125 global $wpdb;
126
127 if($showcontent) {
128 $showcontent=1;
129 } else {
130 $showcontent=0;
131 }
132
133 if($cached) {
134 $cached=1;
135 } else {
136 $cached=0;
137 }
138
139 $table_name = $wpdb->prefix . "lexi";
140 $query="UPDATE " . $table_name ." SET name='".$name."', rss='".$rss."', items='".$items."', showcontent='".$showcontent."', cached='".$cached."' WHERE id=".$id;
141 $wpdb->query($query);
142}
143
144
145/**
146 * Function to add a feed.
147 *
148 * @param string name Feed's name
149 * @param string rss Feed's URL
150 * @param int items Items to show
151 * @param bool showcontent Show contents in Widget?
152 * @param bool cache Record Rss content in cache?
153 * @return bool
154 * @access public
155 */
156
157function lexi_addfeed($name, $rss, $items=5, $showcontent=false, $cached=true)
158{
159 global $wpdb;
160
161 if($showcontent) {
162 $showcontent=1;
163 } else {
164 $showcontent=0;
165 }
166
167 if($cached) {
168 $cached=1;
169 } else {
170 $cached=0;
171 }
172
173 $table_name = $wpdb->prefix . "lexi";
174 $insert = "INSERT INTO " . $table_name .
175 " (name, rss, items, showcontent, cached) " .
176 "VALUES ('" . $wpdb->escape($name) . "', '" . $wpdb->escape($rss) . "', '$items', '$showcontent', '$cached')";
177
178 $results = $wpdb->query( $insert );
179
180 $id = $wpdb->get_var("select last_insert_id()");
181 $position = $wpdb->get_var("SELECT MAX(position) FROM $table_name");
182 $position++;
183
184 $wpdb->query("UPDATE " . $table_name ." SET position='$position' WHERE id=".$id);
185
186 return true;
187}
188
189
190/**
191 * Function to delete a feed.
192 *
193 * @param int id Feed to delete
194 * @return bool
195 * @access public
196 */
197
198function lexi_deletefeed($id)
199{
200 global $wpdb;
201 $table_name = $wpdb->prefix . "lexi";
202 $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id");
203 $query = "DELETE FROM " . $table_name ." WHERE id=" . $id;
204 $answer1=$wpdb->query( $query );
205
206 $wpdb->query("UPDATE " . $table_name ." SET position=position-1 WHERE position > $position");
207
208 return $answer1;
209}
210
211
212/**
213 * Move feed one row up
214 *
215 * @param int id Feed to move
216 * @return bool
217 * @access public
218 */
219
220function lexi_upfeed($id)
221{
222 global $wpdb;
223 $table_name = $wpdb->prefix . "lexi";
224 $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id");
225 if($position>1) {
226 $position_aux=$position-1;
227 $answer1 = $wpdb->query("UPDATE " . $table_name ." SET position = $position WHERE position = $position_aux");
228 $answer2 = $wpdb->query("UPDATE " . $table_name ." SET position = $position_aux WHERE id = $id");
229 }
230 return $answer1 && $answer2;
231}
232
233
234/**
235 * Move feed one row down
236 *
237 * @param int id Feed to move
238 * @return bool
239 * @access public
240 */
241
242function lexi_downfeed($id)
243{
244 global $wpdb;
245 $table_name = $wpdb->prefix . "lexi";
246 $position = $wpdb->get_var("SELECT position FROM $table_name WHERE id=$id");
247 $max_position = $wpdb->get_var("SELECT MAX(position) FROM $table_name");
248 if($position<$max_position) {
249 $position_aux=$position+1;
250 $answer1 = $wpdb->query("UPDATE " . $table_name ." SET position = $position WHERE position = $position_aux");
251 $answer2 = $wpdb->query("UPDATE " . $table_name ." SET position = $position_aux WHERE id = $id");
252 }
253 return $answer1 && $answer2;
254}
255
256
257/**
258 * Returns the html code with 'minimax' script and div.
259 * Add this code into the html page to create the RSS reader.
260 *
261 * @param string link The RSS URL
262 * @param string title The title to put at the beginning of the list
263 * @param string items Max number of feeds to show
264 * @param string sc Show feed contents?
265 * @param string cache Save feeds in cache?
266 * @return string
267 * @access public
268 */
269
270function lexi_postRss($link, $title, $items, $conf) {
271 $answer="";
272 if(function_exists('minimax') && minimax_version()==0.2) {
273 $num = mt_rand();
274 $url=lexi_plugin_url('/content.php');
275 if($sc) $sc=1; else $sc=0;
276 if($cache) $cache=1; else $cache=0;
277 $post="url=".urlencode(str_replace("&amp;", "&", $link))."&amp;title=".urlencode(str_replace("&amp;", "&", $title))."&amp;num=$items&amp;conf=$conf";
278 $answer.="\n<div id='lexi$num'><table><tr><td><img class='lexi' src='".get_bloginfo('wpurl')."/wp-content/plugins/lexi/img/loading.gif' alt='RSS' border='0' /></td><td>".__('Loading Feed...','lexi')."</td></tr></table></div><script type='text/javascript'>mx_lexi$num = new minimax('$url', 'lexi$num');
279 mx_lexi$num.post('$post');
280 </script>";
281 } else {
282 $answer.= "<div id='lexi'><label>";
283 $answer.= sprintf(__('You have to install <a href="%s" target="_BLANK">minimax 0.2</a> in order for this plugin to work', 'lexi'), "http://wordpress.org/extend/plugins/minimax/" );
284 $answer.= "</label></div>";
285 }
286 return $answer;
287}
288
289
290/**
291 * Returns the html code with 'minimax' script and div.
292 * Add this code into the html page to create the RSS reader.
293 *
294 * @param int id The feed Id into lexi list.
295 * @return string
296 * @access public
297 */
298
299function lexi_postId($id) {
300 global $wpdb;
301
302 $show_feed_title = true;
303
304 if($id==-1) {
305 $options = get_option('widget_lexi');
306 $show_feed_title = $options['show_feed_title'];
307 $id=0;
308 }
309
310 $answer="";
311
312 $table_name = $wpdb->prefix . "lexi";
313 if($id)
314 $feedlist = $wpdb->get_results("SELECT * FROM $table_name WHERE id = $id");
315 else
316 $feedlist = $wpdb->get_results("SELECT * FROM $table_name ORDER BY position ASC");
317
318 // These lines generate our output. Widgets can be very complex
319 // but as you can see here, they can also be very, very simple.
320
321 if(function_exists('minimax') && minimax_version()==0.2) {
322 foreach($feedlist as $feed) {
323
324 //Configuration
325 $conf = CONF_TARGETBLANK;
326 if($feed->showcontent) $conf += CONF_SHOWCONTENT;
327 if($feed->cached) $conf += CONF_CACHE;
328 if($show_feed_title) $conf += CONF_SHOWHEADER;
329
330 if(!$id || $id==$feed->id) {
331 $answer.= lexi_postRss($feed->rss,$feed->name,$feed->items,$conf);
332 }
333 }
334 } else {
335 $answer.= "<div id='lexi'><label>";
336 $answer.= sprintf(__('You have to install <a href="%s" target="_BLANK">minimax 0.2</a> in order for this plugin to work', 'lexi'), "http://wordpress.org/extend/plugins/minimax/" );
337 $answer.= "</label></div>";
338 }
339 return $answer;
340}
341
342
343/**
344 * Filter to manage contents. Check for [lexi] tags.
345 *
346 * @access public
347 */
348function lexi_content($content)
349{
350 //Lexi
351 $search = "@(?:<p>)*\s*\[lexi\s*(:\s*\d+)?\]\s*(?:</p>)*@i";
352 if (preg_match_all($search, $content, $matches))
353 {
354 if (is_array($matches))
355 {
356 foreach ($matches[1] as $key =>$v0)
357 {
358 $v1=$matches[1][$key];
359 $id=false;
360 if($v1) {
361 $v1=substr($v1,1);
362 $id=$v1*1;
363 }
364
365 $search = $matches[0][$key];
366 $replace=lexi_postId($id);
367 $content = str_replace ($search, $replace, $content);
368 }
369 }
370 }
371
372 //RSS
373 $search = "@(?:<p>)*\s*\[lexi\s*:([^,]+),(\d+),(true|false),(true|false)?\]\s*(?:</p>)*@i";
374 if (preg_match_all($search, $content, $matches))
375 {
376 if (is_array($matches))
377 {
378 foreach ($matches[1] as $key =>$rss)
379 {
380 $items=$matches[2][$key];
381 $sc=$matches[3][$key];
382 if($sc=='true') $sc=1; else $sc=0;
383 $cache=$matches[4][$key];
384 if($cache=='true') $cache=1; else $cache=0;
385
386 $conf = CONF_SHOWHEADER + CONF_TARGETBLANK;
387 if($sc) $conf += CONF_SHOWCONTENT;
388 if($cache) $conf += CONF_CACHE;
389
390 $search = $matches[0][$key];
391 $replace=lexi_postRss($rss,"",$items,$conf);
392 $content = str_replace ($search, $replace, $content);
393 }
394 }
395 }
396
397 //Lexi 2 w/ title
398 $search = "@(?:<p>)*\s*\[lexi\s*:(\d+),([^,]+),([^,]+),(\d+)?\]\s*(?:</p>)*@i";
399 if (preg_match_all($search, $content, $matches))
400 {
401 if (is_array($matches))
402 {
403 foreach ($matches[1] as $key =>$conf)
404 {
405 $rss=$matches[2][$key];
406 $title=$matches[3][$key];
407 $items=$matches[4][$key];
408
409 $search = $matches[0][$key];
410 $replace=lexi_postRss($rss, $title, $items, $conf);
411 $content = str_replace ($search, $replace, $content);
412 }
413 }
414 }
415
416 //Lexi 2 w/out title
417 $search = "@(?:<p>)*\s*\[lexi\s*:(\d+),([^,]+),(\d+)?\]\s*(?:</p>)*@i";
418 if (preg_match_all($search, $content, $matches))
419 {
420 if (is_array($matches))
421 {
422 foreach ($matches[1] as $key =>$conf)
423 {
424 $url=$matches[2][$key];
425 $items=$matches[3][$key];
426
427 $search = $matches[0][$key];
428 $replace=lexi_postRss($rss, "", $items, $conf);
429 $content = str_replace ($search, $replace, $content);
430 }
431 }
432 }
433
434 return $content;
435}
436
437
438/**
439 * Function to be called in templates. Returns the html code
440 * with 'minimax' script and div. Add this function into the html
441 * page to create the RSS reader.
442 * If the id is numeric, the function returns the code for the
443 * corresponding feed in the lexi list, and forget the other
444 * parameters. If its a string, the function would use it as the URL,
445 * and would use the other parameters.
446 * If you call the function without parameters, it returns the code
447 * for the entire lexi list.
448 *
449 * @param string id Would be the URL or the lexi id. See function description.
450 * @param string num Max number of feeds to show
451 * @param string sc Show feed contents?
452 * @param string cached Save feeds in cache?
453 * @access public
454 */
455 function lexi($id=0, $num=0, $sc=false, $cached=false, $sh=true) {
456 if(is_numeric($id)) {
457 echo lexi_postId($id);
458 } else {
459 echo lexi_postRss($id, "", $num, $sc, $cached, $sh);
460 }
461 }
462
463/**
464 * Function to be called in templates. Returns the html code
465 * with 'minimax' script and div. Add this function into the html
466 * page to create the RSS reader.
467 * If the id is numeric, the function returns the code for the
468 * corresponding feed in the lexi list, and forget the other
469 * parameters. If its a string, the function would use it as the URL,
470 * and would use the other parameters.
471 * If you call the function without parameters, it returns the code
472 * for the entire lexi list.
473 *
474 * @param string id Would be the URL or the lexi id. See function description.
475 * @param string num Max number of feeds to show
476 * @param string sc Show feed contents?
477 * @param string cached Save feeds in cache?
478 * @access public
479 */
480 function lexiRSS($conf, $rss, $title, $max_items) {
481 if(!$title) $title="";
482 echo lexi_postRss($rss, $title, $max_items, $conf);
483 }
484
485
486/**
487 * Returns the HTML list for an RSS feed.
488 *
489 * @param string link The URL of the rss.
490 * @param string name Name to be shown at the top of the list. If empty would use
491 * the name in the rss.
492 * @param string num Max number of feeds to show.
493 * @param string sc Show feed contents?
494 * @param string cached Save feeds in cache?
495 * @return string
496 * @access public
497 */
498function lexi_readfeed($link, $name, $num, $config) {
499 include_once(ABSPATH . WPINC . '/rss.php');
500 @include_once(ABSPATH . WPINC . '/class-simplepie.php');
501
502 $name=str_replace("\\\"","\"",$name);
503
504 if(($config & CONF_TARGETBLANK)) {
505 $target = " target='_blank'";
506 }
507
508 if(class_exists('SimplePie')) {
509 $rss = new SimplePie($link);
510
511 if(!($config & CONF_CACHE)) {
512 $rss->enable_cache(false);
513 $rss->init();
514 }
515
516 $channel_link = $rss->get_permalink();
517 if($name=="") {
518 $name=htmlspecialchars($rss->get_title());
519 }
520
521 $items = $rss->get_items(0, $num);
522
523 if($items) {
524 foreach ($items as $item) {
525 $answer.="<li><a class='rsswidget' href='".htmlspecialchars($item->get_permalink())."'".$target.">".$item->get_title()."</a>";
526 if($config & CONF_SHOWCONTENT) $answer.="<br/>".$item->get_content();
527 $answer.="</li>";
528 }
529 }
530
531 } else {
532 $aux_cached = MAGPIE_CACHE_ON;
533 if(!($config & CONF_CACHE)) {
534 define('MAGPIE_CACHE_ON', 0);
535 }
536 $rss = fetch_rss($link);
537 define('MAGPIE_CACHE_ON', $aux_cached);
538 $channel_link=htmlspecialchars($rss->channel['link']);
539 if($name=="") {
540 $name=htmlspecialchars($rss->channel['title']);
541 }
542
543 if($rss->items) {
544 foreach (array_slice($rss->items, 0, $num) as $item) {
545 $answer.="<li><a class='rsswidget' href='".htmlspecialchars($item['link'])."'".$target.">".$item['title']."</a>";
546 if($config & CONF_SHOWCONTENT) $answer.="<br/>".$item['atom_content'].$item['summary'];
547 $answer.="</li>";
548 }
549 }
550 }
551
552 $header="";
553 if($config & CONF_SHOWHEADER) {
554 $header = "<h2 class='widgettitle'><a class='rsswidget' href='$link' title='" . __('Subscribe' , 'lexi')."'><img class='lexi' src='".get_bloginfo('wpurl')."/wp-includes/images/rss.png' alt='RSS' border='0' /></a> <a class='rsswidget' href='$channel_link' title='$name'>$name</a></h2>";
555 }
556 return "$header<ul>$answer</ul>";
557}
558
559
560/**
561 * Enable menu to manage Feeds.
562 *
563 * @access public
564 */
565
566function lexi_manage()
567{
568 add_management_page('Lexi', 'Lexi', 10, 'leximanage', 'lexi_manage_page');
569}
570
571
572/**
573 * Page to manage feeds.
574 *
575 * @access public
576 */
577
578function lexi_manage_page()
579{
580 global $wpdb;
581
582 $table_name = $wpdb->prefix . "lexi";
583 $messages=array();
584
585 if(!function_exists('minimax')) {
586 array_push($messages, sprintf(__('You have to install <a href="%s" target="_BLANK">minimax 0.2</a> in order for this plugin to work', 'lexi'), "http://wordpress.org/extend/plugins/minimax/" ));
587 }
588
589 $mode_x=$_POST['mode_x']; // Something from POST
590 $mode=$_GET['mode']; // Something from GET?
591
592 //if pressed addfeed, mode must be add feed
593 if($_POST['addfeed']) {
594 $mode='add';
595 $mode_x='done';
596 }
597
598 $doaction=false;
599 if($_POST['doaction']!="") $doaction=$_POST['action'];
600 if($_POST['doaction2']!="") $doaction=$_POST['action2'];
601 if($doaction)
602 {
603 switch($doaction)
604 {
605 case 'delete':
606 foreach($_POST['checked_feeds'] as $checked_id) {
607 lexi_deletefeed($checked_id);
608 }
609 break;
610 }
611 }
612
613 switch($mode_x) {
614 case 'manage_x':
615 $mode='done';
616 break;
617 case 'add_x':
618 $mode='done';
619 if($_POST['submit']) {
620 $name=$_POST['lexi_name'];
621 $rss=$_POST['lexi_rss'];
622 $items=$_POST['lexi_items'];
623 $showcontent=false;
624 if($_POST['lexi_showcontent']=='on') {
625 $showcontent=true;
626 }
627 $cached=false;
628 if($_POST['lexi_cached']=='on') {
629 $cached=true;
630 }
631 lexi_addfeed($name, $rss, $items, $showcontent, $cached);
632 array_push($messages, __( 'Feed added', 'lexi' ));
633 }
634 break;
635 case 'edit_x':
636 $mode='done';
637 if($_POST['submit']) {
638 $id=$_POST['lexi_id'];
639 $name=$_POST['lexi_name'];
640 $rss=$_POST['lexi_rss'];
641 $items=$_POST['lexi_items'];
642 $showcontent=false;
643 if($_POST['lexi_showcontent']=='on') {
644 $showcontent=true;
645 }
646 $cached=false;
647 if($_POST['lexi_cached']=='on') {
648 $cached=true;
649 }
650 lexi_editfeed($id, $name, $rss, $items, $showcontent, $cached);
651 array_push($messages, __( 'Feed modified', 'lexi' ));
652 }
653 break;
654 }
655
656 switch($mode) {
657 case 'add':
658 include('templates/lexi_feed.php');
659 break;
660 case 'edit':
661 check_admin_referer('lexi_editfeed');
662 $id=$_GET['id'];
663 $table_name = $wpdb->prefix . "lexi";
664 $data = $wpdb->get_row("select name, rss, items, showcontent, cached from $table_name where id=$id");
665 $name=$data->name;
666 $rss=$data->rss;
667 $items=$data->items;
668 $cached=$data->cached;
669 $showcontent=$data->showcontent;
670 include('templates/lexi_feed.php');
671 break;
672 case 'up':
673 check_admin_referer('lexi_upfeed');
674 $id=$_GET['id'];
675 if(lexi_upfeed($id)) {
676 array_push($messages, __("Feed moved", 'lexi'));
677 }
678 break;
679 case 'down':
680 check_admin_referer('lexi_downfeed');
681 $id=$_GET['id'];
682 if(lexi_downfeed($id)) {
683 array_push($messages, __("Feed moved", 'lexi'));
684 }
685 break;
686 case 'delete':
687 check_admin_referer('lexi_deletefeed');
688 $id=$_GET['id'];
689 if(lexi_deletefeed($id)) {
690 array_push($messages, __("Feed deleted", 'lexi'));
691 }
692 break;
693 }
694
695 if($mode!='edit' && $mode!='add')
696 {
697 // Now display the manage screen
698 include('templates/lexi_manage.php');
699 }
700}
701
702/**
703 * Enable buttons in tinymce.
704 *
705 * @access public
706 */
707
708function lexi_addbuttons() {
709 // Don't bother doing this stuff if the current user lacks permissions
710 if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;
711
712 // Add only in Rich Editor mode
713 if ( get_user_option('rich_editing') == 'true') {
714
715 // add the button for wp21 in a new way
716 add_filter('mce_external_plugins', 'add_lexi_script');
717 add_filter('mce_buttons', 'add_lexi_button');
718 }
719}
720
721
722/**
723 * Enable buttons in tinymce.
724 *
725 * @access public
726 */
727
728function add_lexi_button($buttons) {
729
730 array_push($buttons, 'Lexi');
731 return $buttons;
732
733}
734
735/**
736 * Enable buttons in tinymce.
737 *
738 * @access public
739 */
740
741function add_lexi_script($plugins) {
742 $dir_name = '/wp-content/plugins/lexi';
743 $url=get_bloginfo('wpurl');
744 $pluginURL = $url.$dir_name.'/tinymce/editor_plugin.js';
745 $plugins['Lexi'] = $pluginURL;
746 return $plugins;
747}
748
749
750/**
751 * Lexi widget stuff.
752 *
753 * @access public
754 */
755
756function lexi_widget_init() {
757
758 if ( !function_exists('register_sidebar_widget') ) {
759 return;
760 }
761
762 function lexi_widget($args) {
763
764 global $wpdb;
765
766 // $args is an array of strings that help widgets to conform to
767 // the active theme: before_widget, before_title, after_widget,
768 // and after_title are the array keys. Default tags: li and h2.
769 extract($args);
770
771 //$table_name = $wpdb->prefix . "lexi";
772 //$feedlist = $wpdb->get_results("SELECT id FROM $table_name ORDER BY position ASC");
773
774 $options = get_option('widget_lexi');
775 $title = $options['title'];
776 $show_feed_title = $options['show_feed_title'];
777
778 // These lines generate our output. Widgets can be very complex
779 // but as you can see here, they can also be very, very simple.
780 echo $before_widget;
781 if(strlen($title)>0) {
782 echo $before_title . $title . $after_title;
783 }
784 lexi(-1);
785 echo $after_widget;
786 }
787
788 // This is the function that outputs the form to let the users edit
789 // the widget's title. It's an optional feature that users cry for.
790 function lexi_widget_control() {
791
792 // Get our options and see if we're handling a form submission.
793 $options = get_option('widget_lexi');
794 if ( !is_array($options) )
795 $options = array('title'=>'', 'show_feed_title'=>1);
796 if ( $_POST['lexi-submit'] ) {
797 // Remember to sanitize and format use input appropriately.
798 $options['title'] = strip_tags(stripslashes($_POST['lexi_title']));
799 if($_POST['showfeedtitle']=='on')
800 $options['show_feed_title'] = true;
801 else
802 $options['show_feed_title'] = false;
803 update_option('widget_lexi', $options);
804 }
805
806 // Be sure you format your options to be valid HTML attributes.
807 $title = htmlspecialchars($options['title'], ENT_QUOTES);
808 $show_feed_title = $options['show_feed_title'];
809
810
811 // Here is our little form segment. Notice that we don't need a
812 // complete form. This will be embedded into the existing form.
813 require('templates/lexi_widget.php');
814 }
815
816 // This registers our widget so it appears with the other available
817 // widgets and can be dragged and dropped into any active sidebars.
818 register_sidebar_widget(array('Lexi RSS Widget', 'widgets'), 'lexi_widget');
819
820 // This registers our optional widget control form. Because of this
821 // our widget will have a button that reveals a 300x100 pixel form.
822 register_widget_control(array('Lexi RSS Widget', 'widgets'), 'lexi_widget_control');
823
824}
825
826// Run our code later in case this loads prior to any required plugins.
827add_action('widgets_init', 'lexi_widget_init');
828
829?>
Note: See TracBrowser for help on using the repository browser.