Exemple #1
0
 /**
  * Load forum settings
  * @access public
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $Config = ForumConfig::getInstance();
     $this->version = $Config->version;
     $this->settings = $Config->settings;
 }
 /**
  * Before filter.
  * 
  * @access public
  * @return void
  */
 public function beforeFilter()
 {
     parent::beforeFilter();
     $Config = ForumConfig::getInstance();
     // Load l10n/i18n support
     if (isset($this->Auth) && $this->Auth->user('locale')) {
         $locale = $this->Auth->user('locale');
     } else {
         $locale = isset($Config->settings['default_locale']) ? $Config->settings['default_locale'] : 'eng';
     }
     Configure::write('Config.language', $locale);
     setlocale(LC_ALL, $locale . 'UTF8', $locale . 'UTF-8', $locale, 'eng.UTF8', 'eng.UTF-8', 'eng', 'en_US');
     // Auth settings
     $referer = $this->referer();
     if (empty($referer) || $referer == '/forum/users/login' || $referer == '/admin/forum/users/login') {
         $referer = array('plugin' => 'forum', 'controller' => 'home', 'action' => 'index');
     }
     if (isset($this->Auth)) {
         $this->Auth->loginAction = array('plugin' => 'forum', 'controller' => 'users', 'action' => 'login', 'admin' => false);
         $this->Auth->loginRedirect = $referer;
         $this->Auth->logoutRedirect = $referer;
         $this->Auth->autoRedirect = false;
         $this->Auth->userModel = 'Forum.User';
         // AutoLogin settings
         $this->AutoLogin->settings = array('plugin' => 'forum', 'controller' => 'users', 'loginAction' => 'login', 'logoutAction' => 'logout');
     }
     $this->Cookie->key = Configure::read('Security.salt');
     // Apply censored words
     if (!empty($Config->settings['censored_words'])) {
         $censored = explode(',', str_replace(', ', ',', $Config->settings['censored_words']));
         $this->helpers['Forum.Decoda'] = array('censored' => $censored);
     }
     // Initialize
     $this->Toolbar->initForum();
 }
Exemple #3
0
 /**
  * After find
  * @access public
  * @param array $results
  * @param boolean $primary
  * @return array
  */
 public function afterFind($results, $primary = NULL)
 {
     if (!empty($results)) {
         $Config = ForumConfig::getInstance();
         $postsPerPage = $Config->settings['posts_per_page'];
         $autoLock = $Config->settings['days_till_autolock'];
         if ($primary === true) {
             foreach ($results as &$result) {
                 if (isset($result['Topic'])) {
                     // Get total pages
                     if (!empty($result['Topic']['post_count'])) {
                         $result['Topic']['page_count'] = $result['Topic']['post_count'] > $postsPerPage ? ceil($result['Topic']['post_count'] / $postsPerPage) : 1;
                     } else {
                         $result['Topic']['page_count'] = 1;
                     }
                     // Automatically lock threads
                     if (!empty($result['Topic']['forum_category_id'])) {
                         $forum = ClassRegistry::init('Forum.ForumCategory')->find('first', array('fields' => array('ForumCategory.settingAutoLock'), 'conditions' => array('ForumCategory.id' => $result['Topic']['forum_category_id']), 'contain' => false));
                         $lock = $forum['ForumCategory']['settingAutoLock'] == 1 ? 'yes' : 'no';
                     } else {
                         $lock = 'yes';
                     }
                     if (isset($result['LastPost']['created'])) {
                         $lastTime = $result['LastPost']['created'];
                     } else {
                         if (isset($result['Topic']['modified'])) {
                             $lastTime = $result['Topic']['modified'];
                         }
                     }
                     if (!empty($lastTime) && $lock == 'yes') {
                         if (strtotime($lastTime) < strtotime('-' . $autoLock . ' days')) {
                             $result['Topic']['status'] = 1;
                         }
                     }
                 }
             }
         } else {
             // Get total pages
             if (!empty($results['post_count'])) {
                 $results['page_count'] = $results['post_count'] > $postsPerPage ? ceil($results['post_count'] / $postsPerPage) : 1;
             } else {
                 $results['page_count'] = 1;
             }
         }
     }
     return $results;
 }
Exemple #4
0
 /**
  * Extra validation checking
  * @access public
  * @return boolean
  */
 public function beforeValidate()
 {
     $action = isset($this->action) ? $this->action : null;
     if ($action == 'login') {
         unset($this->validate['username']['isUnique']);
     } else {
         if ($action == 'signup') {
             $this->validate['security'] = array('equalTo' => array('rule' => array('equalTo', ForumConfig::getInstance()->settings['security_answer']), 'message' => 'Your security answer is incorrect, please try again!'), 'notEmpty' => array('rule' => 'notEmpty', 'message' => 'The security answer is required to proceed'), 'required' => true);
         }
     }
     return true;
 }
	/**
	 * Initialize.
	 *
	 * @access public
	 * @param obj $Controller
	 * @param array $settings 
	 * @return void
	 */  
	public function initialize(&$Controller, $settings = array()) {
		$this->Controller = $Controller;
		$this->settings = ForumConfig::getInstance()->settings;
		$this->columnMap = ForumConfig::getInstance()->columnMap;
	}