本文整理汇总了PHP中OSCLocale::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP OSCLocale::newInstance方法的具体用法?PHP OSCLocale::newInstance怎么用?PHP OSCLocale::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSCLocale
的用法示例。
在下文中一共展示了OSCLocale::newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: osc_checkLocales
function osc_checkLocales()
{
$locales = osc_listLocales();
foreach ($locales as $locale) {
$data = OSCLocale::newInstance()->findByPrimaryKey($locale['code']);
if (!is_array($data)) {
$values = array('pk_c_code' => $locale['code'], 's_name' => $locale['name'], 's_short_name' => $locale['short_name'], 's_description' => $locale['description'], 's_version' => $locale['version'], 's_author_name' => $locale['author_name'], 's_author_url' => $locale['author_url'], 's_currency_format' => $locale['currency_format'], 's_date_format' => $locale['date_format'], 's_stop_words' => $locale['stop_words'], 'b_enabled' => 0, 'b_enabled_bo' => 1);
$result = OSCLocale::newInstance()->insert($values);
if (!$result) {
return false;
}
// if it's a demo, we don't import any sql
if (defined('DEMO')) {
return true;
}
// inserting e-mail translations
$path = sprintf('%s%s/mail.sql', osc_translations_path(), $locale['code']);
if (file_exists($path)) {
$sql = file_get_contents($path);
$conn = DBConnectionClass::newInstance();
$c_db = $conn->getOsclassDb();
$comm = new DBCommandClass($c_db);
$result = $comm->importSQL($sql);
if (!$result) {
return false;
}
}
} else {
// update language version
OSCLocale::newInstance()->update(array('s_version' => $locale['version']), array('pk_c_code' => $locale['code']));
}
}
return true;
}
示例2: getLocale
/**
* Return all locales enabled.
*
* Call OSClocale
* function listAllEnabled($isBo = false, $indexedByPk = false)
*
* @url GET /locale
* @url GET /locale/$code
*/
public function getLocale($code)
{
if ($code) {
$result = OSCLocale::newInstance()->findByCode($code);
} else {
$result = OSCLocale::newInstance()->listAllEnabled();
}
return $result;
}
示例3: osc_checkLocales
function osc_checkLocales()
{
$locales = osc_listLocales();
foreach ($locales as $locale) {
$data = OSCLocale::newInstance()->findByPrimaryKey($locale['code']);
if (!is_array($data)) {
OSCLocale::newInstance()->insert(array('pk_c_code' => $locale['code'], 's_name' => $locale['name'], 's_short_name' => $locale['short_name'], 's_description' => $locale['description'], 's_version' => $locale['version'], 's_author_name' => $locale['author_name'], 's_author_url' => $locale['author_url'], 's_currency_format' => $locale['currency_format'], 's_date_format' => $locale['date_format'], 's_stop_words' => $locale['stop_words'], 'b_enabled' => 0, 'b_enabled_bo' => 1));
}
}
}
示例4: init
public function init()
{
$data = array_map(function ($v) {
return array("s_internal_name" => $v["s_internal_name"], "locales" => array_map(function ($k, $v) {
return array("fk_c_locale_code" => $k, "s_title" => $v["s_title"], "s_excerpt" => "", "s_text" => $v["s_text"]);
}, array_keys($v["locale"]), array_values($v["locale"])));
}, $this->model->listAll(true));
View::newInstance()->_exportVariableToView("datas", json_encode(array("emails" => $data, "footer" => array("locales" => array_map(function ($v) {
return array("fk_c_locale_code" => $v["pk_c_code"], "s_text" => "");
}, OSCLocale::newInstance()->listAll()))), JSON_PRETTY_PRINT));
}
示例5: osc_checkLocales
function osc_checkLocales()
{
$locales = osc_listLocales();
foreach ($locales as $locale) {
$data = OSCLocale::newInstance()->findByPrimaryKey($locale['code']);
if (!is_array($data)) {
OSCLocale::newInstance()->insert(array('pk_c_code' => $locale['code'], 's_name' => $locale['name'], 's_short_name' => $locale['short_name'], 's_description' => $locale['description'], 's_version' => $locale['version'], 's_author_name' => $locale['author_name'], 's_author_url' => $locale['author_url'], 's_currency_format' => $locale['currency_format'], 's_date_format' => $locale['date_format'], 's_stop_words' => $locale['stop_words'], 'b_enabled' => 0, 'b_enabled_bo' => 1));
// inserting e-mail translations
if (defined('DEMO')) {
return true;
}
$path = sprintf('%s%s/mail.sql', osc_translations_path(), $locale['code']);
if (file_exists($path)) {
$sql = file_get_contents($path);
$conn = getConnection();
$conn->osc_dbImportSQL($sql);
}
}
}
}
示例6: _osc_check_languages_update
function _osc_check_languages_update()
{
$total = 0;
$array = array();
$array_downloaded = array();
$languages = OSCLocale::newInstance()->listAll();
foreach ($languages as $lang) {
if (osc_check_language_update($lang['pk_c_code'], $lang['s_version'])) {
$array[] = $lang['pk_c_code'];
$total++;
}
$array_downloaded[] = $lang['pk_c_code'];
}
osc_set_preference('languages_to_update', json_encode($array));
osc_set_preference('languages_downloaded', json_encode($array_downloaded));
osc_set_preference('languages_update_count', $total);
osc_set_preference('languages_last_version_check', time());
osc_reset_preferences();
return $total;
}
示例7: osc_check_languages_update
function osc_check_languages_update( $force = false )
{
$total = 0;
$array = array();
$array_downloaded = array();
// check if exist a new version each day
if( (time() - osc_languages_last_version_check()) > (24 * 3600) || $force ) {
$languages = OSCLocale::newInstance()->listAll();
foreach($languages as $lang) {
if(osc_check_language_update($lang['pk_c_code'], $lang['s_version'] )) {
$array[] = $lang['pk_c_code'];
$total++;
}
$array_downloaded[] = $lang['pk_c_code'];
}
osc_set_preference( 'languages_to_update' , json_encode($array) );
osc_set_preference( 'languages_downloaded', json_encode($array_downloaded) );
osc_set_preference( 'languages_update_count', $total );
osc_set_preference( 'languages_last_version_check', time() );
osc_reset_preferences();
} else {
$total = getPreference('languages_update_count');
}
return $total;
}
示例8: oc_install
//.........这里部分代码省略.........
return array('error' => __('Cannot connect to the database. Check if the user has privileges.'));
break;
case 1044:
return array('error' => __('Cannot connect to the database. Check if the username and password are correct.'));
break;
case 2005:
return array('error' => __('Cannot resolve MySQL host. Check if the host is correct.'));
break;
default:
return array('error' => sprintf(__('Cannot connect to the database. Error number: %s'), $error_num));
break;
}
}
if (file_exists(ABS_PATH . 'config.php')) {
if (!is_writable(ABS_PATH . 'config.php')) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(__('Cannot write in config.php file. Check if the file is writable.'), __FILE__ . "::" . __LINE__);
}
return array('error' => __('Cannot write in config.php file. Check if the file is writable.'));
}
create_config_file($dbname, $username, $password, $dbhost, $tableprefix);
} else {
if (!file_exists(ABS_PATH . 'config-sample.php')) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(__("config-sample.php doesn't exist. Check if you have everything well decompressed."), __FILE__ . "::" . __LINE__);
}
return array('error' => __("config-sample.php doesn't exist. Check if you have everything well decompressed."));
}
if (!is_writable(ABS_PATH)) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(__('Can\'t copy config-sample.php. Check if the root directory is writable.'), __FILE__ . "::" . __LINE__);
}
return array('error' => __('Can\'t copy config-sample.php. Check if the root directory is writable.'));
}
copy_config_file($dbname, $username, $password, $dbhost, $tableprefix);
}
require_once ABS_PATH . 'config.php';
$sql = file_get_contents(ABS_PATH . 'oc-includes/osclass/installer/struct.sql');
$c_db = $conn->getOsclassDb();
$comm = new DBCommandClass($c_db);
$comm->importSQL($sql);
$error_num = $comm->getErrorLevel();
if ($error_num > 0) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(sprintf(__('Cannot create the database structure. Error number: %s'), $error_num), __FILE__ . "::" . __LINE__);
}
switch ($error_num) {
case 1050:
return array('error' => __('There are tables with the same name in the database. Change the table prefix or the database and try again.'));
break;
default:
return array('error' => sprintf(__('Cannot create the database structure. Error number: %s'), $error_num));
break;
}
}
require_once LIB_PATH . 'osclass/model/OSCLocale.php';
$localeManager = OSCLocale::newInstance();
$locales = osc_listLocales();
$values = array('pk_c_code' => $locales[osc_current_admin_locale()]['code'], 's_name' => $locales[osc_current_admin_locale()]['name'], 's_short_name' => $locales[osc_current_admin_locale()]['short_name'], 's_description' => $locales[osc_current_admin_locale()]['description'], 's_version' => $locales[osc_current_admin_locale()]['version'], 's_author_name' => $locales[osc_current_admin_locale()]['author_name'], 's_author_url' => $locales[osc_current_admin_locale()]['author_url'], 's_currency_format' => $locales[osc_current_admin_locale()]['currency_format'], 's_date_format' => $locales[osc_current_admin_locale()]['date_format'], 'b_enabled' => 1, 'b_enabled_bo' => 1);
if (isset($locales[osc_current_admin_locale()]['stop_words'])) {
$values['s_stop_words'] = $locales[osc_current_admin_locale()]['stop_words'];
}
$localeManager->insert($values);
$required_files = array(ABS_PATH . 'oc-includes/osclass/installer/basic_data.sql', ABS_PATH . 'oc-includes/osclass/installer/pages.sql', ABS_PATH . 'oc-content/languages/' . osc_current_admin_locale() . '/mail.sql');
$sql = '';
foreach ($required_files as $file) {
if (!file_exists($file)) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(sprintf(__('The file %s doesn\'t exist'), $file), __FILE__ . "::" . __LINE__);
}
return array('error' => sprintf(__('The file %s doesn\'t exist'), $file));
} else {
$sql .= file_get_contents($file);
}
}
$comm->importSQL($sql);
$error_num = $comm->getErrorLevel();
if ($error_num > 0) {
if (reportToOsclass()) {
LogOsclassInstaller::instance()->error(sprintf(__('Cannot insert basic configuration. Error number: %s'), $error_num), __FILE__ . "::" . __LINE__);
}
switch ($error_num) {
case 1471:
return array('error' => __('Cannot insert basic configuration. This user has no privileges to \'INSERT\' into the database.'));
break;
default:
return array('error' => sprintf(__('Cannot insert basic configuration. Error number: '), $error_num));
break;
}
}
osc_set_preference('language', osc_current_admin_locale());
osc_set_preference('admin_language', osc_current_admin_locale());
oc_install_example_data();
if (reportToOsclass()) {
set_allow_report_osclass(true);
} else {
set_allow_report_osclass(false);
}
return false;
}
示例9: doModel
function doModel()
{
switch ($this->action) {
case 'comments':
//calling the comments settings view
$this->doView('settings/comments.php');
break;
case 'comments_post':
// updating comment
$iUpdated = 0;
$enabledComments = Params::getParam('enabled_comments');
$enabledComments = $enabledComments != '' ? true : false;
$moderateComments = Params::getParam('moderate_comments');
$moderateComments = $moderateComments != '' ? true : false;
$numModerateComments = Params::getParam('num_moderate_comments');
$commentsPerPage = Params::getParam('comments_per_page');
$notifyNewComment = Params::getParam('notify_new_comment');
$notifyNewComment = $notifyNewComment != '' ? true : false;
$notifyNewCommentUser = Params::getParam('notify_new_comment_user');
$notifyNewCommentUser = $notifyNewCommentUser != '' ? true : false;
$regUserPostComments = Params::getParam('reg_user_post_comments');
$regUserPostComments = $regUserPostComments != '' ? true : false;
$msg = '';
if (!osc_validate_int(Params::getParam("num_moderate_comments"))) {
$msg .= _m("Number of moderate comments must only contain numeric characters") . "<br/>";
}
if (!osc_validate_int(Params::getParam("comments_per_page"))) {
$msg .= _m("Comments per page must only contain numeric characters") . "<br/>";
}
if ($msg != '') {
osc_add_flash_error_message($msg, 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments');
}
$iUpdated += Preference::newInstance()->update(array('s_value' => $enabledComments), array('s_name' => 'enabled_comments'));
if ($moderateComments) {
$iUpdated += Preference::newInstance()->update(array('s_value' => $numModerateComments), array('s_name' => 'moderate_comments'));
} else {
$iUpdated += Preference::newInstance()->update(array('s_value' => '-1'), array('s_name' => 'moderate_comments'));
}
$iUpdated += Preference::newInstance()->update(array('s_value' => $notifyNewComment), array('s_name' => 'notify_new_comment'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $notifyNewCommentUser), array('s_name' => 'notify_new_comment_user'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $commentsPerPage), array('s_name' => 'comments_per_page'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $regUserPostComments), array('s_name' => 'reg_user_post_comments'));
if ($iUpdated > 0) {
osc_add_flash_ok_message(_m("Comment settings have been updated"), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments');
break;
case 'locations':
// calling the locations settings view
$location_action = Params::getParam('type');
$mCountries = new Country();
switch ($location_action) {
case 'add_country':
// add country
$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 {
$countries_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=country_code&term=' . urlencode($countryCode));
$countries = json_decode($countries_json);
$mCountries->insert(array('pk_c_code' => $countryCode, 's_name' => $countryName));
CountryStats::newInstance()->setNumItems($countryCode, 0);
if (isset($countries->error)) {
// Country is not in our GEO database
// We have no region for user-typed countries
} else {
// Country is in our GEO database, add regions and cities
$manager_region = new Region();
$regions_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=region&country_code=' . urlencode($countryCode) . '&term=all');
$regions = json_decode($regions_json);
if (!isset($regions->error)) {
if (count($regions) > 0) {
foreach ($regions as $r) {
$manager_region->insert(array("fk_c_country_code" => $r->country_code, "s_name" => $r->name));
$id = $manager_region->dao->insertedId();
RegionStats::newInstance()->setNumItems($id, 0);
}
}
unset($regions);
unset($regions_json);
$manager_city = new City();
if (count($countries) > 0) {
foreach ($countries as $c) {
$regions = $manager_region->findByCountry($c->id);
if (!isset($regions->error)) {
if (count($regions) > 0) {
foreach ($regions as $region) {
$cities_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=city&country=' . urlencode($c->name) . '®ion=' . urlencode($region['s_name']) . '&term=all');
$cities = json_decode($cities_json);
if (!isset($cities->error)) {
if (count($cities) > 0) {
foreach ($cities as $ci) {
$manager_city->insert(array("fk_i_region_id" => $region['pk_i_id'], "s_name" => $ci->name, "fk_c_country_code" => $ci->country_code));
$id = $manager_city->dao->insertedId();
CityStats::newInstance()->setNumItems($id, 0);
}
}
//.........这里部分代码省略.........
示例10: doModel
function doModel()
{
switch ($this->action) {
case 'dashboard':
//dashboard...
$max_items = Params::getParam('max_items') != '' ? Params::getParam('max_items') : 5;
$aItems = Item::newInstance()->findByUserIDEnabled(Session::newInstance()->_get('userId'), 0, $max_items);
//calling the view...
$this->_exportVariableToView('items', $aItems);
$this->_exportVariableToView('max_items', $max_items);
$this->doView('user-dashboard.php');
break;
case 'profile':
//profile...
$user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
$aCountries = Country::newInstance()->listAll();
$aRegions = array();
if ($user['fk_c_country_code'] != '') {
$aRegions = Region::newInstance()->findByCountry($user['fk_c_country_code']);
} elseif (count($aCountries) > 0) {
$aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
}
$aCities = array();
if ($user['fk_i_region_id'] != '') {
$aCities = City::newInstance()->findByRegion($user['fk_i_region_id']);
} else {
if (count($aRegions) > 0) {
$aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
}
}
//calling the view...
$this->_exportVariableToView('countries', $aCountries);
$this->_exportVariableToView('regions', $aRegions);
$this->_exportVariableToView('cities', $aCities);
$this->_exportVariableToView('user', $user);
$this->_exportVariableToView('locales', OSCLocale::newInstance()->listAllEnabled());
$this->doView('user-profile.php');
break;
case 'profile_post':
//profile post...
$userId = Session::newInstance()->_get('userId');
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(false);
$success = $userActions->edit($userId);
osc_add_flash_ok_message(_m('Your profile has been updated successfully'));
$this->redirectTo(osc_user_profile_url());
break;
case 'alerts':
//alerts
$aAlerts = Alerts::newInstance()->findByUser(Session::newInstance()->_get('userId'));
$user = User::newInstance()->findByPrimaryKey(Session::newInstance()->_get('userId'));
foreach ($aAlerts as $k => $a) {
$json = base64_decode($a['s_search']);
$array_conditions = (array) json_decode($json);
// $search = Search::newInstance();
$search = new Search();
$search->setJsonAlert($array_conditions);
$search->limit(0, 3);
$aAlerts[$k]['items'] = $search->doSearch();
}
$this->_exportVariableToView('alerts', $aAlerts);
View::newInstance()->_reset('alerts');
$this->_exportVariableToView('user', $user);
$this->doView('user-alerts.php');
break;
case 'change_email':
//change email
$this->doView('user-change_email.php');
break;
case 'change_email_post':
//change email post
if (!preg_match("/^[_a-z0-9-\\+]+(\\.[_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$/", Params::getParam('new_email'))) {
osc_add_flash_error_message(_m('The specified e-mail is not valid'));
$this->redirectTo(osc_change_user_email_url());
} else {
$user = User::newInstance()->findByEmail(Params::getParam('new_email'));
if (!isset($user['pk_i_id'])) {
$userEmailTmp = array();
$userEmailTmp['fk_i_user_id'] = Session::newInstance()->_get('userId');
$userEmailTmp['s_new_email'] = Params::getParam('new_email');
UserEmailTmp::newInstance()->insertOrUpdate($userEmailTmp);
$code = osc_genRandomPassword(30);
$date = date('Y-m-d H:i:s');
$userManager = new User();
$userManager->update(array('s_pass_code' => $code, 's_pass_date' => $date, 's_pass_ip' => $_SERVER['REMOTE_ADDR']), array('pk_i_id' => Session::newInstance()->_get('userId')));
$validation_url = osc_change_user_email_confirm_url(Session::newInstance()->_get('userId'), $code);
osc_run_hook('hook_email_new_email', Params::getParam('new_email'), $validation_url);
$this->redirectTo(osc_user_profile_url());
} else {
osc_add_flash_error_message(_m('The specified e-mail is already in use'));
$this->redirectTo(osc_change_user_email_url());
}
}
break;
case 'change_password':
//change password
$this->doView('user-change_password.php');
break;
case 'change_password_post':
//change password post
//.........这里部分代码省略.........
示例11: doModel
function doModel()
{
parent::doModel();
//specific things for this class
switch ($this->action) {
case 'create':
// callign create view
$aCountries = array();
$aRegions = array();
$aCities = array();
$aCountries = Country::newInstance()->listAll();
if (isset($aCountries[0]['pk_c_code'])) {
$aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
}
if (isset($aRegions[0]['pk_i_id'])) {
$aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
}
$this->_exportVariableToView('user', null);
$this->_exportVariableToView('countries', $aCountries);
$this->_exportVariableToView('regions', $aRegions);
$this->_exportVariableToView('cities', $aCities);
$this->_exportVariableToView('locales', OSCLocale::newInstance()->listAllEnabled());
$this->doView("users/frm.php");
break;
case 'create_post':
// creating the user...
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->add();
switch ($success) {
case 1:
osc_add_flash_ok_message(_m('The user has been created. We\'ve sent an activation e-mail'), 'admin');
break;
case 2:
osc_add_flash_ok_message(_m('The user has been created successfully'), 'admin');
break;
case 3:
osc_add_flash_warning_message(_m('Sorry, but that e-mail is already in use'), 'admin');
break;
case 5:
osc_add_flash_warning_message(_m('The specified e-mail is not valid'), 'admin');
break;
case 6:
osc_add_flash_warning_message(_m('Sorry, the password cannot be empty'), 'admin');
break;
case 7:
osc_add_flash_warning_message(_m("Sorry, passwords don't match"), 'admin');
break;
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case 'edit':
// calling the edit view
$aUser = array();
$aCountries = array();
$aRegions = array();
$aCities = array();
$aUser = $this->userManager->findByPrimaryKey(Params::getParam("id"));
$aCountries = Country::newInstance()->listAll();
$aRegions = array();
if ($aUser['fk_c_country_code'] != '') {
$aRegions = Region::newInstance()->findByCountry($aUser['fk_c_country_code']);
} else {
if (count($aCountries) > 0) {
$aRegions = Region::newInstance()->findByCountry($aCountries[0]['pk_c_code']);
}
}
$aCities = array();
if ($aUser['fk_i_region_id'] != '') {
$aCities = City::newInstance()->findByRegion($aUser['fk_i_region_id']);
} else {
if (count($aRegions) > 0) {
$aCities = City::newInstance()->findByRegion($aRegions[0]['pk_i_id']);
}
}
$this->_exportVariableToView("user", $aUser);
$this->_exportVariableToView("countries", $aCountries);
$this->_exportVariableToView("regions", $aRegions);
$this->_exportVariableToView("cities", $aCities);
$this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
$this->doView("users/frm.php");
break;
case 'edit_post':
// edit post
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->edit(Params::getParam("id"));
switch ($success) {
case 1:
osc_add_flash_error_message(_m('Passwords don\'t match'), 'admin');
break;
case 2:
osc_add_flash_ok_message(_m('The user has been updated and activated'), 'admin');
break;
default:
osc_add_flash_ok_message(_m('The user has been updated'), 'admin');
break;
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
//.........这里部分代码省略.........
示例12: doModel
function doModel()
{
parent::doModel();
//specific things for this class
switch ($this->action) {
case 'create':
// callign create view
$aCountries = array();
$aRegions = array();
$aCities = array();
$aCountries = Country::newInstance()->listAll();
if (isset($aCountries[0]['pk_c_code'])) {
$aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
}
if (isset($aRegions[0]['pk_i_id'])) {
$aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
}
$this->_exportVariableToView("user", null);
$this->_exportVariableToView("countries", $aCountries);
$this->_exportVariableToView("regions", $aRegions);
$this->_exportVariableToView("cities", $aCities);
$this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
$this->doView("users/frm.php");
break;
case 'create_post':
// creating the user...
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->add();
switch ($success) {
case 1:
osc_add_flash_message(_m('The user has been created. We\'ve sent an activation e-mail'), 'admin');
break;
case 2:
osc_add_flash_message(_m('The user has been created and activated'), 'admin');
break;
case 3:
osc_add_flash_message(_m('Sorry, but that e-mail is already in use'), 'admin');
break;
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case 'edit':
// calling the edit view
$aUser = array();
$aCountries = array();
$aRegions = array();
$aCities = array();
$aUser = $this->userManager->findByPrimaryKey(Params::getParam("id"));
$aCountries = Country::newInstance()->listAll();
$aRegions = array();
if ($aUser['fk_c_country_code'] != '') {
$aRegions = Region::newInstance()->getByCountry($aUser['fk_c_country_code']);
} else {
if (count($aCountries) > 0) {
$aRegions = Region::newInstance()->getByCountry($aCountries[0]['pk_c_code']);
}
}
$aCities = array();
if ($aUser['fk_i_region_id'] != '') {
$aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aUser['fk_i_region_id']);
} else {
if (count($aRegions) > 0) {
$aCities = City::newInstance()->listWhere("fk_i_region_id = %d", $aRegions[0]['pk_i_id']);
}
}
$this->_exportVariableToView("user", $aUser);
$this->_exportVariableToView("countries", $aCountries);
$this->_exportVariableToView("regions", $aRegions);
$this->_exportVariableToView("cities", $aCities);
$this->_exportVariableToView("locales", OSCLocale::newInstance()->listAllEnabled());
$this->doView("users/frm.php");
break;
case 'edit_post':
// edit post
require_once LIB_PATH . 'osclass/UserActions.php';
$userActions = new UserActions(true);
$success = $userActions->edit(Params::getParam("id"));
switch ($success) {
case 1:
osc_add_flash_message(_m('Passwords don\'t match'), 'admin');
break;
case 2:
osc_add_flash_message(_m('The user has been updated and activated'), 'admin');
break;
default:
osc_add_flash_message(_m('The user has been updated'), 'admin');
break;
}
$this->redirectTo(osc_admin_base_url(true) . '?page=users');
break;
case 'activate':
//activate
$iUpdated = 0;
$userId = Params::getParam('id');
if (!is_array($userId)) {
osc_add_flash_message(_m('User id isn\'t in the correct format'), 'admin');
}
foreach ($userId as $id) {
$conditions = array('pk_i_id' => $id);
//.........这里部分代码省略.........
示例13: fn_email_item_validation_non_register_user
function fn_email_item_validation_non_register_user($item)
{
View::newInstance()->_exportVariableToView('item', $item);
$mPages = new Page();
$aPage = $mPages->findByInternalName('email_item_validation_non_register_user');
$locale = osc_current_user_locale();
$content = array();
if (isset($aPage['locale'][$locale]['s_title'])) {
$content = $aPage['locale'][$locale];
} else {
$content = current($aPage['locale']);
}
$item_url = osc_item_url();
$item_url = '<a href="' . $item_url . '" >' . $item_url . '</a>';
$edit_url = osc_item_edit_url($item['s_secret'], $item['pk_i_id']);
$delete_url = osc_item_delete_url($item['s_secret'], $item['pk_i_id']);
$all = '';
if (isset($item['locale'])) {
foreach ($item['locale'] as $locale => $data) {
$locale_name = OSCLocale::newInstance()->listWhere("pk_c_code = '" . $locale . "'");
$all .= '<br/>';
if (isset($locale_name[0]) && isset($locale_name[0]['s_name'])) {
$all .= __('Language') . ': ' . $locale_name[0]['s_name'] . '<br/>';
} else {
$all .= __('Language') . ': ' . $locale . '<br/>';
}
$all .= __('Title') . ': ' . $data['s_title'] . '<br/>';
$all .= __('Description') . ': ' . $data['s_description'] . '<br/>';
$all .= '<br/>';
}
} else {
$all .= __('Title') . ': ' . $item['s_title'] . '<br/>';
$all .= __('Description') . ': ' . $item['s_description'] . '<br/>';
}
// Format activation URL
$validation_url = osc_item_activate_url($item['s_secret'], $item['pk_i_id']);
$words = array();
$words[] = array('{ITEM_DESCRIPTION_ALL_LANGUAGES}', '{ITEM_DESCRIPTION}', '{ITEM_COUNTRY}', '{ITEM_PRICE}', '{ITEM_REGION}', '{ITEM_CITY}', '{ITEM_ID}', '{USER_NAME}', '{USER_EMAIL}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{WEB_TITLE}', '{VALIDATION_LINK}', '{VALIDATION_URL}', '{EDIT_LINK}', '{EDIT_URL}', '{DELETE_LINK}', '{DELETE_URL}');
$words[] = array($all, $item['s_description'], $item['s_country'], osc_prepare_price($item['s_price']), $item['s_region'], $item['s_city'], $item['pk_i_id'], $item['s_contact_name'], $item['s_contact_email'], '<a href="' . osc_base_url() . '" >' . osc_base_url() . '</a>', $item['s_title'], $item_url, osc_page_title(), '<a href="' . $validation_url . '" >' . $validation_url . '</a>', $validation_url, '<a href="' . $edit_url . '">' . $edit_url . '</a>', $edit_url, '<a href="' . $delete_url . '">' . $delete_url . '</a>', $delete_url);
$title = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_item_validation_non_register_user_title', $content['s_title'])), $words);
$body = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_item_validation_non_register_user_description', $content['s_text'])), $words);
$emailParams = array('subject' => $title, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body, 'alt_body' => $body);
osc_sendMail($emailParams);
}
示例14: doModel
function doModel()
{
parent::doModel();
//specific things for this class
switch ($this->action) {
case 'add':
$this->_exportVariableToView("categories", $this->categoryManager->toTreeAll());
$this->_exportVariableToView("languages", OSCLocale::newInstance()->listAllEnabled());
$this->_exportVariableToView("category", array());
$this->doView("categories/frm.php");
break;
case 'add_post':
try {
// fields contain data of t_category
$fields['fk_i_parent_id'] = Params::getParam("fk_i_parent_id") != '' ? Params::getParam("fk_i_parent_id") : null;
$fields['i_expiration_days'] = Params::getParam("i_expiration_days") != '' ? Params::getParam("i_expiration_days") : 0;
$fields['i_position'] = Params::getParam("i_position") != '' ? Params::getParam("i_position") : 0;
$fields['b_enabled'] = Params::getParam("b_enabled") != '' ? 1 : 0;
$postParams = Params::getParamsAsArray();
foreach ($postParams as $k => $v) {
if (preg_match('|(.+?)#(.+)|', $k, $m)) {
$aFieldsDescription[$m[1]][$m[2]] = $v;
}
}
$this->categoryManager->insert($fields, $aFieldsDescription);
osc_add_flash_message(_m('The category has been added'), 'admin');
} catch (Exception $e) {
osc_add_flash_message(_m('The category could\'t be added') . $e->getMessage(), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=categories');
break;
case 'edit':
$this->_exportVariableToView("category", $this->categoryManager->findByPrimaryKey(Params::getParam("id")));
$this->_exportVariableToView("categories", $this->categoryManager->toTreeAll());
$this->_exportVariableToView("languages", OSCLocale::newInstance()->listAllEnabled());
$this->doView("categories/frm.php");
break;
case 'edit_post':
$id = Params::getParam("id");
$fields['fk_i_parent_id'] = Params::getParam("fk_i_parent_id") != '' ? Params::getParam("fk_i_parent_id") : null;
$fields['i_expiration_days'] = Params::getParam("i_expiration_days") != '' ? Params::getParam("i_expiration_days") : 0;
$fields['i_position'] = Params::getParam("i_position") != '' ? Params::getParam("i_position") : 0;
$fields['b_enabled'] = Params::getParam("b_enabled") != '' ? 1 : 0;
$postParams = Params::getParamsAsArray();
foreach ($postParams as $k => $v) {
if (preg_match('|(.+?)#(.+)|', $k, $m)) {
$aFieldsDescription[$m[1]][$m[2]] = $v;
}
}
try {
$this->categoryManager->updateByPrimaryKey($fields, $aFieldsDescription, $id);
osc_add_flash_message(_m('The category has been updated.'), 'admin');
} catch (Exception $e) {
osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
}
if (!is_null($fields['fk_i_parent_id'])) {
$this->redirectTo(osc_admin_base_url(true) . '?page=categories&parentId=' . $fields['fk_i_parent_id']);
} else {
$this->redirectTo(osc_admin_base_url(true) . '?page=categories');
}
break;
case 'delete':
$id = Params::getParam("id");
try {
foreach ($id as $i) {
if (intval($i)) {
$this->categoryManager->deleteByPrimaryKey($i);
}
}
osc_add_flash_message(_m('The categories have been deleted'), 'admin');
} catch (Exception $e) {
osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=categories');
break;
case 'enable':
$id = Params::getParam("id");
$enabled = Params::getParam("enabled") != '' ? Params::getParam("enabled") : 0;
try {
if ($id != '') {
$this->categoryManager->update(array('b_enabled' => $enabled), array('pk_i_id' => $id));
if ($enabled == 1) {
$msg = _m('The category has been enabled');
} else {
$msg = _m('The category has been disabled');
}
} else {
$msg = _m('There was a problem with this page. The ID for the category hasn\'t been set');
}
osc_add_flash_message($msg, 'admin');
} catch (Exception $e) {
osc_add_flash_message(_m('Error: ') . $e->getMessage(), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=categories');
break;
case 'enable_selected':
$ids = Params::getParam("id");
try {
if ($ids != '') {
foreach ($ids as $id) {
//.........这里部分代码省略.........
示例15: doModel
function doModel()
{
//specific things for this class
switch ($this->action) {
case 'bulk_actions':
break;
case 'regions':
//Return regions given a countryId
$regions = Region::newInstance()->findByCountry(Params::getParam("countryId"));
echo json_encode($regions);
break;
case 'cities':
//Returns cities given a regionId
$cities = City::newInstance()->findByRegion(Params::getParam("regionId"));
echo json_encode($cities);
break;
case 'location':
// This is the autocomplete AJAX
$cities = City::newInstance()->ajax(Params::getParam("term"));
echo json_encode($cities);
break;
case 'userajax':
// This is the autocomplete AJAX
$users = User::newInstance()->ajax(Params::getParam("term"));
if (count($users) == 0) {
echo json_encode(array(0 => array('id' => '', 'label' => __('No results'), 'value' => __('No results'))));
} else {
echo json_encode($users);
}
break;
case 'date_format':
echo json_encode(array('format' => Params::getParam('format'), 'str_formatted' => osc_format_date(date(Params::getParam('format')))));
break;
case 'runhook':
// run hooks
$hook = Params::getParam('hook');
if ($hook == '') {
echo json_encode(array('error' => 'hook parameter not defined'));
break;
}
switch ($hook) {
case 'item_form':
osc_run_hook('item_form', Params::getParam('catId'));
break;
case 'item_edit':
$catId = Params::getParam("catId");
$itemId = Params::getParam("itemId");
osc_run_hook("item_edit", $catId, $itemId);
break;
default:
osc_run_hook('ajax_admin_' . $hook);
break;
}
break;
case 'items':
// Return items (use external file oc-admin/ajax/item_processing.php)
require_once osc_admin_base_path() . 'ajax/items_processing.php';
$items_processing = new ItemsProcessingAjax(Params::getParamsAsArray("get"));
break;
case 'users':
// Return items (use external file oc-admin/ajax/item_processing.php)
require_once osc_admin_base_path() . 'ajax/users_processing.php';
$users_processing = new UsersProcessingAjax(Params::getParamsAsArray("get"));
break;
case 'media':
// Return items (use external file oc-admin/ajax/media_processing.php)
require_once osc_admin_base_path() . 'ajax/media_processing.php';
$media_processing = new MediaProcessingAjax(Params::getParamsAsArray("get"));
break;
case 'categories_order':
// Save the order of the categories
$aIds = Params::getParam('list');
$orderParent = 0;
$orderSub = 0;
$catParent = 0;
$error = 0;
$catManager = Category::newInstance();
$aRecountCat = array();
foreach ($aIds as $id => $parent) {
if ($parent == 'root') {
$res = $catManager->updateOrder($id, $orderParent);
if (is_bool($res) && !$res) {
$error = 1;
}
// find category
$auxCategory = Category::newInstance()->findByPrimaryKey($id);
// set parent category
$conditions = array('pk_i_id' => $id);
$array['fk_i_parent_id'] = NULL;
$res = $catManager->update($array, $conditions);
if (is_bool($res) && !$res) {
$error = 1;
} else {
if ($res == 1) {
// updated ok
$parentId = $auxCategory['fk_i_parent_id'];
if ($parentId) {
// update parent category stats
array_push($aRecountCat, $id);
array_push($aRecountCat, $parentId);
//.........这里部分代码省略.........