Пример #1
0
	/**
	 * Grab the current object instance.
	 * 
	 * @access public
	 * @return object
	 * @static
	 */
	public static function getInstance() {
		if (empty(self::$__instance)) {
			self::$__instance = new ForumConfig();
		}
		
		return self::$__instance;
	}
Пример #2
0
 /**
  * Load forum settings
  * @access public
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $Config = ForumConfig::getInstance();
     $this->version = $Config->version;
     $this->settings = $Config->settings;
 }
Пример #3
0
 /**
  * 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();
 }
 private function save()
 {
     $this->config->set_forum_name($this->form->get_value('forum_name'));
     $this->config->set_number_topics_per_page($this->form->get_value('number_topics_per_page'));
     $this->config->set_number_messages_per_page($this->form->get_value('number_messages_per_page'));
     $this->config->set_read_messages_storage_duration($this->form->get_value('read_messages_storage_duration'));
     $this->config->set_max_topic_number_in_favorite($this->form->get_value('max_topic_number_in_favorite'));
     if ($this->form->get_value('edit_mark_enabled')) {
         $this->config->enable_edit_mark();
     } else {
         $this->config->disable_edit_mark();
     }
     if ($this->form->get_value('multiple_posts_allowed')) {
         $this->config->allow_multiple_posts();
     } else {
         $this->config->forbid_multiple_posts();
     }
     if ($this->form->get_value('connexion_form_displayed')) {
         $this->config->display_connexion_form();
     } else {
         $this->config->hide_connexion_form();
     }
     if ($this->form->get_value('left_column_disabled')) {
         $this->config->disable_left_column();
     } else {
         $this->config->enable_left_column();
     }
     if ($this->form->get_value('right_column_disabled')) {
         $this->config->disable_right_column();
     } else {
         $this->config->enable_right_column();
     }
     if ($this->form->get_value('message_before_topic_title_displayed')) {
         $this->config->display_message_before_topic_title();
         $this->config->set_message_before_topic_title($this->form->get_value('message_before_topic_title'));
         $this->config->set_message_when_topic_is_unsolved($this->form->get_value('message_when_topic_is_unsolved'));
         $this->config->set_message_when_topic_is_solved($this->form->get_value('message_when_topic_is_solved'));
         if ($this->form->get_value('message_before_topic_title_icon_displayed')) {
             $this->config->display_message_before_topic_title_icon();
         } else {
             $this->config->hide_message_before_topic_title_icon();
         }
     } else {
         $this->config->hide_message_before_topic_title();
     }
     $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array());
     ForumConfig::save();
     ForumService::get_categories_manager()->regenerate_cache();
 }
 protected function build_new_config()
 {
     $config = $this->get_old_config();
     $forum_config = ForumConfig::load();
     $forum_config->set_forum_name($config['forum_name']);
     $forum_config->set_number_topics_per_page($config['pagination_topic']);
     $forum_config->set_number_messages_per_page($config['pagination_msg']);
     $forum_config->set_read_messages_storage_duration($config['view_time']);
     $forum_config->set_max_topic_number_in_favorite($config['topic_track']);
     if (!empty($config['topic_track'])) {
         $forum_config->enable_edit_mark();
     } else {
         $forum_config->disable_edit_mark();
     }
     if (!empty($config['no_left_column'])) {
         $forum_config->enable_left_column();
     } else {
         $forum_config->disable_left_column();
     }
     if (!empty($config['no_right_column'])) {
         $forum_config->enable_right_column();
     } else {
         $forum_config->disable_right_column();
     }
     if (!empty($config['activ_display_msg'])) {
         $forum_config->display_message_before_topic_title();
     } else {
         $forum_config->hide_message_before_topic_title();
     }
     $forum_config->set_message_before_topic_title($config['display_msg']);
     $forum_config->set_message_when_topic_is_unsolved($config['explain_display_msg']);
     $forum_config->set_message_when_topic_is_solved($config['explain_display_msg_bis']);
     if (!empty($config['icon_activ_display_msg'])) {
         $forum_config->display_message_before_topic_title_icon();
     } else {
         $forum_config->hide_message_before_topic_title_icon();
     }
     if (!empty($config['display_connexion'])) {
         $forum_config->display_connexion_form();
     } else {
         $forum_config->hide_connexion_form();
     }
     $forum_config->set_authorizations($this->build_authorizations(unserialize($config['auth'])));
     ForumConfig::save();
     return true;
 }
    public function get_feed_data_struct($idcat = 0, $name = '')
    {
        $config = ForumConfig::load();
        $category = ForumService::get_categories_manager()->get_categories_cache()->get_category($idcat);
        $data = new FeedData();
        $data->set_title(LangLoader::get_message('xml_forum_desc', 'common', 'forum'));
        $data->set_date(new Date());
        $data->set_link(DispatchManager::get_url('/syndication', '/rss/forum/' . $idcat . '/'));
        $data->set_host(HOST);
        $data->set_desc(LangLoader::get_message('xml_forum_desc', 'common', 'forum'));
        $data->set_lang(LangLoader::get_message('xml_lang', 'main'));
        $data->set_auth_bit(Category::READ_AUTHORIZATIONS);
        $categories = ForumService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
        $ids_categories = array_keys($categories);
        $results = PersistenceContext::get_querier()->select('SELECT t.id, t.idcat, t.title, t.last_timestamp, t.last_msg_id, t.display_msg, t.nbr_msg AS t_nbr_msg, msg.id mid, msg.contents
			FROM ' . PREFIX . 'forum_topics t
			LEFT JOIN ' . PREFIX . 'forum_msg msg ON msg.id = t.last_msg_id
			WHERE t.idcat IN :ids_categories
			ORDER BY t.last_timestamp DESC LIMIT :limit OFFSET 0', array('ids_categories' => $ids_categories, 'limit' => 2 * $config->get_number_messages_per_page()));
        foreach ($results as $row) {
            $item = new FeedItem();
            //Link
            $last_page = ceil($row['t_nbr_msg'] / $config->get_number_messages_per_page());
            $last_page_rewrite = $last_page > 1 ? '-' . $last_page : '';
            $last_page = $last_page > 1 ? 'pt=' . $last_page . '&' : '';
            $link = new Url('/forum/topic' . url('.php?' . $last_page . 'id=' . $row['id'], '-' . $row['id'] . $last_page_rewrite . '+' . Url::encode_rewrite($row['title']) . '.php') . '#m' . $row['last_msg_id']);
            $item->set_title(($config->is_message_before_topic_title_displayed() && !empty($row['display_msg']) ? TextHelper::html_entity_decode($config->get_message_before_topic_title(), ENT_NOQUOTES) . ' ' : '') . stripslashes($row['title']));
            $item->set_link($link);
            $item->set_guid($link);
            $item->set_desc(FormatingHelper::second_parse($row['contents']));
            $item->set_date(new Date($row['last_timestamp'], Timezone::SERVER_TIMEZONE));
            $item->set_auth(ForumService::get_categories_manager()->get_heritated_authorizations($row['idcat'], Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
            $data->add_item($item);
        }
        $results->dispose();
        return $data;
    }
Пример #7
0
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 ###################################################*/
if (defined('PHPBOOST') !== true) {
    exit;
}
load_module_lang('forum');
//Chargement de la langue du module.
$config = ForumConfig::load();
require_once PATH_TO_ROOT . '/forum/forum_defines.php';
//Supprime les menus suivant configuration du site.
$columns_disabled = ThemesManager::get_theme(AppContext::get_current_user()->get_theme())->get_columns_disabled();
if ($config->is_left_column_disabled()) {
    $columns_disabled->set_disable_left_columns(true);
}
if ($config->is_right_column_disabled()) {
    $columns_disabled->set_disable_right_columns(true);
}
//Fonction du forum.
require_once PATH_TO_ROOT . '/forum/forum_functions.php';
 public function get_root_category()
 {
     $root = new ForumCategory();
     $root->set_authorizations(ForumConfig::load()->get_authorizations());
     return $root;
 }
 private function get_authorizations($bit)
 {
     return AppContext::get_current_user()->check_auth(ForumConfig::load()->get_authorizations(), $bit);
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
0
 function Track_topic($idtopic, $tracking_type = 0)
 {
     $config = ForumConfig::load();
     list($mail, $pm, $track) = array(0, 0, 0);
     if ($tracking_type == 0) {
         //Suivi par email.
         $track = '1';
     } elseif ($tracking_type == 1) {
         //Suivi par email.
         $mail = '1';
     } elseif ($tracking_type == 2) {
         //Suivi par email.
         $pm = '1';
     }
     $exist = PersistenceContext::get_querier()->count(PREFIX . 'forum_track', 'WHERE user_id = :user_id AND idtopic = :idtopic', array('user_id' => AppContext::get_current_user()->get_id(), 'idtopic' => $idtopic));
     if ($exist == 0) {
         PersistenceContext::get_querier()->insert(PREFIX . "forum_track", array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id(), 'track' => $track, 'pm' => $pm, 'mail' => $mail));
     } elseif ($tracking_type == 0) {
         PersistenceContext::get_querier()->update(PREFIX . "forum_track", array('track' => 1), 'WHERE idtopic = :idtopic AND user_id = :user_id', array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id()));
     } elseif ($tracking_type == 1) {
         PersistenceContext::get_querier()->update(PREFIX . "forum_track", array('mail' => 1), 'WHERE idtopic = :idtopic AND user_id = :user_id', array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id()));
     } elseif ($tracking_type == 2) {
         PersistenceContext::get_querier()->update(PREFIX . "forum_track", array('pm' => 1), 'WHERE idtopic = :idtopic AND user_id = :user_id', array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id()));
     }
     //Limite de sujets suivis?
     if (!ForumAuthorizationsService::check_authorizations()->unlimited_topics_tracking()) {
         //Récupère l'id du topic le plus vieux autorisé par la limite de sujet suivis.
         $tracked_topics_number = PersistenceContext::get_querier()->select_single_row_query("SELECT COUNT(*) as number\n\t\t\tFROM " . PREFIX . "forum_track\n\t\t\tWHERE user_id = :user_id\n\t\t\tORDER BY id DESC\n\t\t\tLIMIT " . $config->get_max_topic_number_in_favorite(), array('user_id' => AppContext::get_current_user()->get_id()));
         //Suppression des sujets suivis dépassant le nbr maximum autorisé.
         PersistenceContext::get_querier()->delete(PREFIX . 'forum_track', 'WHERE user_id=:id  AND id < :number', array('id' => AppContext::get_current_user()->get_id(), 'number' => $tracked_topics_number['number']));
     }
 }
Пример #13
0
	/**
	 * 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;
	}
 /**
  * {@inheritDoc}
  */
 public function on_changeday(Date $yesterday, Date $today)
 {
     //Suppression des marqueurs de vue du forum trop anciens.
     PersistenceContext::get_querier()->delete(PREFIX . 'forum_view', 'WHERE timestamp < :limit', array('limit' => time() - ForumConfig::load()->get_read_messages_storage_duration() * 3600 * 24));
 }
	/**
	 * Check if the plugin was installed.
	 * 
	 * @access private
	 * @return void
	 */
	private function __checkInstallation() {
		// Check the installation status
		if (ForumConfig::isInstalled()) {
			$this->redirect(array('action' => 'index', 'controller' => 'home', 'plugin' => 'forum'));
		}

		// If progress hasn't begun, redirect
		if ($this->action != 'check_database') {
			if (!$this->Session->check('Install')) {
				$this->redirect(array('action' => 'index'));
			}
		} else {
			if (!$this->Session->check('Install')) {
				$this->Session->write('Install', array());
			}
		}

		// Auto load DB
		if ($this->Session->check('Install.database')) {
			$this->DB =& ConnectionManager::getDataSource($this->Session->read('Install.database'));
		}
	}
Пример #16
0
function mark_topic_as_read($idtopic, $last_msg_id, $last_timestamp)
{
    //Calcul du temps de péremption, ou de dernière vue des messages par à rapport à la configuration.
    $last_view_forum = AppContext::get_session()->get_cached_data('last_view_forum', 0);
    $max_time = time() - ForumConfig::load()->get_read_messages_storage_duration() * 3600 * 24;
    $max_time_msg = $last_view_forum > $max_time ? $last_view_forum : $max_time;
    if (AppContext::get_current_user()->get_id() !== -1 && $last_timestamp >= $max_time_msg) {
        $check_view_id = 0;
        try {
            $check_view_id = PersistenceContext::get_querier()->get_column_value(PREFIX . "forum_view", 'last_view_id', 'WHERE user_id = :user_id AND idtopic = :idtopic', array('user_id' => AppContext::get_current_user()->get_id(), 'idtopic' => $idtopic));
        } catch (RowNotFoundException $e) {
        }
        if (!empty($check_view_id) && $check_view_id != $last_msg_id) {
            PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "forum_topics SET nbr_views = nbr_views + 1 WHERE id = '" . $idtopic . "'");
            PersistenceContext::get_querier()->update(PREFIX . "forum_view", array('last_view_id' => $last_msg_id, 'timestamp' => time()), 'WHERE idtopic = :idtopic AND user_id = :user_id', array('idtopic' => $idtopic, 'user_id' => AppContext::get_current_user()->get_id()));
        } elseif (empty($check_view_id)) {
            PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "forum_topics SET nbr_views = nbr_views + 1 WHERE id = '" . $idtopic . "'");
            PersistenceContext::get_querier()->insert(PREFIX . "forum_view", array('idtopic' => $idtopic, 'last_view_id' => $last_msg_id, 'user_id' => AppContext::get_current_user()->get_id(), 'timestamp' => time()));
        } else {
            PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "forum_topics SET nbr_views = nbr_views + 1 WHERE id = '" . $idtopic . "'");
        }
    } else {
        PersistenceContext::get_querier()->inject("UPDATE " . PREFIX . "forum_topics SET nbr_views = nbr_views + 1 WHERE id = '" . $idtopic . "'");
    }
}