public function action_plugin_act_display_reviews($handler) { $paramarray['fallback'] = array('review.multiple', 'entry.multiple', 'multiple', 'home'); $default_filters = array('content_type' => Post::type('review')); $paramarray['user_filters'] = $default_filters; return $handler->theme->act_display($paramarray); }
/** * Add some variables to the template output */ public function add_template_vars() { // Use theme options to set values that can be used directly in the templates // Don't check for constant values in the template code itself $this->assign('show_title_image', self::SHOW_TITLE_IMAGE); $this->assign('home_label', self::HOME_LABEL); $this->assign('show_powered', self::SHOW_POWERED); $this->assign('display_login', self::DISPLAY_LOGIN); $this->assign('tags_in_multiple', self::TAGS_IN_MULTIPLE); $this->assign('post_class', 'post' . (!self::SHOW_ENTRY_PAPERCLIP ? ' alt' : '')); $this->assign('page_class', 'post' . (!self::SHOW_PAGE_PAPERCLIP ? ' alt' : '')); $this->assign('show_post_nav', self::SHOW_POST_NAV); $locale = Options::get('locale'); if (file_exists(Site::get_dir('theme', true) . $locale . '.css')) { $this->assign('localized_css', $locale . '.css'); } else { $this->assign('localized_css', false); } if (!$this->template_engine->assigned('pages')) { $this->assign('pages', Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1))); } $this->assign('post_id', isset($this->post) && $this->post->content_type == Post::type('page') ? $this->post->id : 0); // Add FormUI template placing the input before the label $this->add_template('charcoal_text', dirname(__FILE__) . '/formcontrol_text.php'); parent::add_template_vars(); }
public function add_template_vars() { //TODO: Fully support localization; //theme configuration $this->assign('da_feedtext', $this->options['darkautumn__feedtext']); $this->assign('da_maintenancetitle', $this->options['darkautumn__maintenancetitle']); $this->assign('da_blurbtext', $this->options['darkautumn__blurbtext']); $this->assign('da_sidenotes_tag', $this->options['darkautumn__sidenotestag']); $this->base_url = Site::get_url('habari'); //TODO: use assign instead $this->theme_url = Site::get_url('theme'); //TODO: use assign instead if (!$this->posts) { $this->posts = Posts::get(array('content_type' => 'entry', 'status' => Post::status('published'))); } if (!$this->pages) { $this->assign('pages', Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1))); } if (!$this->sidenotes) { $this->assign('sidenotes', Posts::get(array('tag' => $this->options['darkautumn__sidenotestag'], 'limit' => 5))); } if (!$this->page) { $this->page = isset($page) ? $page : 1; //TODO: use assign instead } $this->assign('post_id', isset($this->post) && $this->post->content_type == Post::type('page') ? $this->post->id : 0); parent::add_template_vars(); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @access protected */ protected function module_setup() { $user = User::get_by_name( 'posts_test' ); if ( !$user ) { $user = User::create( array ( 'username'=>'posts_test', 'email'=>'*****@*****.**', 'password'=>md5('q' . rand( 0,65535 ) ), ) ); } $this->user = $user; $post = Post::create( array( 'title' => 'Test Post', 'content' => 'These tests expect there to be at least one post.', 'user_id' => $user->id, 'status' => Post::status( 'published' ), 'content_type' => Post::type( 'entry' ), ) ); $this->post_id = $post->id; $this->paramarray = array( 'id' => 'foofoo', 'post_id' => $this->post_id, 'name' => 'test', 'email' => '*****@*****.**', 'url' => 'http://example.org', 'ip' => ip2long('127.0.0.1'), 'content' => 'test content', 'status' => Comment::STATUS_UNAPPROVED, 'date' => HabariDateTime::date_create(), 'type' => Comment::COMMENT ); $this->comment = Comment::create( $this->paramarray ); }
/** * 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'); }
/** * 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'))); if ($firstpostdate) { $this->theme->active_time = DateTime::create($firstpostdate); } // 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 $user = User::identify(); $this->theme->stats = array('author_count' => Users::get(array('count' => 1)), 'post_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('published'))), 'comment_count' => Comments::count_total('approved', false), 'tag_count' => Tags::vocabulary()->count_total(), 'user_draft_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('draft'), 'user_id' => $user->id)), 'unapproved_comment_count' => User::identify()->can('manage_all_comments') ? Comments::count_total('unapproved', false) : Comments::count_by_author(User::identify()->id, Comment::status('unapproved')), 'spam_comment_count' => $user->can('manage_all_comments') ? Comments::count_total('spam', false) : Comments::count_by_author($user->id, Comment::status('spam')), 'user_scheduled_count' => Posts::get(array('count' => 1, 'content_type' => Post::type('any'), 'status' => Post::status('scheduled'), 'user_id' => $user->id))); // check for first run $u = User::identify(); $uinfo = $u->info; if (!isset($uinfo->experience_level)) { $this->theme->first_run = true; $u->info->experience_level = 'user'; $u->info->commit(); } else { $this->theme->first_run = false; } $this->get_additem_form(); Stack::add('admin_header_javascript', 'dashboard-js'); $this->display('dashboard'); }
public function action_form_publish($form, $post) { $selector = $form->append('wrapper', 'type_selector'); $selector->class = 'container'; // Utils::debug( 'bob' ); if (Controller::get_var('to_type') != NULL && $post->content_type != Controller::get_var('to_type')) { /* set type */ $post->content_type = Post::type(Controller::get_var('to_type')); $post->update(); Utils::redirect(URL::get('admin', 'page=publish&id=' . $post->id)); // Refresh view } foreach (Post::list_active_post_types() as $type) { if ($type != 0) { if ($post->id == 0) { $url = URL::get('admin', 'page=publish&content_type=' . Post::type_name($type)); } else { $url = URL::get('admin', 'page=publish&to_type=' . Post::type_name($type) . '&id=' . $post->id); } $html = '<a href="' . $url . '"'; if (Post::type_name($type) == $post->content_type || $type == $post->content_type) { $html .= ' class="active"'; } $html .= '>' . Post::type_name($type) . '</a>'; $selector->append('static', 'type_selector_' . $type, $html); } } $selector->move_before($selector, $form); return $form; }
public static function get_stat($type, $month = NULL) { $str = 'chicklet_stat_' . $type; if ($month != NULL) { $str .= '_' . $month; } if (Cache::has($str)) { return Cache::get($str); } switch ($type) { case 'entries': case 'posts': $params = array('content_type' => array(Post::type('entry'), Post::type('link')), 'nolimit' => TRUE); $stat = count(Posts::get($params)); break; case 'subscribers': $stat = self::fetch(); break; case 'comments': $stat = Comments::count_total(Comment::STATUS_APPROVED); break; case 'tags': $stat = count(Tags::vocabulary()->get_tree()); break; default: $stat = 0; break; } Cache::set($str, $stat); return $stat; }
/** * Respond to post requests on the admin_cctypes template * * @param AdminHandler $handler The admin handler object * @param Theme $theme The admin theme object */ function action_admin_theme_post_admin_cctypes($handler, $theme) { $action = Controller::get_var('cct_action'); switch ($action) { case 'addtype': Post::add_new_type($_POST['newtype']); $typeid = Post::type($_POST['newtype']); $handled = Options::get('cctypes_types'); if (!is_array($handled)) { $handled = array(); } $handled[$typeid] = $typeid; array_unique($handled); Options::set('cctypes_types', $handled); Session::notice(_t('Added post type "' . $_POST['newtype'] . '".')); break; case 'deletetype': $typename = Post::type_name($_POST['deltype']); Post::deactivate_post_type($_POST['deltype']); $handled = Options::get('cctypes_types'); if (isset($handled[$_POST['deltype']])) { unset($handled[$_POST['deltype']]); } Options::set('cctypes_types', $handled); Session::notice(_t('Deactivated post type "' . $typename . '".')); } Utils::redirect(); }
public function filter_post_url($url, $post) { if ($post->content_type == Post::type('urlbounce')) { return $post->info->url; } else { return $url; } }
/** * Save the photo URL in the post's postinfo * * @param Post $post The post that is being saved * @param FormUI $form The submitted publish form */ public function action_publish_post($post, $form) { if ($form->content_type->value == Post::type('entry')) { if ($form->photo->value != '') { $post->info->photo = $form->photo->value; } } }
public function filter_adminhandler_post_loadplugins_main_menu($menus) { unset($menus['create_' . Post::type('imageset')]); unset($menus['manage_' . Post::type('imageset')]); unset($menus['create_' . Post::type('image')]); unset($menus['manage_' . Post::type('image')]); unset($menus['create_' . Post::type('gallery')]); return $menus; }
public function action_form_publish(FormUI $form, Post $post) { if ($form->content_type->value == Post::type('entry')) { // add password feild to settings splitter $settings = $form->settings; $settings->append('text', 'postpass', 'null:null', _t('Password', 'postpass'), 'tabcontrol_text'); $settings->postpass->value = $post->info->password; } }
private function get_params($user_filters = array()) { $default_filters = array('content_type' => Post::type('entry'), 'status' => Post::status('published'), 'limit' => Options::get($this->handler_vars['class_name'] . '__posts_per_page'), 'page' => 1, 'orderby' => Options::get($this->handler_vars['class_name'] . '__show_newest_first') ? 'pubdate DESC' : 'pubdate ASC'); $paramarray = new SuperGlobal($default_filters); $paramarray = $paramarray->merge($user_filters, $this->handler_vars); unset($paramarray['entire_match']); unset($paramarray['class_name']); return $paramarray; }
public function action_publish_post($post, $form) { if ($post->content_type == Post::type('snippet')) { if (strlen($form->snippet->snippet_language->value)) { $post->info->snippet_language = $form->snippet->snippet_language->value; } else { $post->info->__unset('snippet_language'); } } }
public function action_publish_post($post, $form) { if ($post->content_type == Post::type('entry')) { if ($form->private_post->value == true) { $post->add_tokens('private'); } else { $post->remove_tokens('private'); } } }
/** * Modify a post before it is updated * * @param Post $post The post being saved, by reference * @param FormUI $form The form that was submitted on the publish page */ public function action_publish_post($post, $form) { switch ($post->content_type) { case Post::type('entry'): $post->info->extra = $form->extra_textarea->value; break; default: return; } }
public function test_delete_content_type() { Post::add_new_type('test_type'); $params = array('title' => 'A post title', 'content' => 'Some great content. Really.', 'user_id' => $this->user->id, 'status' => Post::status('published'), 'content_type' => Post::type('test_type'), 'pubdate' => DateTime::date_create(time())); $post = Post::create($params); $this->assert_true('test_type' == $post->typename, "Post content type should be 'test_type'."); $this->assert_false(Post::delete_post_type('test_type'), "Post still exists with the content type 'test_type'"); $post->delete(); $this->assert_true(Post::delete_post_type('test_type'), "No posts exist with the content type 'test_type'"); }
public function action_publish_post($post, $form) { if ($post->content_type == Post::type('quote') || $form->content_type->value == Post::type('quote')) { if (strlen($form->quote->quote_author->value)) { $post->info->quote_author = $form->quote->quote_author->value; } if (strlen($form->quote->quote_url->value)) { $post->info->quote_url = $form->quote->quote_url->value; } } }
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); $this->recent_comments = Comments::get(array('limit' => 5, 'status' => Comment::STATUS_APPROVED, 'orderby' => 'date DESC')); $this->recent_posts = Posts::get(array('limit' => 5, 'orderby' => 'pubdate DESC', 'content_type' => Post::type('entry'), 'status' => Post::status('published'))); if (!$this->template_engine->assigned('pages')) { $this->pages = Posts::get(array('content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1)); } parent::add_template_vars(); }
public function filter_theme_act_display_blog_home($handled, $theme) { $page = Options::get('staticfront__page'); if ($page && $page != 'none') { $paramarray['fallback'] = array('{$type}.multiple', 'multiple'); // Makes sure home displays only entries $paramarray['user_filters'] = array('content_type' => Post::type('entry')); $theme->act_display($paramarray); return TRUE; } return FALSE; }
public function test_create_post() { $tags = array('one', 'two', 'THREE'); $params = array('title' => 'A post title', 'content' => 'Some great content. Really.', 'user_id' => $this->user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry'), 'tags' => 'one, two, THREE', 'pubdate' => HabariDateTime::date_create(time())); $post = Post::create($params); $this->assertType('Post', $post, 'Post should be created.'); // Check the post's id is set. $this->assertGreaterThan(0, (int) $post->id, 'The Post id should be greater than zero'); // Check the post's tags are usable. $this->assertEquals(count($post->tags), count($tags), 'All tags should have been created.'); foreach ($post->tags as $tag_slug => $tag_text) { $this->assertEquals($tag_slug, Utils::slugify($tag_text), 'Tags key should be slugified tag.'); } }
public function action_theme_ui($theme) { $ui = new FormUI(__CLASS__); // Potential Static home page $page = $ui->append('select', 'page', 'criticalhit__home', _t('The page to show for the home page: ', 'staticfront')); $page->options['--none--'] = _t('Show Normal Posts', 'staticfront'); foreach (Posts::get(array('content_type' => Post::type('page'), 'nolimit' => 1)) as $post) { $page->options[$post->slug] = $post->title; } // Save $ui->append('submit', 'save', _t('Save')); $ui->set_option('success_message', _t('Options saved')); $ui->out(); }
public function action_block_content_eventone_upcoming($block, $theme) { $criteria = array('status' => Post::status('published')); $criteria['content_type'] = Post::type('event'); if ($block->limit != '') { $criteria['limit'] = $block->limit; } $criteria['has:info'] = array('event_start', 'event_end'); $criteria['orderby'] = 'info_event_start_value ASC'; $criteria['on_query_built'] = function (Query $query) { $query->where()->add("date(hipi1.value, 'unixepoch') > date('now')"); }; $block->posts = Posts::get($criteria); $block->criteria = $criteria; }
public function action_add_template_vars($theme, $handler_vars) { $items = array(); if (isset($theme->request->display_home) && $theme->request->display_home) { $posts = Posts::get(array('content_type' => Post::type('entry'), 'status' => Post::status('published'), 'nolimit' => true, 'orderby' => 'pubdate ASC')); foreach ($posts as $post) { $item = array(); $item['url'] = $post->permalink; $item['title'] = $post->title; $item['time'] = strtotime($post->pubdate); $items[] = $item; } } $theme->timeline_items = $items; }
protected function setUp() { set_time_limit(0); $this->posts = array(); $user = User::get_by_name('posts_test'); if (!$user) { $user = User::create(array('username' => 'posts_test', 'email' => '*****@*****.**', 'password' => md5('q' . rand(0, 65535)))); } $time = time() - 160; $this->tag_sets = array(array('one'), array('two'), array('one', 'two'), array('three')); foreach ($this->tag_sets as $tags) { $time = $time - rand(3600, 3600 * 36); $this->posts[] = Post::create(array('title' => $this->get_title(), 'content' => $this->get_content(1, 3, 'some', array('ol' => 1, 'ul' => 1), 'cat'), 'user_id' => $user->id, 'status' => Post::status('published'), 'content_type' => Post::type('entry'), 'tags' => $tags, 'pubdate' => HabariDateTime::date_create($time))); } }
/** * React to the update of a post status to 'published' * @param Post $post The post object with the status change * @param int $oldvalue The old status value * @param int $newvalue The new status value **/ public function action_post_update_status($post, $oldvalue, $newvalue) { if (is_null($oldvalue)) { return; } if ($newvalue == Post::status('published') && $post->content_type == Post::type('entry') && $newvalue != $oldvalue) { $user = User::get_by_id($post->user_id); if (!empty($user->info->statusnet_name) && !empty($user->info->statusnet_pass)) { $name = $user->info->statusnet_name; $pw = $user->info->statusnet_pass; $svcurl = 'https://' . $user->info->statusnet_svc . '/api/statuses/update.xml'; $this->post_status($svcurl, $user->info->statusnet_prefix . $post->title . ' ' . $post->permalink, $name, $pw); } } }
/** * Modify publish form */ public function action_form_publish($form, $post) { if ($post->content_type == Post::type('project')) { $form->title->caption = 'Project Name'; } else { $projects = self::get_projects_simple(); $projects['other'] = "Other"; $projects = array_reverse($projects); $project_selector = $form->append('select', 'project', 'null:null', _t('Project'), $projects, 'admincontrol_select'); foreach ($projects as $key => $name) { if (array_key_exists($key, $post->tags)) { $project_selector->value = $key; } } $form->move_after($project_selector, $form->tags); } }
private function get_html() { set_time_limit(300); $q = "SELECT YEAR( FROM_UNIXTIME(pubdate) ) AS year, MONTH( FROM_UNIXTIME(pubdate) ) AS month, COUNT( id ) AS cnt\n\t\t\t\tFROM {posts}\n\t\t\t\tWHERE content_type = ? AND status = ?\n\t\t\t\tGROUP BY year, month\n\t\t\t\tORDER BY pubdate DESC"; $p[] = Post::type('entry'); $p[] = Post::status('published'); $results = DB::get_results($q, $p); $archives[] = '<ul id="compact-archives">'; if (empty($results)) { $archives[] = '<li>No Archives Found</li>'; } else { $grouping = array(); // group the results by year foreach ($results as $result) { if (!isset($grouping[$result->year])) { $grouping[$result->year] = array_fill(1, 12, 0); } $grouping[$result->year][$result->month] = $result->cnt; } // build the year lists $years = array_keys($grouping); for ($i = 0, $n = count($grouping); $i < $n; $i++) { $year = $years[$i]; $archives[] = '<li><span class="year">' . $year . '</span>'; $archives[] = '<ul class="months">'; for ($j = 1; $j <= count($grouping[$years[$i]]); $j++) { // make sure the month has a 0 on the front, if it doesn't $month = str_pad($j, 2, 0, STR_PAD_LEFT); $month_text = date('F', mktime(0, 0, 0, $month)); $archives[] = '<li>'; if ($grouping[$years[$i]][$j] == 0) { $archives[] = $month; } else { $archives[] = '<a href="' . URL::get('display_entries_by_date', array('year' => $year, 'month' => $month)) . '" title="View entries in ' . $month_text . ' ' . $year . '">' . $month . '</a>'; } $archives[] = '</li>'; } $archives[] = '</ul>'; $archives[] = '</li>'; } } $archives[] = '</ul>'; return implode('', $archives); }
/** * Handles GET requests of the publish page. */ public function get_publish($template = 'publish') { $extract = $this->handler_vars->filter_keys('id', 'content_type_name'); foreach ($extract as $key => $value) { ${$key} = $value; } $content_type = Post::type($content_type_name); // 0 is what's assigned to new posts if (isset($id) && $id != 0) { $post = Post::get(array('id' => $id, 'status' => Post::status('any'))); Plugins::act('admin_publish_post', $post); if (!$post) { Session::error(_t("You don't have permission to edit that post")); $this->get_blank(); } if (!ACL::access_check($post->get_access(), 'edit')) { Session::error(_t("You don't have permission to edit that post")); $this->get_blank(); } $this->theme->post = $post; } else { $post = new Post(); Plugins::act('admin_publish_post', $post); $this->theme->post = $post; $post->content_type = Post::type(isset($content_type) ? $content_type : 'entry'); // check the user can create new posts of the set type. $user = User::identify(); $type = 'post_' . Post::type_name($post->content_type); if (ACL::user_cannot($user, $type) || !ACL::user_can($user, 'post_any', 'create') && !ACL::user_can($user, $type, 'create')) { Session::error(_t('Access to create posts of type %s is denied', array(Post::type_name($post->content_type)))); $this->get_blank(); } } $this->theme->admin_page = _t('Publish %s', array(Plugins::filter('post_type_display', Post::type_name($post->content_type), 'singular'))); $this->theme->admin_title = _t('Publish %s', array(Plugins::filter('post_type_display', Post::type_name($post->content_type), 'singular'))); $statuses = Post::list_post_statuses(false); $this->theme->statuses = $statuses; $form = $post->get_form('admin'); $this->theme->form = $form; $this->theme->wsse = Utils::WSSE(); $this->display($template); }