function doModel() { switch ($this->action) { case 'advanced': //calling the advanced settings view $this->doView('settings/advanced.php'); break; case 'advanced_post': // updating advanced settings if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced'); } osc_csrf_check(); $subdomain_type = Params::getParam('e_type'); if (!in_array($subdomain_type, array('category', 'country', 'region', 'city', 'user'))) { $subdomain_type = ''; } $iUpdated = osc_set_preference('subdomain_type', $subdomain_type); $iUpdated += osc_set_preference('subdomain_host', Params::getParam('s_host')); if ($iUpdated > 0) { osc_add_flash_ok_message(_m("Advanced settings have been updated"), 'admin'); } osc_calculate_location_slug(osc_subdomain_type()); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced'); break; case 'advanced_cache_flush': osc_cache_flush(); osc_add_flash_ok_message(_m("Cache flushed correctly"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=advanced'); break; } }
function osc_subdomain_base_url($params = array()) { $fields['category'] = 'sCategory'; $fields['country'] = 'sCountry'; $fields['region'] = 'sRegion'; $fields['city'] = 'sCity'; $fields['user'] = '******'; if (isset($fields[osc_subdomain_type()])) { $field = $fields[osc_subdomain_type()]; if (isset($params[$field]) && !is_array($params[$field]) && $params[$field] != '' && strpos($params[$field], ',') === false) { return osc_search_url(array($fields[osc_subdomain_type()] => $params[$field])); } } return osc_base_url(); }
osc_set_preference('mailserver_name_from', ''); osc_set_preference('seo_url_search_prefix', ''); $comm->query(sprintf("ALTER TABLE %st_category ADD `b_price_enabled` TINYINT(1) NOT NULL DEFAULT 1", DB_TABLE_PREFIX)); osc_set_preference('subdomain_type', ''); osc_set_preference('subdomain_host', ''); // email_new_admin $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_new_admin', 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} - Success creating admin account!', '<p>Hi {ADMIN_NAME},</p><p>The admin of {WEB_LINK} has created an account for you,</p><ul><li>Username: {USERNAME}</li><li>Password: {PASSWORD}</li></ul><p>You can access the admin panel here {WEB_ADMIN_LINK}.</p><p>Thank you!</p><p>Regards,</p>')", DB_TABLE_PREFIX, $comm->insertedId())); osc_set_preference('warn_expiration', '0', 'osclass', 'INTEGER'); $comm->query(sprintf("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('email_warn_expiration', 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 ad is about to expire', '<p>Hi {USER_NAME},</p><p>Your listing <a href=\"{ITEM_URL}\">{ITEM_TITLE}</a> is about to expire at {WEB_LINK}.')", DB_TABLE_PREFIX, $comm->insertedId())); osc_set_preference('force_aspect_image', '0', 'osclass', 'BOOLEAN'); } if (osc_version() < 321) { if (function_exists('osc_calculate_location_slug')) { osc_calculate_location_slug(osc_subdomain_type()); } } if (osc_version() < 330) { @mkdir(osc_content_path() . 'uploads/temp/'); @mkdir(osc_content_path() . 'downloads/oc-temp/', 0777); @unlink(osc_lib_path() . 'osclass/classes/Watermark.php'); osc_set_preference('title_character_length', '100', 'osclass', 'INTEGER'); osc_set_preference('description_character_length', '5000', 'osclass', 'INTEGER'); } if (osc_version() < 340) { $comm->query(sprintf("ALTER TABLE `%st_widget` ADD INDEX `idx_s_description` (`s_description`);", DB_TABLE_PREFIX)); osc_set_preference('force_jpeg', '0', 'osclass', 'BOOLEAN'); @unlink(ABS_PATH . '.maintenance'); // THESE LINES PROBABLY HIT LOW TIMEOUT SCRIPTS, RUN THE LAST OF THE UPGRADE PROCESS //osc_calculate_location_slug('country');
/** * Gets search url given params * * @params array $params * @return string */ function osc_search_url($params = null) { if (is_array($params)) { osc_prune_array($params); } $countP = count($params); if ($countP == 0) { $params['page'] = 'search'; } $base_url = osc_base_url(); $http_url = osc_is_ssl() ? "https://" : "http://"; if (osc_subdomain_type() == 'category' && isset($params['sCategory'])) { if ($params['sCategory'] != Params::getParam('sCategory')) { if (is_array($params['sCategory'])) { $params['sCategory'] = implode(",", $params['sCategory']); } if ($params['sCategory'] != '' && strpos($params['sCategory'], ",") === false) { if (is_numeric($params['sCategory'])) { $category = Category::newInstance()->findByPrimaryKey($params['sCategory']); } else { $category = Category::newInstance()->findBySlug($params['sCategory']); } if (isset($category['s_slug'])) { $base_url = $http_url . $category['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL; unset($params['sCategory']); } } } else { if (osc_is_subdomain()) { unset($params['sCategory']); } } } else { if (osc_subdomain_type() == 'country' && isset($params['sCountry'])) { if ($params['sCountry'] != Params::getParam('sCountry')) { if (is_array($params['sCountry'])) { $params['sCountry'] = implode(",", $params['sCountry']); } if ($params['sCountry'] != '' && strpos($params['sCountry'], ",") === false) { if (is_numeric($params['sCountry'])) { $country = Country::newInstance()->findByPrimaryKey($params['sCountry']); } else { $country = Country::newInstance()->findByCode($params['sCountry']); } if (isset($country['s_slug'])) { $base_url = $http_url . $country['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL; unset($params['sCountry']); } } } else { if (osc_is_subdomain()) { unset($params['sCountry']); } } } else { if (osc_subdomain_type() == 'region' && isset($params['sRegion'])) { if ($params['sRegion'] != Params::getParam('sRegion')) { if (is_array($params['sRegion'])) { $params['sRegion'] = implode(",", $params['sRegion']); } if ($params['sRegion'] != '' && strpos($params['sRegion'], ",") === false) { if (is_numeric($params['sRegion'])) { $region = Region::newInstance()->findByPrimaryKey($params['sRegion']); } else { $region = Region::newInstance()->findByName($params['sRegion']); } if (isset($region['s_slug'])) { $base_url = $http_url . $region['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL; unset($params['sRegion']); } } } else { if (osc_is_subdomain()) { unset($params['sRegion']); } } } else { if (osc_subdomain_type() == 'city' && isset($params['sCity'])) { if ($params['sCity'] != Params::getParam('sCity')) { if (is_array($params['sCity'])) { $params['sCity'] = implode(",", $params['sCity']); } if ($params['sCity'] != '' && strpos($params['sCity'], ",") === false) { if (is_numeric($params['sCity'])) { $city = City::newInstance()->findByPrimaryKey($params['sCity']); } else { $city = City::newInstance()->findByName($params['sCity']); } if (isset($city['s_slug'])) { $base_url = $http_url . $city['s_slug'] . "." . osc_subdomain_host() . REL_WEB_URL; unset($params['sCity']); } } } else { if (osc_is_subdomain()) { unset($params['sCity']); } } } else { if (osc_subdomain_type() == 'user' && isset($params['sUser'])) { if ($params['sUser'] != Params::getParam('sUser')) { if (is_array($params['sUser'])) { $params['sUser'] = implode(",", $params['sUser']); } if ($params['sUser'] != '' && strpos($params['sUser'], ",") === false) { if (is_numeric($params['sUser'])) { $user = User::newInstance()->findByPrimaryKey($params['sUser']); } else { $user = User::newInstance()->findByUsername($params['sUser']); } if (isset($user['s_username'])) { $base_url = $http_url . $user['s_username'] . "." . osc_subdomain_host() . REL_WEB_URL; unset($params['sUser']); } } } else { if (osc_is_subdomain()) { unset($params['sUser']); } } } } } } } $countP = count($params); if ($countP == 0) { return $base_url; } unset($params['page']); $countP = count($params); if (osc_rewrite_enabled()) { $url = $base_url . osc_get_preference('rewrite_search_url'); // CANONICAL URLS if (isset($params['sCategory']) && !is_array($params['sCategory']) && strpos($params['sCategory'], ',') === false && ($countP == 1 || $countP == 2 && isset($params['iPage']))) { if (osc_category_id() == $params['sCategory']) { $category['pk_i_id'] = osc_category_id(); $category['s_slug'] = osc_category_slug(); } else { if (is_numeric($params['sCategory'])) { $category = Category::newInstance()->findByPrimaryKey($params['sCategory']); } else { $category = Category::newInstance()->findBySlug($params['sCategory']); } } if (isset($category['pk_i_id'])) { $url = osc_get_preference('rewrite_cat_url'); if (preg_match('|{CATEGORIES}|', $url)) { $categories = Category::newInstance()->hierarchy($category['pk_i_id']); $sanitized_categories = array(); $mCat = Category::newInstance(); for ($i = count($categories); $i > 0; $i--) { $tmpcat = $mCat->findByPrimaryKey($categories[$i - 1]['pk_i_id']); $sanitized_categories[] = $tmpcat['s_slug']; } $url = str_replace('{CATEGORIES}', implode("/", $sanitized_categories), $url); } $seo_prefix = ''; if (osc_get_preference('seo_url_search_prefix') != '') { $seo_prefix = osc_get_preference('seo_url_search_prefix') . '/'; } $url = str_replace('{CATEGORY_NAME}', $category['s_slug'], $url); // DEPRECATED : CATEGORY_SLUG is going to be removed in 3.4 $url = str_replace('{CATEGORY_SLUG}', $category['s_slug'], $url); $url = str_replace('{CATEGORY_ID}', $category['pk_i_id'], $url); } else { // Search by a category which does not exists (by form) // TODO CHANGE TO NEW ROUTES!! return $base_url . 'index.php?page=search&sCategory=' . urlencode($params['sCategory']); } if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) { $url .= '/' . $params['iPage']; } $url = $base_url . $seo_prefix . $url; } else { if (isset($params['sRegion']) && is_string($params['sRegion']) && strpos($params['sRegion'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) { $url = $base_url; if (osc_get_preference('seo_url_search_prefix') != '') { $url .= osc_get_preference('seo_url_search_prefix') . '/'; } if (isset($params['sCategory'])) { $_auxSlug = _aux_search_category_slug($params['sCategory']); if ($_auxSlug != '') { $url .= $_auxSlug . '_'; } } if (isset($params['sRegion'])) { if (osc_list_region_id() == $params['sRegion']) { $url .= osc_sanitizeString(osc_list_region_slug()) . '-r' . osc_list_region_id(); } else { if (is_numeric($params['sRegion'])) { $region = Region::newInstance()->findByPrimaryKey($params['sRegion']); } else { $region = Region::newInstance()->findByName($params['sRegion']); } if (isset($region['s_slug'])) { $url .= osc_sanitizeString($region['s_slug']) . '-r' . $region['pk_i_id']; } else { // Search by a region which does not exists (by form) // TODO CHANGE TO NEW ROUTES!! return $url . 'index.php?page=search&sRegion=' . urlencode($params['sRegion']); } } } if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) { $url .= '/' . $params['iPage']; } } else { if (isset($params['sCity']) && !is_array($params['sCity']) && strpos($params['sCity'], ',') === false && ($countP == 1 || $countP == 2 && (isset($params['iPage']) || isset($params['sCategory'])) || $countP == 3 && isset($params['iPage']) && isset($params['sCategory']))) { $url = $base_url; if (osc_get_preference('seo_url_search_prefix') != '') { $url .= osc_get_preference('seo_url_search_prefix') . '/'; } if (isset($params['sCategory'])) { $_auxSlug = _aux_search_category_slug($params['sCategory']); if ($_auxSlug != '') { $url .= $_auxSlug . '_'; } } if (isset($params['sCity'])) { if (osc_list_city_id() == $params['sCity']) { $url .= osc_sanitizeString(osc_list_city_slug()) . '-c' . osc_list_city_id(); } else { if (is_numeric($params['sCity'])) { $city = City::newInstance()->findByPrimaryKey($params['sCity']); } else { $city = City::newInstance()->findByName($params['sCity']); } if (isset($city['s_slug'])) { $url .= osc_sanitizeString($city['s_slug']) . '-c' . $city['pk_i_id']; } else { // Search by a city which does not exists (by form) // TODO CHANGE TO NEW ROUTES!! return $url . 'index.php?page=search&sCity=' . urlencode($params['sCity']); } } } if (isset($params['iPage']) && $params['iPage'] != '' && $params['iPage'] != 1) { $url .= '/' . $params['iPage']; } } else { if ($params != null && is_array($params)) { foreach ($params as $k => $v) { switch ($k) { case 'sCountry': $k = osc_get_preference('rewrite_search_country'); break; case 'sRegion': $k = osc_get_preference('rewrite_search_region'); break; case 'sCity': $k = osc_get_preference('rewrite_search_city'); break; case 'sCityArea': $k = osc_get_preference('rewrite_search_city_area'); break; case 'sCategory': $k = osc_get_preference('rewrite_search_category'); if (is_array($v)) { $v = implode(",", $v); } break; case 'sUser': $k = osc_get_preference('rewrite_search_user'); if (is_array($v)) { $v = implode(",", $v); } break; case 'sPattern': $k = osc_get_preference('rewrite_search_pattern'); break; case 'meta': // meta(@id),value/meta(@id),value2/... foreach ($v as $key => $value) { if (is_array($value)) { foreach ($value as $_key => $_value) { if ($value != '') { $url .= '/meta' . $key . '-' . $_key . ',' . urlencode($_value); } } } else { if ($value != '') { $url .= '/meta' . $key . ',' . urlencode($value); } } } break; default: break; } if (!is_array($v) && $v != '') { $url .= "/" . $k . "," . urlencode($v); } } } } } } } else { $url = $base_url . 'index.php?page=search'; if ($params != null && is_array($params)) { foreach ($params as $k => $v) { if ($k == 'meta') { if (is_array($v)) { foreach ($v as $_k => $aux) { if (is_array($aux)) { foreach (array_keys($aux) as $aux_k) { $url .= "&" . $k . "[{$_k}][{$aux_k}]=" . urlencode($aux[$aux_k]); } } else { $url .= "&" . $_k . "[]=" . urlencode($aux); } } } } else { if (is_array($v)) { $v = implode(",", $v); } $url .= "&" . $k . "=" . urlencode($v); } } } } return str_replace('%2C', ',', $url); }
><?php _e('Region based'); ?> </option> <option value="city" <?php if (osc_subdomain_type() == 'city') { ?> selected="selected"<?php } ?> ><?php _e('City based'); ?> </option> <option value="user" <?php if (osc_subdomain_type() == 'user') { ?> selected="selected"<?php } ?> ><?php _e('User based'); ?> </option> </select> </div> </div> <div class="form-row"> <div class="form-label"><?php _e('Host'); ?>
function doModel() { // calling the locations settings view $location_action = Params::getParam('type'); $mCountries = new Country(); switch ($location_action) { case('add_country'): // add country if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $countryCode = strtoupper(Params::getParam('c_country')); $countryName = Params::getParam('country'); $exists = $mCountries->findByCode($countryCode); if(isset($exists['s_name'])) { osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $countryName), 'admin'); } else { if(Params::getParam('c_manual')==1) { $mCountries->insert(array('pk_c_code' => $countryCode, 's_name' => $countryName)); osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin'); } else { if(!osc_validate_min($countryCode, 1) || !osc_validate_min($countryName, 1)) { osc_add_flash_error_message(_m('Country code and name should have at least two characters'), 'admin'); } else { $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=country&term=' . urlencode($countryCode) ); if($data_sql!='') { $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); $comm->query("SET FOREIGN_KEY_CHECKS = 0"); $comm->importSQL($data_sql); $comm->query("SET FOREIGN_KEY_CHECKS = 1"); } else { $mCountries->insert(array('pk_c_code' => $countryCode, 's_name' => $countryName)); } osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin'); } } } osc_calculate_location_slug(osc_subdomain_type()); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); break; case('edit_country'): // edit country if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); if(!osc_validate_min(Params::getParam('e_country'), 1)) { osc_add_flash_error_message(_m('Country name cannot be blank'), 'admin'); } else { $name = Params::getParam('e_country'); $slug = Params::getParam('e_country_slug'); if($slug=='') { $slug_tmp = $slug = osc_sanitizeString($name); } else { $exists = $mCountries->findBySlug($slug); if(isset($exists['s_slug']) && $exists['pk_c_code']!=Params::getParam('country_code')) { $slug_tmp = $slug = osc_sanitizeString($name); } else { $slug_tmp = $slug = osc_sanitizeString($slug); } } $slug_unique = 1; while(true) { $location_slug = $mCountries->findBySlug($slug); if(isset($location_slug['s_slug']) && $location_slug['pk_c_code']!=Params::getParam('country_code')) { $slug = $slug_tmp . '-' . $slug_unique; $slug_unique++; } else { break; } } $ok = $mCountries->update(array('s_name'=> $name, 's_slug' => $slug), array('pk_c_code' => Params::getParam('country_code'))); if( $ok ) { osc_add_flash_ok_message(_m('Country has been edited'), 'admin'); } else { osc_add_flash_error_message(_m('There were some problems editing the country'), 'admin'); } } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); break; case('delete_country'): // delete country if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $countryIds = Params::getParam('id'); if(is_array($countryIds)) { $locations = 0; $del_locations = 0; foreach($countryIds as $countryId) { $ok = $mCountries->deleteByPrimaryKey($countryId); } if($ok==0) { $del_locations++; } else { $locations += $ok; } if($locations==0) { osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin'); } } else { osc_add_flash_error_message(_m('No country was selected'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); break; case('add_region'): // add region if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); if( !Params::getParam('r_manual') ) { $regionId = Params::getParam('region_id'); $regionName = Params::getParam('region'); if($regionId!='') { $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=region&term=' . urlencode($regionId) ); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); $comm->query("SET FOREIGN_KEY_CHECKS = 0"); $comm->importSQL($data_sql); $comm->query("SET FOREIGN_KEY_CHECKS = 1"); osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin'); } else { osc_add_flash_error_message(sprintf(_m("%s can't be added"), $regionName), 'admin'); } } else { $mRegions = new Region(); $regionName = Params::getParam('region'); $countryCode = Params::getParam('country_c_parent'); $country = Country::newInstance()->findByCode($countryCode); if(!osc_validate_min($regionName, 1)) { osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin'); } else { $exists = $mRegions->findByName($regionName, $countryCode); if(!isset($exists['s_name'])) { $data = array('fk_c_country_code' => $countryCode ,'s_name' => $regionName); $mRegions->insert($data); $id = $mRegions->dao->insertedId(); RegionStats::newInstance()->setNumItems($id, 0); osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin'); } else { osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin'); } } } osc_calculate_location_slug(osc_subdomain_type()); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$countryCode."&country=".@$country['s_name']); break; case('edit_region'): // edit region if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $mRegions = new Region(); $newRegion = Params::getParam('e_region'); $regionId = Params::getParam('region_id'); if(!osc_validate_min($newRegion, 1)) { osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin'); } else { $exists = $mRegions->findByName($newRegion); if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$regionId) { if($regionId != '') { $aRegion = $mRegions->findByPrimaryKey($regionId); $country = Country::newInstance()->findByCode($aRegion['fk_c_country_code']); $name = $newRegion; $slug = Params::getParam('e_region_slug'); if($slug=='') { $slug_tmp = $slug = osc_sanitizeString($name); } else { $exists = $mRegions->findBySlug($slug); if(isset($exists['s_slug']) && $exists['pk_i_id']!=$regionId) { $slug_tmp = $slug = osc_sanitizeString($name); } else { $slug_tmp = $slug = osc_sanitizeString($slug); } } $slug_unique = 1; while(true) { $location_slug = $mRegions->findBySlug($slug); if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$regionId) { $slug = $slug_tmp . '-' . $slug_unique; $slug_unique++; } else { break; } } $mRegions->update(array('s_name' => $newRegion, 's_slug' => $slug) ,array('pk_i_id' => $regionId)); ItemLocation::newInstance()->update( array('s_region' => $newRegion), array('fk_i_region_id' => $regionId) ); osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newRegion), 'admin'); } } else { osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newRegion), 'admin'); } } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']); break; case('delete_region'): // delete region if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $mRegion = new Region(); $regionIds = Params::getParam('id'); if(is_array($regionIds)) { $locations = 0; $del_locations = 0; if(count($regionIds)>0) { $region = $mRegion->findByPrimaryKey($regionIds[0]); $country = Country::newInstance()->findByCode($region['fk_c_country_code']); foreach($regionIds as $regionId) { if($regionId != '') { $ok = $mRegion->deleteByPrimaryKey($regionId); if($ok==0) { $del_locations++; } else { $locations += $ok; } } } } if($locations==0) { osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%s locations have been deleted', $del_locations), $del_locations), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin'); } } else { osc_add_flash_error_message(_m('No region was selected'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']); break; case('add_city'): // add city if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $regionId = Params::getParam('region_parent'); $countryCode = Params::getParam('country_c_parent'); $mRegion = new Region(); $region = $mRegion->findByPrimaryKey($regionId); $country = Country::newInstance()->findByCode($region['fk_c_country_code']); if( !Params::getParam('ci_manual') ) { $cityId = Params::getParam('city_id'); $cityName = Params::getParam('city'); if($cityId!='') { $data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=city&term=' . urlencode($cityId) ); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); $comm->query("SET FOREIGN_KEY_CHECKS = 0"); $comm->importSQL($data_sql); $comm->query("SET FOREIGN_KEY_CHECKS = 1"); osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $cityName), 'admin'); } else { osc_add_flash_error_message(sprintf(_m("%s can't be added"), $cityName), 'admin'); } } else { $mCities = new City(); $newCity = Params::getParam('city'); if(!osc_validate_min($newCity, 1)) { osc_add_flash_error_message(_m('New city name cannot be blank'), 'admin'); } else { $exists = $mCities->findByName($newCity, $regionId); if(!isset($exists['s_name'])) { $mCities->insert(array('fk_i_region_id' => $regionId ,'s_name' => $newCity ,'fk_c_country_code' => $countryCode)); $id = $mCities->dao->insertedId(); CityStats::newInstance()->setNumItems($id, 0); osc_add_flash_ok_message(sprintf(_m('%s has been added as a new city'), $newCity), 'admin'); } else { osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin'); } } } osc_calculate_location_slug('city'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."®ion=".$regionId); break; case('edit_city'): // edit city if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $mRegion = new Region(); $mCities = new City(); $newCity = Params::getParam('e_city'); $cityId = Params::getParam('city_id'); if(!osc_validate_min($newCity, 1)) { osc_add_flash_error_message(_m('City name cannot be blank'), 'admin'); } else { $exists = $mCities->findByName($newCity); if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$cityId) { $city = $mCities->findByPrimaryKey($cityId); $region = $mRegion->findByPrimaryKey($city['fk_i_region_id']); $country = Country::newInstance()->findByCode($region['fk_c_country_code']); $name = $newCity; $slug = Params::getParam('e_country_slug'); if($slug=='') { $slug_tmp = $slug = osc_sanitizeString($name); } else { $exists = $mCities->findBySlug($slug); if(isset($exists['s_slug']) && $exists['pk_i_id']!=$cityId) { $slug_tmp = $slug = osc_sanitizeString($name); } else { $slug_tmp = $slug = osc_sanitizeString($slug); } } $slug_unique = 1; while(true) { $location_slug = $mCities->findBySlug($slug); if(isset($location_slug['s_slug']) && $location_slug['pk_i_id']!=$cityId) { $slug = $slug_tmp . '-' . $slug_unique; $slug_unique++; } else { break; } } $mCities->update(array('s_name' => $newCity, 's_slug' => $slug) ,array('pk_i_id' => $cityId)); ItemLocation::newInstance()->update( array('s_city' => $newCity), array('fk_i_city_id' => $cityId) ); osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newCity), 'admin'); } else { osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newCity), 'admin'); } } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."®ion=".@$region['pk_i_id']); break; case('delete_city'): // delete city if( defined('DEMO') ) { osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations'); } osc_csrf_check(); $mCities = new City(); $cityIds = Params::getParam('id'); if(is_array($cityIds)) { $locations = 0; $del_locations = 0; $cCity = end($cityIds); $cCity = $mCities->findByPrimaryKey($cCity); $region = Region::newInstance()->findByPrimaryKey($cCity['fk_i_region_id']); $country = Country::newInstance()->findByCode($cCity['fk_c_country_code']); foreach($cityIds as $cityId) { $ok = $mCities->deleteByPrimaryKey($cityId); if($ok==0) { $del_locations++; } else { $locations += $ok; } } if($locations==0) { osc_add_flash_ok_message(sprintf(_n('One location has been deleted', '%d locations have been deleted', $del_locations), $del_locations), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin'); } } else { osc_add_flash_error_message(_m('No city was selected'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$country['pk_c_code']."&country=".@$country['s_name']."®ion=".@$region['pk_i_id']); break; } $aCountries = $mCountries->listAll(); $this->_exportVariableToView('aCountries', $aCountries); $this->doView('settings/locations.php'); }
function doModel() { parent::doModel(); switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); } // calling osc_csrf_check(); $sql = Params::getFiles('sql'); if (isset($sql['size']) && $sql['size'] != 0) { $content_file = file_get_contents($sql['tmp_name']); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); if ($comm->importSQL($content_file)) { osc_calculate_location_slug(osc_subdomain_type()); osc_add_flash_ok_message(_m('Import complete'), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin'); } } else { osc_add_flash_warning_message(_m('No file was uploaded'), 'admin'); } @unlink($sql['tmp_name']); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); break; case 'category': $this->doView('tools/category.php'); break; case 'category_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); } osc_update_cat_stats(); osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); break; case 'locations': $this->doView('tools/locations.php'); break; case 'locations_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); } osc_update_location_stats(true); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'version': $this->doView('tools/version.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } osc_csrf_check(); //databasse dump... if (Params::getParam('bck_dir') != '') { $path = trim(Params::getParam('bck_dir')); if (substr($path, -1, 1) != "/") { $path .= '/'; } } else { $path = osc_base_path(); } $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql'; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-sql_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql'; $path = sys_get_temp_dir() . "/"; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -5: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } $filename = "Osclass_backup." . date('YmdHis') . ".zip"; $path = sys_get_temp_dir() . "/"; if (osc_zip_folder(osc_base_path(), $path . $filename)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //zip of the code just to back it up osc_csrf_check(); if (Params::getParam('bck_dir') != '') { $archive_name = trim(Params::getParam('bck_dir')); if (substr(trim($archive_name), -1, 1) != "/") { $archive_name .= '/'; } $archive_name = Params::getParam('bck_dir') . '/Osclass_backup.' . date('YmdHis') . '.zip'; } else { $archive_name = osc_base_path() . "Osclass_backup." . date('YmdHis') . ".zip"; } $archive_folder = osc_base_path(); if (osc_zip_folder($archive_folder, $archive_name)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; case 'maintenance': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->doView('tools/maintenance.php'); break; } $mode = Params::getParam('mode'); if ($mode == 'on') { osc_csrf_check(); $maintenance_file = osc_base_path() . '.maintenance'; $fileHandler = @fopen($maintenance_file, 'w'); if ($fileHandler) { osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin'); } fclose($fileHandler); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } else { if ($mode == 'off') { osc_csrf_check(); $deleted = @unlink(osc_base_path() . '.maintenance'); if ($deleted) { osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } } $this->doView('tools/maintenance.php'); break; default: } }
private function subdomain_params($host) { $subdomain_type = osc_subdomain_type(); $subhost = osc_subdomain_host(); // strpos is used to check if the domain is different, useful when accessing the website by diferent domains if ($subdomain_type != '' && $subhost != '' && strpos($host, $subhost) !== false) { if (preg_match('|^(www\\.)?(.+)\\.' . $subhost . '$|i', $host, $match)) { $subdomain = $match[2]; if ($subdomain != '' && $subdomain != 'www') { if ($subdomain_type == 'category') { $category = Category::newInstance()->findBySlug($subdomain); if (isset($category['pk_i_id'])) { View::newInstance()->_exportVariableToView('subdomain_name', $category['s_name']); View::newInstance()->_exportVariableToView('subdomain_slug', $category['s_slug']); Params::setParam('sCategory', $category['pk_i_id']); if (Params::getParam('page') == '') { Params::setParam('page', 'search'); } } else { $this->do400(); } } else { if ($subdomain_type == 'country') { $country = Country::newInstance()->findBySlug($subdomain); if (isset($country['pk_c_code'])) { View::newInstance()->_exportVariableToView('subdomain_name', $country['s_name']); View::newInstance()->_exportVariableToView('subdomain_slug', $country['s_slug']); Params::setParam('sCountry', $country['pk_c_code']); } else { $this->do400(); } } else { if ($subdomain_type == 'region') { $region = Region::newInstance()->findBySlug($subdomain); if (isset($region['pk_i_id'])) { View::newInstance()->_exportVariableToView('subdomain_name', $region['s_name']); View::newInstance()->_exportVariableToView('subdomain_slug', $region['s_slug']); Params::setParam('sRegion', $region['pk_i_id']); } else { $this->do400(); } } else { if ($subdomain_type == 'city') { $city = City::newInstance()->findBySlug($subdomain); if (isset($city['pk_i_id'])) { View::newInstance()->_exportVariableToView('subdomain_name', $city['s_name']); View::newInstance()->_exportVariableToView('subdomain_slug', $city['s_slug']); Params::setParam('sCity', $city['pk_i_id']); } else { $this->do400(); } } else { if ($subdomain_type == 'user') { $user = User::newInstance()->findByUsername($subdomain); if (isset($user['pk_i_id'])) { View::newInstance()->_exportVariableToView('subdomain_name', $user['s_name']); View::newInstance()->_exportVariableToView('subdomain_slug', $user['s_username']); Params::setParam('sUser', $user['pk_i_id']); } else { $this->do400(); } } else { $this->do400(); } } } } } } } } }