/** This is the index function called by default. */ public function index($categoryname = "", $category_id = 0, $page, $page_no) { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); $this->template->content->auth = null; if (isset($_SESSION['auth_user'])) { $this->template->content->auth = $_SESSION['auth_user']; } //try getting new feeds and cache them to the database. /** ######### Apala required changes ########## These operations/functions should go through the API BEGIN line 569 - 609 */ $this->get_new_feeds($category_id); $messages = new Messages_Controller(); $messages->auto_render = false; if ($category_id == 11) { $messages->load_tweets(); } // Get all active top level categories $parent_categories = array(); /** ######### Apala required changes ########## DB Call below. ::factory('category')*/ foreach (ORM::factory('category')->where('category_visible', '1')->where('parent_id', '0')->find_all() as $category) { // Get The Children $children = array(); foreach ($category->children as $child) { $children[$child->id] = array($child->category_title, $child->category_color); } // Put it all together $parent_categories[$category->id] = array($category->category_title, $category->category_color, $children); } $this->template->content->categories = $parent_categories; // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('settings.site_email'); /** ######### Apala required changes ########## These settings should go through the API BEGIN line 671 - 684 */ // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; //Cache items to the database. /** ######### Apala required changes ########## These variables and sql statements should go through the API BEGIN line 691 - 812 */ // Filter By Category $categoryYes = isset($category_id) && !empty($category_id) && !$category_id == 0; $category_filter = $categoryYes ? " a.category_id = " . $category_id . " " : " 1=1 "; $category_filter2 = " r.service_id = " . ($category_id == 2 ? " 1 " : ($category_id == 10 ? " 2 " : " 3 ")); $veracity_filter = ""; if (isset($_SESSION['veracity_min']) && isset($_SESSION['veracity_max'])) { $veracity_filter = "\tAND weight >=\t" . $_SESSION['veracity_min'] . " AND weight <= " . $_SESSION['veracity_max'] . " "; } else { $veracity_filter = "\tAND weight >=\t0 AND weight <= 100 "; } $numItems_per_page = Kohana::config('settings.items_per_page'); $coreFolder = DOCROOT . "/../Core/"; $coreSetupFile = $coreFolder . "Setup.php"; include_once $coreSetupFile; if (isset($_SESSION['veracity_min']) && isset($_SESSION['veracity_max'])) { $workflowData = json_encode(array("state" => "new_content", "pagestart" => ($page_no - 1) * $numItems_per_page, "pagesize" => $numItems_per_page, "minVeracity" => $_SESSION['veracity_min'], "maxVeracity" => $_SESSION['veracity_max'])); $workflow = new Swiftriver\Core\Workflows\ContentServices\GetPagedContentByStateAndSourceVeracity(); } else { $workflowData = json_encode(array("state" => "new_content", "pagestart" => ($page_no - 1) * $numItems_per_page, "pagesize" => $numItems_per_page)); $workflow = new \Swiftriver\Core\Workflows\ContentServices\GetPagedContentByState(); } $json = $workflow->RunWorkflow($workflowData, "swiftriver_apala"); $return = json_decode($json); /* APALA - removed in favor of calls to the file $docroot = DOCROOT; $service = new ServiceWrapper("http://local.apala.com/Core/ServiceAPI/ContentServices/GetPagedContentByState.php"); $params = json_encode(array("state" => "new_content", "pagestart" => ($page_no-1)*$numItems_per_page, "pagesize" => $numItems_per_page)); $json = $service->MakePOSTRequest(array("key" => "swiftriver_apala", "data" => $params), 5); //echo($json); $return = json_decode($json); */ $Feedlist = array(); if (isset($return->contentitems)) { foreach ($return->contentitems as $content) { $feed = new GenericClass(); $feed->item_source = $content->source->name; // $content->source->id; $feed->sourceid = $content->source->id; $feed->category_id = 5; //REMEBER to remove this hard coded category ID. $feed->weight = $content->source->score ? $content->source->score : "not yet rated"; $feed->id = $content->id; // echo $content->state ;echo "<br/>"; $feed->item_date = date("c", $content->date); $feed->item_link = $content->link; //echo $content->text[0]->languageCode;echo "<br/>"; $feed->item_title = $content->text[0]->title; $feed->item_description = $content->text[0]->text[0]; $feed->tags = $content->tags; $Feedlist[] = $feed; } } $pagination = new Pagination(array('base_url' => '/main/index/category/5', 'uri_segment' => 'page', 'items_per_page' => (int) $numItems_per_page, 'style' => 'digg', 'total_items' => isset($return->totalcount) ? $return->totalcount : 0)); $Feedlist = $this->template->content->feeds = $Feedlist; $this->template->content->current_page = $page_no; // Get Summary // XXX: Might need to replace magic no. 8 with a constant $this->template->content->feedcounts = isset($return->totalcount) ? $return->totalcount : 0; $feed_summary_sql = " SELECT f.feed_name as feed_name ,f.feed_url as feed_url ,count(fi.id) as total \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `feed` f ,feed_item fi \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE fi.feed_id = f.id AND f.category_id NOT IN (1,11) AND submited_to_ushahidi = 0 GROUP BY f.feed_name \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT f.feed_name as feed_name ,concat('http://twitter.com/statuses/user_timeline/',f.feed_url,'.rss') as feed_url,count(fi.id) as total \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `feed` f ,feed_item fi \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE fi.feed_id = f.id AND f.category_id IN (1) AND submited_to_ushahidi = 0 GROUP BY f.feed_name \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT twitter_hashtags as feed_name, concat('http://twitter.com/search?q=', REPLACE(replace(twitter_hashtags,'#',''),',',' ' )) as \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfeed_url ,count(m.id) as total\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM settings s , message m WHERE m.submited_to_ushahidi = 0 Group BY feed_name "; $db = new Database(); $this->template->content->feedsummary = $db->query($feed_summary_sql); $AnalyicQuery = " SELECT 'Submitted' as title,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed_item WHERE submited_to_ushahidi = 1)+\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM message WHERE submited_to_ushahidi = 1) as count,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed_item )+(select count(*) FROM message ) as total\n\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\tSELECT 'Sources Trusted' as title,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed WHERE weight > 99)+\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM reporter WHERE weight > 99) as count,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\n\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\tSELECT 'tags added' as title,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM tags WHERE tablename IN ('feed_item','message')) as count,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\n\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\tSELECT 'tags approved' as title,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM tags WHERE tablename IN ('feed_item','message') AND correct_yn = 1) as count,\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\n\t\t\t\t\t\t\t\t\t\t "; $this->template->content->analyticSummary = $db->query($AnalyicQuery); // echo $AnalyicQuery ; // exit(0); $this->template->content->pagination = $pagination; $this->template->content->selected_category = $category_id; $feedjs = new View('feed_functions_js'); // Pack the javascript using the javascriptpacker helper $this->template->header->js2 = $feedjs; //feed item content. $feed_item_template = new View('feed_item'); $this->template->content->feed_item_list = $feed_item_template; $this->template->content->feed_item_list->feeds = $Feedlist; }
<?php namespace Swiftriver\Core\ServiceAPI\ChannelProcessingJobServices; header('Content-type: application/json'); //Check for the existance of the unique Swift instance Key if (!isset($_POST["key"])) { //If not found then return a JSON error echo '{"error":"The request to this service did not contain the required post data \'key\'"}'; die; } elseif (!isset($_POST["data"])) { //if not present then return a JSON error echo '{"error":"The request to this service did not contain the required post data \'data\'"}'; die; } else { //include the setup file include_once dirname(__FILE__) . "/../../Setup.php"; //create a new workflow instance $workflow = new \Swiftriver\Core\Workflows\ContentServices\GetPagedContentByState(); //Check that the key supplied works with this core instance if (!$workflow->CheckKey($_POST["key"])) { //If not then return an error in JSON echo '{"error":"The key you supplied is not registered with this instance of the Swiftriver Core"}'; die; } //If all the key is ok, then run the workflow $json = $workflow->RunWorkflow($_POST["data"], $_POST["key"]); //Return the JSON result echo $json; die; }