예제 #1
0
 /**
  * Makes a widget which you can put in your sidebar.
  * The widget displays the 5 most recent entries in the source's feed.
  **/
 static function create_widget()
 {
     $data = '';
     $data = '<?php';
     foreach (SourceAdmin::collect() as $widget) {
         if (SourceAdmin::feed_check($widget->title) == 1) {
             $title = $widget->title;
             $t_title = str_replace(' ', '', $title);
             $cleaned = strtolower($title);
             $cleaned = preg_replace('/\\W/', ' ', $cleaned);
             $cleaned = str_replace(" ", "", $cleaned);
             $data .= "\r\n                function {$t_title}Init() {\r\n                    include_once( TEMPLATEPATH . '/widgets/{$cleaned}.php');\r\n                    register_widget('{$t_title}FeedWidget');\r\n                }";
             add_option($cleaned . '-num', 5);
             SourceAdmin::create_file($title, $cleaned, explode('/', $widget->profile_url), $widget->feed_url);
         }
     }
     $data .= ' ?>';
     file_put_contents(TEMPLATEPATH . '/widgets/sources.php', $data);
 }