Пример #1
0
 function eventsearch($search = '')
 {
     if (!CheckPermissions('public')) {
         return;
     }
     if (array_key_exists('search', $_GET)) {
         redirect('test/james/eventsearch/' . urlencode($_GET['search']));
     }
     // Load the libraries
     $this->load->library('calendar_backend');
     $this->load->library('calendar_source_my_calendar');
     $this->load->library('facebook');
     $data = array('target' => $this->uri->uri_string(), 'search' => $search);
     if (!empty($search)) {
         $source = new CalendarSourceMyCalendar();
         // Use the search phrase
         $source->SetSearchPhrase($search);
         // Set the groups to get events from
         /*
         	groups:
         	'owned'      => TRUE,
         	'subscribed' => TRUE,
         	'all'        => FALSE,
         	
         	'private'    => TRUE,
         	'active'     => TRUE,
         	'inactive'   => TRUE,
         	
         	'hide'       => FALSE,
         	'show'       => TRUE,
         	'rsvp'       => TRUE,
         	
         	'event'      => TRUE,
         	'todo'       => FALSE,
         */
         $source->EnableGroup('all');
         $source->DisableGroup('subscribed');
         // (subset of all)
         $source->DisableGroup('owned');
         // (subset of all)
         $source->EnableGroup('hide');
         // Show events hidden by user
         $source->EnableGroup('todo');
         // Enable todo items
         // Set the date range if applicable
         //$source->SetRange(strtotime('-1month'), NULL))
         //$source->SetTodoRange(strtotime('-1month'), NULL))
         // Get the actual events from the sources
         $calendar_data = new CalendarData();
         $source->FetchEvents($calendar_data);
         // Do whatever with the data
         // $calendar_data->GetEvents() are the events
         // theres a couple of others for occurrences + organisations
         $data['results'] = $calendar_data->GetEvents();
     }
     $this->main_frame->SetContentSimple('test/james-eventsearch', $data);
     $this->main_frame->Load();
 }
    /**
     * @brief Do a small search, reply with max 16 results
     * @param $string string Search string entered.
     */
    function ajax($string)
    {
        $result = array();
        $sql = <<<QUERY
\t\tSELECT articles.article_id AS id,
\t\t\tarticle_content_heading AS title
\t\t\tUNIX_TIMESTAMP(articles.article_publish_date) AS date,
\t\t\tcontent_types.content_type_codename AS type_codename,
\t\t\tparent_type.content_type_codename AS parent_codename,
\t\t\tIF (content_types.content_type_parent_content_type_id IS NOT NULL,
\t\t\t\tparent_type.content_type_name,
\t\t\t\tcontent_types.content_type_name) AS category,
\t\t\tMATCH(article_content_heading, article_content_subheading, article_contents.article_content_blurb,article_content_wikitext_cache)
\t\t\t\tAGAINST(?) as score
\t\tFROM articles, article_contents, content_types
\t\tLEFT JOIN content_types AS parent_type
\t\t\tON content_types.content_type_parent_content_type_id = parent_type.content_type_id
\t\tWHERE
\t\t\tarticles.article_content_type_id = content_types.content_type_id
\t\t\tAND articles.article_pulled = 0 AND articles.article_publish_date < CURRENT_TIMESTAMP()
\t\t\tAND articles.article_deleted = 0 AND articles.article_live_content_id IS NOT NULL
\t\t\tAND articles.article_live_content_id = article_contents.article_content_id
\t\t\tAND articles.article_id = article_contents.article_content_article_id
\t\t\tAND content_types.content_type_archive = 1
\t\t\tAND MATCH(article_content_heading, article_content_subheading, article_contents.article_content_blurb,article_content_wikitext_cache)
\t\tAGAINST(?)
\t\tAND (category = 'uninews'
\t\t\tOR category = 'features'
\t\t\tOR category = 'lifestyle'
\t\t\tOR category = 'food'
\t\t\tOR category = 'drink'
\t\t\tOR category = 'arts'
\t\t\tOR category = 'sport'
\t\t\tOR category = 'blogs'
\t\tORDER BY score DESC LIMIT 4
QUERY;
        $result['articles'] = $this->db->query($sql, array($string, $string));
        curl_init('http://yorkipedia.theyorker.co.uk/api.php?action=opensearch&search=' . urlencode(utf8_decode($filter)));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0.2);
        //possibly not valid, manual says integer only, but we wil try...
        $wikiResult = curl_exec($curl);
        $result['wiki'] = array();
        if ($wikiResult or $wikiResult != 1) {
            //example result ["Tet",["Tet","Tet-off","Tet-on","TetR","Tet 1969","Tet Corporation"]]
            preg_match_all("/[^.|\"\\[\\]]*/", $wikiResult, $wikiResult);
            foreach ($wikiResult as $page) {
                if (!empty($page) & $page != ',') {
                    $result['wiki'][] = $page;
                }
            }
        }
        // This query is possibly even slower than the one above, because It has to match against
        // two separate indexes!
        $sql = <<<QUERY
\t\t\tSELECT
\t\t\t\torganisations.organisation_name AS title,
\t\t\t\torganisations.organisation_directory_entry_name AS link,
\t\t\t\tUNIX_TIMESTAMP(organisation_timestamp) AS date,
\t\t\t\t((MATCH(organisations.organisation_name) AGAINST(?))+
\t\t\t\t\t(MATCH(organisation_contents.organisation_content_description) AGAINST(?))) AS score
\t\t\tFROM organisations
\t\t\tINNER JOIN organisation_types
\t\t\tON organisations.organisation_organisation_type_id=organisation_types.organisation_type_id
\t\t\tLEFT JOIN organisation_contents
\t\t\tON organisations.organisation_live_content_id = organisation_contents.organisation_content_id
\t\t\tINNER JOIN entities
\t\t\tON entities.entity_id = organisations.organisation_entity_id
\t\t\tAND entities.entity_deleted = 0
\t\t\tWHERE organisations.organisation_directory_entry_name IS NOT NULL
\t\t\t\tAND organisation_types.organisation_type_directory=1
\t\t\t\tAND organisations.organisation_show_in_directory=1
\t\t\t\tAND organisations.organisation_needs_approval=0
\t\t\t\tAND (MATCH (organisations.organisation_name) AGAINST (?)
\t\t\t\t OR MATCH (organisation_contents.organisation_content_description) AGAINST (?))
\t\t\tORDER BY score DESC LIMIT 4
QUERY;
        $result['directory'] = $this->db->query($sql, array($string, $string, $string, $string));
        $this->load->library('calendar_backend');
        $this->load->library('calendar_source_my_calendar');
        $this->load->library('facebook');
        $source = new CalendarSourceMyCalendar();
        // Use the search phrase
        $source->SetSearchPhrase($string);
        $source->EnableGroup('all');
        $calendar_data = new CalendarData();
        $source->FetchEvents($calendar_data);
        $result['events'] = $calendar_data->GetEvents();
        return $result;
    }