function doModel() { switch ($this->action) { case 'logout': // unset only the required parameters in Session Session::newInstance()->_drop('adminId'); Session::newInstance()->_drop('adminUserName'); Session::newInstance()->_drop('adminName'); Session::newInstance()->_drop('adminEmail'); Session::newInstance()->_drop('adminLocale'); Cookie::newInstance()->pop('oc_adminId'); Cookie::newInstance()->pop('oc_adminSecret'); Cookie::newInstance()->pop('oc_adminLocale'); Cookie::newInstance()->set(); $this->redirectTo(osc_admin_base_url(true)); break; default: //default dashboard page (main page at oc-admin) $this->_exportVariableToView("numUsers", User::newInstance()->count()); $this->_exportVariableToView("numAdmins", Admin::newInstance()->count()); $this->_exportVariableToView("numItems", Item::newInstance()->count()); $this->_exportVariableToView("numItemsSpam", Item::newInstance()->totalItems(null, 'SPAM')); $this->_exportVariableToView("numItemsBlock", Item::newInstance()->totalItems(null, 'DISABLED')); $this->_exportVariableToView("numItemsInactive", Item::newInstance()->totalItems(null, 'INACTIVE')); $this->_exportVariableToView("numItemsPerCategory", osc_get_non_empty_categories()); $this->_exportVariableToView("newsList", osc_listNews()); $this->_exportVariableToView("comments", ItemComment::newInstance()->getLastComments(5)); //calling the view... $this->doView('main/index.php'); } }
function update_cat_stats() { $categoryTotal = array(); $categoryTree = array(); $aCategories = Category::newInstance()->listAll(false); // append root categories and get the number of items of each category foreach ($aCategories as $category) { $total = Item::newInstance()->numItems($category, true, true); $category += array('category' => array()); if (is_null($category['fk_i_parent_id'])) { $categoryTree += array($category['pk_i_id'] => $category); } $categoryTotal += array($category['pk_i_id'] => $total); } // append childs to root categories foreach ($aCategories as $category) { if (!is_null($category['fk_i_parent_id'])) { $categoryTree[$category['fk_i_parent_id']]['category'][] = $category; } } // sum the result of the subcategories and set in the parent category foreach ($categoryTree as $category) { if (count($category['category']) > 0) { foreach ($category['category'] as $subcategory) { $categoryTotal[$category['pk_i_id']] += $categoryTotal[$subcategory['pk_i_id']]; } } } foreach ($categoryTotal as $k => $v) { CategoryStats::newInstance()->setNumItems($k, $v); } }
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); }
function doModel() { switch ($this->action) { case 'change_email_confirm': //change email confirm if (Params::getParam('userId') && Params::getParam('code')) { $userManager = new User(); $user = $userManager->findByPrimaryKey(Params::getParam('userId')); if ($user['s_pass_code'] == Params::getParam('code') && $user['b_enabled'] == 1) { $userEmailTmp = UserEmailTmp::newInstance()->findByPk(Params::getParam('userId')); $code = osc_genRandomPassword(50); $userManager->update(array('s_email' => $userEmailTmp['s_new_email']), array('pk_i_id' => $userEmailTmp['fk_i_user_id'])); Item::newInstance()->update(array('s_contact_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id'])); ItemComment::newInstance()->update(array('s_author_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id'])); Alerts::newInstance()->update(array('s_email' => $userEmailTmp['s_new_email']), array('fk_i_user_id' => $userEmailTmp['fk_i_user_id'])); Session::newInstance()->_set('userEmail', $userEmailTmp['s_new_email']); UserEmailTmp::newInstance()->delete(array('s_new_email' => $userEmailTmp['s_new_email'])); osc_add_flash_ok_message(_m('Your email has been changed successfully')); $this->redirectTo(osc_user_profile_url()); } else { osc_add_flash_error_message(_m('Sorry, the link is not valid')); $this->redirectTo(osc_base_url()); } } else { osc_add_flash_error_message(_m('Sorry, the link is not valid')); $this->redirectTo(osc_base_url()); } break; case 'activate_alert': $email = Params::getParam('email'); $secret = Params::getParam('secret'); $result = 0; if ($email != '' && $secret != '') { $result = Alerts::newInstance()->activate($email, $secret); } if ($result == 1) { osc_add_flash_ok_message(_m('Alert activated')); } else { osc_add_flash_error_message(_m('Ops! There was a problem trying to activate alert. Please contact the administrator')); } $this->redirectTo(osc_base_url(true)); break; case 'unsub_alert': $email = Params::getParam('email'); $secret = Params::getParam('secret'); if ($email != '' && $secret != '') { Alerts::newInstance()->delete(array('s_email' => $email, 'S_secret' => $secret)); osc_add_flash_ok_message(_m('Unsubscribed correctly')); } else { osc_add_flash_error_message(_m('Ops! There was a problem trying to unsubscribe you. Please contact the administrator')); } $this->redirectTo(osc_base_url()); break; default: $this->redirectTo(osc_user_login_url()); break; } }
function digitalgoods_item_edit($catId = null, $item_id = null) { if (osc_is_this_category('digitalgoods', $catId)) { $dg_files = DGModel::newInstance()->getFilesFromItem($item_id); $dg_item = Item::newInstance()->findByPrimaryKey($item_id); $secret = $dg_item['s_secret']; unset($dg_item); require_once 'item_edit.php'; } }
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_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_more[] = '<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>'; $options[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=comment_edit&id=' . $aRow['pk_i_id'] . '" id="dt_link_edit">' . __('Edit') . '</a>'; if ($aRow['b_active']) { $options[] = '<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[] = '<a href="' . osc_admin_base_url(true) . '?page=comments&action=status&id=' . $aRow['pk_i_id'] . '&' . $csrf_token_url . '&value=ACTIVE">' . __('Activate') . '</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; $status = $this->get_row_status($aRow); $row['status-border'] = ''; $row['status'] = $status['text']; $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'] = osc_format_date($aRow['dt_pub_date']); $row = osc_apply_filter('comments_processing_row', $row, $aRow); $this->addRow($row); $this->rawRows[] = $aRow; } } }
function insert_geo_location($catId, $itemId) { $aItem = Item::newInstance()->findByPrimaryKey($itemId); $sAddress = isset($aItem['s_address']) ? $aItem['s_address'] : ''; $sRegion = isset($aItem['s_region']) ? $aItem['s_region'] : ''; $sCity = isset($aItem['s_city']) ? $aItem['s_city'] : ''; $address = sprintf('%s, %s %s', $sAddress, $sRegion, $sCity); $response = osc_file_get_contents(sprintf('http://maps.google.com/maps/geo?q=%s&output=json&sensor=false', urlencode($address))); $jsonResponse = json_decode($response); if (isset($jsonResponse->Placemark) && count($jsonResponse->Placemark[0]) > 0) { $coord = $jsonResponse->Placemark[0]->Point->coordinates; ItemLocation::newInstance()->update(array('d_coord_lat' => $coord[1], 'd_coord_long' => $coord[0]), array('fk_i_item_id' => $itemId)); } }
function insert_geo_location($item) { $itemId = $item['pk_i_id']; $aItem = Item::newInstance()->findByPrimaryKey($itemId); $sAddress = isset($aItem['s_address']) ? $aItem['s_address'] : ''; $sCity = isset($aItem['s_city']) ? $aItem['s_city'] : ''; $sRegion = isset($aItem['s_region']) ? $aItem['s_region'] : ''; $sCountry = isset($aItem['s_country']) ? $aItem['s_country'] : ''; $address = sprintf('%s, %s, %s, %s', $sAddress, $sCity, $sRegion, $sCountry); $response = osc_file_get_contents(sprintf('https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false', urlencode($address))); $jsonResponse = json_decode($response); if (isset($jsonResponse->results[0]->geometry->location) && count($jsonResponse->results[0]->geometry->location) > 0) { $location = $jsonResponse->results[0]->geometry->location; $lat = $location->lat; $lng = $location->lng; ItemLocation::newInstance()->update(array('d_coord_lat' => $lat, 'd_coord_long' => $lng), array('fk_i_item_id' => $itemId)); } }
public function tableReported($params) { $this->addTableHeaderReported(); $this->mSearch = new Search(true); $this->getDBParams($params); // only some fields can be ordered $direction = Params::getParam('direction'); $arrayDirection = array('desc', 'asc'); if (!in_array($direction, $arrayDirection)) { Params::setParam('direction', 'desc'); $direction = 'desc'; } $sort = Params::getParam('sort'); $arraySortColumns = array('spam' => 'i_num_spam', 'bad' => 'i_num_bad_classified', 'rep' => 'i_num_repeated', 'off' => 'i_num_offensive', 'exp' => 'i_num_expired', 'date' => 'dt_pub_date'); // column sort if (!key_exists($sort, $arraySortColumns)) { $sort = 'dt_pub_date'; $this->mSearch->addHaving('i_num_spam > 0 OR i_num_bad_classified > 0 OR i_num_repeated > 0 OR i_num_offensive > 0 OR i_num_expired > 0'); } else { $sort = $arraySortColumns[$sort]; if ($sort != 'dt_pub_date') { $this->mSearch->addHaving($sort . ' > 0'); } else { $this->mSearch->addHaving('i_num_spam > 0 OR i_num_bad_classified > 0 OR i_num_repeated > 0 OR i_num_offensive > 0 OR i_num_expired > 0'); } } $this->mSearch->order($sort, $direction); $this->mSearch->addTable(sprintf("%st_item_stats s", DB_TABLE_PREFIX)); $this->mSearch->addField('SUM(s.`i_num_spam`) as i_num_spam'); $this->mSearch->addField('SUM(s.`i_num_bad_classified`) as i_num_bad_classified'); $this->mSearch->addField('SUM(s.`i_num_repeated`) as i_num_repeated'); $this->mSearch->addField('SUM(s.`i_num_offensive`) as i_num_offensive'); $this->mSearch->addField('SUM(s.`i_num_expired`) as i_num_expired'); // having $this->mSearch->addConditions(sprintf(" %st_item.pk_i_id ", DB_TABLE_PREFIX)); $this->mSearch->addConditions(sprintf(" %st_item.pk_i_id = s.fk_i_item_id", DB_TABLE_PREFIX)); $this->mSearch->addGroupBy(sprintf(" %st_item.pk_i_id ", DB_TABLE_PREFIX)); // do Search $this->processDataReported(Item::newInstance()->extendCategoryName($this->mSearch->doSearch(true))); $this->totalFiltered = $this->mSearch->countAll(); $this->total = $this->mSearch->count(); return $this->getData(); }
function __construct($params) { $this->mSearch = new Search(true); $this->_get = $params; $this->getDBParams(); $this->mSearch->limit($this->start, $this->limit); // only some fields can be ordered $this->mSearch->order($this->order_by['column_name'], $this->order_by['type'], $this->order_by['table_name']); if (Params::getParam('catId') != '') { $this->mSearch->addCategory(Params::getParam('catId')); } if ($this->search) { $this->mSearch->addPattern($this->search); } // do Search $list_items = $this->mSearch->doSearch(true); $this->items = Item::newInstance()->extendCategoryName($list_items); $this->total_filtered = $this->mSearch->countAll(); $this->total = $this->mSearch->count(); $this->toDatatablesFormat(); $this->dumpToDatatables(); }
function doModel() { switch ($this->action) { case 'logout': // unset only the required parameters in Session $this->logout(); $this->redirectTo(osc_admin_base_url(true)); break; default: //default dashboard page (main page at oc-admin) $this->_exportVariableToView("numItemsPerCategory", osc_get_non_empty_categories()); $this->_exportVariableToView("numUsers", User::newInstance()->count()); $this->_exportVariableToView("numItems", Item::newInstance()->count()); $this->_exportVariableToView('newsList', osc_listNews()); $this->_exportVariableToView('twitterRSS', osc_latestTweets()); // stats $items = array(); $stats_items = Stats::newInstance()->new_items_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $items[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_items as $item) { $items[$item['d_date']] = $item['num']; } $users = array(); $stats_users = Stats::newInstance()->new_users_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $users[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_users as $user) { $users[$user['d_date']] = $user['num']; } $this->_exportVariableToView("item_stats", $items); $this->_exportVariableToView("user_stats", $users); //calling the view... $this->doView('main/index.php'); } }
/** * Delete an user given its id * * @access public * @since unknown * @param int $id * @return bool */ public function deleteUser($id = null) { if ($id != null) { osc_run_hook('delete_user', $id); $this->dao->select('pk_i_id, fk_i_category_id'); $this->dao->from(DB_TABLE_PREFIX . "t_item"); $this->dao->where('fk_i_user_id', $id); $result = $this->dao->get(); $items = $result->result(); $itemManager = Item::newInstance(); foreach ($items as $item) { $itemManager->deleteByPrimaryKey($item['pk_i_id']); } ItemComment::newInstance()->delete(array('fk_i_user_id' => $id)); $this->dao->delete(DB_TABLE_PREFIX . 't_user_email_tmp', array('fk_i_user_id' => $id)); $this->dao->delete(DB_TABLE_PREFIX . 't_user_description', array('fk_i_user_id' => $id)); $this->dao->delete(DB_TABLE_PREFIX . 't_alerts', array('fk_i_user_id' => $id)); return $this->dao->delete($this->getTableName(), array('pk_i_id' => $id)); } return false; }
/* if (osc_user_phone() != '') { ?> <div class="user-phone"> <i class="fa fa-phone"></i> <span><?php echo osc_user_phone() ?></span> </div> <?php }*/ ?> <div class="divider"></div> <?php } ?> <?php $aItems = Item::newInstance()->findByUserID(osc_item_user_id(), 0, 3); View::newInstance()->_exportVariableToView('items', $aItems); ?> <div class="user-products"> <p><?php printf(__('Other products from %s', 'pop'), osc_user_name()); ?> </p> <div> <?php while (osc_has_items()) { if (osc_count_item_resources()) { osc_get_item_resources(); ?> <a class="user-item" href="<?php echo osc_item_url();
/** * Gets premium meta fields * * @return array */ function osc_get_premium_meta() { if (!View::newInstance()->_exists('metafields')) { View::newInstance()->_exportVariableToView('metafields', Item::newInstance()->metaFields(osc_premium_id())); } return View::newInstance()->_get('metafields'); }
function edit() { $aItem = $this->data; $flash_error = ''; // Sanitize foreach(@$aItem['title'] as $key=>$value) { $aItem['title'][$key] = strip_tags( trim ( $value ) ); } $aItem['price'] = !is_null($aItem['price']) ? strip_tags( trim( $aItem['price'] ) ) : $aItem['price']; $aItem['cityArea'] = osc_sanitize_name( strip_tags( trim( $aItem['cityArea'] ) ) ); $aItem['address'] = osc_sanitize_name( strip_tags( trim( $aItem['address'] ) ) ); // Validate if ( !$this->checkAllowedExt($aItem['photos']) ) { $flash_error .= _m("Image with an incorrect extension.") . PHP_EOL; } if ( !$this->checkSize($aItem['photos']) ) { $flash_error .= _m("Image is too big. Max. size") . osc_max_size_kb() . " Kb" . PHP_EOL; } $title_message = ''; $td_message = ''; foreach(@$aItem['title'] as $key => $value) { if( osc_validate_text($value, 1) && osc_validate_max($value, osc_max_characters_per_title()) ) { $td_message = ''; break; } $td_message .= (!osc_validate_text($value, 1) ? _m("Title too short.") . PHP_EOL : '' ) . (!osc_validate_max($value, osc_max_characters_per_title()) ? _m("Title too long.") . PHP_EOL : '' ); } $flash_error .= $td_message; $desc_message = ''; foreach(@$aItem['description'] as $key => $value) { if( osc_validate_text($value, 3) && osc_validate_max($value, osc_max_characters_per_description()) ) { $desc_message = ''; break; } $desc_message .= (!osc_validate_text($value, 3) ? _m("Description too short.") . PHP_EOL : '' ) . (!osc_validate_max($value, osc_max_characters_per_description()) ? _m("Description too long."). PHP_EOL : '' ); } $flash_error .= $desc_message; $flash_error .= ((!osc_validate_category($aItem['catId'])) ? _m("Category invalid.") . PHP_EOL : '' ) . ((!osc_validate_number($aItem['price'])) ? _m("Price must be a number.") . PHP_EOL : '' ) . ((!osc_validate_max(number_format($aItem['price'],0,'',''), 15)) ? _m("Price too long.") . PHP_EOL : '' ) . ((!is_null($aItem['price']) && (int)$aItem['price']<0 ) ? _m('Price must be positive number.') . PHP_EOL : '' ) . ((!osc_validate_text($aItem['countryName'], 3, false)) ? _m("Country too short.") . PHP_EOL : '' ) . ((!osc_validate_max($aItem['countryName'], 50)) ? _m("Country too long.") . PHP_EOL : '' ) . ((!osc_validate_text($aItem['regionName'], 2, false)) ? _m("Region too short.") . PHP_EOL : '' ) . ((!osc_validate_max($aItem['regionName'], 50)) ? _m("Region too long.") . PHP_EOL : '' ) . ((!osc_validate_text($aItem['cityName'], 2, false)) ? _m("City too short.") . PHP_EOL : '' ) . ((!osc_validate_max($aItem['cityName'], 50)) ? _m("City too long.") . PHP_EOL : '' ) . ((!osc_validate_text($aItem['cityArea'], 3, false)) ? _m("Municipality too short.") . PHP_EOL : '' ) . ((!osc_validate_max($aItem['cityArea'], 50)) ? _m("Municipality too long.") . PHP_EOL : '' ) . ((!osc_validate_text($aItem['address'], 3, false))? _m("Address too short.") . PHP_EOL : '' ) . ((!osc_validate_max($aItem['address'], 100)) ? _m("Address too long.") . PHP_EOL : '' ); $_meta = Field::newInstance()->findByCategory($aItem['catId']); $meta = Params::getParam("meta"); foreach($_meta as $_m) { $meta[$_m['pk_i_id']] = (isset($meta[$_m['pk_i_id']]))?$meta[$_m['pk_i_id']]:''; } if($meta!='' && count($meta)>0) { $mField = Field::newInstance(); foreach($meta as $k => $v) { if($v=='') { $field = $mField->findByPrimaryKey($k); if($field['b_required']==1) { $flash_error .= sprintf(_m("%s field is required."), $field['s_name']) . PHP_EOL; } } } }; // hook pre add or edit // DEPRECATED : preitem_psot will be removed in 3.4 osc_run_hook('pre_item_post'); osc_run_hook('pre_item_edit', $aItem); // Handle error if ($flash_error) { $success = $flash_error; } else { $location = array( 'fk_c_country_code' => $aItem['countryId'], 's_country' => $aItem['countryName'], 'fk_i_region_id' => $aItem['regionId'], 's_region' => $aItem['regionName'], 'fk_i_city_id' => $aItem['cityId'], 's_city' => $aItem['cityName'], 's_city_area' => $aItem['cityArea'], 's_address' => $aItem['address'], 'd_coord_lat' => $aItem['d_coord_lat'], 'd_coord_long' => $aItem['d_coord_long'], 's_zip' => $aItem['s_zip'] ); $locationManager = ItemLocation::newInstance(); $old_item_location = $locationManager->findByPrimaryKey($aItem['idItem']); $locationManager->update( $location, array( 'fk_i_item_id' => $aItem['idItem'] ) ); $old_item = $this->manager->findByPrimaryKey( $aItem['idItem'] ); if($aItem['userId'] != '') { $user = User::newInstance()->findByPrimaryKey( $aItem['userId'] ); $aItem['userId'] = $aItem['userId']; $aItem['contactName'] = $user['s_name']; $aItem['contactEmail'] = $user['s_email']; } else { $aItem['userId'] = NULL; } if($aItem['price']!='') { $aItem['currency'] = $aItem['currency']; } else { $aItem['currency'] = NULL; } $aUpdate = array( 'dt_mod_date' => date('Y-m-d H:i:s') ,'fk_i_category_id' => $aItem['catId'] ,'i_price' => $aItem['price'] ,'fk_c_currency_code' => $aItem['currency'] ,'b_show_email' => $aItem['showEmail'] ); // only can change the user if you're an admin if( $this->is_admin ) { $aUpdate['fk_i_user_id'] = $aItem['userId']; $aUpdate['s_contact_name'] = $aItem['contactName']; $aUpdate['s_contact_email'] = $aItem['contactEmail']; } else { $aUpdate['s_ip'] = $aItem['s_ip']; } $result = $this->manager->update( $aUpdate, array('pk_i_id' => $aItem['idItem'], 's_secret' => $aItem['secret'] ) ); // UPDATE title and description locales $this->insertItemLocales( 'EDIT', $aItem['title'], $aItem['description'], $aItem['idItem'] ); // UPLOAD item resources $this->uploadItemResources( $aItem['photos'], $aItem['idItem'] ); Log::newInstance()->insertLog('item', 'edit', $aItem['idItem'], current(array_values($aItem['title'])), $this->is_admin?'admin':'user', $this->is_admin?osc_logged_admin_id():osc_logged_user_id()); /** * META FIELDS */ if($meta!='' && count($meta)>0) { $mField = Field::newInstance(); foreach($meta as $k => $v) { // if dateinterval if( is_array($v) && !isset($v['from']) && !isset($v['to']) ) { $v = implode(',', $v); } $mField->replace($aItem['idItem'], $k, $v); } } $oldIsExpired = osc_isExpired($old_item['dt_expiration']); $dt_expiration = Item::newInstance()->updateExpirationDate($aItem['idItem'], $aItem['dt_expiration'], false); if($dt_expiration===false) { $dt_expiration = $old_item['dt_expiration']; $aItem['dt_expiration'] = $old_item['dt_expiration']; } $newIsExpired = osc_isExpired($dt_expiration); // Recalculate stats related with items $this->_updateStats($result, $old_item, $oldIsExpired, $old_item_location, $aItem, $newIsExpired, $location); unset($old_item); // THIS HOOK IS FINE, YAY! osc_run_hook('edited_item', Item::newInstance()->findByPrimaryKey($aItem['idItem'])); $success = $result; } return $success; }
public function deleteUser($id = null) { if ($id != null) { osc_run_hook('delete_user', $id); $items = $this->conn->osc_dbFetchResults("SELECT pk_i_id FROM %st_item WHERE fk_i_user_id = %d", DB_TABLE_PREFIX, $id); $itemManager = Item::newInstance(); foreach ($items as $item) { $itemManager->deleteByPrimaryKey($item['pk_i_id']); } $this->conn->osc_dbExec('DELETE FROM %st_user_email_tmp WHERE fk_i_user_id = %d', DB_TABLE_PREFIX, $id); $this->conn->osc_dbExec('DELETE FROM %st_user_description WHERE fk_i_user_id = %d', DB_TABLE_PREFIX, $id); $this->conn->osc_dbExec('DELETE FROM %st_alerts WHERE fk_i_user_id = %d', DB_TABLE_PREFIX, $id); $this->conn->osc_dbExec('DELETE FROM %st_user WHERE pk_i_id = %d', DB_TABLE_PREFIX, $id); return true; } return false; }
$conn->osc_dbExec(sprintf("INSERT INTO %st_preference VALUES ('osclass', 'comments_per_page', '10', 'INTEGER')", DB_TABLE_PREFIX)); $conn->osc_dbExec(sprintf("INSERT INTO %st_preference VALUES ('osclass', 'reg_user_post_comments', '0', 'BOOLEAN')", DB_TABLE_PREFIX)); $conn->osc_dbExec(sprintf("INSERT INTO %st_preference VALUES ('osclass', 'reg_user_can_contact', '0', 'BOOLEAN')", DB_TABLE_PREFIX)); $conn->osc_dbExec(sprintf("INSERT INTO %st_preference VALUES ('osclass', 'allow_report_osclass', '1', 'BOOLEAN')", DB_TABLE_PREFIX)); $users = User::newInstance()->listAll(); foreach ($users as $user) { $comments = count(ItemComment::newInstance()->findByAuthorID($user['pk_i_id'])); $items = count(Item::newInstance()->findByUserIDEnabled($user['pk_i_id'])); User::newInstance()->update(array('i_items' => $items, 'i_comments' => $comments), array('pk_i_id' => $user['pk_i_id'])); // CHANGE FROM b_enabled to b_active User::newInstance()->update(array('b_active' => $user['b_enabled'], 'b_enabled' => 1), array('pk_i_id' => $user['pk_i_id'])); } unset($users); $items = $conn->osc_dbFetchResults(sprintf("SELECT * FROM %st_item", DB_TABLE_PREFIX)); foreach ($items as $item) { Item::newInstance()->update(array("b_active" => $item['e_status'] == 'ACTIVE' ? 1 : 0, 'b_enabled' => 1), array('pk_i_id' => $item['pk_i_id'])); } unset($items); $comments = $conn->osc_dbFetchResults(sprintf("SELECT * FROM %st_item_comment", DB_TABLE_PREFIX)); foreach ($comments as $comment) { ItemComment::newInstance()->update(array("b_active" => $comment['e_status'] == 'ACTIVE' ? 1 : 0, 'b_enabled' => 1), array('pk_i_id' => $comment['pk_i_id'])); } unset($comments); // Drop e_status column in t_item and t_item_comment $conn->osc_dbExec(sprintf("ALTER TABLE %st_item DROP e_status", DB_TABLE_PREFIX)); $conn->osc_dbExec(sprintf("ALTER TABLE %st_item_comment DROP e_status", DB_TABLE_PREFIX)); // Delete enabled_item_validation in t_preference $conn->osc_dbExec(sprintf("DELETE FROM %st_preference WHERE s_name = 'enabled_item_validation'", DB_TABLE_PREFIX)); // insert two new e-mail notifications $conn->osc_dbExec(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_alert_validation', 1, '%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s'))); $conn->osc_dbExec(sprintf("INSERT INTO %st_pages_description (fk_i_pages_id, fk_c_locale_code, s_title, s_text) VALUES (%d, 'en_US', 'Please validate your alert', '<p>Hi {USER_NAME},</p>\n<p>Please validate your alert registration by clicking on the following link: {VALIDATION_LINK}</p>\n<p>Thank you!</p>\n<p>Regards,</p>\n<p>{WEB_TITLE}</p>')", DB_TABLE_PREFIX, $conn->get_last_id()));
function sendCommentActivated($commentId) { $aComment = $this->itemCommentManager->findByPrimaryKey($commentId); $aItem = Item::newInstance()->findByPrimaryKey($aComment['fk_i_item_id']); View::newInstance()->_exportVariableToView('item', $aItem); osc_run_hook('hook_email_comment_validated', $aComment); }
<?php if (osc_get_preference('pay_per_post', 'payment')) { // Load Item Information, so we could tell the user which item is he/she paying for $item = Item::newInstance()->findByPrimaryKey(Params::getParam('itemId')); if ($item) { // Check if it's already payed or not if (!ModelPayment::newInstance()->publishFeeIsPaid(Params::getParam("itemId"))) { // Item is not paid, continue $category_fee = ModelPayment::newInstance()->getPublishPrice($item['fk_i_category_id']); if ($category_fee > 0) { ?> <h1><?php _e('Continue the publish process', 'payment'); ?> </h1> <div> <div class="payments-preview"> <label style="font-weight: bold;"><?php _e("Item's title", 'payment'); ?> :</label> <?php echo $item['s_title']; ?> <br/> <label style="font-weight: bold;"><?php _e("Item's description", 'payment'); ?> :</label> <?php echo $item['s_description'];
public function getPremiums($max = 2) { $this->order(sprintf('order_premium_views', DB_TABLE_PREFIX), 'ASC'); $this->page(0, $max); $this->addField(sprintf('sum(%st_item_stats.i_num_premium_views) as total_premium_views', DB_TABLE_PREFIX)); $this->addField(sprintf('(sum(%st_item_stats.i_num_premium_views) + sum(%st_item_stats.i_num_premium_views)*RAND()*0.7 + TIMESTAMPDIFF(DAY,%st_item.dt_pub_date,\'%s\')*0.3) as order_premium_views', DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX, date('Y-m-d H:i:s'))); $this->addTable(sprintf('%st_item_stats', DB_TABLE_PREFIX)); $this->addConditions(sprintf('%st_item_stats.fk_i_item_id = %st_item.pk_i_id', DB_TABLE_PREFIX, DB_TABLE_PREFIX)); $this->addConditions(sprintf("%st_item.b_premium = 1", DB_TABLE_PREFIX)); $items = $this->doSearch(false); $mStat = ItemStats::newInstance(); foreach ($items as $item) { $mStat->increase('i_num_premium_views', $item['pk_i_id']); } return Item::newInstance()->extendData($items); }
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; } }
function fn_email_new_comment_admin($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_admin'); $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}'); $words[] = array($authorName, $authorEmail, $title, $body, $item['s_title'], $itemId, $itemURL); $title_email = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_new_comment_admin_title', $content['s_title'])), $words); $body_email = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_new_comment_admin_description', $content['s_text'])), $words); $from = osc_contact_email(); $from_name = osc_page_title(); if (osc_notify_contact_item()) { $add_bbc = osc_contact_email(); } $emailParams = array('from' => $admin_email, 'from_name' => __('Admin mail system'), 'subject' => $title_email, 'to' => $admin_email, 'to_name' => __('Admin mail system'), 'body' => $body_email, 'alt_body' => $body_email); osc_sendMail($emailParams); }
foreach ($comments as $comment) { ItemComment::newInstance()->update(array("b_active" => $comment['e_status'] == 'ACTIVE' ? 1 : 0, 'b_enabled' => 1), array('pk_i_id' => $comment['pk_i_id'])); } unset($comments); // populate b_active/b_enabled (t_item) $result = $comm->query(sprintf("SELECT * FROM %st_item", DB_TABLE_PREFIX)); $items = $result->result(); foreach ($items as $item) { Item::newInstance()->update(array("b_active" => $item['e_status'] == 'ACTIVE' ? 1 : 0, 'b_enabled' => 1), array('pk_i_id' => $item['pk_i_id'])); } unset($items); // populate i_items/i_comments/b_active/b_enabled (t_user) $users = User::newInstance()->listAll(); foreach ($users as $user) { $comments = count(ItemComment::newInstance()->findByAuthorID($user['pk_i_id'])); $items = count(Item::newInstance()->findByUserIDEnabled($user['pk_i_id'])); User::newInstance()->update(array('i_items' => $items, 'i_comments' => $comments), array('pk_i_id' => $user['pk_i_id'])); // CHANGE FROM b_enabled to b_active User::newInstance()->update(array('b_active' => $user['b_enabled'], 'b_enabled' => 1), array('pk_i_id' => $user['pk_i_id'])); } unset($users); // Drop e_status column in t_item and t_item_comment $comm->query(sprintf("ALTER TABLE %st_item DROP e_status", DB_TABLE_PREFIX)); $comm->query(sprintf("ALTER TABLE %st_item_comment DROP e_status", DB_TABLE_PREFIX)); // Delete enabled_item_validation in t_preference $comm->query(sprintf("DELETE FROM %st_preference WHERE s_name = 'enabled_item_validation'", DB_TABLE_PREFIX)); // insert two new e-mail notifications $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_alert_validation', 1, '%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s'))); $comm->query(sprintf("INSERT INTO %st_pages_description (fk_i_pages_id, fk_c_locale_code, s_title, s_text) VALUES (%d, 'en_US', 'Please validate your alert', '<p>Hi {USER_NAME},</p>\n<p>Please validate your alert registration by clicking on the following link: {VALIDATION_LINK}</p>\n<p>Thank you!</p>\n<p>Regards,</p>\n<p>{WEB_TITLE}</p>')", DB_TABLE_PREFIX, $comm->insertedId())); $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_comment_validated', 1, '%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s'))); $comm->query(sprintf("INSERT INTO %st_pages_description (fk_i_pages_id, fk_c_locale_code, s_title, s_text) VALUES (%d, 'en_US', '{WEB_TITLE} - Your comment has been approved', '<p>Hi {COMMENT_AUTHOR},</p>\n<p>Your comment has been approved on the following item: {ITEM_URL}</p>\n<p>Regards,</p>\n<p>{WEB_TITLE}</p>')", DB_TABLE_PREFIX, $comm->insertedId()));
/** * Recount items for a given a category id * * @param int $id */ function osc_update_cat_stats_id($id) { // get sub categorias if (!Category::newInstance()->isRoot($id)) { $auxCat = Category::newInstance()->findRootCategory($id); $id = $auxCat['pk_i_id']; } $aCategories = Category::newInstance()->findSubcategories($id); $categoryTotal = 0; if (count($aCategories) > 0) { // sumar items de la categoría foreach ($aCategories as $category) { $total = Item::newInstance()->numItems($category, true, true); $categoryTotal += $total; } $categoryTotal += Item::newInstance()->numItems(Category::newInstance()->findByPrimaryKey($id), true, true); } else { $category = Category::newInstance()->findByPrimaryKey($id); $total = Item::newInstance()->numItems($category, true, true); $categoryTotal += $total; } $sql = 'REPLACE INTO ' . DB_TABLE_PREFIX . 't_category_stats (fk_i_category_id, i_num_items) VALUES '; $sql .= " (" . $id . ", " . $categoryTotal . ")"; $result = CategoryStats::newInstance()->dao->query($sql); }
public function deleteByPrimaryKey($pk) { $items = Item::newInstance()->findByCategoryID($pk); $subcats = $this->findSubcategories($pk); if (count($subcats) > 0) { foreach ($subcats as $s) { $this->deleteByPrimaryKey($s["pk_i_id"]); } } if (count($items) > 0) { foreach ($items as $item) { Item::newInstance()->deleteByPrimaryKey($item["pk_i_id"]); } } $this->conn->osc_dbExec("DELETE FROM %s WHERE fk_i_category_id = '" . $pk . "'", $this->getTableDescriptionName()); $this->conn->osc_dbExec("DELETE FROM %s WHERE pk_i_id = '" . $pk . "'", $this->getTableName()); }
function doModel() { switch ($this->action) { case 'logout': // unset only the required parameters in Session osc_run_hook('logout_admin'); $this->logout(); $this->redirectTo(osc_admin_base_url(true)); break; default: //default dashboard page (main page at oc-admin) $this->_exportVariableToView("numItemsPerCategory", osc_get_non_empty_categories()); $this->_exportVariableToView("numUsers", User::newInstance()->count()); $this->_exportVariableToView("numItems", Item::newInstance()->count()); // stats $items = array(); $stats_items = Stats::newInstance()->new_items_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $items[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_items as $item) { $items[$item['d_date']] = $item['num']; } $users = array(); $stats_users = Stats::newInstance()->new_users_count(date('Y-m-d H:i:s', mktime(0, 0, 0, date("m"), date("d") - 10, date("Y"))), 'day'); for ($k = 10; $k >= 0; $k--) { $users[date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") - $k, date("Y")))] = 0; } foreach ($stats_users as $user) { $users[$user['d_date']] = $user['num']; } if (function_exists('disk_free_space')) { $freedisk = @disk_free_space(osc_uploads_path()); if ($freedisk !== false && $freedisk < 52428800) { //52428800 = 50*1024*1024 osc_add_flash_error_message(_m('You have very few free space left, users will not be able to upload pictures'), 'admin'); } } // show messages subscribed $status_subscribe = Params::getParam('subscribe_osclass'); if ($status_subscribe != '') { switch ($status_subscribe) { case -1: osc_add_flash_error_message(_m('Entered an invalid email'), 'admin'); break; case 0: osc_add_flash_warning_message(_m("You're already subscribed"), 'admin'); break; case 1: osc_add_flash_ok_message(_m('Subscribed correctly'), 'admin'); break; default: osc_add_flash_warning_message(_m("Error subscribing"), 'admin'); break; } } $this->_exportVariableToView("item_stats", $items); $this->_exportVariableToView("user_stats", $users); //calling the view... $this->doView('main/index.php'); } }
/** * Return latest posted items, you can filter by category and specify the * number of items returned. * * @param int $numItems * @param mixed $category int or array(int) * @param bool $withPicture * @return array */ public function getLatestItems($numItems = 10, $category = array(), $withPicture = false) { $this->dao->select(DB_TABLE_PREFIX . 't_item.* '); // from + tables $this->dao->from(DB_TABLE_PREFIX . 't_item use index (PRIMARY)'); if ($withPicture) { $this->dao->from(sprintf('%st_item_resource', DB_TABLE_PREFIX)); $this->dao->where(sprintf("%st_item_resource.s_content_type LIKE '%%image%%' AND %st_item.pk_i_id = %st_item_resource.fk_i_item_id", DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX)); } // where $whe = DB_TABLE_PREFIX . 't_item.b_active = 1 AND '; $whe .= DB_TABLE_PREFIX . 't_item.b_enabled = 1 AND '; $whe .= DB_TABLE_PREFIX . 't_item.b_spam = 0 AND '; $whe .= '(' . DB_TABLE_PREFIX . 't_item.b_premium = 1 || ' . DB_TABLE_PREFIX . 't_item.dt_expiration >= \'' . date('Y-m-d H:i:s') . '\') '; //$whe .= 'AND '.DB_TABLE_PREFIX.'t_category.b_enabled = 1 '; if (is_array($category) && count($category) > 0) { $listCategories = implode(',', $category); $whe .= ' AND ' . DB_TABLE_PREFIX . 't_item.fk_i_category_id IN (' . $listCategories . ') '; } $this->dao->where($whe); // group by & order & limit $this->dao->groupBy(DB_TABLE_PREFIX . 't_item.pk_i_id'); $this->dao->orderBy(DB_TABLE_PREFIX . 't_item.pk_i_id', 'DESC'); $this->dao->limit(0, $numItems); $rs = $this->dao->get(); if ($rs === false) { return array(); } if ($rs->numRows() == 0) { return array(); } $items = $rs->result(); return Item::newInstance()->extendData($items); }
/** * Delete a city area * * @access public * @since 3.1 * @param $pk * @return int number of failed deletions or 0 in case of none */ function deleteByPrimaryKey($pk) { Item::newInstance()->deleteByCityArea($pk); User::newInstance()->update(array('fk_i_city_area_id' => null, 's_city_area' => ''), array('fk_i_city_area_id' => $pk)); if (!$this->delete(array('pk_i_id' => $pk))) { return 1; } return 0; }
case "UNFOLLOW": if (osc_is_web_user_logged_in()) { $user_id = osc_logged_user_id(); $seller_id = Params::getParam("seller-id"); $return_url = Params::getParam("return_url"); nc_osc_delete_follow($user_id, $seller_id); header('Location:' . htmlspecialchars_decode($return_url)); } break; case "ADD-WATCHLIST": if (osc_is_web_user_logged_in()) { $user_id = osc_logged_user_id(); $item_id = Params::getParam("item_id"); $return_url = Params::getParam("return_url"); nc_osc_add_watchllist($user_id, $item_id); $aItem = Item::newInstance()->findByPrimaryKey($item_id); $item_title = $aItem['s_title']; osc_add_flash_ok_message($item_title . " is added to your watch list."); header('Location:' . htmlspecialchars_decode($return_url)); } break; case "REMOVE-WATCHLIST": if (osc_is_web_user_logged_in()) { $user_id = osc_logged_user_id(); $item_id = Params::getParam("item_id"); $return_url = Params::getParam("return_url"); nc_osc_remove_watchlist($user_id, $item_id); header('Location:' . htmlspecialchars_decode($return_url)); } break; }
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()); } } } }