示例#1
0
 public function beforeSave($options = array())
 {
     //parent::beforeSave($options);
     //print_r($this->data);
     $loggedInUser = AuthComponent::user();
     $found = false;
     $userId = $loggedInUser['user_id'];
     $this->data['Post']['post_by'] = $userId;
     $this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
     //format('Y-m-d H:i:s')
     if (!empty($this->data['Topic']['topic_subject'])) {
         $str = $this->data['Topic']['topic_subject'];
         $num = $this->data['Post']['post_cat'];
         $subject = new Topic();
         $found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
         if (!$found) {
             $subject->create();
             //create topic
             $subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
             //see also save associated model method cakephp
             $this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
             return true;
         }
         $this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
         return true;
     }
     //nothing
     return true;
 }
 public function run()
 {
     $table = $this->getTable();
     $title = 'Lorem ipsum dolor sit amet';
     $topic = new Topic(['title' => $title]);
     $topic->save();
 }
示例#3
0
 function delete_category($params = array(), $param_op = 'AND')
 {
     $categories = $this->select_record($params, array('id'), $param_op);
     $topic = new Topic($this->config);
     foreach ($categories as $category) {
         $topic->delete_record(array('category' => $category['id']));
     }
     $this->delete_record($params);
 }
示例#4
0
 function DropTables()
 {
     $moderator = new Moderator();
     $moderator->SetDatabase($this);
     $moderator->Drop();
     $message = new Message();
     $message->SetDatabase($this);
     $message->Drop();
     $topic = new Topic();
     $topic->SetDatabase($this);
     $topic->Drop();
     $user_info = new UserInfo();
     $user_info->SetDatabase($this);
     $user_info->Drop();
     $session = new Session();
     $session->SetDatabase($this);
     $session->Drop();
     $new = new News();
     $new->SetDatabase($this);
     $new->Drop();
     $shout = new Shout();
     $shout->SetDatabase($this);
     $shout->Drop();
     $paragraph = new Paragraph();
     $paragraph->SetDatabase($this);
     $paragraph->Drop();
     $privilege = new Privilege();
     $privilege->SetDatabase($this);
     $privilege->Drop();
     $role = new Role();
     $role->SetDatabase($this);
     $role->Drop();
     $menu_item = new MenuItem();
     $menu_item->SetDatabase($this);
     $menu_item->Drop();
     $module = new Module();
     $module->SetDatabase($this);
     $module->Drop();
     $page = new Page();
     $page->SetDatabase($this);
     $page->Drop();
     $article = new Article();
     $article->SetDatabase($this);
     $article->Drop();
     $subject = new Subject();
     $subject->SetDatabase($this);
     $subject->Drop();
     $menu = new Menu();
     $menu->SetDatabase($this);
     $menu->Drop();
     $profile = new Profile();
     $profile->SetDatabase($this);
     $profile->Drop();
     $user = new User();
     $user->SetDatabase($this);
     $user->Drop();
 }
示例#5
0
function addTopic($topic_ancestor_id, $topic_name)
{
    $ancestor_object = TopicQuery::create()->findOneById($topic_ancestor_id);
    $topic_object = new Topic();
    $topic_object->setName($topic_name)->insertAsLastDescendantOf($ancestor_object)->save();
    $topic_synonym_object = new TopicSynonym();
    $topic_synonym_object->setName($topic_name)->setTopic($topic_object)->save();
    return $topic_object->getId();
}
示例#6
0
 function addTopicToTest($id = 1)
 {
     $toc = new Topic();
     $toc->get_by_id($id);
     $t = new Test();
     $t->get_by_id(2);
     if ($t->save($toc)) {
         echo $toc->to_json();
     }
 }
示例#7
0
 /**
  * This will post a new Topic for this forum along with the topic's first / initial message.
  * 
  * @param string $strTitle
  * @param string $strMessageText
  * @param Person $objPerson
  * @param QDateTime $dttPostDate
  * @return Topic
  */
 public function PostTopic($strTitle, $strFirstMessageText, Person $objPerson, QDateTime $dttPostDate = null)
 {
     $objTopic = new Topic();
     $objTopic->TopicLink = $this->TopicLink;
     $objTopic->Name = $strTitle;
     $objTopic->Person = $objPerson;
     $objTopic->Save();
     $objTopic->PostMessage($strFirstMessageText, $objPerson, $dttPostDate);
     return $objTopic;
 }
示例#8
0
 public function delete(Topic $topic)
 {
     $id = $topic->getId();
     $query = "DELETE FROM topic WHERE id='" . $id . "'";
     $res = mysqli_query($this->db, $query);
     if ($res) {
         return true;
     } else {
         return "Internal Server Error";
     }
 }
示例#9
0
function unfollowtopic(){

	$topic = new Topic();
	if (!isset($_GET['topicid_unfollowtopic']))
		return array("ok"=>false, "error"=>"no id");
	$topic->setId($_GET['topicid_unfollowtopic']);
	if ($topic->unfollow())
		return array("ok"=>true, "error"=>"");
	else
		return array("ok"=>false, "error"=>"cant unfollow");

}
示例#10
0
 public function create($titre)
 {
     $topic = new Topic($this->link);
     $topic->setTitre($titre);
     $titre = mysqli_real_escape_string($this->link, $titre);
     $request = "INSERT INTO topics (titre, id_auteur, id_category) VALUES ('" . $titre . "', '" . $_SESSION['id'] . "', '" . $this->id . "')";
     $res = mysqli_query($this->link, $request);
     if ($res) {
         return $this->select(mysqli_insert_id($this->link));
     } else {
         throw new Exception("Internal server error");
     }
 }
示例#11
0
文件: getTopic.php 项目: eruedin/cats
function getTopicStartTest($t_id)
{
    // Wertprüfung
    $t_id = abs(intval($t_id));
    echo '<form action="index.php?site=start_test&amp;action=getQuestions" method="post">';
    $button = Function_getTopic_03;
    $topic = new Topic();
    $topic->getActiveTopic();
    $arrayTopic = $topic->getTopicArray();
    echo " <div id=\"inner_box_top\">\n";
    // In der Mitte der Inhalt
    showForm($t_id, $button, $arrayTopic);
}
示例#12
0
 /**
  * Creates the Topic and TopicLink for this Package object.
  * @param Person $objPerson person who created this package who will be credited with creating the linked topic
  * @return Topic
  */
 public function CreateTopicAndTopicLink(Person $objPerson)
 {
     $objTopicLink = new TopicLink();
     $objTopicLink->TopicLinkTypeId = TopicLinkType::Package;
     $objTopicLink->Package = $this;
     $objTopicLink->Save();
     $objTopic = new Topic();
     $objTopic->TopicLink = $objTopicLink;
     $objTopic->Name = $this->strName;
     $objTopic->Person = $objPerson;
     $objTopic->Save();
     return $objTopic;
 }
示例#13
0
 public function create()
 {
     foreach ($this->required as $required => $strlen) {
         if (!Input::has($required) || strlen(Input::get($required)) < $strlen) {
             return Response::make(['error' => 'You must introduce a ' . $required . ' with ' . $strlen . ' of length...'], 404);
         }
     }
     $new = new Topic();
     $new->fill(Input::only(['title', 'author', 'message']));
     $new->place = $this->place;
     $new->save();
     return Response::make(['success' => 'You just created a new topic!', 'topic' => $new->toArray()], 404);
 }
示例#14
0
 /**
  * Given a list of topic names, return the list of topic ids
  */
 public static function idsFromNames(array $names)
 {
     $ids = [];
     foreach ($names as $name) {
         $topic = static::whereName($name)->first();
         if (!$topic) {
             $topic = new Topic();
             $topic->name = $name;
             $topic->save();
         }
         $ids[] = $topic->id;
     }
     return $ids;
 }
示例#15
0
 public function downVote(Topic $topic)
 {
     if (Recomment::user(Auth::user()->user_id)->topic($topic->topic_id)->type('downvote')->count()) {
         Recomment::user(Auth::user()->user_id)->topic($topic->topic_id)->type('downvote')->delete();
         $topic->increment('recommend_add', 1);
     } elseif (Recomment::user(Auth::user()->user_id)->topic($topic->topic_id)->type('upvote')->count()) {
         Recomment::user(Auth::user()->user_id)->topic($topic->topic_id)->type('upvote')->delete();
         Recomment::create(['user_id' => Auth::user()->user_id, 'topic_id' => $topic->topic_id, 'status' => '0', 'types' => 'downvote']);
         $topic->decrement('recommend_add', 2);
     } else {
         Recomment::create(['user_id' => Auth::user()->user_id, 'topic_id' => $topic->topic_id, 'status' => '0', 'types' => 'downvote']);
         $topic->decrement('recommend_add', 1);
     }
 }
示例#16
0
function topicCount($category_id)
{
    if ($category_id == null) {
        $topicCount = new Topic();
        return $topicCount->getTotalTopics();
    } else {
        $db = new Database();
        $db->query("SELECT * FROM topics WHERE category_id = :category_id");
        $db->bind(':category_id', $category_id);
        $row = $db->resultset();
        $count = $db->rowCount();
        return $count;
    }
}
示例#17
0
function add_post()
{
	global $CONF;
	$user = $_SESSION['user'];

	if ($user->getBanned()>0){
		return array('ok'=>false, 'error'=>'banned '.$user->getBanned());
	}

	if (isset($_SESSION['post_last_flood_time'])){

		if ((time() - $_SESSION['post_last_flood_time']) < $CONF['post_time_to_wait_flood']){
			$time_to_wait = $CONF['post_time_to_wait_flood'] - (time() - $_SESSION['post_last_flood_time']);
			return array('ok'=>false, 'error'=>'flood '.$time_to_wait);
		}

	}

	$post = new Post();

	$topic = new Topic(); $topic->setId($_GET['topicid_add_post']);

	if (!$topic->getChannel()->canIPost())
		return array('ok'=>false, 'error'=>'you cant create post in this channel');

	$post->setTopic($topic);
	$post->setUser($user);

	$msg = unescape_ampersand($_POST['msg']);
	if (strlen(str_replace(' ', '', strip_tags($msg))) < $CONF['min_msg_chars'])
		return array('ok'=>false, 'error'=>'too short message');

	$msg = strip_tags($msg, $CONF['permitted_tags_msg']);
	//$msg = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\"_BLANK\" href=\"\\0\">\\0</a>", $msg); //detectando URLs
	$msg = text_linkify($msg);
	$post->setPost($msg);

	if ($post->save()=='ok'){
		$_SESSION['post_last_flood_time']=time();	

		$topic->follow();
		$topic->setId($topic->getId());	$topic->load(); //update topic->counter
		$topic->visit();
		return array('ok'=>true, 'error'=>'');
	}
	else
		return array('ok'=>false, 'error'=>'Problem with this post.');
}
function get_topics($con, $args)
{
    $topics = array();
    if (isset($args["tid"])) {
        $tid = $args["tid"];
        $sql = $con->prepare("SELECT sid,tname,`order` FROM topic WHERE tid=?");
        $sql->bind_param("i", $tid);
        $sql->bind_result($sid, $tname, $order);
        $sql->execute();
        $sql->fetch();
        $sql->close();
        if (isset($sid) && isset($tname) && isset($order)) {
            $tmp = new Topic();
            $tmp->populate($sid, $tid, $tname, [], $order);
            $topics[] = $tmp->expose();
        }
    } else {
        if (isset($args["tname"])) {
            $tname = $args["tname"];
            $sql = $con->prepare("SELECT sid,tid,`order` FROM topic WHERE tname=?");
            $sql->bind_param("s", $tname);
            $sql->bind_result($sid, $tid, $order);
            $sql->execute();
            while ($sql->fetch()) {
                if (isset($sid) && isset($tid) && isset($order)) {
                    $tmp = new Topic();
                    $tmp->populate($sid, $tid, $tname, [], $order);
                    $topics[] = $tmp->expose();
                }
            }
            $sql->close();
        } else {
            $sql = $con->prepare("SELECT sid,tid,tname,`order` FROM topic");
            $sql->bind_result($sid, $tid, $tname, $order);
            $sql->execute();
            while ($sql->fetch()) {
                if (isset($sid) && isset($tid) && isset($tname) && isset($order)) {
                    $tmp = new Topic();
                    $tmp->populate($sid, $tid, $tname, [], $order);
                    $topic = $tmp->expose();
                    $topics[] = $topic;
                }
            }
            $sql->close();
        }
    }
    return $topics;
}
示例#19
0
 public function actionList()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'id asc';
     $topics = Topic::model()->findAll($criteria);
     $this->render('list', array('topics' => $topics));
 }
示例#20
0
 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 50; $i++) {
         $new = Topic::create(array('author' => $faker->name, 'title' => $faker->sentence(10), 'message' => $faker->paragraphs(2, true), 'place' => $faker->randomElement(array('web', 'api')), 'updated_at' => $faker->dateTime('now'), 'created_at' => $faker->dateTime('now')));
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $topics = Topic::all();
     $markdown = new Markdown();
     $transfer_count = 0;
     $convert_count = 0;
     foreach ($topics as $topic) {
         if (empty($topic->body_original)) {
             // store the original data
             $topic->body_original = $topic->body;
             // convert to markdown
             $topic->body = $markdown->convertMarkdownToHtml($topic->body);
             $topic->save();
             $transfer_count++;
         } else {
             // convert to markdown
             $topic->body = $markdown->convertMarkdownToHtml($topic->body_original);
             $topic->save();
             $convert_count++;
         }
     }
     $this->info("Transfer old data count: " . $transfer_count);
     $this->info("Convert original to body count: " . $convert_count);
     $this->info("It's Done, have a good day.");
 }
示例#22
0
 /**
  * Display a list topics
  * POST /topiclist
  *
  * @return Response
  */
 public function topicList()
 {
     $language = Input::get('language');
     if ($language == '') {
         $arr['Success'] = false;
         $arr['Status'] = 'Parameter missing: language';
         $arr['StatusCode'] = 400;
     } else {
         $topics = Topic::whereTopicLanguage($language)->get();
         $arr = array();
         if (count($topics) > 0) {
             $arr['Success'] = true;
             $arr['Status'] = 'OK';
             $arr['StatusCode'] = 200;
             $arr['language'] = $language;
             $arr['Result'] = array();
             $i = 0;
             foreach ($topics as $topic) {
                 $arr['Result'][$i]['id'] = $topic->topic_id;
                 $arr['Result'][$i]['name'] = ucfirst($topic->topic_name);
                 $i++;
             }
         } else {
             $arr['Success'] = false;
             $arr['Status'] = 'Topic not found';
             $arr['StatusCode'] = 404;
         }
     }
     return Response::json($arr);
 }
 public function run()
 {
     $criteria = new CdbCriteria();
     $criteria->limit = $this->data('limit');
     $criteria->offset = $this->data('offset');
     $criteria->condition = "post_status='publish' AND (post_modified <= '" . date('Y-m-d H:i:s') . "' AND post_modified >= '" . $this->data('time') . "')";
     $criteria->order = 'post_hits DESC';
     if ($this->data('autoByTerm')) {
         if (isset($_GET['id'])) {
             $category = Category::model()->findByPK((int) $_GET['id']);
             $label = Label::model()->findByPK((int) $_GET['id']);
             $topic = Topic::model()->findByPK((int) $_GET['id']);
             $tag = Tag::model()->findByPK((int) $_GET['id']);
             if ($category != null) {
                 $criteria = $this->getCriteriaTerm('categories', $criteria);
             } elseif ($label != null) {
                 $criteria = $this->getCriteriaTerm('labels', $criteria);
             } elseif ($topic != null) {
                 $criteria = $this->getCriteriaTerm('topics', $criteria);
             } elseif ($tag != null) {
                 $criteria = $this->getCriteriaTerm('tags', $criteria);
             }
         }
     }
     $model = Post::model()->findAll($criteria);
     if ($model != null) {
         $this->layout($model);
     }
 }
示例#24
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $topic = Topic::find($id);
     $topic->increment('views');
     $posts = $topic->posts;
     return View::make('topic')->with('topic', $topic)->with('posts', $posts);
 }
示例#25
0
 function getRequestStructure($format, $data = null)
 {
     $supported = array("alert", "autorespond", "source", "topicId", "attachments" => array("*" => array("name", "type", "data", "encoding", "size")), "message", "ip", "priorityId");
     # Fetch dynamic form field names for the given help topic and add
     # the names to the supported request structure
     if (isset($data['topicId']) && ($topic = Topic::lookup($data['topicId'])) && ($form = $topic->getForm())) {
         foreach ($form->getDynamicFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     # Ticket form fields
     # TODO: Support userId for existing user
     if ($form = TicketForm::getInstance()) {
         foreach ($form->getFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     # User form fields
     if ($form = UserForm::getInstance()) {
         foreach ($form->getFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     if (!strcasecmp($format, 'email')) {
         $supported = array_merge($supported, array('header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', 'thread-type', 'flags' => array('bounce', 'auto-reply', 'spam', 'viral'), 'recipients' => array('*' => array('name', 'email', 'source'))));
         $supported['attachments']['*'][] = 'cid';
     }
     return $supported;
 }
示例#26
0
 public function topicDetail()
 {
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     if (!isset($topic)) {
         return Response::view('errors.missing');
     }
     //预载入
     $gifts = Gift::where('topic_id', $topic->id)->with(['giftPosters' => function ($query) {
         $query->orderBy('created_at', 'asc');
     }])->get();
     $number = 1;
     foreach ($gifts as $gift) {
         $gift->img = $gift->giftPosters[0]->url;
         $gift->number = $number++;
     }
     // $gifts = Gift::where('topic_id', '=', $topic->id)->get();
     // if(isset($gifts))
     // {	$number = 1;
     // 	foreach($gifts as $gift)
     // 	{
     // 		$url = GiftPoster::where('gift_id','=',$gift->id)->first()->url;
     // 		// $gift->img = StaticController::imageWH($url);
     // 		$gift->img = $url;
     // 		$gift->number = $number++;
     // 	}
     // }
     $gifts = $this->isGiftLike($gifts);
     $type = $this->isTopicLike($topic_id);
     return View::make('pc.subject')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type));
 }
示例#27
0
 public function getTopicCommentMore()
 {
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     $comments = $topic->hasManyTopicComments;
     return View::make('话题评论内容')->with('comments', $comments)->with('links', $this->link());
 }
示例#28
0
 /**
  * Run Method.
  */
 public function run()
 {
     Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 0');
     $faker = Faker\Factory::create('ru_RU');
     // Заполнение разделов
     $data = [];
     for ($i = 0; $i < 15; $i++) {
         $data[] = ['sort' => $i, 'parent_id' => $i < 4 ? 0 : rand(1, 4), 'title' => $faker->realText(rand(20, 30)), 'description' => $faker->realText(rand(30, 50)), 'closed' => $i % 5 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Forum::connection()->query('TRUNCATE forums');
     $table = $this->table('forums');
     $table->insert($data)->save();
     // Заполнение тем
     $data = [];
     for ($i = 0; $i < 100; $i++) {
         $data[] = ['forum_id' => rand(1, 15), 'user_id' => rand(1, 5), 'title' => $faker->realText(rand(25, 50)), 'note' => $i % 3 ? $faker->realText(rand(30, 100)) : '', 'closed' => $i % 5 ? 0 : 1, 'locked' => $i % 6 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Topic::connection()->query('TRUNCATE topics');
     $table = $this->table('topics');
     $table->insert($data)->save();
     // Заполнение сообщений
     $data = [];
     for ($i = 0; $i < 1000; $i++) {
         $data[] = ['forum_id' => rand(1, 15), 'topic_id' => rand(1, 50), 'user_id' => rand(1, 5), 'text' => $faker->realText(rand(50, 500)), 'ip' => $faker->ipv4, 'brow' => App::getUserAgent($faker->userAgent), 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
     }
     Post::connection()->query('TRUNCATE posts');
     $table = $this->table('posts');
     $table->insert($data)->save();
     Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 1');
 }
示例#29
0
/**
 * Campsite set_topic function plugin
 *
 * Type:     function
 * Name:     set_topic
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the topic to be set
 *     $p_params[identifier] The Identifier of the topic to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_topic($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (isset($p_params['identifier'])) {
        $attrName = 'identifier';
        $attrValue = $p_params['identifier'];
        $topicId = intval($p_params['identifier']);
    } elseif (isset($p_params['name'])) {
        $attrName = 'name';
        $attrValue = $p_params['name'];
        $topic = Topic::GetByFullName($p_params['name']);
        if (!is_null($topic) && $topic->exists()) {
            $topicId = $topic->getTopicId();
        } else {
            $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
            return false;
        }
    } else {
        $property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '{$property}' in set_topic");
        return false;
    }
    if ($campsite->topic->defined && $campsite->topic->identifier == $topicId) {
        return;
    }
    $topicObj = new MetaTopic($topicId);
    if ($topicObj->defined) {
        $campsite->topic = $topicObj;
    } else {
        $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
    }
}
示例#30
0
 public static function store($group_id)
 {
     self::checkLoggedIn();
     $user = self::getUserLoggedIn();
     $params = $_POST;
     $topic = new Topic(array('title' => $params['title'], 'forum_group_id' => $group_id, 'creator' => $user->id));
     $errors = $topic->errors();
     $message;
     if (count($errors) == 0) {
         $topic->save();
         $message = array('message' => 'Aihe lisätty onnistuneesti');
     } else {
         $message = array('errors' => $errors);
     }
     Redirect::to('/groups/' . $group_id, $message);
 }