protected function render_body() { echo "<h1>Communicate</h1>"; $post = new Post(); $post->set_username("tata"); $post->set_post("basdanskjajksdfhsdjaf"); $post_model = new Post_model(); $post_model->store_post($post); $posts = $post_model->get_posts(6); print_r($posts); }
public function delete() { $post = new Post_model(); $post->id = $this->uri->segment(3); if ($post->delete()) { redirect(base_url(), 'location'); } }
public function add() { // add a comment $debug = ""; $error = ""; $info = ""; $post_id = 0; $category_id = 0; $org_id = 0; $post_status = 0; $commenting = -1; $notify_subject = "Tracker Notification - new comment added for post"; $id = 0; $comment = ""; $docs_path = SITE_ROOT . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "docs" . DIRECTORY_SEPARATOR . "posts"; $user_id = $this->template->get_session_value('user_id', 0); isset($_POST["comment"]) && ($comment = $_POST["comment"]); //isset($_POST["id"]) && $id = $_POST["id"]; // for now, no comment edits $p1 = isset($_POST["_p1_"]) ? $_POST["_p1_"] : ""; $p2 = isset($_POST["_p2_"]) ? $_POST["_p2_"] : ""; $user_id < 1 && ($error = "Please, log in first"); if (strlen($error) < 1 && (strlen($p1) < 1 || strlen($p2) < 1)) { $error = "Action prohibited - authenticity of request is in doubt"; } if (strlen($error) < 1 && !$this->is_equal($p1, $p2)) { $error = "Action prohibited - validity of request could not be confirmed"; } if (strlen($error) < 1) { list($post_id, $category_id, $org_id, $posts_status, $commenting) = explode(",", $p1, 5); is_null($commenting) && ($commenting = -1); !is_numeric($commenting) && ($commenting = -1); $post_id < 1 && ($error = "Sorry a post for this comment was not specified"); } strlen($error) < 1 && $commenting < 0 && ($error = "Sorry, the authenticity of this request is in doubt"); strlen($error) < 1 && !array_key_exists($commenting, array("0" => 1, "10" => 1, "11" => 0)) && ($error = "Sorry invalid comments status specified"); strlen($error) < 1 && $commenting == 0 && ($error = "Sorry, comments are not allowed for this post"); if (strlen($error) < 1) { $data = array("post_id" => $post_id, "comment" => substr($comment, 0, 799)); if ($id > 0) { // this is not used now; comments may not be edited $notify_subject = "Tracker Notification - comment updated for post"; $res = $this->update('post_comments', $data, $id, true); } else { $data["files"] = 0; $data["status"] = $commenting; $res = $this->insert('post_comments', $data, true, true); } $error = $this->db_error; DEBUG > 0 && ($debug = $this->db_debug); strlen($error) < 1 && isset($res[0][0]) && ($id = $res[0][0]["id"]); $files_added = 0; if ($id > 0) { // notify $u = new Post_model($this->template, $this->query_string); $x = $u->notify_post($post_id, $notify_subject); // add new files - those that have been pre-uploaded $new_files = array(); if (isset($_POST['new_files'])) { $new_files = explode(",", $_POST['new_files']); } // in case of AJAX call, new files info will be passed via 'new_files_info' // <id>,,,<file name>,,,<caption>,,,<file type>,,,<size>,<pos>##<id>,,,<file name>,,, ... $new_files_info = ""; isset($_POST['new_files_info']) && ($new_files_info = $_POST['new_files_info']); $new_files_info = strlen($new_files_info) > 0 ? explode('##', $new_files_info) : array(); if (count($new_files) > 0) { $thumbs_path = SITE_ROOT . DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . "posts"; foreach ($new_files_info as $f) { // <id>,,,<file name>,,,<caption>,,,<file type>,,,<size>,<pos>##<id>,,,<file name>,,,<main> ... $one_file = explode(',,,', $f); $fields = count($one_file); $preup_file_id = $fields > 0 ? $one_file[0] : 0; !is_numeric($preup_file_id) && ($preup_file_id = 0); $file_name = $fields > 1 ? $one_file[1] : ""; $caption = $fields > 2 ? $one_file[2] : ""; $file_type = $fields > 3 ? $one_file[3] : ""; $file_size = $fields > 4 ? $one_file[4] : 0; !is_numeric($file_size) && ($file_size = 0); $position = $fields > 5 ? $one_file[5] : 0; !is_numeric($position) && ($position = 0); $main = count($one_file) > 6 && !is_null($one_file[6]) && strlen($one_file[6]) > 0 ? $one_file[6] : 0; if ($preup_file_id > 0 && strlen($file_name) > 0) { $file_ext = strtolower(substr(strrchr($file_name, '.'), 1, 10)); // is it an image file ? $is_image = 0; $this->valid_upload_extension($file_ext, array("jpeg", "jpg", "png", "gif")) && ($is_image = 1); $preup_file_name = SITE_ROOT . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "temp" . DIRECTORY_SEPARATOR . "preups" . DIRECTORY_SEPARATOR . "raw" . DIRECTORY_SEPARATOR . $preup_file_id . "." . $file_ext; // add the image in DB & get id $image_id = 0; $data = array("post_id" => $post_id, "comment_id" => $id, "position" => $position, "main" => $main, "caption" => substr($caption, 0, 199), "file_ext" => $file_ext, "file_type" => substr($file_type, 0, 99), "file_name" => substr($file_name, 0, 99), "file_size" => $file_size, "is_image" => $is_image, "status" => 10); $res = $this->insert('post_files', $data, true, true); DEBUG > 0 && ($debug .= "; " . $this->db_debug); if (strlen($this->db_error) < 1) { isset($res[0][0]['id']) && ($image_id = $res[0][0]['id']); if ($image_id > 0) { $files_added += 1; // move file to raw images directory - by renaming $raw_file_name = $docs_path . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR . $post_id . "-" . $id . "-" . $image_id . "." . $file_ext; if (rename($preup_file_name, $raw_file_name)) { // resize image files only if ($is_image > 0) { $thumb_name = $thumbs_path . DIRECTORY_SEPARATOR . $post_id . "-" . $id . "-" . $image_id . "-th." . $file_ext; $image_name = $thumbs_path . DIRECTORY_SEPARATOR . $post_id . "-" . $id . "-" . $image_id . "-im." . $file_ext; $img = $this->resize_image($raw_file_name, 'image', 100, $image_name); DEBUG > 0 && strlen($img["error"]["message"]) > 0 && ($debug .= ", " . $img["error"]["message"]); $img = $this->resize_image($raw_file_name, 'thumb', 100, $thumb_name); DEBUG > 0 && strlen($img["error"]["message"]) > 0 && ($debug .= ", " . $img["error"]["message"]); } // remove from pre_upload $this->delete('pre_uploads', $preup_file_id, 'id'); } else { DEBUG > 0 && ($debug .= "; Could not move file to correct application folder"); } } else { DEBUG > 0 && ($debug .= "; Error recoding file named [" . $file_name . "]"); } } else { DEBUG > 0 && ($debug .= "; " . $this->db_error); } } else { DEBUG > 0 && ($debug .= "; There was a problem trying to find uploaded file [" . $file_name . "]"); } } // foreach // if files added, set count in comment record if ($files_added > 0) { $data = array("files" => $files_added); $res = $this->update('post_comments', $data, $id, true); strlen($this->db_error) > 0 && ($error .= "; " . $this->db_error); DEBUG > 0 && ($debug .= "; " . $this->db_debug); } } // count(new files) > 0 } // id > 0 } // len(error) - comment entries validation $result = array('errors' => array(array('message' => $error, 'debug' => $debug)), 'data' => array("id" => $id, "post_id" => $post_id), 'info' => $info); $this->template->assign("add_comment_result", $result); return $result; }
public function run($subject_id, $clean = true, $query_offset = 0, $from, $to) { $this->load->helper('sphinxapi'); $this->load->helper('mood'); // skip if matching_status is "matching" $matching_status = $this->custom_model->get_value('subject', 'matching_status', $subject_id); if ($matching_status == 'matching') { echo "subject is matching"; return false; } // flag subject as matching.. do other bot runs this queue. //$this->db->update('subject',array('matching_status'=>'matching'),array('id'=>$subject_id)); // clear all match record for this subject $config['hostname'] = "192.168.1.102"; $config['username'] = "******"; $config['password'] = "******"; $config['database'] = "thothconnect"; $config['dbdriver'] = "mysql"; $config['dbprefix'] = ""; $config['pconnect'] = FALSE; $config['db_debug'] = TRUE; $config['cache_on'] = FALSE; $config['cachedir'] = ""; $config['char_set'] = "utf8"; $config['dbcollat'] = "utf8_general_ci"; $thothconnect_db = $this->load->database($config, true); $query = $this->db->query("SELECT client_id FROM subject WHERE id = " . $subject_id); $row = $query->row(); $client_id = $row->client_id; if ($clean) { $thothconnect_db->delete('website_c' . $client_id, array('subject_id' => $subject_id)); $thothconnect_db->delete('twitter_c' . $client_id, array('subject_id' => $subject_id)); $thothconnect_db->delete('facebook_c' . $client_id, array('subject_id' => $subject_id)); } // // begin re-matching this subject // // get search string from subject_id $query = $this->custom_model->get_value('subject', 'query', $subject_id); // sphinx init $cl = new SphinxClient(); $q = $query; $sql = ""; $mode = SPH_MATCH_EXTENDED; $host = "192.168.1.102"; $port = 9312; $index = "*"; $groupby = ""; $groupsort = "@group desc"; $filter = "group_id"; $filtervals = array(); $distinct = ""; $sortby = "@id ASC"; $sortexpr = ""; $offset = $query_offset; $limit = 1000000; $ranker = SPH_RANK_PROXIMITY_BM25; $select = ""; echo 'limit=' . $limit . ' offset=' . $offset . PHP_EOL; //Extract subject keyword from search string $keywords = get_keywords($q); //////////// // do query //////////// $cl->SetServer($host, $port); $cl->SetConnectTimeout(1); $cl->SetArrayResult(true); $cl->SetWeights(array(100, 1)); $cl->SetMatchMode($mode); // if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals ); // if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort ); if ($sortby) { $cl->SetSortMode(SPH_SORT_EXTENDED, $sortby); } // if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr ); if ($distinct) { $cl->SetGroupDistinct($distinct); } if ($select) { $cl->SetSelect($select); } if ($limit) { $cl->SetLimits(0, $limit, $limit > 1000000 ? $limit : 1000000); } $cl->SetRankingMode($ranker); $res = $cl->Query($q, $index); //$res = true; //////////// // do Insert to DB //////////// // Current matching $current_matching = array(); /*$query_matchs = $this->db->get_where('matchs',array('subject_id'=>$subject_id)); if($query_matchs->num_rows() > 0) { echo PHP_EOL.'currents matching :'.$query_matchs->num_rows(); foreach($query_matchs->result() as $match) { $current_matching[] = $match->post_id; } }*/ // set matching date range from-to $from = strtotime($from); $to = strtotime($to); // Search and Update if ($res === false) { echo "Query failed: " . $cl->GetLastError() . ".\n"; } else { if ($cl->GetLastWarning()) { echo "WARNING: " . $cl->GetLastWarning() . "\n\n"; } echo "Query '{$q}' \nretrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n"; if ($res['total'] == 0) { echo "no result<br/>\n"; } else { if ($res['total'] > $limit + $offset) { $this->run($subject_id, $limit + $offset); } else { echo "Updating..."; foreach ($res["matches"] as $k => $docinfo) { // echo '('.$k.')'.$docinfo["id"]." "; // Reset PHP Timeout to 1min // if found in $current_matching then skip if (in_array($docinfo["id"], $current_matching)) { continue; } else { // else insert new match set_time_limit(60); $post = new Post_model(); $post->init($docinfo["id"]); // if post_date is our of range then skip $post_date = strtotime($post->post_date); if ($post_date < $from || $post_date > $to) { continue; } $mood = get_mood($post->body, $keywords); //----------------------------------------------------- $subject = $post->get_subject($subject_id); //print_r($subject); if ($post->type == "post" || $post->type == "comment") { $postData = $post->get_post_website($post->id); if ($postData != null) { $data = array(); $data["post_id"] = $postData->post_id; $data["post_date"] = $postData->post_date; $data["title"] = $postData->title; $data["body"] = $postData->body; $data["type"] = $postData->type; $data["author_id"] = $postData->author_id; $data["author"] = $postData->author; $data["website_id"] = $postData->website_id; $data["website_name"] = $postData->website_name; $data["website_cate_id"] = $postData->website_cate_id; $data["website_cate"] = $postData->website_cate; $data["website_type_id"] = $postData->website_type_id; $data["website_type"] = $postData->website_type; $data["group_id"] = $subject->group_id; $data["group"] = $subject->group; $data["url"] = substr($postData->root_url, 0, -1) . "" . $postData->url; $data["page_id"] = $postData->page_id; $data["subject_id"] = $subject->subject_id; $data["subject_name"] = $subject->subject_name; $data["mood"] = $mood; $data["mood_by"] = 'system'; $thothconnect_db->insert("website_c" . $subject->client_id, $data); $post->insert_post_comment($postData->page_id, $subject->client_id, $thothconnect_db); } } else { if ($post->type == "tweet" || $post->type == "retweet") { $postData = $post->get_post_twitter($post->id); if ($postData != null) { $data = array(); $data["post_id"] = $postData->post_id; $data["post_date"] = $postData->post_date; $data["body"] = $postData->body; $data["type"] = $postData->type; $data["author_id"] = $postData->author_id; $data["author"] = $postData->author; $data["group_id"] = $subject->group_id; $data["group"] = $subject->group; $data["tweet_id"] = $postData->tweet_id; $data["subject_id"] = $subject->subject_id; $data["subject_name"] = $subject->subject_name; $data["mood"] = $mood; $data["mood_by"] = 'system'; $thothconnect_db->insert("twitter_c" . $subject->client_id, $data); } } else { if ($post->type == "fb_post" || $post->type == "fb_comment") { $postData = $post->get_post_facebook($post->id); if ($postData != null) { $data = array(); $data["post_id"] = $postData->post_id; $data["post_date"] = $postData->post_date; $data["body"] = $postData->body; $data["type"] = $postData->type; $data["author_id"] = $postData->author_id; $data["author"] = $postData->author; $data["group_id"] = $subject->group_id; $data["group"] = $subject->group; $data["facebook_page_id"] = $postData->facebook_page_id; $data["facebook_page_name"] = $postData->facebook_page_name; $data["subject_id"] = $subject->subject_id; $data["subject_name"] = $subject->subject_name; $data["facebook_id"] = $postData->facebook_id; $data["parent_post_id"] = $postData->parent_post_id; $data["likes"] = $postData->likes; $data["shares"] = $postData->shares; $data["mood"] = $mood; $data["mood_by"] = 'system'; $thothconnect_db->insert("facebook_c" . $subject->client_id, $data); } } } } /* $data = array( 'post_id'=> $post->id, 'subject_id' => $subject_id , 'matching_date' => null, 'sentiment' => $mood, 'by' => 'system', 'system_correct' => $mood, 'system_correct_date' => mdate('%Y-%m-%d %H:%i',time()) ); $this->db->insert('matchs',$data); */ //--------------------------------------- } } } } } // flag subject as update.. $data = array('matching_status' => 'update', 'latest_matching' => mdate('%Y-%m-%d %H:%i:%s', time()), 'from' => mdate('%Y-%m-%d %H:%i:%s', $from), 'to' => mdate('%Y-%m-%d %H:%i:%s', $to)); $this->db->update('subject', $data, array('id' => $subject_id)); }
function author() { $this->parser->data['active_menu_portal'] = TRUE; $data = array("page_title" => "Welcome!", "params" => array()); $author = $this->input->get('author_name'); if (empty($author)) { redirect('/portal/'); } $data['params']['author_name'] = $author; $page = $this->input->get('page'); if ($page != null && preg_match('/^[0-9]+$/i', $page)) { $page = str_replace("page", "", strtolower($page)); $page--; } else { $page = 0; } $data['params']['page'] = $page; $date_from = $this->input->get("date_from"); $date_to = $this->input->get("date_to"); if ($date_from != NULL) { $date_from = strtolower($date_from); switch ($date_from) { case "today": case "yesterday": $data['date_selected'] = $date_from; $data['params']['date_from'] = $date_from; $date_to = new DateTime($date_from); $date_from = clone $date_to; break; case "7days": $data['date_selected'] = $date_from; $data['params']['date_from'] = $date_from; $date_to = new DateTime("yesterday"); $date_from = clone $date_to; $date_from->modify('-6 days'); break; case "30days": $data['date_selected'] = $date_from; $data['params']['date_from'] = $date_from; $date_to = new DateTime("yesterday"); $date_from = clone $date_to; $date_from->modify('-29 days'); break; default: if ($date_to != NULL) { if (preg_match("/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}\$/", $date_from) && preg_match("/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}\$/", $date_to)) { $data['date_selected'] = "custom"; $data['date_from_input'] = $date_from; $data['date_to_input'] = $date_to; $data['params']['date_from'] = $date_from; $data['params']['date_to'] = $date_to; $date_from = DateTime::createFromFormat("m-d-Y", $date_from); $date_to = DateTime::createFromFormat("m-d-Y", $date_to); break; } } $data['date_selected'] = ""; $date_to = NULL; break; } } if ($date_to == NULL) { $date_to = new DateTime(); $date_from = clone $date_to; $date_from->modify('-29 days'); } $data['date_from'] = $date_from->format("M j, Y"); $data['date_to'] = $date_to->format("M j, Y"); $data['date_from_ymd'] = $date_from->format('Y-m-d'); $data['date_to_ymd'] = $date_to->format('Y-m-d'); $this->load->model("Post_model", "post"); $this->user = $this->ion_auth->user()->row(); if ($this->ion_auth->is_manager()) { $data["is_admin"] = TRUE; } $company_id = array($this->user_company->company_id, $author); $rows = Post_model::get_posts($company_id, $date_to, $date_from, TRUE, TRUE, $page); $day_diff = $date_to->diff($date_from)->days; $rows_prev = Post_model::get_posts($company_id, $date_from->modify('-1 days')->format("Y-m-d"), $date_from->modify("-" . $day_diff . " days")->format("Y-m-d"), FALSE, FALSE); $rows_prev = array_column((array) $rows_prev, 'total_pageviews', 'url'); $data['rows'] = array(); foreach ($rows as $index => $row) { $prev = isset($rows_prev[$row->url]) ? $rows_prev[$row->url] : 0; if ($prev && $row->total_pageviews - $prev) { $prev = round(100 * ($row->total_pageviews - $prev) / $prev, 1); } $ar = array("post_id" => $row->post_id, "n" => $page * 10 + $index + 1, "image" => $row->image, "url" => $row->url, "title" => $row->title, "sessions" => $row->total_pageviews, "date_published" => date('M j, Y', strtotime($row->date_published)), "up_down_text" => $prev ? $prev . "%" : "", 'author' => $row->author); if ($prev > 0) { $ar["up_arrow"] = TRUE; } elseif ($prev < 0) { $ar["down_arrow"] = TRUE; } $data['rows'][] = $ar; } $rows = $this->db->from('post_stats')->select_max('date_updated')->get()->result_array(); $data['last_updated'] = $rows[0]['date_updated']; //Total Stats $count = $this->db->from('posts')->where('company_id', $this->user_company->company_id)->where('date_published >=', $data['date_from_ymd'])->where('date_published <=', $data['date_to_ymd'])->count_all_results(); $count_all = $this->db->from('posts')->where('company_id', $this->user_company->company_id)->count_all_results(); $data['totals'] = array('pageviews' => 0, 'sessions' => 0, 'engaged_minutes' => 0, 'posts' => number_format($count), 'all_posts' => number_format($count_all)); $this->load->library("google_php_client", $this->user_company); $rows = $this->google_php_client->get_profile_stats($data['date_to_ymd'], $data['date_from_ymd']); if ($rows) { $data['totals']['sessions'] = number_format($rows[0][0]); $data['totals']['engaged_minutes'] = number_format($rows[0][0] * $rows[0][1] / 60); $data['totals']['pageviews'] = number_format($rows[0][2]); } $query = $data['params']; $data['prev_link'] = $page == 0 ? "" : "/portal/author/?" . http_build_query($query); $query['page']++; $data['portal_link'] = http_build_query($query); $query['page']++; $data['next_link'] = "/portal/author/?" . http_build_query($query); unset($query['page']); $data['date_link'] = http_build_query($query); $this->parser->parse("portal/home", $data); }
public function run($subject_id, $clean = true, $query_offset = 0, $from, $to) { $this->load->helper('sphinxapi'); $this->load->helper('mood'); // skip if matching_status is "matching" $matching_status = $this->custom_model->get_value('subject', 'matching_status', $subject_id); if ($matching_status == 'matching') { echo "subject is matching"; return false; } // flag subject as matching.. do other bot runs this queue. $this->db->update('subject', array('matching_status' => 'matching'), array('id' => $subject_id)); // clear all match record for this subject if ($clean) { $this->db->delete('matchs', array('subject_id' => $subject_id)); } // // begin re-matching this subject // // get search string from subject_id $query = $this->custom_model->get_value('subject', 'query', $subject_id); // sphinx init $cl = new SphinxClient(); $q = $query; $sql = ""; $mode = SPH_MATCH_EXTENDED; $host = "192.168.1.102"; $port = 9312; $index = "*"; $groupby = ""; $groupsort = "@group desc"; $filter = "group_id"; $filtervals = array(); $distinct = ""; $sortby = "@id ASC"; $sortexpr = ""; $offset = $query_offset; $limit = 1000000; $ranker = SPH_RANK_PROXIMITY_BM25; $select = ""; echo 'limit=' . $limit . ' offset=' . $offset . PHP_EOL; //Extract subject keyword from search string $keywords = get_keywords($q); //////////// // do query //////////// $cl->SetServer($host, $port); $cl->SetConnectTimeout(1); $cl->SetArrayResult(true); $cl->SetWeights(array(100, 1)); $cl->SetMatchMode($mode); // if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals ); // if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort ); if ($sortby) { $cl->SetSortMode(SPH_SORT_EXTENDED, $sortby); } // if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr ); if ($distinct) { $cl->SetGroupDistinct($distinct); } if ($select) { $cl->SetSelect($select); } if ($limit) { $cl->SetLimits(0, $limit, $limit > 1000000 ? $limit : 1000000); } $cl->SetRankingMode($ranker); $res = $cl->Query($q, $index); //////////// // do Insert to DB //////////// // Current matching $current_matching = array(); $query_matchs = $this->db->get_where('matchs', array('subject_id' => $subject_id)); if ($query_matchs->num_rows() > 0) { echo PHP_EOL . 'currents matching :' . $query_matchs->num_rows(); foreach ($query_matchs->result() as $match) { $current_matching[] = $match->post_id; } } // set matching date range from-to $from = strtotime($from); $to = strtotime($to); // Search and Update if ($res === false) { echo "Query failed: " . $cl->GetLastError() . ".\n"; } else { if ($cl->GetLastWarning()) { echo "WARNING: " . $cl->GetLastWarning() . "\n\n"; } echo "Query '{$q}' \nretrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n"; if ($res['total'] == 0) { echo "no result<br/>\n"; } else { if ($res['total'] > $limit + $offset) { $this->run($subject_id, $limit + $offset); } else { echo "Updating..."; foreach ($res["matches"] as $k => $docinfo) { // echo '('.$k.')'.$docinfo["id"]." "; // Reset PHP Timeout to 1min // if found in $current_matching then skip if (in_array($docinfo["id"], $current_matching)) { continue; } else { // else insert new match set_time_limit(60); $post = new Post_model(); $post->init($docinfo["id"]); // if post_date is our of range then skip $post_date = strtotime($post->post_date); if ($post_date < $from || $post_date > $to) { continue; } $mood = get_mood($post->body, $keywords); $data = array('post_id' => $post->id, 'subject_id' => $subject_id, 'matching_date' => null, 'sentiment' => $mood, 'by' => 'system', 'system_correct' => $mood, 'system_correct_date' => mdate('%Y-%m-%d %H:%i', time())); $this->db->insert('matchs', $data); } } } } } // flag subject as update.. $data = array('matching_status' => 'update', 'latest_matching' => mdate('%Y-%m-%d %H:%i:%s', time()), 'from' => mdate('%Y-%m-%d %H:%i:%s', $from), 'to' => mdate('%Y-%m-%d %H:%i:%s', $to), 'bot_id' => 0); $this->db->update('subject', $data, array('id' => $subject_id)); }
function filter($type, $keywords) { foreach ($keywords as $k => $v) { if ($k == 0) { $this->db->like('title', $v); $this->db->or_like('body', $v); } else { $this->db->or_like('title', $v); $this->db->or_like('body', $v); } } $query = $this->db->get('post'); $posts = array(); if ($query->num_rows() > 0) { foreach ($query->result() as $row) { $post = new Post_model(); $post->init($row->id); $posts = $post; } return $posts; } else { return false; } }
function _get_latest($start_date, $debug = FALSE) { $this->load->library("google_php_client"); $end_date = $start_date; $start_time = microtime(TRUE); $companies = $this->company->get_all(); foreach ($companies as $company) { if ($company->ga_token && $company->view_id) { $posts = $this->post->where('company_id', $company->company_id)->as_array()->get_all(); $posts = array_column($posts, 'post_id', 'url'); $this->google_php_client->set_user_company($company); $rows = $this->google_php_client->get_posts_stats($start_date, $end_date); foreach ($rows as $row) { $url = $row[0]; if (array_key_exists($url, $posts)) { $post_id = $posts[$url]; } else { if ($debug) { echo "Post is not found: adding " . $url . PHP_EOL; } $data = Post_model::get_post($url); $data['company_id'] = $company->company_id; $post_id = $this->post->insert($data); } $this->db->query("INSERT INTO post_stats VALUES (?, ?, ?, ?, NOW()) ON DUPLICATE KEY UPDATE sessions = ?, pageviews = ?, date_updated = NOW()", array($post_id, $start_date, $row[1], $row[2], $row[1], $row[2])); if ($debug) { echo "Updated post_id #" . $post_id . " for " . $start_date . " (" . $row[1] . ", " . $row[2] . ")" . PHP_EOL; } } usleep(500000); } elseif ($debug) { echo "Skipping company ID #" . $company->company_id . " - no GA data" . PHP_EOL; } } if ($debug) { echo 'Done: ' . round(microtime(TRUE) - $start_time, 2) . " secs, " . $this->google_php_client->queries . " queries." . PHP_EOL . PHP_EOL; } }
public function preupload() { $u = new Post_model($this->template, $this->router->query_string); $u->preupload($this->router->id); $this->template->render("preupload_result", "json"); }