protected function validate_tag() { if (!Tag::where(['name' => $this->name])->first()) { $this->errors()->add('tag', "couldn't be created"); return false; } }
public function show($name) { $tag = Tag::where('name', '=', $name)->firstOrFail(); $articles = $tag->articles()->where('cid', '>', '0')->with('category')->orderBy('id', 'desc')->paginate(10); $values = array('title' => '标签:' . $tag->name . '_', 'tag' => &$tag, 'articles' => &$articles); return View::make('tag.show', $values); }
public function getTagPosts($name) { try { $tag = Tag::where('name', $name)->first(); if (!$tag) { throw new Exception("Tag not found"); } $posts = $tag->posts()->paginate(8); $i = 0; foreach ($posts as $post) { if (!PrivacyHelper::checkPermission(Auth::user(), $post)) { unset($posts[$i]); $i++; continue; } $i++; $post->makrdown = str_limit($post->makrdown, $limit = 500, $end = '...'); $Parsedown = new Parsedown(); $post->HTML = $Parsedown->text($post->makrdown); } if (Request::ajax()) { return View::make('posts._list')->with('data', $posts); } else { if (count($posts) == 0) { return Redirect::intended(URL::action('ProfileController@getProfile', array($id))); } $this->layout->content = View::make('posts.list')->with('data', $posts); } } catch (Exception $e) { throw $e; } }
public static function getTagByName($name) { if (empty($name)) { return null; } return Tag::where('name', '=', $name); }
function submit() { $data['title'] = 'Submit a Project'; $project = new Project(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get the scalars. $project->from_array($_POST); // Convert properly to boolean if ($project->show_contact == 'yes') { $project->show_contact = TRUE; } else { $project->show_contact = FALSE; } // Handle the relations (tags) if ($project->save($this->_current_user())) { // validations run $this->_save_tags($project); $this->_submit_on_success(); } else { // invalid $data['error'] = $project->error->string; } } // Otherwise, render a form. $tags = new Tag(); foreach (array('field', 'type', 'location') as $category) { $tags->where('category', $category)->get(); $data[$category . '_tags'] = array(); foreach ($tags as $tag) { array_push($data[$category . '_tags'], $tag->name); } } $data['form'] = $project->render_form(array('title', 'start_date', 'end_date', 'field', 'type', 'location', 'text', 'show_contact')); $this->load->view('form_project', $data); }
public function index() { $tags = User::find(Auth::user()->id)->tags()->get(); $tags = Tag::where('user_id', '=', Auth::user()->id)->orWhereHas('notes', function ($query) { $query->whereHas('users', function ($query) { $query->where('note_user.user_id', '=', Auth::user()->id); }); })->where('visibility', '=', 1)->get(); return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $tags); }
public static function createOrGetTags($tagsArray, $noteId, $noteUmask) { $tagsPublicPrefixCharacter = Config::get('paperwork.tagsPublicPrefixCharacter')[0]; $createdOrFoundIds = array(); if (is_null($tagsArray)) { return null; } $userId = Auth::user()->id; foreach ($tagsArray as $tagItem) { $tagTitle = ''; $tagVisibility = 0; if ($tagItem[0] === $tagsPublicPrefixCharacter) { $tagTitle = strtolower(substr($tagItem, 1)); $tagVisibility = 1; $tag = Tag::where('tags.title', '=', $tagTitle)->where('tags.visibility', '=', $tagVisibility)->first(); } else { $tagTitle = strtolower($tagItem); $tagVisibility = 0; $tag = Tag::where('tags.title', '=', $tagTitle)->where('tags.visibility', '=', $tagVisibility)->where('tags.user_id', '=', $userId)->first(); } // ->where('tags.title', '=', $tagTitle) // ->where('tags.visibility', '=', $tagVisibility) // ->select('tags.id') // ->first(); if (is_null($tag) && ($tagVisibility == 0 || $tagVisibility == 1 && $noteUmask > PaperworkHelpers::UMASK_READONLY)) { $newTag = new Tag(); $newTag->title = $tagTitle; $newTag->visibility = $tagVisibility; $newTag->user_id = $userId; $newTag->save(); //$newTag->users()->attach(Auth::user()->id); $createdOrFoundIds[] = $newTag->id; } else { if ($tagVisibility == 0 || $tagVisibility == 1 && $noteUmask > PaperworkHelpers::UMASK_READONLY) { /*if(is_null($tag->users()->where('users.id', '=', Auth::user()->id)->first())) { $tag->users()->attach(Auth::user()->id); }*/ $createdOrFoundIds[] = $tag->id; } } } //we need to add the other user's private tags to the list. $addtags = Note::find($noteId)->tags()->where('tags.visibility', '=', 0)->where('tags.user_id', '!=', $userId)->get(); foreach ($addtags as $addtag) { $createdOrFoundIds[] = $addtag->id; } //if the user is not writer, he cannot change public tags. if ($noteUmask < PaperworkHelpers::UMASK_READWRITE) { $addpubtags = Note::find($noteId)->tags()->where('tags.visibility', '=', 1)->get(); foreach ($addpubtags as $addtag) { $createdOrFoundIds[] = $addtag->id; } } return $createdOrFoundIds; }
public function addTagOrCreateNew($tag, $user_id = 0) { $tagFound = Tag::where('id', '=', $tag)->first(); if (!isset($tagFound)) { $tagFound = new Tag(); $tagFound->name = $tag; $tagFound->user_id = $user_id; $tagFound->save(); } $tagFound->crafts()->save($this); }
public function filterResources() { $name = Input::get('name'); $tag = Tag::where('name', 'LIKE', $name . '%')->get(); if (Request::ajax()) { foreach ($tag as $tag_name) { $results[] = $tag_name->name; print_r($results); } return json_encode(array('tags' => $results)); } $this->layout->content = View::make('tags.resource_tag')->with('tag', $tag); }
public function validateTag($attribute, $value, $parameters, $validator) { $requiredReputation = $parameters[0]; // required reputation points $userReputation = auth()->guest() ? 0 : auth()->user()->reputation; if ($userReputation >= $requiredReputation) { return true; } $tag = Tag::where('name', $value)->pluck('id'); if ($tag) { return true; } return false; }
function _do_tag_filtering($options) { if ($options['tags_not']) { $not = true; $options['tags'] = $options['tags_not']; } else { $not = false; } $tags = explode(',', urldecode($options['tags'])); if ($options['match_all_tags'] || $not) { $content_ids = false; $model = $this->model === 'album' ? 'albums' : $this->model; foreach ($tags as $tag) { $t = new Tag(); $t->where('name', $tag)->get(); if ($t->exists()) { $tag_content_ids = array(); foreach ($t->{$model}->select('id')->get_iterated() as $content) { $tag_content_ids[] = $content->id; } if ($content_ids === false) { $content_ids = $tag_content_ids; } else { if ($options['match_all_tags']) { $content_ids = array_intersect($content_ids, $tag_content_ids); } else { $content_ids = array_merge($content_ids, $tag_content_ids); } } } } if ($not) { $this->where_not_in('id', $content_ids); } else { $this->where_in('id', $content_ids); } } else { $this->distinct(); $this->group_start(); foreach ($tags as $tag) { $t = new Tag(); $t->where('name', $tag)->get(); if ($t->exists()) { $this->or_where_related('tag', 'id', $t->id); } } $this->group_end(); } }
/** * Private! Please do not call this function directly, let the Tag library use it. * Decrement count of tag by one. This function will create tag record if it does not exist. * * @param string $tagString */ public static function decrementCount($tagName, $count, $tag = null) { if ($count <= 0) { return; } if (!$tag) { $tag = Tag::where('tag', '=', $tagName)->first(); } $tag->count = $tag->count - $count; if ($tag->count < 0) { $tag->count = 0; \Log::warning("The \\App\\Modules\\Tag count for `{$tag->name}` was a negative number. This probably means your data got corrupted. Please assess your code and report an issue if you find one."); } $tag->save(); }
public function getTag($tag) { $filtered_tags = array(); $tags = Tag::where('name', '=', $tag)->orderBy('confidence', 'desc')->get(); foreach ($tags as $tag_object) { if ($tag_object->image) { foreach ($tag_object->image->tags()->orderBy('confidence', 'desc')->take(5)->get() as $image_tag) { if ($image_tag->name == $tag) { array_push($filtered_tags, $tag_object); } } } } return View::make('photos.tag', array('tag' => $tag, 'tags' => $filtered_tags)); }
public function tag($the_tags) { $ids = array(); foreach ($the_tags as &$tag_str) { $tag_str = Str::slug(trim($tag_str)); $tag = Tag::where('name', '=', $tag_str)->first(); if ($tag) { $tag->count = $tag->count + 1; $tag->save(); $ids[] = $tag->id; } else { $tag = Tag::create(array('name' => $tag_str, 'count' => 1)); $ids[] = $tag->id; } } $this->tags()->sync($ids); }
/** * Json list */ public function json_list() { if (strlen(Input::get('term')) >= 2) { $q = Tag::where('name', 'LIKE', '%' . Input::get('term') . '%'); if (Input::get('olds')) { $tags = explode(',', Input::get('olds')); $q->whereNotIn('id', $tags); } $list = $q->lists('name', 'id'); } else { $list = array(); } $ajaxArray = array(); foreach ($list as $key => $value) { $ajaxArray[] = array("name" => $value); } return Response::json($ajaxArray); }
/** * Suggest tags * POST /suggesttags * * @return Response */ public function suggestTags() { $arr = array(); $missingParam = ''; $keyword = trim(Input::get('keyword')); if ($keyword == '') { $missingParam .= 'keyword,'; } if (Input::get('language') == '') { $missingParam .= 'language,'; } if ($missingParam != '') { $arr['Success'] = false; $arr['Status'] = 'Parameter missing: ' . rtrim($missingParam, ','); $arr['StatusCode'] = 400; } else { if (strlen($keyword) < 3) { $arr['Success'] = false; $arr['Status'] = 'No Matches found'; $arr['StatusCode'] = 404; } else { $tags = Tag::where('hash_name', 'LIKE', "%{$keyword}%")->get(); if (count($tags) > 0) { $arr['Success'] = true; $arr['Status'] = 'OK'; $arr['StatusCode'] = 200; $arr['language'] = Input::get('language'); $arr['Result'] = array(); $i = 0; foreach ($tags as $tg) { $arr['Result'][$i]['id'] = $tg->hash_id; $arr['Result'][$i]['name'] = ucfirst($tg->hash_name); $i++; } } else { $arr['Success'] = false; $arr['Status'] = 'No matches found'; $arr['StatusCode'] = 404; } } } return Response::json($arr); }
public function get_suggestions($type = 'edit') { $retval = array(); $term = Input::get('term', ''); if ($term) { $tags = Tag::where('tag', 'LIKE', '%' . $term . '%')->get(); foreach ($tags as $tag) { if ($type == 'filter' && strpos($tag->tag, ':') !== false) { $tag_prefix = substr($tag->tag, 0, strpos($tag->tag, ':')); $tag_asterisk = $tag_prefix . ':*'; if (!in_array($tag_asterisk, $retval)) { $retval[] = $tag_asterisk; } } $retval[] = $tag->tag; } } return json_encode($retval); }
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'); }
public function tag($tag) { $page = Input::get('page'); if (!empty($page)) { $page = Input::get('page'); } else { $page = 1; } if (!isset($tag)) { return Redirect::to('videos'); } $tag_name = $tag; $tag = Tag::where('name', '=', $tag)->first(); $tags = VideoTag::where('tag_id', '=', $tag->id)->get(); $tag_array = array(); foreach ($tags as $key => $tag) { array_push($tag_array, $tag->video_id); } $videos = Video::where('active', '=', '1')->whereIn('id', $tag_array)->paginate($this->videos_per_page); $data = array('videos' => $videos, 'current_page' => $page, 'page_title' => 'Videos tagged with "' . $tag_name . '"', 'page_description' => 'Page ' . $page, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'pagination_url' => '/videos/tags/' . $tag_name, 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all()); return View::make('Theme::video-list', $data); }
function post_add() { if (!cmsHelper::isCurrentUserAllowedToPerform('tags')) { return; } //Flash current values to session Input::flash(); //Same action is used for editing and adding a new category $tag_title = Input::get("tagName"); $tag_url = Input::get("tagNameUrl"); $saving_id = Input::get('editingMode'); //Add rules here $rules = array('tagName' => 'required|max:100', 'tagNameUrl' => 'required'); //Get all inputs fields $input = Input::all(); //Apply validaiton rules $validation = Validator::make($input, $rules); $checkIfTagExists = Tag::where('id', '!=', $saving_id)->where('turl', '=', $tag_url)->count(); //Check if same tag exists if ($checkIfTagExists > 0) { return Redirect::to('/admin/tags/add')->with("errormessage", "Tag with the same url already exists"); } //Validate rules if ($validation->fails()) { return Redirect::to('/admin/tags/add')->with_errors($validation); } $temp = !empty($saving_id) ? Tag::find($saving_id) : new Tag(); $temp->turl = $tag_url; $temp->tname = $tag_title; $temp->save(); Input::flush(); if (!empty($saving_id)) { return Redirect::to('/admin/tags/edit?id=' . $saving_id)->with('successmessage', "Tag Edited successfully"); } else { return Redirect::to('/admin/tags/add')->with("successmessage", "New Tag Added successfully"); } }
public function updateStatusN() { $tagID = Input::get('id'); Tag::where('tag_id', '=', $tagID)->update(array('status' => 'Not')); echo $tagID; }
public function tag_links($tags, array $options = array()) { if (!$tags) { return ''; } $prefix = isset($options['prefix']) ? $options['prefix'] : ""; $html = ""; if (is_string(current($tags))) { if (key($tags) !== 0) { $tags = array_keys($tags); } $tags = Tag::where("name in (?)", $tags)->select("tag_type, name, post_count, id")->order('name')->take(); $tags = $tags->reduce(array(), function ($all, $x) { $all[] = [$x->type_name, $x->name, $x->post_count, $x->id]; return $all; }); } elseif (is_array(current($tags))) { # $x is expected to have name as first value and post_count as second. $tags = array_map(function ($x) { return array(array_shift($x), array_shift($x)); }, $tags); $tags_type = Tag::batch_get_tag_types(array_map(function ($data) { return $data[0]; }, $tags)); $i = 0; foreach ($tags_type as $k => $type) { array_unshift($tags[$i], $type); $i++; } } elseif (current($tags) instanceof Tag) { $tags = array_map(function ($x) { return array($x->type_name, $x->name, $x->post_count, $x->id); }, $tags->members()); } // switch ($this->controller()->action_name()) { // case 'show': usort($tags, function ($a, $b) { $aidx = array_search($a[0], CONFIG()->tag_order); false === $aidx && ($aidx = 9); $bidx = array_search($b[0], CONFIG()->tag_order); false === $bidx && ($bidx = 9); if ($aidx == $bidx) { return strcmp($a[1], $b[1]); } return $aidx > $bidx ? 1 : -1; }); // vde($tags); // break; // case 'index': // usort($tags, function($a, $b){ // $aidx = array_search($a[0], CONFIG()->tag_order); // false === $aidx && $aidx = 9; // $bidx = array_search($b[0], CONFIG()->tag_order); // false === $bidx && $bidx = 9; // if ($aidx == $bidx) // return 0; // return ($aidx > $bidx) ? 1 : -1; // }); // break; // } // case controller.action_name // when 'show' // tags.sort_by! { |a| [Tag::TYPE_ORDER[a[0]], a[1]] } // when 'index' // tags.sort_by! { |a| [Tag::TYPE_ORDER[a[0]], -a[2].to_i, a[1]] } // end foreach ($tags as $t) { $tag_type = array_shift($t); $name = array_shift($t); $count = array_shift($t); $id = array_shift($t); !$name && ($name = 'UNKNOWN'); // $tag_type = Tag::type_name($name); // $html .= '<li class="tag-type-' . $tag_type . '">'; $html .= '<li class="tag-link tag-type-' . $tag_type . '" data-name="' . $name . '" data-type="' . $tag_type . '">'; if (CONFIG()->enable_artists && $tag_type == 'artist') { $html .= '<a href="/artist/show?name=' . $this->u($name) . '">?</a> '; } else { $html .= '<a href="/wiki/show?title=' . $this->u($name) . '">?</a> '; } if (current_user()->is_privileged_or_higher()) { $html .= '<a href="/post?tags=' . $this->u($name) . '+' . $this->u($this->params()->tags) . '" class="no-browser-link">+</a> '; $html .= '<a href="/post?tags=-' . $this->u($name) . '+' . $this->u($this->params()->tags) . '" class="no-browser-link">–</a> '; } if (!empty($options['with_hover_highlight'])) { $mouseover = ' onmouseover="Post.highlight_posts_with_tag(\'' . $this->escapeJavascript($name) . '\')"'; $mouseout = ' onmouseout="Post.highlight_posts_with_tag(null)"'; } else { $mouseover = $mouseout = ''; } $html .= '<a href="/post?tags=' . $this->u($name) . '"' . $mouseover . $mouseout . '>' . str_replace("_", " ", $name) . '</a> '; $html .= '<span class="post-count">' . $count . '</span> '; $html .= '</li>'; } return $html; }
public function headerHashtag() { $query = Tag::where('status', 'Use')->get(); return View::make('header')->with(array('tag' => 'all', 'tag' => $query)); }
static function getAllArticlesByTagUrl($tagUrl, &$message, $orderby = 'id') { $curTag = Tag::where('turl', '=', $tagUrl)->first(); $articles = $curTag->Articles(); //If user is not admin, show only his articles if (Auth::user()->type != 1) { $articles = $articles->where('author_id', '=', Auth::user()->id); } $articles = $articles->order_by($orderby, 'desc'); $message = "Showing all articles of tag named " . $curTag->tname; return $articles; }
public function getCloud() { $tags = Tag::where('confidence', '>=', 10)->get(); $tag_cloud = $this->getTags($tags); return View::make('tags.cloud', array('tag_cloud' => $tag_cloud, 'title' => 'Tag cloud')); }
public function hashtag() { $query = Tag::where('status', 'Use')->get(); return Response::json($query); }
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 $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) { fwrite($out, $buff); } } else { $this->error('500', 'Unable to read uploaded file.'); return; } fclose($out); } else { $this->error('500', 'Unable to open output stream.'); return; } } if ($chunk < $chunks - 1) { // Don't continue until all chunks are uploaded exit; } else { if ($chunks > 0) { // Done, move to permanent location and save to DB rename($tmp_path, $path); } } if (!$internal_id) { // Custom text uploads can stop here die(json_encode(array('filename' => $file_name))); } $from = array(); $from['filename'] = $file_name; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { if (isset($_POST['localfile'])) { $filename = basename($_REQUEST['localfile']); list($internal_id, $path) = $c->generate_internal_id(); if (!file_exists($_REQUEST['localfile'])) { $this->error('500', '"localfile" does not exist.'); return; } if ($path) { $path .= $filename; } else { $this->error('500', 'Unable to create directory for upload.'); return; } copy($_REQUEST['localfile'], $path); $from = array(); $from['filename'] = $filename; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { if (isset($_POST['from_url'])) { $filename = basename($_POST['from_url']); list($internal_id, $path) = $c->generate_internal_id(); if ($path) { $path .= $filename; } else { $this->error('500', 'Unable to create directory for upload.'); return; } if ($this->_download(urldecode($_POST['from_url']), $path, true) && file_exists($path)) { $from = array(); $from['filename'] = $filename; $from['internal_id'] = $internal_id; $from['file_modified_on'] = time(); } else { $this->error('500', 'Unable to import file from provided URL.'); return; } } else { if (is_null($id)) { $this->error('403', 'New content records must be accompanied by an upload.'); return; } } } } if (isset($from)) { $from = array_merge($_POST, $from); } else { $from = $_POST; } if (isset($_REQUEST['rotate']) && is_numeric($_REQUEST['rotate']) && $c->exists()) { $r = $_REQUEST['rotate']; if (abs($r) != 90) { $this->error('403', 'Rotation can only be done in multiples of 90.'); return; } if (empty($c->storage_url)) { $path = $c->path_to_original(); $info = pathinfo($path); $midsize_path = preg_replace('/\\.' . $info['extension'] . '$/', '.1600.' . $info['extension'], $path); if (file_exists($midsize_path)) { $midsize = $midsize_path; } } else { $path = tempnam(sys_get_temp_dir(), 'original'); file_put_contents($path, file_get_contents($c->storage_url)); if (!empty($c->storage_url_midsize)) { $midsize = tempnam(sys_get_temp_dir(), 'midsize'); file_put_contents($midsize, file_get_contents($c->storage_url_midsize)); } } $s = new Setting(); $s->where('name', 'image_processing_library')->get(); include_once FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php'; $d = DarkroomUtils::init($s->value); $d->rotate($path, $r); if (isset($midsize)) { $d->rotate($midsize, $r); } if (!empty($c->storage_url)) { $key = $c->path . '/' . $c->filename; Shutter::store_original($path, $c->path . '/' . $c->filename); unlink($path); if (isset($midsize)) { $info = pathinfo($key); $key = preg_replace('/\\.' . $info['extension'] . '$/', '.1600.' . $info['extension'], $key); Shutter::store_original($midsize, $key); unlink($midsize); } } $c->clear_cache(); $from['width'] = $c->height; $from['height'] = $c->width; $from['aspect_ratio'] = $from['width'] / $from['height']; $from['file_modified_on'] = time(); } if (isset($_REQUEST['reset_internal_id']) && $_REQUEST['reset_internal_id'] && $c->exists()) { list($from['internal_id'], ) = $c->generate_internal_id(true); } $hook = 'content.' . ($id ? 'update' : 'create'); if (isset($from['filename']) && $id) { $c->clear_cache(); $hook .= '_with_upload'; $c->_before(); } $from = Shutter::filter("api.{$hook}", array_merge($from, array('id' => $id, 'file' => isset($path) ? $path : $c->path_to_original()))); unset($from['file']); try { $c->from_array($from, array(), true); } catch (Exception $e) { $this->error('400', $e->getMessage()); return; } if (isset($_POST['tags'])) { $c->_format_tags($_POST['tags']); } else { if ($this->method === 'put' && isset($_POST['visibility'])) { $c->_update_tag_counts(); } } $c->_readify(); $content = $c->to_array(array('auth' => true)); if ($hook === 'content.create' || $hook === 'content.update_with_upload') { if (ENVIRONMENT === 'production') { $this->load->library('mcurl'); if ($this->mcurl->is_enabled()) { $options = array(CURLOPT_HTTPHEADER => array('Connection: Close', 'Keep-Alive: 0')); $this->mcurl->add_call('normal', 'get', $content['presets']['medium_large']['url'], array(), $options); $this->mcurl->add_call('cropped', 'get', $content['presets']['medium_large']['cropped']['url'], array(), $options); $this->mcurl->execute(); } } $external_storage_url = Shutter::store_original($c->path_to_original(), str_replace('/storage/originals/', '', $content['original']['relative_url'])); if ($external_storage_url) { unlink($c->path_to_original()); $o = new Content(); $o->where('id', $content['id'])->update(array('storage_url' => $external_storage_url)); $content['storage_url'] = $external_storage_url; } } Shutter::hook($hook, $content); // Important to prevent failures from Lr plugin header('Connection: close'); $this->redirect("/content/{$c->id}" . (isset($params['context']) ? '/context:' . $params['context'] : '')); break; case 'delete': if (is_null($id)) { $this->error('403', 'Required parameter "id" not present.'); return; } else { $t = new Tag(); if (is_numeric($id)) { $content = $c->get_by_id($id); if ($c->exists()) { $trash = new Trash(); $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'"); $c->do_delete(); } else { $this->error('404', "Content with ID: {$id} not found."); return; } } else { $is_trash = $id === 'trash'; if ($id === 'trash') { $id = array(); $trash = new Trash(); $trash->like('id', 'content-')->select_func('REPLACE', '@id', 'content-', '', 'actual_id')->get_iterated(); foreach ($trash as $item) { $id[] = (int) $item->actual_id; } } else { $id = explode(',', $id); } /* Multiple delete /content/n1/n2/n3 */ // Keep track of tags to -- $tags = array(); $c->where_in('id', $id); $contents = $c->get_iterated(); $trash = new Trash(); foreach ($contents as $c) { if ($c->exists()) { $tags = array_merge($tags, $c->tags); $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'"); $c->do_delete(); } } } } exit; break; } } $c = new Content(); if ($slug || isset($id) && strpos($id, ',') === false) { $options = array('context' => false, 'neighbors' => false); $options = array_merge($options, $params); $original_context = $options['context']; if ($options['context'] && !in_array($options['context'], array('stream', 'favorites', 'features')) && strpos($options['context'], 'tag-') !== 0 && strpos($options['context'], 'category-') !== 0) { if (is_numeric($options['context'])) { $context_field = 'id'; } else { $context_field = 'slug'; $options['context'] = str_replace('slug-', '', $options['context']); } $a = new Album(); $a->group_start()->where($context_field, $options['context'])->or_where('internal_id', $options['context'])->group_end()->get(); $c->include_join_fields()->where_related_album('id', $a->id); } $with_token = false; if (is_numeric($id)) { $content = $c->where('deleted', 0)->get_by_id($id); } else { if ($slug) { $content = $c->where('deleted', 0)->group_start()->where('internal_id', $slug)->or_where('slug', $slug)->or_like('old_slug', ',' . $slug . ',', 'both')->group_end()->get(); } else { $content = $c->where('deleted', 0)->where('internal_id', $id)->get(); } if ($content->exists() && $content->internal_id === (is_null($id) ? $slug : $id)) { $with_token = true; } } if ($content->exists()) { if ($c->visibility == 1 && !$this->auth && !$with_token || !$this->auth && !is_numeric($id) && $c->visibility == 2) { $this->error('403', 'Private content.'); return; } $options['auth'] = $this->auth; if ($options['neighbors']) { // Make sure $neighbors is at least 2 $options['neighbors'] = max($options['neighbors'], 2); // Make sure neighbors is even if ($options['neighbors'] & 1 != 0) { $options['neighbors']++; } $options['neighbors'] = $options['neighbors'] / 2; $single_neighbors = false; } else { $options['neighbors'] = 1; $single_neighbors = true; } if ($options['context'] && !in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) { $options['in_album'] = $a; } $final = $content->to_array($options); if ($options['context']) { // TODO: Performance check $next = new Content(); $prev = new Content(); $in_a = new Album(); $next->where('deleted', 0); $prev->where('deleted', 0); $options['context'] = urldecode($options['context']); if (!in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) { if (!isset($options['context_order'])) { list($options['context_order'], $options['context_order_direction']) = explode(' ', $a->sort); } $final['context']['album'] = $a->to_array(array('auth' => $this->auth || $options['context'] === $a->internal_id)); $in_a->where("{$context_field} !=", $options['context']); $next->where_related_album('id', $a->id); $prev->where_related_album('id', $a->id); if ($options['context_order'] === 'manual') { $next->order_by_join_field('album', 'order', 'ASC')->group_start()->where_join_field('album', 'order >', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id >', $content->join_id)->group_end()->group_end(); $prev->order_by_join_field('album', 'order', 'DESC')->group_start()->where_join_field('album', 'order <', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id <', $content->join_id)->group_end()->group_end(); } else { $next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>'; $prev_operator = $next_operator === '<' ? '>' : '<'; $next->group_start()->where($options['context_order'] . " {$next_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$next_operator}", $content->id)->group_end()->group_end(); $prev->group_start()->where($options['context_order'] . " {$prev_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$prev_operator}", $content->id)->group_end()->group_end(); } if (!$this->auth) { $next->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2); $prev->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2); } $in_album = $a; $final['context']['type'] = 'album'; $final['context']['title'] = $a->title; $final['context']['__koken_url'] = $final['context']['album']['__koken_url']; $final['context']['url'] = $final['context']['album']['url']; } else { if (!isset($options['context_order'])) { $options['context_order'] = 'captured_on'; $options['context_order_direction'] = 'DESC'; } else { if ($options['context_order'] === 'manual' && $original_context === 'favorites') { $options['context_order'] = 'favorite_order'; $options['context_order_direction'] = 'ASC'; } else { if ($options['context_order'] === 'manual' && $original_context === 'features') { $options['context_order'] = 'featured_order'; $options['context_order_direction'] = 'ASC'; } } } $next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>'; $prev_operator = $next_operator === '<' ? '>' : '<'; $next->group_start()->where($options['context_order'] . " {$next_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$next_operator}", $content->id)->group_end()->group_end(); $prev->group_start()->where($options['context_order'] . " {$prev_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$prev_operator}", $content->id)->group_end()->group_end(); if (strpos($original_context, 'tag-') === 0) { $tag = str_replace('tag-', '', urldecode($original_context)); $t = new Tag(); $t->where('name', $tag)->get(); if ($t->exists()) { $next->where_related_tag('id', $t->id); $prev->where_related_tag('id', $t->id); $final['context']['type'] = 'tag'; $final['context']['title'] = $tag; $final['context']['slug'] = $tag; $t->model = 'tag_contents'; $t->slug = $t->name; $url = $t->url(); if ($url) { list($final['context']['__koken_url'], $final['context']['url']) = $url; } } } else { if (strpos($original_context, 'category-') === 0) { $category = str_replace('category-', '', $original_context); $cat = new Category(); $cat->where('slug', $category)->get(); if ($cat->exists()) { $next->where_related_category('id', $cat->id); $prev->where_related_category('id', $cat->id); $final['context']['type'] = 'category'; $final['context']['title'] = $cat->title; $final['context']['slug'] = $cat->slug; $cat->model = 'category_contents'; $url = $cat->url(); if ($url) { list($final['context']['__koken_url'], $final['context']['url']) = $url; } } } else { if ($original_context === 'favorites') { $url_data = $prev->get_data(); $urls = $prev->form_urls(); $next->where('favorite', 1); $prev->where('favorite', 1); $final['context']['type'] = 'favorite'; $final['context']['title'] = $url_data['favorite']['plural']; $final['context']['__koken_url'] = $urls['favorites']; if ($final['context']['__koken_url']) { $final['context']['url'] = $prev->get_base() . $final['context']['__koken_url'] . (defined('DRAFT_CONTEXT') && !is_numeric(DRAFT_CONTEXT) ? '&preview=' . DRAFT_CONTEXT : ''); } } else { if ($original_context === 'features') { $url_data = $prev->get_data(); $urls = $prev->form_urls(); $next->where('featured', 1); $prev->where('featured', 1); $final['context']['type'] = 'feature'; $final['context']['title'] = $url_data['feature']['plural']; $final['context']['__koken_url'] = isset($urls['features']) ? $urls['features'] : false; if ($final['context']['__koken_url']) { $final['context']['url'] = $prev->get_base() . $final['context']['__koken_url'] . (defined('DRAFT_CONTEXT') && !is_numeric(DRAFT_CONTEXT) ? '&preview=' . DRAFT_CONTEXT : ''); } } } } } if (!$this->auth) { $next->where('visibility', 0); $prev->where('visibility', 0); } $in_album = false; } $max = $next->get_clone()->count(); $min = $prev->get_clone()->count(); $final['context']['total'] = $max + $min + 1; $final['context']['position'] = $min + 1; $pre_limit = $next_limit = $options['neighbors']; if ($min < $pre_limit) { $next_limit += $pre_limit - $min; $pre_limit = $min; } if ($max < $next_limit) { $pre_limit = min($min, $pre_limit + ($next_limit - $max)); $next_limit = $max; } $final['context']['previous'] = array(); $final['context']['next'] = array(); if ($next_limit > 0) { if ($options['context_order'] !== 'manual') { $next->order_by($options['context_order'] . ' ' . $options['context_order_direction'] . ', id ' . $options['context_order_direction']); } $next->limit($next_limit)->get_iterated(); foreach ($next as $c) { $final['context']['next'][] = $c->to_array(array('auth' => $this->auth, 'in_album' => $in_album, 'context' => $original_context)); } } if ($pre_limit > 0) { if ($options['context_order'] !== 'manual') { $dir = strtolower($options['context_order_direction']) === 'desc' ? 'asc' : 'desc'; $prev->order_by($options['context_order'] . ' ' . $dir . ', id ' . $dir); } $prev->limit($pre_limit)->get_iterated(); foreach ($prev as $c) { $final['context']['previous'][] = $c->to_array(array('auth' => $this->auth, 'in_album' => $in_album, 'context' => $original_context)); } $final['context']['previous'] = array_reverse($final['context']['previous']); } } } else { $this->error('404', "Content with ID: {$id} not found."); return; } } else { if (isset($params['custom'])) { $final = $c->to_array_custom($params['custom']); } else { $c->where('deleted', 0); $params['auth'] = $this->auth; $final = $c->listing($params, $id); } } $this->set_response_data($final); }
/** * Modify charge (form) */ public function modify_check($id) { $charge = $this->dataExist($id); $validator = Validator::make(Input::all(), Charge::$rules); if (!$validator->fails()) { $date_explode = explode('/', Input::get('date_charge')); $date_payment_explode = explode('/', Input::get('date_payment')); $deadline_explode = explode('/', Input::get('deadline')); $charge->date_charge = $date_explode[2] . '-' . $date_explode[1] . '-' . $date_explode[0]; if (Input::get('date_payment')) { $charge->date_payment = $date_payment_explode[2] . '-' . $date_payment_explode[1] . '-' . $date_payment_explode[0]; } if (Input::get('deadline')) { $charge->deadline = $deadline_explode[2] . '-' . $deadline_explode[1] . '-' . $deadline_explode[0]; } if (Input::get('organisation_id')) { $charge->organisation_id = Input::get('organisation_id'); } if (Input::file('document')) { $document = time(true) . '.' . Input::file('document')->guessClientExtension(); if (Input::file('document')->move('uploads/charges', $document)) { if ($charge->document) { unlink(public_path() . '/uploads/charges/' . $charge->document); } $charge->document = $document; } } if ($charge->save()) { if (Input::get('tags')) { $tags = Input::get('tags'); $tags_keys = array(); foreach ($tags as $tag) { if (!array_key_exists($tag, $tags_keys)) { $checkTag = Tag::where('name', '=', $tag)->first(); if ($checkTag) { if (!ChargeTag::where('charge_id', '=', $charge->id)->where('tag_id', '=', $checkTag->id)->first()) { $chargeTag = new ChargeTag(); $chargeTag->charge_id = $charge->id; $chargeTag->tag_id = $checkTag->id; if ($chargeTag->save()) { $tags_keys[$tag] = $tag; } } else { $tags_keys[$tag] = $tag; } } else { if (trim($tag) != '') { $new_tag = new Tag(); $new_tag->name = $tag; if ($new_tag->save()) { $chargeTag = new ChargeTag(); $chargeTag->charge_id = $charge->id; $chargeTag->tag_id = $new_tag->id; if ($chargeTag->save()) { $tags_keys[$tag] = $tag; } } } } } } } foreach ($charge->items as $item) { ChargeItem::where('id', $item->id)->update(array('description' => Input::get('description.' . $item->id), 'amount' => Input::get('amount.' . $item->id), 'vat_types_id' => Input::get('vat_types_id.' . $item->id))); } if (Input::get('description.0')) { $item = new ChargeItem(); $item->insert(array('charge_id' => $id, 'description' => Input::get('description.0'), 'amount' => Input::get('amount.0'), 'vat_types_id' => Input::get('vat_types_id.0'))); } if (Input::get('payment_description.0')) { $date_payment_explode = explode('/', Input::get('payment_date.0')); $payment = new ChargePayment(); $payment->insert(array('charge_id' => $id, 'description' => Input::get('payment_description.0'), 'amount' => Input::get('payment_amount.0'), 'mode' => Input::get('payment_mode.0'), 'date_payment' => $date_payment_explode[2] . '-' . $date_payment_explode[1] . '-' . $date_payment_explode[0])); } return Redirect::route('charge_modify', $charge->id)->with('mSuccess', 'Cette charge a bien été modifiée'); } else { return Redirect::route('charge_modify', $charge->id)->with('mError', 'Impossible de modifier cette charge')->withInput(); } } else { return Redirect::route('charge_modify', $charge->id)->with('mError', 'Il y a des erreurs')->withErrors($validator->messages())->withInput(); } }
public static function findFromData($data) { return Tag::where('id', '=', $data)->orWhere('slug', '=', $data)->orWhere('name', '=', $data)->first(); }
/** * Private! Please do not call this function directly, let the Tag library use it. * Decrement count of tag by one. This function will create tag record if it does not exist. * * @param string $tagString */ public static function decrementCount($tagString, $tagSlug, $count) { if ($count <= 0) { return; } $tag = Tag::where('slug', '=', $tagSlug)->first(); if ($tag) { $tag->count = $tag->count - $count; if ($tag->count < 0) { $tag->count = 0; \Log::warning("The Tag count for `{$tag->name}` was a negative number. This probably means your data got corrupted. Please assess your code and report an issue if you find one."); } $tag->save(); } }