本文整理汇总了PHP中Tag::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::exists方法的具体用法?PHP Tag::exists怎么用?PHP Tag::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tag
的用法示例。
在下文中一共展示了Tag::exists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Recipe
function create_recipe() {
$recipe = new Recipe();
$this->db->insert('recipes', $_POST['recipe']);
$recipe = $recipe->where('title', $_POST['recipe']['title'])->get();
$tags = explode(" ",$_POST['tags']);
// create tag entries in db, save relationship
// would be nice to put in a model method maybe?
foreach($tags as $tag) {
echo "now creating $tag";
$t = new Tag();
$t->where('name', $tag)->get();
if (!$t->exists()) {
// save only if new
$t->name = $tag;
$t->save();
}
$recipe->save($t);
}
$this->load->view('recipes/thankyou');
}
示例2: index
function index()
{
list($params, $id, $slug) = $this->parse_params(func_get_args());
// Create or update
if ($this->method != 'get') {
$c = new Content();
switch ($this->method) {
case 'post':
case 'put':
if ($this->method == 'put') {
// Update
$c->get_by_id($id);
if (!$c->exists()) {
$this->error('404', "Content with ID: {$id} not found.");
return;
}
$c->old_published_on = $c->published_on;
$c->old_captured_on = $c->captured_on;
$c->old_uploaded_on = $c->uploaded_on;
if (isset($_POST['slug'])) {
$c->current_slug = $c->slug;
}
}
if (isset($_REQUEST['name'])) {
if (isset($_REQUEST['upload_session_start'])) {
$s = new Setting();
$s->where('name', 'last_upload')->get();
if ($s->exists() && $s->value != $_REQUEST['upload_session_start']) {
$s->value = $_REQUEST['upload_session_start'];
$s->save();
}
}
$file_name = $c->clean_filename($_REQUEST['name']);
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
$tmp_dir = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
$tmp_path = $tmp_dir . DIRECTORY_SEPARATOR . $file_name;
make_child_dir($tmp_dir);
if ($chunks == 0 || $chunk == $chunks - 1) {
if (isset($_REQUEST['text'])) {
$path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR;
$internal_id = false;
} else {
if (isset($_REQUEST['plugin'])) {
$info = pathinfo($_REQUEST['name']);
$path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $_REQUEST['plugin'] . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR;
$file_name = $_REQUEST['basename'] . '.' . $info['extension'];
$internal_id = false;
} else {
list($internal_id, $path) = $c->generate_internal_id();
}
}
if ($path) {
$path .= $file_name;
if ($chunks == 0) {
$tmp_path = $path;
}
} else {
$this->error('500', 'Unable to create directory for upload.');
return;
}
}
// Look for the content type header
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
} else {
if (isset($_SERVER["CONTENT_TYPE"])) {
$contentType = $_SERVER["CONTENT_TYPE"];
} else {
$contentType = '';
}
}
if (strpos($contentType, "multipart") !== false) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
$out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb");
if ($in) {
while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}
} else {
$this->error('500', 'Unable to read input stream.');
return;
}
fclose($out);
unlink($_FILES['file']['tmp_name']);
} else {
$this->error('500', 'Unable to write to output file.');
return;
}
} else {
$this->error('500', 'Unable to move uploaded file.');
return;
}
} else {
$out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
//.........这里部分代码省略.........
示例3: update_tags
/**
* Updates the tags associated with the given media.
*
* If the image can't be resized, its web and thumbnail images will
* be symlinked to the full size image to prevent broken image sources.
*
* @param Media $media The Media object to associate the tags with.
* @param array $tags An array of tag names.
*/
private static function update_tags($media, $tags)
{
// Remove all existing tag associations
Database::DELETE_FROM(TAG_RELATION_TABLE . ' WHERE image_id = ?', array($media->id));
foreach ($tags as $tag) {
// Skip empty tags
if (trim($tag) == '') {
continue;
}
// Create tags which don't exist yet
if (!Tag::exists($tag)) {
Tag::create($tag);
}
$media->add_tag($tag);
}
}
示例4: Tag
function _format_tags($tags)
{
$t = new Tag();
$model = $this->model;
$existing = array();
foreach ($this->tags->select('id,name')->get_iterated() as $tag) {
$existing[] = $tag->name;
}
if (empty($tags)) {
$remove = $existing;
} else {
$tags = koken_format_tags($tags);
$add = array_diff($tags, $existing);
$remove = array_diff($existing, $tags);
foreach ($add as $tag) {
$t->get_by_name($tag);
if (!$t->exists()) {
$t->name = $tag;
}
$t->last_used = time();
$t->save($this);
$t->update_counts($this->model);
}
}
foreach ($remove as $tag) {
$t->get_by_name($tag);
if ($t->exists()) {
$this->delete($t);
$t->update_counts($this->model);
}
}
}
示例5: getCreateTagModel
/**
* Retrieve tag model by name or save if not exist
* @param string $name
* @return \Tag
*/
protected function getCreateTagModel($name)
{
$name = $this->valuesHandler->input('string', $name);
$tagModel = new TagModel();
$tagModel->get_by_tag_name($name);
if (!$tagModel->exists()) {
$tagModel->tag_name = $name;
$tagModel->save();
}
return $tagModel;
}
示例6: index
function index()
{
$defaults = array('page' => 1, 'limit' => 20, 'context_order' => 'count');
list($params, $id, $slug) = $this->parse_params(func_get_args());
$params = array_merge($defaults, $params);
$t = new Tag();
if ($this->method !== 'get') {
if (is_null($id)) {
$this->error('400', 'ID is required.');
}
$tag = $t->get_by_id($id);
if ($this->method === 'delete') {
$tag->delete();
exit;
} else {
$tag->name = $this->input->post('name');
$tag->save();
$this->redirect('/tags/' . $tag->id);
}
}
if (!$slug && is_null($id)) {
$final = $t->listing($params);
} else {
$slug = urldecode($slug);
if ($slug) {
$t->where('name', $slug)->get();
} else {
$t->get_by_id($id);
}
$tag_array = $t->to_array();
$params['tag'] = $t->id;
$params['tag_slug'] = $t->name;
list($final, $counts) = $this->aggregate('tag', $params);
$final['counts'] = $counts;
$final = array_merge($tag_array, $final);
$prev = new Tag();
$next = new Tag();
$prev->where('id !=', $t->id);
$next->where('id !=', $t->id);
if ($params['context_order'] === 'count') {
$prev->group_start();
$prev->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '>', $t->essay_count + $t->album_count + $t->content_count), null);
$prev->or_group_start();
$prev->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '=', $t->essay_count + $t->album_count + $t->content_count), null);
$prev->where('name <', $t->name);
$prev->group_end();
$prev->group_end();
$next->group_start();
$next->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '<', $t->essay_count + $t->album_count + $t->content_count), null);
$next->or_group_start();
$next->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '=', $t->essay_count + $t->album_count + $t->content_count), null);
$next->where('name >', $t->name);
$next->group_end();
$next->group_end();
$prev->order_by_func('', array('@content_count', '+', '@text_count', '+', '@album_count'), 'ASC');
$next->order_by_func('', array('@content_count', '+', '@text_count', '+', '@album_count'), 'DESC');
} else {
$prev->where('name <', $t->name);
$next->where('name >', $t->name);
}
$prev->order_by('name DESC');
$next->order_by('name ASC');
$max = $next->get_clone()->count();
$min = $prev->get_clone()->count();
$final['context'] = array();
$final['context']['total'] = $max + $min + 1;
$final['context']['position'] = $min + 1;
$final['context']['previous'] = $final['context']['next'] = false;
$prev->get();
$next->get();
if ($prev->exists()) {
$final['context']['previous'] = $prev->to_array();
}
if ($next->exists()) {
$final['context']['next'] = $next->to_array();
}
}
$this->set_response_data($final);
}
示例7: listing
function listing($params, $id = false)
{
$sort = $this->_get_site_order('content');
$options = array('order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'page' => 1, 'match_all_tags' => false, 'limit' => 100, 'include_presets' => true, 'featured' => null, 'types' => false, 'auth' => false, 'favorites' => null, 'before' => false, 'after' => false, 'after_column' => 'uploaded_on', 'before_column' => 'uploaded_on', 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'in_album' => false, 'reduce' => false, 'is_cover' => true, 'independent' => false);
$options = array_merge($options, $params);
if (isset($params['order_by']) && !isset($params['order_direction'])) {
$options['order_direction'] = in_array($params['order_by'], array('title', 'filename')) ? 'ASC' : 'DESC';
}
Shutter::hook('content.listing', array($this, $options));
if ($options['featured'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'featured_on';
} else {
if ($options['favorites'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'favorited_on';
}
}
if ($options['auth']) {
if (isset($options['visibility']) && $options['visibility'] !== 'album') {
$values = array('public', 'unlisted', 'private');
if (in_array($options['visibility'], $values)) {
$options['visibility'] = array_search($options['visibility'], $values);
} else {
if ($options['visibility'] === 'any') {
$options['visibility'] = false;
} else {
$options['visibility'] = 0;
}
}
} else {
if (!isset($options['visibility']) || $options['visibility'] !== 'album') {
$options['visibility'] = 0;
}
}
} else {
if ($options['in_album']) {
$options['visibility'] = 'album';
} else {
$options['visibility'] = 0;
}
}
if ($options['visibility'] > 0 && $options['order_by'] === 'published_on') {
$options['order_by'] = 'captured_on';
}
if ($options['order_by'] == 'dimension') {
$options['order_by'] = 'width * height';
}
if (is_numeric($options['limit']) && $options['limit'] > 0) {
$options['limit'] = min($options['limit'], 100);
} else {
$options['limit'] = 100;
}
if ($options['independent']) {
$this->where_related('album', 'id', null);
}
if ($options['types']) {
$types = explode(',', str_replace(' ', '', $options['types']));
$this->group_start();
foreach ($types as $t) {
switch ($t) {
case 'photo':
$this->or_where('file_type', 0);
break;
case 'video':
$this->or_where('file_type', 1);
break;
case 'audio':
$this->or_where('file_type', 2);
break;
}
}
$this->group_end();
}
if ($options['search'] && $options['search_filter'] === 'tags') {
$options['tags'] = $options['search'];
$options['search'] = false;
}
if ($options['search']) {
$term = urldecode($options['search']);
if ($options['search_filter']) {
if ($options['search_filter'] === 'category') {
$cat = new Category();
$cat->where('title', $term)->get();
if ($cat->exists()) {
$this->where_related('category', 'id', $cat->id);
} else {
$this->where_related('category', 'id', 0);
}
} else {
$this->group_start();
$this->like($options['search_filter'], $term, 'both');
$this->group_end();
}
} else {
$this->group_start();
$this->like('title', $term, 'both');
$this->or_like('caption', $term, 'both');
$t = new Tag();
$t->where('name', $term)->get();
if ($t->exists()) {
$this->or_where_related('tag', 'id', $t->id);
//.........这里部分代码省略.........
示例8: listing
function listing($params)
{
$sort = $this->_get_site_order('album');
$options = array('trash' => false, 'page' => 1, 'order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'match_all_tags' => false, 'limit' => false, 'include_empty' => true, 'types' => false, 'featured' => false, 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'flat' => false, 'reduce' => false, 'id_not' => false, 'auth' => false);
$options = array_merge($options, $params);
if (isset($params['order_by']) && !isset($params['order_direction'])) {
$options['order_direction'] = in_array($params['order_by'], array('created_on', 'modified_on', 'published_on', 'total_count', 'image_count', 'video_count')) ? 'DESC' : 'ASC';
}
$options = Shutter::filter('api.albums.listing.options', $options);
Shutter::hook('albums.listing', array($this, $options));
if ($options['order_by'] === 'manual') {
$options['order_by'] = 'left_id';
if (!isset($params['order_direction'])) {
$options['order_direction'] = 'asc';
}
}
if ($options['featured'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'featured_on';
}
if (!is_numeric($options['limit'])) {
$options['limit'] = false;
}
if ($options['types']) {
$types = explode(',', str_replace(' ', '', $options['types']));
$this->group_start();
foreach ($types as $t) {
switch ($t) {
case 'set':
$this->or_where('album_type', 2);
break;
case 'smart':
$this->or_where('album_type', 1);
break;
case 'standard':
$this->or_where('album_type', 0);
break;
}
}
$this->group_end();
}
if ($options['search'] && $options['search_filter'] === 'tags') {
$options['tags'] = $options['search'];
$options['search'] = false;
}
if ($options['search']) {
$term = urldecode($options['search']);
if ($options['search_filter']) {
if ($options['search_filter'] === 'category') {
$cat = new Category();
$cat->where('title', $term)->get();
if ($cat->exists()) {
$this->where_related('category', 'id', $cat->id);
} else {
$this->where_related('category', 'id', 0);
}
} else {
$this->group_start();
$this->like($options['search_filter'], $term, 'both');
$this->group_end();
}
} else {
$this->group_start();
$this->like('title', $term, 'both');
$this->or_like('description', $term, 'both');
$t = new Tag();
$t->where('name', $term)->get();
if ($t->exists()) {
$this->or_where_related('tag', 'id', $t->id);
}
$this->group_end();
}
} else {
if ($options['tags'] || $options['tags_not']) {
$this->_do_tag_filtering($options);
}
}
if ($options['id_not']) {
$this->where_not_in('id', explode(',', $options['id_not']));
}
$sub_list = false;
if ($this->exists()) {
$sub_list = true;
$this->where('left_id >', $this->left_id)->where('right_id <', $this->right_id)->where('level', $this->level + 1)->where('visibility', $this->visibility);
$options['visibility'] = $this->visibility;
} else {
if ($options['auth']) {
if (isset($options['visibility'])) {
$values = array('public', 'unlisted', 'private');
if (in_array($options['visibility'], $values)) {
$options['visibility'] = array_search($options['visibility'], $values);
} else {
$options['visibility'] = 0;
}
} else {
$options['visibility'] = 0;
}
} else {
$options['visibility'] = 0;
}
}
//.........这里部分代码省略.........
示例9: index
function index()
{
list($params, $id, $slug) = $this->parse_params(func_get_args());
$params['auth'] = $this->auth;
// Create or update
if ($this->method != 'get') {
$t = new Text();
switch ($this->method) {
case 'post':
case 'put':
if ($id) {
$t->get_by_id($id);
$t->old_published = $t->published;
$t->current_slug = $t->slug;
if (isset($_POST['unpublish'])) {
$_POST['published'] = 0;
$_POST['published_on'] = null;
}
} else {
if (isset($_POST['page_type']) && $_POST['page_type'] === 'page') {
$_POST['published'] = 1;
}
}
$arr = $_POST;
global $raw_input_data;
if (isset($raw_input_data['content'])) {
$arr['content'] = $raw_input_data['content'];
}
if (isset($raw_input_data['draft'])) {
$arr['draft'] = $raw_input_data['draft'];
}
// Little hack here to make sure content validation is always run
// (newline gets stripped in text->_format_content)
if (isset($arr['content'])) {
$arr['content'] .= "\n";
}
try {
$t->from_array($arr, array(), true);
} catch (Exception $e) {
$this->error('400', $e->getMessage());
return;
}
if (isset($_POST['tags'])) {
$t->_format_tags($_POST['tags']);
} else {
if ($this->method === 'put' && isset($_POST['published'])) {
$t->_update_tag_counts();
}
}
$arr = $t->to_array(array('expand' => true));
if ($id) {
Shutter::hook('text.update', $arr);
} else {
Shutter::hook('text.create', $arr);
}
$this->redirect("/text/{$t->id}" . (isset($params['render']) ? '/render:' . $params['render'] : ''));
break;
case 'delete':
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
} else {
if (is_numeric($id)) {
$id = array($id);
} else {
$id = explode(',', $id);
}
$tags = array();
foreach ($id as $text_id) {
$text = $t->get_by_id($text_id);
if ($text->exists()) {
$tags = array_merge($tags, $text->tags);
$s = new Slug();
$prefix = $text->page_type == 0 ? 'essay' : 'page';
$this->db->query("DELETE FROM {$s->table} WHERE id = '{$prefix}.{$text->slug}'");
Shutter::hook('text.delete', $text->to_array(array('auth' => true)));
if (!$text->delete()) {
// TODO: More info
$this->error('500', 'Delete failed.');
return;
}
}
}
}
exit;
break;
}
}
$p = new Text();
// No id, so we want a list
if (is_null($id) && !$slug) {
$params['state'] = 'published';
$final = $p->listing($params);
} else {
if (!is_null($id)) {
if (is_numeric($id)) {
$page = $p->get_by_id($id);
} else {
$this->auth = $params['auth'] = true;
$page = $p->get_by_internal_id($id);
//.........这里部分代码省略.........
示例10: validTag
/**
* Validation - Check if tag_id is a valid id
*/
public function validTag($data)
{
$values = array_values($data);
if (!isset($values)) {
return false;
}
$value = $values[0];
/* Load the Tag model */
App::import("Webzash.Model", "Tag");
$Tag = new Tag();
if ($Tag->exists($value)) {
return true;
} else {
return false;
}
}
示例11: array
<?php
include '../../inc/init.inc';
if ((!isset($title) || $title == "") && !isset($question_id) || (!isset($content) || $content == "")) {
$res->load('questions', array());
} else {
if (isset($title)) {
$args['title'] = $title;
}
if (isset($question_id)) {
$args['question_id'] = $question_id;
}
$args['content'] = $content;
$args['user_id'] = $res->user->id;
$question = Question::create($args);
if (isset($tag_list_values)) {
$tags = explode(',', $tag_list_values);
foreach ($tags as $tagName) {
$tagName = strtoupper($tagName);
if (Tag::exists(array('name' => $tagName))) {
$tag = Tag::find_by_name($tagName);
} else {
$tag = Tag::create(array('name' => $tagName));
}
Questions_Tag::create(array('question_id' => $question->id, 'tag_id' => $tag->id));
}
}
}
$res->load('question', array('id' => $question->id));