Ejemplo n.º 1
0
 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;
     }
 }
function smarty_function_print_post_url($option)
{
    if (isset($option['pid'])) {
        echo \CODOF\Forum\Forum::getPostURL($option['tid'], $option['title'], $option['pid']);
    } else {
        echo \CODOF\Forum\Forum::getPostURL($option['tid'], $option['title']);
    }
}
Ejemplo n.º 3
0
 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';
         }
     }
 }
Ejemplo n.º 4
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");
     }
 }