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 function action_block_form_postblock($form, $block) { $form->append('select', 'content_type', $block, 'Content Type:', array_flip(Post::list_active_post_types())); $form->append('text', 'limit', $block, 'Limit:')->add_validator('validate_regex', '%^(\\d+)?$%', _t('Please enter a numeric value for the limit.')); $form->append('text', 'tag', $block, 'Tag:'); $form->append('submit', 'save', 'Save'); }
/** * Respond to get requests on the admin_cctypes template * * @param AdminHandler $handler The admin handler object * @param Theme $theme The admin theme object */ function action_admin_theme_get_admin_cctypes($handler, $theme) { $posttypes = Post::list_active_post_types(); unset($posttypes['any']); $posttypes = array_flip($posttypes); $theme->posttypes = $posttypes; if ($edit_type = Controller::get_var('edit_type')) { $theme->edit_type = $edit_type; $theme->edit_type_name = $posttypes[$edit_type]; } }
public function configure() { $form = new FormUI('selectivep'); $options = array_flip(Post::list_active_post_types()); unset($options[0]); $options = array_combine(array_map(function ($a) { return 'P-' . $a; }, $options), array_map(function ($a) { return 'Post Type: ' . $a; }, $options)); $comment_options = array_combine(Comment::list_comment_types(), Comment::list_comment_types()); $comment_options = array_combine(array_map(function ($a) { return 'C-' . $a; }, $comment_options), array_map(function ($a) { return 'Comment Type: ' . $a; }, $comment_options)); $options = array_merge($options, $comment_options); //$options['comment'] = 'Any Comment'; $form->append(new FormControlStatic('prompt', 'Select the types that should have autop applied to their content:')); $form->append(new FormControlCheckboxes('post_types', 'selectivep_types', 'Post types that should autop', $options)); $form->append(new FormControlSubmit('save', 'Save')); return $form; }
/** * Plugin hook filter for the values of a faceted search * @param array $other_values The incoming array of values for this facet * @param string $facet The selected facet * @param string $q A string filter for facet values * @return array The returned list of possible values */ public static function filter_facetvalues($other_values, $facet, $q) { switch ($facet) { case 'type': $values = array_keys(Post::list_active_post_types()); break; case 'status': $values = array_keys(Post::list_post_statuses()); break; case 'tag': $tags = Tags::search($q); $values = array(); foreach ($tags as $tag) { $values[] = $tag->term_display; } break; case 'author': $values = array(); $users = Users::get(array('criteria' => $q)); foreach ($users as $user) { $values[] = $user->username; } break; case 'before': case 'after': $values = array($q); break; } return array_merge($other_values, $values); }
/** * function get * Returns requested comments * @param array An associated array of parameters, or a querystring * @return array An array of Comment objects, one for each query result * * <code> * $comments = comments::get( array ( "author" => "skippy" ) ); * $comments = comments::get( array ( "slug" => "first-post", "status" => "1", "orderby" => "date ASC" ) ); * </code> * **/ public static function get($paramarray = array()) { $params = array(); $fns = array('get_results', 'get_row', 'get_value'); $select = ''; // what to select -- by default, everything foreach (Comment::default_fields() as $field => $value) { $select .= '' == $select ? "{comments}.{$field}" : ", {comments}.{$field}"; } // defaults $orderby = 'date DESC'; $limit = Options::get('pagination'); // Put incoming parameters into the local scope $paramarray = Utils::get_params($paramarray); // Transact on possible multiple sets of where information that is to be OR'ed if (isset($paramarray['where']) && is_array($paramarray['where'])) { $wheresets = $paramarray['where']; } else { $wheresets = array(array()); } $wheres = array(); $joins = array(); if (isset($paramarray['where']) && is_string($paramarray['where'])) { $wheres[] = $paramarray['where']; } else { foreach ($wheresets as $paramset) { // safety mechanism to prevent empty queries $where = array('1=1'); $paramset = array_merge((array) $paramarray, (array) $paramset); if (isset($paramset['id']) && (is_numeric($paramset['id']) || is_array($paramset['id']))) { if (is_numeric($paramset['id'])) { $where[] = "{comments}.id= ?"; $params[] = $paramset['id']; } else { if (is_array($paramset['id']) && !empty($paramset['id'])) { $id_list = implode(',', $paramset['id']); // Clean up the id list - remove all non-numeric or comma information $id_list = preg_replace("/[^0-9,]/", "", $id_list); // You're paranoid, ringmaster! :P $limit = count($paramset['id']); $where[] = '{comments}.id IN (' . addslashes($id_list) . ')'; } } } if (isset($paramset['status']) && FALSE !== $paramset['status']) { if (is_array($paramset['status'])) { $paramset['status'] = array_diff($paramset['status'], array('any')); array_walk($paramset['status'], create_function('&$a,$b', '$a = Comment::status( $a );')); $where[] = "{comments}.status IN (" . Utils::placeholder_string(count($paramset['status'])) . ")"; $params = array_merge($params, $paramset['status']); } else { $where[] = "{comments}.status= ?"; $params[] = Comment::status($paramset['status']); } } if (isset($paramset['type']) && FALSE !== $paramset['type']) { if (is_array($paramset['type'])) { $paramset['type'] = array_diff($paramset['type'], array('any')); array_walk($paramset['type'], create_function('&$a,$b', '$a = Comment::type( $a );')); $where[] = "type IN (" . Utils::placeholder_string(count($paramset['type'])) . ")"; $params = array_merge($params, $paramset['type']); } else { $where[] = "type= ?"; $params[] = Comment::type($paramset['type']); } } if (isset($paramset['name'])) { $where[] = "name= ?"; $params[] = $paramset['name']; } if (isset($paramset['email'])) { $where[] = "email= ?"; $params[] = $paramset['email']; } if (isset($paramset['url'])) { $where[] = "url= ?"; $params[] = $paramset['url']; } if (isset($paramset['post_id'])) { $where[] = "{comments}.post_id= ?"; $params[] = $paramset['post_id']; } if (isset($paramset['ip'])) { $where[] = "ip= ?"; $params[] = $paramset['ip']; } /* do searching */ if (isset($paramset['post_author'])) { $joins['posts'] = ' INNER JOIN {posts} ON {comments}.post_id = {posts}.id'; if (is_array($paramset['post_author'])) { $where[] = "{posts}.user_id IN (" . implode(',', array_fill(0, count($paramset['post_author']), '?')) . ")"; $params = array_merge($params, $paramset['post_author']); } else { $where[] = '{posts}.user_id = ?'; $params[] = (string) $paramset['post_author']; } } if (isset($paramset['criteria'])) { if (isset($paramset['criteria_fields'])) { // Support 'criteria_fields' => 'author,ip' rather than 'criteria_fields' => array( 'author', 'ip' ) if (!is_array($paramset['criteria_fields']) && is_string($paramset['criteria_fields'])) { $paramset['criteria_fields'] = explode(',', $paramset['criteria_fields']); } } else { $paramset['criteria_fields'] = array('content'); } $paramset['criteria_fields'] = array_unique($paramset['criteria_fields']); preg_match_all('/(?<=")([\\p{L}\\p{N}]+[^"]*)(?=")|([\\p{L}\\p{N}]+)/u', $paramset['criteria'], $matches); $where_search = array(); foreach ($matches[0] as $word) { foreach ($paramset['criteria_fields'] as $criteria_field) { $where_search[] .= "({comments}.{$criteria_field} LIKE CONCAT('%',?,'%'))"; $params[] = $word; } } if (count($where_search) > 0) { $where[] = '(' . implode(" \nOR\n ", $where_search) . ')'; } } /* * Build the pubdate * If we've got the day, then get the date. * If we've got the month, but no date, get the month. * If we've only got the year, get the whole year. * @todo Ensure that we've actually got all the needed parts when we query on them * @todo Ensure that the value passed in is valid to insert into a SQL date (ie '04' and not '4') */ if (isset($paramset['day'])) { /* Got the full date */ $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], $paramset['day']); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 day')->sql; } elseif (isset($paramset['month'])) { $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 month')->sql; } elseif (isset($paramset['year'])) { $where[] = 'date BETWEEN ? AND ?'; $startDate = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1); $startDate = HabariDateTime::date_create($startDate); $params[] = $startDate->sql; $params[] = $startDate->modify('+1 year')->sql; } // Concatenate the WHERE clauses if (count($where) > 0) { $wheres[] = ' (' . implode(' AND ', $where) . ') '; } } } // Only show comments to which the current user has permission to read the associated post if (isset($paramset['ignore_permissions'])) { $master_perm_where = ''; } else { // This set of wheres will be used to generate a list of comment_ids that this user can read $perm_where = array(); $perm_where_denied = array(); $params_where = array(); $where = array(); // every condition here will require a join with the posts table $joins['posts'] = 'INNER JOIN {posts} ON {comments}.post_id={posts}.id'; // Get the tokens that this user is granted or denied access to read $read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true); $deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true); // If a user can read his own posts, let him if (User::identify()->can('own_posts', 'read')) { $perm_where['own_posts_id'] = '{posts}.user_id = ?'; $params_where[] = User::identify()->id; } // If a user can read any post type, let him if (User::identify()->can('post_any', 'read')) { $perm_where = array('post_any' => '(1=1)'); $params_where = array(); } else { // If a user can read specific post types, let him $permitted_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->can('post_' . Utils::slugify($name), 'read')) { $permitted_post_types[] = $posttype; } } if (count($permitted_post_types) > 0) { $perm_where[] = '{posts}.content_type IN (' . implode(',', $permitted_post_types) . ')'; } // If a user can read posts with specific tokens, let him see comments on those posts if (count($read_tokens) > 0) { $joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')'; $perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL'; } } // If a user is denied access to all posts, do so if (User::identify()->cannot('post_any')) { $perm_where_denied = array('(0=1)'); } else { // If a user is denied read access to specific post types, deny him $denied_post_types = array(); foreach (Post::list_active_post_types() as $name => $posttype) { if (User::identify()->cannot('post_' . Utils::slugify($name))) { $denied_post_types[] = $posttype; } } if (count($denied_post_types) > 0) { $perm_where_denied[] = '{posts}.content_type NOT IN (' . implode(',', $denied_post_types) . ')'; } } // If there are granted permissions to check, add them to the where clause if (count($perm_where) == 0 && !isset($joins['post_tokens__allowed'])) { // You have no grants. You get no comments. $where['perms_granted'] = '(0=1)'; } elseif (count($perm_where) > 0) { $where['perms_granted'] = ' (' . implode(' OR ', $perm_where) . ') '; $params = array_merge($params, $params_where); } if (count($deny_tokens) > 0) { $joins['post_tokens__denied'] = ' LEFT JOIN {post_tokens} pt_denied ON {posts}.id= pt_denied.post_id AND pt_denied.token_id IN (' . implode(',', $deny_tokens) . ')'; $perm_where_denied['perms_join_null'] = 'pt_denied.post_id IS NULL'; } // If there are denied permissions to check, add them to the where clause if (count($perm_where_denied) > 0) { $where['perms_denied'] = ' (' . implode(' AND ', $perm_where_denied) . ') '; } $master_perm_where = implode(' AND ', $where); } // Get any full-query parameters $possible = array('page', 'fetch_fn', 'count', 'month_cts', 'nolimit', 'limit', 'offset', 'orderby'); foreach ($possible as $varname) { if (isset($paramarray[$varname])) { ${$varname} = $paramarray[$varname]; } } if (isset($page) && is_numeric($page)) { $offset = (intval($page) - 1) * intval($limit); } if (isset($fetch_fn)) { if (!in_array($fetch_fn, $fns)) { $fetch_fn = $fns[0]; } } else { $fetch_fn = $fns[0]; } // is a count being request? if (isset($count)) { $select = "COUNT( 1 )"; $fetch_fn = 'get_value'; $orderby = ''; } // is a count of comments by month being requested? $groupby = ''; if (isset($month_cts)) { $select = 'MONTH(FROM_UNIXTIME(date)) AS month, YEAR(FROM_UNIXTIME(date)) AS year, COUNT({comments}.id) AS ct'; $groupby = 'year, month'; $orderby = 'year, month'; } if (isset($limit)) { $limit = " LIMIT {$limit}"; if (isset($offset)) { $limit .= " OFFSET {$offset}"; } } if (isset($nolimit) || isset($month_cts)) { $limit = ''; } // Build the final SQL statement $query = ' SELECT DISTINCT ' . $select . ' FROM {comments} ' . implode(' ', $joins); if (count($wheres) > 0) { $query .= ' WHERE (' . implode(" \nOR\n ", $wheres) . ')'; $query .= $master_perm_where == '' ? '' : ' AND (' . $master_perm_where . ')'; } elseif ($master_perm_where != '') { $query .= ' WHERE (' . $master_perm_where . ')'; } $query .= $groupby == '' ? '' : ' GROUP BY ' . $groupby; $query .= ($orderby == '' ? '' : ' ORDER BY ' . $orderby) . $limit; //Utils::debug( $query, $params ); DB::set_fetch_mode(PDO::FETCH_CLASS); DB::set_fetch_class('Comment'); $results = DB::$fetch_fn($query, $params, 'Comment'); if ('get_results' != $fetch_fn) { // return the results return $results; } elseif (is_array($results)) { $c = __CLASS__; $return_value = new $c($results); $return_value->get_param_cache = $paramarray; return $return_value; } }
/** * Parses a search string for status, type, author, and tag keywords. Returns * an associative array which can be passed to Posts::get(). If multiple * authors, statuses, tags, or types are specified, we assume an implicit OR * such that (e.g.) any author that matches would be returned. * * @param string $search_string The search string * @return array An associative array which can be passed to Posts::get() */ public static function search_to_get($search_string) { $keywords = array('author' => 1, 'status' => 1, 'type' => 1, 'tag' => 1); $statuses = Post::list_post_statuses(); $types = Post::list_active_post_types(); $arguments = array('user_id' => array(), 'status' => array(), 'content_type' => array(), 'tag' => array()); $criteria = ''; $tokens = explode(' ', $search_string); foreach ($tokens as $token) { //check for triple combination if (preg_match('/^\\w+:[^:\\s]*:\\S+$/', $token)) { list($keyword, $infokey, $infovalue) = explode(':', $token); $keyword = strtolower($keyword); switch ($keyword) { case 'info': $arguments['info'][] = array($infokey => $infovalue); break; } } // check for a keyword:value pair if (preg_match('/^\\w+:\\S+$/', $token)) { list($keyword, $value) = explode(':', $token); $keyword = strtolower($keyword); switch ($keyword) { case 'author': if ($u = User::get($value)) { $arguments['user_id'][] = (int) $u->id; } break; case 'tag': $arguments['tag'][] = $value; break; case 'status': if (isset($statuses[$value])) { $arguments['status'][] = (int) $statuses[$value]; } break; case 'type': if (isset($types[$value])) { $arguments['content_type'][] = (int) $types[$value]; } break; } } else { $criteria .= $token . ' '; } } // flatten keys that have single-element or no-element arrays foreach ($arguments as $key => $arg) { switch (count($arg)) { case 0: unset($arguments[$key]); break; case 1: $arguments[$key] = $arg[0]; break; } } if ($criteria != '') { $arguments['criteria'] = $criteria; } return $arguments; }
/** * Returns a form for editing this post * @param string $context The context the form is being created in, most often 'admin' * @return FormUI A form appropriate for creating and updating this post. */ public function get_form($context) { $form = new FormUI('create-content'); $form->class[] = 'create'; $newpost = 0 === $this->id; // If the post has already been saved, add a link to its permalink if (!$newpost) { $post_links = $form->append('wrapper', 'post_links'); $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink; $post_links->append('static', 'post_permalink', '<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>'); $post_links->class = 'container'; } // Store this post instance into a hidden field for later use when saving data $form->append('hidden', 'post', $this, _t('Title'), 'admincontrol_text'); // Create the Title field $form->append('text', 'title', 'null:null', _t('Title'), 'admincontrol_text'); $form->title->class[] = 'important'; $form->title->class[] = 'check-change'; $form->title->tabindex = 1; $form->title->value = $this->title_internal; // Create the silos if (count(Plugins::get_by_interface('MediaSilo'))) { $form->append('silos', 'silos'); $form->silos->silos = Media::dir(); } // Create the Content field $form->append('textarea', 'content', 'null:null', _t('Content'), 'admincontrol_textarea'); $form->content->class[] = 'resizable'; $form->content->class[] = 'check-change'; $form->content->tabindex = 2; $form->content->value = $this->content_internal; $form->content->raw = true; // Create the tags field $form->append('text', 'tags', 'null:null', _t('Tags, separated by, commas'), 'admincontrol_text'); $form->tags->class = 'check-change'; $form->tags->tabindex = 3; $tags = (array) $this->get_tags(); array_walk($tags, function (&$element, $key) { $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable; }); $form->tags->value = implode(', ', $tags); // Create the splitter $publish_controls = $form->append('tabs', 'publish_controls'); // Create the publishing controls // pass "false" to list_post_statuses() so that we don't include internal post statuses $statuses = Post::list_post_statuses($this); unset($statuses[array_search('any', $statuses)]); $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses); $settings = $publish_controls->append('fieldset', 'settings', _t('Settings')); $settings->append('select', 'status', 'null:null', _t('Content State'), array_flip($statuses), 'tabcontrol_select'); $settings->status->value = $this->status; // hide the minor edit checkbox if the post is new if ($newpost) { $settings->append('hidden', 'minor_edit', 'null:null'); $settings->minor_edit->value = false; } else { $settings->append('checkbox', 'minor_edit', 'null:null', _t('Minor Edit'), 'tabcontrol_checkbox'); $settings->minor_edit->value = true; $form->append('hidden', 'modified', 'null:null')->value = $this->modified; } $settings->append('checkbox', 'comments_enabled', 'null:null', _t('Comments Allowed'), 'tabcontrol_checkbox'); $settings->comments_enabled->value = $this->info->comments_disabled ? false : true; $settings->append('text', 'pubdate', 'null:null', _t('Publication Time'), 'tabcontrol_text'); $settings->pubdate->value = $this->pubdate->format('Y-m-d H:i:s'); $settings->pubdate->helptext = _t('YYYY-MM-DD HH:MM:SS'); $settings->append('hidden', 'updated', 'null:null'); $settings->updated->value = $this->updated->int; $settings->append('text', 'newslug', 'null:null', _t('Content Address'), 'tabcontrol_text'); $settings->newslug->id = 'newslug'; $settings->newslug->value = $this->slug; // Create the button area $buttons = $form->append('fieldset', 'buttons'); $buttons->template = 'admincontrol_buttons'; $buttons->class[] = 'container'; $buttons->class[] = 'buttons'; $buttons->class[] = 'publish'; // Create the Save button $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create'); if ($newpost && User::identify()->can_any($require_any) || !$newpost && ACL::access_check($this->get_access(), 'edit')) { $buttons->append('submit', 'save', _t('Save'), 'admincontrol_submit'); $buttons->save->tabindex = 4; } // Add required hidden controls $form->append('hidden', 'content_type', 'null:null'); $form->content_type->id = 'content_type'; $form->content_type->value = $this->content_type; $form->append('hidden', 'post_id', 'null:null'); $form->post_id->id = 'id'; $form->post_id->value = $this->id; $form->append('hidden', 'slug', 'null:null'); $form->slug->value = $this->slug; $form->slug->id = 'originalslug'; $form->on_success(array($this, 'form_publish_success')); // Let plugins alter this form Plugins::act('form_publish', $form, $this, $context); $content_types = array_flip(Post::list_active_post_types()); Plugins::act('form_publish_' . Utils::slugify($content_types[$this->content_type], '_'), $form, $this, $context); // Return the form object return $form; }
public function action_block_form_grayposts($form, $block) { $form->append('select', 'content_type', $block, 'Content Type:', array_flip(Post::list_active_post_types())); $form->append('text', 'limit', $block, 'Limit:'); $form->limit->add_validator('validate_range', 1, 999); $form->append('text', 'offset', $block, 'Offset:'); $form->offset->add_validator('validate_range', 0, 999); $form->append('text', 'tag', $block, 'Tag:'); $form->append('checkbox', 'main', $block, 'This block changes based on URL paramters.'); $form->append('submit', 'save', 'Save'); }
/** * Handles POST values from /manage/posts. * Used to control what content to show / manage. */ public function post_posts() { $this->fetch_posts(); // Get special search statuses $statuses = array_keys(Post::list_post_statuses()); array_shift($statuses); $labels = array_map(function ($a) { return MultiByte::ucfirst(Plugins::filter("post_status_display", $a)); }, $statuses); $terms = array_map(function ($a) { return "status:{$a}"; }, $statuses); $statuses = array_combine($terms, $labels); // Get special search types $types = array_keys(Post::list_active_post_types()); array_shift($types); $labels = array_map(function ($a) { return Plugins::filter("post_type_display", $a, "singular"); }, $types); $terms = array_map(function ($a) { return "type:{$a}"; }, $types); $types = array_combine($terms, $labels); $special_searches = array_merge($statuses, $types); // Add a filter to get the only the user's posts $special_searches["author:" . User::identify()->username] = _t('My Posts'); $this->theme->admin_page = _t('Manage Posts'); $this->theme->admin_title = _t('Manage Posts'); $this->theme->special_searches = Plugins::filter('special_searches', $special_searches); $this->display('posts'); }
/** * filter_dash_module_post_types * Function used to set theme variables to the post types dashboard widget * @param string $module_id * @return string The contents of the module */ public function filter_dash_module_post_types_and_statuses( $module, $module_id, $theme ) { $messages = array(); $user = User::identify(); $post_types = Post::list_active_post_types(); array_shift( $post_types ); $post_statuses = array_values( Post::list_post_statuses() ); array_shift( $post_statuses ); foreach( $post_types as $type => $type_id ) { $plural = Plugins::filter( 'post_type_display', $type, 'plural' ); foreach( $post_statuses as $status => $status_id ) { $status_display = MultiByte::ucfirst( Plugins::filter( 'post_status_display', Post::status_name( $status_id ) ) ); $site_count = Posts::get( array( 'content_type' => $type_id, 'count' => true, 'status' => $status_id ) ); $user_count = Posts::get( array( 'content_type' => $type_id, 'count' => true, 'status' => $status_id, 'user_id' => $user->id ) ); // @locale First variable is the post status, second is the post type $message['label'] = _t( '%1$s %2$s', array( $status_display, $plural ) ); if( ! $site_count ) { $message['site_count'] = ''; } else if( $user->cannot( 'post_unpublished' ) && Post::status_name( $status_id ) != 'published' ) { $message['site_count'] = ''; } else { $message['site_count'] = $site_count; } $perms = array( 'post_any' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ), 'own_posts' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ), 'post_' . $type => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ), ); if ( $user->can_any( $perms ) && $message['site_count'] ) { $message['site_count'] = '<a href="' . Utils::htmlspecialchars( URL::get( 'admin', array( 'page' => 'posts', 'type' => Post::type( $type ), 'status' => $status_id ) ) ) . '">' . Utils::htmlspecialchars( $message['site_count'] ) . '</a>'; } if( ! $user_count ) { $message['user_count'] = ''; } else { $message['user_count'] = $user_count; } // @locale First variable is the post status, second is the post type $perms = array( 'own_posts' => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ), 'post_' . $type => array( ACL::get_bitmask( 'delete' ), ACL::get_bitmask( 'edit' ) ), ); if ( $user->can_any( $perms ) && $message['user_count'] ) { $message['user_count'] = '<a href="' . Utils::htmlspecialchars( URL::get( 'admin', array( 'page' => 'posts', 'type' => Post::type( $type ), 'status' => $status_id, 'user_id' => $user->id ) ) ) . '">' . Utils::htmlspecialchars( $message['user_count'] ) . '</a>'; } if( $message['site_count'] || $message['user_count'] ) { $messages[] = $message; } } } $theme->type_messages = $messages; $module['title'] = _t( 'Post Types and Statuses' ); $module['content'] = $theme->fetch( 'dash_posttypes' ); return $module; }
/** * Handles POST values from /manage/posts. * Used to control what content to show / manage. */ public function post_posts() { $this->fetch_posts(); // Get special search statuses $statuses = array_keys(Post::list_post_statuses()); array_shift($statuses); $statuses = array_combine($statuses, array_map(create_function('$a', 'return "status:{$a}";'), $statuses)); // Get special search types $types = array_keys(Post::list_active_post_types()); array_shift($types); $types = array_combine($types, array_map(create_function('$a', 'return "type:{$a}";'), $types)); $this->theme->admin_page = _t('Manage Posts'); $this->theme->admin_title = _t('Manage Posts'); $this->theme->special_searches = Plugins::filter('special_searches', array_merge($statuses, $types)); $this->display('posts'); }
/** * Returns a form for editing this post * @param string $context The context the form is being created in, most often 'admin' * @return FormUI A form appropriate for creating and updating this post. */ public function get_form($context) { /** @var FormUI $form */ $form = new FormUI('create-content', null, array('class' => array('create'))); $form->set_wrap_each('<div class="container">%s</div>'); $newpost = 0 === $this->id; // If the post has already been saved, add a link to its permalink if (!$newpost) { /** @var FormControlWrapper $post_links */ $post_links = $form->append(FormControlWrapper::create('post_links', null, array('class' => 'container'))); $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink; $post_links->append(FormControlStatic::create('post_permalink')->set_static('<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>')); } // Store this post instance into a hidden field for later use when saving data $form->append(FormControlData::create('post')->set_value($this)); // Create the Title field $form->append(FormControlLabel::wrap(_t('Title'), FormControlText::create('title', null, array('class' => array('check-change full-width')))->set_value($this->title_internal))); // Create the silos if (count(Plugins::get_by_interface('MediaSilo'))) { $silos = FormControlSilos::create('silos')->set_setting('wrap', '<div class="container silos">%s</div>'); $form->append($silos); } // Create the Content field $form->append(FormControlLabel::wrap(_t('Content'), FormControlTextArea::create('content', null, array('class' => array('resizable', 'check-change full-width rte')))->set_value($this->content_internal))); $form->content->raw = true; // @todo What does this do? // Create the tags field /** @var FormControlAutocomplete $tags_control */ $form->append(FormControlLabel::wrap(_t('Tags, separated by, commas'), $tags_control = FormControlAutocomplete::create('tags', null, array('style' => 'width:100%;margin:0px 0px 20px;', 'class' => 'check-change full-width'), array('allow_new' => true, 'init_selection' => true)))->set_properties(array('style' => 'width:100%;margin:0px 0px 20px;'))); $tags = (array) $this->get_tags(); array_walk($tags, function (&$element, $key) { $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable; }); $tags_control->set_value(implode(',', $tags)); $tags_control->set_ajax(URL::auth_ajax('tag_list')); // Create the splitter /** @var FormControlTabs $publish_controls */ $publish_controls = $form->append(FormControlTabs::create('publish_controls')->set_setting('wrap', '%s')->set_setting('class_each', 'container')); // Create the publishing controls // pass "false" to list_post_statuses() so that we don't include internal post statuses $statuses = Post::list_post_statuses($this); unset($statuses[array_search('any', $statuses)]); $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses); /** @var FormControlFieldset $settings */ $settings = $publish_controls->append(FormControlFieldset::create('post_settings')->set_caption(_t('Settings'))); $settings->append(FormControlLabel::wrap(_t('Content State'), FormControlSelect::create('status')->set_options(array_flip($statuses))->set_value($this->status))); // hide the minor edit checkbox if the post is new if ($newpost) { $settings->append(FormControlData::create('minor_edit')->set_value(false)); } else { $settings->append(FormControlLabel::wrap(_t('Minor Edit'), FormControlCheckbox::create('minor_edit')->set_value(true))); $form->append(FormControlData::create('modified')->set_value($this->modified)); } $settings->append(FormControlLabel::wrap(_t('Comments Allowed'), FormControlCheckbox::create('comments_enabled')->set_value($this->info->comments_disabled ? false : true))); $settings->append(FormControlLabel::wrap(_t('Publication Time'), FormControlText::create('pubdate')->set_value($this->pubdate->format('Y-m-d H:i:s')))); $settings->pubdate->set_helptext(_t('YYYY-MM-DD HH:MM:SS')); $settings->append(FormControlData::create('updated')->set_value($this->updated->int)); $settings->append(FormControlLabel::wrap(_t('Content Address'), FormControlText::create('newslug')->set_value($this->slug))); // Create the button area $buttons = $form->append(FormControlFieldset::create('buttons', null, array('class' => array('container', 'buttons', 'publish')))); // What buttons should we have? $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create'); $show_buttons = array(); if ($newpost) { if (User::identify()->can_any($require_any)) { $show_buttons['save'] = true; $show_buttons['publish'] = true; } } else { if (ACL::access_check($this->get_access(), 'edit')) { if ($this->status == Post::status('draft')) { $show_buttons['publish'] = true; } $show_buttons['save'] = true; } if (ACL::access_check($this->get_access(), 'delete')) { $show_buttons['delete'] = true; } } $show_buttons = Plugins::filter('publish_form_buttons', $show_buttons, $this); if (isset($show_buttons['delete'])) { // Create the Delete button $buttons->append(FormControlSubmit::create('delete', null, array('class' => 'three columns'))->set_caption(_t('Delete'))->on_success(array($this, 'form_publish_delete'))); } if (isset($show_buttons['save'])) { // Create the Save button $buttons->append(FormControlSubmit::create('save', null, array('class' => 'three columns'))->set_caption(_t('Save'))); } if (isset($show_buttons['publish'])) { // Create the Publish button $buttons->append(FormControlSubmit::create('publish', null, array('class' => 'three columns'))->set_caption(_t('Publish'))->add_validator(function ($value, FormControlSubmit $control, FormUI $form) { $form->status->set_value(Post::status('published')); $allow = Plugins::filter('post_publish_allow', true, $this); if (!$allow) { return array('Publishing has been denied'); } return array(); })); } // Add required hidden controls $form->append(FormControlData::create('content_type', null, array('id' => 'content_type'))->set_value($this->content_type)); $form->append(FormControlData::create('post_id', null, array('id' => 'id'))->set_value($this->id)); $form->append(FormControlData::create('slug', null, array('id' => 'originalslug'))->set_value($this->slug)); $form->on_success(array($this, 'form_publish_success')); // Let plugins alter this form Plugins::act('form_publish', $form, $this, $context); $content_types = array_flip(Post::list_active_post_types()); Plugins::act('form_publish_' . Utils::slugify($content_types[$this->content_type], '_'), $form, $this, $context); // Return the form object return $form; }
public function get_code() { $cases_form = ''; $types = Post::list_active_post_types(); unset($types['any']); foreach ($types as $type => $id) { $fields = Options::get('postfields__fields_' . $id); if (!is_array($fields) || count($fields) == 0) { continue; } $fieldlist = array(); foreach ($fields as $field) { $fieldlist[] = "'" . addslashes($field) . "'"; } $fieldlist = implode(', ', $fieldlist); $cases_form .= "\t\t\tcase {$id}:\n\t\t\t\t\$fields = array({$fieldlist});\n\t\t\t\tbreak;\n"; } $code = <<<PLUGIN_CODE_1 \t/** \t* Add additional controls to the publish page tab \t* \t* @param FormUI \$form The form that is used on the publish page \t* @param Post \$post The post being edited \t**/ \tpublic function action_form_publish(\$form, \$post) \t{ \t\tswitch(\$post->content_type) { \t\t\t{$cases_form} \t\t\tdefault: \t\t\t\treturn; \t\t} \t\tforeach(\$fields as \$field) { \t\t\t\$control_id = md5(\$field); \t\t\t\$fieldname = "postfield_{\$control_id}"; \t\t\t\$customfield = \$postfields->append('text', \$fieldname, 'null:null', \$field); \t\t\t\$customfield->value = isset(\$post->info->{\$field}) ? \$post->info->{\$field} : ''; \t\t\t\$customfield->template = 'tabcontrol_text'; \t\t} \t} \t \t/** \t* Modify a post before it is updated \t* \t* @param Post \$post The post being saved, by reference \t* @param FormUI \$form The form that was submitted on the publish page \t*/ \tpublic function action_publish_post(\$post, \$form) \t{ \t\tswitch(\$post->content_type) { \t\t\t{$cases_form} \t\t\tdefault: \t\t\t\treturn; \t\t} \t\tforeach(\$fields as \$field) { \t\t\t\$control_id = md5(\$field); \t\t\t\$fieldname = "postfield_{\$control_id}"; \t\t\t\$customfield = \$form->\$fieldname; \t\t\t\$post->info->{\$field} = \$customfield->value; \t\t} \t} PLUGIN_CODE_1; return $code; }
protected function get_menu() { $createmenu = array(); $managemenu = array(); foreach (Post::list_active_post_types() as $type => $typeint) { if ($typeint == 0) { continue; } $createmenu['create_' . $typeint] = array('url' => 'page=publish&content_type=' . $type, 'text' => sprintf(_t('Create %s'), ucwords($type))); $managemenu['manage_' . $typeint] = array('url' => 'page=posts&type=' . $typeint, 'text' => sprintf(_t('Manage %s'), ucwords($type))); } $adminmenu = array('comments' => array('url' => 'page=comments', 'text' => _t('Comments')), 'tags' => array('url' => 'page=tags', 'text' => _t('Tags')), 'dashboard' => array('url' => 'page=', 'text' => _t('Dashboard')), 'options' => array('url' => 'page=options', 'text' => _t('Options')), 'themes' => array('url' => 'page=themes', 'text' => _t('Themes')), 'plugins' => array('url' => 'page=plugins', 'text' => _t('Plugins')), 'import' => array('url' => 'page=import', 'text' => _t('Import')), 'users' => array('url' => 'page=users', 'text' => _t('Users')), 'logs' => array('url' => 'page=logs', 'text' => _t('Logs')), 'logout' => array('url' => 'page=logout', 'text' => _t('Logout')), 'user' => array('url' => 'page=user&userid=' . User::identify()->id, 'text' => _t('User\'s own profile page')), 'otheruser' => array('url' => 'page=user', 'text' => _t('Other user\'s profile page'))); $mainmenus = array_merge($createmenu, $managemenu, $adminmenu); return $mainmenus; }
public function act_display_pageless_js($handler_vars) { // If 'slug' exists, then it must be single, don't do anything if (!isset($handler_vars['slug'])) { // Determine act_display $filter_type = ''; $filter_param = ''; if (isset($handler_vars['tag'])) { $filter_type = 'tag'; $filter_param = $handler_vars['tag']; } else { if (isset($handler_vars['year'])) { $filter_type = 'date'; $filter_param = $handler_vars['year']; if (isset($handler_vars['month'])) { $filter_param .= '/' . $handler_vars['month']; } if (isset($handler_vars['day'])) { $filter_param .= '/' . $handler_vars['day']; } } else { if (isset($handler_vars['criteria'])) { $filter_type = 'search'; $filter_param = $handler_vars['criteria']; } } } $active_types = array_flip(Post::list_active_post_types()); unset($active_types[0]); $active_types = implode('|', $active_types); // Get settings $options = self::options(); $out = '(function($){ $(function() { $("#' . $options['pager_id'] . '").hide(); $("#' . $options['pager_id'] . '").before("<div id=\\"pageless-indicator\\"></div>"); var spinner = { start: function() { $("#pageless-indicator").html(\'<img src="' . Site::get_url('admin_theme') . '/images/spin.gif">\'); $("#pageless-indicator").show(); }, stop: function() { $("#pageless-indicator").hide(); } } var the_end = false; function appendEntries() { if ($(window).scrollTop() >= $(document).height() - ($(window).height() * 2)) { var slug = $(".' . $options['post_class'] . ':last").attr("id").replace(/^(?:' . $active_types . ')-/, ""); $.ajax({ url: "' . URL::get('display_pageless', array('type' => $filter_type, 'param' => $filter_param)) . '".replace("{$slug}", slug), beforeSend: function() { spinner.start(); $(window).unbind("scroll", appendEntries); }, success: function(response) { if (response.length > 100) { $(".' . $options['post_class'] . ':last").after(response); } else { the_end = true; } }, complete: function() { spinner.stop(); if (!the_end && activated) { $(window).bind("scroll", appendEntries); } } }); } } $(window).bind("scroll", appendEntries); var activated = true; function toggleScroll() { activated = !activated; if (!the_end && activated) { $(window).bind("scroll", appendEntries); $("#' . $options['pager_id'] . '").hide(); appendEntries(); } else { $(window).unbind("scroll", appendEntries); $("#' . $options['pager_id'] . '").show(); } } $(document).bind("dblclick", toggleScroll); }); })(jQuery);'; ob_clean(); header('Content-type: text/javascript'); header('ETag: ' . md5($out)); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 315360000) . ' GMT'); header('Cache-Control: max-age=315360000'); echo $out; } exit; }
/** * function _filter_token_description_display * Filter to localize token descriptions * @param string Token to get the description of * @return string The localized token description */ public static function _filter_token_description_display($token) { $desc = array('super_user' => _t('Permissions for super users'), 'manage_all_comments' => _t('Manage comments on all posts'), 'manage_own_post_comments' => _t('Manage comments on one\'s own posts'), 'manage_tags' => _t('Manage tags'), 'manage_options' => _t('Manage options'), 'manage_theme' => _t('Change theme'), 'manage_theme_config' => _t('Configure the active theme'), 'manage_plugins' => _t('Activate/deactivate plugins'), 'manage_plugins_config' => _t('Configure active plugins'), 'manage_import' => _t('Use the importer'), 'manage_users' => _t('Add, remove, and edit users'), 'manage_self' => _t('Edit own profile'), 'manage_groups' => _t('Manage groups and permissions'), 'manage_logs' => _t('Manage logs'), 'manage_dash_modules' => _t('Manage dashboard modules'), 'own_posts' => _t('Permissions on one\'s own posts'), 'post_any' => _t('Permissions to all posts'), 'post_unpublished' => _t('Permissions to other user\'s unpublished posts'), 'comment' => _t('Make comments on any post')); // content tokens foreach (Post::list_active_post_types() as $name => $posttype) { $label = MultiByte::strtolower(Plugins::filter('post_type_display', $name, 'singular')); $desc['post_' . Utils::slugify($name)] = _t('Permissions to posts of type "%s"', array($label)); } return isset($desc[$token]) ? $desc[$token] : $token; }
/** * Checks if the currently logged in user has access to a page and post type. */ private function access_allowed($page, $type) { $user = User::identify(); $require_any = array(); $result = false; switch ($page) { case 'comment': case 'comments': case 'ajax_comments': case 'ajax_in_edit': case 'ajax_update_comment': $require_any = array('manage_all_comments' => true, 'manage_own_post_comments' => true); break; case 'tags': case 'ajax_tags': $require_any = array('manage_tags' => true); break; case 'options': $require_any = array('manage_options' => true); break; case 'themes': $require_any = array('manage_themes' => true, 'manage_theme_config' => true); break; case 'activate_theme': $require_any = array('manage_themes' => true); break; case 'preview_theme': $require_any = array('manage_themes' => true); break; case 'plugins': $require_any = array('manage_plugins' => true, 'manage_plugins_config' => true); break; case 'plugin_toggle': $require_any = array('manage_plugins' => true); break; case 'import': $require_any = array('manage_import' => true); break; case 'users': case 'ajax_update_users': case 'ajax_users': $require_any = array('manage_users' => true); break; case 'user': $require_any = array('manage_users' => true, 'manage_self' => true); break; case 'groups': case 'group': case 'ajax_update_groups': case 'ajax_groups': $require_any = array('manage_groups' => true); break; case 'logs': case 'ajax_delete_logs': case 'ajax_logs': $require_any = array('manage_logs' => true); break; case 'publish': case 'ajax_media': case 'ajax_media_panel': $type = Post::type_name($type); $require_any = array('post_any' => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit')), 'post_' . $type => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit')), 'own_posts' => array(ACL::get_bitmask('create'), ACL::get_bitmask('edit'))); break; case 'delete_post': $type = Post::type_name($type); $require_any = array('post_any' => ACL::get_bitmask('delete'), 'post_' . $type => ACL::get_bitmask('delete'), 'own_posts' => ACL::get_bitmask('delete')); break; case 'posts': case 'ajax_posts': case 'ajax_delete_entries': case 'ajax_update_entries': $require_any = array('post_any' => array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit')), 'own_posts' => array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit'))); foreach (Post::list_active_post_types() as $type => $type_id) { $require_any['post_' . $type] = array(ACL::get_bitmask('delete'), ACL::get_bitmask('edit')); } break; case 'sysinfo': $require_any = array('super_user' => true); break; case 'dashboard': case 'ajax_dashboard': $result = true; break; case 'ajax_add_block': $result = true; break; case 'ajax_delete_block': $result = true; break; case 'configure_block': $result = true; break; case 'ajax_save_areas': $result = true; break; default: break; } $require_any = Plugins::filter('admin_access_tokens', $require_any, $page, $type); foreach ($require_any as $token => $access) { $access = Utils::single_array($access); foreach ($access as $mask) { if (is_bool($mask) && $user->can($token)) { $result = true; break; } elseif ($user->can($token, $mask)) { $result = true; break 2; } } } $result = Plugins::filter('admin_access', $result, $page, $type); return $result; }
/** * 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]; } } $where_filters = array(); $where_filters = Controller::get_handler()->handler_vars->filter_keys($this->valid_filters); //$where_filters['status'] = Post::status( 'published' ); if (array_key_exists('tag', $where_filters)) { $where_filters['tag_slug'] = Utils::slugify($where_filters['tag']); unset($where_filters['tag']); } if (User::identify()->loggedin) { $where_filters['status'] = isset($_GET['preview']) ? Post::status('any') : Post::status('published'); } else { $where_filters['status'] = Post::status('published'); } if (!isset($posts)) { $user_filters = Plugins::filter('template_user_filters', $user_filters); $user_filters = array_intersect_key($user_filters, array_flip($this->valid_filters)); $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( !isset( $this->page ) ) { if( isset( $page ) ) { $this->assign( 'page', $page ); } elseif( isset( Controller::get_handler()->handler_vars['page'] ) ) { $this->assign( 'page', Controller::get_handler()->handler_vars['page'] ); } }*/ if ($posts !== false && count($posts) > 0) { $post = count($posts) > 1 ? $posts[0] : $posts; $this->assign('post', $post); $types = array_flip(Post::list_active_post_types()); $type = $types[$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'); } 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'); $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); $fallback = array_values(array_unique(str_replace($searches, $replacements, $fallback))); for ($z = 0; $z < count($fallback); $z++) { if (strpos($fallback[$z], '{$posttag}') !== false && isset($post) && $post instanceof Post) { $replacements = array(); if ($alltags = $post->tags) { foreach ($alltags as $tag_slug => $tag_text) { $replacements[] = str_replace('{$posttag}', $tag_slug, $fallback[$z]); } array_splice($fallback, $z, 1, $replacements); } else { break; } } } return $this->display_fallback($fallback); }
/** * Parses a search string for status, type, author, and tag keywords. Returns * an associative array which can be passed to Posts::get(). If multiple * authors, statuses, tags, or types are specified, we assume an implicit OR * such that (e.g.) any author that matches would be returned. * * @param string $search_string The search string * @return array An associative array which can be passed to Posts::get() */ public static function search_to_get($search_string) { // if adding to this array, make sure you update the consequences of a search on this below in the switch. $keywords = array('author' => 1, 'status' => 1, 'type' => 1, 'tag' => 1, 'info' => 1); $statuses = Post::list_post_statuses(); $types = Post::list_active_post_types(); $arguments = array('user_id' => array(), 'status' => array(), 'content_type' => array(), 'vocabulary' => array(), 'info' => array()); $criteria = ''; // this says, find stuff that has the keyword at the start, and then some term straight after. // the terms should have no whitespace, or if it does, be ' delimited. // ie tag:foo or tag:'foo bar' $flag_regex = '/(?P<flag>\\w+):(?P<value>[^\'"][^\\s]*|(?P<quote>[\'"])[^\\3]+(?<!\\\\)\\3)/i'; // now do some matching. preg_match_all($flag_regex, $search_string, $matches, PREG_SET_ORDER); // now we remove those terms from the search string, otherwise the keyword search below has issues. It will pick up things like // from tag:'pair of' -> matches of' $criteria = trim(preg_replace($flag_regex, '', $search_string)); // Add special criteria based on the flag parameters. foreach ($matches as $match) { // trim out any quote marks that have been matched. $quote = isset($match['quote']) ? $match['quote'] : ' '; $value = trim(stripslashes($match['value']), $quote); $flag = $match['flag']; $arguments = Plugins::filter('posts_search_to_get', $arguments, $flag, $value, $match, $search_string); switch ($flag) { case 'author': if ($u = User::get($value)) { $arguments['user_id'][] = (int) $u->id; } break; case 'tag': $arguments['vocabulary'][Tags::vocabulary()->name . ':term_display'][] = $value; break; case 'status': if (isset($statuses[$value])) { $arguments['status'][] = (int) $statuses[$value]; } break; case 'type': if (isset($types[$value])) { $arguments['content_type'][] = (int) $types[$value]; } break; case 'info': if (strpos($value, ':') !== false) { list($infokey, $infovalue) = explode(':', $value, 2); $arguments['info'][] = array($infokey => $infovalue); } break; } } // flatten keys that have single-element or no-element arrays foreach ($arguments as $key => $arg) { switch (count($arg)) { case 0: unset($arguments[$key]); break; case 1: if (is_array($arg)) { $arguments[$key] = $arg; } else { $arguments[$key] = $arg[0]; } break; } } if ($criteria != '') { $arguments['criteria'] = $criteria; } return $arguments; }
/** * Creates the default set of permissions. */ public static function create_default_tokens() { // super user token self::create_token('super_user', 'Permissions for super users', 'Super User'); // admin tokens self::create_token('manage_all_comments', _t('Manage comments on all posts'), 'Administration'); self::create_token('manage_own_post_comments', _t('Manage comments on one\'s own posts'), 'Administration'); self::create_token('manage_tags', _t('Manage tags'), 'Administration'); self::create_token('manage_options', _t('Manage options'), 'Administration'); self::create_token('manage_theme', _t('Change theme'), 'Administration'); self::create_token('manage_theme_config', _t('Configure the active theme'), 'Administration'); self::create_token('manage_plugins', _t('Activate/deactivate plugins'), 'Administration'); self::create_token('manage_plugins_config', _t('Configure active plugins'), 'Administration'); self::create_token('manage_import', _t('Use the importer'), 'Administration'); self::create_token('manage_users', _t('Add, remove, and edit users'), 'Administration'); self::create_token('manage_self', _t('Edit own profile'), 'Administration'); self::create_token('manage_groups', _t('Manage groups and permissions'), 'Administration'); self::create_token('manage_logs', _t('Manage logs'), 'Administration'); self::create_token('manage_dash_modules', _t('Manage dashboard modules'), 'Administration'); // content tokens self::create_token('own_posts', _t('Permissions on one\'s own posts'), _t('Content'), true); self::create_token('post_any', _t('Permissions to all posts'), _t('Content'), true); self::create_token('post_unpublished', _t("Permissions to other users' unpublished posts"), _t('Content'), true); foreach (Post::list_active_post_types() as $name => $posttype) { self::create_token('post_' . Utils::slugify($name), _t('Permissions to posts of type "%s"', array($name)), _t('Content'), true); } // comments tokens self::create_token('comment', 'Make comments on any post', _t('Comments')); }
private function get_perms() { $type_perms = array(); $types = Post::list_active_post_types(); foreach ($types as $key => $value) { $perm = array('post_' . $key => ACL::get_bitmask('delete')); $types_perms = array_merge($type_perms, $perm); } $perms = array('own_posts' => ACL::get_bitmask('delete'), 'post_any' => ACL::get_bitmask('delete')); $perms = array_merge($perms, $type_perms); return $perms; }
/** * Recent Posts * * Allow configuration of the number of recent posts to show * * @param FormUI $form The configuration form for this block * @param Block $block The block instance to be configured */ public function action_block_form_recent_posts($form, $block) { $content = $form->append('text', 'quantity', $block, _t('Posts to show:')); $content_types = Post::list_active_post_types(); unset($content_types['any']); foreach ($content_types as $k => $v) { $content_types[$k] = Plugins::filter('post_type_display', $k, 'plural'); } $form->append('checkboxes', 'content_types', $block, _t('Content Types to Include:'), $content_types); }
/** * returns the friendly name of a post type, or null * @param mixed a post type number, or name * @return mixed a string of the post type, or null */ public static function type_name( $type ) { $types = array_flip( Post::list_active_post_types() ); if ( is_numeric( $type ) && isset( $types[$type] ) ) { return $types[$type]; } if ( false !== in_array( $type, $types ) ) { return $type; } return ''; }
private function upgrade_db_post_3158() { // delete own_post_typeX tokens rather than rebuild the whole default token set foreach (Post::list_active_post_types() as $name => $posttype) { ACL::destroy_token('own_post_' . Utils::slugify($name)); } ACL::destroy_token('own_posts_any'); ACL::create_token('own_posts', _t('Permissions on one\'s own posts'), 'Content', true); }
/** * Parses a search string for status, type, author, and tag keywords. Returns * an associative array which can be passed to Posts::get(). If multiple * authors, statuses, tags, or types are specified, we assume an implicit OR * such that (e.g.) any author that matches would be returned. * * @param string $search_string The search string * @return array An associative array which can be passed to Posts::get() */ public static function search_to_get($search_string) { // if adding to this array, make sure you update the consequences of a search on this below in the switch. $keywords = array('author' => 1, 'status' => 1, 'type' => 1, 'tag' => 1, 'info' => 1); $statuses = Post::list_post_statuses(); $types = Post::list_active_post_types(); $arguments = array('user_id' => array(), 'status' => array(), 'content_type' => array(), 'tag' => array(), 'info' => array()); $criteria = ''; // this says, find stuff that has the keyword at the start, and then some term straight after. // the terms should have no whitespace, or if it does, be ' delimited. // ie tag:foo or tag:'foo bar' $flag_regex = '/(?P<flag>' . implode('|', array_keys($keywords)) . '):(?P<value>[^\'"][^\\s]*(?:\\s|$)|([\'"]+)(?P<quotedvalue>[^\\3]+)(?<!\\\\)\\3)/Uui'; // now do some matching. preg_match_all($flag_regex, $search_string, $matches, PREG_SET_ORDER); // now we remove those terms from the search string, otherwise the keyword search below has issues. It will pick up things like // from tag:'pair of' -> matches of' $criteria = trim(preg_replace($flag_regex, '', $search_string)); // go through flagged things. foreach ($matches as $match) { // switch on the type match. ie status, type et al. // also, trim out the quote marks that have been matched. if (isset($match['quotedvalue']) && $match['quotedvalue']) { $value = stripslashes($match['quotedvalue']); } else { $value = $match['value']; } switch (strtolower($match['flag'])) { case 'author': if ($u = User::get($value)) { $arguments['user_id'][] = (int) $u->id; } break; case 'tag': $arguments['tag'][] = $value; break; case 'status': if (isset($statuses[$value])) { $arguments['status'][] = (int) $statuses[$value]; } break; case 'type': if (isset($types[$value])) { $arguments['content_type'][] = (int) $types[$value]; } break; case 'info': if (strpos($value, ':') !== FALSE) { list($infokey, $infovalue) = explode(':', $value, 2); $arguments['info'][] = array($infokey => $infovalue); } break; } } // flatten keys that have single-element or no-element arrays foreach ($arguments as $key => $arg) { switch (count($arg)) { case 0: unset($arguments[$key]); break; case 1: $arguments[$key] = $arg[0]; break; } } if ($criteria != '') { $arguments['criteria'] = $criteria; } return $arguments; }
/** * The configure form */ public function action_plugin_ui_configure() { $ui = new FormUI(strtolower(__CLASS__)); $ui->append('static', 'explanation', _t('Select which content types you would like to include in the sitemap. By default, all public published content types are included.')); // Get all content types $content_types = Post::list_active_post_types(); // Display a checkbox for all content type foreach (array_keys($content_types) as $content_type) { $opt = $ui->append('checkbox', 'include_' . $content_type, __CLASS__ . '__' . $content_type, _t($content_type)); if ($content_type != "any") { $opt->class = "formcontrol sitexml"; } } $ui->append('submit', 'save', _t('Save')); // Expire the cache when we save options $ui->on_success(Cache::expire('sitemap')); $ui->set_option('success_message', _t('Options successfully saved.')); $ui->out(); }