public function action_init()
 {
     $class_name = strtolower(get_class($this));
     $this->config['provider'] = Options::get($class_name . '__provider');
     $this->config['identity'] = Options::get($class_name . '__identity');
     $this->config['is2'] = Options::get($class_name . '__is2');
 }
 public function __construct(Options $options)
 {
     $this->token = $options->get('token');
     if (empty($this->token)) {
         SS_Envato_API()->notices->add_warning('Please, set up your Envato API token.', true);
     }
 }
Exemple #3
0
 /**
  * Upload Proccess Function.
  * This will do the upload proccess. This function need some variables, eg: 
  * @param string $input This is the input field name.
  * @param string $path This is the path the file will be stored.
  * @param array $allowed This is the array of the allowed file extension.
  * @param false $uniq Set to true if want to use a unique name.
  * @param int $size File size maximum allowed.
  * @param int $width The width of the dimension.
  * @param int $height The height of the dimension.
  * 
  * @return array
  *
  * @author Puguh Wijayanto (www.metalgenix.com)
  * @since 0.0.1
  */
 public static function go($input, $path, $allowed = '', $uniq = false, $size = '', $width = '', $height = '')
 {
     $filename = Typo::cleanX($_FILES[$input]['name']);
     $filename = str_replace(' ', '_', $filename);
     if (isset($_FILES[$input]) && $_FILES[$input]['error'] == 0) {
         if ($uniq == true) {
             $site = Typo::slugify(Options::get('sitename'));
             $uniqfile = $site . '-' . sha1(microtime() . $filename) . '-';
         } else {
             $uniqfile = '';
         }
         $extension = pathinfo($_FILES[$input]['name'], PATHINFO_EXTENSION);
         $filetmp = $_FILES[$input]['tmp_name'];
         $filepath = GX_PATH . $path . $uniqfile . $filename;
         if (!in_array(strtolower($extension), $allowed)) {
             $result['error'] = 'File not allowed';
         } else {
             if (move_uploaded_file($filetmp, $filepath)) {
                 $result['filesize'] = filesize($filepath);
                 $result['filename'] = $uniqfile . $filename;
                 $result['path'] = $path . $uniqfile . $filename;
                 $result['filepath'] = $filepath;
                 $result['fileurl'] = Site::$url . $path . $uniqfile . $filename;
             } else {
                 $result['error'] = 'Cannot upload to directory, please check 
                 if directory is exist or You had permission to write it.';
             }
         }
     } else {
         //$result['error'] = $_FILES[$input]['error'];
         $result['error'] = '';
     }
     return $result;
 }
 public static function check_posts($nolimit = false)
 {
     $autoclosed = array();
     $age_in_days = Options::get('autoclose__age_in_days');
     if (is_null($age_in_days)) {
         return;
     }
     $age_in_days = abs(intval($age_in_days));
     $search = array('content_type' => 'entry', 'before' => HabariDateTime::date_create()->modify('-' . $age_in_days . ' days'), 'nolimit' => true, 'status' => 'published');
     if (!$nolimit) {
         $search['after'] = HabariDateTime::date_create()->modify('-' . ($age_in_days + 30) . ' days');
     }
     $posts = Posts::get($search);
     foreach ($posts as $post) {
         if (!$post->info->comments_disabled && !$post->info->comments_autoclosed) {
             $post->info->comments_disabled = true;
             $post->info->comments_autoclosed = true;
             $post->info->commit();
             $autoclosed[] = sprintf('<a href="%s">%s</a>', $post->permalink, htmlspecialchars($post->title));
         }
     }
     if (count($autoclosed)) {
         if (count($autoclosed) > 5) {
             Session::notice(sprintf(_t('Comments autoclosed for: %s and %d other posts', 'autoclose'), implode(', ', array_slice($autoclosed, 0, 5)), count($autoclosed) - 5));
         } else {
             Session::notice(sprintf(_t('Comments autoclosed for: %s', 'autoclose'), implode(', ', $autoclosed)));
         }
     } else {
         Session::notice(sprintf(_t('Found no posts older than %d days with comments enabled.', 'autoclose'), $age_in_days));
     }
     return true;
 }
Exemple #5
0
 /**
  * Add some variables to the template output
  */
 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)));
     }
     $page = Controller::get_var('page');
     $page = isset($page) ? $page : 1;
     if (!$this->template_engine->assigned('page')) {
         $this->assign('page', $page);
     }
     $this->assign('show_previously', false);
     $this->assign('show_latest', false);
     $action = Controller::get_action();
     if ($action == 'display_home' || $action == 'display_entries') {
         $offset = (int) (($page + 1 - 1) * Options::get('pagination'));
         $this->assign('previously', Posts::get(array('status' => 'published', 'content_type' => 'entry', 'offset' => $offset, 'limit' => self::PREVIOUSLY_ITEMS)));
         $this->assign('show_previously', true);
     }
     if ($action != 'display_home') {
         $this->assign('latest', Posts::get(array('status' => 'published', 'content_type' => 'entry', 'offset' => 0, 'limit' => self::LATEST_ITEMS)));
         $this->assign('show_latest', true);
     }
     $this->assign('controller_action', $action);
     parent::add_template_vars();
 }
Exemple #6
0
	/**
	 * Determine if the database needs to be updated based on the source database version being newer than the schema last applied to the database
	 *
	 * @return boolean True if an update is needed
	 */
	public static function requires_upgrade()
	{
		if ( Options::get( 'db_version' ) < Version::DB_VERSION ) {
			return true;
		}
		return false;
	}
Exemple #7
0
 public function __construct()
 {
     $this->connection = @mysqli_connect(Options::get("mysql_host"), Options::get("mysql_user"), Options::get("mysql_password"), Options::get("mysql_db"));
     if (!$this->connection) {
         throw new Exception("Couldn't connect to database.", 1);
     }
 }
 function action_add_template_vars($theme)
 {
     $username = Options::get('freshsurf__username');
     $password = Options::get('freshsurf__password');
     $count = Options::get('freshsurf__count');
     if ($username != '' && $password != '') {
         if (Cache::has('freshsurf__' . $username)) {
             $response = Cache::get('freshsurf__' . $username);
         } else {
             $request = new RemoteRequest("https://{$username}:{$password}@" . self::BASE_URL . "posts/recent?count={$count}", 'GET', 20);
             $request->execute();
             $response = $request->get_response_body();
             Cache::set('freshsurf__' . $username, $response);
         }
         $delicious = @simplexml_load_string($response);
         if ($delicious instanceof SimpleXMLElement) {
             $theme->delicious = $delicious;
         } else {
             $theme->delicious = @simplexml_load_string('<posts><post href="#" description="Could not load feed from delicious.  Is username/password correct?"/></posts>');
             Cache::expire('freshsurf__' . $username);
         }
     } else {
         $theme->delicious = @simplexml_load_string('<posts></posts>');
     }
 }
Exemple #9
0
 /**
  * Runs this job.
  *
  * Executes the Cron Job callback. Deletes the Cron Job if end_time is reached
  * or if it failed to execute the last # consecutive attempts. Also sends notification
  * by email to specified address.
  * Note: end_time can be null, ie. "The Never Ending Cron Job".
  *
  * Callback is passed a param_array of the Cron Job fields and the execution time
  * as the 'now' field. The 'result' field contains the result of the last execution; either
  * 'executed' or 'failed'.
  *
  * @todo send notification of execution/failure.
  */
 public function execute()
 {
     $paramarray = array_merge(array('now' => $this->now), $this->to_array());
     // this is an ugly hack that we could probably work around better by forking each cron into its own process
     // we increment the failure count now so that if we don't return after calling the callback (ie: a fatal error) it still counts against it, rather than simply never running
     // and preventing all those queued up after it from running
     $this->failures = $this->failures + 1;
     // check to see if we have failed too many times before we update, we might go ahead and skip this one
     if ($this->failures > Options::get('cron_max_failures', 10)) {
         EventLog::log(_t('CronJob %s has failed %d times and is being deactivated!', array($this->name, $this->failures - 1)), 'alert', 'cron');
         $this->active = 0;
     }
     // update before we run it
     $this->update();
     // if the check has been deactivated, just return
     if ($this->active == 0) {
         return;
     }
     if (is_callable($this->callback)) {
         // this is a callable we can actually call, so do it
         $result = call_user_func($this->callback, $paramarray);
     } else {
         if (!is_string($this->callback) && is_callable($this->callback, true, $callable_name)) {
             // this looks like a callable to PHP, but it cannot be called at present and should not be assumed to be a plugin filter name
             // there is nothing for us to do, but it was a specifically-named function for us to call, so assume this is a failure
             $result = false;
         } else {
             // this is not callable and doesn't look like one - it should simply be a textual plugin filter name
             // is this plugin filter actually implemented?
             if (Plugins::implemented($this->callback, 'filter')) {
                 // then run it and use that result
                 $result = true;
                 $result = Plugins::filter($this->callback, $result, $paramarray);
             } else {
                 // the filter isn't implemented, consider that a failure
                 $result = false;
             }
         }
     }
     if ($result === false) {
         $this->result = 'failed';
         // simply increment the failure counter. if it's over the limit it'll be deactivated on the next go-around
         $this->failures = $this->failures + 1;
         EventLog::log(_t('CronJob %s failed.', array($this->name)), 'err', 'cron');
     } else {
         $this->result = 'executed';
         // reset failures, we were successful
         $this->failures = 0;
         EventLog::log(_t('CronJob %s completed successfully.', array($this->name)), 'debug', 'cron');
         // it ran successfully, so check if it's time to delete it.
         if (!is_null($this->end_time) && $this->now >= $this->end_time) {
             EventLog::log(_t('CronJob %s is not scheduled to run again and is being deleted.', array($this->name)), 'debug', 'cron');
             $this->delete();
             return;
         }
     }
     $this->last_run = $this->now;
     $this->next_run = $this->now->int + $this->increment;
     $this->update();
 }
 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;
 }
 /**
  * Build a selection input of paginated paths to be used for pagination.
  *
  * @param string The RewriteRule name used to build the links.
  * @param array Various settings used by the method and the RewriteRule.
  * @return string Collection of paginated URLs built by the RewriteRule.
  */
 function theme_page_dropdown($theme, $rr_name = NULL, $settings = array())
 {
     $output = "";
     $current = $theme->page;
     $items_per_page = isset($theme->posts->get_param_cache['limit']) ? $theme->posts->get_param_cache['limit'] : Options::get('pagination');
     $total = Utils::archive_pages($theme->posts->count_all(), $items_per_page);
     // Make sure the current page is valid
     if ($current > $total) {
         $current = $total;
     } else {
         if ($current < 1) {
             $current = 1;
         }
     }
     $output = '<select onchange="location.href=options[selectedIndex].value">';
     for ($page = 1; $page < $total; ++$page) {
         $settings['page'] = $page;
         $caption = $page == $current ? $current : $page;
         // Build the path using the supplied $settings and the found RewriteRules arguments.
         $url = URL::get($rr_name, $settings, false, false, false);
         // Build the select option.
         $output .= '<option value="' . $url . '"' . ($page == $current ? ' selected="selected"' : '') . '>' . $caption . '</option>' . "\n";
     }
     $output .= "</select>";
     return $output;
 }
Exemple #12
0
 /**
  * Add additional template variables to the template output.
  * 
  * 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()
 {
     parent::add_template_vars();
     if (!$this->template_engine->assigned('pages')) {
         $this->assign('pages', Posts::get('page_list'));
     }
     if (!$this->template_engine->assigned('asides')) {
         //For Asides loop in sidebar.php
         $this->assign('asides', Posts::get('asides'));
     }
     if (!$this->template_engine->assigned('recent_comments')) {
         //for recent comments loop in sidebar.php
         $this->assign('recent_comments', Comments::get(array('limit' => 5, 'status' => Comment::STATUS_APPROVED, 'orderby' => 'date DESC')));
     }
     if (!$this->template_engine->assigned('more_posts')) {
         //Recent posts in sidebar.php
         //visiting page/2 will offset to the next page of posts in the footer /3 etc
         $pagination = Options::get('pagination');
         $this->assign('more_posts', Posts::get(array('content_type' => 'entry', 'status' => 'published', 'vocabulary' => array('tags:not:tag' => 'asides'), 'offset' => $pagination * $this->page, 'limit' => 5)));
     }
     if (!$this->template_engine->assigned('all_tags')) {
         // List of all the tags
         $this->assign('all_tags', Tags::vocabulary()->get_tree());
     }
     if (!$this->template_engine->assigned('all_entries')) {
         // List of all the entries
         $this->assign('all_entries', Posts::get(array('content_type' => 'entry', 'status' => 'published', 'nolimit' => 1)));
     }
 }
	/**
	 * Ouputs the default menu in the template footer, and runs the 'habmin_bar' plugin filter.
	 * You can add menu items via the filter. See the 'filter_habminbar' method for
	 * an example.
	 */
	public function action_template_footer()
	{
		if ( User::identify()->loggedin ) {
			$bar = '<div id="habminbar"><div>';
			$bar.= '<div id="habminbar-name"><a href="' . Options::get('base_url') . '">' . Options::get('title') . '</a></div>';
			$bar.= '<ul>';

			$menu = array();
			$menu['dashboard']= array( 'Dashboard', URL::get( 'admin', 'page=dashboard' ), "view the admin dashboard" );
			$menu['write']= array( 'Write', URL::get( 'admin', 'page=publish' ), "create a new entry" );
			$menu['option']= array( 'Options', URL::get( 'admin', 'page=options' ), "configure site options" );
			$menu['comment']= array( 'Moderate', URL::get( 'admin', 'page=comments' ),"moderate comments" );
			$menu['user']= array( 'Users', URL::get( 'admin', 'page=users' ), "administer users" );
			$menu['plugin']= array( 'Plugins', URL::get( 'admin', 'page=plugins' ), "activate and configure plugins" );
			$menu['theme']= array( 'Themes', URL::get( 'admin', 'page=themes' ), "select a theme" );

			$menu = Plugins::filter( 'habminbar', $menu );

			$menu['logout']= array( 'Logout', URL::get( 'user', 'page=logout' ), "logout" );

			foreach ( $menu as $name => $item ) {
				list( $label, $url, $tooltip )= array_pad( $item, 3, "" );
				$bar.= "\n\t<li><a href=\"$url\" class=\"$name\"" .
				( ( $tooltip ) ? " title=\"$tooltip\"" : "" ) .">$label</a></li>";
			}
			$bar.= '</ul><br style="clear:both;" /></div></div>';

			echo $bar;
		}
	}
 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;
 }
 /**
  * On plugin init
  **/
 public function action_init()
 {
     $this->class_name = strtolower(get_class($this));
     foreach (self::default_options() as $name => $value) {
         $this->config[$name] = Options::get($this->class_name . '__' . $name);
     }
 }
Exemple #16
0
 /**
  * Customize comment form layout with fieldsets.
  */
 public function action_form_comment($form)
 {
     //My custom comment form
     $form->append('fieldset', 'cf_commentbox', _t('Who Are You'));
     $form->cf_commentbox->class = "form-part-1";
     //move the Name ( cf_commenter) into the fieldset
     $form->cf_commenter->move_into($form->cf_commentbox);
     $form->cf_commenter->caption = _t('Name:') . '<span class="required">' . (Options::get('comments_require_id') == 1 ? ' *' . _t('Required') : '') . '</span></label>';
     //move the Email ( cf_email) into the Fieldset
     $form->cf_email->move_into($form->cf_commentbox);
     $form->cf_email->caption = _t('Email Address:') . '<span class="required">' . (Options::get('comments_require_id') == 1 ? ' *' . _t('Required') : '') . '</span></label>';
     //add a disclaimer/message
     $form->append('static', 'cf_disclaimer', _t('<p><em><small>Email address is not published</small></em></p>'));
     //move the disclaimer into the fieldset
     $form->cf_disclaimer->move_into($form->cf_commentbox);
     //remove the url piece
     $form->cf_url->remove();
     //add a second fieldset for the next two fields
     $form->append('fieldset', 'cf_contentsubmit', _t('Leave A Message'));
     $form->cf_contentsubmit->class = "form-part-2";
     //move the textarea into a second fieldset
     $form->cf_content->move_into($form->cf_contentsubmit);
     $form->cf_content->caption = _t('Message: (Required)');
     //move the submit button in too
     $form->cf_submit->move_into($form->cf_contentsubmit);
     $form->cf_submit->caption = _t('Submit');
 }
 public function filter_default_rewrite_rules($rules)
 {
     if ($this->current_load() > self::KILL_LOAD) {
         foreach ($rules as $key => $rule) {
             if (strpos($rule['build_str'], 'admin') !== false) {
                 $rules[$key]['handler'] = 'UserThemeHandler';
                 $rules[$key]['action'] = 'display_throttle';
             }
         }
         if (Options::get('throttle') == '') {
             EventLog::log(sprintf(_t('Kill - Load is %s'), $this->current_load()));
             Options::set('throttle', 'kill');
         }
     } elseif ($this->current_load() > self::MAX_LOAD) {
         foreach ($rules as $key => $rule) {
             if ($rule['name'] == 'search') {
                 unset($rules[$key]);
             }
         }
         $rules[] = array('name' => 'search', 'parse_regex' => '%^search(?:/(?P<criteria>[^/]+))?(?:/page/(?P<page>\\d+))?/?$%i', 'build_str' => 'search(/{$criteria})(/page/{$page})', 'handler' => 'UserThemeHandler', 'action' => 'display_throttle', 'priority' => 8, 'description' => 'Searches posts');
         if (Options::get('throttle') == '') {
             EventLog::log(sprintf(_t('Restrict - Load is %s'), $this->current_load()));
             Options::set('throttle', 'restrict');
         }
     } else {
         if (Options::get('throttle') != '') {
             EventLog::log(sprintf(_t('Normal - Load is %s'), $this->current_load()));
             Options::set('throttle', '');
         }
     }
     return $rules;
 }
 /**
  * Открытие сокета.
  * 
  * @return boolean
  * @throws IO_Stream_Spark_Socket_Exception
  */
 public function ignite()
 {
     $url = sprintf('%s://%s:%d', $this->_opts->get('transport'), $this->_opts->get('host'), $this->_opts->get('port'));
     $timeout = $this->_opts->get('connect_timeout');
     /**
      * @todo Попробовать сделать подключение асинхронным
      * (STREAM_CLIENT_ASYNC_CONNECT).
      */
     $this->_stream = stream_socket_client($url, $errno, $errstr, $timeout);
     if (false === $this->_stream) {
         $e = 'Error connecting %s: %s - %s';
         $e = sprintf($url, $errno, $errstr, $e);
         throw new IO_Stream_Spark_Socket_Exception($e);
     }
     return true;
 }
Exemple #19
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()
 {
     //Theme Options
     $this->assign('home_tab', 'Home');
     //Set to whatever you want your first tab text to be.
     $this->assign('show_author', false);
     //Display author in posts
     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('page')) {
         $page = Controller::get_var('page');
         $this->assign('page', isset($page) ? $page : 1);
     }
     parent::add_template_vars();
     //from mzingi
     //visiting page/2, /3 will offset to the next page of posts in the sidebar
     $page = Controller::get_var('page');
     $pagination = Options::get('pagination');
     if ($page == '') {
         $page = 1;
     }
     $this->assign('more_posts', Posts::get(array('status' => 'published', 'content_type' => 'entry', 'offset' => $pagination * $page, 'limit' => 5)));
     //from mzingi
     //for recent comments loop in sidebar.php
     $this->assign('recent_comments', Comments::get(array('limit' => 5, 'status' => Comment::STATUS_APPROVED, 'orderby' => 'date DESC')));
 }
    public function action_comment_insert_after($comment)
    {
        // we should only execute on comments, not pingbacks
        // and don't bother if the comment is know to be spam
        if ($comment->type != Comment::COMMENT || $comment->status == Comment::STATUS_SPAM) {
            return;
        }
        $post = Post::get(array('id' => $comment->post_id));
        $author = User::get_by_id($post->user_id);
        $status = $comment->status == Comment::STATUS_UNAPPROVED ? ' UNAPPROVED' : ' approved';
        $title = sprintf(_t('[%1$s] New%3$s comment on: %2$s'), Options::get('title'), $post->title, $status);
        $message = <<<MESSAGE
The following comment was added to the post "%1\$s".
%2\$s

Author: %3\$s <%4\$s>
URL: %5\$s

%6\$s

-----
Moderate comments: %7\$s
MESSAGE;
        $message = _t($message);
        $message = sprintf($message, $post->title, $post->permalink, $comment->name, $comment->email, $comment->url, $comment->content, URL::get('admin', 'page=comments'));
        $headers = array('MIME-Version: 1.0', 'Content-type: text/plain; charset=utf-8', 'Content-Transfer-Encoding: 8bit', 'From: ' . $this->mh_utf8($comment->name) . ' <' . $comment->email . '>');
        mail($author->email, $this->mh_utf8($title), $message, implode("\r\n", $headers));
    }
Exemple #21
0
 /**
  * parse the request URL
  *
  * @return array Matched route
  */
 public static function parseRequest()
 {
     $routes = array('index' => array('url' => '/\\A\\z/', 'controller' => 'SiteHandler', 'action' => 'display_sites'), 'site' => array('url' => '%^site/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site'), 'cron_run' => array('url' => '%^cron/?\\z%', 'controller' => 'CronTab', 'action' => 'act_poll_cron'), 'site_create' => array('url' => '%^site/create/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_create'), 'site_update' => array('url' => '%^site/update/?\\z%', 'controller' => 'SiteHandler', 'action' => 'site_update'), 'site_delete' => array('url' => '%^site/delete/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_delete'), 'site_create_from_page' => array('url' => '%^site/from-page/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_create_from_page'), 'site_create_from_sitemap' => array('url' => '%^site/from-sitemap/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_create_from_sitemap'), 'site_page' => array('url' => '%^site/page/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_page'), 'site_keyword_add' => array('url' => '%^site/keyword/add/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_site_keyword_add'), 'site_page_update' => array('url' => '%^site/page/update/?\\z%', 'controller' => 'SiteHandler', 'action' => 'site_page_update'), 'site_page_inlink_update' => array('url' => '%^site/page/inlink/update/?\\z%', 'controller' => 'SiteHandler', 'action' => 'site_page_inlink_update'), 'settings' => array('url' => '%^settings/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_settings'), 'logs' => array('url' => '%^logs/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_logs'), 'login' => array('url' => '%^login/?\\z%', 'controller' => 'SiteHandler', 'action' => 'display_login'), 'logout' => array('url' => '%^logout/?\\z%', 'controller' => 'SiteHandler', 'action' => 'do_logout'), '404' => array('url' => '/\\A.*$/', 'controller' => 'SiteHandler', 'action' => 'display_404'));
     // get the request parts, 404 on error
     if (!($request_parts = parse_url($_SERVER['REQUEST_URI']))) {
         trigger_error('Unable to parse the request URI.', E_USER_ERROR);
         return $routes['404'];
     }
     // format the request url before matching
     $base_path = parse_url(Options::get('base_url'), PHP_URL_PATH);
     $request_url = substr($request_parts['path'], strlen($base_path));
     // match a route
     foreach ($routes as $route) {
         if (preg_match($route['url'], $request_url, $route['params']) == 1) {
             // remove numeric keys
             foreach (array_keys($route['params']) as $k) {
                 if (is_int($k)) {
                     unset($route['params'][$k]);
                 }
             }
             if (isset($request_parts['query'])) {
                 parse_str($request_parts['query'], $query_params);
                 $route['params'] = array_merge($route['params'], $query_params);
             }
             return $route;
         }
     }
     return $routes['404'];
 }
 /**
  * Create the bookmarklet that is appropriate for the client's User Agent
  *
  * @return array The array of actions to attach to the specified $plugin_id
  */
 private function get_bookmarklet()
 {
     $admin_url = Site::get_url('admin');
     $link_name = Options::get('title');
     $bookmarklet = "\n\t\t<p>Bookmark this link to leave the page when quoting:\n\t\t<a href=\"javascript:var w=window,d=document,gS='getSelection';location.href='{$admin_url}/publish?quote='+encodeURIComponent((''+(w[gS]?w[gS]():d[gS]?d[gS]():d.selection.createRange().text)).replace(/(^\\s+|\\s+\$)/g,''))+'&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(d.title);\">Quote on {$link_name}</a>\n\t\t<br>\n\t\tBookmark this link to open a new tab or window when quoting:\n\t\t<a href=\"javascript:var w=window,d=document,gS='getSelection';window.open('{$admin_url}/publish?quote='+encodeURIComponent((''+(w[gS]?w[gS]():d[gS]?d[gS]():d.selection.createRange().text)).replace(/(^\\s+|\\s+\$)/g,''))+'&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(d.title));void(0);\">Quote on {$link_name}</a>\n\t\t</p>";
     return $bookmarklet;
 }
 public function filter_dash_module_123linkit($module, $module_id, $theme)
 {
     $module['title'] = _t('123LinkIt', 'linkit');
     $theme->status_data = Options::get('linkit__stats', array(_t('Status', 'linkit') => _t('Queued', 'linkit')));
     $module['content'] = $theme->fetch('dash_status');
     return $module;
 }
Exemple #24
0
 /**
  * Plugin init action, executed when plugins are initialized.
  */
 public function action_init()
 {
     $this->class_name = strtolower(get_class($this));
     foreach ($this->default_options as $name => $unused) {
         $this->config[$name] = Options::get($this->class_name . '__' . $name);
     }
 }
 /**
  * Do any wrapper-like things to the Atom feed proper.
  * @param SimpleXMLElement $xml the Atom feed document
  * @return SimpleXMLElement the modified Atom feed document
  */
 public function action_atom_create_wrapper($xml)
 {
     if ($iconurl = Options::get('atomicon_iconurl')) {
         $xml->addChild('icon', $iconurl);
     }
     return $xml;
 }
 /**
  * Handles get requests for the dashboard
  * @todo update check should probably be cron'd and cached, not re-checked every load
  */
 public function get_dashboard()
 {
     // Not sure how best to determine this yet, maybe set an option on install, maybe do this:
     $firstpostdate = DB::get_value('SELECT min(pubdate) FROM {posts} WHERE status = ?', array(Post::status('published')));
     $this->theme->active_time = HabariDateTime::date_create($firstpostdate);
     // get the active theme, so we can check it
     // @todo this should be worked into the main Update::check() code for registering beacons
     $active_theme = Themes::get_active();
     $active_theme = $active_theme->name . ':' . $active_theme->version;
     // check to see if we have updates to display
     $this->theme->updates = Options::get('updates_available', array());
     // collect all the stats we display on the dashboard
     $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'page_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('published'))), 'entry_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total(Comment::STATUS_APPROVED, false), 'tag_count' => Tags::vocabulary()->count_total(), 'page_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('page'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'entry_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('entry'), 'status' => Post::status('draft'), 'user_id' => User::identify()->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_UNAPPROVED, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_UNAPPROVED), 'spam_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total(Comment::STATUS_SPAM, false) : Comments::count_by_author(User::identify()->id, Comment::STATUS_SPAM), 'user_entry_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => User::identify()->id)));
     $this->fetch_dashboard_modules();
     // check for first run
     $u = User::identify();
     if (!isset($u->info->experience_level)) {
         $this->theme->first_run = true;
         $u->info->experience_level = 'user';
         $u->info->commit();
     } else {
         $this->theme->first_run = false;
     }
     $this->display('dashboard');
 }
 public function filter_post_content_out($content, $post)
 {
     $option = Options::get('acronyms__acronyms');
     // if option is empty, populate it with the defaults
     if (empty($option)) {
         $this->action_plugin_activation(null);
         $option = Options::get('acronyms__acronyms');
     }
     $option = explode("\n", $option);
     $acronyms = array();
     foreach ($option as $line) {
         $line = explode('||', $line);
         if (count($line) < 2) {
             continue;
         }
         $acronyms[$line[0]] = $line[1];
     }
     $content = " {$content} ";
     foreach ($acronyms as $acronym => $text) {
         $text = trim($text);
         $preg_acronym = preg_quote($acronym, '|');
         $content = preg_replace('|(?!<[^<>]*?)(?<![?.&])\\b' . $preg_acronym . '(?!\\w)(?!:)(?![^<>]*?>)|msU', "<abbr title=\"{$text}\">{$acronym}</abbr>", $content);
     }
     $content = trim($content);
     return $content;
 }
 /**
  * Failsafe, if $theme->switcher() was not called, display the template in the footer.
  * If you enabled it.
  */
 function theme_footer($theme)
 {
     if (!$this->shown && Options::get('themeswitcher__show')) {
         $this->shown = true;
         return $theme->fetch('switcher');
     }
 }
 public function action_post_update_before($post)
 {
     $aliases = self::get_aliases();
     if (Options::get('tagrewriter__plurals') != NULL && Options::get('tagrewriter__plurals') == 1) {
         $pluralize = true;
     } else {
         $pluralize = false;
     }
     $tags = array();
     foreach ($post->tags as $tag) {
         if (isset($aliases[$tag])) {
             $tags[] = $aliases[$tag];
             continue;
         }
         if ($pluralize) {
             if (Tags::get_by_slug($tag . 's') != false) {
                 $tags[] = $tag . 's';
                 continue;
             } elseif (Tags::get_by_slug(rtrim($tag, 's')) != false) {
                 $tags[] = rtrim($tag, 's');
                 continue;
             }
         }
         $tags[] = $tag;
     }
     $post->tags = $tags;
 }
 public function filter_post_content($content, Post $post)
 {
     if ($post->info->password) {
         // if user logged in, show post
         // make sure it's not just the anonymous user!
         $user = User::identify();
         if ($user instanceof User && $user != User::anonymous()) {
             return $content;
         }
         $session = Session::get_set('post_passwords', false);
         $token = Utils::crypt('42' . $post->info->password . $post->id . Options::get('GUID'));
         // if password was submitted verify it
         if (Controller::get_var('post_password') && Controller::get_var('post_password_id') == $post->id) {
             $pass = InputFilter::filter(Controller::get_var('post_password'));
             if (Utils::crypt($pass, $post->info->password)) {
                 Session::add_to_set('post_passwords', $token, $post->id);
                 $session[$post->id] = $token;
             } else {
                 Session::error(_t('That password was incorrect.', 'postpass'));
             }
         }
         // if password is stored in session verify it
         if (isset($session[$post->id]) && $session[$post->id] == $token) {
             return $content;
         } else {
             $theme = Themes::create();
             $theme->post = $post;
             return $theme->fetch('post_password_form');
         }
     } else {
         return $content;
     }
 }