function google_cars() { echo '<rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>' . osc_page_title() . '</title> <description>' . osc_page_description() . '</description> <link>' . osc_base_url() . '</link>'; if (osc_count_items()) { while (osc_has_items()) { $item = feed_get_car_data(osc_item()); $date = date('d/m/Y'); $time = date('H:i'); if (preg_match('|([0-9]{4})-([0-9]{2})-([0-9]{2})|', osc_item_pub_date(), $tmp)) { $date = $tmp[3] . "/" . $tmp[2] . "/" . $tmp[1]; } echo '<item> <title>' . osc_item_title() . '</title> <description>' . osc_item_description() . '</description> <g:id>' . osc_item_id() . '</g:id> <link>' . osc_item_url() . '</link> <g:location>' . (osc_item_address() != '' ? osc_item_address() : '') . ', ' . (osc_item_city() != '' ? osc_item_city() : '') . ', ' . (osc_item_region() != '' ? osc_item_region() : '') . ', ' . (osc_item_zip() != '' ? osc_item_zip() : '') . ' ' . (osc_item_country() != '' ? osc_item_country() : '') . '</g:location> <g:publish_date>' . $date . '</g:publish_date> <g:color>' . (isset($item['s_color']) ? $item['s_color'] : '') . '</g:color> <g:condition>' . (isset($item['b_new']) && $item['b_new'] == 1 ? 'new' : 'used') . '</g:condition>'; if (osc_count_item_resources() > 0) { while (osc_has_item_resources()) { if (strpos(osc_resource_type(), 'image') !== FALSE) { echo '<g:image_link>' . osc_resource_path() . '</g:image_link>'; } } } echo '<g:make>' . (isset($item['s_make']) ? $item['s_make'] : '') . '</g:make> <g:mileage>' . (isset($item['i_mileage']) ? $item['i_mileage'] : '') . '</g:mileage> <g:model>' . (isset($item['s_model']) ? $item['s_model'] : '') . '</g:model> <g:price>' . (osc_item_price() != '' ? osc_item_price() : '') . '</g:price> <g:vehicle_type>' . (isset($item['s_name']) ? $item['s_name'] : '') . '</g:vehicle_type> <g:year>' . (isset($item['i_year']) ? $item['i_year'] : '') . '</g:year> </item>'; } } echo '</channel> </rss>'; }
function oodle_realstate() { echo '<?xml version="1.0" encoding="utf-8"?><listings>'; if (osc_count_items()) { while (osc_has_items()) { $item = feed_get_house_data(osc_item()); $time = explode(" ", osc_item_pub_date()); if (isset($item['s_square_meters'])) { $lot_size = $item['s_square_meters'] * 10.7639104; } else { $lot_size = 0; } $amenities = array(); if (isset($item['b_heating']) && $item['b_heating']) { $amenities[] = __('Heating', 'extra_feeds'); } if (isset($item['b_air_condition']) && $item['b_air_condition']) { $amenities[] = __('Air condition', 'extra_feeds'); } if (isset($item['b_elevator']) && $item['b_elevator']) { $amenities[] = __('Elevator', 'extra_feeds'); } if (isset($item['b_terrace']) && $item['b_terrace']) { $amenities[] = __('Terrace', 'extra_feeds'); } if (isset($item['b_parking']) && $item['b_parking']) { $amenities[] = __('Parking', 'extra_feeds'); } echo '<listing> <category>' . osc_item_category() . '</category> <description><![CDATA[' . osc_item_description() . ']]></description> <id>' . osc_item_id() . '</id> <title><![CDATA[' . osc_item_title() . ']]></title> <url>' . osc_item_url() . '</url> <address>' . osc_item_address() . '</address> <city>' . osc_item_city() . '</city> <country>' . osc_item_country_code() . '</country> <neighborhood>' . osc_item_city_area() . '</neighborhood> <state>' . osc_item_region() . '</state> <zip_code>' . osc_item_zip() . '</zip_code> <longitude>' . osc_item_longitude() . '</longitude> <latitude>' . osc_item_latitude() . '</latitude> <amenities>' . implode(", ", $amenities) . '</amenities> <bathrooms>' . @$item['i_num_bathrooms'] . '</bathrooms> <bedrooms>' . @$item['i_num_rooms'] . '</bedrooms> <condition>' . @$item['e_status'] . '</condition> <create_time>' . $time[0] . '</create_time> <currency>' . osc_item_currency() . '</currency> <furnished>' . (@$item['b_furnished'] ? 'Furnished' : '') . '</furnished>'; if (osc_count_item_resources() > 0) { if (strpos(osc_resource_type(), 'image') !== FALSE) { echo '<image_url><![CDATA[' . osc_resource_path() . ']]></image_url>'; } } echo '<lot_size>' . $lot_size . '</lot_size> <lot_size_units>square feet</lot_size_units> <price>' . osc_item_price() . '</price> <seller_email>' . osc_item_contact_email() . '</seller_email> <seller_name><![CDATA[' . osc_item_contact_name() . ']]></seller_name> <year>' . @$item['i_year'] . '</year> </listing>'; } } echo '</listings>'; }
function show_qrcode() { $filename = osc_item_id() . "_" . md5(osc_item_url()) . "_" . osc_get_preference("code_size", "qrcode") . ".png"; if (!file_exists(osc_get_preference('upload_path', 'qrcode') . $filename)) { qrcode_generateqr(osc_item_url(), osc_item_id()); } echo '<img src="' . osc_get_preference('upload_url', 'qrcode') . $filename . '" alt="QR CODE" id="qrcode_' . osc_item_id() . '" class="qrcode" />'; }
function indeed() { echo '<?xml version="1.0" encoding="utf-8"?> <source> <publisher>' . osc_page_title() . '</publisher> <publisherurl>' . osc_base_url() . '</publisherurl> <lastBuildDate>' . date("D, j M Y G:i:s T") . '</lastBuildDate>'; if (osc_count_items()) { while (osc_has_items()) { $item = feed_get_job_data(osc_item()); $salary = ""; if (isset($item['i_salary_min']) && $item['i_salary_min'] != '') { $salary = $item['i_salary_min']; } if (isset($item['i_salary_max']) && $item['i_salary_max'] != '') { if ($salary != "") { $salary .= ' - '; } $salary .= $item['i_salary_max']; } if (isset($item['e_salary_period']) && $item['e_slary_period'] != '') { if ($salary != "") { $salary .= ' '; $salary .= $item['e_salary_period']; } } $locale = current($item['locale']); if (isset($locale['s_desired_exp']) && $locale['s_desired_exp'] != '') { $experience = $locale['s_desired_exp']; } else { $experience = ''; } if (isset($locale['s_studies']) && $locale['s_studies'] != '') { $education = $locale['s_studies']; } else { $education = ''; } echo '<job> <title><![CDATA[' . osc_item_title() . ']]></title> <date><![CDATA[' . osc_item_pub_date() . ']]></date> <referencenumber><![CDATA[' . osc_item_id() . ']]></referencenumber> <url><![CDATA[' . osc_item_url() . ']]></url> <company><![CDATA[' . (isset($item['s_company_name']) && $item['s_company_name'] != NULL ? $item['s_company_name'] : '') . ']]></company> <city><![CDATA[' . (osc_item_city() != NULL ? osc_item_city() : '') . ']]></city> <state><![CDATA[' . (osc_item_region() != NULL ? osc_item_region() : '') . ']]></state> <country><![CDATA[' . (osc_item_country() != NULL ? osc_item_country() : '') . ']]></country> <postalcode><![CDATA[' . (osc_item_zip() != NULL ? osc_item_zip() : '') . ']]></postalcode> <description><![CDATA[' . (osc_item_description() != NULL ? osc_item_description() : '') . ']]></description> <salary><![CDATA[' . $salary . ']]></salary> <education><![CDATA[' . $education . ']]></education> <jobtype><![CDATA[' . (isset($item['e_position_type']) && $item['e_position_type'] != NULL ? $item['e_position_type'] : '') . ']]></jobtype> <category><![CDATA[]]></category> <experience><![CDATA[' . $experience . ']]></experience> </job>'; } } echo '</source>'; }
function fn_email_item_validation_non_register_user($item) { View::newInstance()->_exportVariableToView('item', $item); $mPages = new Page(); $aPage = $mPages->findByInternalName('email_item_validation_non_register_user'); $locale = osc_current_user_locale(); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item_url = osc_item_url(); $item_url = '<a href="' . $item_url . '" >' . $item_url . '</a>'; $edit_url = osc_item_edit_url($item['s_secret'], $item['pk_i_id']); $delete_url = osc_item_delete_url($item['s_secret'], $item['pk_i_id']); $all = ''; if (isset($item['locale'])) { foreach ($item['locale'] as $locale => $data) { $locale_name = OSCLocale::newInstance()->listWhere("pk_c_code = '" . $locale . "'"); $all .= '<br/>'; if (isset($locale_name[0]) && isset($locale_name[0]['s_name'])) { $all .= __('Language') . ': ' . $locale_name[0]['s_name'] . '<br/>'; } else { $all .= __('Language') . ': ' . $locale . '<br/>'; } $all .= __('Title') . ': ' . $data['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $data['s_description'] . '<br/>'; $all .= '<br/>'; } } else { $all .= __('Title') . ': ' . $item['s_title'] . '<br/>'; $all .= __('Description') . ': ' . $item['s_description'] . '<br/>'; } // Format activation URL $validation_url = osc_item_activate_url($item['s_secret'], $item['pk_i_id']); $words = array(); $words[] = array('{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}'); $words[] = array($all, $item['s_description'], $item['s_country'], osc_prepare_price($item['s_price']), $item['s_region'], $item['s_city'], $item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], '<a href="' . osc_base_url() . '" >' . osc_base_url() . '</a>', $item['s_title'], $item_url, osc_page_title(), '<a href="' . $validation_url . '" >' . $validation_url . '</a>', $validation_url, '<a href="' . $edit_url . '">' . $edit_url . '</a>', $edit_url, '<a href="' . $delete_url . '">' . $delete_url . '</a>', $delete_url); $title = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_item_validation_non_register_user_title', $content['s_title'])), $words); $body = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_item_validation_non_register_user_description', $content['s_text'])), $words); $emailParams = array('subject' => $title, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); }
/** * Create automatically the url of the item's comments page * * @param string $locale * @return string */ function osc_comment_url($locale = '') { return osc_item_url($locale) . "?comment=" . osc_comment_id(); }
function doModel() { //calling the view... $locales = OSCLocale::newInstance()->listAllEnabled(); $this->_exportVariableToView('locales', $locales); switch ($this->action) { case 'item_add': // post if (osc_reg_user_post() && $this->user == null) { // CHANGEME: This text osc_add_flash_error_message(_m('Only registered users are allowed to post items')); $this->redirectTo(osc_user_login_url()); } $countries = Country::newInstance()->listAll(); $regions = array(); if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') { $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']); } } $this->_exportVariableToView('countries', $countries); $this->_exportVariableToView('regions', $regions); $this->_exportVariableToView('cities', $cities); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } if (Session::newInstance()->_getForm('countryId') != "") { $countryId = Session::newInstance()->_getForm('countryId'); $regions = Region::newInstance()->getByCountry($countryId); $this->_exportVariableToView('regions', $regions); if (Session::newInstance()->_getForm('regionId') != "") { $regionId = Session::newInstance()->_getForm('regionId'); $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regionId); $this->_exportVariableToView('cities', $cities); } } $this->_exportVariableToView('user', $this->user); osc_run_hook('post_item'); $this->doView('item-post.php'); break; case 'item_add_post': //post_item if (osc_reg_user_post() && $this->user == null) { osc_add_flash_error_message(_m('Only registered users are allowed to post items')); $this->redirectTo(osc_base_url(true)); } $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(true); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_post_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } // POST ITEM ( ADD ITEM ) $success = $mItems->add(); if ($success != 1 && $success != 2) { osc_add_flash_error_message($success); $this->redirectTo(osc_item_post_url()); } else { Session::newInstance()->_dropkeepForm('meta_' . $key); if ($success == 1) { osc_add_flash_ok_message(_m('Check your inbox to verify your email address')); } else { osc_add_flash_ok_message(_m('Your item has been published')); } $itemId = Params::getParam('itemId'); $item = $this->itemManager->findByPrimaryKey($itemId); osc_run_hook('posted_item', $item); $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId')); View::newInstance()->_exportVariableToView('category', $category); $this->redirectTo(osc_search_category_url()); } break; case 'item_edit': // edit item $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $item = Item::newInstance()->findByPrimaryKey($id); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } $this->_exportVariableToView('item', $item); osc_run_hook("before_item_edit", $item); $this->doView('item-edit.php'); } else { // add a flash message [ITEM NO EXISTE] osc_add_flash_error_message(_m('Sorry, we don\'t have any items with that ID')); if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } break; case 'item_edit_post': // recoger el secret y el $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $this->_exportVariableToView('item', $item[0]); $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(false); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_post_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $success = $mItems->edit(); osc_run_hook('edited_item', Item::newInstance()->findByPrimaryKey($id)); if ($success == 1) { osc_add_flash_ok_message(_m('Great! We\'ve just updated your item')); $this->redirectTo(osc_base_url(true) . "?page=item&id={$id}"); } else { osc_add_flash_error_message($success); $this->redirectTo(osc_item_edit_url($secret)); } } break; case 'activate': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); View::newInstance()->_exportVariableToView('item', $item[0]); if ($item[0]['b_active'] == 0) { // ACTIVETE ITEM $mItems = new ItemActions(false); $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']); if ($success) { osc_add_flash_ok_message(_m('The item has been validated')); } else { osc_add_flash_error_message(_m('The item can\'t be validated')); } } else { osc_add_flash_error_message(_m('The item has already been validated')); } $this->redirectTo(osc_item_url()); break; case 'item_delete': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $mItems = new ItemActions(false); $success = $mItems->delete($item[0]['s_secret'], $item[0]['pk_i_id']); if ($success) { osc_add_flash_ok_message(_m('Your item has been deleted')); } else { osc_add_flash_error_message(_m('The item you are trying to delete couldn\'t be deleted')); } if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } else { osc_add_flash_error_message(_m('The item you are trying to delete couldn\'t be deleted')); $this->redirectTo(osc_base_url()); } break; case 'mark': $mItem = new ItemActions(false); $id = Params::getParam('id'); $as = Params::getParam('as'); $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); $mItem->mark($id, $as); osc_add_flash_ok_message(_m('Thanks! That\'s very helpful')); $this->redirectTo(osc_item_url()); break; case 'send_friend': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); $this->doView('item-send-friend.php'); break; case 'send_friend_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("friendName", Params::getParam('friendName')); Session::newInstance()->_setForm("friendEmail", Params::getParam('friendEmail')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_send_friend_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $mItem = new ItemActions(false); $success = $mItem->send_friend(); if ($success) { Session::newInstance()->_clearVariables(); $this->redirectTo(osc_item_url()); } else { $this->redirectTo(osc_item_send_friend_url()); } break; case 'contact': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); if (empty($item)) { osc_add_flash_error_message(_m('This item doesn\'t exist')); $this->redirectTo(osc_base_url(true)); } else { $this->_exportVariableToView('item', $item); if (osc_item_is_expired()) { osc_add_flash_error_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller')); $this->redirectTo(osc_item_url()); } if (osc_reg_user_can_contact() && osc_is_web_user_logged_in() || !osc_reg_user_can_contact()) { $this->doView('item-contact.php'); } else { osc_add_flash_error_message(_m('You can\'t contact the seller, only registered users can')); $this->redirectTo(osc_item_url()); } } break; case 'contact_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("phoneNumber", Params::getParam('phoneNumber')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); $this->redirectTo(osc_item_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']); if ($category['i_expiration_days'] > 0) { $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600); $date = time(); if ($item_date < $date && $item['b_premium'] != 1) { // The item is expired, we can not contact the seller osc_add_flash_error_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller')); $this->redirectTo(osc_item_url()); } } $mItem = new ItemActions(false); $result = $mItem->contact(); if (is_string($result)) { osc_add_flash_error_message($result); } else { osc_add_flash_ok_message(_m('We\'ve just sent an e-mail to the seller')); } $this->redirectTo(osc_item_url()); break; case 'add_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); switch ($status) { case -1: $msg = _m('Sorry, we could not save your comment. Try again later'); osc_add_flash_error_message($msg); break; case 1: $msg = _m('Your comment is awaiting moderation'); osc_add_flash_error_message($msg); break; case 2: $msg = _m('Your comment has been approved'); osc_add_flash_ok_message($msg); break; case 3: $msg = _m('Please fill the required fields (name, email)'); osc_add_flash_error_message($msg); break; case 4: $msg = _m('Please type a comment'); osc_add_flash_error_message($msg); break; case 5: $msg = _m('Your comment has been marked as spam'); osc_add_flash_error_message($msg); break; } $this->redirectTo(osc_item_url()); break; case 'delete_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); $itemId = Params::getParam('id'); $commentId = Params::getParam('comment'); $item = Item::newInstance()->findByPrimaryKey($itemId); if (count($item) == 0) { osc_add_flash_error_message(_m('This item doesn\'t exist')); $this->redirectTo(osc_base_url(true)); } View::newInstance()->_exportVariableToView('item', $item); if ($this->userId == null) { osc_add_flash_error_message(_m('You must be logged in to delete a comment')); $this->redirectTo(osc_item_url()); } $commentManager = ItemComment::newInstance(); $aComment = $commentManager->findByPrimaryKey($commentId); if (count($aComment) == 0) { osc_add_flash_error_message(_m('The comment doesn\'t exist')); $this->redirectTo(osc_item_url()); } if ($aComment['b_active'] != 1) { osc_add_flash_error_message(_m('The comment is not active, you cannot delete it')); $this->redirectTo(osc_item_url()); } if ($aComment['fk_i_user_id'] != $this->userId) { osc_add_flash_error_message(_m('The comment was not added by you, you cannot delete it')); $this->redirectTo(osc_item_url()); } $commentManager->deleteByPrimaryKey($commentId); osc_add_flash_ok_message(_m('The comment has been deleted')); $this->redirectTo(osc_item_url()); break; default: if (Params::getParam('id') == '') { $this->redirectTo(osc_base_url()); } if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); // if item doesn't exist redirect to base url if (count($item) == 0) { osc_add_flash_error_message(_m('This item doesn\'t exist')); $this->redirectTo(osc_base_url(true)); } else { if ($item['b_active'] != 1) { if ($this->userId == $item['fk_i_user_id']) { osc_add_flash_error_message(_m('The item hasn\'t been validated. Please validate it in order to show it to the rest of users')); } else { osc_add_flash_error_message(_m('This item hasn\'t been validated')); $this->redirectTo(osc_base_url(true)); } } else { if ($item['b_enabled'] == 0) { osc_add_flash_error_message(_m('The item has been suspended')); $this->redirectTo(osc_base_url(true)); } } $mStats = new ItemStats(); $mStats->increase('i_num_views', $item['pk_i_id']); foreach ($item['locale'] as $k => $v) { $item['locale'][$k]['s_title'] = osc_apply_filter('item_title', $v['s_title']); $item['locale'][$k]['s_description'] = nl2br(osc_apply_filter('item_description', $v['s_description'])); } $this->_exportVariableToView('items', array($item)); osc_run_hook('show_item', $item); $this->doView('item.php'); } break; case 'dashboard': //dashboard... break; } }
function item_success_meta_og() { $image = null; $r = ItemResource::newInstance()->getResource(osc_item_id()); if (isset($r['pk_i_id'])) { $image = (string) osc_base_url() . $r['s_path'] . $r['pk_i_id'] . "_thumbnail." . $r['s_extension']; } $_item = Item::newInstance()->findByPrimaryKey(osc_item_id()); ?> <meta property="og:title" content="<?php echo osc_esc_html($_item['s_title']); ?> "/> <meta property="og:url" content="<?php echo osc_item_url(); ?> "/> <?php if ($image != null) { ?> <meta property="og:image" content="<?php echo $image; ?> "/> <?php } else { ?> <meta property="og:image" content="<?php echo osc_plugin_url(true) . 'item_success/images/no_photo.gif'; ?> "/> <?php } ?> <meta property="og:site_name" content="<?php echo osc_esc_html(meta_title()); ?> "/> <meta property="og:description" content="<?php echo osc_esc_html(osc_highlight($_item['s_description'])); ?> "/> <?php }
function payment_pro_send_email($email) { $item = Item::newInstance()->findByPrimaryKey($email['fk_i_item_id']); $mPages = new Page(); $aPage = $mPages->findByInternalName('payment_pro_email_payment'); $locale = osc_current_user_locale(); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item_url = osc_item_url(); $item_url = '<a href="' . $item_url . '" >' . $item_url . '</a>'; $publish_url = osc_route_url('payment-pro-addcart', array('item' => 'PUB' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'])); $premium_url = osc_route_url('payment-pro-addcart', array('item' => 'PRM' . $item['fk_i_category_id'] . '-' . $item['pk_i_id'])); $words = array(); $words[] = array('{ITEM_ID}', '{CONTACT_NAME}', '{CONTACT_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{PUBLISH_LINK}', '{PUBLISH_URL}', '{PREMIUM_LINK}', '{PREMIUM_URL}', '{START_PUBLISH_FEE}', '{END_PUBLISH_FEE}', '{START_PREMIUM_FEE}', '{END_PREMIUM_FEE}'); $words[] = array($item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], osc_base_url(), $item['s_title'], $item_url, osc_page_title(), '<a href="' . $publish_url . '">' . $publish_url . '</a>', $publish_url, '<a href="' . $premium_url . '">' . $premium_url . '</a>', $premium_url, '', '', '', ''); if ($email['b_publish'] == 0) { $content['s_text'] = preg_replace('|{START_PUBLISH_FEE}(.*){END_PUBLISH_FEE}|', '', $content['s_text']); } if ($email['b_premium'] == 0) { $content['s_text'] = preg_replace('|{START_PREMIUM_FEE}(.*){END_PREMIUM_FEE}|', '', $content['s_text']); } $title = osc_apply_filter('alert_email_payment_pro_title_after', osc_mailBeauty(osc_apply_filter('email_payment_pro_title', osc_apply_filter('alert_email_payment_pro_title', $content['s_title'], $email, $item)), $words), $email, $item); $body = osc_apply_filter('alert_email_payment_pro_description_after', osc_mailBeauty(osc_apply_filter('email_payment_pro_description', osc_apply_filter('alert_email_payment_pro_description', $content['s_text'], $email, $item)), $words), $email, $item); $emailParams = array('subject' => $title, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); }
<?php $data = payment_get_custom(Params::getParam('extra')); $product_type = explode('x', Params::getParam('item_number')); osc_add_flash_info_message(__('We are processing your payment, if we did not finish in a few minutes, please contact us', 'payment')); if ($product_type[0] == 301) { if (osc_is_web_user_logged_in()) { osc_redirect_to(osc_route_url('payment-user-pack')); } else { // THIS SHOULD NOT HAPPEN osc_redirect_to(osc_base_path()); } } else { if (osc_is_web_user_logged_in()) { osc_redirect_to(osc_route_url('payment-user-menu')); } else { View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($product_type[2])); osc_redirect_to(osc_item_url()); } }
function doModel() { osc_run_hook('before_search'); $mCategories = Category::newInstance(); if (osc_rewrite_enabled()) { // IF rewrite is not enabled, skip this part, preg_match is always time&resources consuming task $p_sParams = "/" . Params::getParam('sParams', false, false); if (preg_match_all('|\\/([^,]+),([^\\/]*)|', $p_sParams, $m)) { $l = count($m[0]); for ($k = 0; $k < $l; $k++) { switch ($m[1][$k]) { case osc_get_preference('rewrite_search_country'): $m[1][$k] = 'sCountry'; break; case osc_get_preference('rewrite_search_region'): $m[1][$k] = 'sRegion'; break; case osc_get_preference('rewrite_search_city'): $m[1][$k] = 'sCity'; break; case osc_get_preference('rewrite_search_city_area'): $m[1][$k] = 'sCityArea'; break; case osc_get_preference('rewrite_search_category'): $m[1][$k] = 'sCategory'; break; case osc_get_preference('rewrite_search_user'): $m[1][$k] = 'sUser'; break; case osc_get_preference('rewrite_search_pattern'): $m[1][$k] = 'sPattern'; break; default: break; } $_REQUEST[$m[1][$k]] = $m[2][$k]; $_GET[$m[1][$k]] = $m[2][$k]; unset($_REQUEST['sParams']); unset($_GET['sParams']); unset($_POST['sParams']); } } } //////////////////////////////// //GETTING AND FIXING SENT DATA// //////////////////////////////// $p_sCategory = Params::getParam('sCategory'); if (!is_array($p_sCategory)) { if ($p_sCategory == '') { $p_sCategory = array(); } else { $p_sCategory = explode(",", $p_sCategory); } } $p_sCityArea = Params::getParam('sCityArea'); if (!is_array($p_sCityArea)) { if ($p_sCityArea == '') { $p_sCityArea = array(); } else { $p_sCityArea = explode(",", $p_sCityArea); } } $p_sCity = Params::getParam('sCity'); if (!is_array($p_sCity)) { if ($p_sCity == '') { $p_sCity = array(); } else { $p_sCity = explode(",", $p_sCity); } } $p_sRegion = Params::getParam('sRegion'); if (!is_array($p_sRegion)) { if ($p_sRegion == '') { $p_sRegion = array(); } else { $p_sRegion = explode(",", $p_sRegion); } } $p_sCountry = Params::getParam('sCountry'); if (!is_array($p_sCountry)) { if ($p_sCountry == '') { $p_sCountry = array(); } else { $p_sCountry = explode(",", $p_sCountry); } } $p_sUser = Params::getParam('sUser'); if (!is_array($p_sUser)) { if ($p_sUser == '') { $p_sUser = ''; } else { $p_sUser = explode(",", $p_sUser); } } $p_sPattern = strip_tags(Params::getParam('sPattern')); // ADD TO THE LIST OF LAST SEARCHES if (osc_save_latest_searches()) { if (trim($p_sPattern) != '') { LatestSearches::newInstance()->insert(array('s_search' => trim($p_sPattern), 'd_date' => date('Y-m-d H:i:s'))); } } $p_bPic = Params::getParam('bPic'); $p_bPic == 1 ? $p_bPic = 1 : ($p_bPic = 0); $p_sPriceMin = Params::getParam('sPriceMin'); $p_sPriceMax = Params::getParam('sPriceMax'); //WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting() $p_sOrder = Params::getParam('sOrder'); if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) { $p_sOrder = osc_default_order_field_at_search(); } $old_order = $p_sOrder; //ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES $p_iOrderType = Params::getParam('iOrderType'); $allowedTypesForSorting = Search::getAllowedTypesForSorting(); $orderType = osc_default_order_type_at_search(); foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == $v) { $orderType = $k; break; } } $p_iOrderType = $orderType; $p_sFeed = Params::getParam('sFeed'); $p_iPage = 0; if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') > 0) { $p_iPage = intval(Params::getParam('iPage')) - 1; } if ($p_sFeed != '') { $p_sPageSize = 1000; } $p_sShowAs = Params::getParam('sShowAs'); $aValidShowAsValues = array('list', 'gallery'); if (!in_array($p_sShowAs, $aValidShowAsValues)) { $p_sShowAs = osc_default_show_as_at_search(); } // search results: it's blocked with the maxResultsPerPage@search defined in t_preferences $p_iPageSize = intval(Params::getParam('iPagesize')); if ($p_iPageSize > 0) { if ($p_iPageSize > osc_max_results_per_page_at_search()) { $p_iPageSize = osc_max_results_per_page_at_search(); } } else { $p_iPageSize = osc_default_results_per_page_at_search(); } //FILTERING CATEGORY $bAllCategoriesChecked = false; if (count($p_sCategory) > 0) { foreach ($p_sCategory as $category) { $this->mSearch->addCategory($category); } } else { $bAllCategoriesChecked = true; } //FILTERING CITY_AREA foreach ($p_sCityArea as $city_area) { $this->mSearch->addCityArea($city_area); } $p_sCityArea = implode(", ", $p_sCityArea); //FILTERING CITY foreach ($p_sCity as $city) { $this->mSearch->addCity($city); } $p_sCity = implode(", ", $p_sCity); //FILTERING REGION foreach ($p_sRegion as $region) { $this->mSearch->addRegion($region); } $p_sRegion = implode(", ", $p_sRegion); //FILTERING COUNTRY foreach ($p_sCountry as $country) { $this->mSearch->addCountry($country); } $p_sCountry = implode(", ", $p_sCountry); // FILTERING PATTERN if ($p_sPattern != '') { $this->mSearch->addPattern($p_sPattern); $osc_request['sPattern'] = $p_sPattern; } else { // hardcoded - if there isn't a search pattern, order by dt_pub_date desc if ($p_sOrder == 'relevance') { $p_sOrder = 'dt_pub_date'; foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == 'desc') { $orderType = $k; break; } } $p_iOrderType = $orderType; } } // FILTERING USER if ($p_sUser != '') { $this->mSearch->fromUser($p_sUser); } // FILTERING IF WE ONLY WANT ITEMS WITH PICS if ($p_bPic) { $this->mSearch->withPicture(true); } //FILTERING BY RANGE PRICE $this->mSearch->priceRange($p_sPriceMin, $p_sPriceMax); //ORDERING THE SEARCH RESULTS $this->mSearch->order($p_sOrder, $allowedTypesForSorting[$p_iOrderType]); //SET PAGE $this->mSearch->page($p_iPage, $p_iPageSize); osc_run_hook('search_conditions', Params::getParamsAsArray()); if (!Params::existParam('sFeed')) { // RETRIEVE ITEMS AND TOTAL $aItems = $this->mSearch->doSearch(); $iTotalItems = $this->mSearch->count(); $iStart = $p_iPage * $p_iPageSize; $iEnd = min(($p_iPage + 1) * $p_iPageSize, $iTotalItems); $iNumPages = ceil($iTotalItems / $p_iPageSize); osc_run_hook('search', $this->mSearch); //preparing variables... $regionName = $p_sRegion; if (is_numeric($p_sRegion)) { $r = Region::newInstance()->findByPrimaryKey($p_sRegion); if ($r) { $regionName = $r['s_name']; } } $cityName = $p_sCity; if (is_numeric($p_sCity)) { $c = City::newInstance()->findByPrimaryKey($p_sCity); if ($c) { $cityName = $c['s_name']; } } //$this->_exportVariableToView('non_empty_categories', $aCategories) ; $this->_exportVariableToView('search_start', $iStart); $this->_exportVariableToView('search_end', $iEnd); $this->_exportVariableToView('search_category', $p_sCategory); // hardcoded - non pattern and order by relevance $p_sOrder = $old_order; $this->_exportVariableToView('search_order_type', $p_iOrderType); $this->_exportVariableToView('search_order', $p_sOrder); $this->_exportVariableToView('search_pattern', $p_sPattern); $this->_exportVariableToView('search_from_user', $p_sUser); $this->_exportVariableToView('search_total_pages', $iNumPages); $this->_exportVariableToView('search_page', $p_iPage); $this->_exportVariableToView('search_has_pic', $p_bPic); $this->_exportVariableToView('search_region', $regionName); $this->_exportVariableToView('search_city', $cityName); $this->_exportVariableToView('search_price_min', $p_sPriceMin); $this->_exportVariableToView('search_price_max', $p_sPriceMax); $this->_exportVariableToView('search_total_items', $iTotalItems); $this->_exportVariableToView('items', $aItems); $this->_exportVariableToView('search_show_as', $p_sShowAs); $this->_exportVariableToView('search', $this->mSearch); // json $json = $this->mSearch->toJson(); $this->_exportVariableToView('search_alert', base64_encode($json)); //calling the view... $this->doView('search.php'); } else { $this->mSearch->page(0, osc_num_rss_items()); // RETRIEVE ITEMS AND TOTAL $iTotalItems = $this->mSearch->count(); $aItems = $this->mSearch->doSearch(); $this->_exportVariableToView('items', $aItems); if ($p_sFeed == '' || $p_sFeed == 'rss') { // FEED REQUESTED! header('Content-type: text/xml; charset=utf-8'); $feed = new RSSFeed(); $feed->setTitle(__('Latest listings added') . ' - ' . osc_page_title()); $feed->setLink(osc_base_url()); $feed->setDescription(__('Latest listings added in') . ' ' . osc_page_title()); if (osc_count_items() > 0) { while (osc_has_items()) { if (osc_count_item_resources() > 0) { osc_has_item_resources(); $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8"), 'description' => osc_item_description(), 'dt_pub_date' => osc_item_pub_date(), 'image' => array('url' => htmlentities(osc_resource_thumbnail_url(), ENT_COMPAT, "UTF-8"), 'title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8")))); } else { $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8"), 'description' => osc_item_description(), 'dt_pub_date' => osc_item_pub_date())); } } } osc_run_hook('feed', $feed); $feed->dumpXML(); } else { osc_run_hook('feed_' . $p_sFeed, $aItems); } } }
public static function ajaxPayment() { $status = self::processPayment(); $data = payment_get_custom(Params::getParam('extra')); $product_type = explode('x', $data['product']); if ($status == PAYMENT_COMPLETED) { osc_add_flash_ok_message(sprintf(__('Success! Please write down this transaction ID in case you have any problem: %s', 'payment'), Params::getParam('stripe_transaction_id'))); if ($product_type[0] == 101) { $item = Item::newInstance()->findByPrimaryKey($product_type[2]); $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']); View::newInstance()->_exportVariableToView('category', $category); payment_js_redirect_to(osc_search_category_url()); } else { if ($product_type[0] == 201) { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-menu')); } else { View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($product_type[2])); payment_js_redirect_to(osc_item_url()); } } else { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-pack')); } else { // THIS SHOULD NOT HAPPEN payment_js_redirect_to(osc_base_path()); } } } } else { if ($status == PAYMENT_ALREADY_PAID) { osc_add_flash_warning_message(__('Warning! This payment was already paid', 'payment')); } else { osc_add_flash_error_message(_e('There were an error processing your payment', 'payment')); } if ($product_type[0] == 301) { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-pack')); } else { // THIS SHOULD NOT HAPPEN payment_js_redirect_to(osc_base_path()); } } else { if (osc_is_web_user_logged_in()) { payment_js_redirect_to(osc_route_url('payment-user-menu')); } else { View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($product_type[2])); payment_js_redirect_to(osc_item_url()); } } } }
function twitter_breadcrumb($separator = '/') { $breadcrumb = array(); $text = ''; $location = Rewrite::newInstance()->get_location(); $section = Rewrite::newInstance()->get_section(); $separator = '<span class="divider">' . trim($separator) . '</span>'; $page_title = '<li><a href="' . osc_base_url() . '">' . osc_page_title() . '</a>' . $separator . '</li>'; switch ($location) { case 'item': switch ($section) { case 'item_add': break; default: $aCategories = Category::newInstance()->toRootTree((string) osc_item_category_id()); $category = ''; if (count($aCategories) == 0) { break; } foreach ($aCategories as $aCategory) { $list[] = '<li><a href="' . osc_item_category_url($aCategory['pk_i_id']) . '">' . $aCategory['s_name'] . '</a>' . $separator . '</li>'; } $category = implode('', $list); break; } switch ($section) { case 'item_add': $text = $page_title . '<li>' . __('Publish an item', 'twitter') . '</li>'; break; case 'item_edit': $text = $page_title . '<li><a href="' . osc_item_url() . '">' . osc_item_title() . '</a>' . $separator . '</li><li>' . __('Edit your item', 'twitter') . '</li>'; break; case 'send_friend': $text = $page_title . $category . '<li><a href="' . osc_item_url() . '">' . osc_item_title() . '</a>' . $separator . '</li><li>' . __('Send to a friend', 'twitter') . '</li>'; break; case 'contact': $text = $page_title . $category . '<li><a href="' . osc_item_url() . '">' . osc_item_title() . '</a>' . $separator . '<li><li>' . __('Contact seller', 'twitter') . '</li>'; break; default: $text = $page_title . $category . '<li>' . osc_item_title() . '</li>'; break; } break; case 'page': $text = $page_title . '<li>' . osc_static_page_title() . '</li>'; break; case 'search': $region = Params::getParam('sRegion'); $city = Params::getParam('sCity'); $pattern = Params::getParam('sPattern'); $category = osc_search_category_id(); $category = count($category) == 1 ? $category[0] : ''; $b_show_all = $pattern == '' && $category == '' && $region == '' && $city == ''; $b_category = $category != ''; $b_pattern = $pattern != ''; $b_region = $region != ''; $b_city = $city != ''; $b_location = $b_region || $b_city; if ($b_show_all) { $text = $page_title . '<li>' . __('Search', 'twitter') . '</li>'; break; } // init $result = $page_title; if ($b_category) { $list = array(); $aCategories = Category::newInstance()->toRootTree($category); if (count($aCategories) > 0) { $deep = 1; foreach ($aCategories as $single) { $list[] = '<li><a href="' . osc_item_category_url($single['pk_i_id']) . '">' . $single['s_name'] . '</a>' . $separator . '</li>'; $deep++; } // remove last link if (!$b_pattern && !$b_location) { $list[count($list) - 1] = preg_replace('|<li><a href.*?>(.*?)</a>.*?</li>|', '$01', $list[count($list) - 1]); } $result .= implode('', $list); } } if ($b_location) { $list = array(); $params = array(); if ($b_category) { $params['sCategory'] = $category; } if ($b_city) { $aCity = City::newInstance()->findByName($city); if (count($aCity) == 0) { $params['sCity'] = $city; $list[] = '<li><a href="' . osc_search_url($params) . '">' . $city . '</a>' . $separator . '</li>'; } else { $aRegion = Region::newInstance()->findByPrimaryKey($aCity['fk_i_region_id']); $params['sRegion'] = $aRegion['s_name']; $list[] = '<li><a href="' . osc_search_url($params) . '">' . $aRegion['s_name'] . '</a>' . $separator . '</li>'; $params['sCity'] = $aCity['s_name']; $list[] = '<li><a href="' . osc_search_url($params) . '">' . $aCity['s_name'] . '</a>' . $separator . '</li>'; } if (!$b_pattern) { $list[count($list) - 1] = preg_replace('|<li><a href.*?>(.*?)</a>.*?</li>|', '$01', $list[count($list) - 1]); } $result .= implode('', $list); } else { if ($b_region) { $params['sRegion'] = $region; $list[] = '<li><a href="' . osc_search_url($params) . '">' . $region . '</a>' . $separator . '</li>'; if (!$b_pattern) { $list[count($list) - 1] = preg_replace('|<li><a href.*?>(.*?)</a>.*?</li>|', '$01', $list[count($list) - 1]); } $result .= implode('', $list); } } } if ($b_pattern) { $result .= '<li>' . __('Search Results', 'twitter') . ': ' . $pattern . '</li>'; } // remove last separator $result = preg_replace('|' . trim($separator) . '\\s*$|', '', $result); $text = $result; break; case 'login': switch ($section) { case 'recover': $text = $page_title . '<li>' . __('Recover your password', 'twitter') . '</li>'; break; default: $text = $page_title . '<li>' . __('Login', 'twitter') . '</li>'; } break; case 'register': $text = $page_title . '<li>' . __('Create a new account', 'twitter') . '</li>'; break; case 'contact': $text = $page_title . '<li>' . __('Contact', 'twitter') . '</li>'; break; default: break; } return '<ul class="breadcrumb">' . $text . '</ul>'; }
private function processDataReported($items) { if(!empty($items)) { $csrf_token_url = osc_csrf_token_url(); foreach($items as $aRow) { View::newInstance()->_exportVariableToView('item', $aRow); $row = array(); $options = array(); // -- prepare data -- // prepare item title $title = mb_substr($aRow['s_title'], 0, 30, 'UTF-8'); if($title != $aRow['s_title']) { $title .= '...'; } $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=all">' . __('Clear All') .'</a>'; if( $aRow['i_num_spam'] > 0 ) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=spam">' . __('Clear Spam') .'</a>'; } if( $aRow['i_num_bad_classified'] > 0 ) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=bad">' . __('Clear Misclassified') .'</a>'; } if( $aRow['i_num_repeated'] > 0 ) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=duplicated">' . __('Clear Duplicated') .'</a>'; } if( $aRow['i_num_offensive'] > 0 ) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=offensive">' . __('Clear Offensive') .'</a>'; } if( $aRow['i_num_expired'] > 0 ) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&stat=expired">' . __('Clear Expired') .'</a>'; } if(count($options) > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=item_edit&id=' . $aRow['pk_i_id'] . '">' . __('Edit') . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" href="' . osc_admin_base_url(true) . '?page=items&action=delete&id[]=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '">' . __('Delete') . '</a>'; } // create list of actions $auxOptions = '<ul>'.PHP_EOL; foreach( $options as $actual ) { $auxOptions .= '<li>'.$actual.'</li>'.PHP_EOL; } $auxOptions .= '</ul>'.PHP_EOL; $actions = '<div class="actions">'.$auxOptions.'</div>'.PHP_EOL; // fill a row $row['bulkactions'] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" active="' . $aRow['b_active'] . '" blocked="' . $aRow['b_enabled'] . '"/>'; $row['title'] = '<a href="' . osc_item_url().'" target="_blank">' . $title . '</a>'. $actions; $row['user'] = $aRow['s_user_name']; $row['spam'] = $aRow['i_num_spam']; $row['bad'] = $aRow['i_num_bad_classified']; $row['rep'] = $aRow['i_num_repeated']; $row['exp'] = $aRow['i_num_expired']; $row['off'] = $aRow['i_num_offensive']; $row['date'] = osc_format_date($aRow['dt_pub_date']); $row['expiration'] = ($aRow['dt_expiration'] != '9999-12-31 23:59:59') ? osc_format_date($aRow['dt_expiration']) : __('Never expires'); $row = osc_apply_filter('items_processing_reported_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
function doModel() { //calling the view... $locales = OSCLocale::newInstance()->listAllEnabled(); $this->_exportVariableToView('locales', $locales); switch ($this->action) { case 'item_add': // post if (!osc_users_enabled()) { osc_add_flash_message(_m('Users not enabled')); $this->redirectTo(osc_base_url(true)); } if (osc_reg_user_post() && $this->user == null) { // CHANGEME: This text osc_add_flash_message(_m('Only registered users are allowed to post items')); $this->redirectTo(osc_user_login_url()); } $countries = Country::newInstance()->listAll(); $regions = array(); if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') { $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']); } } $this->_exportVariableToView('countries', $countries); $this->_exportVariableToView('regions', $regions); $this->_exportVariableToView('cities', $cities); $this->_exportVariableToView('user', $this->user); osc_run_hook('post_item'); $this->doView('item-post.php'); break; case 'item_add_post': //post_item if (!osc_users_enabled()) { osc_add_flash_message(_m('Users not allowed')); $this->redirectTo(osc_base_url(true)); } if (osc_reg_user_post() && $this->user == null) { osc_add_flash_message(_m('Only registered users are allowed to post items')); $this->redirectTo(osc_base_url(true)); } // POST ITEM ( ADD ITEM ) $mItems = new ItemActions(false); $success = $mItems->add(); if ($success) { $PcontactName = Params::getParam('contactName'); $PcontactEmail = Params::getParam('contactEmail'); $itemId = Params::getParam('itemId'); $item = array(); if (Session::newInstance()->_get('userId') == '') { $mPages = new Page(); $aPage = $mPages->findByInternalName('email_new_item_non_register_user'); $locale = osc_current_user_locale(); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item = $this->itemManager->findByPrimaryKey($itemId); $item_url = osc_item_url(); // before page = user , action = item_edit $edit_url = osc_item_edit_url($item['s_secret'], $itemId); // before page = user , action = item_delete $delete_url = osc_item_delete_url($item['s_secret'], $itemId); $words = array(); $words[] = array('{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}'); $words[] = array($itemId, $PcontactName, $PcontactEmail, osc_base_url(), $item['s_title'], $item_url, osc_page_title(), '<a href="' . $edit_url . '">' . $edit_url . '</a>', $edit_url, '<a href="' . $delete_url . '">' . $delete_url . '</a>', $delete_url); $title = osc_mailBeauty($content['s_title'], $words); $body = osc_mailBeauty($content['s_text'], $words); $emailParams = array('subject' => $title, 'to' => $PcontactEmail, 'to_name' => $PcontactName, 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); } osc_run_hook('posted_item', $item); $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId')); View::newInstance()->_exportVariableToView('category', $category); $this->redirectTo(osc_search_category_url()); } else { $this->redirectTo(osc_item_post_url()); } break; case 'item_edit': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $item = Item::newInstance()->findByPrimaryKey($id); $categories = Category::newInstance()->toTree(); $countries = Country::newInstance()->listAll(); $regions = array(); if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') { $regions = Region::newInstance()->getByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->getByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->listWhere("fk_i_region_id = %d", $regions[0]['pk_i_id']); } } $currencies = Currency::newInstance()->listAll(); $this->_exportVariableToView('item', $item); //$this->_exportVariableToView('user', $this->user) ; $this->doView('item-edit.php'); } else { // add a flash message [ITEM NO EXISTE] //$this->redirectTo(osc_base_url(true)); osc_add_flash_message(_m('Sorry, we don\'t have any items with that ID')); if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } break; case 'item_edit_post': // recoger el secret y el $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $this->_exportVariableToView('item', $item[0]); $mItems = new ItemActions(false); $success = $mItems->edit(); if ($success) { osc_add_flash_message(_m('Great! We\'ve just updated your item')); $this->redirectTo(osc_base_url(true) . "?page=item&id={$id}"); } else { $this->redirectTo(osc_item_edit_url($secret)); } } break; case 'activate': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); View::newInstance()->_exportVariableToView('item', $item[0]); if ($item[0]['e_status'] == 'INACTIVE') { // ACTIVETE ITEM $mItems = new ItemActions(false); $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']); if ($success) { osc_add_flash_message(_m('The item has been validated')); } else { osc_add_flash_message(_m('The item can\'t be validated')); } } else { osc_add_flash_message(_m('The item has already been validated')); } $this->redirectTo(osc_item_url()); break; case 'item_delete': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", $id, $secret, $this->userId); if (count($item) == 1) { $mItems = new ItemActions(false); $success = $mItems->delete($item[0]['s_secret'], $item[0]['pk_i_id']); if ($success) { osc_add_flash_message(_m('Your item has been deleted')); } else { osc_add_flash_message(_m('The item you are trying to delete couldn\'t be deleted')); } if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } else { osc_add_flash_message(_m('The item you are trying to delete couldn\'t be deleted')); $this->redirectTo(osc_base_url()); } break; case 'deleteResource': $id = Params::getParam('id'); $item = Params::getParam('item'); $code = Params::getParam('code'); $secret = Params::getParam('secret'); // Check for required fields if (!(is_numeric($id) && is_numeric($item) && preg_match('/^([a-z0-9]+)$/i', $code))) { osc_add_flash_message(_m("The selected photo couldn't be deleted, the url doesn't exist")); if ($this->userId == null) { $this->redirectTo(osc_base_url()); } else { $this->redirectTo(osc_user_dashboard_url()); } } $aItem = $this->itemManager->findByPrimaryKey($item); // Check if the item exists if (count($aItem) == 0) { osc_add_flash_message(_m('The item doesn\'t exist')); $this->redirectTo(osc_base_url()); } // Check if the item belong to the user if ($this->userId != null && $this->userId != $aItem['fk_i_user_id']) { osc_add_flash_message(_m('The item doesn\'t belong to you')); $this->redirectTo(osc_item_url_ns($item)); } // Check if the secret passphrase match with the item if ($this->userId == null && $secret != $aItem['s_secret']) { osc_add_flash_message(_m('The item doesn\'t belong to you')); $this->redirectTo(osc_item_url_ns($item)); } // Does id & code combination exist? $result = ItemResource::newInstance()->getResourceSecure($id, $code); if ($result > 0) { // Delete: file, db table entry osc_deleteResource($id); ItemResource::newInstance()->delete(array('pk_i_id' => $id, 'fk_i_item_id' => $item, 's_name' => $code)); osc_add_flash_message(_m('The selected photo has been successfully deleted')); } else { osc_add_flash_message(_m("The selected photo couldn't be deleted")); } // Redirect to item_edit. If unregistered user, include $secret. $this->redirectTo(osc_item_edit_url($secret, $item)); break; case 'mark': $mItem = new ItemActions(false); $id = Params::getParam('id'); $as = Params::getParam('as'); $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); $mItem->mark($id, $as); osc_add_flash_message(_m('Thanks! That\'s very helpful')); $this->redirectTo(osc_item_url()); break; case 'send_friend': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); $this->doView('item-send-friend.php'); break; case 'send_friend_post': $mItem = new ItemActions(false); $mItem->send_friend(); $item_url = Params::getParam('item_url'); $this->redirectTo($item_url); break; case 'contact': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']); if ($category['i_expiration_days'] > 0) { $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600); $date = time(); if ($item_date < $date) { // The item is expired, we can not contact the seller osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller')); $this->redirectTo(osc_create_item_url($item)); } } $this->_exportVariableToView('item', $item); $this->doView('item-contact.php'); break; case 'contact_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $category = Category::newInstance()->findByPrimaryKey($item['fk_i_category_id']); if ($category['i_expiration_days'] > 0) { $item_date = strtotime($item['dt_pub_date']) + $category['i_expiration_days'] * (24 * 3600); $date = time(); if ($item_date < $date) { // The item is expired, we can not contact the seller osc_add_flash_message(_m('We\'re sorry, but the item has expired. You can\'t contact the seller')); $this->redirectTo(osc_item_url()); } } $mItem = new ItemActions(false); $mItem->contact(); osc_add_flash_message(_m('We\'ve just sent an e-mail to the seller')); $this->redirectTo(osc_item_url()); break; case 'add_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); switch ($status) { case -1: $msg = _m('Sorry, we could not save your comment. Try again later'); break; case 1: $msg = _m('Your comment is awaiting moderation'); break; case 2: $msg = _m('Your comment has been approved'); break; case 3: $msg = _m('Please fill the required fields (name, email)'); break; case 4: $msg = _m('Please type a comment'); break; case 5: $msg = _m('Your comment has been marked as spam'); break; } osc_add_flash_message($msg); $this->redirectTo(Params::getParam('itemURL')); break; case 'delete_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); $itemId = Params::getParam('id'); $commentId = Params::getParam('comment'); $item = Item::newInstance()->findByPrimaryKey($itemId); if (count($item) == 0) { osc_add_flash_message(_m('This item doesn\'t exist')); $this->redirectTo(osc_base_url(true)); } View::newInstance()->_exportVariableToView('item', $item); if ($this->userId == null) { osc_add_flash_message(_m('You have to be logged to delete a comment')); $this->redirectTo(osc_item_url()); } $commentManager = ItemComment::newInstance(); $aComment = $commentManager->findByPrimaryKey($commentId); if (count($aComment) == 0) { osc_add_flash_message(_m('The comment doesn\'t exist')); $this->redirectTo(osc_item_url()); } if ($aComment['e_status'] != 'ACTIVE') { osc_add_flash_message(_m('The comment is not active, you cannot delete it')); $this->redirectTo(osc_item_url()); } if ($aComment['fk_i_user_id'] != $this->userId) { osc_add_flash_message(_m('You cannot delete the comment')); $this->redirectTo(osc_item_url()); } $commentManager->deleteByPrimaryKey($commentId); osc_add_flash_message(_m('The comment has been deleted correctly')); $this->redirectTo(osc_item_url()); break; default: if (Params::getParam('id') == '') { $this->redirectTo(osc_base_url()); } if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); // if item doesn't exist redirect to base url if (count($item) == 0) { osc_add_flash_message(_m('This item doesn\'t exist')); $this->redirectTo(osc_base_url(true)); } else { if ($item['e_status'] != 'ACTIVE') { if ($this->userId == $item['fk_i_user_id']) { osc_add_flash_message(_m('The item hasn\'t been validated. Please validate it in order to show it to the rest of users')); } else { osc_add_flash_message(_m('This item hasn\'t been validated')); $this->redirectTo(osc_base_url(true)); } } $mStats = new ItemStats(); $mStats->increase('i_num_views', $item['pk_i_id']); foreach ($item['locale'] as $k => $v) { $item['locale'][$k]['s_title'] = osc_apply_filter('item_title', $v['s_title']); $item['locale'][$k]['s_description'] = nl2br(osc_apply_filter('item_description', $v['s_description'])); } $this->_exportVariableToView('items', array($item)); osc_run_hook('show_item', $item); $this->doView('item.php'); } break; case 'dashboard': //dashboard... break; } }
/** * new Design - return array * @return type */ private function toArrayFormatReported() { $this->result['iTotalRecords'] = $this->total_filtered; $this->result['iTotalDisplayRecords'] = $this->total; $this->result['sColumns'] = $this->sColumns; $this->result['iDisplayLength'] = $this->_get['iDisplayLength']; $this->result['aaData'] = array(); if (count($this->items) == 0) { return; } $this->result['aaObject'] = $this->items; $count = 0; foreach ($this->items as $aRow) { View::newInstance()->_exportVariableToView('item', $aRow); $row = array(); $options = array(); // -- prepare data -- // prepare item title $title = mb_substr($aRow['s_title'], 0, 30, 'utf-8'); if ($title != $aRow['s_title']) { $title .= '...'; } $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=all">' . __('Clear All') . '</a>'; if ($aRow['i_num_spam'] > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=spam">' . __('Clear Spam') . '</a>'; } if ($aRow['i_num_bad_classified'] > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=bad">' . __('Clear Misclassified') . '</a>'; } if ($aRow['i_num_repeated'] > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=duplicated">' . __('Clear Duplicated') . '</a>'; } if ($aRow['i_num_offensive'] > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=offensive">' . __('Clear Offensive') . '</a>'; } if ($aRow['i_num_expired'] > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&id=' . $aRow['pk_i_id'] . '&stat=expired">' . __('Clear Expired') . '</a>'; } if (count($options) > 0) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=item_edit&id=' . $aRow['pk_i_id'] . '">' . __('Edit') . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" href="' . osc_admin_base_url(true) . '?page=items&action=delete&id[]=' . $aRow['pk_i_id'] . '">' . __('Delete') . '</a>'; } // create list of actions $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $auxOptions .= '</ul>' . PHP_EOL; $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; // fill a row $row[] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" active="' . $aRow['b_active'] . '" blocked="' . $aRow['b_enabled'] . '"/>'; $row[] = '<a href="' . osc_item_url() . '" target="_blank">' . $title . '</a>' . $actions; $row[] = $aRow['s_user_name']; $row[] = $aRow['i_num_spam']; $row[] = $aRow['i_num_bad_classified']; $row[] = $aRow['i_num_repeated']; $row[] = $aRow['i_num_expired']; $row[] = $aRow['i_num_offensive']; $row[] = $aRow['dt_pub_date']; $count++; $this->result['aaData'][] = $row; } return; }
function doModel() { $mCategories = new Category(); $aCategories = $mCategories->findRootCategories(); $mCategoryStats = new CategoryStats(); //////////////////////////////// //GETTING AND FIXING SENT DATA// //////////////////////////////// $p_sCategory = Params::getParam('sCategory'); if (!is_array($p_sCategory)) { if ($p_sCategory == '') { $p_sCategory = array(); } else { $p_sCategory = explode(",", $p_sCategory); } } $p_sCity = Params::getParam('sCity'); if (!is_array($p_sCity)) { if ($p_sCity == '') { $p_sCity = array(); } else { $p_sCity = explode(",", $p_sCity); } } $p_sRegion = Params::getParam('sRegion'); if (!is_array($p_sRegion)) { if ($p_sRegion == '') { $p_sRegion = array(); } else { $p_sRegion = explode(",", $p_sRegion); } } $p_sCountry = Params::getParam('sCountry'); if (!is_array($p_sCountry)) { if ($p_sCountry == '') { $p_sCountry = array(); } else { $p_sCountry = explode(",", $p_sCountry); } } $p_sPattern = strip_tags(Params::getParam('sPattern')); $p_bPic = Params::getParam('bPic'); $p_bPic == 1 ? $p_bPic = 1 : ($p_bPic = 0); $p_sPriceMin = Params::getParam('sPriceMin'); $p_sPriceMax = Params::getParam('sPriceMax'); //WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting() $p_sOrder = Params::getParam('sOrder'); if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) { $p_sOrder = osc_default_order_field_at_search(); } //ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES $p_iOrderType = Params::getParam('iOrderType'); $allowedTypesForSorting = Search::getAllowedTypesForSorting(); $orderType = osc_default_order_type_at_search(); foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == $v) { $orderType = $k; break; } } $p_iOrderType = $orderType; $p_sFeed = Params::getParam('sFeed'); $p_iPage = intval(Params::getParam('iPage')); if ($p_sFeed != '') { $p_sPageSize = 1000; } $p_sShowAs = Params::getParam('sShowAs'); $aValidShowAsValues = array('list', 'gallery'); if (!in_array($p_sShowAs, $aValidShowAsValues)) { $p_sShowAs = osc_default_show_as_at_search(); } // search results: it's blocked with the maxResultsPerPage@search defined in t_preferences $p_iPageSize = intval(Params::getParam('iPagesize')); if ($p_iPageSize > 0) { if ($p_iPageSize > osc_max_results_per_page_at_search()) { $p_iPageSize = osc_max_results_per_page_at_search(); } } else { $p_iPageSize = osc_default_results_per_page_at_search(); } //FILTERING CATEGORY $bAllCategoriesChecked = false; if (count($p_sCategory) > 0) { foreach ($p_sCategory as $category) { $this->mSearch->addCategory($category); } } else { $bAllCategoriesChecked = true; } //FILTERING CITY foreach ($p_sCity as $city) { $this->mSearch->addCity($city); } $p_sCity = implode(", ", $p_sCity); //FILTERING REGION foreach ($p_sRegion as $region) { $this->mSearch->addRegion($region); } $p_sRegion = implode(", ", $p_sRegion); //FILTERING COUNTRY foreach ($p_sCountry as $country) { $this->mSearch->addCountry($country); } $p_sCountry = implode(", ", $p_sCountry); // FILTERING PATTERN if ($p_sPattern != '') { $this->mSearch->addConditions(sprintf("(d.s_title LIKE '%%%s%%' OR d.s_description LIKE '%%%s%%')", $p_sPattern, $p_sPattern)); $osc_request['sPattern'] = $p_sPattern; } // FILTERING IF WE ONLY WANT ITEMS WITH PICS if ($p_bPic) { $this->mSearch->withPicture(true); } //FILTERING BY RANGE PRICE $this->mSearch->priceRange($p_sPriceMin, $p_sPriceMax); //ORDERING THE SEARCH RESULTS $this->mSearch->order($p_sOrder, $allowedTypesForSorting[$p_iOrderType]); //SET PAGE $this->mSearch->page($p_iPage, $p_iPageSize); osc_run_hook('search_conditions', Params::getParamsAsArray()); $this->mSearch->addConditions(sprintf("%st_item.e_status = 'ACTIVE' ", DB_TABLE_PREFIX)); // RETRIEVE ITEMS AND TOTAL $iTotalItems = $this->mSearch->count(); $aItems = $this->mSearch->doSearch(); if (!Params::existParam('sFeed')) { $iStart = $p_iPage * $p_iPageSize; $iEnd = min(($p_iPage + 1) * $p_iPageSize, $iTotalItems); //Static data, which is the point? /*$aOrders = array( __('Newly listed') => array('sOrder' => 'dt_pub_date', 'iOrderType' => 'desc') ,__('Lower price first') => array('sOrder' => 'f_price', 'iOrderType' => 'asc') ,__('Higher price first') => array('sOrder' => 'f_price', 'iOrderType' => 'desc') );*/ $iNumPages = ceil($iTotalItems / $p_iPageSize); //Categories for select at view "search.php" $mCategories = new Category(); $aCategories = $mCategories->findRootCategories(); $mCategoryStats = new CategoryStats(); $aCategories = $mCategories->toTree(); foreach ($aCategories as $k => $v) { $iCategoryNumItems = CategoryStats::newInstance()->getNumItems($v); if ($iCategoryNumItems > 0) { $aCategories[$k]['total'] = $iCategoryNumItems; } else { unset($aCategories[$k]); } } osc_run_hook('search', $this->mSearch); //preparing variables... $this->_exportVariableToView('categories', $aCategories); $this->_exportVariableToView('search_start', $iStart); $this->_exportVariableToView('search_end', $iEnd); $this->_exportVariableToView('search_category', $p_sCategory); $this->_exportVariableToView('search_order_type', $p_iOrderType); $this->_exportVariableToView('search_order', $p_sOrder); $this->_exportVariableToView('search_pattern', $p_sPattern); $this->_exportVariableToView('search_total_pages', $iNumPages); $this->_exportVariableToView('search_page', $p_iPage); $this->_exportVariableToView('search_has_pic', $p_bPic); $this->_exportVariableToView('search_city', $p_sCity); $this->_exportVariableToView('search_price_min', $p_sPriceMin); $this->_exportVariableToView('search_price_max', $p_sPriceMax); $this->_exportVariableToView('search_total_items', $iTotalItems); $this->_exportVariableToView('items', $aItems); $this->_exportVariableToView('search_show_as', $p_sShowAs); $this->_exportVariableToView('search', $this->mSearch); //calling the view... $this->doView('search.php'); } else { $this->_exportVariableToView('items', $aItems); if ($p_sFeed == '' || $p_sFeed == 'rss') { // FEED REQUESTED! header('Content-type: text/xml; charset=utf-8'); $feed = new RSSFeed(); $feed->setTitle(__('Latest items added') . ' - ' . osc_page_title()); $feed->setLink(osc_base_url()); $feed->setDescription(__('Latest items added in') . ' ' . osc_page_title()); if (osc_count_items() > 0) { while (osc_has_items()) { $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url()), 'description' => osc_item_description())); } } osc_run_hook('feed', $feed); $feed->dumpXML(); } else { osc_run_hook('feed_' . $p_sFeed, $aItems); } } }
private function toDatatablesFormat() { $this->result['iTotalRecords'] = $this->total_filtered; $this->result['iTotalDisplayRecords'] = $this->total; $this->result['sEcho'] = $this->sEcho; $this->result['sColumns'] = $this->sColumns; $this->result['aaData'] = array(); if (count($this->items) == 0) { return; } $count = 0; foreach ($this->items as $aRow) { View::newInstance()->_exportVariableToView('item', $aRow); $row = array(); $options = array(); // prepare data $title = mb_substr($aRow['s_title'], 0, 30, 'utf-8'); if ($title != $aRow['s_title']) { $title .= '...'; } $options[] = '<a href="' . osc_item_url() . '">' . __('View item') . '</a>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=list&id=' . $aRow['pk_i_id'] . '">' . __('View comments') . '</a>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=media&action=list&id=' . $aRow['pk_i_id'] . '">' . __('View media') . '</a>'; if ($aRow['b_active']) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status&id=' . $aRow['pk_i_id'] . '&value=INACTIVE">' . __('Deactivate') . '</a>'; } else { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status&id=' . $aRow['pk_i_id'] . '&value=ACTIVE">' . __('Activate') . '</a>'; } if ($aRow['b_enabled']) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status&id=' . $aRow['pk_i_id'] . '&value=DISABLE">' . __('Block') . '</a>'; } else { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status&id=' . $aRow['pk_i_id'] . '&value=ENABLE">' . __('Unblock') . '</a>'; } if ($aRow['b_premium']) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status_premium&id=' . $aRow['pk_i_id'] . '&value=0">' . __('Unmark as premium') . '</a>'; } else { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status_premium&id=' . $aRow['pk_i_id'] . '&value=1">' . __('Mark as premium') . '</a>'; } if ($aRow['b_spam']) { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status_spam&id=' . $aRow['pk_i_id'] . '&value=0">' . __('Unmark as spam') . '</a>'; } else { $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=status_spam&id=' . $aRow['pk_i_id'] . '&value=1">' . __('Mark as spam') . '</a>'; } $options[] = '<a href="' . osc_admin_base_url(true) . '?page=items&action=item_edit&id=' . $aRow['pk_i_id'] . '">' . __('Edit') . '</a>'; $onclick_delete = 'onclick="javascript:return confirm(\'' . osc_esc_js(__('This action can not be undone. Are you sure you want to continue?')) . '\')"'; $options[] = '<a ' . $onclick_delete . ' href="' . osc_admin_base_url(true) . '?page=items&action=delete&id[]=' . $aRow['pk_i_id'] . '">' . __('Delete') . '</a>'; foreach ($this->stat as $k => $s) { $options[] = '<a ' . $onclick_delete . ' href="' . osc_admin_base_url(true) . '?page=items&action=clear_stat&stat=' . $k . '&id=' . $aRow['pk_i_id'] . '">' . sprintf(__('Clear %s'), $k) . '</a>'; } // fill a row $row[] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" />'; $row[] = $title . ' <div class="datatable_wrapper" style="display: none;"><div class="datatables_quick_edit" style="position: absolute;" >' . implode(' · ', $options) . '</div></div>'; $row[] = $aRow['s_user_name']; $row[] = $aRow['s_category_name']; $row[] = $aRow['s_country']; $row[] = $aRow['s_region']; $row[] = $aRow['s_city']; $row[] = $aRow['dt_pub_date']; $count++; $this->result['aaData'][] = $row; } return; }
function doModel() { osc_run_hook('before_search'); if (osc_rewrite_enabled()) { // IF rewrite is not enabled, skip this part, preg_match is always time&resources consuming task $p_sParams = "/" . Params::getParam('sParams', false, false); if (preg_match_all('|\\/([^,]+),([^\\/]*)|', $p_sParams, $m)) { $l = count($m[0]); for ($k = 0; $k < $l; $k++) { switch ($m[1][$k]) { case osc_get_preference('rewrite_search_country'): $m[1][$k] = 'sCountry'; break; case osc_get_preference('rewrite_search_region'): $m[1][$k] = 'sRegion'; break; case osc_get_preference('rewrite_search_city'): $m[1][$k] = 'sCity'; break; case osc_get_preference('rewrite_search_city_area'): $m[1][$k] = 'sCityArea'; break; case osc_get_preference('rewrite_search_category'): $m[1][$k] = 'sCategory'; break; case osc_get_preference('rewrite_search_user'): $m[1][$k] = 'sUser'; break; case osc_get_preference('rewrite_search_pattern'): $m[1][$k] = 'sPattern'; break; default: // custom fields if (preg_match("/meta(\\d+)-?(.*)?/", $m[1][$k], $results)) { $meta_key = $m[1][$k]; $meta_value = $m[2][$k]; $array_r = array(); if (Params::existParam('meta')) { $array_r = Params::getParam('meta'); } if ($results[2] == '') { // meta[meta_id] = meta_value $meta_key = $results[1]; $array_r[$meta_key] = $meta_value; } else { // meta[meta_id][meta_key] = meta_value $meta_key = $results[1]; $meta_key2 = $results[2]; $array_r[$meta_key][$meta_key2] = $meta_value; } $m[1][$k] = 'meta'; $m[2][$k] = $array_r; } break; } Params::setParam($m[1][$k], $m[2][$k]); } Params::unsetParam('sParams'); } } $uriParams = Params::getParamsAsArray(); $searchUri = osc_search_url($uriParams); if ($this->uri != 'feed') { if (str_replace("%20", '+', $searchUri) != str_replace("%20", '+', WEB_PATH . $this->uri)) { $this->redirectTo($searchUri, 301); } } //////////////////////////////// //GETTING AND FIXING SENT DATA// //////////////////////////////// $p_sCategory = Params::getParam('sCategory'); if (!is_array($p_sCategory)) { if ($p_sCategory == '') { $p_sCategory = array(); } else { $p_sCategory = explode(",", $p_sCategory); } } $p_sCityArea = Params::getParam('sCityArea'); if (!is_array($p_sCityArea)) { if ($p_sCityArea == '') { $p_sCityArea = array(); } else { $p_sCityArea = explode(",", $p_sCityArea); } } $p_sCity = Params::getParam('sCity'); if (!is_array($p_sCity)) { if ($p_sCity == '') { $p_sCity = array(); } else { $p_sCity = explode(",", $p_sCity); } } $p_sRegion = Params::getParam('sRegion'); if (!is_array($p_sRegion)) { if ($p_sRegion == '') { $p_sRegion = array(); } else { $p_sRegion = explode(",", $p_sRegion); } } $p_sCountry = Params::getParam('sCountry'); if (!is_array($p_sCountry)) { if ($p_sCountry == '') { $p_sCountry = array(); } else { $p_sCountry = explode(",", $p_sCountry); } } $p_sUser = Params::getParam('sUser'); if (!is_array($p_sUser)) { if ($p_sUser == '') { $p_sUser = ''; } else { $p_sUser = explode(",", $p_sUser); } } $p_sLocale = Params::getParam('sLocale'); if (!is_array($p_sLocale)) { if ($p_sLocale == '') { $p_sLocale = ''; } else { $p_sLocale = explode(",", $p_sLocale); } } $p_sPattern = trim(strip_tags(Params::getParam('sPattern'))); // ADD TO THE LIST OF LAST SEARCHES if (osc_save_latest_searches() && (!Params::existParam('iPage') || Params::getParam('iPage') == 1)) { $savePattern = osc_apply_filter('save_latest_searches_pattern', $p_sPattern); if ($savePattern != '') { LatestSearches::newInstance()->insert(array('s_search' => $savePattern, 'd_date' => date('Y-m-d H:i:s'))); } } $p_bPic = Params::getParam('bPic'); $p_bPic = $p_bPic == 1 ? 1 : 0; $p_bPremium = Params::getParam('bPremium'); $p_bPremium = $p_bPremium == 1 ? 1 : 0; $p_sPriceMin = Params::getParam('sPriceMin'); $p_sPriceMax = Params::getParam('sPriceMax'); //WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting() $p_sOrder = Params::getParam('sOrder'); if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) { $p_sOrder = osc_default_order_field_at_search(); } $old_order = $p_sOrder; //ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES $p_iOrderType = Params::getParam('iOrderType'); $allowedTypesForSorting = Search::getAllowedTypesForSorting(); $orderType = osc_default_order_type_at_search(); foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == $v) { $orderType = $k; break; } } $p_iOrderType = $orderType; $p_sFeed = Params::getParam('sFeed'); $p_iPage = 0; if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') > 0) { $p_iPage = intval(Params::getParam('iPage')) - 1; } if ($p_sFeed != '') { $p_sPageSize = 1000; } $p_sShowAs = Params::getParam('sShowAs'); $aValidShowAsValues = array('list', 'gallery'); if (!in_array($p_sShowAs, $aValidShowAsValues)) { $p_sShowAs = osc_default_show_as_at_search(); } // search results: it's blocked with the maxResultsPerPage@search defined in t_preferences $p_iPageSize = intval(Params::getParam('iPagesize')); if ($p_iPageSize > 0) { if ($p_iPageSize > osc_max_results_per_page_at_search()) { $p_iPageSize = osc_max_results_per_page_at_search(); } } else { $p_iPageSize = osc_default_results_per_page_at_search(); } //FILTERING CATEGORY $bAllCategoriesChecked = false; $successCat = false; if (count($p_sCategory) > 0) { foreach ($p_sCategory as $category) { $successCat = $this->mSearch->addCategory($category) || $successCat; } } else { $bAllCategoriesChecked = true; } //FILTERING CITY_AREA foreach ($p_sCityArea as $city_area) { $this->mSearch->addCityArea($city_area); } $p_sCityArea = implode(", ", $p_sCityArea); //FILTERING CITY foreach ($p_sCity as $city) { $this->mSearch->addCity($city); } $p_sCity = implode(", ", $p_sCity); //FILTERING REGION foreach ($p_sRegion as $region) { $this->mSearch->addRegion($region); } $p_sRegion = implode(", ", $p_sRegion); //FILTERING COUNTRY foreach ($p_sCountry as $country) { $this->mSearch->addCountry($country); } $p_sCountry = implode(", ", $p_sCountry); // FILTERING PATTERN if ($p_sPattern != '') { $this->mSearch->addPattern($p_sPattern); $osc_request['sPattern'] = $p_sPattern; } else { // hardcoded - if there isn't a search pattern, order by dt_pub_date desc if ($p_sOrder == 'relevance') { $p_sOrder = 'dt_pub_date'; foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == 'desc') { $orderType = $k; break; } } $p_iOrderType = $orderType; } } // FILTERING USER if ($p_sUser != '') { $this->mSearch->fromUser($p_sUser); } // FILTERING LOCALE $this->mSearch->addLocale($p_sLocale); // FILTERING IF WE ONLY WANT ITEMS WITH PICS if ($p_bPic) { $this->mSearch->withPicture(true); } // FILTERING IF WE ONLY WANT PREMIUM ITEMS if ($p_bPremium) { $this->mSearch->onlyPremium(true); } //FILTERING BY RANGE PRICE $this->mSearch->priceRange($p_sPriceMin, $p_sPriceMax); //ORDERING THE SEARCH RESULTS $this->mSearch->order($p_sOrder, $allowedTypesForSorting[$p_iOrderType]); //SET PAGE if ($p_sFeed == 'rss') { // If param sFeed=rss, just output last 'osc_num_rss_items()' $this->mSearch->page(0, osc_num_rss_items()); } else { $this->mSearch->page($p_iPage, $p_iPageSize); } // CUSTOM FIELDS $custom_fields = Params::getParam('meta'); $fields = Field::newInstance()->findIDSearchableByCategories($p_sCategory); $table = DB_TABLE_PREFIX . 't_item_meta'; if (is_array($custom_fields)) { foreach ($custom_fields as $key => $aux) { if (in_array($key, $fields)) { $field = Field::newInstance()->findByPrimaryKey($key); switch ($field['e_type']) { case 'TEXTAREA': case 'TEXT': case 'URL': if ($aux != '') { $aux = "%{$aux}%"; $sql = "SELECT fk_i_item_id FROM {$table} WHERE "; $str_escaped = Search::newInstance()->dao->escape($aux); $sql .= $table . '.fk_i_field_id = ' . $key . ' AND '; $sql .= $table . ".s_value LIKE " . $str_escaped; $this->mSearch->addConditions(DB_TABLE_PREFIX . 't_item.pk_i_id IN (' . $sql . ')'); } break; case 'DROPDOWN': case 'RADIO': if ($aux != '') { $sql = "SELECT fk_i_item_id FROM {$table} WHERE "; $str_escaped = Search::newInstance()->dao->escape($aux); $sql .= $table . '.fk_i_field_id = ' . $key . ' AND '; $sql .= $table . ".s_value = " . $str_escaped; $this->mSearch->addConditions(DB_TABLE_PREFIX . 't_item.pk_i_id IN (' . $sql . ')'); } break; case 'CHECKBOX': if ($aux != '') { $sql = "SELECT fk_i_item_id FROM {$table} WHERE "; $sql .= $table . '.fk_i_field_id = ' . $key . ' AND '; $sql .= $table . ".s_value = 1"; $this->mSearch->addConditions(DB_TABLE_PREFIX . 't_item.pk_i_id IN (' . $sql . ')'); } break; case 'DATE': if ($aux != '') { $y = (int) date('Y', $aux); $m = (int) date('n', $aux); $d = (int) date('j', $aux); $start = mktime('0', '0', '0', $m, $d, $y); $end = mktime('23', '59', '59', $m, $d, $y); $sql = "SELECT fk_i_item_id FROM {$table} WHERE "; $sql .= $table . '.fk_i_field_id = ' . $key . ' AND '; $sql .= $table . ".s_value >= " . $start . " AND "; $sql .= $table . ".s_value <= " . $end; $this->mSearch->addConditions(DB_TABLE_PREFIX . 't_item.pk_i_id IN (' . $sql . ')'); } break; case 'DATEINTERVAL': if (is_array($aux) && (!empty($aux['from']) && !empty($aux['to']))) { $from = $aux['from']; $to = $aux['to']; $start = $from; $end = $to; $sql = "SELECT fk_i_item_id FROM {$table} WHERE "; $sql .= $table . '.fk_i_field_id = ' . $key . ' AND '; $sql .= $start . " >= " . $table . ".s_value AND s_multi = 'from'"; $sql1 = "SELECT fk_i_item_id FROM {$table} WHERE "; $sql1 .= $table . ".fk_i_field_id = " . $key . " AND "; $sql1 .= $end . " <= " . $table . ".s_value AND s_multi = 'to'"; $sql_interval = "select a.fk_i_item_id from (" . $sql . ") a where a.fk_i_item_id IN (" . $sql1 . ")"; $this->mSearch->addConditions(DB_TABLE_PREFIX . 't_item.pk_i_id IN (' . $sql_interval . ')'); } break; default: break; } } } } osc_run_hook('search_conditions', Params::getParamsAsArray()); // RETRIEVE ITEMS AND TOTAL $key = md5(osc_base_url() . $this->mSearch->toJson()); $found = null; $cache = osc_cache_get($key, $found); $aItems = null; $iTotalItems = null; if ($cache) { $aItems = $cache['aItems']; $iTotalItems = $cache['iTotalItems']; } else { $aItems = $this->mSearch->doSearch(); $iTotalItems = $this->mSearch->count(); $_cache['aItems'] = $aItems; $_cache['iTotalItems'] = $iTotalItems; osc_cache_set($key, $_cache, OSC_CACHE_TTL); } $iStart = $p_iPage * $p_iPageSize; $iEnd = min(($p_iPage + 1) * $p_iPageSize, $iTotalItems); $iNumPages = ceil($iTotalItems / $p_iPageSize); // works with cache enabled ? osc_run_hook('search', $this->mSearch); //preparing variables... $countryName = $p_sCountry; if (strlen($p_sCountry) == 2) { $c = Country::newInstance()->findByCode($p_sCountry); if ($c) { $countryName = $c['s_name']; } } $regionName = $p_sRegion; if (is_numeric($p_sRegion)) { $r = Region::newInstance()->findByPrimaryKey($p_sRegion); if ($r) { $regionName = $r['s_name']; } } $cityName = $p_sCity; if (is_numeric($p_sCity)) { $c = City::newInstance()->findByPrimaryKey($p_sCity); if ($c) { $cityName = $c['s_name']; } } $this->_exportVariableToView('search_start', $iStart); $this->_exportVariableToView('search_end', $iEnd); $this->_exportVariableToView('search_category', $p_sCategory); // hardcoded - non pattern and order by relevance $p_sOrder = $old_order; $this->_exportVariableToView('search_order_type', $p_iOrderType); $this->_exportVariableToView('search_order', $p_sOrder); $this->_exportVariableToView('search_pattern', $p_sPattern); $this->_exportVariableToView('search_from_user', $p_sUser); $this->_exportVariableToView('search_total_pages', $iNumPages); $this->_exportVariableToView('search_page', $p_iPage); $this->_exportVariableToView('search_has_pic', $p_bPic); $this->_exportVariableToView('search_only_premium', $p_bPremium); $this->_exportVariableToView('search_country', $countryName); $this->_exportVariableToView('search_region', $regionName); $this->_exportVariableToView('search_city', $cityName); $this->_exportVariableToView('search_price_min', $p_sPriceMin); $this->_exportVariableToView('search_price_max', $p_sPriceMax); $this->_exportVariableToView('search_total_items', $iTotalItems); $this->_exportVariableToView('items', $aItems); $this->_exportVariableToView('search_show_as', $p_sShowAs); $this->_exportVariableToView('search', $this->mSearch); // json $json = $this->mSearch->toJson(); $encoded_alert = base64_encode(osc_encrypt_alert($json)); // Create the HMAC signature and convert the resulting hex hash into base64 $stringToSign = osc_get_alert_public_key() . $encoded_alert; $signature = hex2b64(hmacsha1(osc_get_alert_private_key(), $stringToSign)); $server_signature = Session::newInstance()->_set('alert_signature', $signature); $this->_exportVariableToView('search_alert', $encoded_alert); // calling the view... if (count($aItems) === 0) { header('HTTP/1.1 404 Not Found'); } osc_run_hook("after_search"); if (!Params::existParam('sFeed')) { $this->doView('search.php'); } else { if ($p_sFeed == '' || $p_sFeed == 'rss') { // FEED REQUESTED! header('Content-type: text/xml; charset=utf-8'); $feed = new RSSFeed(); $feed->setTitle(__('Latest listings added') . ' - ' . osc_page_title()); $feed->setLink(osc_base_url()); $feed->setDescription(__('Latest listings added in') . ' ' . osc_page_title()); if (osc_count_items() > 0) { while (osc_has_items()) { if (osc_count_item_resources() > 0) { osc_has_item_resources(); $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8"), 'description' => osc_item_description(), 'country' => osc_item_country(), 'region' => osc_item_region(), 'city' => osc_item_city(), 'city_area' => osc_item_city_area(), 'category' => osc_item_category(), 'dt_pub_date' => osc_item_pub_date(), 'image' => array('url' => htmlentities(osc_resource_thumbnail_url(), ENT_COMPAT, "UTF-8"), 'title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8")))); } else { $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8"), 'description' => osc_item_description(), 'country' => osc_item_country(), 'region' => osc_item_region(), 'city' => osc_item_city(), 'city_area' => osc_item_city_area(), 'category' => osc_item_category(), 'dt_pub_date' => osc_item_pub_date())); } } } osc_run_hook('feed', $feed); $feed->dumpXML(); } else { osc_run_hook('feed_' . $p_sFeed, $aItems); } } }
function breadcrumbs($separator = '/') { $text = ''; $location = Rewrite::newInstance()->get_location(); $section = Rewrite::newInstance()->get_section(); $separator = ' ' . trim($separator) . ' '; $page_title = '<a href="' . osc_base_url() . '"><span class="bc_root">' . osc_page_title() . '</span></a>'; switch ($location) { case 'item': switch ($section) { case 'item_add': break; default: $aCategories = Category::newInstance()->toRootTree((string) osc_item_category_id()); $category = ''; if (count($aCategories) == 0) { break; } $deep = 1; foreach ($aCategories as $aCategory) { $list[] = '<a href="' . breadcrumbs_category_url($aCategory['pk_i_id']) . '"><span class="bc_level_' . $deep . '">' . $aCategory['s_name'] . '</span></a>'; $deep++; } $category = implode($separator, $list) . $separator; $category = preg_replace('|' . trim($separator) . '\\s*$|', '', $category); break; } switch ($section) { case 'item_add': $text = $page_title . $separator . '<span class="bc_last">' . __('Publish an item', 'breadcrumbs'); break; case 'item_edit': $text = $page_title . $separator . $category . $separator . '<a href="' . osc_item_url() . '"><span class="bc_item">' . osc_item_title() . '</span></a>' . $separator . '<span class="bc_last">' . __('Edit your item', 'breadcrumbs') . '</span>'; break; case 'send_friend': $text = $page_title . $separator . $category . $separator . '<a href="' . osc_item_url() . '"><span class="bc_item">' . osc_item_title() . '</span></a>' . $separator . '<span class="bc_last">' . __('Send to a friend', 'breadcrumbs') . '</span>'; break; case 'contact': $text = $page_title . $separator . $category . $separator . '<a href="' . osc_item_url() . '"><span class="bc_item">' . osc_item_title() . '</span></a>' . $separator . '<span class="bc_last">' . __('Contact seller', 'breadcrumbs') . '</span>'; break; default: $text = $page_title . $separator . $category . $separator . '<span class="bc_last">' . osc_item_title() . '</span>'; break; } break; case 'page': $text = $page_title . $separator . '<span class="bc_last">' . osc_static_page_title() . '</span>'; break; case 'search': $region = osc_search_region(); $city = osc_search_city(); $pattern = osc_search_pattern(); $category = osc_search_category_id(); $category = count($category) == 1 ? $category[0] : ''; $b_show_all = $pattern == '' && $category == '' && $region == '' && $city == ''; $b_category = $category != ''; $b_pattern = $pattern != ''; $b_region = $region != ''; $b_city = $city != ''; $b_location = $b_region || $b_city; if ($b_show_all) { $text = $page_title . $separator . '<span class="bc_last">' . __('Search', 'breadcrumbs') . '</span>'; break; } // init $result = $page_title . $separator; if ($b_category) { $list = array(); $aCategories = Category::newInstance()->toRootTree($category); if (count($aCategories) > 0) { $deep = 1; foreach ($aCategories as $single) { $list[] = '<a href="' . breadcrumbs_category_url($single['pk_i_id']) . '"><span class="bc_level_' . $deep . '">' . $single['s_name'] . '</span></a>'; $deep++; } // remove last link if (!$b_pattern && !$b_location) { $list[count($list) - 1] = preg_replace('|<a href.*?>(.*?)</a>|', '$01', $list[count($list) - 1]); } $result .= implode($separator, $list) . $separator; } } if ($b_location) { $list = array(); $params = array(); if ($b_category) { $params['sCategory'] = $category; } if ($b_city) { $aCity = City::newInstance()->findByName($city); if (count($aCity) == 0) { $params['sCity'] = $city; $list[] = '<a href="' . osc_search_url($params) . '"><span class="bc_city">' . $city . '</span></a>'; } else { $aRegion = Region::newInstance()->findByPrimaryKey($aCity['fk_i_region_id']); $params['sRegion'] = $aRegion['s_name']; $list[] = '<a href="' . osc_search_url($params) . '"><span class="bc_region">' . $aRegion['s_name'] . '</span></a>'; $params['sCity'] = $aCity['s_name']; $list[] = '<a href="' . osc_search_url($params) . '"><span class="bc_city">' . $aCity['s_name'] . '</span></a>'; } if (!$b_pattern) { $list[count($list) - 1] = preg_replace('|<a href.*?>(.*?)</a>|', '$01', $list[count($list) - 1]); } $result .= implode($separator, $list) . $separator; } else { if ($b_region) { $params['sRegion'] = $region; $list[] = '<a href="' . osc_search_url($params) . '"><span class="bc_region">' . $region . '</span></a>'; if (!$b_pattern) { $list[count($list) - 1] = preg_replace('|<a href.*?>(.*?)</a>|', '$01', $list[count($list) - 1]); } $result .= implode($separator, $list) . $separator; } } } if ($b_pattern) { $result .= '<span class="bc_last">' . __('Search Results', 'breadcrumbs') . ': ' . $pattern . '</span>' . $separator; } // remove last separator $result = preg_replace('|' . trim($separator) . '\\s*$|', '', $result); $text = $result; break; case 'login': switch ($section) { case 'recover': $text = $page_title . $separator . '<span class="bc_last">' . __('Recover your password', 'breadcrumbs') . '</span>'; default: $text = $page_title . $separator . '<span class="bc_last">' . __('Login', 'breadcrumbs') . '</span>'; } break; case 'register': $text = $page_title . $separator . '<span class="bc_last">' . __('Create a new account', 'breadcrumbs') . '</span>'; break; case 'user': $user_dashboard = '<a href="' . osc_user_dashboard_url() . '"><span class="bc_user">' . __('My account', 'breadcrumbs') . '</span></a>'; switch ($section) { case 'dashboard': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Dashboard', 'breadcrumbs') . '</span>'; break; case 'items': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Manage my items', 'breadcrumbs') . '</span>'; break; case 'alerts': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Manage my alerts', 'breadcrumbs') . '</span>'; break; case 'profile': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Update my profile', 'breadcrumbs') . '</span>'; break; case 'change_email': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Change my email', 'breadcrumbs') . '</span>'; break; case 'change_password': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Change my password', 'breadcrumbs') . '</span>'; break; case 'forgot': $text = $page_title . $separator . $user_dashboard . $separator . '<span class="bc_last">' . __('Recover my password', 'breadcrumbs') . '</span>'; break; } break; case 'contact': $text = $page_title . $separator . '<span class="bc_last">' . __('Contact', 'breadcrumbs') . '</span>'; break; default: break; } echo $text; return true; }
function pop_email_share_url() { if (osc_is_public_profile()) { $subject = sprintf(__("Check out this profile with interesting products at %s.", 'pop'), osc_page_title()); $body = sprintf(__('Take a look at %1$s\'s profile on %2$s', 'pop'), osc_user_public_profile_url(), osc_page_title()); } if (osc_is_ad_page()) { $subject = sprintf(__("Check out what I just found < %s >", 'pop'), osc_item_title()); $body = sprintf(__('Take a look at %s', 'pop'), osc_item_url()); } return 'mailto:?body=' . $body . '&subject=' . $subject; }
private function processData($comments) { if (!empty($comments)) { $csrf_token_url = osc_csrf_token_url(); foreach ($comments as $aRow) { $row = array(); $options = array(); $options_more = array(); View::newInstance()->_exportVariableToView('item', Item::newInstance()->findByPrimaryKey($aRow['fk_i_item_id'])); if ($aRow['b_active']) { $options_more[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=status&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&value=INACTIVE">' . __('Deactivate') . '</a>'; } else { $options_more[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=status&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&value=ACTIVE">' . __('Activate') . '</a>'; } if ($aRow['b_enabled']) { $options_more[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=status&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&value=DISABLE">' . __('Block') . '</a>'; } else { $options_more[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=status&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&value=ENABLE">' . __('Unblock') . '</a>'; } $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=comment_edit&id=' . $aRow['pk_i_id'] . '" id="dt_link_edit">' . __('Edit') . '</a>'; $options[] = '<a onclick="return delete_dialog(\'' . $aRow['pk_i_id'] . '\');" href="' . osc_admin_base_url(true) . '?page=comments&action=delete&id=' . $aRow['pk_i_id'] . '" id="dt_link_delete">' . __('Delete') . '</a>'; // more actions $moreOptions = '<li class="show-more">' . PHP_EOL . '<a href="#" class="show-more-trigger">' . __('Show more') . '...</a>' . PHP_EOL . '<ul>' . PHP_EOL; foreach ($options_more as $actual) { $moreOptions .= '<li>' . $actual . "</li>" . PHP_EOL; } $moreOptions .= '</ul>' . PHP_EOL . '</li>' . PHP_EOL; // create list of actions $auxOptions = '<ul>' . PHP_EOL; foreach ($options as $actual) { $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL; } $auxOptions .= $moreOptions; $auxOptions .= '</ul>' . PHP_EOL; $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL; $row['bulkactions'] = '<input type="checkbox" name="id[]" value="' . $aRow['pk_i_id'] . '" />'; if (empty($aRow['s_author_name'])) { $user = User::newInstance()->findByPrimaryKey($aRow['fk_i_user_id']); $aRow['s_author_name'] = $user['s_email']; } $row['author'] = $aRow['s_author_name'] . ' (<a target="_blank" href="' . osc_item_url() . '">' . osc_item_title() . '</a>)' . $actions; $row['comment'] = $aRow['s_body']; $row['date'] = $aRow['dt_pub_date']; $row = osc_apply_filter('comments_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
function doModel() { osc_run_hook('before_search'); $mCategories = new Category(); //////////////////////////////// //GETTING AND FIXING SENT DATA// //////////////////////////////// $p_sCategory = Params::getParam('sCategory'); if (!is_array($p_sCategory)) { if ($p_sCategory == '') { $p_sCategory = array(); } else { $p_sCategory = explode(",", $p_sCategory); } } $p_sCityArea = Params::getParam('sCityArea'); if (!is_array($p_sCityArea)) { if ($p_sCityArea == '') { $p_sCityArea = array(); } else { $p_sCityArea = explode(",", $p_sCityArea); } } $p_sCity = Params::getParam('sCity'); if (!is_array($p_sCity)) { if ($p_sCity == '') { $p_sCity = array(); } else { $p_sCity = explode(",", $p_sCity); } } $p_sRegion = Params::getParam('sRegion'); if (!is_array($p_sRegion)) { if ($p_sRegion == '') { $p_sRegion = array(); } else { $p_sRegion = explode(",", $p_sRegion); } } $p_sCountry = Params::getParam('sCountry'); if (!is_array($p_sCountry)) { if ($p_sCountry == '') { $p_sCountry = array(); } else { $p_sCountry = explode(",", $p_sCountry); } } $p_sPattern = strip_tags(Params::getParam('sPattern')); $p_sUser = strip_tags(Params::getParam('sUser')); // ADD TO THE LIST OF LAST SEARCHES if (osc_save_latest_searches()) { if (trim($p_sPattern) != '') { LatestSearches::newInstance()->insert(array('s_search' => trim($p_sPattern), 'd_date' => date('Y-m-d H:i:s'))); } } $p_bPic = Params::getParam('bPic'); $p_bPic == 1 ? $p_bPic = 1 : ($p_bPic = 0); $p_sPriceMin = Params::getParam('sPriceMin'); $p_sPriceMax = Params::getParam('sPriceMax'); //WE CAN ONLY USE THE FIELDS RETURNED BY Search::getAllowedColumnsForSorting() $p_sOrder = Params::getParam('sOrder'); if (!in_array($p_sOrder, Search::getAllowedColumnsForSorting())) { $p_sOrder = osc_default_order_field_at_search(); } //ONLY 0 ( => 'asc' ), 1 ( => 'desc' ) AS ALLOWED VALUES $p_iOrderType = Params::getParam('iOrderType'); $allowedTypesForSorting = Search::getAllowedTypesForSorting(); $orderType = osc_default_order_type_at_search(); foreach ($allowedTypesForSorting as $k => $v) { if ($p_iOrderType == $v) { $orderType = $k; break; } } $p_iOrderType = $orderType; $p_sFeed = Params::getParam('sFeed'); $p_iPage = intval(Params::getParam('iPage')); if ($p_sFeed != '') { $p_sPageSize = 1000; } $p_sShowAs = Params::getParam('sShowAs'); $aValidShowAsValues = array('list', 'gallery'); if (!in_array($p_sShowAs, $aValidShowAsValues)) { $p_sShowAs = osc_default_show_as_at_search(); } // search results: it's blocked with the maxResultsPerPage@search defined in t_preferences $p_iPageSize = intval(Params::getParam('iPagesize')); if ($p_iPageSize > 0) { if ($p_iPageSize > osc_max_results_per_page_at_search()) { $p_iPageSize = osc_max_results_per_page_at_search(); } } else { $p_iPageSize = osc_default_results_per_page_at_search(); } //FILTERING CATEGORY $bAllCategoriesChecked = false; if (count($p_sCategory) > 0) { foreach ($p_sCategory as $category) { $this->mSearch->addCategory($category); } } else { $bAllCategoriesChecked = true; } //FILTERING CITY_AREA foreach ($p_sCityArea as $city_area) { $this->mSearch->addCityArea($city_area); } $p_sCityArea = implode(", ", $p_sCityArea); //FILTERING CITY foreach ($p_sCity as $city) { $this->mSearch->addCity($city); } $p_sCity = implode(", ", $p_sCity); //FILTERING REGION foreach ($p_sRegion as $region) { $this->mSearch->addRegion($region); } $p_sRegion = implode(", ", $p_sRegion); //FILTERING COUNTRY foreach ($p_sCountry as $country) { $this->mSearch->addCountry($country); } $p_sCountry = implode(", ", $p_sCountry); // FILTERING PATTERN if ($p_sPattern != '') { $this->mSearch->addConditions(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $p_sPattern)); $osc_request['sPattern'] = $p_sPattern; } // FILTERING USER if ($p_sUser != '') { $this->mSearch->fromUser(explode(",", $p_sUser)); } // FILTERING IF WE ONLY WANT ITEMS WITH PICS if ($p_bPic) { $this->mSearch->withPicture(true); } //FILTERING BY RANGE PRICE $this->mSearch->priceRange($p_sPriceMin, $p_sPriceMax); //ORDERING THE SEARCH RESULTS $this->mSearch->order($p_sOrder, $allowedTypesForSorting[$p_iOrderType]); //SET PAGE $this->mSearch->page($p_iPage, $p_iPageSize); osc_run_hook('search_conditions', Params::getParamsAsArray()); if (!Params::existParam('sFeed')) { // RETRIEVE ITEMS AND TOTAL $aItems = $this->mSearch->doSearch(); $iTotalItems = $this->mSearch->count(); $iStart = $p_iPage * $p_iPageSize; $iEnd = min(($p_iPage + 1) * $p_iPageSize, $iTotalItems); $iNumPages = ceil($iTotalItems / $p_iPageSize); osc_run_hook('search', $this->mSearch); //preparing variables... //$this->_exportVariableToView('non_empty_categories', $aCategories) ; $this->_exportVariableToView('search_start', $iStart); $this->_exportVariableToView('search_end', $iEnd); $this->_exportVariableToView('search_category', $p_sCategory); $this->_exportVariableToView('search_order_type', $p_iOrderType); $this->_exportVariableToView('search_order', $p_sOrder); $this->_exportVariableToView('search_pattern', $p_sPattern); $this->_exportVariableToView('search_from_user', $p_sUser); $this->_exportVariableToView('search_total_pages', $iNumPages); $this->_exportVariableToView('search_page', $p_iPage); $this->_exportVariableToView('search_has_pic', $p_bPic); $this->_exportVariableToView('search_region', $p_sRegion); $this->_exportVariableToView('search_city', $p_sCity); $this->_exportVariableToView('search_price_min', $p_sPriceMin); $this->_exportVariableToView('search_price_max', $p_sPriceMax); $this->_exportVariableToView('search_total_items', $iTotalItems); $this->_exportVariableToView('items', $aItems); $this->_exportVariableToView('search_show_as', $p_sShowAs); $this->_exportVariableToView('search', $this->mSearch); $this->_exportVariableToView('search_alert', base64_encode(serialize($this->mSearch))); //calling the view... $this->doView('search.php'); } else { $this->mSearch->page(0, osc_num_rss_items()); // RETRIEVE ITEMS AND TOTAL $iTotalItems = $this->mSearch->count(); $aItems = $this->mSearch->doSearch(); $this->_exportVariableToView('items', $aItems); if ($p_sFeed == '' || $p_sFeed == 'rss') { // FEED REQUESTED! header('Content-type: text/xml; charset=utf-8'); $feed = new RSSFeed(); $feed->setTitle(__('Latest items added') . ' - ' . osc_page_title()); $feed->setLink(osc_base_url()); $feed->setDescription(__('Latest items added in') . ' ' . osc_page_title()); if (osc_count_items() > 0) { while (osc_has_items()) { if (osc_count_item_resources() > 0) { osc_has_item_resources(); $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url()), 'description' => osc_item_description(), 'dt_pub_date' => osc_item_pub_date(), 'image' => array('url' => htmlentities(osc_resource_thumbnail_url()), 'title' => osc_item_title(), 'link' => htmlentities(osc_item_url())))); } else { $feed->addItem(array('title' => osc_item_title(), 'link' => htmlentities(osc_item_url()), 'description' => osc_item_description(), 'dt_pub_date' => osc_item_pub_date())); } } } osc_run_hook('feed', $feed); $feed->dumpXML(); } else { osc_run_hook('feed_' . $p_sFeed, $aItems); } } }
function moreedit_moderate_edit($item_) { $cat_id = $item_['fk_i_category_id']; $item_id = $item_['pk_i_id']; if (osc_get_preference('notify_edit', 'moreedit') == '1') { $aPage = Page::newInstance()->findByInternalName('email_moreedit_notify_edit'); $content = array(); $locale = osc_current_user_locale(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $item = Item::newInstance()->findByPrimaryKey($item_id); View::newInstance()->_exportVariableToView('item', $item); $item_url = osc_item_url(); $item_url = '<a href="' . $item_url . '" >' . $item_url . '</a>'; $admin_edit_url = osc_item_admin_edit_url($item['pk_i_id']); $words = array(); $words[] = array('{EDIT_LINK}', '{EDIT_URL}', '{ITEM_DESCRIPTION}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}'); $words[] = array('<a href="' . $admin_edit_url . '" >' . $admin_edit_url . '</a>', $admin_edit_url, $item['s_description'], $item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], '<a href="' . osc_base_url() . '" >' . osc_base_url() . '</a>', $item['s_title'], $item_url, osc_page_title()); $title = osc_mailBeauty($content['s_title'], $words); $body = osc_mailBeauty($content['s_text'], $words); $emailParams = array('subject' => $title, 'to' => osc_contact_email(), 'to_name' => 'admin', 'body' => $body, 'alt_body' => $body); osc_sendMail($emailParams); } if (osc_get_preference('moderate_edit', 'moreedit') == '1') { Item::newInstance()->update(array('b_enabled' => 0), array('pk_i_id' => $item_id)); } }
function doModel() { //calling the view... $locales = OSCLocale::newInstance()->listAllEnabled(); $this->_exportVariableToView('locales', $locales); switch ($this->action) { case 'item_add': // post if (osc_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $this->redirectTo(osc_user_login_url()); } $countries = Country::newInstance()->listAll(); $regions = array(); if (isset($this->user['fk_c_country_code']) && $this->user['fk_c_country_code'] != '') { $regions = Region::newInstance()->findByCountry($this->user['fk_c_country_code']); } else { if (count($countries) > 0) { $regions = Region::newInstance()->findByCountry($countries[0]['pk_c_code']); } } $cities = array(); if (isset($this->user['fk_i_region_id']) && $this->user['fk_i_region_id'] != '') { $cities = City::newInstance()->findByRegion($this->user['fk_i_region_id']); } else { if (count($regions) > 0) { $cities = City::newInstance()->findByRegion($regions[0]['pk_i_id']); } } $this->_exportVariableToView('countries', $countries); $this->_exportVariableToView('regions', $regions); $this->_exportVariableToView('cities', $cities); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } if (Session::newInstance()->_getForm('countryId') != "") { $countryId = Session::newInstance()->_getForm('countryId'); $regions = Region::newInstance()->findByCountry($countryId); $this->_exportVariableToView('regions', $regions); if (Session::newInstance()->_getForm('regionId') != "") { $regionId = Session::newInstance()->_getForm('regionId'); $cities = City::newInstance()->findByRegion($regionId); $this->_exportVariableToView('cities', $cities); } } $this->_exportVariableToView('user', $this->user); osc_run_hook('post_item'); $this->doView('item-post.php'); break; case 'item_add_post': //post_item if (osc_reg_user_post() && $this->user == null) { osc_add_flash_warning_message(_m('Only registered users are allowed to post listings')); $this->redirectTo(osc_base_url(true)); } $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(true); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_post_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (!osc_is_web_user_logged_in()) { $user = User::newInstance()->findByEmail($mItems->data['contactEmail']); // The user exists but it's not logged if (isset($user['pk_i_id'])) { foreach ($mItems->data as $key => $value) { Session::newInstance()->_keepForm($key); } osc_add_flash_error_message(_m('A user with that email address already exists, if it is you, please log in')); $this->redirectTo(osc_user_login_url()); } } // POST ITEM ( ADD ITEM ) $success = $mItems->add(); if ($success != 1 && $success != 2) { osc_add_flash_error_message($success); $this->redirectTo(osc_item_post_url()); } else { Session::newInstance()->_dropkeepForm('meta_' . $key); if ($success == 1) { osc_add_flash_ok_message(_m('Check your inbox to validate your listing')); } else { osc_add_flash_ok_message(_m('Your listing has been published')); } $itemId = Params::getParam('itemId'); $item = $this->itemManager->findByPrimaryKey($itemId); osc_run_hook('posted_item', $item); $category = Category::newInstance()->findByPrimaryKey(Params::getParam('catId')); View::newInstance()->_exportVariableToView('category', $category); $this->redirectTo(osc_search_category_url()); } break; case 'item_edit': // edit item $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $item = Item::newInstance()->findByPrimaryKey($id); $form = count(Session::newInstance()->_getForm()); $keepForm = count(Session::newInstance()->_getKeepForm()); if ($form == 0 || $form == $keepForm) { Session::newInstance()->_dropKeepForm(); } $this->_exportVariableToView('item', $item); osc_run_hook("before_item_edit", $item); $this->doView('item-edit.php'); } else { // add a flash message [ITEM NO EXISTE] osc_add_flash_error_message(_m("Sorry, we don't have any listings with that ID")); if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } break; case 'item_edit_post': // recoger el secret y el $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s' AND i.fk_i_user_id IS NULL) OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $this->_exportVariableToView('item', $item[0]); $mItems = new ItemActions(false); // prepare data for ADD ITEM $mItems->prepareData(false); // set all parameters into session foreach ($mItems->data as $key => $value) { Session::newInstance()->_setForm($key, $value); } $meta = Params::getParam('meta'); if (is_array($meta)) { foreach ($meta as $key => $value) { Session::newInstance()->_setForm('meta_' . $key, $value); Session::newInstance()->_keepForm('meta_' . $key); } } if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_edit_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $success = $mItems->edit(); osc_run_hook('edited_item', Item::newInstance()->findByPrimaryKey($id)); if ($success == 1) { osc_add_flash_ok_message(_m("Great! We've just updated your listing")); View::newInstance()->_exportVariableToView("item", Item::newInstance()->findByPrimaryKey($id)); $this->redirectTo(osc_item_url()); } else { osc_add_flash_error_message($success); $this->redirectTo(osc_item_edit_url($secret)); } } break; case 'activate': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); // item doesn't exist if (count($item) == 0) { $this->do404(); return; } View::newInstance()->_exportVariableToView('item', $item[0]); if ($item[0]['b_active'] == 0) { // ACTIVETE ITEM $mItems = new ItemActions(false); $success = $mItems->activate($item[0]['pk_i_id'], $item[0]['s_secret']); if ($success) { osc_add_flash_ok_message(_m('The listing has been validated')); } else { osc_add_flash_error_message(_m("The listing can't be validated")); } } else { osc_add_flash_warning_message(_m('The listing has already been validated')); } $this->redirectTo(osc_item_url()); break; case 'item_delete': $secret = Params::getParam('secret'); $id = Params::getParam('id'); $item = $this->itemManager->listWhere("i.pk_i_id = '%s' AND ((i.s_secret = '%s') OR (i.fk_i_user_id = '%d'))", addslashes($id), addslashes($secret), addslashes($this->userId)); if (count($item) == 1) { $mItems = new ItemActions(false); $success = $mItems->delete($item[0]['s_secret'], $item[0]['pk_i_id']); if ($success) { osc_add_flash_ok_message(_m('Your listing has been deleted')); } else { osc_add_flash_error_message(_m("The listing you are trying to delete couldn't be deleted")); } if ($this->user != null) { $this->redirectTo(osc_user_list_items_url()); } else { $this->redirectTo(osc_base_url()); } } else { osc_add_flash_error_message(_m("The listing you are trying to delete couldn't be deleted")); $this->redirectTo(osc_base_url()); } break; case 'mark': $id = Params::getParam('id'); $as = Params::getParam('as'); $item = Item::newInstance()->findByPrimaryKey($id); View::newInstance()->_exportVariableToView('item', $item); require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { // mark item if it's not a bot $mItem = new ItemActions(false); $mItem->mark($id, $as); break; } } osc_add_flash_ok_message(_m("Thanks! That's very helpful")); $this->redirectTo(osc_item_url()); break; case 'send_friend': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); $this->doView('item-send-friend.php'); break; case 'send_friend_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("friendName", Params::getParam('friendName')); Session::newInstance()->_setForm("friendEmail", Params::getParam('friendEmail')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); $this->redirectTo(osc_item_send_friend_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } $mItem = new ItemActions(false); $success = $mItem->send_friend(); if ($success) { Session::newInstance()->_clearVariables(); $this->redirectTo(osc_item_url()); } else { $this->redirectTo(osc_item_send_friend_url()); } break; case 'contact': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); if (empty($item)) { osc_add_flash_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } else { $this->_exportVariableToView('item', $item); if (osc_item_is_expired()) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } if (osc_reg_user_can_contact() && osc_is_web_user_logged_in() || !osc_reg_user_can_contact()) { $this->doView('item-contact.php'); } else { osc_add_flash_error_message(_m("You can't contact the seller, only registered users can")); $this->redirectTo(osc_item_url()); } } break; case 'contact_post': $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); $this->_exportVariableToView('item', $item); if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) { if (!osc_check_recaptcha()) { osc_add_flash_error_message(_m('The Recaptcha code is wrong')); Session::newInstance()->_setForm("yourEmail", Params::getParam('yourEmail')); Session::newInstance()->_setForm("yourName", Params::getParam('yourName')); Session::newInstance()->_setForm("phoneNumber", Params::getParam('phoneNumber')); Session::newInstance()->_setForm("message_body", Params::getParam('message')); $this->redirectTo(osc_item_url()); return false; // BREAK THE PROCESS, THE RECAPTCHA IS WRONG } } if (osc_isExpired($item['dt_expiration'])) { osc_add_flash_error_message(_m("We're sorry, but the listing has expired. You can't contact the seller")); $this->redirectTo(osc_item_url()); } $mItem = new ItemActions(false); $result = $mItem->contact(); if (is_string($result)) { osc_add_flash_error_message($result); } else { osc_add_flash_ok_message(_m("We've just sent an e-mail to the seller")); } $this->redirectTo(osc_item_url()); break; case 'add_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); switch ($status) { case -1: $msg = _m('Sorry, we could not save your comment. Try again later'); osc_add_flash_error_message($msg); break; case 1: $msg = _m('Your comment is awaiting moderation'); osc_add_flash_info_message($msg); break; case 2: $msg = _m('Your comment has been approved'); osc_add_flash_ok_message($msg); break; case 3: $msg = _m('Please fill the required field (email)'); osc_add_flash_warning_message($msg); break; case 4: $msg = _m('Please type a comment'); osc_add_flash_warning_message($msg); break; case 5: $msg = _m('Your comment has been marked as spam'); osc_add_flash_error_message($msg); break; } $this->redirectTo(osc_item_url()); break; case 'delete_comment': $mItem = new ItemActions(false); $status = $mItem->add_comment(); $itemId = Params::getParam('id'); $commentId = Params::getParam('comment'); $item = Item::newInstance()->findByPrimaryKey($itemId); if (count($item) == 0) { osc_add_flash_error_message(_m("This listing doesn't exist")); $this->redirectTo(osc_base_url(true)); } View::newInstance()->_exportVariableToView('item', $item); if ($this->userId == null) { osc_add_flash_error_message(_m('You must be logged in to delete a comment')); $this->redirectTo(osc_item_url()); } $commentManager = ItemComment::newInstance(); $aComment = $commentManager->findByPrimaryKey($commentId); if (count($aComment) == 0) { osc_add_flash_error_message(_m("The comment doesn't exist")); $this->redirectTo(osc_item_url()); } if ($aComment['b_active'] != 1) { osc_add_flash_error_message(_m('The comment is not active, you cannot delete it')); $this->redirectTo(osc_item_url()); } if ($aComment['fk_i_user_id'] != $this->userId) { osc_add_flash_error_message(_m('The comment was not added by you, you cannot delete it')); $this->redirectTo(osc_item_url()); } $commentManager->deleteByPrimaryKey($commentId); osc_add_flash_ok_message(_m('The comment has been deleted')); $this->redirectTo(osc_item_url()); break; default: // if there isn't ID, show an error 404 if (Params::getParam('id') == '') { $this->do404(); return; } if (Params::getParam('lang') != '') { Session::newInstance()->_set('userLocale', Params::getParam('lang')); } $item = $this->itemManager->findByPrimaryKey(Params::getParam('id')); // if item doesn't exist show an error 404 if (count($item) == 0) { $this->do404(); return; } if ($item['b_active'] != 1) { if ($this->userId == $item['fk_i_user_id']) { osc_add_flash_warning_message(_m("The listing hasn't been validated. Please validate it in order to make it public")); } else { osc_add_flash_warning_message(_m("This listing hasn't been validated")); $this->redirectTo(osc_base_url(true)); } } else { if ($item['b_enabled'] == 0) { osc_add_flash_warning_message(_m('The listing has been suspended')); $this->redirectTo(osc_base_url(true)); } } if (!osc_is_admin_user_logged_in()) { require_once osc_lib_path() . 'osclass/user-agents.php'; foreach ($user_agents as $ua) { if (preg_match('|' . $ua . '|', @$_SERVER['HTTP_USER_AGENT'])) { $mStats = new ItemStats(); $mStats->increase('i_num_views', $item['pk_i_id']); break; } } } foreach ($item['locale'] as $k => $v) { $item['locale'][$k]['s_title'] = osc_apply_filter('item_title', $v['s_title']); $item['locale'][$k]['s_description'] = nl2br(osc_apply_filter('item_description', $v['s_description'])); } if ($item['fk_i_user_id'] != '') { $user = User::newInstance()->findByPrimaryKey($item['fk_i_user_id']); $this->_exportVariableToView('user', $user); } $this->_exportVariableToView('item', $item); osc_run_hook('show_item', $item); // redirect to the correct url just in case it has changed $itemURI = str_replace(osc_base_url(), '', osc_item_url()); $URI = preg_replace('|^' . REL_WEB_URL . '|', '', $_SERVER['REQUEST_URI']); // do not clean QUERY_STRING if permalink is not enabled if (osc_rewrite_enabled()) { $URI = str_replace('?' . $_SERVER['QUERY_STRING'], '', $URI); } else { $params_keep = array('page', 'id'); $params = array(); foreach (Params::getParamsAsArray('get') as $k => $v) { if (in_array($k, $params_keep)) { $params[] = "{$k}={$v}"; } } $URI = 'index.php?' . implode('&', $params); } // redirect to the correct url if ($itemURI != $URI) { $this->redirectTo(osc_base_url() . $itemURI); } $this->doView('item.php'); break; } }
} $img_source = osc_current_web_theme_url('images/no-items.png'); $total_listing = get_total_listing_by_parent($sa['cat_id']); $total_item_views = get_total_item_views($sa['cat_id']); if ($total_item_views == null || empty($total_item_view)) { $total_item_views = '0'; } else { $total_item_views = $total_item_views[0]['TotalViews']; } } else { $no_item = true; $primary_id = (int) $top_item[0]['fk_i_item_id']; $item = Item::newInstance()->findByPrimaryKey($primary_id); View::newInstance()->_exportVariableToView('item', $item); $resource = Item::newInstance()->findResourcesByID($primary_id); $item_url = osc_item_url(); $img_title = osc_item_title(); if (!empty($resource) || $resource != "") { $resource_path = osc_apply_filter('resource_path', osc_base_url() . $resource[0]['s_path']); $img_source = (string) $resource_path . $resource[0]['pk_i_id'] . "." . $resource[0]['s_extension']; } else { $img_source = osc_current_web_theme_url('images/no-image-available.png'); } $total_listing = get_total_listing_by_parent($sa['cat_id']); $total_item_views = get_total_item_views($sa['cat_id']); if ($total_item_views == null || empty($total_item_views)) { $total_item_views = '0'; } else { $total_item_views = $total_item_views[0]['TotalViews']; } $category_name = get_parent_category_name(osc_item_category_id());
public function add_comment() { if(!osc_comments_enabled()) { return 7; } $aItem = $this->prepareDataForFunction('add_comment'); $authorName = trim(strip_tags($aItem['authorName'])); $authorEmail = trim(strip_tags($aItem['authorEmail'])); $body = trim(strip_tags($aItem['body'])); $title = trim(strip_tags($aItem['title'])); $itemId = $aItem['id']; $userId = $aItem['userId']; $status_num = -1; $banned = osc_is_banned(trim(strip_tags($aItem['authorEmail']))); if($banned==1 || $banned==2) { Session::newInstance()->_setForm('commentAuthorName', $authorName); Session::newInstance()->_setForm('commentTitle', $title); Session::newInstance()->_setForm('commentBody', $body); Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail); return 5; } $item = $this->manager->findByPrimaryKey($itemId); View::newInstance()->_exportVariableToView('item', $item); $itemURL = osc_item_url(); $itemURL = '<a href="'.$itemURL.'" >'.$itemURL.'</a>'; Params::setParam('itemURL', $itemURL); if(osc_reg_user_post_comments() && !osc_is_web_user_logged_in()) { Session::newInstance()->_setForm('commentAuthorName', $authorName); Session::newInstance()->_setForm('commentTitle', $title); Session::newInstance()->_setForm('commentBody', $body); return 6; } if( !preg_match('|^.*?@.{2,}\..{2,3}$|', $authorEmail)) { Session::newInstance()->_setForm('commentAuthorName', $authorName); Session::newInstance()->_setForm('commentTitle', $title); Session::newInstance()->_setForm('commentBody', $body); return 3; } if( ($body == '') ) { Session::newInstance()->_setForm('commentAuthorName', $authorName); Session::newInstance()->_setForm('commentAuthorEmail', $authorEmail); Session::newInstance()->_setForm('commentTitle', $title); return 4; } $num_moderate_comments = osc_moderate_comments(); if($userId==null) { $num_comments = 0; } else { $user = User::newInstance()->findByPrimaryKey($userId); $num_comments = $user['i_comments']; } if ($num_moderate_comments == -1 || ($num_moderate_comments != 0 && $num_comments >= $num_moderate_comments)) { $status = 'ACTIVE'; $status_num = 2; } else { $status = 'INACTIVE'; $status_num = 1; } if (osc_akismet_key()) { require_once LIB_PATH . 'Akismet.class.php'; $akismet = new Akismet(osc_base_url(), osc_akismet_key()); $akismet->setCommentAuthor($authorName); $akismet->setCommentAuthorEmail($authorEmail); $akismet->setCommentContent($body); $akismet->setPermalink($itemURL); $status = $akismet->isCommentSpam() ? 'SPAM' : $status; if($status == 'SPAM') { $status_num = 5; } } $mComments = ItemComment::newInstance(); $aComment = array('dt_pub_date' => date('Y-m-d H:i:s') ,'fk_i_item_id' => $itemId ,'s_author_name' => $authorName ,'s_author_email' => $authorEmail ,'s_title' => $title ,'s_body' => $body ,'b_active' => ($status=='ACTIVE' ? 1 : 0) ,'b_enabled' => 1 ,'fk_i_user_id' => $userId); osc_run_hook('before_add_comment', $aComment); if( $mComments->insert($aComment) ) { $commentID = $mComments->dao->insertedId(); if($status_num == 2 && $userId != null) { // COMMENT IS ACTIVE $user = User::newInstance()->findByPrimaryKey($userId); if( $user ) { User::newInstance()->update( array( 'i_comments' => $user['i_comments'] + 1) ,array( 'pk_i_id' => $user['pk_i_id'] ) ); } } //Notify admin if ( osc_notify_new_comment() ) { osc_run_hook('hook_email_new_comment_admin', $aItem); } //Notify user if ( osc_notify_new_comment_user() ) { osc_run_hook('hook_email_new_comment_user', $aItem); } osc_run_hook( 'add_comment', $commentID ); return $status_num; } return -1; }
function fn_email_new_comment_user($aItem) { $authorName = trim($aItem['authorName']); $authorName = strip_tags($authorName); $authorEmail = trim($aItem['authorEmail']); $authorEmail = strip_tags($authorEmail); $body = trim($aItem['body']); $body = strip_tags($body); $title = $aItem['title']; $itemId = $aItem['id']; $userId = $aItem['userId']; $admin_email = osc_contact_email(); $prefLocale = osc_language(); $item = Item::newInstance()->findByPrimaryKey($itemId); View::newInstance()->_exportVariableToView('item', $item); $itemURL = osc_item_url(); $itemURL = '<a href="' . $itemURL . '" >' . $itemURL . '</a>'; $mPages = new Page(); $aPage = $mPages->findByInternalName('email_new_comment_user'); $locale = osc_current_user_locale(); $content = array(); if (isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $words = array(); $words[] = array('{COMMENT_AUTHOR}', '{COMMENT_EMAIL}', '{COMMENT_TITLE}', '{COMMENT_TEXT}', '{ITEM_TITLE}', '{ITEM_ID}', '{ITEM_URL}', '{SELLER_NAME}', '{SELLER_EMAIL}'); $words[] = array($authorName, $authorEmail, $title, $body, $item['s_title'], $itemId, $itemURL, $item['s_contact_name'], $item['s_contact_email']); $title_email = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_new_comment_user_title', $content['s_title'])), $words); $body_email = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_new_comment_user_description', $content['s_text'])), $words); $from = osc_contact_email(); $from_name = osc_page_title(); $emailParams = array('from' => $admin_email, 'from_name' => __('Admin mail system'), 'subject' => $title_email, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body_email, 'alt_body' => $body_email); osc_sendMail($emailParams); }
?> " alt="<?php echo osc_item_title(); ?> " class="img-responsive"></a> <?php } ?> </div> </div> <?php } ?> <div class="caption"> <h3><a href="<?php echo osc_item_url(); ?> "><?php echo osc_item_title(); ?> </a></h3> <p class="user"><?php _e('by', 'flatter'); ?> <?php if (osc_item_user_id() != null) { ?> <a href="<?php echo osc_user_public_profile_url(osc_item_user_id()); ?> " ><?php
function fn_email_warn_expiration($aItem) { $itemId = $aItem['pk_i_id']; $admin_email = osc_contact_email(); View::newInstance()->_exportVariableToView('item', $aItem); $itemURL = osc_item_url(); $itemURL = '<a href="'.$itemURL.'" >'.$itemURL.'</a>'; $mPages = new Page(); $aPage = $mPages->findByInternalName('email_warn_expiration'); $locale = osc_current_user_locale(); if(isset($aPage['locale'][$locale]['s_title'])) { $content = $aPage['locale'][$locale]; } else { $content = current($aPage['locale']); } $words = array(); $words[] = array( '{USER_NAME}', '{ITEM_TITLE}', '{ITEM_ID}', '{ITEM_EXPIRATION_DATE}', '{ITEM_URL}', '{ITEM_LINK}', '{SELLER_NAME}', '{SELLER_EMAIL}', '{CONTACT_NAME}', '{CONTACT_EMAIL}' ); $words[] = array( $aItem['s_contact_name'], $aItem['s_title'], $itemId, $aItem['dt_expiration'], osc_item_url(), $itemURL, $aItem['s_contact_name'], $aItem['s_contact_email'], $aItem['s_contact_name'], $aItem['s_contact_email'] ); $title_email = osc_apply_filter('email_warn_expiration_title_after', osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_warn_expiration_title', $content['s_title'], $aItem)), $words), $aItem); $body_email = osc_apply_filter('email_warn_expiration_description_after', osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_warn_expiration_description', $content['s_text'], $aItem)), $words), $aItem); $emailParams = array( 'from' => $admin_email, 'subject' => $title_email, 'to' => $aItem['s_contact_email'], 'to_name' => $aItem['s_contact_name'], 'body' => $body_email, 'alt_body' => $body_email ); osc_sendMail($emailParams); }