Exemplo n.º 1
0
 /**
 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.
     $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();
     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 all active Layers (KMZ/KML)
     $layers = array();
     foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) {
         $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file);
     }
     $this->template->content->layers = $layers;
     // Get all active Shares
     $shares = array();
     foreach (ORM::factory('sharing')->where('sharing_active', 1)->where('sharing_type', 1)->find_all() as $share) {
         $shares[$share->id] = array($share->sharing_site_name, $share->sharing_color);
     }
     $this->template->content->shares = $shares;
     // 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');
     // 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.
     // 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');
     $sql = "\tSELECT \r\n\t\t\t\t\t\t\t\t\t\t\t\tf.id as id,\r\n\t\t\t\t\t\t\t\t\t\t\t\titem_title,\r\n\t\t\t\t\t\t\t\t\t\t\t\titem_description,\r\n\t\t\t\t\t\t\t\t\t\t\t\titem_link,\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\titem_date, \r\n\t\t\t\t\t\t\t\t\t\t \t\ta.weight as weight,\r\n\t\t\t\t\t\t\t\t\t\t \t\ta.feed_name as item_source,\r\n\t\t\t\t\t\t\t\t\t\t \t\ta.category_id as category_id,\r\n\t\t\t\t\t\t\t\t\t\t\t\t'feed_item' as tablename\r\n\t\t\t\t\t\t\t\t\t\t\t\tFROM feed_item f \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t INNER JOIN feed a ON f.feed_id = a.id \r\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE submited_to_ushahidi = 0 AND " . $category_filter . $veracity_filter;
     if ($category_id == 11 || $category_id == 10 || $category_id == 2) {
         $sql = " \tSELECT \r\n\t\t\t\t\t\t\t\t\t\t\t m.id as id\r\n\t\t\t\t\t\t\t\t\t\t\t,m.message as item_title,\r\n\t\t\t\t\t\t\t\t\t\t\t m.message as item_description,";
         //ISNULL(m.message,'') + ' ' + ISNULL (message_detail,'') as item_description,
         $sql .= " CASE r.service_id \r\n\t\t\t \t\t\t\t\t\t\t\t\tWHEN 3 THEN CONCAT('http://twitter.com/',m.message_from,'/statuses/',m.service_messageid)\r\n\t\t\t \t\t\t\t\t\t\t\t\tELSE '#'\r\n\t\t\t \t\t\t\t\t\t\t\t\tEND as item_link,\r\n\t\t\t\t\t\t\t\t\t\t\t m.message_date as item_date,\r\n\t\t\t\t\t\t\t\t\t\t\t r.weight as weight,\r\n\t\t\t\t\t\t\t\t\t\t\t m.message_from as item_source,\r\n\t\t\t\t\t\t\t\t\t\t\t CASE r.service_id  WHEN 1 THEN 2 WHEN 2 THEN 10 ELSE 11 END as category_id,\r\n\t\t\t\t\t\t\t\t\t\t\t 'message' as tablename\r\n\t\t\t\t\t\t\t\t\t\t\tFROM message m  \r\n\t\t\t\t\t\t\t\t\t\t\t\t\tINNER JOIN reporter r ON r.id = m.reporter_id \r\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE  submited_to_ushahidi = 0 AND " . $category_filter2 . $veracity_filter;
     }
     // echo $sql; exit(0);
     $sql .= " ORDER BY item_date desc ";
     $db = new Database();
     if ($category_id == 11 || $category_id == 10 || $category_id == 2) {
         $countersql = " SELECT count(m.id)as Total FROM message m INNER JOIN reporter r ON r.id = m.reporter_id AND " . $category_filter2 . $veracity_filter;
         $Feedcounts = $db->query($countersql);
     } else {
         $Feedcounts = $db->query("select count(f.id)as Total FROM feed_item f INNER JOIN feed a ON f.feed_id = a.id  WHERE " . $category_filter . $veracity_filter);
     }
     $pagination = new Pagination(array('base_url' => '/main/index/category/' . $category_id, 'uri_segment' => 'page', 'items_per_page' => (int) $numItems_per_page, 'style' => 'digg', 'total_items' => $Feedcounts[0]->Total));
     $Feedlist = $db->query($sql . " Limit " . $numItems_per_page * ($page_no - 1) . " , " . $numItems_per_page);
     // Get RSS News Feeds
     $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 = $Feedcounts->count();
     $feed_summary_sql = " SELECT f.feed_name as feed_name ,f.feed_url as feed_url ,count(fi.id) as total \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `feed` f ,feed_item fi \r\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 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION \r\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 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `feed` f ,feed_item fi \r\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 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION \r\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 \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfeed_url ,count(m.id) as total\r\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 ";
     $this->template->content->feedsummary = $db->query($feed_summary_sql);
     $AnalyicQuery = " SELECT 'Submitted' as title,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed_item WHERE  submited_to_ushahidi = 1)+\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM message WHERE  submited_to_ushahidi = 1) as count,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed_item )+(select count(*) FROM message ) as total\r\n\t\t\t\t\t\t\t\t\t\tUNION\r\n\t\t\t\t\t\t\t\t\t\tSELECT 'Sources Trusted' as title,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed WHERE  weight > 99)+\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM reporter WHERE  weight > 99) as count,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\r\n\t\t\t\t\t\t\t\t\t\tUNION\r\n\t\t\t\t\t\t\t\t\t\tSELECT 'tags added' as title,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM tags WHERE  tablename IN ('feed_item','message')) as count,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\r\n\t\t\t\t\t\t\t\t\t\tUNION\r\n\t\t\t\t\t\t\t\t\t\tSELECT 'tags approved' as title,\r\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,\r\n\t\t\t\t\t\t\t\t\t\t(select count(*) FROM feed )+(select count(*) FROM reporter ) as total\r\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;
 }
Exemplo n.º 2
0
 /**
 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;
 }