Ejemplo n.º 1
0
 /**
  * Respond to call to $theme->linkoid() in template
  *
  * @param string $return The return value to the template function (passed through other potential plugin calls)
  * @param Theme $theme The theme object
  * @param string $tag An optional tag to use instead of the one defined in the plugin options.
  * @return string The return value to the template function
  */
 public function theme_linkoid($theme, $tag = null)
 {
     if (!isset($tag)) {
         $tag = Options::get('linkoid__show');
     }
     $linkoids = Posts::get(array('tag_slug' => $tag, 'limit' => Options::get('linkoid__count')));
     $theme->linkoids = $linkoids;
     return $theme->fetch('linkoid');
 }
 public function filter_plugin_loader($existing_loader, Theme $theme)
 {
     $infos = array();
     foreach ($this->get_repos() as $repo) {
         $infos = array_merge($infos, $this->scrape_repo($repo));
     }
     //Utils::debug($theme->inactive_plugins);
     $plugins = array();
     $id = 0;
     foreach ($infos as $key => $info) {
         $xinfo = reset($info);
         $id = sprintf('%x', crc32($key));
         $plugins[$id] = array('plugind_id' => $id, 'file' => '', 'debug' => false, 'info' => new SimpleXMLElement($xinfo), 'active' => false, 'verb' => 'Download');
         foreach ($info as $version => $xinfo) {
             $plugins[$id]['actions'][$version] = array('url' => URL::get('admin', 'page=plugin_download&plugin_id=' . $id . '&version=' . $version), 'caption' => _t('Get %s', array($version)), 'action' => 'download-');
         }
     }
     $theme->loadable = $plugins;
     $loader = $theme->fetch('plugins.loader');
     return $existing_loader . $loader;
 }
Ejemplo n.º 3
0
 /**
  * Assigns output code to the template variables
  * @param Theme $theme The theme that will display the template
  */
 function theme_colophon($theme)
 {
     $theme->colophon_text = Format::autop(Options::get('colophon__text'));
     $theme->colophon_title = Options::get('colophon__title');
     return $theme->fetch('colophon');
 }
Ejemplo n.º 4
0
 /**
  * Add last Twitter status, time, and image to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_twitter($theme)
 {
     $notices = array();
     if (Options::get('twitter__show') && Options::get('twitter__username') != '') {
         $twitter_url = 'http://twitter.com/statuses/user_timeline/' . urlencode(Options::get('twitter__username')) . '.xml';
         // We only need to get a single tweet if we're hiding replies (otherwise we can rely on the maximum returned and hope there's a non-reply)
         if (!Options::get('twitter__hide_replies') && Options::get('twitter__limit')) {
             $twitter_url .= '?count=' . Options::get('twitter__limit');
         }
         if (Cache::has('twitter_notices')) {
             $notices = Cache::get('twitter_notices');
         } else {
             try {
                 $r = new RemoteRequest($twitter_url);
                 $r->set_timeout(10);
                 $r->execute();
                 $response = $r->get_response_body();
                 $xml = @new SimpleXMLElement($response);
                 // Check we've got a load of statuses returned
                 if ($xml->getName() === 'statuses') {
                     foreach ($xml->status as $status) {
                         if (!Options::get('twitter__hide_replies') || strpos($status->text, '@') === false) {
                             $notice = (object) array('text' => (string) $status->text, 'time' => (string) $status->created_at, 'image_url' => (string) $status->user->profile_image_url);
                             $notices[] = $notice;
                             if (Options::get('twitter__hide_replies') && count($notices) >= Options::get('twitter__limit')) {
                                 break;
                             }
                         } else {
                             // it's a @. Keep going.
                         }
                     }
                     if (!$notices) {
                         $notice = (object) array('text' => 'No non-replies replies available from Twitter.', 'time' => '', 'image_url' => '');
                     }
                 } else {
                     if ($xml->getName() === 'error') {
                         $notice = (object) array('text' => (string) $xml, 'time' => '', 'image_url' => '');
                     } else {
                         $notice = (object) array('text' => 'Received unexpected XML from Twitter.', 'time' => '', 'image_url' => '');
                     }
                 }
             } catch (Exception $e) {
                 $notice = (object) array('text' => 'Unable to contact Twitter.', 'time' => '', 'image_url' => '');
             }
             if (!$notices) {
                 $notices[] = $notice;
             }
             // Cache (even errors) to avoid hitting rate limit.
             Cache::set('twitter_notices', $notices, Options::get('twitter__cache'), true);
         }
     } else {
         $notice = (object) array('text' => _t('Please set your username in the <a href="%s">Twitter plugin config</a>', array(URL::get('admin', 'page=plugins&configure=' . $this->plugin_id . '&configaction=Configure') . '#plugin_' . $this->plugin_id), 'twitter'), 'time' => '', 'image_url' => '');
         $notices[] = $notice;
     }
     if (Options::get('twitter__linkify_urls') != FALSE) {
         foreach ($notices as $notice) {
             /* link to all http: */
             $notice->text = preg_replace('%https?://\\S+?(?=(?:[.:?"!$&\'()*+,=]|)(?:\\s|$))%i', "<a href=\"\$0\">\$0</a>", $notice->text);
             /* link to usernames */
             $notice->text = preg_replace("/(?<!\\w)@([\\w-_.]{1,64})/", "@<a href=\"http://twitter.com/\$1\">\$1</a>", $notice->text);
             /* link to hashtags */
             $notice->text = preg_replace('/(?<!\\w)#((?>\\d{1,64}|)[\\w-.]{1,64})/', "<a href=\"" . Options::get('twitter__hashtags_query') . "\$1\">#\$1</a>", $notice->text);
         }
     }
     $theme->tweets = $notices;
     return $theme->fetch('tweets');
 }
 /**
  * Add simplified tag array to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_tag_links($theme, $sortorder = 'term_display asc')
 {
     $theme->tag_links = Tags::vocabulary()->get_tree($sortorder);
     return $theme->fetch('simpletaglist');
 }
Ejemplo n.º 6
0
 /**
  * Add Flickr images to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_flickrfeed($theme, $params = array())
 {
     $params = array_merge($this->config, $params);
     if ($this->plugin_configured($params)) {
         $theme->flickrfeed = $this->load_feeds($params);
     } else {
         $theme->flickrfeed = _t('FlickrFeed Plugin is not configured properly.', $this->class_name);
     }
     return $theme->fetch('flickrfeed');
 }
 /**
  * Theme function for displaying similar posts to the post passed in. By default
  * will display a list of post titles that are considered similar to the post in
  * question. Note that the post needs to be found in the search index, so this 
  * will only work on published items. The easiest way with unpublished would be to 
  * index then delete the post.
  * 
  * Called from a theme like <code><?php $theme->similar_posts($post); ?></code>
  * Uses search_similar template.
  *
  * @param Theme $theme 
  * @param Post $post 
  * @param int $max_recommended 
  */
 public function theme_similar_posts($theme, $post, $max_recommended = 5)
 {
     if (!$this->_enabled) {
         return;
     }
     if ($this->_enabled && $post instanceof Post && intval($post->id) > 0) {
         $ids = $this->_backend->get_similar_posts($post, $max_recommended);
         $theme->similar = count($ids) > 0 ? Posts::get(array('id' => $ids)) : array();
         $theme->base_post = $post;
         return $theme->fetch('searchsimilar');
     }
 }
Ejemplo n.º 8
0
 /**
  * Provide the content for the System Status dashboard module
  *
  * @param array $module the module data
  * @param string $id the id of the module
  * @param Theme $theme an associated theme for outputting a template
  * @return array An array of module data
  */
 public static function filter_dash_module_status($module, $id, $theme)
 {
     $theme->status_data = self::$status_data;
     $module['content'] = $theme->fetch('dash_status');
     return $module;
 }
Ejemplo n.º 9
0
 /**
  * $theme->show_tweetbacks();
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_show_tweetbacks($theme, $params = array())
 {
     return $theme->fetch('tweetbacks');
 }
Ejemplo n.º 10
0
 /**
  * Add last Jaiku status, time, and image to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_jaiku($theme, $params = array())
 {
     $params = array_merge($this->config, $params);
     $cache_name = $this->class_name . '__' . md5(serialize($params));
     if ($params['username'] != '') {
         if (Cache::has($cache_name)) {
             $theme->presences = Cache::get($cache_name);
         } else {
             if ($params['limit'] == 1) {
                 $url = 'http://' . $params['username'] . '.jaiku.com/presence/last/json';
             } else {
                 $url = 'http://' . $params['username'] . '.jaiku.com/feed/json';
             }
             try {
                 // Get JSON content via Jaiku API
                 $call = new RemoteRequest($url);
                 $call->set_timeout(5);
                 $result = $call->execute();
                 if (Error::is_error($result)) {
                     throw Error::raise(_t('Unable to contact Jaiku.', $this->class_name));
                 }
                 $response = $call->get_response_body();
                 // Decode JSON
                 $obj = json_decode($response);
                 if (!$obj instanceof stdClass) {
                     // Response is not JSON
                     throw Error::raise(_t('Response is not correct, maybe Jaiku server is down or API is changed.', $this->class_name));
                 }
                 $serial = property_exists($obj, 'stream') ? serialize($obj->stream) : serialize($obj);
                 // Convert stdClass to JaikuPresence and JaikuUser
                 $serial = str_replace('s:4:"user";O:8:"stdClass":', 's:4:"user";O:9:"JaikuUser":'******'O:8:"stdClass":', 'O:13:"JaikuPresence":', $serial);
                 $presences = unserialize($serial);
                 // Pass $presences to $theme
                 if (is_array($presences)) {
                     $theme->presences = array_slice($presences, 0, $params['limit']);
                 } else {
                     $theme->presences = array($presences);
                 }
                 // Do cache
                 Cache::set($cache_name, $theme->presences, $params['cache']);
             } catch (Exception $e) {
                 $theme->presences = $e->getMessage();
             }
         }
     } else {
         $theme->presences = _t('Please set your username in the Jaiku plugin config.', $this->class_name);
     }
     return $theme->fetch('jaiku');
 }
Ejemplo n.º 11
0
 /**
  * Add last Twitter status, time, and image to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_twitter($theme)
 {
     $twitter = Options::get_group('twitter');
     $theme->tweets = $this->tweets($twitter['username'], $twitter['hide_replies'], $twitter['limit'], $twitter['cache'], $twitter['linkify_urls'], $twitter['hashtags_query']);
     return $theme->fetch('tweets');
 }
 /**
  * Add last Audioscrobbler status, time, and image to the available template vars
  * @param Theme $theme The theme that will display the template
  **/
 public function theme_audioscrobbler($theme, $params = array())
 {
     $params = array_merge($this->config, $params);
     $cache_name = $this->class_name . '__' . md5(serialize($params));
     if ($params['username'] != '') {
         $track_url = 'http://ws.audioscrobbler.com/1.0/user/' . urlencode($params['username']) . '/recenttracks.xml';
         if (Cache::has($cache_name)) {
             $xml = new SimpleXMLElement(Cache::get($cache_name));
             $theme->track = $xml->track;
         } else {
             try {
                 // Get XML content via Audioscrobbler API
                 $call = new RemoteRequest($track_url);
                 $call->set_timeout(5);
                 $result = $call->execute();
                 if (Error::is_error($result)) {
                     throw Error::raise(_t('Unable to contact Last.fm.', $this->class_name));
                 }
                 $response = $call->get_response_body();
                 // Parse XML content
                 $xml = new SimpleXMLElement($response);
                 $theme->track = $xml->track;
                 Cache::set($cache_name, $response, $params['cache']);
             } catch (Exception $e) {
                 $theme->track = $e->getMessage();
             }
         }
     } else {
         $theme->track = _t('Please set your username in the Audioscrobbler plugin config.', $this->class_name);
     }
     return $theme->fetch('audioscrobbler');
 }