本文整理汇总了PHP中Tags::get_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Tags::get_by_id方法的具体用法?PHP Tags::get_by_id怎么用?PHP Tags::get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tags
的用法示例。
在下文中一共展示了Tags::get_by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajax_tags
/**
* Handles AJAX from /admin/tags
* Used to delete and rename tags
*/
public function ajax_tags($handler_vars)
{
Utils::check_request_method(array('POST'));
$wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
if ($handler_vars['digest'] != $wsse['digest']) {
Session::error(_t('WSSE authentication failed.'));
echo Session::messages_get(true, array('Format', 'json_messages'));
return;
}
$tag_names = array();
$theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', true));
$this->theme = Themes::create('admin', 'RawPHPEngine', $theme_dir);
$action = $this->handler_vars['action'];
switch ($action) {
case 'delete':
foreach ($_POST as $id => $delete) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $delete) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
Tags::vocabulary()->delete_term($tag);
}
}
$msg_status = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names));
Session::notice($msg_status);
break;
case 'rename':
if (!isset($this->handler_vars['master'])) {
Session::error(_t('Error: New name not specified.'));
echo Session::messages_get(true, array('Format', 'json_messages'));
return;
}
$master = $this->handler_vars['master'];
$tag_names = array();
foreach ($_POST as $id => $rename) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $rename) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
}
}
Tags::vocabulary()->merge($master, $tag_names);
$msg_status = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master);
Session::notice($msg_status);
break;
}
$this->theme->tags = Tags::vocabulary()->get_tree();
$this->theme->max = Tags::vocabulary()->max_count();
echo json_encode(array('msg' => Session::messages_get(true, 'array'), 'tags' => $this->theme->fetch('tag_collection')));
}
示例2: post_count
/**
* Returns the count of times a tag is used.
*
* @param mixed The tag to count usage.
* @return int The number of times a tag is used.
**/
public static function post_count($tag)
{
if (is_int($tag)) {
$tag = Tags::get_by_id($tag);
} else {
if (is_string($tag)) {
$tag = Tags::get_by_slug(Utils::slugify($tag));
}
}
return DB::get_row('SELECT COUNT(tag_id) AS count FROM {tag2post} WHERE tag_id = ?', array($tag->id));
}
示例3: process_tags
/**
* Handles submitted tag forms and processes tag actions
* @param FormUI $form The tag form
*/
public function process_tags($form)
{
if ($_POST['action'] == 'delete') {
$tag_names = array();
foreach ($form->selected_items->value as $id) {
// We only collect the names so we can display them - deletion could also happen directly using the id
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
Tags::vocabulary()->delete_term($tag);
}
Session::notice(_n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names)));
} elseif ($_POST['action'] == 'rename') {
if (!isset($_POST['rename_text']) || empty($_POST['rename_text'])) {
Session::error(_t('Error: New name not specified.'));
} else {
$tag_names = array();
foreach ($form->selected_items->value as $id) {
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
}
Tags::vocabulary()->merge($_POST['rename_text'], $tag_names);
Session::notice(sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $_POST['rename_text']));
}
}
Utils::redirect(URL::get('display_tags'));
}
示例4: ajax_tags
/**
* Handles AJAX from /admin/tags
* Used to delete and rename tags
*/
public function ajax_tags($handler_vars)
{
Utils::check_request_method(array('POST'));
$response = new AjaxResponse();
$wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
if ($handler_vars['digest'] != $wsse['digest']) {
$response->message = _t('WSSE authentication failed.');
$response->out();
return;
}
$tag_names = array();
$this->create_theme();
$action = $this->handler_vars['action'];
switch ($action) {
case 'delete':
foreach ($_POST as $id => $delete) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $delete) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
Tags::vocabulary()->delete_term($tag);
}
}
$response->message = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names));
break;
case 'rename':
if (!isset($this->handler_vars['master'])) {
$response->message = _t('Error: New name not specified.');
$response->out();
return;
}
$master = $this->handler_vars['master'];
$tag_names = array();
foreach ($_POST as $id => $rename) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $rename) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
}
}
Tags::vocabulary()->merge($master, $tag_names);
$response->message = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master);
break;
}
$this->theme->tags = Tags::vocabulary()->get_tree('term_display ASC');
$this->theme->max = Tags::vocabulary()->max_count();
$response->data = $this->theme->fetch('tag_collection');
$response->out();
}