public function setTagsAndSave($item,$tags) { $last = NULL; if($del_tags = $item->fetch('BlogTag')) { foreach($del_tags as $del_tag) { $last = $del_tag->fetchSingle('TagDescribesEntry'); $last->deleteLater(); } } if($last) $last->purge(); //ADD TAGS FOR THE ITEM $tag_array = explode(',',$tags); $trimmed = array(); $item = $item->restrict(); $item->read(); foreach($tag_array as $tmp) $trimmed[] = trim($tmp); $tag_array = $trimmed; $tag = new BlogTag(); $tag->clauseSafe('tag_name',$tag_array,Clause::IN); $flipped = array_flip($tag_array); if($existing_tags = $tag->fetch()) { foreach($existing_tags as $existing) { unset($flipped[$existing->toString()]); $item->add($existing); } } $tags = array_flip($flipped); $new_tag = NULL; if(count($tags)) { foreach($tags as $tag_name) { $new_tag = new BlogTag(); $new_tag->set('tag_name',$tag_name); $item->add($new_tag); } } $item->save(); }
public function run() { $this->command->info('Deleting existing BlogTag table...'); DB::table('blogtags')->truncate(); $count = 5; $faker = Faker\Factory::create('fr_FR'); for ($i = 0; $i < $count; $i++) { $name = $faker->word; BlogTag::create(array('name' => ucwords($name), 'slug' => Str::slug($name))); } $this->command->info('Blog Tags inserted successfully!'); }
/** * {@inheritdoc} */ public function up() { //Migrate comma separated tags into BlogTag objects. foreach ($this->TagNames() as $tag) { $existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID)); if ($existingTag->count()) { //if tag already exists we will simply add it to this post. $tagObject = $existingTag->First(); } else { //if the tag is now we create it and add it to this post. $tagObject = new BlogTag(); $tagObject->Title = $tag; $tagObject->BlogID = $this->ParentID; $tagObject->write(); } if ($tagObject) { $this->Tags()->add($tagObject); } } //Store if the original entity was published or not (draft) $published = $this->IsPublished(); // If a user has subclassed BlogEntry, it should not be turned into a BlogPost. if ($this->ClassName === 'BlogEntry') { $this->ClassName = 'BlogPost'; $this->RecordClassName = 'BlogPost'; } //Migrate these key data attributes $this->PublishDate = $this->Date; $this->AuthorNames = $this->Author; $this->InheritSideBar = true; //Write and additionally publish the item if it was published before. $this->write(); if ($published) { $this->publish('Stage', 'Live'); $message = "PUBLISHED: "; } else { $message = "DRAFT: "; } return $message . $this->Title; }
public function getFeaturedBlogPost() { $category = $this->getCategory(); $tag = $this->getTag(); $archive = $this->getArchive(); if ($category) { $category = BlogCategory::get()->filter("URLSegment", $category)->first(); return $category->BlogPosts()->filter("FeaturedPost", true)->first(); } if ($tag) { $tag = BlogTag::get()->filter("URLSegment", $tag)->first(); return $tag->BlogPosts()->filter("FeaturedPost", true)->first(); } if ($archive) { return $this->owner->getArchivedBlogPosts($archive["Year"], $archive["Month"], $archive["Day"])->filter("FeaturedPost", true)->first(); } return BlogPost::get()->filter("FeaturedPost", true)->first(); }
/** * {@inheritdoc} */ public function getCMSFields() { Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); $self =& $this; $this->beforeUpdateCMSFields(function ($fields) use($self) { $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); /** * @var FieldList $fields */ $fields->insertAfter($uploadField, 'Content'); $summary = HtmlEditorField::create('Summary', false); $summary->setRows(5); $summary->setDescription(_t('BlogPost.SUMMARY_DESCRIPTION', 'If no summary is specified the first 30 words will be used.')); $summaryHolder = ToggleCompositeField::create('CustomSummary', _t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'), array($summary)); $summaryHolder->setHeadingLevel(4); $summaryHolder->addExtraClass('custom-summary'); $fields->insertAfter($summaryHolder, 'FeaturedImage'); $fields->push(HiddenField::create('MenuTitle')); $urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment->setURLPrefix($self->Parent()->RelativeLink()); $fields->removeFieldsFromTab('Root.Main', array('MenuTitle', 'URLSegment')); $authorField = ListboxField::create('Authors', _t('BlogPost.Authors', 'Authors'), $self->getCandidateAuthors()->map()->toArray())->setMultiple(true); $authorNames = TextField::create('AuthorNames', _t('BlogPost.AdditionalCredits', 'Additional Credits'), null, 1024)->setDescription(_t('BlogPost.AdditionalCredits_Description', 'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.')); if (!$self->canEditAuthors()) { $authorField = $authorField->performDisabledTransformation(); $authorNames = $authorNames->performDisabledTransformation(); } $publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date')); $publishDate->getDateField()->setConfig('showcalendar', true); if (!$self->PublishDate) { $publishDate->setDescription(_t('BlogPost.PublishDate_Description', 'Will be set to "now" if published without a value.')); } // Get categories and tags $parent = $self->Parent(); $categories = $parent instanceof Blog ? $parent->Categories() : BlogCategory::get(); $tags = $parent instanceof Blog ? $parent->Tags() : BlogTag::get(); $options = BlogAdminSidebar::create($publishDate, $urlSegment, TagField::create('Categories', _t('BlogPost.Categories', 'Categories'), $categories, $self->Categories())->setCanCreate($self->canCreateCategories())->setShouldLazyLoad(true), TagField::create('Tags', _t('BlogPost.Tags', 'Tags'), $tags, $self->Tags())->setCanCreate($self->canCreateTags())->setShouldLazyLoad(true), $authorField, $authorNames)->setTitle('Post Options'); $options->setName('blog-admin-sidebar'); $fields->insertBefore($options, 'Root'); }); $fields = parent::getCMSFields(); $fields->fieldByName('Root')->setTemplate('TabSet_holder'); return $fields; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // Get the page data if (is_null($post = BlogPost::find($id))) { // Redirect to BlogPost management page return Redirect::route('blog.admin')->with('error', Lang::get('modules/blog/messages.error.not_found')); } if (!empty($post->image)) { unlink($this->destinationPath . $post->image); } $post->tags()->detach(); foreach (BlogTag::all() as $tag) { if (!$tag->posts->count()) { $tag->delete(); } } // Was the page created? if ($post->delete()) { // Redirect to the BlogPost management page return Redirect::route('blog.admin')->with('success', Lang::get('modules/blog/messages.success.delete')); } // Redirect to the BlogPost management page return Redirect::route('blog.admin')->with('error', Lang::get('modules/blog/messages.error.delete')); }
public static function addTags($id_lang = null, $id_post, $tag_list, $separator = ',') { if ($id_lang == null) { $id_lang = (int) Context::getContext()->language->id; } if (!Validate::isUnsignedId($id_lang)) { return false; } if (!is_array($tag_list)) { $tag_list = array_filter(array_unique(array_map('trim', preg_split('#\\' . $separator . '#', $tag_list, null, PREG_SPLIT_NO_EMPTY)))); } $list = array(); if (is_array($tag_list)) { foreach ($tag_list as $tag) { $id_tag = BlogTag::TagExists($tag, (int) $id_lang); if (!$id_tag) { $tag_obj = new BlogTag(null, $tag, (int) $id_lang); if (!Validate::isLoadedObject($tag_obj)) { $tag_obj->name = $tag; $tag_obj->id_lang = (int) $id_lang; $tag_obj->add(); } if (!in_array($tag_obj->id, $list)) { $list[] = $tag_obj->id; } } else { if (!in_array($id_tag, $list)) { $list[] = $id_tag; } } } } $data = ''; foreach ($list as $tag) { $data .= '(' . (int) $tag . ',' . (int) $id_post . '),'; } $data = rtrim($data, ','); return Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'smart_blog_post_tag` (`id_tag`, `id_post`) VALUES ' . $data); }
public function getTag() { if ($this->row['Tag'] == 0) { return null; } else { return BlogTag::ROW($this->row['Tag']); } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param BlogTag $value A BlogTag object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(BlogTag $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Declares an association between this object and a BlogTag object. * * @param BlogTag $v * @return BlogTagArticle The current object (for fluent API support) * @throws PropelException */ public function setBlogTag(BlogTag $v = null) { if ($v === null) { $this->setTagId(NULL); } else { $this->setTagId($v->getId()); } $this->aBlogTag = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the BlogTag object, it will not be re-added. if ($v !== null) { $v->addBlogTagArticle($this); } return $this; }
|-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ // Blog Route::get('/', array('as' => 'home', 'uses' => 'HomeController@getIndex')); Route::group(array('prefix' => 'blog'), function () { Route::get('admin', array('as' => 'blog.admin', 'uses' => 'BlogController@admin')); Route::get('{id}/delete', array('as' => 'blog.delete', 'uses' => 'BlogController@destroy')); Route::get('{id}/publish/{state}', array('as' => 'blog.publish', 'uses' => 'BlogController@publish')); Route::get('tag/{slug}', array('as' => 'blog.postsByTag', 'uses' => 'BlogController@getPostsByTag')); Route::get('cats.json', function () { return BlogTag::all()->lists('name'); }); }); Route::resource('blog', 'BlogController'); // Portfolio Route::group(array('prefix' => 'portfolio'), function () { Route::get('admin', array('as' => 'portfolio.admin', 'uses' => 'PortfolioController@admin')); Route::get('{id}/delete', array('as' => 'portfolio.delete', 'uses' => 'PortfolioController@destroy')); Route::get('{id}/publish/{state}', array('as' => 'portfolio.publish', 'uses' => 'PortfolioController@publish')); Route::get('cats.json', function () { return PortfolioTag::all()->lists('name'); }); }); Route::resource('portfolio', 'PortfolioController'); // Contact Route::get('contact', array('as' => 'contact', 'uses' => 'ContactController@getIndex'));
/** * @return \yii\db\ActiveQuery */ public function getBlogTag() { return $this->hasOne(BlogTag::className(), ['tag_id' => 'id']); }