function codo_cat_build_structure($cat, $new_topics)
{
    $DURI = DURI;
    $CAT_IMGS = CAT_ICON_IMGS;
    $no_topics_title = _t('No. of topics');
    $new_no = '';
    if (isset($new_topics[$cat->cat_id])) {
        $new_no = '<a title="' . _t('new topics') . '"><span class="codo_new_topics_count">' . $new_topics[$cat->cat_id] . '</span></a>';
    }
    if ($cat->granted) {
        $no_topics = \CODOF\Util::abbrev_no($cat->no_topics, 2);
    } else {
        $no_topics = '-';
    }
    $url = RURI . 'category/' . $cat->cat_alias;
    echo <<<EOD
    <div class="row">
    <div class="codo_category_img col-md-2 col-xs-2">
        <img draggable="false" src="{$DURI}{$CAT_IMGS}{$cat->cat_img}" />
    </div>
   <div class="codo_categories_category col-md-10 col-xs-10">
        <a href="{$url}"><div class="codo_category_title">{$cat->cat_name}</div></a>
        <span data-toggle="tooltip" data-placement="bottom" title="{$no_topics_title}" class="codo_category_num_topics codo_bs_tooltip">{$no_topics}</span>            
        {$new_no}    
   </div>
    </div>  
EOD;
    static $num_topics = 0;
    $num_topics++;
}
 public function queue_mails($args)
 {
     $cid = (int) $args['cid'];
     $tid = (int) $args['tid'];
     $pid = (int) $args['pid'];
     $type = $args['type'];
     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;
     }
 }
 public function get_topics($catid, $page)
 {
     $topic = new \CODOF\Forum\Topic($this->db);
     $topics = array();
     $cid = (int) $catid;
     $num_pages = 'not_passed';
     if (isset($_GET['get_page_count']) && $_GET['get_page_count'] == 'yes') {
         $num_pages = 'calc_count';
     }
     $new_topics = array();
     $new_replies = array();
     if (isset($_GET['str']) && $_GET['str'] != "") {
         $user = \CODOF\User\User::get();
         if (!$user->can('use search')) {
             exit('permission denied');
         }
         $search = new \CODOF\Search\Search();
         $search->str = $_GET['str'];
         $search->num_results = \CODOF\Util::get_opt("num_posts_cat_topics");
         $search->from = ($page - 1) * $search->num_results;
         if ($num_pages == 'calc_count') {
             $search->count_rows = true;
         }
         $cats = (int) $_GET['catid'];
         $search->cats = $cats;
         $search->match_titles = $_GET['match_titles'];
         $search->order = $_GET['order'];
         $search->sort = $_GET['sort'];
         $search->time_within = $_GET['search_within'];
         $res = $search->search();
         if ($num_pages == 'calc_count') {
             $num_pages = $search->get_total_count();
         }
         $_topics = $topic->gen_topic_arr_all_topics($res, $search);
         $tids = array();
         foreach ($topics as $_topic) {
             $tids[] = $_topic['topic_id'];
         }
         //var_dump($topics);
     } else {
         //$num_pages = $topic->get_num_pages(
         //        $topic->get_num_topics($cid), \CODOF\Util::get_opt("num_posts_cat_topics")
         //);
         $num_pages = 'not_passed';
         $topics = $topic->get_topics($cid, $page);
         $tids = array();
         foreach ($topics as $_topic) {
             $tids[] = $_topic['topic_id'];
         }
         if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
             $tracker = new \CODOF\Forum\Tracker($this->db);
             $topic->new_topic_ids = $tracker->get_new_topic_ids($cid, $tids);
             $topic->new_replies = $tracker->get_new_reply_counts($tids);
         }
         $topic->tags = $topic->getAllTags($tids);
         $_topics = $topic->gen_topic_arr($topics, $cid);
     }
     return array("topics" => $_topics, "new_topics" => $topic->new_topic_ids, "page_no" => $page, "num_pages" => $num_pages);
 }
function smarty_function_get_no_children($params)
{
    $cnt = \CODOF\Util::count_children($params['cat']);
    if ($cnt > 0) {
        return "<span>{$cnt}</span> " . _t("sub-category", "sub-categories", $cnt);
    }
    return false;
}
 static function ftp_step()
 {
     echo "hey";
     $result = upgrader::get_all_files();
     require "ftpabstract.php";
     $mstring = "cache/" . time() . ".php";
     file_put_contents(ABSPATH . $mstring, "adi");
     chmod(ABSPATH . $mstring, 0777);
     $ftp = new ftp();
     $ftp->Verbose = TRUE;
     $ftp->LocalEcho = TRUE;
     if (!$ftp->SetServer($_REQUEST['fserver'])) {
         $ftp->quit();
         die("Setting server failed :(\n<br>");
     }
     if (!$ftp->connect()) {
         die("Cannot connect: Refresh and try again\n<br>");
     }
     if (!$ftp->login($_REQUEST['fusername'], $_REQUEST['fpassword'])) {
         $ftp->quit();
         die("Login failed: Refresh and try again\n<br>");
     }
     require 'path.php';
     $finder = new finder();
     $finder->mstring = $mstring;
     $finder->connect($ftp);
     $res = $finder->searcher();
     $dirs = $result['dirs'];
     $phpfiles = $result['phpfiles'];
     $only_files = $result['only_files'];
     $everything = $phpfiles;
     //$result["everything"];
     //  file_put_contents("out.txt", print_r($everything, true));
     $xdirs = \CODOF\Util::get_777s();
     @$ftp->chmod($res, 0777);
     foreach ($everything as $thing) {
         @$ftp->chmod($res . $thing, 0777);
         // echo $res.$thing."<br>";
     }
     upgrader::chmod_array($ftp, $everything, $res, 0777);
     upgrader::direct_upgrade();
     $result = upgrader::get_all_files();
     //get all files after unpacking
     $dirs = $result['dirs'];
     $phpfiles = $result['phpfiles'];
     $only_files = $result['only_files'];
     $everything = $phpfiles;
     //$result["everything"];
     upgrader::chmod_array($ftp, $phpfiles, $res, 0644);
     //PHP FILES
     upgrader::chmod_array($ftp, $dirs, $res, 0755);
     //ALL DIRS
     upgrader::chmod_array($ftp, $xdirs, $res, 0777);
     //CACHE & SITE DIRS
 }
 private function format($topics)
 {
     $_topics = array();
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("cat_alias" => $topic['cat_alias'], "cat_img" => $topic['cat_img'], "id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe($topic['title']), "title" => \CODOF\Util::mid_cut($topic['title'], 200), "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_uid" => $topic['last_post_uid'], "last_post_name" => $topic['last_post_name'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['last_post_time'] != $topic['topic_created'] ? $topic['last_post_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         $_topics[$i]["status"] = $topic['topic_status'];
         $_topics[$i]["what"] = 'is_topic';
         $i++;
     }
     return $_topics;
 }
 private function gen_posts_arr($posts)
 {
     $_posts = array();
     $i = 0;
     $topics_set = array();
     foreach ($posts as $post) {
         if (isset($topics_set[$post['topic_id']])) {
             $_posts[$topics_set[$post['topic_id']]]['contents'][] = array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']));
             //$topics_set[$post['topic_id']]++;
             continue;
         }
         $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "no_replies" => \CODOF\Util::abbrev_no($post['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($post['no_views'], 1), "topic_created" => \CODOF\Time::get_pretty_time($post['topic_created']), "cat_alias" => $post['cat_alias'], "cat_img" => $post['cat_img'], "contents" => array(array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']))), "topic_id" => $post['topic_id'], "safe_title" => \CODOF\Filter::URL_safe($post['title']), "title" => html_entity_decode(\CODOF\Util::mid_cut($post['title'], 200), ENT_NOQUOTES, "UTF-8"));
         $topics_set[$post['topic_id']] = $i;
         $i++;
     }
     return $_posts;
 }
Example #8
0
 public function req_pass()
 {
     $errors = array();
     $token = uniqid() . '&' . (time() + 3600);
     $mail = new \CODOF\Forum\Notification\Mail();
     //update the user's password with the generated password
     $user = \CODOF\User\User::getByMailOrUsername($_GET['ident'], $_GET['ident']);
     $gen = false;
     if (!$user) {
         $errors[] = _t("User does not exist with the given username/mail");
     } else {
         $old_token = $user->token;
         if ($old_token != null) {
             $parts = explode("&", $old_token);
             $expiry = (int) $parts[1];
             if ($expiry > time()) {
                 $gen = true;
             }
         } else {
             $gen = true;
         }
     }
     if (empty($errors) && $gen) {
         \DB::table(PREFIX . 'codo_users')->where('id', $user->id)->update(array('token' => $token));
         $body = \CODOF\Util::get_opt('password_reset_message');
         $sub = \CODOF\Util::get_opt('password_reset_subject');
         $mail->user = array("token" => $token, "link" => RURI . 'user/reset');
         $message = $mail->replace_tokens($body);
         $subject = $mail->replace_tokens($sub);
         $mail->to = $user->mail;
         $mail->subject = $subject;
         $mail->message = $message;
         $mail->send_mail();
         if (!$mail->sent) {
             $errors[] = $mail->error;
         }
     }
     $resp = array("status" => "success", "msg" => _t("E-mail sent successfully"));
     if (!empty($errors)) {
         $resp = array("status" => "fail", "msg" => $errors);
     }
     echo json_encode($resp);
 }
Example #9
0
 /**
  * Constraints defined for username
  * @param type $username
  */
 public function username($username)
 {
     $username_len = strlen($username);
     $min_username_len = \CODOF\Util::get_opt('register_username_min');
     $errors = array();
     if ($username_len < $min_username_len) {
         $errors[] = _t("username cannot be less than {$min_username_len} characters!");
     }
     if (preg_match('/^[A-Za-z0-9_-]+$/', $username) === 0) {
         $errors[] = _t("username can have only letters digits and underscores");
     }
     if (\CODOF\User\User::usernameExists($username)) {
         $errors[] = _t("user already exists");
     }
     $this->errors = array_merge($errors, $this->errors);
     if (empty($errors)) {
         \CODOF\Hook::call('on_username_ok');
         return TRUE;
         //passed
     }
     \CODOF\Hook::call('on_username_fail');
     return FALSE;
     //Fail
 }
 /**
  * 
  * Get different possible errors before registering an user
  * @return Array errors
  */
 public function get_errors()
 {
     $constraints = new \CODOF\Constraints\User();
     $constraints->username($this->username);
     $constraints->password($this->password);
     $constraints->mail($this->mail);
     $errors = $constraints->get_errors();
     if (\CODOF\Util::get_opt('captcha') == "enabled") {
         require_once ABSPATH . 'sys/Ext/recaptcha/recaptchalib.php';
         $privatekey = \CODOF\Util::get_opt("captcha_private_key");
         // your secret key
         $secret = $privatekey;
         // empty response
         $response = null;
         // check secret key
         $reCaptcha = new \ReCaptcha($secret);
         if ($_POST["g-recaptcha-response"]) {
             $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
         }
         if (!($response != null && $response->success)) {
             $errors[] = _t("capcha entered was wrong");
         }
     }
     return $errors;
 }
Example #11
0
 public function edit()
 {
     //hacking attempt
     if ($_POST['end_of_line'] != "") {
         exit;
     }
     $tid = (int) $_POST['tid'];
     $topic = new \CODOF\Forum\Topic($this->db);
     $topic_info = $topic->get_topic_info($tid);
     //i have come to edit the topic
     $tuid = $topic_info['uid'];
     $cid = $topic_info['cat_id'];
     $topic_status = (int) $topic_info['topic_status'];
     $req_cid = (int) $_POST['cat'];
     $topicNeedsToBeMoved = $cid != $req_cid;
     $has_permission = $topic->canViewTopic($tuid, $cid, $tid) && $topic->canEditTopic($tuid, $cid, $tid);
     $user = \CODOF\User\User::get();
     if ($topicNeedsToBeMoved) {
         $has_permission = $has_permission && $user->can('move topics', $req_cid);
     }
     if ($has_permission) {
         if (isset($_POST['title']) && isset($_POST['cat']) && isset($_POST['imesg']) && isset($_POST['omesg'])) {
             if ($topicNeedsToBeMoved) {
                 \DB::table(PREFIX . 'codo_notify_subscribers')->where('tid', '=', $tid)->update(array('cid' => $req_cid));
                 //above also checks whether category exists
                 \DB::table(PREFIX . 'codo_categories')->where('cat_id', $cid)->update(array('no_topics' => \DB::raw('no_topics-1'), 'no_posts' => \DB::raw('no_posts-' . $topic_info['no_posts'])));
                 \DB::table(PREFIX . 'codo_categories')->where('cat_id', $req_cid)->update(array('no_topics' => \DB::raw('no_topics+1'), 'no_posts' => \DB::raw('no_posts+' . $topic_info['no_posts'])));
                 $cid = $req_cid;
                 if ($_POST['notify'] === 'true') {
                     $categoryName = $topic->getCatNameFromId($cid);
                     $topicData = array("label" => 'Topic moved', "cid" => $req_cid, "tid" => $tid, "pid" => $topic_info['post_id'], "notification" => "%actor% moved <b>%title%</b> to %category%", "bindings" => array("title" => \CODOF\Util::start_cut($topic_info['title'], 100), "category" => $categoryName));
                     $notifier = new \CODOF\Forum\Notification\Notifier();
                     $notifier->queueNotify('ofTopic', $topicData);
                 }
             }
             $sticky = $_POST['sticky'] === "true" ? 'yes' : 'no';
             $frontpage = $_POST['frontpage'] === "true" ? 'yes' : 'no';
             $new_topic_status = $topic_status;
             if ($sticky == 'yes' && $user->can('make sticky')) {
                 if ($frontpage == 'yes') {
                     $new_topic_status = \CODOF\Forum\Forum::STICKY;
                 } else {
                     $new_topic_status = \CODOF\Forum\Forum::STICKY_ONLY_CATEGORY;
                 }
             }
             if ($sticky == 'no' && \CODOF\Forum\Forum::isSticky($topic_status)) {
                 $new_topic_status = \CODOF\Forum\Forum::APPROVED;
             }
             $topic->edit_topic($cid, $tid, $topic_info['post_id'], $_POST['title'], $_POST['imesg'], $_POST['omesg'], $new_topic_status);
         }
         if (isset($_POST['tags']) && $user->can('add tags')) {
             $tags = $_POST['tags'];
             $dbTags = $topic->getTags($tid);
             $_tags = $topic->getTagStatus($dbTags, $tags);
             $topic->insertTags($tid, $_tags['toInsert']);
             $topic->removeTags($tid, $_tags['toDelete']);
         }
         echo json_encode(array('tid' => $tid));
     } else {
         echo _t("You do not have permission to ") . _t("edit this topic");
     }
 }
Example #12
0
 /** private functions --------------------------------------------------------- */
 public function gen_posts_arr($posts, $search = false)
 {
     $_posts = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($posts as $post) {
         $message = \CODOF\Format::message($post['message']);
         if ($search) {
             $message = $search->get_matching_str($message);
         }
         $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "post_created" => \CODOF\Time::get_pretty_time($post['post_created']), "post_modified" => \CODOF\Time::get_pretty_time($post['post_modified']), "post_id" => $post['post_id'], "message" => $message, "imessage" => $post['imessage'], "reputation" => $post['reputation'], "role" => \CODOF\User\User::getRoleName($post['rid']), "no_posts" => \CODOF\Util::abbrev_no($post['no_posts'], 1), "signature" => $post['signature']);
         $_posts[$i]['tid'] = $this->tid;
         $_posts[$i]['page'] = $this->from + 1;
         $_posts[$i]['safe_title'] = $this->safe_title;
         if ($this->topic_post_id == $post['post_id']) {
             //is a topic
             $_posts[$i]['is_topic'] = true;
             if ($post['id'] == $uid) {
                 //this topic belongs to current user
                 $_posts[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $this->cat_id);
                 $_posts[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $this->cat_id);
             } else {
                 $_posts[$i]['can_edit_topic'] = $user->can('edit all topics', $this->cat_id);
                 $_posts[$i]['can_delete_topic'] = $user->can('delete all topics', $this->cat_id);
             }
             $_posts[$i]['can_manage_topic'] = $_posts[$i]['can_edit_topic'] || $_posts[$i]['can_delete_topic'];
         } else {
             $_posts[$i]['is_topic'] = false;
             if ($post['id'] == $uid) {
                 //this topic belongs to current user
                 $_posts[$i]['can_edit_post'] = $user->can(array('edit my posts', 'edit all posts'), $this->cat_id);
                 $_posts[$i]['can_delete_post'] = $user->can(array('delete my posts', 'delete all posts'), $this->cat_id);
             } else {
                 $_posts[$i]['can_edit_post'] = $user->can('edit all posts', $this->cat_id);
                 $_posts[$i]['can_delete_post'] = $user->can('delete all posts', $this->cat_id);
             }
             $_posts[$i]['can_manage_post'] = $_posts[$i]['can_edit_post'] || $_posts[$i]['can_delete_post'];
         }
         $_posts[$i]['can_see_history'] = $user->can('see history', $this->cat_id);
         if ($this->tuid == $uid) {
             //if my topic
             $_posts[$i]['can_reply'] = true;
             //i can reply to my own topic
         } else {
             $_posts[$i]['can_reply'] = $user->can('reply to all topics', $this->cat_id, $this->tid);
         }
         if ($search) {
             $_posts[$i]['in_search'] = true;
         }
         $i++;
     }
     return $_posts;
 }
Example #13
0
 public function gen_topic_arr($topics, $cid)
 {
     $_topics = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_created" => $topic['topic_created'], "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe(html_entity_decode($topic['title'])), "title" => $topic['title'], "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_name" => $topic['lname'], "last_post_uid" => $topic['luid'], "sticky" => Forum::isSticky($topic['topic_status']), "last_post_id" => $topic['last_post_id'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['lpost_time'] != $topic['topic_created'] ? $topic['lpost_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         if ($topic['uid'] == $uid) {
             //this topic belongs to current user
             $_topics[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $cid);
             $_topics[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $cid);
         } else {
             $_topics[$i]['can_edit_topic'] = $user->can('edit all topics', $cid);
             $_topics[$i]['can_delete_topic'] = $user->can('delete all topics', $cid);
         }
         $_topics[$i]['can_manage_topic'] = $_topics[$i]['can_edit_topic'] || $_topics[$i]['can_delete_topic'];
         if (isset($search)) {
             $_topics[$i]['in_search'] = true;
         }
         if (in_array($topic['topic_id'], $this->new_topic_ids)) {
             $_topics[$i]["new_topic"] = true;
         }
         if (in_array($topic['topic_id'], $this->new_replies)) {
             $_topics[$i]["new_replies"] = $this->new_replies[$topic['topic_id']][0];
             $_topics[$i]["last_reply_id"] = $this->new_replies[$topic['topic_id']][1];
         }
         if (isset($this->tags[$topic['topic_id']])) {
             $_topics[$i]["tags"] = $this->tags[$topic['topic_id']];
         }
         $i++;
     }
     return $_topics;
 }
Example #14
0
 public function replace_tokens($text)
 {
     preg_match_all("/\\[(.*?)\\]/", $text, $tkns);
     $tokens = $tkns[1];
     //we use str_replace which anyway replaces all occurences
     $ids = array_unique($tokens);
     foreach ($ids as $id) {
         $fields = explode(":", $id);
         switch ($fields[0]) {
             //user related
             case 'user':
                 $value = $this->user[$fields[1]];
                 break;
                 //any config from codo_config table
             //any config from codo_config table
             case 'option':
                 $value = \CODOF\Util::get_opt($fields[1]);
                 break;
             case 'this':
                 $value = $this->curr[$fields[1]];
                 break;
             case 'post':
                 $value = $this->post[$fields[1]];
                 break;
             default:
                 $value = '';
         }
         $text = str_replace("[{$id}]", $value, $text);
     }
     return $text;
 }
Example #15
0
 private function assign_editor_vars()
 {
     $this->smarty->assign('max_file_size', \CODOF\Util::get_opt('forum_attachments_size'));
     $this->smarty->assign('allowed_file_mimetypes', \CODOF\Util::get_opt('forum_attachments_mimetypes'));
     $this->smarty->assign('forum_attachments_parallel', \CODOF\Util::get_opt('forum_attachments_parallel'));
     $this->smarty->assign('forum_attachments_multiple', \CODOF\Util::get_opt('forum_attachments_multiple'));
     $this->smarty->assign('forum_attachments_max', \CODOF\Util::get_opt('forum_attachments_max'));
     $this->smarty->assign('forum_smileys', json_encode(\CODOF\Util::get_smileys($this->db)));
     $this->smarty->assign('reply_min_chars', \CODOF\Util::get_opt('reply_min_chars'));
 }
 public function can_down($pid, $to_id)
 {
     $user = \CODOF\User\User::get();
     $res = \DB::table(PREFIX . 'codo_daily_rep_log')->select('rep_count', 'start_rep_time')->where('uid', '=', $user->id)->first();
     if (!$res) {
         $res['rep_count'] = 0;
         $res['start_rep_time'] = time();
         \DB::table(PREFIX . 'codo_daily_rep_log')->insert(array("uid" => $user->id, "rep_count" => 0, "start_rep_time" => time()));
     }
     $max_rep_allowed = \CODOF\Util::get_opt('max_rep_per_day');
     //RULE 1: User can give max X rep per day
     $one_day = 24 * 60 * 60;
     $within_one_day = time() - $res['start_rep_time'] < $one_day;
     $this->max_rep_count_reached = $res['rep_count'] == $max_rep_allowed;
     $this->rule1 = !($this->max_rep_count_reached && $within_one_day);
     //RULE 2: User must have X reputation points or Y posts to increment reputation
     $rep_to_inc = \CODOF\Util::get_opt('rep_req_to_dec');
     $posts_to_inc = \CODOF\Util::get_opt('posts_req_to_dec');
     $this->rule2 = $user->reputation >= $rep_to_inc && $user->no_posts >= $posts_to_inc;
     //RULE 3: Reputation cannot be given/taken to same user more N times
     //        until X hours have passed
     $rep_times_same_user = \CODOF\Util::get_opt('rep_times_same_user');
     $rep_hours_same_user = \CODOF\Util::get_opt('rep_hours_same_user');
     $rep_seconds_same_user = $rep_hours_same_user * 60;
     $rows = \DB::table(PREFIX . 'codo_reputation')->where('from_id', '=', $user->id)->where('to_id', '=', $to_id)->where('post_id', '=', $pid)->where('rep_time', '>', time() - $rep_seconds_same_user)->select('points')->get();
     $numbers_of_reps = count($rows);
     $this->rule3 = $numbers_of_reps < $rep_times_same_user;
     //RULE 4: User cannot give reputation to the same post more than once
     $has_rep = \DB::table(PREFIX . 'codo_reputation')->where('from_id', '=', $user->id)->where('post_id', '=', $pid)->where('points', '=', 1)->get();
     $this->rule4 = !$has_rep;
     $this->rule5 = $user->id != $to_id;
     return $this->rule1 && $this->rule2 && $this->rule3 && $this->rule4 && $this->rule5 && $user->can('rep up');
 }
Example #17
0
 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();
 }
Example #18
0
 public function sendDigest()
 {
     $smarty = \CODOF\Smarty\Single::get_instance(SYSPATH . 'CODOF/Forum/Notification/Digest/', true);
     $user = \CODOF\User\User::get();
     $smarty->assign('site_title', \CODOF\Util::get_opt('site_title'));
     $smarty->assign('brand_img', \CODOF\Util::get_opt('brand_img'));
     $smarty->assign('username', $user->username);
     $date = date('Y-F-j-S', time());
     list($year, $month, $day, $ordinal) = explode("-", $date);
     $dayInfo = array("year" => $year, "month" => $month, "day" => $day, "ordinal" => $ordinal);
     $smarty->assign('dayInfo', $dayInfo);
     $smarty->assign('statistics_img', 'http://i.imgur.com/7sBa4Ow.png');
     //RAW
     $smarty->assign('create_new_img', 'http://i.imgur.com/E0MhBwI.png');
     //RAW
     $notifier = new \CODOF\Forum\Notification\Notifier();
     $events = $notifier->get(TRUE, 0, 'asc');
     //get all unread notifications
     $sortedEvents = $this->sort($events);
     $smarty->assign('events', $sortedEvents);
     $smarty->assign('new_posts', $this->newPosts . " ");
     $smarty->assign('new_topics', $this->newTopics . " ");
     if (empty($events)) {
         $smarty->assign('nothing_new', true);
     } else {
         $smarty->assign('nothing_new', false);
     }
     $frequency = $user->prefers('notification_frequency');
     $html = $smarty->fetch("{$frequency}.tpl");
     $text = $smarty->fetch("{$frequency}Text.tpl");
     $this->daily = $html;
     $this->dailyText = $text;
     $mailer = new \CODOF\Forum\Notification\Mail();
     $mailer->setHTML($mailer->replace_tokens($this->dailyText));
     $mailer->to = $user->mail;
     $mailer->subject = _t('Daily digest - ') . \CODOF\Util::get_opt('site_title');
     $mailer->message = $this->daily;
     $mailer->send_mail();
 }
Example #19
0
 public function ins_topics($topic_info, $pid, $use_passed_pid)
 {
     $cats = array();
     $i = 0;
     $defs = array("last_post_id" => 0, "topic_updated" => 0);
     foreach ($topic_info as $cat) {
         $cats[$i] = $this->set_value($cat, $defs);
         $cats[$i] += $cat;
         //$cats[$i]['topic_id'] = $tid;
         if ($use_passed_pid) {
             $cats[$i]['post_id'] = ++$pid;
         }
         $cats[$i]['title'] = Format::title($cat['title']);
         //does all last post details exist ?
         if (\CODOF\Util::is_set($cat, array('last_post_id', 'last_post_uid', 'last_post_name', 'last_post_time'))) {
             //correct last post time
             if ($cat['last_post_time'] == null || $cat['last_post_time'] == 0) {
                 $cats[$i]['last_post_time'] = $cat['topic_created'];
             }
         } else {
             $cats[$i]['last_post_id'] = 0;
             $cats[$i]['last_post_uid'] = NULL;
             $cats[$i]['last_post_name'] = NULL;
             $cats[$i]['last_post_time'] = $cat['topic_created'];
         }
         if (isset($cat['no_views'])) {
             $cats[$i]['no_views'] = $cat['no_views'];
         } else {
             $cats[$i]['no_views'] = 0;
         }
         $i++;
     }
     // var_dump($cats);
     $attrs = array("topic_id", "title", "cat_id", "post_id", "uid", "last_post_id", "last_post_uid", "last_post_name", "topic_created", "topic_updated", "last_post_time", "no_views");
     $qry = $this->prepare_ins_qry($cats, $attrs, "codo_topics");
     $this->query .= $qry;
     return $pid;
 }
function smarty_modifier_get_opt($option)
{
    return \CODOF\Util::get_opt($option);
}
<?php

/*
 * @CODOLICENSE
 */
$smarty = \CODOF\Smarty\Single::get_instance();
$db = \DB::getPDO();
CODOF\Util::get_config($db);
$reg_req_admin = \CODOF\Util::get_opt('reg_req_admin');
if (isset($_POST['action']) && CODOF\Access\CSRF::valid($_POST['CSRF_token'])) {
    $action = $_POST['action'];
    if ($action == 'approve') {
        \DB::table(PREFIX . 'codo_users')->whereIn('id', $_POST['ids'])->update(array('user_status' => 1));
        \DB::table(PREFIX . 'codo_user_roles')->whereIn('uid', $_POST['ids'])->update(array('rid' => ROLE_USER));
    } else {
        foreach ($_POST['ids'] as $id) {
            $user = CODOF\User\User::get((int) $id);
            $user->deleteAccount();
        }
    }
}
$qry = "SELECT id,username,mail,created,user_status FROM " . PREFIX . "codo_users WHERE user_status=2 OR user_status=0 AND username<>'anonymous'";
$obj = $db->query($qry);
$res = $obj->fetchAll();
$users = array();
foreach ($res as $user) {
    $users[] = array('id' => $user['id'], 'username' => $user['username'], 'mail' => $user['mail'], 'created' => CODOF\Time::get_pretty_time($user['created']), 'confirmed' => (int) $user['user_status'] == 2 ? 'yes' : 'no');
}
$smarty->assign('reg_req_admin', $reg_req_admin);
$smarty->assign('users', $users);
$content = $smarty->fetch('moderation/approve_users.tpl');
function smarty_modifier_abbrev_no($string)
{
    return \CODOF\Util::abbrev_no($string, 2);
}
Example #23
0
 public function getTaggedTopics($tag, $from)
 {
     $new_topic_ids = array();
     $new_replies = array();
     $topic = new \CODOF\Forum\Topic($this->db);
     $topic->ajax = true;
     $topics = $topic->getTaggedTopics($tag, $from);
     $tids = array();
     foreach ($topics as $one_topic) {
         $tids[] = $one_topic['topic_id'];
     }
     if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
         $tracker = new \CODOF\Forum\Tracker($this->db);
         //0.76 = 3 queries
         $new_topic_ids = $tracker->get_all_new_topic_ids($tids);
         $new_replies = $tracker->get_new_reply_counts($tids);
     }
     //echo json_encode(
     return array("topics" => $topics, "tags" => $topic->getAllTags($tids), "new_topic_ids" => $new_topic_ids, "find_topics_tagged" => _t("find topics tagged"), "new_replies" => $new_replies, "new" => _t("new"), "new_topic" => _t("new topic"), "new_replies_txt" => _t("new replies"), "RURI" => RURI, "DURI" => DURI, "CAT_IMGS" => CAT_IMGS, "CURR_THEME" => CURR_THEME, "reply_txt" => _t("replies"), "views_txt" => _t("views"), "recent_txt" => _t('recent by'), "num_posts" => \CODOF\Util::get_opt('num_posts_all_topics'));
     //);
 }
Example #24
0
 public function confirm()
 {
     $this->view = 'user/confirm';
     $action = array();
     if (empty($_GET['user']) || empty($_GET['token'])) {
         $action['result'] = 'VAR_NOT_PASSED';
         //$action['text'] = 'We are missing variables. Please double check your email.';
     } else {
         //cleanup the variables
         $username = $_GET['user'];
         $token = $_GET['token'];
         //check if the key is in the database
         $qry = "SELECT username FROM  " . PREFIX . "codo_signups WHERE username=:username AND token=:token LIMIT 1 OFFSET 0";
         $stmt = $this->db->prepare($qry);
         $result = $stmt->execute(array("username" => $username, "token" => $token));
         if ($result) {
             //get the confirm info
             $res = $stmt->fetch();
             $reg_req_admin = \CODOF\Util::get_opt('reg_req_admin');
             $user_status = 1;
             if ($reg_req_admin == 'yes') {
                 $user_status = 2;
             }
             //confirm the email and update the users database
             $qry = "UPDATE " . PREFIX . "codo_users SET user_status={$user_status} WHERE username=:username";
             $stmt = $this->db->prepare($qry);
             $stmt->execute(array("username" => $username));
             if ($reg_req_admin == 'no') {
                 $user = \CODOF\User\User::getByUsername($username);
                 $qry = "UPDATE " . PREFIX . "codo_user_roles SET rid=:rid WHERE uid=" . $user->id;
                 $stmt = $this->db->prepare($qry);
                 $stmt->execute(array("rid" => ROLE_USER));
             }
             //delete the signup rows associated with the selected username
             $qry = "DELETE FROM " . PREFIX . "codo_signups WHERE username = '******'username'] . "'";
             $this->db->query($qry);
             $action['result'] = 'SUCCESS';
         } else {
             $action['result'] = 'VAR_NOT_FOUND';
         }
     }
     \CODOF\Store::set('sub_title', _t('Confirm user'));
     $this->smarty->assign('result', $action['result']);
 }
Example #25
0
 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);
 }
Example #26
0
    //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!');
}
Example #27
0
 /**
  * Get matched users with limit 10
  * @param string $qry
  * @return array
  */
 public function find($qry, $catid, $tid)
 {
     $cid = (int) $catid;
     $tid = (int) $tid;
     $selector = '';
     if ($cid) {
         $selector = ', MAX(p.granted) AS allowed';
     }
     $users = \DB::table(PREFIX . 'codo_users AS u');
     $users->select(\DB::raw('u.id, u.username, u.avatar' . $selector))->where('u.username', 'LIKE', "{$qry}%")->where('u.mail', '<>', 'anonymous@localhost');
     if ($cid) {
         $users->leftJoin(PREFIX . 'codo_user_roles AS r', 'r.uid', '=', 'u.id')->leftJoin(PREFIX . 'codo_permissions AS p', function ($join) use($cid) {
             $join->on('p.permission', '=', \DB::raw('\'view all topics\''))->on('p.rid', '=', 'r.rid')->on('p.cid', '=', \DB::raw($cid))->on('p.tid', '=', \DB::raw(0));
         })->groupBy('u.id');
     }
     $users = $users->take(10)->get();
     $type = '';
     if ($cid) {
         $type = 'new_topic';
     }
     if ($tid) {
         $type = 'new_reply';
     }
     $mutedIds = array();
     if ($type != '' && count($users)) {
         $uids = array_column($users, 'id');
         $subscriber = new Subscriber();
         $mutedIds = $subscriber->mutedOf($type, $cid, $tid, $uids);
     }
     $_users = array();
     $i = 0;
     foreach ($users as $user) {
         $_users[$i]["username"] = $user['username'];
         $_users[$i]["avatar"] = \CODOF\Util::get_avatar_path($user['avatar'], $user['id'], false);
         if ($cid) {
             //if $cid is not provided can't say whether user is mentionable or not
             $notMentionable = in_array($user['id'], $mutedIds) || $user['allowed'] === 0;
             $_users[$i]["mentionable"] = !$notMentionable ? 'yes' : 'no';
             //better for js -> y/n
         }
         $i++;
     }
     return $_users;
 }
Example #28
0
 /**
  * Returns user info from database 
  * @param string $qry
  * @param array $vals
  * @param PDO $db
  * @return object
  */
 protected static function getUserObject($qry, $vals, $db)
 {
     $obj = $db->prepare($qry);
     $obj->execute($vals);
     $userDetails = $obj->fetchAll(PDO::FETCH_OBJ);
     foreach ($userDetails as $u) {
         $rids[] = $u->rid;
         if ($u->is_primary == '1') {
             $primary_rid = $u->rid;
         }
     }
     if (isset($userDetails[0])) {
         $user = $userDetails[0];
         $user->rids = $rids;
         $user->rid = $primary_rid;
         unset($user->is_primary);
         //not required and is wrong
     }
     if (isset($user) && property_exists($user, 'id')) {
         $user->rawAvatar = $user->avatar;
         $user->avatar = \CODOF\Util::get_avatar_path($user->avatar, $user->id);
         return $user;
     }
     \CODOF\Util::log('Unable to fetch user data User.php:39 vals= ' . print_r($vals, true) . ' ' . print_r($_SESSION, true));
     return false;
 }
Example #29
0
/*
 * @CODOLICENSE
 */
//Limonade -> 230 ms
//display & routing
if (get_magic_quotes_gpc()) {
    $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    array_walk_recursive($gpc, function (&$value) {
        $value = stripslashes($value);
    });
}
use CODOF\Util;
use CODOF\Access\Request;
$db = \DB::getPDO();
Util::get_config($db);
\Constants::post_boot('themes/' . Util::get_opt('theme') . "/");
CODOF\Smarty\Single::get_instance();
//-------------------------server static files --------------------------------
dispatch_get('Ajax/history/posts', function () {
    if (Request::valid($_GET['_token'])) {
        $post = new \CODOF\Forum\Post();
        $post->getHistory($_GET['pid']);
    }
});
dispatch_get('Ajax/reputation/:pid/up', function ($pid) {
    if (Request::valid($_GET['_token'])) {
        $rep = new \CODOF\Forum\Reputation();
        $rep->up($pid);
    }
});
dispatch_get('Ajax/reputation/:pid/down', function ($pid) {