Esempio n. 1
0
 function recreateAvatarts()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     JToolBarHelper::title(JText::_('COM_DJCLASSIFIEDS_RECREATING_AVATARS'), 'generic.png');
     $cid = JRequest::getVar('cid', array(), 'default', 'array');
     JArrayHelper::toInteger($cid);
     if (count($cid) < 1) {
         JError::raiseError(500, JText::_('COM_DJCLASSIFIEDS_SELECT_ITEM_TO_RECREATE_AVATARS'));
     }
     $tmp = array();
     $tmp[0] = $cid[0];
     unset($cid[0]);
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__djcf_images WHERE item_id =  " . $tmp[0] . " AND type='profile' ";
     $db->setQuery($query);
     $images = $db->loadObjectList();
     if ($images) {
         $nw = $par->get('profth_width', 120);
         $nh = $par->get('profth_height', 120);
         $nws = $par->get('prof_smallth_width', 50);
         $nhs = $par->get('prof_smallth_height', 50);
         foreach ($images as $image) {
             $path = JPATH_SITE . $image->path . $image->name;
             if (JFile::exists($path . '.' . $image->ext)) {
                 if (JFile::exists($path . '_th.' . $image->ext)) {
                     JFile::delete($path . '_th.' . $image->ext);
                 }
                 if (JFile::exists($path . '_ths.' . $image->ext)) {
                     JFile::delete($path . '_ths.' . $image->ext);
                 }
                 //DJClassifiedsImage::makeThumb($path.$images[$ii], $nws, $nhs, 'ths');
                 DJClassifiedsImage::makeThumb($path . '.' . $image->ext, $path . '_th.' . $image->ext, $nw, $nh);
                 DJClassifiedsImage::makeThumb($path . '.' . $image->ext, $path . '_ths.' . $image->ext, $nws, $nhs);
             }
         }
     }
     if (count($cid) < 1) {
         $this->setRedirect('index.php?option=com_djclassifieds&view=profiles', JText::_('COM_DJCLASSIFIEDS_THUMBNAILS_RECREATED'));
     } else {
         $cids = null;
         foreach ($cid as $value) {
             $cids .= '&cid[]=' . $value;
         }
         echo '<h3>' . JTEXT::_('COM_DJCLASSIFIEDS_RESIZING_ITEM') . ' [id = ' . $tmp[0] . ']... ' . JTEXT::_('COM_DJCLASSIFIEDS_PLEASE_WAIT') . '</h3>';
         header("refresh: 0; url=" . JURI::base() . 'index.php?option=com_djclassifieds&task=profiles.recreateAvatarts' . $cids);
     }
     //$redirect = 'index.php?option=com_djclassifieds&view=items';
     //$app->redirect($redirect, JText::_('COM_DJCLASSIFIEDS_THUMBNAILS_RECREATED'));
 }
Esempio n. 2
0
 public function save()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $id = JRequest::getVar('id', '0', '', 'int');
     $db = JFactory::getDBO();
     $del_avatar_id = JRequest::getInt('del_avatar_id', 0);
     $del_avatar_path = JRequest::getVar('del_avatar_path', '');
     $del_avatar_name = JRequest::getVar('del_avatar_name', '');
     $del_avatar_ext = JRequest::getVar('del_avatar_ext', '');
     if (JRequest::getVar('del_avatar', '0', '', 'int')) {
         if ($del_avatar_path && $del_avatar_name && $del_avatar_ext) {
             $path_to_delete = JPATH_SITE . $del_avatar_path . $del_avatar_name;
             if (JFile::exists($path_to_delete . '.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_th.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_th.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $del_avatar_ext);
             }
             $query = "DELETE FROM #__djcf_images WHERE type='profile' AND item_id=" . $id . " AND id=" . $del_avatar_id . " ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $new_icon = $_FILES['new_image'];
     if (substr($new_icon['type'], 0, 5) == "image") {
         $path_to_delete = JPATH_SITE . $del_avatar_path . $del_avatar_name;
         if (JFile::exists($path_to_delete . '.' . $del_avatar_ext)) {
             JFile::delete($path_to_delete . '.' . $del_avatar_ext);
         }
         if (JFile::exists($path_to_delete . '_th.' . $del_avatar_ext)) {
             JFile::delete($path_to_delete . '_th.' . $del_avatar_ext);
         }
         if (JFile::exists($path_to_delete . '_ths.' . $del_avatar_ext)) {
             JFile::delete($path_to_delete . '_ths.' . $del_avatar_ext);
         }
         $query = "DELETE FROM #__djcf_images WHERE type='profile' AND item_id=" . $id . " AND id=" . $del_avatar_id . " ";
         $db->setQuery($query);
         $db->query();
         $lang = JFactory::getLanguage();
         $icon_name = str_ireplace(' ', '_', $new_icon['name']);
         $icon_name = $lang->transliterate($icon_name);
         $icon_name = strtolower($icon_name);
         $icon_name = JFile::makeSafe($icon_name);
         $icon_name = $id . '_' . $icon_name;
         $icon_url = $icon_name;
         $path = JPATH_SITE . "/components/com_djclassifieds/images/profile/" . $icon_name;
         move_uploaded_file($new_icon['tmp_name'], $path);
         $nw = $par->get('profth_width', 120);
         $nh = $par->get('profth_height', 120);
         $nws = $par->get('prof_smallth_width', 50);
         $nhs = $par->get('prof_smallth_height', 50);
         $name_parts = pathinfo($path);
         $img_name = $name_parts['filename'];
         $img_ext = $name_parts['extension'];
         $new_path = JPATH_SITE . "/components/com_djclassifieds/images/profile/";
         //DJClassifiedsImage::makeThumb($path, $nw, $nh, 'ths');
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_th.' . $img_ext, $nw, $nh);
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
         $query = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
         $query .= "('" . $id . "','profile','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/profile/','','1'); ";
         $db->setQuery($query);
         $db->query();
     }
     $query = "DELETE FROM #__djcf_fields_values_profile WHERE user_id= " . $id . " ";
     $db->setQuery($query);
     $db->query();
     $query = "SELECT f.* FROM #__djcf_fields f " . "WHERE f.source=2 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values_profile(`field_id`,`user_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                         $query .= "('" . $fl->id . "','" . $id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     if ($ins) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     switch (JRequest::getVar('task')) {
         case 'apply':
             $link = 'index.php?option=com_djclassifieds&task=profile.edit&id=' . $id;
             $msg = JText::_('COM_DJCLASSIFIEDS_PROFILE_SAVED');
             break;
         case 'saveProfile':
         default:
             $link = 'index.php?option=com_djclassifieds&view=profiles';
             $msg = JText::_('COM_DJCLASSIFIEDS_PROFILE_SAVED');
             break;
     }
     $app->redirect($link, $msg);
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 function recreateThumbnails_all()
 {
     $app = JFactory::getApplication();
     $par =& JComponentHelper::getParams('com_djclassifieds');
     $cid = JRequest::getVar('cid', array(), '', 'array');
     $db =& JFactory::getDBO();
     if (count($cid)) {
         $cids = implode(',', $cid);
         $query = "SELECT id, image_url FROM #__djcf_items WHERE id IN ( " . $cids . " )";
         $db->setQuery($query);
         $items = $db->loadObjectList();
         $path = JPATH_BASE . "/../components/com_djclassifieds/images/";
         $nw = (int) $par->get('th_width', -1);
         $nh = (int) $par->get('th_height', -1);
         $nws = $par->get('smallth_width', -1);
         $nhs = $par->get('smallth_height', -1);
         $nwm = $par->get('middleth_width', -1);
         $nhm = $par->get('middleth_height', -1);
         $nwb = $par->get('bigth_width', -1);
         $nhb = $par->get('bigth_height', -1);
         foreach ($items as $i) {
             if ($i->image_url) {
                 $images = explode(";", $i->image_url);
                 for ($ii = 0; $ii < count($images) - 1; $ii++) {
                     if (JFile::exists($path . $images[$ii] . '.thb.jpg')) {
                         JFile::delete($path . $images[$ii] . '.thb.jpg');
                     }
                     if (JFile::exists($path . $images[$ii] . '.th.jpg')) {
                         JFile::delete($path . $images[$ii] . '.th.jpg');
                     }
                     if (JFile::exists($path . $images[$ii] . '.thm.jpg')) {
                         JFile::delete($path . $images[$ii] . '.thm.jpg');
                     }
                     if (JFile::exists($path . $images[$ii] . '.ths.jpg')) {
                         JFile::delete($path . $images[$ii] . '.ths.jpg');
                     }
                     //DJClassifiedsImage::makeThumb($path.$images[$ii], $nw, $nh, 'th');
                     DJClassifiedsImage::makeThumb($path . $images[$ii], $nws, $nhs, 'ths');
                     DJClassifiedsImage::makeThumb($path . $images[$ii], $nwm, $nhm, 'thm');
                     DJClassifiedsImage::makeThumb($path . $images[$ii], $nwb, $nhb, 'thb');
                 }
             }
         }
     }
     $redirect = 'index.php?option=com_djclassifieds&view=items';
     $app->redirect($redirect, JText::_('COM_DJCLASSIFIEDS_THUMBNAILS_RECREATED'));
 }
Esempio n. 6
0
 function cronOptimize()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__djcf_images WHERE optimized=0 LIMIT 1";
     $db->setQuery($query);
     $image = $db->loadObject();
     if ($image) {
         $path = JPATH_SITE . $image->path . $image->name;
         if (JFile::exists($path . '.' . $image->ext)) {
             if (JFile::exists($path . '_thb.' . $image->ext)) {
                 DJClassifiedsImage::resmushitThumbnails($path . '_thb.' . $image->ext);
             }
             if (JFile::exists($path . '_th.' . $image->ext)) {
                 DJClassifiedsImage::resmushitThumbnails($path . '_th.' . $image->ext);
             }
             if (JFile::exists($path . '_thm.' . $image->ext)) {
                 DJClassifiedsImage::resmushitThumbnails($path . '_thm.' . $image->ext);
             }
             if (JFile::exists($path . '_ths.' . $image->ext)) {
                 DJClassifiedsImage::resmushitThumbnails($path . '_ths.' . $image->ext);
             }
         }
         $query = "UPDATE #__djcf_images SET optimized=1 WHERE id =  " . $image->id . " ";
         $db->setQuery($query);
         $db->query();
         echo 'Optymizing ' . $image->id;
         header("refresh: 0; url=" . JURI::base() . 'index.php?option=com_djclassifieds&task=cronOptimize');
     } else {
         die('done');
     }
     die;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 public function save()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('category');
     $row = JTable::getInstance('Categories', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $row->bind(JRequest::get('post'));
     $icon_url = $row->icon_url;
     $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     if ($row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->alias);
     } else {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $del_icon_id = JRequest::getInt('del_icon_id', 0);
     $del_icon_path = JRequest::getVar('del_icon_path', '');
     $del_icon_name = JRequest::getVar('del_icon_name', '');
     $del_icon_ext = JRequest::getVar('del_icon_ext', '');
     if (JRequest::getVar('del_icon', '0', '', 'int')) {
         if ($del_icon_path && $del_icon_name && $del_icon_ext) {
             $path_to_delete = JPATH_SITE . $del_icon_path . $del_icon_name;
             if (JFile::exists($path_to_delete . '.' . $del_icon_ext)) {
                 JFile::delete($path_to_delete . '.' . $del_icon_ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $del_icon_ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $del_icon_ext);
             }
             $query = "DELETE FROM #__djcf_images WHERE type='category' AND item_id=" . $row->id . " AND id=" . $del_icon_id . " ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $row->price = $row->price * 100;
     //echo '<pre>';print_r($row);die();
     if (!$row->ordering) {
         $query = "SELECT ordering FROM #__djcf_categories WHERE parent_id = " . $row->parent_id . " ORDER BY ordering DESC LIMIT 1";
         $db = JFactory::getDBO();
         $db->setQuery($query);
         $order = $db->loadObject();
         $row->ordering = $order->ordering + 1;
     }
     if (!$row->store()) {
         echo $row->getError();
         exit;
     }
     $new_icon = $_FILES['icon'];
     if (substr($new_icon['type'], 0, 5) == "image") {
         $path_to_delete = JPATH_SITE . $del_icon_path . $del_icon_name;
         if (JFile::exists($path_to_delete . '.' . $del_icon_ext)) {
             JFile::delete($path_to_delete . '.' . $del_icon_ext);
         }
         if (JFile::exists($path_to_delete . '_ths.' . $del_icon_ext)) {
             JFile::delete($path_to_delete . '_ths.' . $del_icon_ext);
         }
         $query = "DELETE FROM #__djcf_images WHERE type='category' AND item_id=" . $row->id . " AND id=" . $del_icon_id . " ";
         $db->setQuery($query);
         $db->query();
         $last_id = $row->id;
         $lang = JFactory::getLanguage();
         $icon_name = str_ireplace(' ', '_', $new_icon['name']);
         $icon_name = $lang->transliterate($icon_name);
         $icon_name = strtolower($icon_name);
         $icon_name = JFile::makeSafe($icon_name);
         $icon_name = $last_id . '_' . $icon_name;
         $icon_url = $icon_name;
         $path = JPATH_SITE . "/components/com_djclassifieds/images/category/" . $icon_name;
         move_uploaded_file($new_icon['tmp_name'], $path);
         $nw = $par->get('catth_width', -1);
         $nh = $par->get('catth_height', -1);
         $name_parts = pathinfo($path);
         $img_name = $name_parts['filename'];
         $img_ext = $name_parts['extension'];
         $new_path = JPATH_SITE . "/components/com_djclassifieds/images/category/";
         //DJClassifiedsImage::makeThumb($path, $nw, $nh, 'ths');
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_ths.' . $img_ext, $nw, $nh);
         $query = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
         $query .= "('" . $row->id . "','category','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/category/','','1'); ";
         $db->setQuery($query);
         $db->query();
     }
     $db = JFactory::getDBO();
     $query = "DELETE FROM #__djcf_categories_groups WHERE cat_id= " . $row->id . " ";
     $db->setQuery($query);
     $db->query();
     if (isset($_POST['cat_groups'])) {
         $query = "INSERT INTO #__djcf_categories_groups(`cat_id`,`group_id`) VALUES ";
         for ($i = 0; $i < count($_POST['cat_groups']); $i++) {
             $group_id = $_POST['cat_groups'][$i];
             $query .= "('" . $row->id . "','" . $group_id . "'), ";
         }
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     switch (JRequest::getVar('task')) {
         case 'apply':
             $link = 'index.php?option=com_djclassifieds&task=category.edit&id=' . $row->id;
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
         case 'save2new':
             $link = 'index.php?option=com_djclassifieds&task=category.add';
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
         case 'saveItem':
         default:
             $link = 'index.php?option=com_djclassifieds&view=categories';
             $msg = JText::_('COM_DJCLASSIFIEDS_CATEGORY_SAVED');
             break;
     }
     $app->redirect($link, $msg);
 }
Esempio n. 10
0
 function recreateThumbnails()
 {
     $app = JFactory::getApplication();
     $par = JComponentHelper::getParams('com_djclassifieds');
     $cid = JRequest::getVar('cid', array(), '', 'array');
     $db = JFactory::getDBO();
     if (count($cid)) {
         $cids = implode(',', $cid);
         /*$query = "SELECT id, icon_url FROM #__djcf_categories WHERE id IN ( ".$cids." )";
         			$db->setQuery($query);
         			$items = $db->loadObjectList();
         			
         			$path = JPATH_BASE."/../components/com_djclassifieds/images/";
         				$nw = $par->get('catth_width',-1);
         		        $nh = $par->get('catth_height',-1);
         							
         		
         			foreach($items as $i){
         				if($i->icon_url){									
                 			if (JFile::exists($path.$i->icon_url.'.ths.jpg')){
                     			JFile::delete($path.$i->icon_url.'.ths.jpg');
                 			}						
         			 		DJClassifiedsImage::makeThumb($path.$i->icon_url, $nw, $nh, 'ths');										
         				}
         			} */
         $query = "SELECT * FROM #__djcf_images WHERE item_id IN  ( " . $cids . " ) AND type='category' ";
         $db->setQuery($query);
         $images = $db->loadObjectList();
         if ($images) {
             $nw = $par->get('catth_width', -1);
             $nh = $par->get('catth_height', -1);
             foreach ($images as $image) {
                 $path = JPATH_SITE . $image->path . $image->name;
                 if (JFile::exists($path . '_ths.' . $image->ext)) {
                     JFile::delete($path . '_ths.' . $image->ext);
                 }
                 DJClassifiedsImage::makeThumb($path . '.' . $image->ext, $path . '_ths.' . $image->ext, $nws, $nhs);
             }
         }
     }
     $redirect = 'index.php?option=com_djclassifieds&view=categories';
     $app->redirect($redirect, JText::_('COM_DJCLASSIFIEDS_THUMBNAILS_RECREATED'));
 }
 public function save()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('item');
     $row = JTable::getInstance('Items', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $db = JFactory::getDBO();
     $lang = JFactory::getLanguage();
     $dispatcher = JDispatcher::getInstance();
     $row->bind(JRequest::get('post'));
     $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->intro_desc = JRequest::getVar('intro_desc', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $row->contact = nl2br(JRequest::getVar('contact', '', 'post', 'string'));
     if ($row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->alias);
     } else {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $row->image_url = '';
     //$exp_date = explode('-', $_POST['date_expir']);
     //$exp_time = explode(':', $_POST['time_expir']);
     //$row->date_exp = mktime($exp_time[0],$exp_time[1],0,$exp_date[1],$exp_date[2],$exp_date[0]);
     $row->date_exp = $_POST['date_expir'] . ' ' . $_POST['time_expir'] . ':00';
     $is_new = 1;
     if ($row->id > 0) {
         $old_date_exp = JRequest::getVar('date_exp_old', '');
         if ($old_date_exp != $row->date_exp) {
             $row->notify = 0;
         }
         $is_new = 0;
     }
     if ($row->id == 0) {
         $row->exp_days = ceil((strtotime($row->date_exp) - time()) / (60 * 60 * 24));
     }
     if ($row->user_id == 0 && $row->id == 0) {
         $user = JFactory::getUser();
         $row->user_id = $user->id;
         $row->ip_address = $_SERVER['REMOTE_ADDR'];
     }
     $row->region_id = end($_POST['regions']);
     if (!$row->region_id) {
         $row->region_id = $_POST['regions'][count($_POST['regions']) - 2];
         if (!reset($_POST['regions'])) {
             $row->region_id = 0;
         }
     }
     if ($row->id > 0) {
         $query = "DELETE FROM #__djcf_fields_values WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         if ($row->payed == 1) {
             $row->pay_type = '';
             $query = "UPDATE #__djcf_payments SET status='Completed' WHERE item_id= " . $row->id . " AND type=0 ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $row->promotions = '';
     $query = "SELECT p.* FROM #__djcf_promotions p ORDER BY p.id ";
     $db->setQuery($query);
     $promotions = $db->loadObjectList();
     foreach ($promotions as $prom) {
         if (JRequest::getVar($prom->name, '0')) {
             $row->promotions .= $prom->name . ',';
         }
     }
     if ($row->promotions) {
         $row->promotions = substr($row->promotions, 0, -1);
     }
     if (strstr($row->promotions, 'p_first')) {
         $row->special = 1;
     } else {
         $row->special = 0;
     }
     if (($row->region_id || $row->address) && ($row->latitude == '0.000000000000000' && $row->longitude == '0.000000000000000' || !$row->latitude && !$row->longitude)) {
         $address = '';
         if ($row->region_id) {
             $reg_path = DJClassifiedsRegion::getParentPath($row->region_id);
             for ($r = count($reg_path) - 1; $r >= 0; $r--) {
                 if ($reg_path[$r]->country) {
                     $address = $reg_path[$r]->name;
                 }
                 if ($reg_path[$r]->city) {
                     if ($address) {
                         $address .= ', ';
                     }
                     $address .= $reg_path[$r]->name;
                 }
             }
         }
         if ($address) {
             $address .= ', ';
         }
         $address .= $row->address;
         if ($row->post_code) {
             $address .= ', ' . $row->post_code;
         }
         $loc_coord = DJClassifiedsGeocode::getLocation($address);
         if (is_array($loc_coord)) {
             $row->latitude = $loc_coord['lat'];
             $row->longitude = $loc_coord['lng'];
         }
     }
     //echo '<pre>';print_r($_POST);print_r($row);echo '</pre>';die();
     if (!$row->store()) {
         echo $row->getError();
         exit;
     }
     if ($is_new) {
         $query = "UPDATE #__djcf_items SET date_sort=date_start WHERE id=" . $row->id . " ";
         $db->setQuery($query);
         $db->query();
     }
     $item_images = '';
     if (!$is_new) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' ";
         $db->setQuery($query);
         $item_images = $db->loadObjectList('id');
     }
     $img_ids = JRequest::getVar('img_id', array(), 'post', 'array');
     $img_captions = JRequest::getVar('img_caption', array(), 'post', 'array');
     $img_images = JRequest::getVar('img_image', array(), 'post', 'array');
     $img_id_to_del = '';
     foreach ($item_images as $item_img) {
         $img_to_del = 1;
         foreach ($img_ids as $img_id) {
             if ($item_img->id == $img_id) {
                 $img_to_del = 0;
                 break;
             }
         }
         if ($img_to_del) {
             $path_to_delete = JPATH_ROOT . $item_img->path . $item_img->name;
             if (JFile::exists($path_to_delete . '.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_thm.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_thm.' . $item_img->ext);
             }
             if (JFile::exists($path_to_delete . '_thb.' . $item_img->ext)) {
                 JFile::delete($path_to_delete . '_thb.' . $item_img->ext);
             }
             $img_id_to_del .= $item_img->id . ',';
         }
     }
     if ($img_id_to_del) {
         $query = "DELETE FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' AND ID IN (" . substr($img_id_to_del, 0, -1) . ") ";
         $db->setQuery($query);
         $db->query();
     }
     $last_id = $row->id;
     $nw = (int) $par->get('th_width', -1);
     $nh = (int) $par->get('th_height', -1);
     $nws = (int) $par->get('smallth_width', -1);
     $nhs = (int) $par->get('smallth_height', -1);
     $nwm = (int) $par->get('middleth_width', -1);
     $nhm = (int) $par->get('middleth_height', -1);
     $nwb = (int) $par->get('bigth_width', -1);
     $nhb = (int) $par->get('bigth_height', -1);
     $img_ord = 1;
     $img_to_insert = 0;
     $query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
     $new_img_path = JPATH_SITE . "/components/com_djclassifieds/images/item/";
     for ($im = 0; $im < count($img_ids); $im++) {
         if ($img_ids[$im]) {
             if ($item_images[$img_ids[$im]]->ordering != $img_ord || $item_images[$img_ids[$im]]->caption != $img_captions[$im]) {
                 $query = "UPDATE #__djcf_images SET ordering='" . $img_ord . "', caption='" . $db->escape($img_captions[$im]) . "' WHERE item_id=" . $row->id . " AND type='item' AND id=" . $img_ids[$im] . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         } else {
             $new_img_name = explode(';', $img_images[$im]);
             if (is_array($new_img_name)) {
                 $new_img_name_u = JPATH_ROOT . '/tmp/djupload/' . $new_img_name[0];
                 if (JFile::exists($new_img_name_u)) {
                     if (getimagesize($new_img_name_u)) {
                         $new_img_n = $last_id . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                         $new_img_n = $lang->transliterate($new_img_n);
                         $new_img_n = strtolower($new_img_n);
                         $new_img_n = JFile::makeSafe($new_img_n);
                         $new_path_check = $new_img_path . $new_img_n;
                         $nimg = 0;
                         while (JFile::exists($new_path_check)) {
                             $nimg++;
                             $new_img_n = $last_id . '_' . $nimg . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                             $new_img_n = $lang->transliterate($new_img_n);
                             $new_img_n = strtolower($new_img_n);
                             $new_img_n = JFile::makeSafe($new_img_n);
                             $new_path_check = $new_img_path . $new_img_n;
                         }
                         rename($new_img_name_u, $new_img_path . $new_img_n);
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thm.' . $img_ext, $nwm, $nhm);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thb.' . $img_ext, $nwb, $nhb);
                         $query_img .= "('" . $row->id . "','item','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/item/','" . $db->escape($img_captions[$im]) . "','" . $img_ord . "'), ";
                         $img_to_insert++;
                         if ($par->get('store_org_img', '1') == 0) {
                             JFile::delete($new_img_path . $new_img_n);
                         }
                     }
                 }
             }
         }
         $img_ord++;
     }
     if ($img_to_insert) {
         $query_img = substr($query_img, 0, -2) . ';';
         $db->setQuery($query_img);
         $db->query();
     }
     //if($row->cat_id){
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . "WHERE (fx.cat_id  = " . $row->cat_id . " OR f.source=1) ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values(`field_id`,`item_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $row->id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                         $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     //print_r($query);die();
     if ($ins) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     //}
     JPluginHelper::importPlugin('djclassifieds');
     $dispatcher->trigger('onAfterDJClassifiedsSaveAdvert', array($row, $is_new));
     switch (JRequest::getVar('task')) {
         case 'apply':
             $link = 'index.php?option=com_djclassifieds&task=item.edit&id=' . $row->id;
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
         case 'save2new':
             $link = 'index.php?option=com_djclassifieds&task=item.add';
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
         case 'saveItem':
         default:
             $link = 'index.php?option=com_djclassifieds&view=items';
             $msg = JText::_('COM_DJCLASSIFIEDS_ITEM_SAVED');
             break;
     }
     $app->redirect($link, $msg);
 }
Esempio n. 12
0
 function save()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $par = JComponentHelper::getParams('com_djclassifieds');
     if ($user->id == '0') {
         $uri = DJClassifiedsSEO::getCategoryRoute('0:all');
         $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN'));
     }
     $del_avatar_id = JRequest::getInt('del_avatar', 0);
     if ($del_avatar_id) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $user->id . " AND type='profile' ORDER BY ordering LIMIT 1";
         $db->setQuery($query);
         $avatar = $db->loadObject();
         if ($avatar) {
             $path_to_delete = JPATH_SITE . $avatar->path . $avatar->name;
             $del_avatar_ext = $avatar->ext;
             if (JFile::exists($path_to_delete . '.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_th.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_th.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $del_avatar_ext);
             }
             $query = "DELETE FROM #__djcf_images WHERE type='profile' AND item_id=" . $user->id . " AND id=" . $avatar->id . " ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $new_avatar = $_FILES['new_avatar'];
     if (substr($new_avatar['type'], 0, 5) == "image") {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $user->id . " AND type='profile' ORDER BY ordering LIMIT 1";
         $db->setQuery($query);
         $avatar = $db->loadObject();
         if ($avatar) {
             $path_to_delete = JPATH_SITE . $avatar->path . $avatar->name;
             $del_avatar_ext = $avatar->ext;
             if (JFile::exists($path_to_delete . '.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_th.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_th.' . $del_avatar_ext);
             }
             if (JFile::exists($path_to_delete . '_ths.' . $del_avatar_ext)) {
                 JFile::delete($path_to_delete . '_ths.' . $del_avatar_ext);
             }
             $query = "DELETE FROM #__djcf_images WHERE type='profile' AND item_id=" . $user->id . " AND id=" . $avatar->id . " ";
             $db->setQuery($query);
             $db->query();
         }
         $lang = JFactory::getLanguage();
         $icon_name = str_ireplace(' ', '_', $new_avatar['name']);
         $icon_name = $lang->transliterate($icon_name);
         $icon_name = strtolower($icon_name);
         $icon_name = JFile::makeSafe($icon_name);
         $icon_name = $user->id . '_' . $icon_name;
         $icon_url = $icon_name;
         $path = JPATH_SITE . "/components/com_djclassifieds/images/profile/" . $icon_name;
         move_uploaded_file($new_avatar['tmp_name'], $path);
         $nw = $par->get('profth_width', 120);
         $nh = $par->get('profth_height', 120);
         $nws = $par->get('prof_smallth_width', 50);
         $nhs = $par->get('prof_smallth_height', 50);
         $name_parts = pathinfo($path);
         $img_name = $name_parts['filename'];
         $img_ext = $name_parts['extension'];
         $new_path = JPATH_SITE . "/components/com_djclassifieds/images/profile/";
         //DJClassifiedsImage::makeThumb($path, $nw, $nh, 'ths');
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_th.' . $img_ext, $nw, $nh);
         DJClassifiedsImage::makeThumb($path, $new_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
         $query = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
         $query .= "('" . $user->id . "','profile','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/profile/','','1'); ";
         $db->setQuery($query);
         $db->query();
     }
     $query = "DELETE FROM #__djcf_fields_values_profile WHERE user_id= " . $user->id . " ";
     $db->setQuery($query);
     $db->query();
     $query = "SELECT f.* FROM #__djcf_fields f WHERE f.source=2 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $a_tags_cf = '';
     if ((int) $par->get('allow_htmltags_cf', '0')) {
         $allowed_tags_cf = explode(';', $par->get('allowed_htmltags_cf', ''));
         for ($a = 0; $a < count($allowed_tags_cf); $a++) {
             $a_tags_cf .= '<' . $allowed_tags_cf[$a] . '>';
         }
     }
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values_profile(`field_id`,`user_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $user->id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $user->id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         if ($a_tags_cf) {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                             $f_var = strip_tags($f_var, $a_tags_cf);
                         } else {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         }
                         $query .= "('" . $fl->id . "','" . $user->id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     //print_r($query);die();
     if ($ins > 0) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     $menus = JSite::getMenu();
     $menu_profile = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=profile', 1);
     $menu_item = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&cid=0', 1);
     $menu_item_blog = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&layout=blog&cid=0', 1);
     $redirect = 'index.php?option=com_djclassifieds&view=profile';
     if ($menu_profile) {
         $redirect .= '&Itemid=' . $menu_profile->id;
     } else {
         if ($menu_item) {
             $redirect .= '&Itemid=' . $menu_item->id;
         } else {
             if ($menu_item_blog) {
                 $redirect .= '&Itemid=' . $menu_item_blog->id;
             }
         }
     }
     $message = JTExt::_('COM_DJCLASSIFIEDS_PROFILE_SAVED_SUCCESSFULLY');
     $redirect = JRoute::_($redirect, false);
     $app->redirect($redirect, $message);
 }
Esempio n. 13
0
 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);
     }
 }
 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;
 }
Esempio n. 15
0
 function save()
 {
     $app = JFactory::getApplication();
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     jimport('joomla.database.table');
     JPluginHelper::importPlugin('djclassifieds');
     $row = JTable::getInstance('Items', 'DJClassifiedsTable');
     $par = JComponentHelper::getParams('com_djclassifieds');
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $dispatcher = JDispatcher::getInstance();
     $db = JFactory::getDBO();
     $id = JRequest::getVar('id', 0, '', 'int');
     $token = JRequest::getCMD('token', '');
     $redirect = '';
     $menus = $app->getMenu('site');
     $menu_item = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&cid=0', 1);
     $menu_item_blog = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=items&layout=blog&cid=0', 1);
     $itemid = '';
     if ($menu_item) {
         $itemid = '&Itemid=' . $menu_item->id;
     } else {
         if ($menu_item_blog) {
             $itemid = '&Itemid=' . $menu_item_blog->id;
         }
     }
     $menu_newad_itemid = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=additem', 1);
     $new_ad_link = 'index.php?option=com_djclassifieds&view=additem';
     if ($menu_newad_itemid) {
         $new_ad_link .= '&Itemid=' . $menu_newad_itemid->id;
     }
     $new_ad_link = JRoute::_($new_ad_link);
     if ($user->id == 0 && $id > 0) {
         $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
         //$redirect="index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
         $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
         $redirect = JRoute::_($redirect);
         $app->redirect($redirect, $message, 'error');
     }
     $db = JFactory::getDBO();
     if ($id > 0) {
         $query = "SELECT user_id FROM #__djcf_items WHERE id='" . $id . "' LIMIT 1";
         $db->setQuery($query);
         $item_user_id = $db->loadResult();
         if ($item_user_id != $user->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_WRONG_AD');
             $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
             $redirect = JRoute::_($redirect);
             $app->redirect($redirect, $message, 'error');
         }
     }
     if ($par->get('user_type') == 1 && $user->id == '0') {
         //$uri = "index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
         $uri = DJClassifiedsSEO::getCategoryRoute('0:all');
         $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_PLEASE_LOGIN'));
     }
     $row->bind(JRequest::get('post'));
     if ($token && !$user->id && !$id) {
         $query = "SELECT i.id FROM #__djcf_items i " . "WHERE i.user_id=0 AND i.token=" . $db->Quote($db->escape($token));
         $db->setQuery($query);
         $ad_id = $db->loadResult();
         if ($ad_id) {
             $row->id = $ad_id;
         } else {
             $uri = DJClassifiedsSEO::getCategoryRoute('0:all');
             $app->redirect('index.php?option=com_users&view=login&return=' . base64_encode($uri), JText::_('COM_DJCLASSIFIEDS_WRONG_TOKEN'));
         }
     }
     $dispatcher->trigger('onAfterInitialiseDJClassifiedsSaveAdvert', array(&$row, &$par));
     if ($par->get('title_char_limit', '0') > 0) {
         $row->name = mb_substr($row->name, 0, $par->get('title_char_limit', '100'), "UTF-8");
     }
     if ((int) $par->get('allow_htmltags', '0')) {
         $row->description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $allowed_tags = explode(';', $par->get('allowed_htmltags', ''));
         $a_tags = '';
         for ($a = 0; $a < count($allowed_tags); $a++) {
             $a_tags .= '<' . $allowed_tags[$a] . '>';
         }
         $row->description = strip_tags($row->description, $a_tags);
     } else {
         $row->description = nl2br(JRequest::getVar('description', '', 'post', 'string'));
     }
     $row->intro_desc = mb_substr(strip_tags(nl2br($row->intro_desc)), 0, $par->get('introdesc_char_limit', '120'), "UTF-8");
     if (!$row->intro_desc) {
         $row->intro_desc = mb_substr(strip_tags($row->description), 0, $par->get('introdesc_char_limit', '120'), "UTF-8");
     }
     $row->contact = nl2br(JRequest::getVar('contact', '', 'post', 'string'));
     $row->price_negotiable = JRequest::getInt('price_negotiable', '0');
     $row->bid_min = str_ireplace(',', '.', JRequest::getVar('bid_min', '', 'post', 'string'));
     $row->bid_max = str_ireplace(',', '.', JRequest::getVar('bid_max', '', 'post', 'string'));
     $row->price_reserve = str_ireplace(',', '.', JRequest::getVar('price_reserve', '', 'post', 'string'));
     if (!$id && !$token && !$user->id && $par->get('guest_can_edit', 0)) {
         $characters = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
         $row->token = '';
         for ($p = 0; $p < 20; $p++) {
             $row->token .= $characters[mt_rand(0, strlen($characters))];
         }
     }
     /*
     	//removing images from folder and from database
     	$path = JPATH_BASE."/components/com_djclassifieds/images/";
     $images = $row->image_url;
     		if(isset($_POST['del_img'])){			
     			$del_image = $_POST['del_img'];	
     		}else{
     			$del_image = array();
     		}    
     
     
     for ($i = 0; $i < count($del_image); $i++){
     
         $images = str_replace($del_image[$i].';', '', $images);
         //deleting the main image
         if (JFile::exists($path.$del_image[$i])){
             JFile::delete($path.$del_image[$i]);
         }
         //deleting thumbnail of image
     		if (JFile::exists($path.$del_image[$i].'.thb.jpg')){
             JFile::delete($path.$del_image[$i].'.thb.jpg');
         }
         if (JFile::exists($path.$del_image[$i].'.th.jpg')){
             JFile::delete($path.$del_image[$i].'.th.jpg');
         }
     		if (JFile::exists($path.$del_image[$i].'.thm.jpg')){
             JFile::delete($path.$del_image[$i].'.thm.jpg');
         }
         if (JFile::exists($path.$del_image[$i].'.ths.jpg')){
             JFile::delete($path.$del_image[$i].'.ths.jpg');
         }
     }
     
      
     //add images
     $new_files = $_FILES['image'];
     if(count($new_files['name'])>0 && $row->id==0){			
     		$query = "SELECT id FROM #__djcf_items ORDER BY id DESC LIMIT 1";
     		$db->setQuery($query);
     		$last_id =$db->loadResult();
     		$last_id++;
     	}else{
     		$last_id= $row->id;
     	}
     	
     	$nw = (int)$par->get('th_width',-1);
     $nh = (int)$par->get('th_height',-1);
     	$nws = $par->get('smallth_width',-1);
     $nhs = $par->get('smallth_height',-1);
     	$nwm = $par->get('middleth_width',-1);
     $nhm = $par->get('middleth_height',-1);			
     	$nwb = $par->get('bigth_width',-1);
     $nhb = $par->get('bigth_height',-1);		
     	$img_maxsize = $par->get('img_maxsize',0);		
     		if($img_maxsize>0){
     			$img_maxsize = $img_maxsize*1024*1024;
     		}
     	
     	$lang = JFactory::getLanguage();
     for ($i = 0; $i < count($new_files['name']); $i++)
     {
         if (substr($new_files['type'][$i], 0, 5) == "image")
         {
        			if($img_maxsize>0 && $new_files['size'][$i]>$img_maxsize){
        				$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_TO_BIG_IMAGE').' : \''.$new_files['name'][$i].'\'','error');
     				continue;
     			}
     			if(!getimagesize($new_files['tmp_name'][$i])){
     				$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_IMAGE_TYPE').' : \''.$new_files['name'][$i].'\'','error');
     				continue;
     			}				
     			$n_name = $last_id.'_'.$new_files['name'][$i];    				
     			$n_name = $lang->transliterate($n_name);
     			$n_name = strtolower($n_name);
     			$n_name = JFile::makeSafe($n_name);
     			        	
         	$new_path = JPATH_BASE."/components/com_djclassifieds/images/".$n_name;
     			$nimg= 0;			
     			while(JFile::exists($new_path)){
     				$nimg++;
     			$n_name = $last_id.'_'.$nimg.'_'.$new_files['name'][$i];
     					$n_name = $lang->transliterate($n_name);
     					$n_name = strtolower($n_name);
     					$n_name = JFile::makeSafe($n_name);            	
         		$new_path = JPATH_BASE."/components/com_djclassifieds/images/".$n_name;
     			}
     			$images .= $n_name.';';
         	move_uploaded_file($new_files['tmp_name'][$i], $new_path);
     			//DJClassifiedsImage::makeThumb($new_path, $nw, $nh, 'th');
     			 	DJClassifiedsImage::makeThumb($new_path, $nws, $nhs, 'ths');
     				DJClassifiedsImage::makeThumb($new_path, $nwm, $nhm, 'thm');
     				DJClassifiedsImage::makeThumb($new_path, $nwb, $nhb, 'thb');
         }else if($new_files['name'][$i]){
     			$app->enqueueMessage(JText::_('COM_DJCLASSIFIEDS_WRONG_IMAGE_TYPE').' : \''.$new_files['name'][$i].'\'','error');	        	
         }
     }
     	
     $row->image_url = $images;
     */
     $row->image_url = '';
     $duration_price = 0;
     if ($row->id == 0) {
         if ($par->get('durations_list', '')) {
             $exp_days = JRequest::getVar('exp_days', $par->get('exp_days'), '', 'int');
             $query = "SELECT * FROM #__djcf_days WHERE days = " . $exp_days;
             $db->setQuery($query);
             $duration = $db->loadObject();
             if ($duration) {
                 $duration_price = $duration->price;
             } else {
                 //$exp_days = $par->get('exp_days','7');
                 $message = JText::_('COM_DJCLASSIFIEDS_WRONG_DURATION_LIMIT');
                 $app->redirect($new_ad_link, $message, 'error');
             }
         } else {
             $exp_days = $par->get('exp_days', '7');
         }
         if ($exp_days == 0) {
             $row->date_exp = "2038-01-01 00:00:00";
         } else {
             $row->date_exp = date("Y-m-d G:i:s", mktime(date("G"), date("i"), date("s"), date("m"), date("d") + $exp_days, date("Y")));
         }
         if ($row->date_exp == '1970-01-01 1:00:00') {
             $row->date_exp = '2038-01-19 00:00:00';
         }
         $row->exp_days = $exp_days;
         $row->date_start = date("Y-m-d H:i:s");
     }
     $row->cat_id = end($_POST['cats']);
     if (!$row->cat_id) {
         $row->cat_id = $_POST['cats'][count($_POST['cats']) - 2];
     }
     $row->cat_id = str_ireplace('p', '', $row->cat_id);
     /*if($par->get('region_add_type','1')){
     			$g_area = JRequest::getVar('g_area','');
     			$g_locality = JRequest::getVar('g_locality','');
     			$g_country = JRequest::getVar('g_country','');			
     			$latlong = str_ireplace(array('(',')'), array('',''), JRequest::getVar('latlong',''));
     			
     				$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_area."'";	
     				$db->setQuery($query);
     				$parent_r_id = $db->loadResult();
     				
     				if($parent_r_id){					
     					$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_locality."' AND parent_id=".$parent_r_id;	
     					$db->setQuery($query);
     					$region_id = $db->loadResult();
     					
     					if($region_id){
     						$row->region_id=$region_id;
     					}else{					
     						$region_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     							$region_row->country=0;
     							$region_row->city=1;
     							$region_row->name=$g_locality;
     							$region_row->parent_id=$parent_r_id;
     													
     							//$ll = explode(',', $latlong);
     							//$region_row->latitude=$ll[0];
     							//$region_row->longitude=$ll[0];	
     							$region_row->published=1;
     							//echo '<pre>';print_r($region_row);die();							
     							if (!$region_row->store()){
     				        		exit ();	
     				    		}
     						$row->region_id=$region_row->id;	
     					}
     				}else{
     					$query = "SELECT id FROM #__djcf_regions WHERE name = '".$g_country."' ";	
     					$db->setQuery($query);
     					$country_id = $db->loadResult();
     					
     					if(!$country_id){$country_id=0;}
     					
     					$area_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     						$area_row->country=0;
     						$area_row->city=0;
     						$area_row->name=$g_area;
     						$area_row->parent_id=$country_id;
     						$area_row->published=1;
     						//echo '<pre>';print_r($region_row);die();							
     						if (!$area_row->store()){
     			        		exit ();	
     			    		}
     					
     					$region_row = &JTable::getInstance('Regions', 'DJClassifiedsTable');
     						$region_row->country=0;
     						$region_row->city=1;
     						$region_row->name=$g_locality;
     						$region_row->parent_id=$area_row->id;
     												
     						//$ll = explode(',', $latlong);
     						//$region_row->latitude=$ll[0];
     						//$region_row->longitude=$ll[0];
     						$region_row->published=1;		
     						//echo '<pre>';print_r($region_row);die();							
     						if (!$region_row->store()){
     			        		exit ();	
     			    		}
     					$row->region_id=$region_row->id;	
     					
     				} 						
     		}else{*/
     $row->region_id = end($_POST['regions']);
     if (!$row->region_id) {
         $row->region_id = $_POST['regions'][count($_POST['regions']) - 2];
     }
     //}
     if (($row->region_id || $row->address) && ($row->latitude == '0.000000000000000' && $row->longitude == '0.000000000000000' || !$row->latitude && !$row->longitude)) {
         $address = '';
         if ($row->region_id) {
             $reg_path = DJClassifiedsRegion::getParentPath($row->region_id);
             for ($r = count($reg_path) - 1; $r >= 0; $r--) {
                 if ($reg_path[$r]->country) {
                     $address = $reg_path[$r]->name;
                 }
                 if ($reg_path[$r]->city) {
                     if ($address) {
                         $address .= ', ';
                     }
                     $address .= $reg_path[$r]->name;
                 }
             }
         }
         if ($address) {
             $address .= ', ';
         }
         $address .= $row->address;
         if ($row->post_code) {
             $address .= ', ' . $row->post_code;
         }
         $loc_coord = DJClassifiedsGeocode::getLocation($address);
         if (is_array($loc_coord)) {
             $row->latitude = $loc_coord['lat'];
             $row->longitude = $loc_coord['lng'];
         }
     }
     //echo '<pre>';print_r($row);die();
     $row->user_id = $user->id;
     $row->ip_address = $_SERVER['REMOTE_ADDR'];
     $row->promotions = '';
     if ($par->get('promotion', '1') == '1') {
         $query = "SELECT p.* FROM #__djcf_promotions p WHERE p.published=1 ORDER BY p.id ";
         $db->setQuery($query);
         $promotions = $db->loadObjectList();
         foreach ($promotions as $prom) {
             if (JRequest::getVar($prom->name, '0')) {
                 $row->promotions .= $prom->name . ',';
             }
         }
         if ($row->promotions) {
             $row->promotions = substr($row->promotions, 0, -1);
         }
     } else {
         if ($row->id > 0) {
             $row->promotions = $old_row->promotions;
         }
     }
     if (strstr($row->promotions, 'p_first')) {
         $row->special = 1;
     } else {
         $row->special = 0;
     }
     $cat = '';
     if ($row->cat_id) {
         $query = "SELECT name,alias,price,autopublish FROM #__djcf_categories WHERE id = " . $row->cat_id;
         $db->setQuery($query);
         $cat = $db->loadObject();
         if (!$cat->alias) {
             $cat->alias = DJClassifiedsSEO::getAliasName($cat->name);
         }
     }
     $is_new = 1;
     if ($row->id > 0) {
         $query = "SELECT * FROM #__djcf_items WHERE id = " . $row->id;
         $db->setQuery($query);
         $old_row = $db->loadObject();
         $query = "DELETE FROM #__djcf_fields_values WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         $query = "DELETE FROM #__djcf_fields_values_sale WHERE item_id= " . $row->id . " ";
         $db->setQuery($query);
         $db->query();
         $row->payed = $old_row->payed;
         $row->pay_type = $old_row->pay_type;
         $row->exp_days = $old_row->exp_days;
         $row->alias = $old_row->alias;
         $row->published = $old_row->published;
         $is_new = 0;
     }
     if (!$row->alias) {
         $row->alias = DJClassifiedsSEO::getAliasName($row->name);
     }
     $dispatcher->trigger('onBeforePaymentsDJClassifiedsSaveAdvert', array(&$row, $is_new, &$cat, &$promotions));
     if ($cat->autopublish == '0') {
         if ($par->get('autopublish') == '1') {
             $row->published = 1;
             if ($row->id) {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY');
             } else {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY');
             }
         } else {
             $row->published = 0;
             if ($row->id) {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
             } else {
                 $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
             }
             //$redirect="index.php?option=com_djclassifieds&view=items&cid=0".$itemid;
             $redirect = DJClassifiedsSEO::getItemRoute($row->id . ':' . $row->alias, $row->cat_id . ':' . $i->c_alias);
         }
     } elseif ($cat->autopublish == '1') {
         $row->published = 1;
         if ($row->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY');
         } else {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY');
         }
     } elseif ($cat->autopublish == '2') {
         $row->published = 0;
         if ($row->id) {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
         } else {
             $message = JText::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_WAITING_FOR_PUBLISH');
         }
         $redirect = DJClassifiedsSEO::getCategoryRoute('0:all');
     }
     $pay_redirect = 0;
     $row->pay_type = '';
     $row->payed = 1;
     //echo '<pre>';print_r($old_row);print_r($row);die();
     if (isset($old_row)) {
         if ($cat->price == 0 && $row->promotions == '' && !strstr($old_row->pay_type, 'duration')) {
             $row->payed = 1;
             $row->pay_type = '';
         } else {
             if ($old_row->cat_id != $row->cat_id && $cat->price > 0 || $old_row->promotions != $row->promotions || strstr($old_row->pay_type, 'duration') || $old_row->pay_type) {
                 $row->pay_type = '';
                 if ($old_row->cat_id != $row->cat_id && $cat->price > 0) {
                     $row->pay_type = 'cat,';
                 } else {
                     if ($old_row->cat_id == $row->cat_id && $cat->price > 0 && strstr($old_row->pay_type, 'cat')) {
                         $row->pay_type = 'cat,';
                     }
                 }
                 //if($old_row->promotions!=$row->promotions){
                 $prom_new = explode(',', $row->promotions);
                 for ($pn = 0; $pn < count($prom_new); $pn++) {
                     if (!strstr($old_row->promotions, $prom_new[$pn]) || strstr($old_row->pay_type, $prom_new[$pn])) {
                         $row->pay_type .= $prom_new[$pn] . ',';
                     }
                 }
                 //}
                 if (strstr($old_row->pay_type, 'duration')) {
                     $row->pay_type .= 'duration,';
                 }
                 if ($row->pay_type) {
                     $row->published = 0;
                     $row->payed = 0;
                     $pay_redirect = 1;
                 }
                 //echo $row->pay_type;print_r($old_row);
                 //print_r($row);echo $pay_redirect;die();
             } else {
                 if ($row->payed == 0 && ($cat->price > 0 || $row->promotions != '')) {
                     $row->payed = 0;
                     $row->published = 0;
                     $pay_redirect = 1;
                 }
             }
         }
     } else {
         if ($cat->price > 0 || $row->promotions != '' || $duration_price > 0) {
             if ($cat->price > 0) {
                 $row->pay_type .= 'cat,';
             }
             if ($duration_price > 0) {
                 $row->pay_type .= 'duration,';
             }
             if ($row->promotions != '') {
                 $row->pay_type .= $row->promotions;
             }
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
         } else {
             $row->payed = 1;
             $row->pay_type = '';
         }
     }
     //check for free promotions
     if (!strstr($row->pay_type, 'cat') && !strstr($row->pay_type, 'duration') && strstr($row->pay_type, 'p_')) {
         $prom_to_pay = explode(',', $row->pay_type);
         $prom_price = 0;
         for ($pp = 0; $pp < count($prom_to_pay); $pp++) {
             foreach ($promotions as $prom) {
                 if ($prom->name == $prom_to_pay[$pp]) {
                     $prom_price += $prom->price;
                 }
             }
         }
         if ($prom_price == 0) {
             $row->pay_type = '';
             $redirect = '';
             $pay_redirect = 0;
             if ($cat->autopublish == '0' && $par->get('autopublish') == '1' || $cat->autopublish == '1') {
                 $row->published = 1;
             }
         }
     }
     //echo '<pre>';print_r($row);die();echo '</pre>';
     $dispatcher->trigger('onBeforeDJClassifiedsSaveAdvert', array(&$row, $is_new));
     if (!$row->store()) {
         //echo $row->getError();exit ();
     }
     if ($is_new) {
         $query = "UPDATE #__djcf_items SET date_sort=date_start WHERE id=" . $row->id . " ";
         $db->setQuery($query);
         $db->query();
     }
     $item_images = '';
     $images_c = 0;
     if (!$is_new) {
         $query = "SELECT * FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' ";
         $db->setQuery($query);
         $item_images = $db->loadObjectList('id');
         $images_c = count($item_images);
     }
     $img_ids = JRequest::getVar('img_id', array(), 'post', 'array');
     $img_captions = JRequest::getVar('img_caption', array(), 'post', 'array');
     $img_images = JRequest::getVar('img_image', array(), 'post', 'array');
     $img_id_to_del = '';
     if ($item_images) {
         foreach ($item_images as $item_img) {
             $img_to_del = 1;
             foreach ($img_ids as $img_id) {
                 if ($item_img->id == $img_id) {
                     $img_to_del = 0;
                     break;
                 }
             }
             if ($img_to_del) {
                 $images_c--;
                 $path_to_delete = JPATH_ROOT . $item_img->path . $item_img->name;
                 if (JFile::exists($path_to_delete . '.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_ths.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_ths.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_thm.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_thm.' . $item_img->ext);
                 }
                 if (JFile::exists($path_to_delete . '_thb.' . $item_img->ext)) {
                     JFile::delete($path_to_delete . '_thb.' . $item_img->ext);
                 }
                 $img_id_to_del .= $item_img->id . ',';
             }
         }
         if ($img_id_to_del) {
             $query = "DELETE FROM #__djcf_images WHERE item_id=" . $row->id . " AND type='item' AND ID IN (" . substr($img_id_to_del, 0, -1) . ") ";
             $db->setQuery($query);
             $db->query();
         }
     }
     $last_id = $row->id;
     $imglimit = $par->get('img_limit', '3');
     $nw = (int) $par->get('th_width', -1);
     $nh = (int) $par->get('th_height', -1);
     $nws = (int) $par->get('smallth_width', -1);
     $nhs = (int) $par->get('smallth_height', -1);
     $nwm = (int) $par->get('middleth_width', -1);
     $nhm = (int) $par->get('middleth_height', -1);
     $nwb = (int) $par->get('bigth_width', -1);
     $nhb = (int) $par->get('bigth_height', -1);
     $img_ord = 1;
     $img_to_insert = 0;
     $query_img = "INSERT INTO #__djcf_images(`item_id`,`type`,`name`,`ext`,`path`,`caption`,`ordering`) VALUES ";
     $new_img_path = JPATH_SITE . "/components/com_djclassifieds/images/item/";
     for ($im = 0; $im < count($img_ids); $im++) {
         if ($img_ids[$im]) {
             if ($item_images[$img_ids[$im]]->ordering != $img_ord || $item_images[$img_ids[$im]]->caption != $img_captions[$im]) {
                 $query = "UPDATE #__djcf_images SET ordering='" . $img_ord . "', caption='" . $db->escape($img_captions[$im]) . "' WHERE item_id=" . $row->id . " AND type='item' AND id=" . $img_ids[$im] . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         } else {
             if ($images_c >= $imglimit) {
                 break;
             }
             $new_img_name = explode(';', $img_images[$im]);
             if (is_array($new_img_name)) {
                 $new_img_name_u = JPATH_ROOT . '/tmp/djupload/' . $new_img_name[0];
                 if (JFile::exists($new_img_name_u)) {
                     if (getimagesize($new_img_name_u)) {
                         $new_img_n = $last_id . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                         $new_img_n = $lang->transliterate($new_img_n);
                         $new_img_n = strtolower($new_img_n);
                         $new_img_n = JFile::makeSafe($new_img_n);
                         $nimg = 0;
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         $new_path_check = $new_img_path . $new_img_n;
                         $new_path_check = str_ireplace('.' . $img_ext, '_thm.' . $img_ext, $new_path_check);
                         while (JFile::exists($new_path_check)) {
                             $nimg++;
                             $new_img_n = $last_id . '_' . $nimg . '_' . str_ireplace(' ', '_', $new_img_name[1]);
                             $new_img_n = $lang->transliterate($new_img_n);
                             $new_img_n = strtolower($new_img_n);
                             $new_img_n = JFile::makeSafe($new_img_n);
                             $new_path_check = $new_img_path . $new_img_n;
                             $new_path_check = str_ireplace('.' . $img_ext, '_thm.' . $img_ext, $new_path_check);
                         }
                         rename($new_img_name_u, $new_img_path . $new_img_n);
                         $name_parts = pathinfo($new_img_n);
                         $img_name = $name_parts['filename'];
                         $img_ext = $name_parts['extension'];
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_ths.' . $img_ext, $nws, $nhs);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thm.' . $img_ext, $nwm, $nhm);
                         DJClassifiedsImage::makeThumb($new_img_path . $new_img_n, $new_img_path . $img_name . '_thb.' . $img_ext, $nwb, $nhb);
                         $query_img .= "('" . $row->id . "','item','" . $img_name . "','" . $img_ext . "','/components/com_djclassifieds/images/item/','" . $db->escape($img_captions[$im]) . "','" . $img_ord . "'), ";
                         $img_to_insert++;
                         if ($par->get('store_org_img', '1') == 0) {
                             JFile::delete($new_img_path . $new_img_n);
                         }
                     }
                 }
             }
             $images_c++;
         }
         $img_ord++;
     }
     if ($img_to_insert) {
         $query_img = substr($query_img, 0, -2) . ';';
         $db->setQuery($query_img);
         $db->query();
     }
     $imgfreelimit = $par->get('img_free_limit', '-1');
     if ($imgfreelimit > -1 && $images_c > $imgfreelimit) {
         $extra_images = $images_c - $imgfreelimit;
         $images_to_pay = $extra_images;
         if (!$is_new) {
             if ($old_row->extra_images >= $images_to_pay) {
                 $images_to_pay = 0;
             } else {
                 $images_to_pay = $images_to_pay - $old_row->extra_images;
             }
         }
         $images_to_pay = $images_to_pay + $old_row->extra_images_to_pay;
         if ($images_to_pay > 0) {
             $row->extra_images = $extra_images;
             $row->extra_images_to_pay = $images_to_pay;
             $row->pay_type .= 'extra_img,';
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
             $row->store();
         }
     }
     $desc_chars_limit = $par->get('pay_desc_chars_free_limit', 0);
     $desc_c = strlen($row->description);
     if ($par->get('pay_desc_chars', 0) && $desc_c > $desc_chars_limit) {
         $extra_chars = $desc_c - $desc_chars_limit;
         $chars_to_pay = $extra_chars;
         if (!$is_new) {
             if ($old_row->extra_chars >= $chars_to_pay) {
                 $chars_to_pay = 0;
             } else {
                 $chars_to_pay = $chars_to_pay - $old_row->extra_chars;
             }
         }
         $chars_to_pay = $chars_to_pay + $old_row->extra_chars_to_pay;
         if ($chars_to_pay > 0) {
             $row->extra_chars = $extra_chars;
             $row->extra_chars_to_pay = $chars_to_pay;
             $row->pay_type .= 'extra_chars,';
             $row->published = 0;
             $row->payed = 0;
             $pay_redirect = 1;
             $row->store();
         }
     }
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . " WHERE fx.cat_id  = " . $row->cat_id . " OR f.source=1 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($db);print_r($fields_list);die();
     $a_tags_cf = '';
     if ((int) $par->get('allow_htmltags_cf', '0')) {
         $allowed_tags_cf = explode(';', $par->get('allowed_htmltags_cf', ''));
         for ($a = 0; $a < count($allowed_tags_cf); $a++) {
             $a_tags_cf .= '<' . $allowed_tags_cf[$a] . '>';
         }
     }
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values(`field_id`,`item_id`,`value`,`value_date`) VALUES ";
         foreach ($fields_list as $fl) {
             if ($fl->type == 'checkbox') {
                 if (isset($_POST[$fl->name])) {
                     $field_v = $_POST[$fl->name];
                     $f_value = ';';
                     for ($fv = 0; $fv < count($field_v); $fv++) {
                         $f_value .= $field_v[$fv] . ';';
                     }
                     $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_value) . "',''), ";
                     $ins++;
                 }
             } else {
                 if ($fl->type == 'date') {
                     if (isset($_POST[$fl->name])) {
                         $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         $query .= "('" . $fl->id . "','" . $row->id . "','','" . $db->escape($f_var) . "'), ";
                         $ins++;
                     }
                 } else {
                     if (isset($_POST[$fl->name])) {
                         if ($a_tags_cf) {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string', JREQUEST_ALLOWRAW);
                             $f_var = strip_tags($f_var, $a_tags_cf);
                         } else {
                             $f_var = JRequest::getVar($fl->name, '', '', 'string');
                         }
                         $query .= "('" . $fl->id . "','" . $row->id . "','" . $db->escape($f_var) . "',''), ";
                         $ins++;
                     }
                 }
             }
         }
     }
     //print_r($query);die();
     if ($ins > 0) {
         $query = substr($query, 0, -2) . ';';
         $db->setQuery($query);
         $db->query();
     }
     $query = "SELECT f.* FROM #__djcf_fields f " . "LEFT JOIN #__djcf_fields_xref fx ON f.id=fx.field_id " . "WHERE fx.cat_id  = " . $row->cat_id . " AND f.in_buynow=1 ";
     $db->setQuery($query);
     $fields_list = $db->loadObjectList();
     //echo '<pre>'; print_r($_POST);print_r($fields_list);die();
     $ins = 0;
     if (count($fields_list) > 0) {
         $query = "INSERT INTO #__djcf_fields_values_sale(`item_id`,`quantity`,`options`) VALUES ";
         $bn_quantity = JRequest::getVar('bn-quantity', array());
         $quantity_total = 0;
         foreach ($fields_list as &$fl) {
             $fl->bn_values = JRequest::getVar('bn-' . $fl->name, array());
         }
         $bn_options = array();
         for ($q = 0; $q < count($bn_quantity); $q++) {
             if ($bn_quantity[$q] == '' || $bn_quantity[$q] == 0) {
                 continue;
             }
             $bn_option = array();
             $bn_option['quantity'] = $bn_quantity[$q];
             $bn_option['options'] = array();
             $quantity_total = $quantity_total + $bn_quantity[$q];
             foreach ($fields_list as &$fl) {
                 if ($fl->bn_values[$q]) {
                     $bn_opt = array();
                     $bn_opt['id'] = $fl->id;
                     $bn_opt['name'] = $fl->name;
                     $bn_opt['label'] = $fl->label;
                     $bn_opt['value'] = $fl->bn_values[$q];
                     $bn_option['options'][] = $bn_opt;
                 }
             }
             if (count($bn_option['options'])) {
                 $bn_options[] = $bn_option;
             }
         }
         if (count($bn_options)) {
             foreach ($bn_options as $opt) {
                 $query .= "('" . $row->id . "','" . $opt['quantity'] . "','" . $db->escape(json_encode($opt['options'])) . "'), ";
                 $ins++;
             }
             if ($ins) {
                 $query = substr($query, 0, -2) . ';';
                 $db->setQuery($query);
                 $db->query();
                 $query = "UPDATE #__djcf_items SET quantity=" . $quantity_total . " WHERE id=" . $row->id . " ";
                 $db->setQuery($query);
                 $db->query();
             }
         }
     }
     if ($par->get('notify_admin', '0')) {
         if ($id > 0) {
             $new_ad = 0;
         } else {
             $new_ad = 1;
         }
         if ($par->get('notify_admin', '0') == 1) {
             DJClassifiedsNotify::notifyAdmin($row, $cat, $new_ad);
         } else {
             if ($par->get('notify_admin', '0') == 2 && $id == 0) {
                 DJClassifiedsNotify::notifyAdmin($row, $cat, $new_ad);
             }
         }
     }
     if ($id == 0 && $par->get('user_new_ad_email', '0') && ($user->id > 0 || $par->get('email_for_guest', '0') && $row->email)) {
         DJClassifiedsNotify::notifyNewAdvertUser($row, $cat);
     }
     $dispatcher->trigger('onAfterDJClassifiedsSaveAdvert', array(&$row, $is_new));
     if ($pay_redirect == 1) {
         $menu_uads_itemid = $menus->getItems('link', 'index.php?option=com_djclassifieds&view=useritems', 1);
         $redirect = 'index.php?option=com_djclassifieds&view=payment&id=' . $row->id;
         if ($menu_uads_itemid) {
             $redirect .= '&Itemid=' . $menu_uads_itemid->id;
         }
         //$redirect= 'index.php?option=com_djclassifieds&view=payment&id='.$row->id.$itemid;
         if ($row->id) {
             $message = JTExt::_('COM_DJCLASSIFIEDS_AD_SAVED_SUCCESSFULLY_CHOOSE_PAYMENT');
         } else {
             $message = JTExt::_('COM_DJCLASSIFIEDS_AD_ADDED_SUCCESSFULLY_CHOOSE_PAYMENT');
         }
     }
     if (!$redirect) {
         //$redirect= 'index.php?option=com_djclassifieds&view=item&cid='.$row->cat_id.'&id='.$row->id.$itemid;
         $redirect = DJClassifiedsSEO::getItemRoute($row->id . ':' . $row->alias, $row->cat_id . ':' . $cat->alias);
     }
     $redirect = JRoute::_($redirect, false);
     $app->redirect($redirect, $message);
 }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
 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;
 }