Inheritance: extends DataExtension
 function findListCount($options = array())
 {
     /*$cache = Cache::read('BlogCategoryList');
     		$cacheKey = 'BlogCategoryList-'.Configure::read('Config.language');
     		if(!empty($cache[$cacheKey])){
     			return $cache[$cacheKey];
     		}*/
     App::import('Lib', 'Blog.BlogConfig');
     $defOpt = BlogConfig::load('categoryList');
     $opt = Set::merge($defOpt, $options);
     $this->BlogCategory = ClassRegistry::init('Blog.BlogCategory');
     $this->BlogCategory->recursive = 1;
     $categoryList = array();
     if ($opt['allCategoriesLink']) {
         $chTotal = $this->BlogCategory->BlogPost->find('count');
         $categoryList[0] = array('id' => null, 'title' => __($opt['allCategoriesLink']['label'], true), 'count' => $chTotal);
     }
     $joinModel = $this->BlogCategory->BlogCategoriesBlogPost;
     $findOpt = array('fields' => array($this->BlogCategory->alias . '.id', $this->BlogCategory->alias . '.title', 'COUNT(' . $this->BlogCategory->BlogPost->alias . '.' . $this->BlogCategory->BlogPost->primaryKey . ') as `count`'), 'conditions' => array($this->BlogCategory->BlogPost->alias . '.active' => true), 'group' => array($this->BlogCategory->alias . '.' . $this->BlogCategory->primaryKey), 'joins' => array(array('alias' => $joinModel->alias, 'table' => $joinModel->table, 'type' => 'INNER', 'conditions' => array($joinModel->alias . '.blog_category_id = ' . $this->BlogCategory->alias . '.' . $this->BlogCategory->primaryKey)), array('alias' => $this->BlogCategory->BlogPost->alias, 'table' => $this->BlogCategory->BlogPost->table, 'type' => 'INNER', 'conditions' => array($joinModel->alias . '.blog_post_id = ' . $this->BlogCategory->BlogPost->alias . '.' . $this->BlogCategory->BlogPost->primaryKey))), 'recursive' => -1);
     $categories = $this->BlogCategory->find('all', $findOpt);
     if (!empty($categories)) {
         foreach ($categories as $k => $cat) {
             $cb = $cat[0]['count'];
             if ($cb > 0 || $opt['hideEmpty'] != true) {
                 $categoryList[$cat['BlogCategory']['id']] = array('id' => $cat['BlogCategory']['id'], 'title' => $cat['BlogCategory']['title'], 'count' => $cb);
             }
         }
     }
     //pr($categories);
     /*$cache[$cacheKey] = $categoryList;
     		Cache::write('BlogCategoryList', $cache);*/
     return $categoryList;
 }
	/**
	 * @Acl allow blog-admin
	*/
	public function configsave($enableComments, $enableCommentsFor,
	                           $moderationEmail, $moderationTime)
	{
		$config = BlogConfig::get();
		$config->enableComments = $enableComments;
		$config->enableCommentsFor = $enableCommentsFor;
		$config->moderationEmail = $moderationEmail;
		$config->moderationTime = $moderationTime;
		try
		{
			$config->save();
		
			$this->notice(t('Saved blog configuration'));
			$this->redirect('admin/blog/config');
		}
		catch (ValidationException $e)
		{
			$this->_adminTab = 'BlogConfigureAdminTab';
		
			$this->openForOptions = BlogConfig::openForOptions();
			$this->moderationTimeOptions = BlogConfig::moderationTimeOptions();
			$this->blogConfig = $config;
			$this->error('Blog configuration not saved');
			$this->render('admin/config');
		}
	}
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     BlogConfig::create(array('name' => 'title', 'value' => 'Jtauri blog'));
     BlogConfig::create(array('name' => 'user_posting_enabled', 'value' => 'true'));
     BlogConfig::create(array('name' => 'user_can_edit_posts', 'value' => 'true'));
     BlogConfig::create(array('name' => 'post_moderation', 'value' => 'true'));
     BlogConfig::create(array('name' => 'registration_enabled', 'value' => 'true'));
 }
Exemple #4
0
 function __construct($id = false, $table = NULL, $ds = NULL)
 {
     if (in_array('Search', App::objects('plugin'))) {
         $this->actsAs[] = 'Search.Searchable';
     }
     if (in_array('Comment', App::objects('plugin'))) {
         $this->actsAs[] = 'Comment.Commented';
     }
     App::import('Lib', 'Blog.BlogConfig');
     $this->multimedia['multimedia']['fields']['format'] = BlogConfig::load('cropFormats');
     parent::__construct($id, $table, $ds);
 }
Exemple #5
0
 function load($path = true)
 {
     $_this =& BlogConfig::getInstance();
     if (!$_this->loaded) {
         config('plugins/blog');
         $config = Configure::read('Blog');
         $config = Set::merge($_this->defaultConfig, $config);
         $config = $_this->_parseTrueToDefault($config);
         Configure::write('Blog', $config);
         $_this->loaded = true;
     }
     if (!empty($path)) {
         return Configure::read('Blog' . ($path !== true ? '.' . $path : ''));
     }
 }
 function beforeFilter()
 {
     parent::beforeFilter();
     $this->checked_blogger = false;
     if (!empty($this->user['User']['id'])) {
         $this->checked_blogger = $this->Acl->check(array('model' => 'User', 'foreign_key' => $this->user['User']['id']), 'blog_post');
     }
     $this->set('checked_blogger', $this->checked_blogger);
     $this->allow_blogger_edit = false;
     if (!empty($this->user['User']['id']) && BlogConfig::load('useBlogger')) {
         $this->allow_blogger_edit = $this->Acl->check(array('model' => 'User', 'foreign_key' => $this->user['User']['id']), 'blogger_edit');
     }
     //$this->allow_blogger_edit = true;
     $this->set('allow_blogger_edit', $this->allow_blogger_edit);
     if (!isset($this->params['admin']) || $this->params['admin'] == false) {
         //List of categories of blog
         $listCategories = $this->BlogFunctions->findListCount();
         $this->set(compact('listCategories'));
         //List of Archives
         $listArchives = $this->BlogFunctions->findArchivesCount(null, $this->lang);
         $this->set(compact('listArchives'));
     }
 }
 public function apply_edit_article_changes($id)
 {
     if (!Auth::check() || !Auth::user()->isAdmin() && !BlogConfig::getConfigValue('user_can_edit_posts')) {
         return Redirect::route('login');
     }
     $postInstance = Post::findOrFail($id);
     $postInstance->title = Input::get('title');
     $postInstance->body = Input::get('body');
     $validatorInstance = Validator::make(array('title' => Input::get('title'), 'body' => Input::get('body')), array('title' => 'required', 'body' => 'required'));
     if ($validatorInstance->passes()) {
         $postInstance->save();
         return Redirect::route('view_article', $id);
     } else {
         $data["message"] = "Please fill out every field correctly.";
         $data["id"] = $postInstance->id;
         return View::make('article_edit')->with('data', $data);
     }
 }
	/**
	 * @before get $year $month $day $id $language
	 * @Acl owns $:_blog
	*/
	public function edit($year, $month, $day, $id, $language = null)
	{
		$this->openFor = BlogConfig::openForOptions();
		$this->blog = $this->_blog;
		if ($this->_blog->commentsCloseDate === null)
		{
			$this->currentOpenFor = 0;
		}
		else
		{
			$this->currentOpenFor = (int)(($this->_blog->commentsCloseDate - $this->_blog->timePosted)/(60*60*24));
		}
		$this->render('edit');
	}