本文整理汇总了PHP中Post::list_active_post_types方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::list_active_post_types方法的具体用法?PHP Post::list_active_post_types怎么用?PHP Post::list_active_post_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::list_active_post_types方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_form_publish
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;
}
示例2: action_block_form_postblock
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');
}
示例3: action_admin_theme_get_admin_cctypes
/**
* 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];
}
}
示例4: configure
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;
}
示例5: filter_facetvalues
/**
* 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);
}
示例6: get
//.........这里部分代码省略.........
}
// 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)';
示例7: search_to_get
/**
* 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;
}
示例8: get_form
//.........这里部分代码省略.........
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;
}
示例9: action_block_form_grayposts
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');
}
示例10: post_posts
/**
* 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');
}
示例11: filter_dash_module_post_types_and_statuses
/**
* 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;
}
示例12: post_posts
/**
* 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');
}
示例13: get_form
//.........这里部分代码省略.........
$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;
}
示例14: get_code
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;
}
示例15: get_menu
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;
}