public function add_core_hooks() { \CODOF\Hook::add('on_cron_notify', array(new \CODOF\Forum\Notification\Notifier(), 'dequeueNotify')); \CODOF\Hook::add('on_cron_daily_digest', array(new \CODOF\Forum\Notification\Digest\Digest(), 'sendDailyDigest')); \CODOF\Hook::add('on_cron_weekly_digest', array(new \CODOF\Forum\Notification\Digest\Digest(), 'sendWeeklyDigest')); \CODOF\Hook::add('on_cron_mail_notify_send', array(new \CODOF\Forum\Notification\MailQueue(), 'dequeue')); }
public function register_user() { $username = $this->username; $name = $this->name == null ? $this->username : $this->name; $password = $this->password; $mail = $this->mail; $errors = array(); $hasher = new \CODOF\Pass(8, false); $hash = $hasher->HashPassword($password); if (strlen($hash) >= 20) { $fields = array("username" => $username, "name" => $name, "pass" => $hash, "mail" => $mail, "created" => time(), "last_access" => time(), "user_status" => $this->user_status, "avatar" => $this->avatar, "no_posts" => $this->no_posts, "oauth_id" => $this->oauth_id); $qry = 'INSERT INTO codo_users (username, name, pass, mail, created, last_access, user_status, avatar, no_posts, oauth_id) ' . 'VALUES(:username, :name, :pass, :mail, :created, :last_access, :user_status, :avatar, :no_posts, :oauth_id)'; $obj = $this->db->prepare($qry); if (!$obj->execute($fields)) { \CODOF\Log::error("Could not register user! \nError:\n " . print_r($obj->errorInfo(), true) . " \nData:\n" . print_r($fields, true)); $errors[] = "Could not register user"; } else { $this->userid = $this->db->lastInsertId('id'); \DB::table(PREFIX . 'codo_user_roles')->insert(array('uid' => $this->userid, 'rid' => $this->rid, 'is_primary' => 1)); if ($this->user_status == 0) { $this->add_signup_attempt($fields); $this->send_mail($fields, $errors); } //TODO: CurrentUser -> store user //dont know the security implications when $fields is passed with hook \CODOF\Hook::call('on_user_registered'); } } return $errors; }
public function get_edit_view($passed_id, $uid) { $view = 'access_denied'; if ($passed_id && isset($_SESSION[UID . 'USER']['id'])) { if ($passed_id == $_SESSION[UID . 'USER']['id'] && \CODOF\Access\Access::hasPermission('edit my profile') || \CODOF\Access\Access::hasPermission('edit all profiles')) { $view = 'user/profile/edit'; \CODOF\Hook::call('before_profile_edit_load', array($uid)); } } return $view; }
public function getCategoriesWhereUserCanCreateTopic() { $user = \CODOF\User\User::get(); $rids = implode(",", $user->rids); $qry = 'SELECT cat_id, cat_pid, cat_name, cat_alias, no_topics, cat_img' . ' FROM ' . PREFIX . 'codo_categories' . ' INNER JOIN ' . PREFIX . 'codo_permissions ON cid=cat_id ' . ' WHERE permission=\'create new topic\'' . ' AND granted=1 ' . ' AND rid IN (' . $rids . ')' . ' ORDER BY cat_order'; $ans = $this->db->query($qry); if ($ans) { $cats = $ans->fetchAll(\PDO::FETCH_CLASS); } $cats = \CODOF\Hook::call('on_get_categories_for_create_topic', $cats); return $cats; }
//IoC::setIoCContainer($container); //$container->loadServiceProvider(); if (!$installed) { $r_path = str_replace("index.php", "", $path); header('Location: ' . $r_path . 'install'); } \Constants::post_config($CONF); //contains routing system require ABSPATH . 'sys/Ext/limonade/limonade.php'; require ABSPATH . 'sys/vendor/autoload.php'; $capsule = new Capsule(); $config = get_codo_db_conf(); $capsule->addConnection($config); $capsule->setAsGlobal(); $capsule->bootEloquent(); // $x = $container->make('db')->query('SELECT * FROM codo_config')->fetchAll(); Hook::call('after_config_loaded'); Util::start_session(); //$u = \User::get(); //var_dump($u->id); //exit('hello'); //loads translation system require DATA_PATH . 'locale/lang.php'; require SYSPATH . 'globals/global.php'; //initiate all plugins //Now the plugins can work on the data available $plg = new \CODOF\Plugin(); $plg->init(); } else { die('codo forums not installed!'); }
public function create() { //hacking attempt if ($_POST['end_of_line'] != "") { exit; } if (isset($_POST['title']) && isset($_POST['cat']) && isset($_POST['imesg']) && isset($_POST['omesg'])) { $catid = (int) $_POST['cat']; $category = new \CODOF\Forum\Category($this->db); if (!$category->exists($catid) || !$category->canCreateTopicIn($catid)) { exit(_t("No such category exists!")); } $post = new \CODOF\Forum\Post($this->db); $topic = new \CODOF\Forum\Topic($this->db); $notifier = new \CODOF\Forum\Notification\Notifier(); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $title = \CODOF\Format::title($_POST['title']); $filter = new \CODOF\SpamFilter(); $needsModeration = false; $sticky = $_POST['sticky'] === "true" ? 'yes' : 'no'; $frontpage = $_POST['frontpage'] === "true" ? 'yes' : 'no'; if ($filter->isSpam($_POST['imesg'])) { $needsModeration = true; } $user = \CODOF\User\User::get(); if ($sticky == 'yes' && $user->can('make sticky')) { if ($frontpage == 'yes') { $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::STICKY); } else { $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::STICKY_ONLY_CATEGORY); } } else { $tid = $topic->ins_topic($catid, $title, $needsModeration, \CODOF\Forum\Forum::APPROVED); } $pid = $post->ins_post($catid, $tid, $_POST['imesg'], $_POST['omesg']); $topic->link_topic_post($pid, $tid); //get any @mentions from the topic post $mentions = $subscriber->getMentions($_POST['imesg']); //get userids from mentions that actually exists in the database $ids = $subscriber->getIdsThatExisits($mentions); //subscribe self to topic as a Subscriber::NOTIFIED $subscriber->toTopic($catid, $tid, \CODOF\Forum\Notification\Subscriber::$NOTIFIED); //if post was inserted successfully if ($pid) { $topicData = array("label" => 'New topic', "cid" => $catid, "tid" => $tid, "tuid" => $user->id, "pid" => $pid, "mentions" => $ids, "message" => \CODOF\Util::start_cut(\CODOF\Format::imessage($_POST['imesg']), 120), "notification" => "%actor% created <b>%title%</b>", "bindings" => array("title" => \CODOF\Util::start_cut($title, 100))); $notifier->queueNotify('new_topic', $topicData); //$notifier->dequeueNotify(); \CODOF\Hook::call('after_topic_insert', $topicData); } //insert tags if any present in the topic if (isset($_POST['tags']) && $user->can('add tags')) { //the method does the filtering $topic->insertTags($tid, $_POST['tags']); } echo json_encode(array('tid' => $tid)); } }
/** * Inserts a new post in codo_posts * * @param type $catid * @param type $tid * @param type $imesg * @param type $omesg */ public function ins_post($catid, $tid, $imesg, $omesg, $needsModeration = false) { \CODOF\Hook::call('before_post_insert'); $time = time(); $uid = $_SESSION[UID . 'USER']['id']; $post_status = Topic::APPROVED; if ($needsModeration) { $post_status = Topic::MODERATION_BY_FILTER; } //$message = \CODOF\Filter::msg_safe($mesg); //$mesg = nl2br($message); $qry = 'INSERT INTO codo_posts (topic_id,cat_id,uid,imessage,omessage,post_created,post_status) ' . 'VALUES(:tid, :cid, :uid, :imesg, :omesg, :post_created,:post_status)'; $stmt = $this->db->prepare($qry); $params = array(":tid" => $tid, ":cid" => $catid, ":uid" => $uid, ":imesg" => \CODOF\Format::imessage($imesg), ":omesg" => \CODOF\Format::omessage($omesg), ":post_created" => $time, ":post_status" => $post_status); $this->success = $stmt->execute($params); $pid = $this->db->lastInsertId(); if ($this->success && !$needsModeration) { $this->incPostCount($catid, $tid, $uid); \CODOF\Hook::call('after_post_insert', $pid); return $pid; } return false; }
public function mail($mail) { $errors = array(); if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) { $errors[] = _t("email address not formatted correctly"); } if (\CODOF\User\User::mailExists($mail)) { $errors[] = _t("email address is already registered"); } $this->errors = array_merge($errors, $this->errors); if (empty($errors)) { \CODOF\Hook::call('on_mail_ok'); return TRUE; //passed } \CODOF\Hook::call('on_mail_fail'); return FALSE; //Fail }
/** * Dequeues notification queue and enqueues email queue * Table codo_notify * type id data is_read * new_reply 1 {tid: 4, pid: 5} 0 --> depends on subscription * new_topic 2 {tid: 4} 1 --> depends on subscription * new_badge 2 {bid: 3} 0 --> system notification * vote_up 2 {pid: 5} 1 --> depend on user settings * new_like 1 {pid: 7} 1 --> depend on user settings * mention 4 {pid: 3} 0 --> depends on subscription */ public function dequeueNotify() { $qry = 'SELECT q.id,q.type,q.nid,t.data FROM ' . PREFIX . 'codo_notify_queue AS q' . ' INNER JOIN codo_notify_text AS t ON q.nid=t.id'; $res = $this->db->query($qry); if (!$res) { return false; } $maxID = 0; $queue = $res->fetchAll(); $subscriber = new Subscriber(); $user = \CODOF\User\User::get(); $frequency = $user->prefers('notification_frequency'); foreach ($queue as $queuedNotification) { $maxID = max($queuedNotification['id'], $maxID); $type = $queuedNotification['type']; $nid = $queuedNotification['nid']; $data = json_decode($queuedNotification['data']); $mentions = $data->mentions; $cid = $data->cid; $tid = $data->tid; $pid = $data->pid; if (!empty($mentions)) { $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $mentions); $notMuted = array_diff($mentions, $mutedIds); $this->notify($notMuted, 'mention', $nid); } $offset = 0; //get all types of subscribers of this category/topic while ($subscribers = $subscriber->of($type, $cid, $tid, $offset)) { //we do not need anyone subscribed to this topic since it //is a new topic and so the creator will be the first subscriber //segregate subscribers into different groups based on type $idTypes = $subscriber->groupBySubscriptionType($subscribers); //add notifications for FOLLOWING & NOTIFIED that a new topic is created $this->notify(array_merge($idTypes['FOLLOWING'], $idTypes['NOTIFIED']), $type, $nid); $offset += Subscriber::$maxRows; } //if ($frequency == 'immediate') { //queue all emails which will be sent in different cron run \CODOF\Hook::call('after_notify_insert', array("cid" => $cid, "tid" => $tid, "pid" => $pid, "type" => $type)); //} } //delete old queued notifications $qry = 'DELETE FROM ' . PREFIX . 'codo_notify_queue WHERE id <= ' . $maxID; $this->db->query($qry); }
public function topic($tid, $page) { $topic = new \CODOF\Forum\Topic($this->db); $post = new \CODOF\Forum\Post($this->db); $topic_info = $topic->get_topic_info($tid); if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MERGED_REDIRECT_ONLY) { $tid = $topic_info['redirect_to']; $topic_info = $topic->get_topic_info($tid); } if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MODERATION_BY_FILTER) { $topic_is_spam = true; } else { $topic_is_spam = false; } $this->smarty->assign('topic_is_spam', $topic_is_spam); $user = \CODOF\User\User::get(); if ($topic_is_spam) { if (!($user->can('moderate topics') || $user->id == $topic_info['uid'])) { $this->view = 'access_denied'; return false; } } if (!$topic->canViewTopic($topic_info['uid'], $topic_info['cat_id'], $topic_info['topic_id'])) { //\CODOF\Hook::call('page not found', array('type' => 'topic', 'id' => $tid)); \CODOF\Store::set('sub_title', _t('Access denied')); $this->view = 'access_denied'; return; } $tracker = new \CODOF\Forum\Tracker($this->db); $tracker->mark_topic_as_read($topic_info['cat_id'], $tid); if (!$topic_info) { $this->view = 'not_found'; } else { $posts_per_page = \CODOF\Util::get_opt("num_posts_per_topic"); if (strpos($page, "post-") !== FALSE) { $pid = (int) str_replace("post-", "", $page); $prev_posts = $post->get_num_prev_posts($tid, $pid); $from = floor($prev_posts / $posts_per_page); } else { $from = (int) $page - 1; } $topic_info['no_replies'] = $topic_info['no_posts'] - 1; $name = \CODOF\Filter::URL_safe($topic_info['title']); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $this->smarty->assign('no_followers', $subscriber->followersOfTopic($topic_info['topic_id'])); if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $this->smarty->assign('my_subscription_type', $subscriber->levelForTopic($topic_info['topic_id'])); } $this->smarty->assign('tags', $topic->getTags($topic_info['topic_id'])); $api = new Ajax\forum\topic(); $posts_data = $api->get_posts($tid, $from, $topic_info); $num_pages = $posts_data['num_pages']; $posts = $posts_data['posts']; $posts_tpl = \CODOF\HB\Render::tpl('forum/topic', $posts_data); $this->smarty->assign('posts', $posts_tpl); $this->smarty->assign('topic_info', $topic_info); $this->smarty->assign('title', htmlentities($topic_info['title'], ENT_QUOTES, "UTF-8")); $search_data = array(); if (isset($_GET['str'])) { $search_data = array('str' => strip_tags($_GET['str'])); } $this->smarty->assign('search_data', json_encode($search_data)); $url = 'topic/' . $topic_info['topic_id'] . '/' . $name . '/'; $this->smarty->assign('pagination', $post->paginate($num_pages, $from + 1, $url, false, $search_data)); if (ceil(($topic_info['no_posts'] + 1) / $posts_per_page) > $num_pages) { //next reply will go to next page $this->smarty->assign('new_page', 'yes'); } else { $this->smarty->assign('new_page', 'nope'); } $cat = new \CODOF\Forum\Category($this->db); $cats = $cat->get_categories(); $cid = $topic_info['cat_id']; $parents = $cat->find_parents($cats, $cid); array_push($parents, array("name" => $topic_info['cat_name'], "alias" => $topic_info['cat_alias'])); $this->smarty->assign('can_search', $user->can('use search')); $this->smarty->assign('parents', $parents); $this->smarty->assign('num_pages', $num_pages); $this->smarty->assign('curr_page', $from + 1); //starts from 1 $this->smarty->assign('url', RURI . $url); $this->assign_editor_vars(); $tuid = $topic_info['uid']; $this->assign_admin_vars($tuid); $this->css_files = array('topic', 'editor', 'jquery.textcomplete'); $arr = array(array('topic/topic.js', array('type' => 'defer')), array('modal.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer'))); $this->js_files = array_merge($arr, $post->get_js_editor_files()); \CODOF\Hook::call('on_topic_view', array($topic_info)); $this->view = 'forum/topic'; \CODOF\Store::set('sub_title', $topic_info['title']); \CODOF\Store::set('og:type', 'article'); \CODOF\Store::set('og:title', $topic_info['title']); \CODOF\Store::set('og:url', RURI . $url); $mesg = $posts[0]['imessage']; \CODOF\Store::set('og:desc', strlen($mesg) > 200 ? substr($mesg, 0, 197) . "..." : $mesg); if ($from > 0) { //previous page exists \CODOF\Store::set('rel:prev', RURI . $url . $from); } $curr_page = $from + 1; if ($curr_page < $num_pages) { //next page exists \CODOF\Store::set('rel:next', RURI . $url . ($curr_page + 1)); } \CODOF\Store::set('article:published', date('c', $topic_info['topic_created'])); if ($topic_info['topic_updated'] > 0) { \CODOF\Store::set('article:modified', date('c', $topic_info['topic_updated'])); } } }
if ($type == 'new_topic') { $subject = \CODOF\Util::get_opt('topic_notify_subject'); $message = \CODOF\Util::get_opt('topic_notify_message'); } else { $subject = \CODOF\Util::get_opt('post_notify_subject'); $message = \CODOF\Util::get_opt('post_notify_message'); } $mail = new \CODOF\Forum\Notification\Mail(); $me = CODOF\User\User::get(); $mails = array(); $offset = 0; while ($data = $this->getData($cid, $tid, $pid, $offset)) { foreach ($data as $info) { //do not send email to the user making the post if ($me->id == $info['id'] || $info['mail'] == null) { continue; } $user = array("id" => $me->id, "username" => $me->username); $post = array("omessage" => $info['omessage'], "imessage" => $info['imessage'], "url" => \CODOF\Forum\Forum::getPostURL($tid, $info['title'], $pid), "id" => $info['id'], "username" => $info['username'], "title" => $info['title'], "category" => $info['cat_name']); $mail->user = $user; $mail->post = $post; $mails[] = array("to_address" => $info['mail'], "mail_subject" => html_entity_decode($mail->replace_tokens($subject), ENT_NOQUOTES, "UTF-8"), "body" => html_entity_decode($mail->replace_tokens($message), ENT_QUOTES, "UTF-8")); } \DB::table(PREFIX . 'codo_mail_queue')->insert($mails); $offset += 400; } } } $pn = new Notify(); \CODOF\Hook::add('after_notify_insert', array($pn, 'queue_mails'));
/** * This function is called on every page load by the user . * * It checks for any cron that is scheduled to run * * @return boolean */ public function run($cron = null) { $crons = $this->acquire_lock($cron); if (!$crons) { $this->cleanUp(); //could not acquire lock because another cron is already running //or the cron last completed is not older than cron_interval return false; } //script must continue even if user aborts @ignore_user_abort(true); //parallel crons may cause write conflicts if (!$this->serial) { //write and end session session_write_close(); } //amount of time for which cron is allowed to run set_time_limit($this->time_limit); ob_start(); $this->add_core_hooks(); foreach ($crons as $cron) { if ($cron['cron_name'] == 'core') { //run all core jobs of cron $this->run_jobs(); } //there is no guarantee that user defined plugins wont produce //errors . try { \CODOF\Hook::call('on_cron_' . $cron['cron_name']); } catch (Exception $ex) { } } $this->log = ob_get_clean(); //cron jobs done, set status as not running $this->release_lock(); //below hook should not be used to run cron jobs \CODOF\Hook::call('after_cron_run'); if ($this->log != '') { \CODOF\Log::info('Cron:' . $this->log); } return true; }
public function profile($id, $action) { $this->view = 'user/profile/view'; \CODOF\Store::set('meta:robots', 'noindex, follow'); if ($id == null) { $id = 0; } if ($action == null) { $action = 'view'; } $profile = new \CODOF\User\Profile(); $uid = $profile->get_uid($id); $currUser = \CODOF\User\User::get(); if (!$currUser->can('view user profiles') && $uid != $currUser->id) { //if current user cannot view user profiles and if he is trying //to view a profile that is not his, we need to deny him permission $action = 'deny'; } $user = \CODOF\User\User::getByIdOrUsername($uid, $uid); if ($user) { $user->avatar = $user->getAvatar(); //pass user object to template $this->smarty->assign('user', $user); $this->smarty->assign('rname', \CODOF\User\User::getRoleName($user->rid)); \CODOF\Store::set('sub_title', $user->username); $can_edit = $this->can_edit_profile($uid); if ($action == 'edit' && $can_edit) { $this->view = 'user/profile/edit'; $this->css_files = array('profile_edit'); $this->js_files = array(array(DATA_PATH . 'assets/js/user/profile/edit.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer'))); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $categories = $subscriber->getCategorySubscriptions($uid); $topics = $subscriber->getTopicSubscriptions($uid); $this->smarty->assign('categories', $categories); $this->smarty->assign('topics', $topics); $this->smarty->assign('signature_char_lim', \CODOF\Util::get_opt('signature_char_lim')); } else { if ($action == 'view') { $this->view = 'user/profile/view'; if ($uid != $currUser->id) { $user->incProfileViews(); } $this->smarty->assign('user_not_confirmed', $uid == $currUser->id && !$user->isConfirmed()); $reg_req_admin = \CODOF\Util::get_opt('reg_req_admin') == 'yes'; $this->smarty->assign('user_not_approved', $uid == $currUser->id && (int) $user->rid == ROLE_UNVERIFIED && $reg_req_admin); $this->smarty->assign('can_edit', $can_edit); $this->css_files = array('profile_view'); $this->js_files = array(array(DATA_PATH . 'assets/js/user/profile/view.js', array('type' => 'defer'))); \CODOF\Hook::call('before_profile_view', $user); } else { $this->view = 'access_denied'; } } } else { $this->view = 'not_found'; } }
public static function do_upload($image, $path) { self::$error = true; if (!self::valid($image)) { return 'File is not valid'; } if (!self::not_empty($image)) { return 'File is empty'; } if (!self::size($image, (int) \CODOF\Util::get_opt('forum_attachments_size'))) { return 'File size too large'; } $types = explode(",", \CODOF\Util::get_opt('forum_attachments_exts')); if (self::$supportBmp) { //add support for bmp array_merge($types, 'bmp'); } else { $types = array_diff($types, array('bmp')); } if (!self::type($image, $types)) { return 'File extension type not supported'; } self::$error = false; \CODOF\Hook::call('on_file_upload', array($image, $path)); $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION)); return self::save($image, uniqid() . "." . $ext, DATA_PATH . $path, 0777); }
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(); }
} echo ' <script> var codopm={}; codopm.path="' . codopm::$path . '"; codopm.req_path="' . codopm::$req_path . '"; codopm.from="' . $user->id . '"; codopm.xhash="' . codopm::$xhash . '"; codopm.profile_id="' . codopm::$profile_id . '"; codopm.profile_name="' . codopm::$profile_name . '"; </script>'; require "start.php"; } } $user = $adapter->get_user(); if ($myadapter == 'Codoforum') { \CODOF\Hook::add('before_profile_view', function ($user) { codopm::$profile_id = $user->id; codopm::$profile_name = $user->username; codopm::$profile_path = RURI . 'user/profile'; }); \CODOF\Hook::add('block_profile_view_tabs_after', 'codopm_load'); \CODOF\Hook::add('tpl_before_user_profile_view', 'codopm_add_assets'); require 'server/codopm.php'; } else { codopm::$profile_id = $user->id; codopm::$profile_path = ''; codopm::$profile_name = ''; codopm_load(); codopm_add_assets(); }
/** * Logs the user out by resetting the SESSION */ public function logout() { \CODOF\Hook::call('on_user_logout'); unset($_SESSION[UID . 'USER']); session_regenerate_id(true); self::$has_user = false; \CODOF\Cookie::Delete('codo_remember'); }
}); //-------------PAGES-------------------------- dispatch_get('/page/:id/:url', function ($id, $url) { $pid = (int) $id; $user = \CODOF\User\User::get(); $qry = 'SELECT title, content FROM ' . PREFIX . 'codo_pages p ' . ' LEFT JOIN ' . PREFIX . 'codo_page_roles r ON r.pid=p.id ' . ' WHERE (r.rid IS NULL OR (r.rid IS NOT NULL AND r.rid IN (' . implode($user->rids) . ')))' . ' AND p.id=' . $pid; $res = \DB::getPDO()->query($qry); $row = $res->fetch(); if ($row) { $title = $row['title']; $content = $row['content']; $smarty = CODOF\Smarty\Single::get_instance(); $smarty->assign('contents', $content); \CODOF\Store::set('sub_title', $title); \CODOF\Smarty\Layout::load('page'); \CODOF\Hook::call('on_page_load', array($id)); } else { $page = \DB::table(PREFIX . 'codo_pages')->where('id', $id)->first(); if ($page == null) { \CODOF\Smarty\Layout::not_found(); } else { \CODOF\Smarty\Layout::access_denied(); } } }); //-------------USER------------------------------------------------------------- dispatch_get('/user/logout', function () { $user = new \Controller\user(); $user->logout(); CODOF\Smarty\Layout::load($user->view, $user->css_files, $user->js_files); });