Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/photo/components/search.php
Строк: 111
<?php
defined
('_VALID') or die('Restricted Access!');
defined('_SEARCH') or die('Restricted Access!');
class 
VComponent_photo_search extends VModule_photo
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
$request    VUri::query();
        if (isset(
$request['2']) && $request['2']) {
            
VF::redirect(BASE_URL.'/search/photo/?s='.str_replace('-''+'$request['2']), 301);
        }
        
        
$filter        VF::factory('filter');
        
$query        = (isset($_GET['s'])) ? $filter->clean(trim($_GET['s'])) : null;
        
        
$orders    = array(
            
'relevance'        => __('relevant'),
            
'recent'        => __('recent'),
            
'popular'        => __('popular'),
            
'rated'            => __('rated')
        );        
        
$order        = (isset($_GET['o']) && isset($orders[trim($_GET['o'])])) ? trim($_GET['o']) : 'relevance';
        
        
$timelines    = array(
            
'today'        => __('todays'),
            
'yesterday'    => __('yesterdays'),
            
'week'        => __('this-weeks'),
            
'month'        => __('this-months'),
            
'year'        => __('this-years')
        );
        
$timeline    = (isset($_GET['t']) && isset($timelines[trim($_GET['t'])])) ? trim($_GET['t']) : 'all';
        
        
$category    = (isset($_GET['c'])) ? (int) trim($_GET['c']) : 'all';
        
$page        = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
        
        if (
$category != 'all' && $category !== 0) {
            
$this->db->query("
                SELECT cat_id, name
                FROM #__photo_categories
                WHERE cat_id = "
.$category."
                AND status = '1'
                LIMIT 1
            "
);
            
            if (!
$this->db->affected_rows()) {
                
VModule::load('404'true);
            }
            
            
$name                 $this->db->fetch_field('name');
            
$this->tpl->name    $name;
        }
        
        
VLanguage::load('frontend.photo');
    
        if (
$query != '') {
            
// lets limit this to 10 words
            
$regex    = (utf8_is_ascii($query)) ? '/[^A-Za-z0-9, ]+/' '/[^pLpNpZ,s]+/u';
            
$query    preg_replace($regex' '$query);
            
$query     preg_replace('/ss+/'' '$query);
            
$query    VText::truncate_words($query20'');
            
$query    utf8_strtolower(utf8_trim($query));
            
            
$this->set_popular_search($query);
            
$this->tpl->searches    $this->get_popular_searches($query);
            
            
$this->search_mysql($query$order$timeline$category$page);
        }
        
        
        
$time_name        = ($timeline != 'all') ? $timelines[$timeline].' ' '';
        
$order_name        $orders[$order].' ';
        
$category_name    = ($category != 'all') ? $name.' ' '';
        
$page_add        = ($page 1) ? ' - '.__('page').' '.$page '';
        
        
$this->tpl->menu        'photo';
        
        
$this->tpl->title        = ($query) ? $time_name.$order_name.$category_name.__('photo-results').': "'.$query.'"' null;
        
$this->tpl->meta_title    __('search-meta-title', array($time_name.$order_name.$category_name$query.$page_addVF::cfg_item('site_name')));
        
        
$this->tpl->canonical   BASE_URL.'/search/photo/?s='.$query;
        
$this->tpl->canonicalm  MOBILE_URL.'/search/photo/?s='.$query;        

        
$this->tpl->query        $query;
        
$this->tpl->order        $order;
        
$this->tpl->timeline    $timeline;
        
$this->tpl->category    $category;
        
        
$this->tpl->categories    $this->get_photo_categories();
        
        
$this->tpl->load(array('header''photo_search''footer'));
        
$this->tpl->display();
    }
    
    private function 
set_popular_search($query)
    {
        
$this->db->query("
            SELECT hits
            FROM #__photo_search
            WHERE keyword = '"
.$this->db->escape($query)."'
            LIMIT 1
        "
);
        
        if (
$this->db->affected_rows()) {
            
$this->db->query("
                UPDATE #__photo_search
                SET hits = hits+1
                WHERE keyword = '"
.$this->db->escape($query)."'
                LIMIT 1
            "
);
        } else {
            
$this->db->query("
                INSERT INTO #__photo_search
                SET keyword = '"
.$this->db->escape($query)."',
                    hits = 1
            "
);            
        }
    }
    
    private function 
get_popular_searches($query)
    {
        
$this->db->query("
            SELECT keyword
            FROM #__photo_search
            WHERE keyword LIKE '"
.$this->db->escape($query)."%'
            AND keyword != '"
.$this->db->escape($query)."'
            ORDER BY hits DESC
            LIMIT 10
        "
);
        
        return 
$this->db->fetch_rows();
    }
    
    private function 
search_mysql($query$order$timeline$duration$category 0$page 1)
    {
        
$query        str_replace('+'' '$query);
        
$sql_add    null;
        if (
$timeline == 'today') {
              
$start_time  strtotime('today');
            
$end_time    $start_time+86400;
            
$sql_add  .= " AND a.add_time > ".$start_time." AND a.add_time < ".$end_time;          
        } elseif (
$timeline == 'yesterday') {
            
$start_time  strtotime('yesterday');
            
$end_time    $start_time+86400;
            
$sql_add  .= " AND a.add_time > ".$start_time." AND a.add_time < ".$end_time;          
        } elseif (
$timeline == 'week') {
            
$now         time();
            
$start_time  = (date('w'$now) === 1) ? strtotime('today'$now) : strtotime('last Monday'$now);
            
$sql_add  .= " AND a.add_time > ".$start_time;          
        } elseif (
$timeline == 'month') {
            
$start_time strtotime('first day of '.date('F Y'));
            
$sql_add  .= " AND a.add_time > ".$start_time;          
        } elseif (
$timeline == 'year') {
            
$start_time strtotime('first day of '.date('Y'));
            
$sql_add  .= " AND a.add_time > ".$start_time;          
        }
          
        
$orders = array(
            
'relevance'        => 'relevance',
            
'recent'         => 'a.add_time',
            
'popular'        => 'a.total_views',
            
'rated'            => 'a.likes'
        
);          
    
        if (
$category == 'all') {
              
$sql_count  "SELECT COUNT(*) AS total_albums
                             FROM #__photo_albums AS a
                             WHERE MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE)
                             AND a.status = '1'"
.$sql_add;
            
$sql        "SELECT a.album_id, a.title, a.slug, a.likes, a.rating, a.rated_by,
                                  a.total_views, a.total_photos, a.add_time, a.type, u.username,
                                  MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE) AS relevance
                             FROM #__photo_albums AS a
                             LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
                             WHERE MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE)
                             AND a.status = '1'"
.$sql_add;
        } else {
              
$sql_count  "SELECT COUNT(*) AS total_albums
                             FROM #__photo_albums AS a, #__photo_category AS c
                             WHERE MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE)
                             AND c.cat_id = "
.$category."
                             AND a.status = '1'"
.$sql_add;
            
$sql        "SELECT a.album_id, a.title, a.slug, a.likes, a.rating, a.rated_by,
                                  a.total_views, a.total_photos, a.add_time, a.type, u.username,
                                  MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE) AS relevance
                             FROM #__photo_albums AS a
                             LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
                             INNER JOIN #__photo_category AS c ON (c.album_id = a.album_id AND c.cat_id = "
.$category.")
                             WHERE MATCH (a.title) AGAINST ('"
.$this->db->escape($query)."*' IN BOOLEAN MODE)
                             AND a.status = '1'"
.$sql_add;
        }
        
        
$total_albums                $this->db->get_field($sql_count'total_albums');
        
        
$this->tpl->pagination        VPagination::get($page$total_albumsVCfg::get('photo.search_per_page'));
        
$this->tpl->albums            $this->db->get_rows($sql." ORDER BY ".$orders[$order]." DESC LIMIT ".$this->tpl->pagination['limit']);
    }
}

function 
build_search_url($query$order$timeline 'all'$category 'all'$page false)
{
    
$args    = array(
        
's' => $query,
        
'o' => $order,
        
't'    => ($timeline != 'all') ? $timeline null,
        
'c' => ($category != 'all') ? $category null
    
);
    
    if (
$page) {
        
$args['page'] = $page;
    }
    
    return 
REL_URL.'/search/photo/?'.http_build_query($args);
}
Онлайн: 0
Реклама