Пример #1
0
 /**
  * Add additional template variables to the template output.
  *
  *  You can assign additional output values in the template here, instead of
  *  having the PHP execute directly in the template.  The advantage is that
  *  you would easily be able to switch between template types (RawPHP/Smarty)
  *  without having to port code from one to the other.
  *
  *  You could use this area to provide "recent comments" data to the template,
  *  for instance.
  *
  *  Note that the variables added here should possibly *always* be added,
  *  especially 'user'.
  *
  *  Also, this function gets executed *after* regular data is assigned to the
  *  template.  So the values here, unless checked, will overwrite any existing
  *  values.
  */
 public function add_template_vars()
 {
     if (!$this->template_engine->assigned('pages')) {
         $this->assign('pages', Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1)));
     }
     if (!$this->template_engine->assigned('user')) {
         $this->assign('user', User::identify());
     }
     if (!$this->template_engine->assigned('tags')) {
         $this->assign('tags', Tags::get());
     }
     if (!$this->template_engine->assigned('page')) {
         $this->assign('page', isset($page) ? $page : 1);
     }
     if (!$this->template_engine->assigned('feed_alternate')) {
         $matched_rule = URL::get_matched_rule();
         switch ($matched_rule->name) {
             case 'display_entry':
             case 'display_page':
                 $feed_alternate = URL::get('atom_entry', array('slug' => Controller::get_var('slug')));
                 break;
             case 'display_entries_by_tag':
                 $feed_alternate = URL::get('atom_feed_tag', array('tag' => Controller::get_var('tag')));
                 break;
             case 'display_home':
             default:
                 $feed_alternate = URL::get('atom_feed', array('index' => '1'));
         }
         $this->assign('feed_alternate', $feed_alternate);
     }
     // Specify pages you want in your navigation here
     $this->assign('nav_pages', Posts::get(array('content_type' => 'page', 'status' => 'published', 'nolimit' => 1)));
     parent::add_template_vars();
 }
Пример #2
0
 /**
  * Output the page title.
  */
 public function out_title()
 {
     switch (URL::get_matched_rule()->name) {
         case 'display_entry':
         case 'display_page':
             $title = $this->post->title;
             break;
         case 'display_entries_by_tag':
             $title = $this->tag;
             break;
         case 'display_entries_by_date':
             $args = URL::get_matched_rule()->named_arg_values;
             if (isset($args['day'])) {
                 $title = date('d : F : Y', mktime(0, 0, 0, $args['month'], $args['day'], $args['year']));
             } elseif (isset($args['month'])) {
                 $title = date('F : Y', mktime(0, 0, 0, $args['month'], 1, $args['year']));
             } else {
                 $title = date('Y', mktime(0, 0, 0, 1, 1, $args['year']));
             }
             break;
         default:
             $title = NULL;
     }
     if (!empty($title)) {
         $title .= ' :';
     }
     echo $title;
 }
Пример #3
0
 /**
  * All handlers must implement act() to conform to handler API.
  * This is the default implementation of act(), which attempts
  * to call a class member method of $this->act_$action().  Any
  * subclass is welcome to override this default implementation.
  *
  * @param string $action the action that was in the URL rule
  */
 public function act($action)
 {
     if (null === $this->handler_vars) {
         $this->handler_vars = new SuperGlobal(array());
     }
     $this->action = $action;
     $this->theme->assign('matched_rule', URL::get_matched_rule());
     $request = new StdClass();
     foreach (URL::get_active_rules() as $rule) {
         $request->{$rule->name} = false;
     }
     $request->{$this->theme->matched_rule->name} = true;
     $this->theme->assign('request', $request);
     $action_hook = 'plugin_act_' . $action;
     $before_action_hook = 'before_' . $action_hook;
     $theme_hook = 'route_' . $action;
     $after_action_hook = 'after_' . $action_hook;
     Plugins::act($before_action_hook, $this);
     Plugins::act($action_hook, $this);
     if (Plugins::implemented($theme_hook, 'theme')) {
         $theme = Themes::create();
         $rule = URL::get_matched_rule();
         Plugins::theme($theme_hook, $theme, $rule->named_arg_values, $this);
     }
     Plugins::act($after_action_hook);
 }
 public function filter_template_where_filters($where_filters)
 {
     if (Options::get('customquery__' . URL::get_matched_rule()->name)) {
         $where_filters['limit'] = Options::get('customquery__' . URL::get_matched_rule()->name);
     }
     return $where_filters;
 }
 public function embed_gists($content)
 {
     $gists_regex = '/<script[^>]+src="(http:\\/\\/gist.github.com\\/[^"]+)"[^>]*><\\/script>/i';
     // remove gists from multiple-post templates
     if (Options::get('gistextras__removefrommultiple')) {
         if (!in_array(URL::get_matched_rule()->name, array('display_entry', 'display_page'))) {
             return preg_replace($gists_regex, '', $content);
         }
     }
     preg_match_all($gists_regex, $content, $gists);
     for ($i = 0, $n = count($gists[0]); $i < $n; $i++) {
         if (Options::get('gistextras__cachegists')) {
             if (Cache::has($gists[1][$i])) {
                 $gist = Cache::get($gists[1][$i]);
             } else {
                 if ($gist = RemoteRequest::get_contents($gists[1][$i])) {
                     $gist = $this->process_gist($gist);
                     Cache::set($gists[1][$i], $gist, 86400);
                     // cache for 1 day
                 }
             }
         } else {
             $gist = RemoteRequest::get_contents($gists[1][$i]);
             $gist = $this->process_gist($gist);
         }
         // replace the script tag
         $content = str_replace($gists[0][$i], $gist, $content);
     }
     return $content;
 }
Пример #6
0
    function theme_footer()
    {
        if (URL::get_matched_rule()->entire_match == 'user/login') {
            // Login page; don't dipslay
            return;
        }
        if (User::identify()->loggedin) {
            // Only track the logged in user if we were told to
            if (Options::get('getclicky__loggedin')) {
                return;
            }
        }
        $siteid = Options::get('getclicky__siteid');
        $sitedb = Options::get('getclicky__sitedb');
        echo <<<ENDAD
<a title="Clicky Web Analytics" href="http://getclicky.com/{$siteid}">
  <img alt="Clicky Web Analytics" src="http://static.getclicky.com/media/links/badge.gif" border="0" />
</a>
<script src="http://static.getclicky.com/{$siteid}.js" type="text/javascript"></script>
<noscript>
  <p>
    <img alt="Clicky" src="http://static.getclicky.com/{$siteid}-{$sitedb}.gif" />
  </p>
</noscript>
ENDAD;
    }
Пример #7
0
    public function theme_footer()
    {
        if (URL::get_matched_rule()->entire_match == 'user/login') {
            // Login page; don't display
            return;
        }
        $clientcode = Options::get('googleanalytics__clientcode');
        // get the url for the main Google Analytics code
        if (Options::get('googleanalytics__cache')) {
            $ga_url = Site::get_url('habari') . '/ga.js';
        } else {
            $ga_url = self::detect_ssl() ? 'https://ssl.google-analytics.com/ga.js' : 'http://www.google-analytics.com/ga.js';
        }
        // only actually track the page if we're not logged in, or we're told to always track
        $do_tracking = !User::identify()->loggedin || Options::get('googleanalytics__loggedintoo');
        $ga_extra_url = $do_tracking ? '<script src="' . Site::get_url('habari') . '/gaextra.js' . '" type="text/javascript"></script>' : '';
        $track_page = $do_tracking ? 'pageTracker._trackPageview();' : '';
        echo <<<ANALYTICS
{$ga_extra_url}
<script src="{$ga_url}" type="text/javascript"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--
try {var pageTracker = _gat._getTracker("{$clientcode}");{$track_page}} catch(e) {}
//--><!]]>
</script>
ANALYTICS;
    }
Пример #8
0
 /**
  * Add additional template variables to the template output.
  * 	 
  *  You can assign additional output values in the template here, instead of 
  *  having the PHP execute directly in the template.  The advantage is that 
  *  you would easily be able to switch between template types (RawPHP/Smarty)
  *  without having to port code from one to the other.
  *  
  *  You could use this area to provide "recent comments" data to the template,
  *  for instance.	  	 	 
  *  
  *  Note that the variables added here should possibly *always* be added, 
  *  especially 'user'.
  * 	 
  *  Also, this function gets executed *after* regular data is assigned to the
  *  template.  So the values here, unless checked, will overwrite any existing 
  *  values.	 	 	 
  */
 public function add_template_vars()
 {
     $this->add_template('formcontrol_text', dirname(__FILE__) . '/forms/formcontrol_text.php', true);
     $this->add_template('formcontrol_textarea', dirname(__FILE__) . '/forms/formcontrol_textarea.php', true);
     if (!$this->template_engine->assigned('pages')) {
         $this->assign('pages', Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1)));
     }
     if (!$this->template_engine->assigned('user')) {
         $this->assign('user', User::identify());
     }
     if (!$this->template_engine->assigned('page')) {
         $this->assign('page', isset($page) ? $page : 1);
     }
     if (!$this->template_engine->assigned('feed_alternate')) {
         $matched_rule = URL::get_matched_rule();
         switch ($matched_rule->name) {
             case 'display_entry':
             case 'display_page':
                 $feed_alternate = URL::get('entry', array('slug' => Controller::get_var('slug')));
                 break;
             case 'display_entries_by_tag':
                 $feed_alternate = URL::get('tag_collection', array('tag' => Controller::get_var('tag')));
                 break;
             case 'index_page':
             default:
                 $feed_alternate = URL::get('collection', array('index' => '1'));
         }
         $this->assign('feed_alternate', $feed_alternate);
     }
     parent::add_template_vars();
 }
Пример #9
0
 public function body_class()
 {
     $classes = array();
     foreach (get_object_vars($this->request) as $key => $value) {
         if ($value) {
             $classes[$key] = $key;
         }
     }
     $classes[] = URL::get_matched_rule()->entire_match;
     $classes = array_unique(array_merge($classes, Stack::get_named_stack('body_class')));
     $classes = Plugins::filter('body_class', $classes, $this);
     echo implode(' ', $classes);
 }
Пример #10
0
	/**
	 * Verifies user credentials before creating the theme and displaying the request.
	 */
	public function __construct()
	{
		$user = User::identify();
		if ( !$user->loggedin ) {
			Session::add_to_set( 'login', $_SERVER['REQUEST_URI'], 'original' );
			if ( URL::get_matched_rule()->action == 'admin_ajax' && isset( $_SERVER['HTTP_REFERER'] ) ) {
				 $ar = new AjaxResponse(408, _t('Your session has ended, please log in and try again.') );
				 $ar->out();
			}
			else {
				$post_raw = $_POST->get_array_copy_raw();
				if ( !empty( $post_raw ) ) {
					Session::add_to_set( 'last_form_data', $post_raw, 'post' );
					Session::error( _t( 'We saved the last form you posted. Log back in to continue its submission.' ), 'expired_form_submission' );
				}
				$get_raw = $_GET->get_array_copy_raw();
				if ( !empty( $get_raw ) ) {
					Session::add_to_set( 'last_form_data', $get_raw, 'get' );
					Session::error( _t( 'We saved the last form you posted. Log back in to continue its submission.' ), 'expired_form_submission' );
				}
				Utils::redirect( URL::get( 'auth', array( 'page' => 'login' ) ) );
			}
			exit;
		}

		$last_form_data = Session::get_set( 'last_form_data' ); // This was saved in the "if ( !$user )" above, UserHandler transferred it properly.
		/* At this point, Controller has not created handler_vars, so we have to modify $_POST/$_GET. */
		if ( isset( $last_form_data['post'] ) ) {
			$_POST = $_POST->merge( $last_form_data['post'] );
			$_SERVER['REQUEST_METHOD'] = 'POST'; // This will trigger the proper act_admin switches.
			Session::remove_error( 'expired_form_submission' );
		}
		if ( isset( $last_form_data['get'] ) ) {
			$_GET = $_GET->merge( $last_form_data['get'] );
			Session::remove_error( 'expired_form_submission' );
			// No need to change REQUEST_METHOD since GET is the default.
		}
		$user->remember();

		// Create an instance of the active public theme so that its plugin functions are implemented
		$this->active_theme = Themes::create();

		// setup the stacks for javascript in the admin - it's a method so a plugin can call it externally
		self::setup_stacks();
		
		// on every page load check the plugins currently loaded against the list we last checked for updates and trigger a cron if we need to
		Update::check_plugins();
	}
Пример #11
0
 /**
  * When the AtomHandler is created, check what action called it
  * If the action is set in our URL list, intercept and redirect to Feedburner
  */
 public function action_init_atom()
 {
     $action = Controller::get_action();
     $feed_uri = Options::get('feedburner__' . $action);
     $exclude_ips = Options::get('feedburner__exlude_ips');
     $exclude_agents = Options::get('feedburner__exclude_agents');
     if ($feed_uri != '' && (!isset(URL::get_matched_rule()->named_arg_values['index']) || URL::get_matched_rule()->named_arg_values['index'] == 1)) {
         if (!in_array($_SERVER['REMOTE_ADDR'], (array) $exclude_ips)) {
             if (isset($_SERVER['HTTP_USER_AGENT']) && !in_array($_SERVER['HTTP_USER_AGENT'], (array) $exclude_agents)) {
                 ob_clean();
                 header('Location: http://feedproxy.google.com/' . $feed_uri, TRUE, 302);
                 die;
             }
         }
     }
 }
Пример #12
0
 /**
  * Verifies user credentials before creating the theme and displaying the request.
  */
 public function __construct()
 {
     $user = User::identify();
     if (!$user->loggedin) {
         Session::add_to_set('login', $_SERVER['REQUEST_URI'], 'original');
         if (URL::get_matched_rule()->name == 'admin_ajax' && isset($_SERVER['HTTP_REFERER'])) {
             header('Content-Type: text/javascript;charset=utf-8');
             echo '{callback: function(){location.href="' . $_SERVER['HTTP_REFERER'] . '"} }';
         } else {
             $post_raw = $_POST->get_array_copy_raw();
             if (!empty($post_raw)) {
                 Session::add_to_set('last_form_data', $post_raw, 'post');
                 Session::error(_t('We saved the last form you posted. Log back in to continue its submission.'), 'expired_form_submission');
             }
             $get_raw = $_GET->get_array_copy_raw();
             if (!empty($get_raw)) {
                 Session::add_to_set('last_form_data', $get_raw, 'get');
                 Session::error(_t('We saved the last form you posted. Log back in to continue its submission.'), 'expired_form_submission');
             }
             Utils::redirect(URL::get('auth', array('page' => 'login')));
         }
         exit;
     }
     $last_form_data = Session::get_set('last_form_data');
     // This was saved in the "if ( !$user )" above, UserHandler transferred it properly.
     /* At this point, Controller has not created handler_vars, so we have to modify $_POST/$_GET. */
     if (isset($last_form_data['post'])) {
         $_POST = $_POST->merge($last_form_data['post']);
         $_SERVER['REQUEST_METHOD'] = 'POST';
         // This will trigger the proper act_admin switches.
         Session::remove_error('expired_form_submission');
     }
     if (isset($last_form_data['get'])) {
         $_GET = $_GET->merge($last_form_data['get']);
         Session::remove_error('expired_form_submission');
         // No need to change REQUEST_METHOD since GET is the default.
     }
     $user->remember();
     // Create an instance of the active public theme so that its plugin functions are implemented
     $this->active_theme = Themes::create();
     // setup the stacks for javascript in the admin - it's a method so a plugin can call it externally
     self::setup_stacks();
 }
Пример #13
0
 /**
  * All handlers must implement act() to conform to handler API.
  * This is the default implementation of act(), which attempts
  * to call a class member method of $this->act_$action().  Any
  * subclass is welcome to override this default implementation.
  *
  * @param string $action the action that was in the URL rule
  */
 public function act($action)
 {
     if (null === $this->handler_vars) {
         $this->handler_vars = new SuperGlobal(array());
     }
     $this->action = $action;
     $this->theme->assign('matched_rule', URL::get_matched_rule());
     $request = new StdClass();
     foreach (RewriteRules::get_active() as $rule) {
         $request->{$rule->name} = false;
     }
     $request->{$this->theme->matched_rule->name} = true;
     $this->theme->assign('request', $request);
     $action_hook = 'plugin_act_' . $action;
     $before_action_hook = 'before_' . $action_hook;
     $after_action_hook = 'after_' . $action_hook;
     Plugins::act($before_action_hook, $this);
     Plugins::act($action_hook, $this);
     Plugins::act($after_action_hook);
 }
    private function tracking_code()
    {
        if (URL::get_matched_rule()->entire_match == 'user/login') {
            // Login page; don't display
            return;
        }
        $clientcode = Options::get('googleanalytics__clientcode');
        if (empty($clientcode)) {
            return;
        }
        // only actually track the page if we're not logged in, or we're told to always track
        $do_tracking = !User::identify()->loggedin || Options::get('googleanalytics__loggedintoo');
        $track_pageview = $do_tracking ? "_gaq.push(['_trackPageview']);" : '';
        $habari_url = Site::get_url('habari');
        if (Options::get('googleanalytics__skip_gaextra')) {
            $extra = '';
        } else {
            $extra = <<<EXTRA

  var ex = document.createElement('script'); ex.type = 'text/javascript'; ex.async = true;
  ex.src = '{$habari_url}/gaextra.js';
  s.parentNode.insertBefore(ex, s);

EXTRA;
        }
        return <<<ANALYTICS

var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{$clientcode}']);
{$track_pageview}

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
{$extra}})();

ANALYTICS;
    }
Пример #15
0
    /**
     * Outputs the Javascript tracking code in the theme's footer.
     *
     * @param Theme $theme The current Theme to add the tracking JS to.
     */
    public function theme_footer(Theme $theme)
    {
        // trailing slash url
        $siteurl = Options::get('piwik__siteurl');
        if ($siteurl[strlen($siteurl) - 1] != '/') {
            $siteurl .= '/';
        }
        $ssl_siteurl = str_replace("http://", "https://", $siteurl);
        $sitenum = Options::get('piwik__sitenum');
        if (URL::get_matched_rule()->entire_match == 'auth/login') {
            // Login page; don't dipslay
            return;
        }
        // don't track loggedin user
        if (User::identify()->loggedin && !Options::get('piwik__trackloggedin')) {
            return;
        }
        // set title and track 404's'
        $title = 'piwikTracker.setDocumentTitle(document.title);';
        if ($theme->request->display_404 == true) {
            $title = <<<KITTENS
piwikTracker.setDocumentTitle('404/URL = '+String(document.location.pathname+document.location.search).replace(/\\//g,"%2f") + '/From = ' + String(document.referrer).replace(/\\//g,"%2f"));
KITTENS;
        }
        // track tags for individual posts
        $tags = '';
        if (count($theme->posts) == 1 && $theme->posts instanceof Post) {
            foreach ($theme->posts->tags as $i => $tag) {
                $n = $i + 1;
                $tags .= "piwikTracker.setCustomVariable ({$n}, 'Tag', '{$tag->term_display}', 'page');";
            }
        }
        // output the javascript
        echo $this->get_piwik_script($ssl_siteurl, $siteurl, $sitenum, $title, $tags);
        if (Options::get('piwik__use_clickheat', false)) {
            // Click Heat integration
            // @todo use groups of entry, page, home, archive, etc. instead of title
            // @todo implement select option to let user choose group, page title, or URL for click tracking
            // @todo implement click quota option
            // $group = $this->get_click_heat_group(); this will check rewrite rule a determine group
            echo $this->get_clickheat_script($sitenum, "(document.title == '' ? '-none-' : encodeURIComponent(document.title))");
        }
    }
Пример #16
0
	/**
	 * Output a post collection based on the provided parameters.
	 *
	 * @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
	 */
	public function get_collection( $params = array() )
	{
		// Store handler vars since we'll be using them a lot.
		$handler_vars = Controller::get_handler_vars();

		// Retrieve the current matched rule and store its name and argument values.
		$rr = URL::get_matched_rule();
		$rr_name = $rr->name;
		$rr_args = $rr->named_arg_values;

		// Assign alternate links based on the matched rule.
		$alternate_rules = array(
			'atom_feed_tag' => 'display_entries_by_tag',
			'atom_feed' => 'display_home',
			'atom_entry' => 'display_entry',
			'atom_feed_entry_comments' => 'display_entry',
			'atom_feed_page_comments' => 'display_entry',
			'atom_feed_comments' => 'display_home',
			);
		$alternate_rules = Plugins::filter( 'atom_get_collection_alternate_rules', $alternate_rules );
		$alternate = URL::get( $alternate_rules[$rr_name], $handler_vars, false );

		// Assign self link based on the matched rule.
		$self = URL::get( $rr_name, $rr_args, false );

		// Get posts to put in the feed
		$page = ( isset( $rr_args['page'] ) ) ? $rr_args['page'] : 1;
		if ( $page > 1 ) {
			$params['page'] = $page;
		}

		if ( !isset( $params['content_type'] ) ) {
			$params['content_type'] = Post::type( 'entry' );
		}
		$params['content_type'] = Plugins::filter( 'atom_get_collection_content_type', $params['content_type'] );

		$params['status'] = $this->is_auth() ? 'any' : Post::status( 'published' );
		$params['orderby'] = 'updated DESC';
		$params['limit'] = Options::get( 'atom_entries' );

		$params = array_merge( $params, $rr_args );

		if ( array_key_exists( 'tag', $params ) ) {
			$id = urlencode( $params['tag'] );
			$tags = explode( ' ', $params['tag'] );
			foreach ( $tags as $tag ) {
				if ( $tag[0] == '-' ) {
					$tag = substr( $tag, 1 );
					$params['vocabulary'][Tags::vocabulary()->name . ':not:term'][] = Utils::slugify( $tag );
				}
				else {
					$params['vocabulary'][Tags::vocabulary()->name . ':all:term'][] = Utils::slugify( $tag );
				}
			}
			unset( $params['tag'] );
		}
		else {
			$id = 'atom';
		}
		$posts = Posts::get( $params );

		if ( count( $posts ) ) {
			$updated = $posts[0]->updated;
		}
		else {
			$updated = null;
			header( 'HTTP/1.1 404 Not Found', true, 404 );
			die( 'Posts could not be found' );
		}

		$xml = $this->create_atom_wrapper( $alternate, $self, $id, $updated );

		$xml = $this->add_pagination_links( $xml, $posts->count_all() );

		$xml = $this->add_posts( $xml, $posts );

		Plugins::act( 'atom_get_collection', $xml, $params, $handler_vars );
		$xml = $xml->asXML();

		ob_clean();
		header( 'Content-Type: application/atom+xml' );

		print $this->tidy_xml( $xml );
	}
Пример #17
0
 /**
  * function page_selector
  * Returns a page selector
  *
  * The $paramarray can contain:
  * 'current' => Current page
  * 'total' => Total pages
  * 'token' => Token for the URL calls
  * 'settings' => Array of settings for the URL calls
  *
  * @param array parameters to render the pagination
  * @return array contains a 'current' and 'pages' key
  **/
 public function get($current, $total, $rr_name = NULL, $settings = array())
 {
     // Extract the style and remove it from the array.
     if (isset($settings['style'])) {
         $style = $settings['style'];
         unset($settings['style']);
     } else {
         $style = 'span';
     }
     // If RewriteRule name is not supplied, use the current RewriteRule
     if ($rr_name == '') {
         $rr = URL::get_matched_rule();
     } else {
         list($rr) = RewriteRules::by_name($rr_name);
     }
     // Retrieve the RewriteRule and aggregate an array of matching arguments
     $rr_named_args = $rr->named_args;
     $rr_args = array_merge($rr_named_args['required'], $rr_named_args['optional']);
     $rr_args_values = array();
     foreach ($rr_args as $rr_arg) {
         $rr_arg_value = Controller::get_var($rr_arg);
         if ($rr_arg_value != '') {
             $rr_args_values[$rr_arg] = $rr_arg_value;
         }
     }
     $settings = array_merge($settings, $rr_args_values);
     // Current page
     if ($current > $total) {
         $current = $total;
     }
     $p = array('current' => $current);
     // 1 - First page
     $p['pages'][1]['caption'] = 1;
     // Skip if there is only one page
     if ($total > 1) {
         // &amp;
         if (($current != 1 || $current != $total) && $current - 2 > 1) {
             $p['pages'][] = '&hellip;';
         }
         // Previous Page
         if ($current - 1 > 1) {
             $p['pages'][]['caption'] = $current - 1;
         }
         // Current Page
         if ($current > 1 && $current < $total) {
             $p['pages'][]['caption'] = $current;
         }
         // Next Page
         if ($current + 1 < $total) {
             $p['pages'][]['caption'] = $current + 1;
         }
         // &hellip;
         if (($current != 1 || $current != $total) && $current + 2 < $total) {
             $p['pages'][] = '&hellip;';
         }
         // Last page
         $p['pages'][]['caption'] = $total;
     }
     $count = count($p['pages']);
     for ($z = 1; $z <= $count; $z++) {
         if (is_array($p['pages'][$z])) {
             $p['pages'][$z]['url'] = $rr->build(array_merge($settings, array('page' => $p['pages'][$z]['caption'])), false);
         }
     }
     return self::format($p, $style);
 }
Пример #18
0
 /**
  *	Output a post collection based on the provided parameters.
  *
  * @param array $params An array of parameters as passed to Posts::get() to retrieve posts.
  */
 public function get_collection($params = array())
 {
     // Store handler vars since we'll be using them a lot.
     $handler_vars = Controller::get_handler_vars();
     // Retrieve the current matched rule and store its name and argument values.
     $rr = URL::get_matched_rule();
     $rr_name = $rr->name;
     $rr_args = $rr->named_arg_values;
     // Assign alternate links based on the matched rule.
     $alternate_rules = array('atom_feed_tag' => 'display_entries_by_tag', 'atom_feed' => 'display_home', 'atom_entry' => 'display_entry', 'atom_feed_entry_comments' => 'display_entry', 'atom_feed_page_comments' => 'display_entry', 'atom_feed_comments' => 'display_home');
     $alternate_rules = Plugins::filter('atom_get_collection_alternate_rules', $alternate_rules);
     $alternate = URL::get($alternate_rules[$rr_name], $handler_vars, false);
     // Assign self link based on the matched rule.
     $self = URL::get($rr_name, $rr_args, false);
     $id = isset($rr_args_values['tag']) ? $rr_args_values['tag'] : 'atom';
     $xml = $this->create_atom_wrapper($alternate, $self, $id);
     $xml = $this->add_pagination_links($xml, Posts::count_total(Post::status('published')));
     // Get posts to put in the feed
     $page = isset($rr_args['page']) ? $rr_args['page'] : 1;
     if ($page > 1) {
         $params['page'] = $page;
     }
     if (!isset($params['content_type'])) {
         $params['content_type'] = Post::type('entry');
     }
     $params['content_type'] = Plugins::filter('atom_get_collection_content_type', $params['content_type']);
     $params['status'] = Post::status('published');
     $params['orderby'] = 'updated DESC';
     $params['limit'] = Options::get('atom_entries');
     $params = array_merge($params, $rr_args);
     if (array_key_exists('tag', $params)) {
         $params['tag_slug'] = Utils::slugify($params['tag']);
         unset($params['tag']);
     }
     $posts = Posts::get($params);
     $xml = $this->add_posts($xml, $posts);
     Plugins::act('atom_get_collection', $xml, $params, $handler_vars);
     $xml = $xml->asXML();
     ob_clean();
     header('Content-Type: application/atom+xml');
     print $xml;
 }
 /**
  * The output buffer callback used to capture the output and cache it.
  *
  * @see StaticCache::init()
  * @param string $buffer The output buffer contents
  * @return string $buffer unchanged
  */
 public static function store_final_output($buffer)
 {
     // prevent caching of 404 responses
     if (!URL::get_matched_rule() || URL::get_matched_rule()->name == 'display_404') {
         return $buffer;
     }
     $request_id = StaticCache::get_request_id();
     $query_id = StaticCache::get_query_id();
     $expire = Options::get('staticcache__expire', StaticCache::EXPIRE);
     // get cache if exists
     if (Cache::has(array(StaticCache::GROUP_NAME, $request_id))) {
         $cache = Cache::get(array(StaticCache::GROUP_NAME, $request_id));
     } else {
         $cache = array();
     }
     // don't cache cookie headers (ie. session cookies)
     $headers = headers_list();
     foreach ($headers as $i => $head) {
         if (stripos($head, 'cookie') !== false) {
             unset($headers[$i]);
         }
     }
     // see if we want compression and store cache
     $cache[$query_id] = array('headers' => $headers, 'request_uri' => Site::get_url('host') . $_SERVER['REQUEST_URI']);
     if (Options::get('staticcache__compress') && extension_loaded('zlib')) {
         $cache[$query_id]['body'] = gzcompress($buffer, StaticCache::GZ_COMPRESSION);
         $cache[$query_id]['compressed'] = true;
     } else {
         $cache[$query_id]['body'] = $buffer;
         $cache[$query_id]['compressed'] = false;
     }
     Cache::set(array(StaticCache::GROUP_NAME, $request_id), $cache, $expire);
     return $buffer;
 }
Пример #20
0
 /**
  * function filter_theme_act_display_entries_by_author
  * Helper function: Display the posts for an author. Probably should be more generic eventually.
  */
 public function filter_theme_act_display_entries_by_author($handled, $theme)
 {
     $paramarray = array();
     $vars = Controller::get_handler_vars();
     $user = Users::get_by_info('slug', $vars['author']);
     if (count($user) > 0) {
         $author = $user[0];
     } elseif ($user = User::get($vars['author'])) {
         $author = $user;
     } else {
         $theme->request->{URL::get_matched_rule()->name} = false;
         $theme->request->{URL::set_404()->name} = true;
         $theme->matched_rule = URL::get_matched_rule();
         $theme->act_display_404();
         return;
     }
     if (isset($author)) {
         $paramarray['fallback'][] = 'author.{$author->id}';
     }
     $paramarray['fallback'][] = 'author';
     $paramarray['fallback'][] = 'multiple';
     $paramarray['fallback'][] = 'home';
     $default_filters = array('content_type' => Post::type('entry'));
     $paramarray['user_filters'] = $default_filters;
     $theme->assign('author', $author);
     $theme->act_display($paramarray);
     return true;
 }
Пример #21
0
 /**
  * function get_title
  *
  * creates the html title for the page being displayed
  *
  * @return string the html title for the page
  */
 private function get_title()
 {
     $months = array(1 => _t('January', 'metaseo'), _t('February', 'metaseo'), _t('March', 'metaseo'), _t('April', 'metaseo'), _t('May', 'metaseo'), _t('June', 'metaseo'), _t('July', 'metaseo'), _t('August', 'metaseo'), _t('September', 'metaseo'), _t('October', 'metaseo'), _t('November', 'metaseo'), _t('December', 'metaseo'));
     $out = '';
     $matched_rule = URL::get_matched_rule();
     if (is_object($matched_rule)) {
         $rule = $matched_rule->name;
         switch ($rule) {
             case 'display_home':
             case 'display_entries':
                 $out = Options::get('title');
                 if (Options::get('tagline')) {
                     $out .= ' - ' . Options::get('tagline');
                 }
                 break;
             case 'display_entries_by_date':
                 $out = 'Archive for ';
                 if (isset($this->theme->day)) {
                     $out .= $this->theme->day . ' ';
                 }
                 if (isset($this->theme->month)) {
                     $out .= $months[$this->theme->month] . ' ';
                 }
                 if (isset($this->theme->year)) {
                     $out .= $this->theme->year . ' ';
                 }
                 $out .= ' - ' . Options::get('title');
                 break;
             case 'display_entries_by_tag':
                 // parse the tags out of the URL, just like the handler does
                 $tags = Tags::parse_url_tags(Controller::get_var('tag'));
                 // build the pieces we'll use for text
                 $include_tag_text = array();
                 $exclude_tag_text = array();
                 foreach ($tags['include_tag'] as $include_tag) {
                     $include_tag_text[] = Tags::vocabulary()->get_term($include_tag)->term_display;
                 }
                 foreach ($tags['exclude_tag'] as $exclude_tag) {
                     $exclude_tag_text[] = Tags::vocabulary()->get_term($exclude_tag)->term_display;
                 }
                 $out = Format::and_list($include_tag_text);
                 if (!empty($exclude_tag_text)) {
                     $out .= ' but not ' . Format::and_list($exclude_tag_text);
                 }
                 $out .= ' Archive - ' . Options::get('title');
                 break;
             case 'display_entry':
             case 'display_page':
                 if (strlen($this->theme->post->info->html_title)) {
                     $out = $this->theme->post->info->html_title;
                 } else {
                     $out = $this->theme->post->title;
                 }
                 $out .= ' - ' . Options::get('title');
                 break;
             case 'display_search':
                 if (isset($_GET['criteria'])) {
                     $out = 'Search Results for ' . $_GET['criteria'] . ' - ';
                 }
                 $out .= Options::get('title');
                 break;
             case 'display_404':
                 $out = 'Page Not Found';
                 $out .= ' - ' . Options::get('title');
                 break;
         }
         if (strlen($out)) {
             $out = Utils::htmlspecialchars(strip_tags($out));
             $out = stripslashes($out);
         }
     }
     return $out;
 }
Пример #22
0
 /**
  * Matches the scope criteria against the current request
  *
  * @param array $criteria An array of scope criteria data in RPN, where values are arrays and operators are strings
  * @return boolean True if the criteria matches the current request
  */
 function check_scope_criteria($criteria)
 {
     $stack = array();
     foreach ($criteria as $crit) {
         if (is_array($crit)) {
             $value = false;
             switch ($crit[0]) {
                 case 'request':
                     $value = URL::get_matched_rule()->name == $crit[1];
                     break;
                 case 'token':
                     if (isset($crit[2])) {
                         $value = User::identify()->can($crit[1], $crit[2]);
                     } else {
                         $value = User::identify()->can($crit[1]);
                     }
                     break;
                 default:
                     $value = Plugins::filter('scope_criteria_value', $value, $crit[1], $crit[2]);
                     break;
             }
             $stack[] = $value;
         } else {
             switch ($crit) {
                 case 'not':
                     $stack[] = !array_pop($stack);
                     break;
                 case 'or':
                     $value1 = array_pop($stack);
                     $value2 = array_pop($stack);
                     $stack[] = $value1 || $value2;
                     break;
                 case 'and':
                     $value1 = array_pop($stack);
                     $value2 = array_pop($stack);
                     $stack[] = $value1 && $value2;
                     break;
                 default:
                     Plugins::act('scope_criteria_operator', $stack, $crit);
                     break;
             }
         }
     }
     return array_pop($stack);
 }
Пример #23
0
 private function get_matched_rule()
 {
     $matched_rule = URL::get_matched_rule();
     if (is_object($matched_rule)) {
         $rule = $matched_rule->name;
         return $rule;
     }
     return NULL;
 }
Пример #24
0
 /**
  * Load the active theme and create a new Theme instance.
  * Also, assign the request variables.
  */
 public function setup_theme()
 {
     $this->theme = Themes::create();
     $this->theme->assign('matched_rule', URL::get_matched_rule());
     $request = Controller::get_request_obj();
     $this->theme->assign('request', $request);
 }
Пример #25
0
 /**
  * Returns the appropriate alternate feed based on the currently matched rewrite rule.
  *
  * @param mixed $return Incoming return value from other plugins
  * @param Theme $theme The current theme object
  * @return string Link to the appropriate alternate Atom feed
  */
 public function theme_feed_rss_alternate($theme)
 {
     $matched_rule = URL::get_matched_rule();
     if (is_object($matched_rule)) {
         // This is not a 404
         $rulename = $matched_rule->name;
     } else {
         // If this is a 404 and no rewrite rule matched the request
         $rulename = '';
     }
     switch ($rulename) {
         case 'display_entry':
         case 'display_page':
             return URL::get('rss_entry', array('slug' => Controller::get_var('slug')));
             break;
         case 'display_entries_by_tag':
             return URL::get('rss_feed_tag', array('tag' => Controller::get_var('tag')));
             break;
         case 'display_home':
         default:
             return URL::get('rss_feed', array('index' => '1'));
     }
     return '';
 }
Пример #26
0
 /**
  * Get an object that represents the request made
  * @return stdClass An object with properties named after rewrite rules, which are true if those rules were used to handle the current request
  */
 public static function get_request_obj()
 {
     $request = new StdClass();
     foreach (URL::get_active_rules() as $rule) {
         $request->{$rule->name} = false;
     }
     $matched_rule = URL::get_matched_rule();
     $request->{$matched_rule->name} = true;
     // Does the rule have any supplemental request types?
     if (isset($matched_rule->named_arg_values['request_types'])) {
         foreach ($matched_rule->named_arg_values['request_types'] as $type) {
             $request->{$type} = true;
         }
     }
     $request = Plugins::filter('request_object', $request, $matched_rule);
     return $request;
 }
Пример #27
0
 /**
  * Replace specified text in the post with the desired text
  *
  * @param string $content The post content
  * @param Post $post The post object to which the content belongs
  *
  * @return string The altered content
  */
 public function filter_post_content($content, $post)
 {
     $rule = URL::get_matched_rule();
     if ('UserThemeHandler' == $rule->handler) {
         $this->current_post = $post;
         preg_match_all('%<a href="(.*)(" rel="enclosure">)(.*)</a>%i', $content, $matches);
         $count = count($matches[1]);
         for ($i = 0; $i < $count; $i++) {
             $player = $this->embed_player($matches[1][$i]);
             if ($player) {
                 $content = str_ireplace($matches[0][$i], $player, $content);
             }
         }
         $this->current_post = NULL;
         $this->title = '';
     }
     return $content;
 }
Пример #28
0
 /**
  * Display the login form
  *
  * @param string $name Pre-fill the name field with this name
  */
 protected function login_form($name)
 {
     // Display the login form.
     $this->theme = Themes::create();
     if (!$this->theme->template_exists('login')) {
         $this->theme = Themes::create('admin', 'RawPHPEngine', Site::get_dir('admin_theme', TRUE));
         $this->theme->assign('admin_page', 'login');
     }
     $request = new StdClass();
     foreach (URL::get_active_rules() as $rule) {
         $request->{$rule->name} = $rule->name == URL::get_matched_rule()->name;
     }
     if (isset($this->handler_vars['error'])) {
         $this->theme->assign('error', Utils::htmlspecialchars($this->handler_vars['error']));
     }
     $this->theme->assign('request', $request);
     $this->theme->assign('habari_username', htmlentities($name, ENT_QUOTES, 'UTF-8'));
     $this->display('login');
     return TRUE;
 }
Пример #29
0
 /**
  * Load the active theme and create a new Theme instance.
  * Also, assign the request variables.
  */
 public function setup_theme()
 {
     $this->theme = Themes::create();
     $this->theme->assign('matched_rule', URL::get_matched_rule());
     $request = new StdClass();
     foreach (RewriteRules::get_active() as $rule) {
         $request->{$rule->name} = false;
     }
     $request->{$this->theme->matched_rule->name} = true;
     $this->theme->assign('request', $request);
 }
Пример #30
0
 /**
  * function get_title
  *
  * creates the html title for the page being displayed
  *
  * @return string the html title for the page
  */
 private function get_title()
 {
     $months = array(1 => _t('January', 'metaseo'), _t('February', 'metaseo'), _t('March', 'metaseo'), _t('April', 'metaseo'), _t('May', 'metaseo'), _t('June', 'metaseo'), _t('July', 'metaseo'), _t('August', 'metaseo'), _t('September', 'metaseo'), _t('October', 'metaseo'), _t('November', 'metaseo'), _t('December', 'metaseo'));
     $out = '';
     $matched_rule = URL::get_matched_rule();
     if (is_object($matched_rule)) {
         $rule = $matched_rule->name;
         switch ($rule) {
             case 'display_home':
             case 'display_entries':
                 $out = Options::get('title');
                 if (Options::get('tagline')) {
                     $out .= ' - ' . Options::get('tagline');
                 }
                 break;
             case 'display_entries_by_date':
                 $out = 'Archive for ';
                 if (isset($this->theme->day)) {
                     $out .= $this->theme->day . ' ';
                 }
                 if (isset($this->theme->month)) {
                     $out .= $months[$this->theme->month] . ' ';
                 }
                 if (isset($this->theme->year)) {
                     $out .= $this->theme->year . ' ';
                 }
                 $out .= ' - ' . Options::get('title');
                 break;
             case 'display_entries_by_tag':
                 // Assumes there is only one tag term in the url
                 $out = Tags::vocabulary()->get_term(Controller::get_var('tag'))->term_display;
                 $out .= ' Archive - ' . Options::get('title');
                 break;
             case 'display_entry':
             case 'display_page':
                 if (strlen($this->theme->post->info->html_title)) {
                     $out = $this->theme->post->info->html_title;
                 } else {
                     $out = $this->theme->post->title;
                 }
                 $out .= ' - ' . Options::get('title');
                 break;
             case 'display_search':
                 if (isset($_GET['criteria'])) {
                     $out = 'Search Results for ' . $_GET['criteria'] . ' - ';
                 }
                 $out .= Options::get('title');
                 break;
             case 'display_404':
                 $out = 'Page Not Found';
                 $out .= ' - ' . Options::get('title');
                 break;
         }
         if (strlen($out)) {
             $out = Utils::htmlspecialchars(strip_tags($out));
             $out = stripslashes($out);
         }
     }
     return $out;
 }