/** * Add appropriate CSS to this plugin's configuration form */ public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); if ($theme->admin_page == 'plugins' && isset($vars['configure']) && $vars['configure'] === $this->plugin_id) { Stack::add('admin_stylesheet', array($this->get_url() . '/metaseo.css', 'screen')); } }
/** * 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; }
/** * Add additional controls to the publish page tab * * @param FormUI $form The form that is used on the publish page * @param Post $post The post being edited */ public function action_form_publish($form, $post) { // If quote has been sent in the URL, insert the quote data in the post $this->handler_vars = Controller::get_handler_vars(); if (array_key_exists('quote', $this->handler_vars)) { $form->title->value = $this->handler_vars['title']; // Get the user so that we can grab the saved templates and tags $user = User::identify(); $title = $user->info->title__template; if (!$title) { $title = self::$default_title_template; } // Filter the quote title using the title template $form->title->value = preg_replace_callback('%\\{\\$(.+?)\\}%', array(&$this, 'replace_parts'), $title); // Only change the slug if the template is set. For example, you might have HTML in the title. $slug = $user->info->slug__template; if ($slug) { // Filter the quote title using the title template $form->newslug->value = preg_replace_callback('%\\{\\$(.+?)\\}%', array(&$this, 'replace_parts'), $slug); } $content = $user->info->content__template; if (!$content) { $content = self::$default_content_template; } // Filter the quote content using the content template $form->content->value = preg_replace_callback('%\\{\\$(.+?)\\}%', array(&$this, 'replace_parts'), $content); // Add tags for quotes $tags = $user->info->quote__tags; if ($tags) { $form->tags->value = $tags; } } }
public function filter_theme_act_display_home($handled, $theme) { $vars = Controller::get_handler_vars(); if (empty($vars['page'])) { $page = Options::get('criticalhit__home'); if ($page && $page != '--none--') { $post = Post::get(array('slug' => $page)); $theme->act_display(array('posts' => $post)); return true; } } return false; }
public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); $js_xid2def = ''; if ($theme->page == 'plugins' && isset($vars['configure']) && $this->plugin_id == $vars['configure']) { Stack::add('admin_stylesheet', array($this->get_url() . '/macros.css', 'screen'), 'macros', array('admin')); $macros = DB::get_results('SELECT * FROM ' . DB::table('macro') . ' ORDER BY name ASC'); $js_xid2def .= "\n \$(document).ready(function(){\n" . " mDefs = [];\n" . " mDefs[0] = ['', false, false, 0, '', ''];\n"; foreach ($macros as $macro) { $xid = $macro->xid; $nargs = $macro->nargs; $enabled = $macro->enabled; $name = HTMLentities("'" . $macro->name . "'"); $desc = HTMLentities("'" . $macro->description . "'"); $def = HTMLentities("'" . $macro->definition . "'"); $container = $macro->container ? 'true' : 'false'; $eval = $macro->eval ? 'true' : 'false'; $js_xid2def .= " mDefs[{$xid}] = [" . $name . ', ' . $enabled . ', ' . $container . ', ' . $eval . ', ' . $nargs . ', ' . $desc . ', ' . $def . "];\n"; } $js_xid2def .= " \$('#mName select')" . ".change(function(){\n" . " mNum = \$(this).val();\n" . " \$('#mEnabled input[type=\"checkbox\"]')" . ".attr('checked', mDefs[mNum][1]);\n" . " \$('#mDefinition input').val(\$('<input value=\"' + mDefs[mNum][6] + '\"/>').val());\n" . " \$('#mContainer input[type=\"checkbox\"]')" . ".attr('checked', mDefs[mNum][2]);\n" . " \$('#mEval input[type=\"checkbox\"]')" . ".attr('checked', mDefs[mNum][3]);\n" . " \$('#mNargs input[type=\"text\"]')" . ".val(\$('<input value=\"' + mDefs[mNum][4] + '\"/>').val());\n" . " \$('#mDescription input[type=\"text\"]')" . ".val(\$('<input value=\"' + mDefs[mNum][5] + '\"/>').val());\n" . " \$('#mDefinition input[type=\"text\"]')" . ".val(\$('<input value=\"' + mDefs[mNum][6] + '\"/o>').val())});\n" . " })\n"; Stack::add('admin_header_javascript', $js_xid2def, 'macros', 'admin'); } }
public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); if ($theme->page == 'plugins' && isset($vars['configure']) && $this->plugin_id == $vars['configure']) { Stack::add('admin_stylesheet', array($this->get_url() . '/abbrev.css', 'screen'), 'abbrev', array('admin')); Stack::add('template_header_javascript', $this->get_url() . '/abbrev.js', 'abbrev'); $abbrevs = $this->_getAbbrevs(); if ($n = count($abbrevs)) { $js_xid2def .= "\n \$(document).ready(function(){\n" . " function aDef(abbrev_p, definition_p, caseful_p, prefix_p, postfix_p) {\n" . " this.abbrev = abbrev_p;\n" . " this.definition = definition_p;\n" . " this.caseful = caseful_p;\n" . " this.prefix = prefix_p;\n" . " this.postfix = postfix_p;\n" . " }\n" . " aDefs = [];\n"; foreach ($abbrevs as $abbrev) { $prefix = "'" . $abbrev->prefix . "'"; $postfix = "'" . $abbrev->postfix . "'"; $prefix = str_replace('\\', '\\\\', $prefix); $prefix = str_replace('"', '\\"', $prefix); $postfix = str_replace('\\', '\\\\', $postfix); $postfix = str_replace('"', '\\"', $postfix); $js_xid2def .= ' aDefs[' . $abbrev->xid . '] = new aDef(' . $this->qsafe($abbrev->abbrev, true) . $this->qsafe($abbrev->definition, true) . ($abbrev->caseful ? 'true' : 'false') . ', ' . $this->qsafe($prefix, true) . $this->qsafe($postfix) . ");\n"; } $js_xid2def .= " \$('#mAbbrev select')" . ".change(function(){\n" . " aNum = \$(this).val();\n" . " \$('#mDefinition input').val(\$('<input value=\"' + aDefs[aNum].definition + '\"/>').val());\n" . " \$('#mCaseful input[type=\"checkbox\"]')" . ".attr('checked', aDefs[aNum].caseful);\n" . " \$('#mPreRegex input[type=\"text\"]')" . ".val(\$('<input value=\"' + aDefs[aNum].prefix + '\"/>').val());\n" . " \$('#mPostRegex input[type=\"text\"]')" . ".val(\$('<input value=\"' + aDefs[aNum].postfix + '\"/>').val())});\n" . " })\n"; Stack::add('admin_header_javascript', $js_xid2def, 'abbrev', 'admin'); } } }
/** * function filter_template_where_filters * Limit the Posts::get call to categories * (uses tag_slug because that's really term under the hood) **/ public function filter_template_where_filters($filters) { $vars = Controller::get_handler_vars(); if (isset($vars['category_slug'])) { $labels = explode('/', $vars['category_slug']); $level = count($labels) - 1; $term = $this->get_term($labels, $level); // $term = $this->vocabulary->get_term( $vars['category_slug'] ); if ($term instanceof Term) { $terms = (array) $term->descendants(); array_push($terms, $term); $filters['vocabulary'] = array_merge($filters['vocabulary'], array('any' => $terms)); } } return $filters; }
/** * 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; }
public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); if ('plugins' == $theme->page && isset($vars['configure']) && $this->plugin_id == $vars['configure']) { } }
/** * Grabs post data and inserts that data into the internal * handler_vars array, which eventually gets extracted into * the theme's ( and thereby the template_engine's ) local * symbol table for use in the theme's templates * * This is the default, generic function to grab posts. To * "filter" the posts retrieved, simply pass any filters to * the handler_vars variables associated with the post retrieval. * For instance, to filter by tag, ensure that handler_vars['tag'] * contains the tag to filter by. Simple as that. */ public function act_display($paramarray = array('user_filters' => array())) { Utils::check_request_method(array('GET', 'HEAD', 'POST')); // Get any full-query parameters $possible = array('user_filters', 'fallback', 'posts', 'post', 'content_type'); foreach ($possible as $varname) { if (isset($paramarray[$varname])) { ${$varname} = $paramarray[$varname]; } } /** * Since handler_vars no longer contains $_GET and $_POST, we have broken out our valid filters into * an array based upon where we should expect them to be. We then only merge those specific pieces together. * * These are ordered so that handler vars gets overwritten by POST, which gets overwritten by GET, should the * same key exist multiple places. This seemed logical to me at the time, but needs further thought. */ $where_filters = array(); $where_filters_hv = Controller::get_handler_vars()->filter_keys($this->valid_filters['handler_vars']); $where_filters_post = $_POST->filter_keys($this->valid_filters['POST']); $where_filters_get = $_GET->filter_keys($this->valid_filters['GET']); $where_filters = $where_filters_hv->merge($where_filters_post, $where_filters_get); $where_filters['vocabulary'] = array(); if (array_key_exists('tag', $where_filters)) { $tags = Tags::parse_url_tags($where_filters['tag']); $not_tag = $tags['exclude_tag']; $all_tag = $tags['include_tag']; if (count($not_tag) > 0) { $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':not:term' => $not_tag)); } if (count($all_tag) > 0) { $where_filters['vocabulary'] = array_merge($where_filters['vocabulary'], array(Tags::vocabulary()->name . ':all:term' => $all_tag)); } $where_filters['tag_slug'] = Utils::slugify($where_filters['tag']); unset($where_filters['tag']); } if (!isset($_GET['preview'])) { $where_filters['status'] = Post::status('published'); } if (!isset($posts)) { $user_filters = Plugins::filter('template_user_filters', $user_filters); // Work around the tags parameters to Posts::get() being subsumed by the vocabulary parameter if (isset($user_filters['not:tag'])) { $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':not:term' => $user_filters['not:tag']); unset($user_filters['not:tag']); } if (isset($user_filters['tag'])) { $user_filters['vocabulary'] = array(Tags::vocabulary()->name . ':term_display' => $user_filters['tag']); unset($user_filters['tag']); } $where_filters = $where_filters->merge($user_filters); $where_filters = Plugins::filter('template_where_filters', $where_filters); $posts = Posts::get($where_filters); } $this->assign('posts', $posts); if ($posts !== false && count($posts) > 0) { if (count($posts) == 1) { $post = $posts instanceof Post ? $posts : reset($posts); Stack::add('body_class', Post::type_name($post->content_type) . '-' . $post->id); Stack::add('body_class', 'single'); } else { $post = reset($posts); Stack::add('body_class', 'multiple'); } $this->assign('post', $post); $type = Post::type_name($post->content_type); } elseif ($posts === false || isset($where_filters['page']) && $where_filters['page'] > 1 && count($posts) == 0) { if ($this->template_exists('404')) { $fallback = array('404'); // Replace template variables with the 404 rewrite rule $this->request->{URL::get_matched_rule()->name} = false; $this->request->{URL::set_404()->name} = true; $this->matched_rule = URL::get_matched_rule(); // 404 status header sent in act_display_404, but we're past // that, so send it now. header('HTTP/1.1 404 Not Found', true, 404); } else { $this->display('header'); echo '<h2>'; _e("Whoops! 404. The page you were trying to access is not really there. Please try again."); echo '</h2>'; header('HTTP/1.1 404 Not Found', true, 404); $this->display('footer'); die; } } $extract = $where_filters->filter_keys('page', 'type', 'id', 'slug', 'posttag', 'year', 'month', 'day', 'tag', 'tag_slug'); foreach ($extract as $key => $value) { ${$key} = $value; } $this->assign('page', isset($page) ? $page : 1); if (!isset($fallback)) { // Default fallbacks based on the number of posts $fallback = array('{$type}.{$id}', '{$type}.{$slug}', '{$type}.tag.{$posttag}'); if (count($posts) > 1) { $fallback[] = '{$type}.multiple'; $fallback[] = 'multiple'; } else { $fallback[] = '{$type}.single'; $fallback[] = 'single'; } } $searches = array('{$id}', '{$slug}', '{$year}', '{$month}', '{$day}', '{$type}', '{$tag}'); $replacements = array(isset($post) && $post instanceof Post ? $post->id : '-', isset($post) && $post instanceof Post ? $post->slug : '-', isset($year) ? $year : '-', isset($month) ? $month : '-', isset($day) ? $day : '-', isset($type) ? $type : '-', isset($tag_slug) ? $tag_slug : '-'); $fallback[] = 'home'; $fallback = Plugins::filter('template_fallback', $fallback, $posts, isset($post) ? $post : null); $fallback = array_values(array_unique(MultiByte::str_replace($searches, $replacements, $fallback))); for ($z = 0; $z < count($fallback); $z++) { if (MultiByte::strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) { $replacements = array(); if ($alltags = $post->tags) { foreach ($alltags as $current_tag) { $replacements[] = MultiByte::str_replace('{$posttag}', $current_tag->term, $fallback[$z]); } array_splice($fallback, $z, 1, $replacements); } else { break; } } } return $this->display_fallback($fallback); }
/** * function filter_template_where_filters * Limit the Posts::get call to shelves * (uses tag_slug because that's really term under the hood) **/ public function filter_template_where_filters($filters) { $vars = Controller::get_handler_vars(); if (isset($vars['shelf_slug'])) { $term = $this->vocabulary->get_term($vars['shelf_slug']); if ($term instanceof Term) { $terms = (array) $term->descendants(); $terms = array_map(create_function('$a', 'return $a->term;'), $terms); array_push($terms, $vars['shelf_slug']); $filters['vocabulary'] = array_merge($filters['vocabulary'], array(self::$vocabulary . ':term' => $terms)); } } return $filters; }
/** * Modify publish form */ public function action_form_publish($form, $post) { if ($post->content_type == Post::type('link')) { $url = $form->append('text', 'url', 'null:null', _t('URL'), 'admincontrol_text'); // CNS: If we're using this in conjunction with my modified version of the "Publish Quote" plugin, we might already have the URL in the handler_vars. $vars = Controller::get_handler_vars(); $url->value = isset($vars['url']) ? $vars['url'] : $post->info->url; $form->move_after($url, $form->title); } }
/** * action: ajax_amazon_search * * @access public * @return void */ public function action_before_act_admin_ajax() { $handler_vars = Controller::get_handler_vars(); switch ($handler_vars['context']) { case 'amazon_search': if (empty($handler_vars['keywords'])) { echo json_encode(array('errorMessage' => _t('please specify keywords.'))); die; } if (empty($handler_vars['search_index'])) { echo json_encode(array('errorMessage' => _t('please specify searchIndex.'))); die; } $keywords = InputFilter::filter($handler_vars['keywords']); $search_index = InputFilter::filter($handler_vars['search_index']); if (empty($handler_vars['page'])) { $page = 1; } else { $page = InputFilter::filter($handler_vars['page']); } $result = $this->item_search($keywords, $search_index, $page); $xml = simplexml_load_string($result); if ((string) $xml->Items->Request->IsValid != 'True') { echo json_encode(array('errorMessage' => _t('following error reply existed from the server: ', 'amazon') . (string) $xml->Items->Request->Errors->Error->Message)); die; } if ((int) $xml->Items->TotalResults == 0) { echo json_encode(array('errorMessage' => _t('did not match any items.', 'amazon'))); die; } $output = array(); $output['TotalResults'] = (int) $xml->Items->TotalResults; $output['TotalPages'] = (int) $xml->Items->TotalPages; $output['CurrentPage'] = $page; $output['Start'] = ($page - 1) * 10 + 1; $output['End'] = $output['Start'] + 10; if ($output['End'] > $output['TotalResults']) { $output['End'] = $output['TotalResults']; } $output['HasPrev'] = false; $output['HasNext'] = false; if ($page != 1) { $output['HasPrev'] = true; } if ($page < $output['TotalPages']) { $output['HasNext'] = true; } $output['Items'] = array(); for ($i = 0; $i < count($xml->Items->Item); $i++) { $item = array(); $item['ASIN'] = (string) $xml->Items->Item[$i]->ASIN; $item['DetailPageURL'] = (string) $xml->Items->Item[$i]->DetailPageURL; $item['SmallImageURL'] = (string) $xml->Items->Item[$i]->SmallImage->URL; $item['SmallImageWidth'] = (int) $xml->Items->Item[$i]->SmallImage->Width; $item['SmallImageHeight'] = (int) $xml->Items->Item[$i]->SmallImage->Height; $item['Title'] = (string) $xml->Items->Item[$i]->ItemAttributes->Title; $item['Price'] = (string) $xml->Items->Item[$i]->ItemAttributes->ListPrice->FormattedPrice; $item['Binding'] = (string) $xml->Items->Item[$i]->ItemAttributes->Binding; $output['Items'][] = $item; } echo json_encode($output); die; case 'amazon_insert': if (empty($handler_vars['asin'])) { echo json_encode(array('errorMessage' => _t('please specify ASIN.', 'amazon'))); die; } $asin = InputFilter::filter($handler_vars['asin']); $result = $this->item_lookup($asin); $xml = simplexml_load_string($result); if ((string) $xml->Items->Request->IsValid != 'True') { echo json_encode(array('errorMessage' => _t('following error reply existed from the server: ', 'amazon') . (string) $xml->Items->Request->Errors->Error->Message)); die; } $item =& $xml->Items->Item; ob_start(); $template = preg_replace('/[^A-Za-z0-9\\-\\_]/', '', Options::get('amazon__template')); include dirname($this->get_file()) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.php'; $output['html'] = ob_get_contents(); ob_end_clean(); echo json_encode($output); //echo $output['html']; die; default: break; } }
/** * 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 ); }
/** * Adds the podcast stylesheet to the admin header, * Adds menu items to the Habari silo for mp3 files * for each feed so the mp3 can be added to multiple * feeds. * * @param Theme $theme The current theme being used. */ public function action_admin_header( $theme ) { $vars = Controller::get_handler_vars(); if( 'dashboard' == $theme->page ) { Stack::add( 'admin_stylesheet', array( $this->get_url() . '/coredashmodules.css', 'screen' ), 'coredashmodules', array( 'admin' ) ); } }
public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); if ($theme->admin_page == 'themes') { // This hook is only fired if this theme is active anyway. Stack::add('admin_stylesheet', array($this->get_url() . '/css/config.css', 'screen')); Stack::add('admin_stylesheet', array($this->get_url() . '/colorpicker/colorpicker.css', 'screen')); Stack::add('admin_header_javascript', $this->get_url() . '/colorpicker/colorpicker.js', 'colorpicker'); Stack::add('admin_header_javascript', $this->get_url() . '/js/config.js', 'configjs'); $configured = Options::get('darkautumn__configured') ? true : false; if (!$configured) { $this->set_default_options(); } } }
public function action_admin_header($theme) { $vars = Controller::get_handler_vars(); if ($theme->admin_page == 'plugins' && isset($vars['configure']) && $vars['configure'] === $this->plugin_id) { Stack::add('admin_stylesheet', array($this->get_url(true) . 'admin.css', 'screen'), 'picasa-silo-admin-css', 'admin'); } Stack::add('admin_header_javascript', $this->get_url(true) . 'picasasilo.js', 'picasasilo', 'jquery'); // Add the AJAX callback URL. $url = 'picasagallery.url=\'' . URL::get('auth_ajax', array('context' => 'picasagallery')) . '\''; Stack::add('admin_header_javascript', $url, 'picasasilo_url', 'picasasilo'); }
/** * theme: show_calendar * * @access public * @param object $theme * @return string */ public function theme_show_calendar($theme) { $handler_vars = Controller::get_handler_vars(); if (Controller::get_action() == 'display_date' && isset($handler_vars['month'])) { $year = (int) $handler_vars['year']; $month = (int) $handler_vars['month']; } else { $year = date('Y'); $month = date('m'); } $next_year = $year; $prev_year = $year; $next_month = $month + 1; $prev_month = $month - 1; if ($next_month == 13) { $next_month = 1; $next_year++; } if ($prev_month == 0) { $prev_month = 12; $prev_year--; } $start_time = mktime(0, 0, 0, $month, 1, $year); $end_time = mktime(0, 0, 0, $next_month, 1, $next_year); $t_posts_day = DB::get_column('SELECT pubdate FROM {posts} WHERE pubdate >= ? AND pubdate < ? AND status = ?', array($start_time, $end_time, Post::status('published'))); $posts_day = array(); @reset($t_posts_day); while (list(, $pubdate) = @each($t_posts_day)) { $posts_day[] = (int) date("j", $pubdate); } $month_start_week = date("w", $start_time); $month_days = date("t", $start_time); $week_days = array(_t('Sun', 'calendar'), _t('Mon', 'calendar'), _t('Tue', 'calendar'), _t('Wed', 'calendar'), _t('Thu', 'calendar'), _t('Fri', 'calendar'), _t('Sat', 'calendar')); $week_start = Options::get('calendar__week_start'); $calendar = array(); $day = 0; while (1) { $week = array(); for ($i = 0; $i < 7; $i++) { $wday = ($i + $week_start) % 7; if (count($calendar) == 0) { $week[] = array('label' => $week_days[($i + $week_start) % 7]); continue; } elseif ($day == 0) { if ($wday == $month_start_week) { $day = 1; if (array_search($day, $posts_day) !== false) { $week[] = array('label' => $day, 'url' => URL::get('display_entries_by_date', array('year' => $year, 'month' => sprintf('%02d', $month), 'day' => sprintf('%02d', $day)))); } else { $week[] = array('label' => $day); } } else { $week[] = array('label' => null); continue; } } elseif ($day >= $month_days) { $week[] = array('label' => null); continue; } else { $day++; if (array_search($day, $posts_day) !== false) { $week[] = array('label' => $day, 'url' => URL::get('display_entries_by_date', array('year' => $year, 'month' => sprintf('%02d', $month), 'day' => sprintf('%02d', $day)))); } else { $week[] = array('label' => $day); } } } $calendar[] = $week; if ($day == $month_days) { break; } } $theme->year = $year; $theme->month = $month; $theme->prev_month_url = URL::get('display_entries_by_date', array('year' => $prev_year, 'month' => sprintf('%02d', $prev_month))); $theme->next_month_url = URL::get('display_entries_by_date', array('year' => $next_year, 'month' => sprintf('%02d', $next_month))); $theme->calendar = $calendar; return $theme->fetch('calendar'); }
public function act_display_lifestream() { $vars = Controller::get_handler_vars(); $this->fetch_feeds(); if (!isset($vars['type'])) { $vars['type'] = 'any'; } if (!isset($vars['page'])) { $vars['page'] = 0; } $offset = $vars['page'] * Options::get('lifestream__perpage'); $this->theme->assign('lifestream', LifeStream::get_entries($vars['type'], $offset, Options::get('lifestream__perpage'))); $this->theme->assign('title', 'Lifestream - ' . Options::get('title')); $this->theme->assign('streams', $this->config->stream); $this->theme->display('lifestream'); $this->theme->fetch('lifestream_template'); }
/** * Filter the parameters being passed to Posts::get() * * @param array $filters The parameters to be passed to Posts::get() * * @return array The updated parameters */ public function filter_template_where_filters($filters) { $vars = Controller::get_handler_vars(); if (strlen($vars['entire_match']) && strpos($vars['entire_match'], 'podcast/') !== FALSE && isset($vars['podcast_name'])) { $filters['where'] = "{posts}.id in ( select post_id from {postinfo} where name = '{$vars['podcast_name']}' )"; } if (isset($filters['content_type'])) { $types = Utils::single_array($filters->offsetGet('content_type')); $types[] = Post::type('podcast'); $filters->offsetSet('content_type', $types); } return $filters; }
/** * The plugin sink for the auth_ajax_mt_import_trackbacks hook. * Responds via authenticated ajax to requests for comment importing. * * @access public * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_mt_mysql_import_trackbacks($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'blog_id', 'trackbackindex'); $inputs = Controller::get_handler_vars()->filter_keys($valid_fields)->getArrayCopy(); extract($inputs); $mtdb = $this->mt_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if (!$mtdb) { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; return; } $trackbackcount = $mtdb->get_value("SELECT count(trackback_id) FROM {$db_prefix}trackback WHERE trackback_blog_id = '{$blog_id}';"); $min = $trackbackindex * $this->import_batch + 1; $max = min(($trackbackindex + 1) * $this->import_batch, $trackbackcount); echo sprintf(_t('<p>Importing trackbacks %d-%d of %d.</p>'), $min, $max, $trackbackcount); $post_info = DB::get_results("SELECT post_id, value FROM " . DB::table('postinfo') . " WHERE name= 'mt_id';"); @reset($post_info); while (list(, $info) = @each($post_info)) { $post_map[$info->value] = $info->post_id; } $trackbacks = $mtdb->get_results("SELECT\n\t\t\ttrackback_title AS name,\n\t\t\ttrackback_url AS url,\n\t\t\ttrackback_description AS content,\n\t\t\ttrackback_created_on AS date,\n\t\t\ttrackback_entry_id AS mt_post_id,\n\t\t\ttrackback_id,\n\t\t\ttrackback_is_disabled\n\t\t\tFROM {$db_prefix}trackback\n\t\t\tWHERE trackback_blog_id = '{$blog_id}'\n\t\t\tLIMIT {$min}," . $this->import_batch, array(), 'Comment'); $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_trackback_id';"); @reset($trackbacks); while (list(, $trackback) = @each($trackback)) { // already exists skipped if (in_array($trackback->trackback_id, $comment_map)) { continue; } $trackback->type = Comment::TRACKBACK; $carray = $trackback->to_array(); $carray['ip'] = 0; if ($carray['trackback_is_disabled'] == 0) { $carray['status'] = Comment::STATUS_APPROVED; } else { $carray['status'] = Comment::STATUS_UNAPPROVED; } unset($carray['trackback_is_disabled']); if (!isset($post_map[$carray['mt_post_id']])) { Utils::debug($carray); } else { $carray['post_id'] = $post_map[$carray['wp_post_id']]; unset($carray['mt_post_id']); $trackback_id = $carray['trackback_id']; unset($carray['trackback_id']); $c = new Comment($carray); $c->info->mt_trackback_id = $trackback_id; try { $c->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } if ($max < $trackbackcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'mt_mysql_import_trackbacks')); $trackbackindex++; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } return; } ?> <script type="text/javascript"> $( '#import_progress' ).load( "<?php echo $ajax_url; ?> ", { db_host: "<?php echo htmlspecialchars($db_host); ?> ", db_name: "<?php echo htmlspecialchars($db_name); ?> ", db_user: "******", db_pass: "******", db_prefix: "<?php echo htmlspecialchars($db_prefix); ?> ", blog_id: "<?php echo htmlspecialchars($blog_id); ?> ", trackbackindex: <?php echo $trackbackindex; ?> } ); </script> <?php }
/** * action: before_act_admin_ajax * * @access public * @return void */ public function action_before_act_admin_ajax() { $handler_vars = Controller::get_handler_vars(); switch ($handler_vars['context']) { case 'fireeagle_update': $user = User::identify(); $access_token = Options::get('fireeagle__access_token_' . $user->id); $access_token_secret = Options::get('fireeagle__access_token_secret_' . $user->id); if (empty($access_token) || empty($access_token_secret)) { echo json_encode(array('errorMessage' => _t('Authorize is not done!', 'fireeagle'))); die; } $fireeagle = new FireEagleAPI($this->consumer_key, $this->consumer_secret, $access_token, $access_token_secret); try { $result = $fireeagle->update(array('address' => $handler_vars['location'])); } catch (FireEagleException $e) { echo json_encode(array('errorMessage' => $e->getMessage())); die; } if (!is_object($result) || $result->stat != 'ok') { echo json_encode(array('errorMessage' => _t('Update failed.', 'fireeagle'))); die; } // refresh location if (!$this->update((int) $user->id)) { echo json_encode(array('errorMessage' => _t('Update failed.', 'fireeagle'))); die; } $location = ''; if (isset($user->info->fireeagle_location)) { $location = $user->info->fireeagle_location; } echo json_encode(array('location' => $location, 'message' => sprintf(_t('Your present place was updated to "%s".', 'fireeagle'), $location))); die; default: break; } }
/** * Handle the requested action by firing off the matched handler action(s) */ public static function dispatch_request() { /* OK, set the wheels in motion... */ Plugins::act('handler_' . Controller::instance()->action, Controller::get_handler_vars()); if (method_exists(Controller::instance()->handler, 'act')) { Controller::instance()->handler->act(Controller::instance()->action); } }
public function theme_footer($theme) { if (count(self::$handler_vars) === 0) { self::$handler_vars = Controller::get_handler_vars(); } // If 'slug' exists, then it must be single, don't do anything if (!isset(self::$handler_vars['slug'])) { // If jQuery is loaded in header, then do not load it again if (!Stack::has('template_header_javascript', 'jquery')) { Stack::add('template_footer_javascript', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', 'jquery'); } $params = new SuperGlobal($this->config); $params = $params->merge(self::$handler_vars); Stack::add('template_footer_javascript', URL::get('display_pageless_js', array('config' => md5(serialize($params)))), 'jquery.pageless', 'jquery'); } }