public function manage_topic($id = false) { $topic_info = ''; $topic = new \CODOF\Forum\Topic($this->db); if ($id) { $tid = (int) $id; $qry = 'SELECT t.topic_id,t.title, t.cat_id, t.uid,t.topic_status, c.cat_name, p.imessage ' . 'FROM ' . PREFIX . 'codo_topics AS t ' . 'INNER JOIN ' . PREFIX . 'codo_categories AS c ON c.cat_id=t.cat_id ' . 'INNER JOIN ' . PREFIX . 'codo_posts AS p ON p.topic_id=t.topic_id ' . 'WHERE t.topic_id=' . $tid; $res = $this->db->query($qry); $topic_info = $res->fetch(); //i have come to edit the topic $tuid = $topic_info['uid']; $cid = $topic_info['cat_id']; $has_permission = $topic->canViewTopic($tuid, $cid, $tid) && $topic->canEditTopic($tuid, $cid, $tid); } else { $topic_info = array("title" => "", "imessage" => "", "topic_status" => 0, "cat_id" => 0, "topic_id" => 0); //i have come to create a new topic $has_permission = $topic->canCreateTopicInAtleastOne(); } if ($has_permission) { $tags = ''; if ($id) { $_tags = $topic->getTags($id); if ($_tags) { $tags = implode(",", $_tags); } \CODOF\Store::set('sub_title', _t('Edit topic ') . $topic_info['title']); } else { \CODOF\Store::set('sub_title', _t('Create topic')); } $this->smarty->assign('tags', $tags); $cat = new \CODOF\Forum\Category($this->db); $cats = $cat->generate_tree($cat->getCategoriesWhereUserCanCreateTopic()); $this->smarty->assign('cats', $cats); $this->assign_editor_vars(); $this->smarty->assign('topic', $topic_info); $this->smarty->assign('sticky_checked', \CODOF\Forum\Forum::isSticky($topic_info['topic_status'])); $this->smarty->assign('frontpage_checked', $topic_info['topic_status'] == \CODOF\Forum\Forum::STICKY); $user = \CODOF\User\User::get(); $this->smarty->assign('can_make_sticky', $user->can('make sticky')); $this->smarty->assign('can_add_tags', $user->can('add tags')); $this->css_files = array('new_topic', 'editor', 'jquery.textcomplete'); $arr = array(array(DATA_PATH . "assets/js/bootstrap-tagsinput.min.js", array('type' => 'defer'))); $this->js_files = array_merge($arr, $cat->get_js_editor_files()); $this->view = 'forum/new_topic'; } else { if (!\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { header('Location: ' . \CODOF\User\User::getProfileUrl()); } else { \CODOF\Store::set('sub_title', _t('Access denied')); $this->view = 'access_denied'; } } }
public static function load($tpl, $css_files = array(), $js_files = array()) { \CODOF\Util::inc_global_views(); //This sets all variables which will be used by the theme require CURR_THEME_PATH . 'theme.php'; $page = array(); \CODOF\Hook::call('before_site_head'); \CODOF\Hook::call('tpl_before_' . str_replace("/", "_", $tpl)); $asset = new \CODOF\Asset\Stream(); $page["head"]["css"] = $asset->dumpCSS(); //\CODOF\Theme\Js::sort_js(); $page["head"]["js"] = $asset->dumpJS('head'); $page["body"]["js"] = $asset->dumpJS('body'); $page["defer"] = json_encode($asset->deferred()); //after all modification its time for smarty to display the mod data $smarty = Single::get_instance(); $site_title = \CODOF\Util::get_opt('site_title'); $sub_title = \CODOF\Store::get('sub_title'); $smarty->assign('site_title', $site_title); $smarty->assign('sub_title', $sub_title); $smarty->assign('home_title', \CODOF\Store::get('home_title', _t('All topics'))); $smarty->assign('site_url', \CODOF\Util::get_opt('site_url')); $smarty->assign('logged_in', \CODOF\User\CurrentUser\CurrentUser::loggedIn()); $smarty->assign('login_url', \CODOF\User\User::getLoginUrl()); $smarty->assign('logout_url', \CODOF\User\User::getLogoutUrl()); $smarty->assign('register_url', \CODOF\User\User::getRegisterUrl()); $smarty->assign('profile_url', \CODOF\User\User::getProfileUrl()); $smarty->assign('page', $page); $smarty->assign('CSRF_token', \CODOF\Access\CSRF::get_token()); $smarty->assign('php_time_now', time()); $category = new \CODOF\Forum\Category(); $canCreateTopicInAtleastOneCategory = $category->canCreateTopicInAtleastOne(); $smarty->assign('canCreateTopicInAtleastOneCategory', $canCreateTopicInAtleastOneCategory); $page = \CODOF\Store::get('rel:canonical_page', isset($_GET['u']) ? $_GET['u'] : ''); $smarty->assign('canonical', rtrim(RURI, '/') . strip_tags($page)); if (\CODOF\Store::has('rel:prev')) { $smarty->assign('rel_prev', \CODOF\Store::get('rel:prev')); } if (\CODOF\Store::has('rel:next')) { $smarty->assign('rel_next', \CODOF\Store::get('rel:next')); } if (\CODOF\Store::has('meta:robots')) { $smarty->assign('meta_robots', \CODOF\Store::get('meta:robots')); } $og = array("type" => \CODOF\Store::get('og:type', 'website'), "title" => \CODOF\Store::get('og:title', $sub_title . ' | ' . $site_title)); if (\CODOF\Store::has('og:url')) { $og['url'] = \CODOF\Store::get('og:url'); } if (\CODOF\Store::has('og:desc')) { $og['desc'] = \CODOF\Store::get('og:desc'); } else { $og['desc'] = \CODOF\Util::get_opt('site_description'); } if (\CODOF\Store::has('og:image')) { $og['image'] = \CODOF\Store::get('og:image'); } $smarty->assign('og', $og); if (\CODOF\Store::has('article:published')) { $smarty->assign('article_published', \CODOF\Store::get('article:published')); } if (\CODOF\Store::has('article:modified')) { $smarty->assign('article_modified', \CODOF\Store::get('article:modified')); } $I = \CODOF\User\User::get(); //current user details $smarty->assign('I', $I); $smarty->assign('can_moderate_posts', $I->can('moderate posts')); if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $notifier = new \CODOF\Forum\Notification\Notifier(); $smarty->assign('unread_notifications', $notifier->getNoOfUnread()); } $html = $smarty->fetch("{$tpl}.tpl"); require_once SYSPATH . 'Ext/simplehtmldom/simple_html_dom.php'; $dom = new \simple_html_dom(); $dom->load($html, true, false); //let plugins modify html \CODOF\Hook::call('tpl_after_' . str_replace("/", "_", $tpl), $dom); \CODOF\Hook::call('after_site_head', $dom); echo $dom->save(); }
public function register($do) { if (isset($_SESSION[UID . 'USER']['id'])) { header('Location: ' . \CODOF\User\User::getProfileUrl()); exit; } $this->view = 'user/register'; $set_fields = array('username', 'password', 'mail'); $req_fields = array('username', 'password', 'mail'); $this->js_files = array(array(DATA_PATH . 'assets/js/user/register.js', array('type' => 'defer'))); if (\CODOF\Util::is_set($_REQUEST, $set_fields) && !\CODOF\Util::is_empty($_REQUEST, $req_fields) && $do) { $register = new \CODOF\User\Register($this->db); $register->username = str_replace('"', '"', $_REQUEST['username']); $register->name = null; //$_REQUEST['name']; $register->password = $_REQUEST["password"]; $register->mail = $_REQUEST['mail']; $register->rid = ROLE_UNVERIFIED; $errors = $register->get_errors(); if (empty($errors)) { $errors = $register->register_user(); $register->login(); header('Location: ' . \CODOF\User\User::getProfileUrl()); exit; } $this->smarty->assign('errors', $errors); } else { $register = new \stdClass(); $register->username = null; $register->name = null; //$_REQUEST['name']; $register->password = null; $register->mail = null; } if (\CODOF\Util::get_opt('captcha') == "enabled") { $publickey = \CODOF\Util::get_opt('captcha_public_key'); // you got this from the signup page $this->smarty->assign('recaptcha', '<div class="g-recaptcha col-md-6" data-sitekey="' . $publickey . '"></div>'); $this->js_files[] = array('https://www.google.com/recaptcha/api.js', array('type' => 'remote')); } $this->smarty->assign('min_pass_len', \CODOF\Util::get_opt('register_pass_min')); $this->smarty->assign('min_username_len', \CODOF\Util::get_opt('register_username_min')); $this->smarty->assign('register', $register); \CODOF\Store::set('sub_title', 'Register'); }