コード例 #1
0
ファイル: view.html.php プロジェクト: politik86/test2
 function display($tpl = null)
 {
     $model = $this->getModel();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $dispatcher = JDispatcher::getInstance();
     $theme = $par->get('theme', 'default');
     $item = $model->getItem();
     $item_images = DJClassifiedsImage::getAdsImages($item->id);
     $category = $model->getCategory($item->cat_id);
     $fields = $model->getFields($item->cat_id);
     $fields_contact = $model->geContactFields();
     $item_payments = $model->getItemPayment($item->id);
     if ($item->user_id != 0) {
         $user_items_c = $model->getUserItemsCount($item->user_id);
         $this->assignRef('user_items_c', $user_items_c);
     }
     $menus = $app->getMenu('site');
     $m_active = $menus->getActive();
     $cat_menu_path = array();
     $cid_menu = 0;
     if ($m_active) {
         if (strstr($m_active->link, 'com_djclassifieds') && strstr($m_active->link, 'items')) {
             $cid_menu = $m_active->query['cid'];
             if ($cid_menu > 0) {
                 $cat_menu_path = DJClassifiedsCategory::getParentPath(1, $cid_menu);
             }
         }
     }
     $main_cat_id = $item->cat_id;
     $pathway = $app->getPathway();
     $cat_path = array();
     $cat_theme = '';
     if ($category->id != 0) {
         $cat_path = DJClassifiedsCategory::getParentPath(1, $category->id);
         $main_cat_id = $cat_path[count($cat_path) - 1]->id;
         for ($c = count($cat_path); $c > 0; $c--) {
             $to_b = 1;
             if (count($cat_menu_path)) {
                 foreach ($cat_menu_path as $cm) {
                     if ($cm->id == $cat_path[$c - 1]->id) {
                         $to_b = 0;
                         break;
                     }
                 }
             }
             if ($to_b) {
                 $pathway->addItem($cat_path[$c - 1]->name, DJClassifiedsSEO::getCategoryRoute($cat_path[$c - 1]->id . ':' . $cat_path[$c - 1]->alias));
             }
         }
         foreach ($cat_path as $cp) {
             if ($cp->theme) {
                 $cat_theme = $cp->theme;
             }
         }
     }
     DJClassifiedsTheme::includeCSSfiles($cat_theme);
     if ($cat_theme) {
         $this->_addPath('template', JPATH_COMPONENT . '/themes/' . $cat_theme . '/views/item');
         $theme = $cat_theme;
     }
     $regions = $model->getRegions();
     $country = '';
     $city = '';
     $region_name = '';
     if ($item->region_id != 0 && $par->get('show_regions', '1')) {
         $address = '';
         $rid = $item->region_id;
         if ($rid != 0) {
             while ($rid != 0) {
                 foreach ($regions as $li) {
                     if ($li->id == $rid) {
                         $rid = $li->parent_id;
                         $address .= $li->name . ', ';
                         if ($li->country) {
                             $country = $li->name;
                         }
                         if ($li->city) {
                             $city = $li->name;
                         }
                         if (!$region_name) {
                             $region_name = $li->name;
                         }
                         break;
                     }
                 }
                 if ($rid == $item->region_id) {
                     break;
                 }
             }
         }
         $address = substr($address, 0, -2);
     }
     $profile = '';
     if ($item->user_id) {
         $profile = $model->getProfile($item->user_id);
     }
     if ($item->metakey != '') {
         $document->setMetaData('keywords', $item->metakey);
     } else {
         if ($category->metakey != '') {
             $document->setMetaData('keywords', $category->metakey);
         } else {
             if ($m_active) {
                 if ($m_active->params->get('menu-meta_description')) {
                     $document->setMetaData('keywords', $m_active->params->get('menu-meta_description'));
                 }
             }
         }
     }
     if ($item->metadesc != '') {
         $document->setDescription($item->metadesc);
     } else {
         if ($par->get('seo_item_metadesc', '0') == 0) {
             $document->setDescription($item->intro_desc);
         } else {
             if ($category->metadesc != '') {
                 $document->setDescription($category->metadesc);
             } else {
                 if ($m_active) {
                     if ($m_active->params->get('menu-meta_keywords')) {
                         $document->setDescription($m_active->params->get('menu-meta_keywords'));
                     }
                 }
             }
         }
     }
     $c_title = $document->getTitle();
     $cat_name = $category->name;
     $item_name = $item->name;
     $seo_cat_path = '';
     $seo_title_separator = $par->get('seo_title_separator', ' - ');
     foreach ($cat_path as $cp) {
         if ($seo_cat_path) {
             $seo_cat_path .= $seo_title_separator;
         }
         $seo_cat_path .= $cp->name;
     }
     $seo_title_from = array('|', '<default_title>', '<category_name>', '<category_path>', '<item_name>', '<region_name>');
     $seo_title_to = array($seo_title_separator, $c_title, $cat_name, $seo_cat_path, $item_name, $region_name);
     $seo_title = str_ireplace($seo_title_from, $seo_title_to, $par->get('seo_title_item', '<item_name>|<category_name>|<default_title>'));
     $document->setTitle($seo_title);
     $document->setMetaData('og:title', $item->name);
     $document->setMetaData('og:description', $item->intro_desc);
     if ($item->image_url != '') {
         $images = explode(";", $item->image_url);
         $document->setMetaData('og:image', JURI::base() . 'components/com_djclassifieds/images/' . $images[0]);
     }
     /* plugins */
     JPluginHelper::importPlugin('djclassifieds');
     $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$par));
     $item->event = new stdClass();
     $resultsAfterTitle = $dispatcher->trigger('onAfterDJClassifiedsDisplayTitle', array(&$item, &$par));
     $item->event->afterDJClassifiedsDisplayTitle = trim(implode("\n", $resultsAfterTitle));
     $resultsBeforeContent = $dispatcher->trigger('onBeforeDJClassifiedsDisplayContent', array(&$item, &$par));
     $item->event->beforeDJClassifiedsDisplayContent = trim(implode("\n", $resultsBeforeContent));
     $resultsAfterContent = $dispatcher->trigger('onAfterDJClassifiedsDisplayContent', array(&$item, &$par));
     $item->event->afterDJClassifiedsDisplayContent = trim(implode("\n", $resultsAfterContent));
     $pathway->addItem($item->name);
     $this->assignRef('item', $item);
     $this->assignRef('item_images', $item_images);
     $this->assignRef('fields', $fields);
     $this->assignRef('fields_contact', $fields_contact);
     $this->assignRef('country', $country);
     $this->assignRef('city', $city);
     $this->assignRef('address', $address);
     $this->assignRef('main_cat_id', $main_cat_id);
     $this->assignRef('item_payments', $item_payments);
     $this->assignRef('category', $category);
     $this->assignRef('profile', $profile);
     $this->assignRef('theme', $theme);
     parent::display($tpl);
 }
コード例 #2
0
ファイル: helper.php プロジェクト: kidaa30/lojinha
 static function getItems($params)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $date_time = JFactory::getDate();
     $date_exp = $date_time->toSQL();
     $user = JFactory::getUser();
     $ord = "i.date_start DESC";
     if ($params->get('items_ord') == 1) {
         $ord = "i.display DESC";
     } else {
         if ($params->get('items_ord') == 2) {
             $ord = "rand()";
         }
     }
     if ($params->get('follow_search', 1) == 1 && JRequest::getInt('se', 0) != 0) {
         $where = '';
         $search = '';
         $search_fields = '';
         $cat_id = 0;
         $reg_id = 0;
         $search_radius_v = '';
         $search_radius_h = '';
         if (JRequest::getVar('search', JText::_('COM_DJCLASSIFIEDS_SEARCH'), '', 'string') != JText::_('COM_DJCLASSIFIEDS_SEARCH')) {
             $search_word = $db->Quote('%' . $db->escape(JRequest::getVar('search', '', '', 'string'), true) . '%');
             $search = " AND (CONCAT(i.name,i.intro_desc,i.description) LIKE " . $search_word . " OR c.name LIKE " . $search_word . " OR r.name LIKE " . $search_word . " ) ";
         }
         if (isset($_GET['se_cats'])) {
             if (is_array($_GET['se_cats'])) {
                 $cat_id = end($_GET['se_cats']);
                 if ($cat_id == '' && count($_GET['se_cats']) > 2) {
                     $cat_id = $_GET['se_cats'][count($_GET['se_cats']) - 2];
                 }
             } else {
                 $cat_ids = explode(',', JRequest::getVar('se_cats'));
                 $cat_id = end($cat_ids);
             }
         }
         $cat_id = str_ireplace('p', '', $cat_id);
         $cat_id = (int) $cat_id;
         if ($cat_id > 0) {
             $cats = DJClassifiedsCategory::getSubCat($cat_id, 1);
             $catlist = $cat_id;
             foreach ($cats as $c) {
                 $catlist .= ',' . $c->id;
             }
             $search .= ' AND i.cat_id IN (' . $catlist . ') ';
             $search_fields = self::getSearchFields();
         }
         if (isset($_GET['se_regs'])) {
             if (is_array($_GET['se_regs'])) {
                 $reg_id = end($_GET['se_regs']);
                 if ($reg_id == '' && count($_GET['se_regs']) > 2) {
                     $reg_id = $_GET['se_regs'][count($_GET['se_regs']) - 2];
                 }
             } else {
                 $reg_ids = explode(',', JRequest::getVar('se_regs'));
                 $reg_id = end($reg_ids);
             }
             $reg_id = (int) $reg_id;
         }
         if ($reg_id > 0) {
             $regs = DJClassifiedsRegion::getSubReg($reg_id, 1);
             $reglist = $reg_id;
             foreach ($regs as $r) {
                 $reglist .= ',' . $r->id;
             }
             $search .= ' AND i.region_id IN (' . $reglist . ') ';
         }
         $se_price_from = JRequest::getInt('se_price_f', '');
         $se_price_to = JRequest::getInt('se_price_t', '');
         if ($se_price_from) {
             $search .= " AND ABS(i.price) >= " . $se_price_from . " ";
         }
         if ($se_price_to && $se_price_to > $se_price_from) {
             $search .= " AND ABS(i.price) <= " . $se_price_to . " ";
         }
         $type_id = JRequest::getInt('se_type_id', '0');
         if ($type_id > 0) {
             $where .= " AND i.type_id=" . $type_id . " ";
         }
         $days_l = JRequest::getInt('days_l', '0');
         if ($days_l > 0) {
             $date_limit = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $days_l, date("Y")));
             $where .= " AND i.date_start >= '" . $date_limit . "' ";
         }
         $only_img = JRequest::getInt('se_only_img', 0);
         if ($only_img == 1) {
             //	$search .= " AND img.name !='' ";
         }
         $only_video = JRequest::getInt('se_only_video', 0);
         if ($only_video == 1) {
             $search .= " AND i.video!='' ";
         }
         $postcode = JRequest::getVar('se_postcode', '');
         $radius = JRequest::getInt('se_radius', 0);
         if ($postcode != '' && $postcode != JText::_('COM_DJCLASSIFIEDS_SEARCH_MODULE_POSTCODE') && $radius) {
             $postcode_country = JRequest::getVar('se_postcode_c', '');
             $post_coord = DJClassifiedsGeocode::getLocationPostCode($postcode, $postcode_country);
             $radius_unit = JRequest::getCmd('se_radius_unit', 'km');
             if ($radius_unit == 'mile') {
                 $radius_unit_v = 3959;
             } else {
                 $radius_unit_v = 6371;
             }
             if ($post_coord) {
                 $search_radius_v = ', ( ' . $radius_unit_v . ' * acos( cos( radians(' . $post_coord['lat'] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $post_coord['lng'] . ') ) + sin( radians(' . $post_coord['lat'] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance ';
                 $search_radius_h = 'HAVING distance < ' . $radius . ' ';
             } else {
                 $app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_SORRY_WE_CANT_FIND_COORDINATES_FROM_POSTCODE_WE_OMIITED_RANGE_RESTRICTION'), 'notice');
             }
         }
         $groups_acl = '0,' . implode(',', $user->getAuthorisedViewLevels());
         $where .= " AND c.access_view IN (" . $groups_acl . ") ";
         $date_now = date("Y-m-d H:i:s");
         $query = "SELECT i.*, c.name AS c_name,c.alias AS c_alias, c.id as c_id, r.name as r_name, r.id as r_id " . $search_radius_v . " FROM " . $search_fields . " #__djcf_categories c, #__djcf_items i " . "LEFT JOIN #__djcf_regions r ON i.region_id = r.id " . "WHERE i.date_exp > '" . $date_now . "' AND i.published=1 AND i.cat_id = c.id " . $where;
         if ($search_fields) {
             $query .= " AND sf.item_id=i.id ";
         }
         $query .= $search_radius_h . $search . " ORDER BY i.special DESC, " . $ord . "";
         $db->setQuery($query);
         $items = $db->loadObjectList();
         //echo '<pre>'; print_r($items);die();
     } else {
         $where = '';
         $cid = JRequest::getInt('cid', '0');
         if ($params->get('follow_category', 1) == 1 && $cid > 0) {
             $djcfcatlib = new DJClassifiedsCategory();
             $cats = $djcfcatlib->getSubCat($cid, 1);
             $catlist = $cid;
             foreach ($cats as $c) {
                 $catlist .= ',' . $c->id;
             }
             $where .= ' AND i.cat_id IN (' . $catlist . ') ';
         }
         $groups_acl = '0,' . implode(',', $user->getAuthorisedViewLevels());
         $where .= " AND c.access_view IN (" . $groups_acl . ") ";
         $query = "SELECT i.*, c.name as c_name, c.alias as c_alias " . "FROM #__djcf_categories c, #__djcf_items i  " . "WHERE i.date_exp > '" . $date_exp . "' AND i.published = 1 AND i.cat_id=c.id AND i.latitude!='0.000000000000000' AND i.longitude!='0.000000000000000' " . $where . " " . "ORDER BY " . $ord . " limit " . $params->get('items_limit');
         $db->setQuery($query);
         $items = $db->loadObjectList();
     }
     if (count($items)) {
         $id_list = '';
         foreach ($items as $item) {
             if ($id_list) {
                 $id_list .= ',' . $item->id;
             } else {
                 $id_list .= $item->id;
             }
         }
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         for ($i = 0; $i < count($items); $i++) {
             $img_found = 0;
             $items[$i]->images = array();
             foreach ($items_img as $img) {
                 if ($items[$i]->id == $img->item_id) {
                     $img_found = 1;
                     $items[$i]->images[] = $img;
                 } else {
                     if ($img_found) {
                         break;
                     }
                 }
             }
         }
     }
     return $items;
 }
コード例 #3
0
 function getItems($uid)
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $limit = JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     //$uid		= JRequest::getVar('uid','0','','int');
     $where = " AND i.user_id=" . $uid . " ";
     $fav_s = '';
     $fav_lj = '';
     if ($par->get('favourite', '1') && $user->id > 0) {
         $fav_lj = "LEFT JOIN ( SELECT * FROM #__djcf_favourites WHERE user_id=" . $user->id . ") f ON i.id=f.item_id ";
         $fav_s = ',f.id as f_id ';
         $fav = JRequest::getVar('fav', '0', '', 'int');
         if ($fav > 0) {
             $where .= " AND f.id IS NOT NULL ";
         }
     }
     $distance_v = '';
     if ($par->get('column_distance', '0') && isset($_COOKIE["djcf_latlon"])) {
         $distance_unit = JRequest::getCmd('column_distance_unit', 'km');
         $user_latlog = explode('_', $_COOKIE["djcf_latlon"]);
         if ($distance_unit == 'mile') {
             $distance_unit_v = 3959;
         } else {
             $distance_unit_v = 6371;
         }
         $distance_v = ', ( ' . $distance_unit_v . ' * acos( cos( radians(' . $user_latlog[0] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $user_latlog[1] . ') ) + sin( radians(' . $user_latlog[0] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance_latlon ';
     }
     $order = JRequest::getCmd('order', $par->get('items_ordering', 'date_e'));
     $ord_t = JRequest::getCmd('ord_t', $par->get('items_ordering_dir', 'desc'));
     $ord = "i.date_exp ";
     if ($order == "title") {
         $ord = "i.name ";
     } elseif ($order == "cat") {
         $ord = "c.name ";
     } elseif ($order == "loc") {
         $ord = "r.name ";
     } elseif ($order == "price") {
         $ord = "ABS(i.price) ";
     } elseif ($order == "display") {
         $ord = "i.display ";
     } elseif ($order == "date_a") {
         $ord = "i.date_start ";
     } elseif ($order == "date_e") {
         $ord = "i.date_exp ";
     } elseif ($order == "date_sort") {
         $ord = "i.date_sort ";
     } elseif ($order == "distance") {
         $ord = $distance_v ? "distance_latlon " : "i.date_exp ";
     } elseif ($order == "random") {
         $ord = "RAND() ";
     }
     if ($ord_t == 'desc') {
         $ord .= 'DESC';
     } else {
         $ord .= 'ASC';
     }
     $date_time = JFactory::getDate();
     $date_exp = $date_time->toSQL();
     $query = "SELECT i.*, c.name AS c_name,c.alias AS c_alias, c.id as c_id, r.name as r_name, r.id as r_id, img.img_c " . $fav_s . $distance_v . " FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON i.cat_id = c.id " . "LEFT JOIN #__djcf_regions r ON i.region_id = r.id " . "LEFT JOIN ( SELECT COUNT(img.id) as img_c, img.item_id FROM #__djcf_images img\r\n\t\t\t\t\t\t\t\t WHERE img.type='item' GROUP BY item_id ) img ON i.id=img.item_id " . $fav_lj . "WHERE i.date_exp > NOW() AND i.published=1 " . $where;
     $query .= " ORDER BY i.special DESC, " . $ord . "";
     $items = $this->_getList($query, $limitstart, $limit);
     //echo '<pre>';print_r($db);print_r($items);echo '<pre>';die();
     if (count($items)) {
         $id_list = '';
         foreach ($items as $item) {
             if ($id_list) {
                 $id_list .= ',' . $item->id;
             } else {
                 $id_list .= $item->id;
             }
         }
         $query = "SELECT fv.item_id, fv.field_id, fv.value, fv.value_date,f.label, f.type FROM #__djcf_fields_values fv,#__djcf_fields f " . "WHERE fv.item_id IN (" . $id_list . ") AND f.id=fv.field_id AND (f.in_table>0 OR f.in_blog=1) AND f.access=0 AND f.published=1 " . "ORDER BY fv.item_id, f.label";
         $db->setQuery($query);
         $custom_fields = $db->loadObjectList();
         //echo '<pre>';print_r($custom_fields);die();
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         for ($i = 0; $i < count($items); $i++) {
             $cf_found = 0;
             $items[$i]->fields = array();
             foreach ($custom_fields as $cf) {
                 if ($items[$i]->id == $cf->item_id) {
                     $cf_found = 1;
                     if ($cf->type == 'date') {
                         if ($cf->value_date != '0000-00-00') {
                             $items[$i]->fields[$cf->field_id] = $cf->value_date;
                         }
                     } else {
                         $items[$i]->fields[$cf->field_id] = $cf->value;
                     }
                 } else {
                     if ($cf_found) {
                         break;
                     }
                 }
             }
             $img_found = 0;
             $items[$i]->images = array();
             foreach ($items_img as $img) {
                 if ($items[$i]->id == $img->item_id) {
                     $img_found = 1;
                     $items[$i]->images[] = $img;
                 } else {
                     if ($img_found) {
                         break;
                     }
                 }
             }
         }
     }
     //$db= &JFactory::getDBO();$db->setQuery($query);$items=$db->loadObjectList();
     //echo '<pre>';print_r($db);print_r($items);echo '<pre>';die();
     return $items;
 }
コード例 #4
0
ファイル: saleshistory.php プロジェクト: kidaa30/lojinha
 function getOrders()
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $limit = JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $user = JFactory::getUser();
     $order = JRequest::getCmd('order', $par->get('items_ordering', 'date_e'));
     $ord_t = JRequest::getCmd('ord_t', $par->get('items_ordering_dir', 'desc'));
     $db = JFactory::getDBO();
     $ord = "o.date ";
     /*if($order=="points"){
     			$ord="p.points ";
     		}*/
     if ($ord_t == 'asc') {
         $ord .= 'ASC';
     } else {
         $ord .= 'DESC';
     }
     if ($par->get('authorname', 'name') == 'name') {
         $u_name = 'u.name as username';
     } else {
         $u_name = 'u.username';
     }
     $query = "SELECT o.*, i.name as i_name, i.alias as i_alias, i.cat_id, i.currency, c.alias as c_alias, " . $u_name . ", u.email FROM #__djcf_orders o, #__users u, #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON c.id=i.cat_id " . "WHERE o.item_id=i.id AND u.id=o.user_id AND i.user_id='" . $user->id . "'  " . "ORDER BY  " . $ord . " ";
     $orders = $this->_getList($query, $limitstart, $limit);
     //$db->setQuery($query);
     //$plans=$db->loadObjectList();
     if (count($orders)) {
         $users_id = array();
         $id_list = '';
         foreach ($orders as $order) {
             if ($id_list) {
                 $id_list .= ',' . $order->item_id;
             } else {
                 $id_list .= $order->item_id;
             }
             if ($order->user_id) {
                 $users_id[$order->user_id] = $order->user_id;
             }
         }
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         $users_ids = implode(',', $users_id);
         $user_items_c = '';
         if ($users_ids) {
             $date_now = date("Y-m-d H:i:s");
             $query = "SELECT user_id , COUNT(i.id) as user_items_c FROM #__djcf_items i " . "WHERE i.published=1 AND i.date_exp>'" . $date_now . "' AND i.user_id  IN (" . $users_ids . ") " . "GROUP BY user_id";
             $db->setQuery($query);
             $user_items_c = $db->loadObjectList('user_id');
         }
         for ($i = 0; $i < count($orders); $i++) {
             $orders[$i]->i_user_items_count = '';
             if (isset($user_items_c[$orders[$i]->user_id])) {
                 $orders[$i]->i_user_items_count = $user_items_c[$orders[$i]->user_id]->user_items_c;
             }
             $img_found = 0;
             $orders[$i]->images = array();
             foreach ($items_img as $img) {
                 if ($orders[$i]->item_id == $img->item_id) {
                     $img_found = 1;
                     $orders[$i]->images[] = $img;
                 } else {
                     if ($img_found) {
                         break;
                     }
                 }
             }
         }
     }
     //echo '<pre>';print_r($db);print_r($orders);echo '<pre>';die();
     return $orders;
 }
コード例 #5
0
ファイル: items.php プロジェクト: kidaa30/lojinha
 function getItems($catlist = '')
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $limit = JRequest::getVar('limit', $par->get('limit_djitem_show'), '', 'int');
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $cid = JRequest::getInt('cid', 0);
     $where = '';
     if ($catlist) {
         $where = ' AND i.cat_id IN (' . $catlist . ') ';
     }
     $uid = JRequest::getVar('uid', '0', '', 'int');
     if ($uid > 0) {
         $where .= " AND i.user_id=" . $uid . " ";
     }
     $fav_s = '';
     $fav_lj = '';
     if ($par->get('favourite', '1') && $user->id > 0) {
         $fav_lj = "LEFT JOIN ( SELECT * FROM #__djcf_favourites WHERE user_id=" . $user->id . ") f ON i.id=f.item_id ";
         $fav_s = ',f.id as f_id ';
         $fav = JRequest::getVar('fav', '0', '', 'int');
         if ($fav > 0) {
             $where .= " AND f.id IS NOT NULL ";
         }
     }
     $search = '';
     $search_fields = '';
     $cat_id = 0;
     $reg_id = 0;
     $search_radius_v = '';
     $search_radius_h = '';
     $search_img_count_v = '';
     $search_img_count_lj = '';
     if (JRequest::getVar('se', '0', '', 'string') != '0') {
         if (JRequest::getVar('search', JText::_('COM_DJCLASSIFIEDS_SEARCH'), '', 'string') != JText::_('COM_DJCLASSIFIEDS_SEARCH')) {
             if ($par->get('search_type_phrase', 0) == 1) {
                 $se_words = explode(' ', $db->escape(JRequest::getVar('search', '', '', 'string'), true));
                 foreach ($se_words as $se_w) {
                     if (strlen($se_w) > 2) {
                         $search .= " AND (CONCAT_WS(i.name,i.intro_desc,i.description) LIKE " . $db->Quote('%' . $se_w . '%') . " OR c.name LIKE " . $db->Quote('%' . $se_w . '%') . " OR r.name LIKE " . $db->Quote('%' . $se_w . '%') . " OR i.id=" . $db->Quote($se_w) . " ) ";
                     }
                 }
             } else {
                 $search_word = $db->Quote('%' . $db->escape(JRequest::getVar('search', '', '', 'string'), true) . '%');
                 $search_word2 = $db->Quote($db->escape(JRequest::getVar('search', '', '', 'string'), true));
                 $search = " AND (CONCAT_WS(i.name,i.intro_desc,i.description) LIKE " . $search_word . " OR c.name LIKE " . $search_word . " OR r.name LIKE " . $search_word . " OR i.id=" . $search_word2 . " ) ";
             }
         }
         if (isset($_GET['se_cats'])) {
             if (is_array($_GET['se_cats'])) {
                 $cat_id = end($_GET['se_cats']);
                 if ($cat_id == '' && count($_GET['se_cats']) > 2) {
                     $cat_id = $_GET['se_cats'][count($_GET['se_cats']) - 2];
                 }
             } else {
                 $cat_ids = explode(',', JRequest::getVar('se_cats'));
                 $cat_id = end($cat_ids);
             }
         }
         $cat_id = str_ireplace('p', '', $cat_id);
         $cat_id = (int) $cat_id;
         if ($cat_id > 0) {
             $cats = DJClassifiedsCategory::getSubCat($cat_id, 1);
             $catlist = $cat_id;
             foreach ($cats as $c) {
                 $catlist .= ',' . $c->id;
             }
             $search .= ' AND i.cat_id IN (' . $catlist . ') ';
         }
         $se_ef = JRequest::getInt('ef', 0);
         if ($cat_id > 0 || $se_ef) {
             $search_fields = $this->getSearchFields($cat_id, $se_ef);
         }
         if (isset($_GET['se_regs'])) {
             if (is_array($_GET['se_regs'])) {
                 $reg_id = end($_GET['se_regs']);
                 if ($reg_id == '' && count($_GET['se_regs']) > 2) {
                     $reg_id = $_GET['se_regs'][count($_GET['se_regs']) - 2];
                 }
             } else {
                 $reg_ids = explode(',', JRequest::getVar('se_regs'));
                 $reg_id = end($reg_ids);
             }
             $reg_id = (int) $reg_id;
         }
         if ($reg_id > 0) {
             $regs = DJClassifiedsRegion::getSubReg($reg_id, 1);
             $reglist = $reg_id;
             foreach ($regs as $r) {
                 $reglist .= ',' . $r->id;
             }
             $search .= ' AND i.region_id IN (' . $reglist . ') ';
         }
         $se_price_from = JRequest::getInt('se_price_f', '');
         $se_price_to = JRequest::getInt('se_price_t', '');
         if ($se_price_from) {
             $search .= " AND ABS(i.price) >= " . $se_price_from . " ";
         }
         if ($se_price_to && $se_price_to > $se_price_from) {
             $search .= " AND ABS(i.price) <= " . $se_price_to . " ";
         }
         $type_id = JRequest::getInt('se_type_id', '0');
         if ($type_id > 0) {
             $where .= " AND i.type_id=" . $type_id . " ";
         }
         $days_l = JRequest::getInt('days_l', '0');
         if ($days_l > 0) {
             $date_limit = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $days_l, date("Y")));
             $where .= " AND i.date_start >= '" . $date_limit . "' ";
         }
         $only_img = JRequest::getInt('se_only_img', 0);
         if ($only_img == 1) {
             $search .= " AND img.img_c>0 ";
             $search_img_count_v = ', img.img_c';
             $search_img_count_lj = "LEFT JOIN ( SELECT COUNT(img.id) as img_c, img.item_id FROM #__djcf_images img\r\n\t\t\t\t\t\t\t\t \t\t\t\tWHERE img.type='item' GROUP BY item_id ) img ON i.id=img.item_id ";
         }
         $only_video = JRequest::getInt('se_only_video', 0);
         if ($only_video == 1) {
             $search .= " AND i.video!='' ";
         }
         $only_auctions = JRequest::getInt('se_only_auctions', 0);
         if ($only_auctions == 1) {
             $search .= " AND i.auction = 1 ";
         }
         $postcode = JRequest::getVar('se_postcode', '');
         $radius = JRequest::getFloat('se_radius', 0);
         $se_address = JRequest::getVar('se_address', '');
         $se_geoloc = JRequest::getVar('se_geoloc', '');
         if ($radius) {
             $radius_unit = JRequest::getCmd('se_radius_unit', 'km');
             if ($radius_unit == 'mile') {
                 $radius_unit_v = 3959;
             } else {
                 $radius_unit_v = 6371;
             }
             if ($se_geoloc) {
                 $user_latlog = explode('_', $_COOKIE["djcf_latlon"]);
                 $search_radius_v = ', ( ' . $radius_unit_v . ' * acos( cos( radians(' . $user_latlog[0] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $user_latlog[1] . ') ) + sin( radians(' . $user_latlog[0] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance ';
                 $search_radius_h = 'HAVING distance < ' . $radius . ' ';
             } else {
                 if ($postcode != '' && $postcode != JText::_('COM_DJCLASSIFIEDS_SEARCH_MODULE_POSTCODE')) {
                     $postcode_country = JRequest::getVar('se_postcode_c', '');
                     $post_coord = DJClassifiedsGeocode::getLocationPostCode($postcode, $postcode_country);
                     if ($post_coord) {
                         $search_radius_v = ', ( ' . $radius_unit_v . ' * acos( cos( radians(' . $post_coord['lat'] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $post_coord['lng'] . ') ) + sin( radians(' . $post_coord['lat'] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance ';
                         $search_radius_h = 'HAVING distance < ' . $radius . ' ';
                     } else {
                         $app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_SORRY_WE_CANT_FIND_COORDINATES_FROM_POSTCODE_WE_OMIITED_RANGE_RESTRICTION'), 'notice');
                     }
                 } else {
                     if ($se_address != '' && $se_address != JText::_('COM_DJCLASSIFIEDS_SEARCH_MODULE_ADDRESS')) {
                         $se_address_coord = DJClassifiedsGeocode::getLocation($se_address);
                         if ($se_address_coord) {
                             $search_radius_v = ', ( ' . $radius_unit_v . ' * acos( cos( radians(' . $se_address_coord['lat'] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $se_address_coord['lng'] . ') ) + sin( radians(' . $se_address_coord['lat'] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance ';
                             $search_radius_h = 'HAVING distance < ' . $radius . ' ';
                         } else {
                             $app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_SORRY_WE_CANT_FIND_COORDINATES_FROM_ADDRESS_WE_OMIITED_RANGE_RESTRICTION'), 'notice');
                         }
                     }
                 }
             }
         }
         if (JRequest::getInt('se_also_18', 0) == 0) {
             $search .= " AND c.restriction_18=0 ";
         }
     } else {
         if ($par->get('restriction_18_allads', 0) == 1 && !isset($_COOKIE["djcf_warning18"])) {
             $where .= " AND c.restriction_18=0 ";
         }
     }
     $groups_acl = '0,' . implode(',', $user->getAuthorisedViewLevels());
     $where .= " AND c.access_view IN (" . $groups_acl . ") ";
     $distance_v = '';
     if ($par->get('column_distance', '0') && isset($_COOKIE["djcf_latlon"])) {
         $distance_unit = JRequest::getCmd('column_distance_unit', 'km');
         $user_latlog = explode('_', $_COOKIE["djcf_latlon"]);
         if ($distance_unit == 'mile') {
             $distance_unit_v = 3959;
         } else {
             $distance_unit_v = 6371;
         }
         $distance_v = ', ( ' . $distance_unit_v . ' * acos( cos( radians(' . $user_latlog[0] . ') ) * cos( radians( i.latitude ) ) * cos( radians( i.longitude ) - radians(' . $user_latlog[1] . ') ) + sin( radians(' . $user_latlog[0] . ') ) * sin( radians( i.latitude ) ) ) ) AS distance_latlon ';
     }
     $order = JRequest::getCmd('order', $par->get('items_ordering', 'date_e'));
     $ord_t = JRequest::getCmd('ord_t', $par->get('items_ordering_dir', 'desc'));
     $ord = "i.date_exp ";
     if ($order == "title") {
         $ord = "i.name ";
     } elseif ($order == "cat") {
         $ord = "c.name ";
     } elseif ($order == "loc") {
         $ord = "r.name ";
     } elseif ($order == "price") {
         $ord = "ABS(i.price) ";
     } elseif ($order == "display") {
         $ord = "i.display ";
     } elseif ($order == "date_a") {
         $ord = "i.date_start ";
     } elseif ($order == "date_e") {
         $ord = "i.date_exp ";
     } elseif ($order == "date_sort") {
         $ord = "i.date_sort ";
     } elseif ($order == "distance") {
         $ord = $distance_v ? "distance_latlon " : "i.date_exp ";
     } elseif ($order == "random") {
         $ord = "RAND() ";
     }
     if ($ord_t == 'desc') {
         $ord .= 'DESC';
     } else {
         $ord .= 'ASC';
     }
     $date_time = JFactory::getDate();
     $date_exp = $date_time->toSQL();
     $date_now = date("Y-m-d H:i:s");
     $query = "SELECT i.*, c.name AS c_name,c.alias AS c_alias, c.id as c_id, r.name as r_name, r.id as r_id " . $search_img_count_v . $fav_s . $search_radius_v . $distance_v . " FROM " . $search_fields . " #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON i.cat_id = c.id " . "LEFT JOIN #__djcf_regions r ON i.region_id = r.id " . $search_img_count_lj . $fav_lj . "WHERE i.date_exp > '" . $date_now . "' AND i.published=1 AND c.published=1 " . $where;
     if ($search_fields) {
         $query .= " AND sf.item_id=i.id ";
     }
     if (JRequest::getVar('format', '') == 'feed') {
         $query .= $search . $search_radius_h . " ORDER BY i.date_start DESC ";
         $items = $this->_getList($query, 0, 100);
     } else {
         $query .= $search . $search_radius_h . " ORDER BY i.special DESC, " . $ord . "";
         $items = $this->_getList($query, $limitstart, $limit);
     }
     //echo '<pre>';print_r($query);print_r($items);echo '<pre>';die();
     if (count($items)) {
         $id_list = '';
         foreach ($items as $item) {
             if ($id_list) {
                 $id_list .= ',' . $item->id;
             } else {
                 $id_list .= $item->id;
             }
         }
         $query = "SELECT fv.item_id, fv.field_id, fv.value, fv.value_date,f.label, f.type FROM #__djcf_fields_values fv,#__djcf_fields f " . "WHERE fv.item_id IN (" . $id_list . ") AND f.id=fv.field_id AND (f.in_table>0 OR f.in_blog=1) AND f.access=0 AND f.published=1 " . "ORDER BY fv.item_id,f.ordering, f.label";
         $db->setQuery($query);
         $custom_fields = $db->loadObjectList();
         //echo '<pre>';print_r($custom_fields);die();
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         for ($i = 0; $i < count($items); $i++) {
             $cf_found = 0;
             $items[$i]->fields = array();
             foreach ($custom_fields as $cf) {
                 if ($items[$i]->id == $cf->item_id) {
                     $cf_found = 1;
                     if ($cf->type == 'date') {
                         if ($cf->value_date != '0000-00-00') {
                             $items[$i]->fields[$cf->field_id] = $cf->value_date;
                         }
                     } else {
                         $items[$i]->fields[$cf->field_id] = $cf->value;
                     }
                 } else {
                     if ($cf_found) {
                         break;
                     }
                 }
             }
             $img_found = 0;
             $items[$i]->images = array();
             foreach ($items_img as $img) {
                 if ($items[$i]->id == $img->item_id) {
                     $img_found = 1;
                     $items[$i]->images[] = $img;
                 } else {
                     if ($img_found) {
                         break;
                     }
                 }
             }
         }
     }
     //$db= &JFactory::getDBO();$db->setQuery($query);$items=$db->loadObjectList();
     //echo '<pre>';print_r($db);print_r($items);echo '<pre>';die();
     return $items;
 }
コード例 #6
0
ファイル: view.html.php プロジェクト: kidaa30/lojinha
 function display($tpl = null)
 {
     $model = $this->getModel();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $document = JFactory::getDocument();
     $app = JFactory::getApplication();
     $dispatcher = JDispatcher::getInstance();
     $theme = $par->get('theme', 'default');
     $user = JFactory::getUser();
     $item = $model->getItem();
     if ($item->user_id != $user->id) {
         $groups_acl = ',' . implode(',', $user->getAuthorisedViewLevels()) . ',';
         if (!strstr($groups_acl, ',' . $item->c_access_view . ',') || !$item) {
             DJClassifiedsTheme::djAccessRestriction('category');
         } else {
             if ($item->access_view == 0) {
                 if (!strstr($groups_acl, ',' . $item->c_access_item_view . ',')) {
                     DJClassifiedsTheme::djAccessRestriction();
                 }
             } else {
                 if (!strstr($groups_acl, ',' . $item->access_view . ',')) {
                     DJClassifiedsTheme::djAccessRestriction();
                 }
             }
         }
     }
     $item_images = DJClassifiedsImage::getAdsImages($item->id);
     $category = $model->getCategory($item->cat_id);
     $fields = $model->getFields($item->cat_id);
     $fields_contact = $model->geContactFields();
     $item_payments = $model->getItemPayment($item->id);
     $item_options = $model->getItemOptions($item->id);
     $bids = $model->getBids($item->id, $par->get('bids_displayed', 5));
     if ($item->user_id != 0) {
         $user_items_c = $model->getUserItemsCount($item->user_id);
         $this->assignRef('user_items_c', $user_items_c);
     }
     $menus = $app->getMenu('site');
     $m_active = $menus->getActive();
     $cat_menu_path = array();
     $cid_menu = 0;
     if ($m_active) {
         if (strstr($m_active->link, 'com_djclassifieds') && strstr($m_active->link, 'items')) {
             $cid_menu = $m_active->query['cid'];
             if ($cid_menu > 0) {
                 $cat_menu_path = DJClassifiedsCategory::getParentPath(1, $cid_menu);
             }
         }
     }
     $warning18 = '';
     $main_cat_id = $item->cat_id;
     $pathway = $app->getPathway();
     $cat_path = array();
     $cat_theme = '';
     if ($category->id != 0) {
         $cat_path = DJClassifiedsCategory::getParentPath(1, $category->id);
         $main_cat_id = $cat_path[count($cat_path) - 1]->id;
         for ($c = count($cat_path); $c > 0; $c--) {
             $to_b = 1;
             if (count($cat_menu_path)) {
                 foreach ($cat_menu_path as $cm) {
                     if ($cm->id == $cat_path[$c - 1]->id) {
                         $to_b = 0;
                         break;
                     }
                 }
             }
             if ($to_b) {
                 $pathway->addItem($cat_path[$c - 1]->name, DJClassifiedsSEO::getCategoryRoute($cat_path[$c - 1]->id . ':' . $cat_path[$c - 1]->alias));
             }
         }
         foreach ($cat_path as $cp) {
             if ($cp->theme) {
                 $cat_theme = $cp->theme;
             }
             if ($cp->restriction_18) {
                 $warning18 = 1;
             }
         }
     }
     DJClassifiedsTheme::includeCSSfiles($cat_theme);
     if ($cat_theme) {
         $this->_addPath('template', JPATH_COMPONENT . '/themes/' . $cat_theme . '/views/item');
         $theme = $cat_theme;
     }
     $regions = $model->getRegions();
     $country = '';
     $city = '';
     $region_name = '';
     if ($item->region_id != 0 && $par->get('show_regions', '1')) {
         $address = '';
         $rid = $item->region_id;
         if ($rid != 0) {
             while ($rid != 0) {
                 foreach ($regions as $li) {
                     if ($li->id == $rid) {
                         $rid = $li->parent_id;
                         $address .= $li->name . ', ';
                         if ($li->country) {
                             $country = $li->name;
                         }
                         if ($li->city) {
                             $city = $li->name;
                         }
                         if (!$region_name) {
                             $region_name = $li->name;
                         }
                         break;
                     }
                 }
                 if ($rid == $item->region_id) {
                     break;
                 }
             }
         }
         $address = substr($address, 0, -2);
     }
     $profile = '';
     if ($item->user_id) {
         $profile = $model->getProfile($item->user_id);
     }
     $custom_ask_seller = $model->getCustomAskSellerFields();
     if ($item->metakey != '') {
         $document->setMetaData('keywords', $item->metakey);
     } else {
         if ($category->metakey != '') {
             $document->setMetaData('keywords', $category->metakey);
         } else {
             if ($m_active) {
                 if ($m_active->params->get('menu-meta_description')) {
                     $document->setMetaData('keywords', $m_active->params->get('menu-meta_description'));
                 }
             }
         }
     }
     if ($item->metadesc != '') {
         $document->setDescription($item->metadesc);
     } else {
         if ($par->get('seo_item_metadesc', '0') == 0) {
             $document->setDescription($item->intro_desc);
         } else {
             if ($category->metadesc != '') {
                 $document->setDescription($category->metadesc);
             } else {
                 if ($m_active) {
                     if ($m_active->params->get('menu-meta_keywords')) {
                         $document->setDescription($m_active->params->get('menu-meta_keywords'));
                     }
                 }
             }
         }
     }
     $c_title = $document->getTitle();
     $cat_name = $category->name;
     $item_name = $item->name;
     $seo_cat_path = '';
     $seo_title_separator = $par->get('seo_title_separator', ' - ');
     foreach ($cat_path as $cp) {
         if ($seo_cat_path) {
             $seo_cat_path .= $seo_title_separator;
         }
         $seo_cat_path .= $cp->name;
     }
     $seo_title_from = array('|', '<default_title>', '<category_name>', '<category_path>', '<item_name>', '<region_name>');
     $seo_title_to = array($seo_title_separator, $c_title, $cat_name, $seo_cat_path, $item_name, $region_name);
     $seo_title = str_ireplace($seo_title_from, $seo_title_to, $par->get('seo_title_item', '<item_name>|<category_name>|<default_title>'));
     $document->setTitle($seo_title);
     $document->setMetaData('og:title', $item->name);
     $document->setMetaData('og:description', $item->intro_desc);
     if ($item_images) {
         $document->setMetaData('og:image', JURI::base() . $item_images[0]->thumb_b);
     }
     if ($par->get('comments', '0') == 1 && $par->get('fb_comments_admin', '') != '') {
         $document->addCustomTag('<meta property="fb:admins" content="' . $par->get('fb_comments_admin', '') . '" />');
     }
     $anch = $par->get('showitem_jump', 0) ? '#dj-classifieds' : '';
     $correct_link = JRoute::_(DJClassifiedsSEO::getItemRoute($item->id . ':' . $item->alias, $item->cat_id . ':' . $item->c_alias)) . $anch;
     $document->setMetaData('canonical', $correct_link);
     /* plugins */
     if ($category) {
         $item->c_alias = $category->alias;
     }
     $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$par, 'item'));
     $item->event = new stdClass();
     $resultsAfterTitle = $dispatcher->trigger('onAfterDJClassifiedsDisplayTitle', array(&$item, &$par, 'item'));
     $item->event->afterDJClassifiedsDisplayTitle = trim(implode("\n", $resultsAfterTitle));
     $resultsBeforeContent = $dispatcher->trigger('onBeforeDJClassifiedsDisplayContent', array(&$item, &$par, 'item'));
     $item->event->beforeDJClassifiedsDisplayContent = trim(implode("\n", $resultsBeforeContent));
     $resultsAfterContent = $dispatcher->trigger('onAfterDJClassifiedsDisplayContent', array(&$item, &$par, 'item'));
     $item->event->afterDJClassifiedsDisplayContent = trim(implode("\n", $resultsAfterContent));
     $resultsAfterAuthorProfile = $dispatcher->trigger('onAfterDJClassifiedsDisplayAdvertAuthor', array(&$item, &$par, 'item'));
     $item->event->onAfterDJClassifiedsDisplayAdvertAuthor = trim(implode("\n", $resultsAfterAuthorProfile));
     $pathway->addItem($item->name);
     $this->assignRef('item', $item);
     $this->assignRef('item_images', $item_images);
     $this->assignRef('item_options', $item_options);
     $this->assignRef('fields', $fields);
     $this->assignRef('fields_contact', $fields_contact);
     $this->assignRef('country', $country);
     $this->assignRef('city', $city);
     $this->assignRef('address', $address);
     $this->assignRef('main_cat_id', $main_cat_id);
     $this->assignRef('item_payments', $item_payments);
     $this->assignRef('category', $category);
     $this->assignRef('profile', $profile);
     $this->assignRef('theme', $theme);
     $this->assignRef('bids', $bids);
     $this->assignRef('custom_ask_seller', $custom_ask_seller);
     if ($warning18 && !isset($_COOKIE["djcf_warning18"])) {
         $warning18_link = '';
         if ($par->get('restriction_18_art_id', 0)) {
             require_once JPATH_SITE . '/components/com_content/helpers/route.php';
             $terms_article = $model->getTermsLink($par->get('restriction_18_art_id', 0));
             if ($terms_article) {
                 $slug = $terms_article->id . ':' . $terms_article->alias;
                 $cslug = $terms_article->catid . ':' . $terms_article->c_alias;
                 $warning18_link = ContentHelperRoute::getArticleRoute($slug, $cslug);
                 if ($par->get('restriction_18_art', 0) == 2) {
                     $warning18_link .= '&tmpl=component';
                 }
                 $warning18_link = JRoute::_($warning18_link);
             }
         }
         $this->assignRef('terms_link', $warning18_link);
         parent::display('terms');
     } else {
         parent::display($tpl);
     }
 }
コード例 #7
0
ファイル: items.php プロジェクト: kidaa30/lojinha
 function getItems()
 {
     //$limit = JRequest::getVar('limit', '25', '', 'int');
     //$limitstart = JRequest::getVar('limitstart', '0', '', 'int');
     $limit = $this->getState('list.limit');
     $limitstart = $this->getState('list.start');
     $orderCol = $this->state->get('list.ordering');
     $orderDirn = $this->state->get('list.direction');
     if ($orderCol == 'i.ordering') {
         $orderCol = 'i.cat_id asc,i.ordering';
     } elseif ($orderCol == 'category_name') {
         $orderCol = 'c.name';
     } elseif ($orderCol == 's_active') {
         $active = $this->getState('filter.active');
         if (is_numeric($active)) {
             $orderCol = ' i.date_exp ';
         } else {
             $orderCol = 's_active ' . $orderDirn . ', i.date_exp DESC ';
             $orderDirn = '';
         }
     }
     $db = JFactory::getDBO();
     $query = "SELECT i.*, c.name as cat_name, u.name as user_name,a.c_abuse, i.date_start <= NOW() AND i.date_exp >= NOW() AS s_active " . "FROM #__djcf_items i " . "LEFT JOIN #__djcf_categories c ON i.cat_id=c.id " . "LEFT JOIN #__users u ON i.user_id=u.id " . "LEFT JOIN ( SELECT count(a.id) as c_abuse, a.item_id \r\n\t\t\t \t\t\t\t\t FROM #__djcf_items_abuse a GROUP BY a.item_id ) a ON i.id=a.item_id " . "  WHERE 1  " . $this->_buildWhere() . " order by " . $orderCol . " " . $orderDirn . " ";
     $items = $this->_getList($query, $limitstart, $limit);
     //$db->setQuery($query);$items=$db->loadObjectList();echo '<pre>';print_r($db);print_r($items);die();
     if (count($items)) {
         $id_list = '';
         foreach ($items as $item) {
             $id_list .= $id_list ? ',' . $item->id : $item->id;
         }
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         for ($i = 0; $i < count($items); $i++) {
             $items[$i]->img_path = '';
             $items[$i]->img_name = '';
             $items[$i]->img_ext = '';
             $items[$i]->img_ord = '';
             foreach ($items_img as $img) {
                 if ($items[$i]->id == $img->item_id) {
                     $items[$i]->img_path = $img->path;
                     $items[$i]->img_name = $img->name;
                     $items[$i]->img_ext = $img->ext;
                     $items[$i]->img_ord = $img->ordering;
                     break;
                 }
             }
         }
     }
     return $items;
 }
コード例 #8
0
ファイル: helper.php プロジェクト: kidaa30/lojinha
 public static function getItems($params)
 {
     $date_time = JFactory::getDate();
     $date_exp = $date_time->toSQL();
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $ord = "i.date_start DESC";
     if ($params->get('items_ord') == 1) {
         $ord = "i.display DESC";
     } else {
         if ($params->get('items_ord') == 2) {
             $ord = "rand()";
         } else {
             if ($params->get('items_ord') == 3) {
                 $ord = "i.name";
             }
         }
     }
     $promoted = '';
     $prom_list = array();
     if ($params->get('only_p_special', '0') == 1) {
         $prom_list[] = " i.promotions LIKE '%p_special%' ";
     }
     if ($params->get('only_p_first', '0') == 1) {
         $prom_list[] = " i.promotions LIKE '%p_first%' ";
     }
     if ($params->get('only_p_bold', '0') == 1) {
         $prom_list[] = " i.promotions LIKE '%p_bold%' ";
     }
     if ($params->get('only_p_border', '0') == 1) {
         $prom_list[] = " i.promotions LIKE '%p_border%' ";
     }
     if ($params->get('only_p_bg', '0') == 1) {
         $prom_list[] = " i.promotions LIKE '%p_bg%' ";
     }
     if (count($prom_list) == 1) {
         $promoted = ' AND ' . $prom_list[0] . ' ';
     } else {
         if (count($prom_list) > 1) {
             $promoted = ' AND (' . implode(' OR ', $prom_list) . ') ';
         }
     }
     $item_ids = $params->get('items_ids', '');
     if ($item_ids) {
         $item_ids = ' AND i.id IN (' . $item_ids . ')';
     } else {
         $item_ids = '';
     }
     $users_ids = $params->get('users_ids', '');
     if ($users_ids) {
         $users_ids = ' AND i.user_id IN (' . $users_ids . ')';
     } else {
         $users_ids = '';
     }
     $types_ids_v = $params->get('type_id', '');
     $types_ids = '';
     if (is_array($types_ids_v)) {
         if (count($types_ids_v)) {
             $types_ids = ' AND i.type_id IN (' . implode(',', $types_ids_v) . ')';
         }
     }
     $cat_ids = $params->get('cat_id', '0');
     $cid = JRequest::getInt('cid', '0');
     $fallow_cat = '';
     $cat_list = '';
     if ($params->get('fallow_category') == 1 && JRequest::getVar('option', '') == 'com_djclassifieds' && $cid > 0) {
         $djcfcatlib = new DJClassifiedsCategory();
         $cats = $djcfcatlib->getSubCat($cid, 1);
         $catlist = $cid;
         foreach ($cats as $c) {
             $catlist .= ',' . $c->id;
         }
         $fallow_cat = ' AND i.cat_id IN (' . $catlist . ') ';
     } else {
         if (is_array($cat_ids)) {
             if (count($cat_ids) > 1) {
                 $cat_list = ' AND i.cat_id IN (' . implode(',', $cat_ids) . ') ';
             } else {
                 if (isset($cat_ids[0])) {
                     if ($cat_ids[0] > 0) {
                         $cat_list = ' AND i.cat_id = ' . $cat_ids[0] . ' ';
                     }
                 }
             }
         }
     }
     $reg_ids = $params->get('region_id', '0');
     $fallow_region = '';
     $region_list = '';
     if ($params->get('fallow_region', '0') == 1 && JRequest::getVar('option', '') == 'com_djclassifieds') {
         $djcfreglib = new DJClassifiedsRegion();
         if (JRequest::getVar('view', '') == 'item') {
             $id = JRequest::getInt('id', '0');
             $query = "SELECT i.region_id FROM #__djcf_items i " . "WHERE i.id=" . $id . " LIMIT 1";
             $db->setQuery($query);
             $region_id = $db->loadResult();
             if ($region_id) {
                 $regs = $djcfreglib->getSubReg($region_id);
                 $reglist = $region_id;
                 foreach ($regs as $r) {
                     $reglist .= ',' . $r->id;
                 }
                 $fallow_region = ' AND i.region_id IN (' . $reglist . ') ';
             }
         } else {
             if (JRequest::getVar('view', '') == 'items' && JRequest::getInt('se', '') == 1 && isset($_GET['se_regs'])) {
                 if (is_array($_GET['se_regs'])) {
                     $reg_id_se = end($_GET['se_regs']);
                     if ($reg_id_se == '' && count($_GET['se_regs']) > 2) {
                         $reg_id_se = $_GET['se_regs'][count($_GET['se_regs']) - 2];
                     }
                 } else {
                     $reg_ids_se = explode(',', JRequest::getVar('se_regs'));
                     $reg_id_se = end($reg_ids_se);
                 }
                 $reg_id_se = (int) $reg_id_se;
                 if ($reg_id_se) {
                     $regs = $djcfreglib->getSubReg($reg_id_se);
                     $reglist = $reg_id_se;
                     foreach ($regs as $r) {
                         $reglist .= ',' . $r->id;
                     }
                     $fallow_region = ' AND i.region_id IN (' . $reglist . ') ';
                 }
             }
         }
     }
     if (is_array($reg_ids) && $fallow_region == '') {
         if (count($reg_ids) > 1) {
             $region_list = ' AND i.region_id IN (' . implode(',', $reg_ids) . ') ';
         } else {
             if (isset($reg_ids[0])) {
                 if ($reg_ids[0] > 0) {
                     $region_list = ' AND i.region_id = ' . $reg_ids[0] . ' ';
                 }
             }
         }
     }
     $only_img = '';
     $search_img_count_lj = '';
     if ($params->get('only_with_img', '0') == 1) {
         //$only_img = " AND img.name !='' ";
         $only_img .= " AND img.img_c>0 ";
         $search_img_count_lj = "LEFT JOIN ( SELECT COUNT(img.id) as img_c, img.item_id FROM #__djcf_images img\r\n\t\t\t\t\t\t\t\t\tWHERE img.type='item' GROUP BY item_id ) img ON i.id=img.item_id ";
     }
     $source = '';
     $fav_lj = '';
     $fav_s = '';
     if ($user->id) {
         if ($params->get('items_source', '0') == 1) {
             $source = ' AND i.user_id=' . $user->id . ' ';
         } else {
             if ($params->get('items_source', '0') == 2) {
                 $fav_lj = "LEFT JOIN ( SELECT * FROM #__djcf_favourites WHERE user_id=" . $user->id . ") f ON i.id=f.item_id ";
                 $fav_s = ',f.id as f_id ';
                 $source = " AND f.id IS NOT NULL ";
             }
         }
     }
     $groups_acl = '0,' . implode(',', $user->getAuthorisedViewLevels());
     $access_view = " AND c.access_view IN (" . $groups_acl . ") ";
     $current_ad = '';
     if (JRequest::getVar('option', '') == 'com_djclassifieds' && JRequest::getVar('view', '') == 'item' && JRequest::getInt('id', 0) > 0) {
         $current_ad = ' AND i.id!=' . JRequest::getInt('id', 0) . ' ';
     }
     $adult_restriction = '';
     if (!isset($_COOKIE["djcf_warning18"])) {
         $adult_restriction .= " AND c.restriction_18=0 ";
     }
     $query = "SELECT i.*,c.id as c_id, c.name as c_name,c.alias as c_alias,c.icon_url as c_icon_url, r.name as r_name " . $fav_s . "FROM #__djcf_categories c, #__djcf_items i " . $search_img_count_lj . "LEFT JOIN #__djcf_regions r ON r.id=i.region_id " . $fav_lj . "WHERE i.date_exp > '" . $date_exp . "' AND i.published = 1 AND c.published = 1 AND i.cat_id=c.id " . $promoted . $item_ids . $users_ids . $fallow_cat . $cat_list . $fallow_region . $region_list . $types_ids . $only_img . $source . $access_view . $current_ad . $adult_restriction . "ORDER BY " . $ord . " limit " . $params->get('items_nr');
     $db->setQuery($query);
     $items = $db->loadObjectList();
     //echo '<pre>';print_r($db);die();
     if (count($items)) {
         $id_list = '';
         foreach ($items as $item) {
             if ($id_list) {
                 $id_list .= ',' . $item->id;
             } else {
                 $id_list .= $item->id;
             }
         }
         $items_img = DJClassifiedsImage::getAdsImages($id_list);
         for ($i = 0; $i < count($items); $i++) {
             $img_found = 0;
             $items[$i]->images = array();
             foreach ($items_img as $img) {
                 if ($items[$i]->id == $img->item_id) {
                     $img_found = 1;
                     $items[$i]->images[] = $img;
                 } else {
                     if ($img_found) {
                         break;
                     }
                 }
             }
         }
     }
     return $items;
 }