Exemplo n.º 1
0
/**
 * Tries to delete the directory recursivaly.
 * @return true on success.
 */
function osc_deleteDir($path)
{
    if (!is_dir($path)) {
        return false;
    }
    $fd = @opendir($path);
    if (!$fd) {
        return false;
    }
    while ($file = @readdir($fd)) {
        if ($file != '.' && $file != '..') {
            if (!is_dir($path . '/' . $file)) {
                if (!@unlink($path . '/' . $file)) {
                    closedir($fd);
                    return false;
                } else {
                    osc_deleteDir($path . '/' . $file);
                }
            } else {
                osc_deleteDir($path . '/' . $file);
            }
        }
    }
    closedir($fd);
    return @rmdir($path);
}
Exemplo n.º 2
0
 function doModel()
 {
     switch ($this->action) {
         case 'add':
             // caliing add view
             $this->doView('languages/add.php');
             break;
         case 'add_post':
             // adding a new language
             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=languages');
             }
             osc_csrf_check();
             $filePackage = Params::getFiles('package');
             if (isset($filePackage['size']) && $filePackage['size'] != 0) {
                 $path = osc_translations_path();
                 (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
                 @unlink($filePackage['tmp_name']);
             } else {
                 $status = 3;
             }
             switch ($status) {
                 case 0:
                     $msg = _m('The translation folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 1:
                     if (osc_checkLocales()) {
                         $msg = _m('The language has been installed correctly');
                         osc_add_flash_ok_message($msg, 'admin');
                     } else {
                         $msg = _m('There was a problem adding the language');
                         osc_add_flash_error_message($msg, 'admin');
                     }
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 3:
                     $msg = _m('No file was uploaded');
                     osc_add_flash_warning_message($msg, 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=languages&action=add");
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the language');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'edit':
             // editing a language
             $sLocale = Params::getParam('id');
             if (!preg_match('/.{2}_.{2}/', $sLocale)) {
                 osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $aLocale = $this->localeManager->findByPrimaryKey($sLocale);
             if (count($aLocale) == 0) {
                 osc_add_flash_error_message(_m('Language id doesn\'t exist'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $this->_exportVariableToView("aLocale", $aLocale);
             $this->doView('languages/frm.php');
             break;
         case 'edit_post':
             // edit language post
             osc_csrf_check();
             $iUpdated = 0;
             $languageCode = Params::getParam('pk_c_code');
             $enabledWebstie = Params::getParam('b_enabled');
             $enabledBackoffice = Params::getParam('b_enabled_bo');
             $languageName = Params::getParam('s_name');
             $languageShortName = Params::getParam('s_short_name');
             $languageDescription = Params::getParam('s_description');
             $languageCurrencyFormat = Params::getParam('s_currency_format');
             $languageDecPoint = Params::getParam('s_dec_point');
             $languageNumDec = Params::getParam('i_num_dec');
             $languageThousandsSep = Params::getParam('s_thousands_sep');
             $languageDateFormat = Params::getParam('s_date_format');
             $languageStopWords = Params::getParam('s_stop_words');
             // formatting variables
             if (!preg_match('/.{2}_.{2}/', $languageCode)) {
                 osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $enabledWebstie = $enabledWebstie != '' ? true : false;
             $enabledBackoffice = $enabledBackoffice != '' ? true : false;
             $languageName = strip_tags($languageName);
             $languageName = trim($languageName);
             $languageShortName = strip_tags($languageShortName);
             $languageShortName = trim($languageShortName);
             $languageDescription = strip_tags($languageDescription);
             $languageDescription = trim($languageDescription);
             $languageCurrencyFormat = strip_tags($languageCurrencyFormat);
             $languageCurrencyFormat = trim($languageCurrencyFormat);
             $languageDateFormat = strip_tags($languageDateFormat);
             $languageDateFormat = trim($languageDateFormat);
             $languageStopWords = strip_tags($languageStopWords);
             $languageStopWords = trim($languageStopWords);
             $msg = '';
             if (!osc_validate_text($languageName)) {
                 $msg .= _m("Language name field is required") . "<br/>";
             }
             if (!osc_validate_text($languageShortName)) {
                 $msg .= _m("Language short name field is required") . "<br/>";
             }
             if (!osc_validate_text($languageDescription)) {
                 $msg .= _m("Language description field is required") . "<br/>";
             }
             if (!osc_validate_text($languageCurrencyFormat)) {
                 $msg .= _m("Currency format field is required") . "<br/>";
             }
             if (!osc_validate_int($languageNumDec)) {
                 $msg .= _m("Number of decimals must only contain numeric characters") . "<br/>";
             }
             if ($msg != '') {
                 osc_add_flash_error_message($msg, 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages&action=edit&id=' . $languageCode);
             }
             $array = array('b_enabled' => $enabledWebstie, 'b_enabled_bo' => $enabledBackoffice, 's_name' => $languageName, 's_short_name' => $languageShortName, 's_description' => $languageDescription, 's_currency_format' => $languageCurrencyFormat, 's_dec_point' => $languageDecPoint, 'i_num_dec' => $languageNumDec, 's_thousands_sep' => $languageThousandsSep, 's_date_format' => $languageDateFormat, 's_stop_words' => $languageStopWords);
             $iUpdated = $this->localeManager->update($array, array('pk_c_code' => $languageCode));
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message(sprintf(_m('%s has been updated'), $languageShortName), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_selected':
             osc_csrf_check();
             $msg = _m('Selected languages have been enabled for the website');
             $iUpdated = 0;
             $aValues = array('b_enabled' => 1);
             $id = Params::getParam('id');
             if (!is_array($id)) {
                 osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             foreach ($id as $i) {
                 osc_translate_categories($i);
                 $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i));
             }
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_selected':
             osc_csrf_check();
             $msg = _m('Selected languages have been disabled for the website');
             $msg_warning = '';
             $iUpdated = 0;
             $aValues = array('b_enabled' => 0);
             $id = Params::getParam('id');
             if (!is_array($id)) {
                 osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             foreach ($id as $i) {
                 if (osc_language() == $i) {
                     $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language());
                     continue;
                 }
                 $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i));
             }
             if ($msg_warning != '') {
                 if ($iUpdated > 0) {
                     osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin');
                 } else {
                     osc_add_flash_warning_message($msg_warning, 'admin');
                 }
             } else {
                 osc_add_flash_ok_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_bo_selected':
             osc_csrf_check();
             $msg = _m('Selected languages have been enabled for the backoffice (oc-admin)');
             $iUpdated = 0;
             $aValues = array('b_enabled_bo' => 1);
             $id = Params::getParam('id');
             if (!is_array($id)) {
                 osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             foreach ($id as $i) {
                 osc_translate_categories($i);
                 $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i));
             }
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_bo_selected':
             osc_csrf_check();
             $msg = _m('Selected languages have been disabled for the backoffice (oc-admin)');
             $msg_warning = '';
             $iUpdated = 0;
             $aValues = array('b_enabled_bo' => 0);
             $id = Params::getParam('id');
             if (!is_array($id)) {
                 osc_add_flash_warning_message(_m("The language ids aren't in the correct format"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             foreach ($id as $i) {
                 if (osc_language() == $i) {
                     $msg_warning = sprintf(_m("%s can't be disabled because it's the default language"), osc_language());
                     continue;
                 }
                 $iUpdated += $this->localeManager->update($aValues, array('pk_c_code' => $i));
             }
             if ($msg_warning != '') {
                 if ($iUpdated > 0) {
                     osc_add_flash_warning_message($msg . '</p><p>' . $msg_warning, 'admin');
                 } else {
                     osc_add_flash_warning_message($msg_warning, 'admin');
                 }
             } else {
                 osc_add_flash_ok_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'delete':
             osc_csrf_check();
             if (is_array(Params::getParam('id'))) {
                 $default_lang = osc_language();
                 foreach (Params::getParam('id') as $code) {
                     if ($default_lang != $code) {
                         if ($this->localeManager->deleteLocale($code)) {
                             if (!osc_deleteDir(osc_translations_path() . $code)) {
                                 osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed"), $code), 'admin');
                             } else {
                                 osc_add_flash_ok_message(sprintf(_m('Directory "%s" has been successfully removed'), $code), 'admin');
                             }
                         } else {
                             osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed;)"), $code), 'admin');
                         }
                     } else {
                         osc_add_flash_error_message(sprintf(_m("Directory '%s' couldn't be removed because it's the default language. Set another language as default first and try again"), $code), 'admin');
                     }
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         default:
             if (Params::getParam('checkUpdated') != '') {
                 osc_admin_toolbar_update_languages(true);
             }
             if (Params::getParam("action") != "") {
                 osc_run_hook("language_bulk_" . Params::getParam("action"), Params::getParam('id'));
             }
             // -----
             if (Params::getParam('iDisplayLength') == '') {
                 Params::setParam('iDisplayLength', 10);
             }
             // ?
             $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
             $p_iPage = 1;
             if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') >= 1) {
                 $p_iPage = Params::getParam('iPage');
             }
             Params::setParam('iPage', $p_iPage);
             $aLanguages = OSCLocale::newInstance()->listAll();
             // pagination
             $start = ($p_iPage - 1) * Params::getParam('iDisplayLength');
             $limit = Params::getParam('iDisplayLength');
             $count = count($aLanguages);
             $displayRecords = $limit;
             if ($start + $limit > $count) {
                 $displayRecords = $start + $limit - $count;
             }
             // ----
             $aLanguagesToUpdate = json_decode(osc_get_preference('languages_to_update'));
             $bLanguagesToUpdate = is_array($aLanguagesToUpdate) ? true : false;
             // ----
             $aData = array();
             $max = $start + $limit;
             if ($max > $count) {
                 $max = $count;
             }
             for ($i = $start; $i < $max; $i++) {
                 $l = $aLanguages[$i];
                 $row = array();
                 $row[] = '<input type="checkbox" name="id[]" value="' . $l['pk_c_code'] . '" />';
                 $options = array();
                 $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&amp;action=edit&amp;id=' . $l['pk_c_code'] . '">' . __('Edit') . '</a>';
                 $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&amp;action=' . ($l['b_enabled'] == 1 ? 'disable_selected' : 'enable_selected') . '&amp;id[]=' . $l['pk_c_code'] . '&amp;' . osc_csrf_token_url() . '">' . ($l['b_enabled'] == 1 ? __('Disable (website)') : __('Enable (website)')) . '</a> ';
                 $options[] = '<a href="' . osc_admin_base_url(true) . '?page=languages&amp;action=' . ($l['b_enabled_bo'] == 1 ? 'disable_bo_selected' : 'enable_bo_selected') . '&amp;id[]=' . $l['pk_c_code'] . '&amp;' . osc_csrf_token_url() . '">' . ($l['b_enabled_bo'] == 1 ? __('Disable (oc-admin)') : __('Enable (oc-admin)')) . '</a>';
                 $options[] = '<a onclick="return delete_dialog(\'' . $l['pk_c_code'] . '\');"  href="' . osc_admin_base_url(true) . '?page=languages&amp;action=delete&amp;id[]=' . $l['pk_c_code'] . '&amp;' . osc_csrf_token_url() . '">' . __('Delete') . '</a>';
                 $auxOptions = '<ul>' . PHP_EOL;
                 foreach ($options as $actual) {
                     $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL;
                 }
                 $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL;
                 $sUpdate = '';
                 // get languages to update from t_preference
                 if ($bLanguagesToUpdate) {
                     if (in_array($l['pk_c_code'], $aLanguagesToUpdate)) {
                         $sUpdate = '<a class="btn-market-update btn-market-popup" href="#' . htmlentities($l['pk_c_code']) . '">' . __("Update here") . '</a>';
                     }
                 }
                 $row[] = $l['s_name'] . $sUpdate . $actions;
                 $row[] = $l['s_short_name'];
                 $row[] = $l['s_description'];
                 $row[] = $l['b_enabled'] ? __('Yes') : __('No');
                 $row[] = $l['b_enabled_bo'] ? __('Yes') : __('No');
                 $aData[] = $row;
             }
             // ----
             $array['iTotalRecords'] = $displayRecords;
             $array['iTotalDisplayRecords'] = count($aLanguages);
             $array['iDisplayLength'] = $limit;
             $array['aaData'] = $aData;
             $page = (int) Params::getParam('iPage');
             if (count($array['aaData']) == 0 && $page != 1) {
                 $total = (int) $array['iTotalDisplayRecords'];
                 $maxPage = ceil($total / (int) $array['iDisplayLength']);
                 $url = osc_admin_base_url(true) . '?' . $_SERVER['QUERY_STRING'];
                 if ($maxPage == 0) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url);
                     $this->redirectTo($url);
                 }
                 if ($page > 1) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url);
                     $this->redirectTo($url);
                 }
             }
             $this->_exportVariableToView('aLanguages', $array);
             $bulk_options = array(array('value' => '', 'data-dialog-content' => '', 'label' => __('Bulk actions')), array('value' => 'enable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (Website)'))), 'label' => __('Enable (Website)')), array('value' => 'disable_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (Website)'))), 'label' => __('Disable (Website)')), array('value' => 'enable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Enable (oc-admin)'))), 'label' => __('Enable (oc-admin)')), array('value' => 'disable_bo_selected', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Disable (oc-admin)'))), 'label' => __('Disable (oc-admin)')), array('value' => 'delete', 'data-dialog-content' => sprintf(__('Are you sure you want to %s the selected languages?'), strtolower(__('Delete'))), 'label' => __('Delete')));
             $bulk_options = osc_apply_filter("language_bulk_filter", $bulk_options);
             $this->_exportVariableToView('bulk_options', $bulk_options);
             $this->doView('languages/index.php');
             break;
     }
 }
Exemplo n.º 3
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("appearance/add.php");
             break;
         case 'add_post':
             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=appearance');
             }
             osc_csrf_check();
             $filePackage = Params::getFiles('package');
             if (isset($filePackage['size']) && $filePackage['size'] != 0) {
                 $path = osc_themes_path();
                 (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
                 @unlink($filePackage['tmp_name']);
             } else {
                 $status = 3;
             }
             switch ($status) {
                 case 0:
                     $msg = _m('The theme folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 1:
                     $msg = _m('The theme has been installed correctly');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 3:
                     $msg = _m('No file was uploaded');
                     osc_add_flash_error_message($msg, 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=add");
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the theme');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         case 'delete':
             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=appearance');
             }
             osc_csrf_check();
             $theme = Params::getParam('webtheme');
             if ($theme != '') {
                 if ($theme != osc_current_web_theme()) {
                     if (file_exists(osc_content_path() . "themes/" . $theme . "/functions.php")) {
                         include osc_content_path() . "themes/" . $theme . "/functions.php";
                     }
                     osc_run_hook("theme_delete_" . $theme);
                     if (osc_deleteDir(osc_content_path() . "themes/" . $theme . "/")) {
                         osc_add_flash_ok_message(_m("Theme removed successfully"), "admin");
                     } else {
                         osc_add_flash_error_message(_m("There was a problem removing the theme"), "admin");
                     }
                 } else {
                     osc_add_flash_error_message(_m("Current theme can not be deleted"), "admin");
                 }
             } else {
                 osc_add_flash_error_message(_m("No theme selected"), "admin");
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
             /* widgets */
         /* widgets */
         case 'widgets':
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/widgets.php');
             break;
         case 'add_widget':
             $this->doView('appearance/add_widget.php');
             break;
         case 'edit_widget':
             $id = Params::getParam('id');
             $widget = Widget::newInstance()->findByPrimaryKey($id);
             $this->_exportVariableToView("widget", $widget);
             $this->doView('appearance/add_widget.php');
             break;
         case 'delete_widget':
             osc_csrf_check();
             Widget::newInstance()->delete(array('pk_i_id' => Params::getParam('id')));
             osc_add_flash_ok_message(_m('Widget removed correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'edit_widget_post':
             osc_csrf_check();
             if (!osc_validate_text(Params::getParam("description"))) {
                 osc_add_flash_error_message(_m('Description field is required'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             }
             $res = Widget::newInstance()->update(array('s_description' => Params::getParam('description'), 's_content' => Params::getParam('content', false, false)), array('pk_i_id' => Params::getParam('id')));
             if ($res) {
                 osc_add_flash_ok_message(_m('Widget updated correctly'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('Widget cannot be updated correctly'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'add_widget_post':
             osc_csrf_check();
             if (!osc_validate_text(Params::getParam("description"))) {
                 osc_add_flash_error_message(_m('Description field is required'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             }
             Widget::newInstance()->insert(array('s_location' => Params::getParam('location'), 'e_kind' => 'html', 's_description' => Params::getParam('description'), 's_content' => Params::getParam('content', false, false)));
             osc_add_flash_ok_message(_m('Widget added correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
             /* /widget */
         /* /widget */
         case 'activate':
             osc_csrf_check();
             osc_set_preference('theme', Params::getParam('theme'));
             osc_add_flash_ok_message(_m('Theme activated correctly'), 'admin');
             osc_run_hook("theme_activate", Params::getParam('theme'));
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         case 'render':
             if (Params::existParam('route')) {
                 $routes = Rewrite::newInstance()->getRoutes();
                 $rid = Params::getParam('route');
                 $file = '../';
                 if (isset($routes[$rid]) && isset($routes[$rid]['file'])) {
                     $file = $routes[$rid]['file'];
                 }
             } else {
                 // DEPRECATED: Disclosed path in URL is deprecated, use routes instead
                 // This will be REMOVED in 3.6
                 $file = Params::getParam('file');
                 // We pass the GET variables (in case we have somes)
                 if (preg_match('|(.+?)\\?(.*)|', $file, $match)) {
                     $file = $match[1];
                     if (preg_match_all('|&([^=]+)=([^&]*)|', urldecode('&' . $match[2] . '&'), $get_vars)) {
                         for ($var_k = 0; $var_k < count($get_vars[1]); $var_k++) {
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = Params::getParam('file');
                 }
             }
             if (strpos($file, '../') !== false || strpos($file, '..\\') !== false || !file_exists(osc_base_path() . $file)) {
                 osc_add_flash_warning_message(__('Error loading theme custom file'), 'admin');
             }
             $this->_exportVariableToView('file', osc_base_path() . $file);
             $this->doView('appearance/view.php');
             break;
         default:
             if (Params::getParam('checkUpdated') != '') {
                 osc_admin_toolbar_update_themes(true);
             }
             $themes = WebThemes::newInstance()->getListThemes();
             //preparing variables for the view
             $this->_exportVariableToView("themes", $themes);
             $this->doView('appearance/index.php');
             break;
     }
 }
Exemplo n.º 4
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("appearance/add.php");
             break;
         case 'add_post':
             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=appearance');
             }
             osc_csrf_check();
             $filePackage = Params::getFiles('package');
             if (isset($filePackage['size']) && $filePackage['size'] != 0) {
                 $path = osc_themes_path();
                 (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
             } else {
                 $status = 3;
             }
             switch ($status) {
                 case 0:
                     $msg = _m('The theme folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 1:
                     $msg = _m('The theme has been installed correctly');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 3:
                     $msg = _m('No file was uploaded');
                     osc_add_flash_error_message($msg, 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=add");
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the theme');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         case 'delete':
             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=appearance');
             }
             osc_csrf_check();
             $theme = Params::getParam('webtheme');
             if ($theme != '') {
                 if ($theme != osc_current_web_theme()) {
                     if (osc_deleteDir(osc_content_path() . "themes/" . $theme . "/")) {
                         osc_add_flash_ok_message(_m("Theme removed successfully"), "admin");
                     } else {
                         osc_add_flash_error_message(_m("There was a problem removing the theme"), "admin");
                     }
                 } else {
                     osc_add_flash_error_message(_m("Current theme can not be deleted"), "admin");
                 }
             } else {
                 osc_add_flash_error_message(_m("No theme selected"), "admin");
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
             /* widgets */
         /* widgets */
         case 'widgets':
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/widgets.php');
             break;
         case 'add_widget':
             $this->doView('appearance/add_widget.php');
             break;
         case 'edit_widget':
             $id = Params::getParam('id');
             $widget = Widget::newInstance()->findByPrimaryKey($id);
             $this->_exportVariableToView("widget", $widget);
             $this->doView('appearance/add_widget.php');
             break;
         case 'delete_widget':
             osc_csrf_check();
             Widget::newInstance()->delete(array('pk_i_id' => Params::getParam('id')));
             osc_add_flash_ok_message(_m('Widget removed correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'edit_widget_post':
             osc_csrf_check();
             if (!osc_validate_text(Params::getParam("description"))) {
                 osc_add_flash_error_message(_m('Description field is required'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             }
             $res = Widget::newInstance()->update(array('s_description' => Params::getParam('description'), 's_content' => Params::getParam('content', false, false)), array('pk_i_id' => Params::getParam('id')));
             if ($res) {
                 osc_add_flash_ok_message(_m('Widget updated correctly'), 'admin');
             } else {
                 osc_add_flash_ok_message(_m('Widget cannot be updated correctly'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'add_widget_post':
             osc_csrf_check();
             if (!osc_validate_text(Params::getParam("description"))) {
                 osc_add_flash_error_message(_m('Description field is required'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             }
             Widget::newInstance()->insert(array('s_location' => Params::getParam('location'), 'e_kind' => 'html', 's_description' => Params::getParam('description'), 's_content' => Params::getParam('content', false, false)));
             osc_add_flash_ok_message(_m('Widget added correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
             /* /widget */
         /* /widget */
         case 'activate':
             osc_csrf_check();
             Preference::newInstance()->update(array('s_value' => Params::getParam('theme')), array('s_section' => 'osclass', 's_name' => 'theme'));
             osc_add_flash_ok_message(_m('Theme activated correctly'), 'admin');
             osc_run_hook("theme_activate", Params::getParam('theme'));
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         case 'render':
             $this->_exportVariableToView('file', osc_base_path() . Params::getParam("file"));
             $this->doView('appearance/view.php');
             break;
         default:
             //                    $marketError = Params::getParam('marketError');
             //                    $slug = Params::getParam('slug');
             //                    if($marketError!='') {
             //                        if($marketError == '0') { // no error installed ok
             //                            $help = '<br/><br/><b>' . __('You only need to activate or preview the theme').'</b>';
             //                            osc_add_flash_ok_message( __('Everything was OK!') . ' ( ' . $slug .' ) ' . $help, 'admin');
             //                        } else {
             //                            osc_add_flash_error_message( __('Error occurred') . ' ( ' . $slug .' ) ', 'admin');
             //                        }
             //                    }
             // force the recount of themes that need to be updated
             if (Params::getParam('checkUpdated') != '') {
                 osc_admin_toolbar_update_themes(true);
             }
             $themes = WebThemes::newInstance()->getListThemes();
             //preparing variables for the view
             $this->_exportVariableToView("themes", $themes);
             $this->doView('appearance/index.php');
             break;
     }
 }
Exemplo n.º 5
0
 function doModel()
 {
     switch ($this->action) {
         case 'add':
             // caliing add view
             $this->doView('languages/add.php');
             break;
         case 'add_post':
             // adding a new language
             $filePackage = Params::getFiles('package');
             if (isset($filePackage['size']) && $filePackage['size'] != 0) {
                 $path = osc_translations_path();
                 (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
             } else {
                 $status = 3;
             }
             switch ($status) {
                 case 0:
                     $msg = _m('The translation folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 1:
                     if (osc_checkLocales()) {
                         $msg = _m('The language has been installed correctly');
                         osc_add_flash_ok_message($msg, 'admin');
                     } else {
                         $msg = _m('There was a problem adding the language');
                         osc_add_flash_error_message($msg, 'admin');
                     }
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 3:
                     $msg = _m('No file was uploaded');
                     osc_add_flash_warning_message($msg, 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=languages&action=add");
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the language');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'edit':
             // editing a language
             $sLocale = Params::getParam('id');
             if (!preg_match('/.{2}_.{2}/', $sLocale)) {
                 osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $aLocale = $this->localeManager->findByPrimaryKey($sLocale);
             if (count($aLocale) == 0) {
                 osc_add_flash_error_message(_m('Language id doesn\'t exist'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $this->_exportVariableToView("aLocale", $aLocale);
             $this->doView('languages/frm.php');
             break;
         case 'edit_post':
             // edit language post
             $iUpdated = 0;
             $languageCode = Params::getParam('pk_c_code');
             $enabledWebstie = Params::getParam('b_enabled');
             $enabledBackoffice = Params::getParam('b_enabled_bo');
             $languageName = Params::getParam('s_name');
             $languageShortName = Params::getParam('s_short_name');
             $languageDescription = Params::getParam('s_description');
             $languageCurrencyFormat = Params::getParam('s_currency_format');
             $languageDecPoint = Params::getParam('s_dec_point');
             $languageNumDec = Params::getParam('i_num_dec');
             $languageThousandsSep = Params::getParam('s_thousands_sep');
             $languageDateFormat = Params::getParam('s_date_format');
             $languageStopWords = Params::getParam('s_stop_words');
             // formatting variables
             if (!preg_match('/.{2}_.{2}/', $languageCode)) {
                 osc_add_flash_error_message(_m('Language id isn\'t in the correct format'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $enabledWebstie = $enabledWebstie != '' ? true : false;
             $enabledBackoffice = $enabledBackoffice != '' ? true : false;
             $languageName = strip_tags($languageName);
             $languageName = trim($languageName);
             if ($languageName == '') {
                 osc_add_flash_error_message(_m('Language name can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageShortName = strip_tags($languageShortName);
             $languageShortName = trim($languageShortName);
             if ($languageShortName == '') {
                 osc_add_flash_error_message(_m('Language short name can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageDescription = strip_tags($languageDescription);
             $languageDescription = trim($languageDescription);
             if ($languageDescription == '') {
                 osc_add_flash_error_message(_m('Language description can\'t be empty'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             }
             $languageCurrencyFormat = strip_tags($languageCurrencyFormat);
             $languageCurrencyFormat = trim($languageCurrencyFormat);
             $languageDateFormat = strip_tags($languageDateFormat);
             $languageDateFormat = trim($languageDateFormat);
             $languageStopWords = strip_tags($languageStopWords);
             $languageStopWords = trim($languageStopWords);
             $array = array('b_enabled' => $enabledWebstie, 'b_enabled_bo' => $enabledBackoffice, 's_name' => $languageName, 's_short_name' => $languageShortName, 's_description' => $languageDescription, 's_currency_format' => $languageCurrencyFormat, 's_dec_point' => $languageDecPoint, 'i_num_dec' => $languageNumDec, 's_thousands_sep' => $languageThousandsSep, 's_date_format' => $languageDateFormat, 's_stop_words' => $languageStopWords);
             $iUpdated = $this->localeManager->update($array, array('pk_c_code' => $languageCode));
             if ($iUpdated > 0) {
                 osc_add_flash_ok_message(sprintf(_m('%s has been updated'), $languageShortName), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable':
         case 'enable_bo':
             $default_lang = osc_language();
             $id = Params::getParam('id');
             $enabled = Params::getParam('enabled');
             if ($id) {
                 if ($action == 'enable' && $default_lang == $id && $enabled == 0) {
                     osc_add_flash_error_message(sprintf(_m('The language can\'t be disabled because it\'s the default language. You can change modify it in General Settings'), $i), 'admin');
                 } else {
                     $msg = $enabled == 1 ? _m('The language has been enabled for the public website') : _m('The language has been disabled for the public website');
                     $aValues = array('b_enabled' => $enabled);
                     $this->localeManager->update($aValues, array('pk_c_code' => $id));
                 }
                 if ($action == 'enable_bo') {
                     $msg = $enabled == 1 ? _m('The language has been enabled for the backoffice (oc-admin)') : _m('The language has been disabled for the backoffice (oc-admin)');
                     $aValues = array('b_enabled_bo' => $enabled);
                     $this->localeManager->update($aValues, array('pk_c_code' => $id));
                 }
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 osc_add_flash_error_message(_m('There was a problem updating the language. The language id was lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_selected':
             $msg = _m('Selected languages have been enabled for the website');
             $aValues = array('b_enabled' => 1);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 osc_add_flash_error_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_selected':
             $msg = _m('Selected languages have been disabled for the website');
             $aValues = array('b_enabled' => 0);
             $id = Params::getParam('id');
             if ($id != '') {
                 $default_lang = osc_language();
                 foreach ($id as $i) {
                     if ($default_lang == $i) {
                         $msg = _m('The language can\'t be disabled because it\'s the default language. You can change the default language under General Settings in order to disable it');
                     } else {
                         $this->localeManager->update($aValues, array('pk_c_code' => $i));
                     }
                 }
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 osc_add_flash_error_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'enable_bo_selected':
             $msg = _m('Selected languages have been enabled for the backoffice (oc-admin)');
             $aValues = array('b_enabled_bo' => 1);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 osc_add_flash_error_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'disable_bo_selected':
             $msg = _m('Selected languages have been disabled for the backoffice (oc-admin)');
             $aValues = array('b_enabled_bo' => 0);
             $id = Params::getParam('id');
             if ($id != '') {
                 foreach ($id as $i) {
                     $this->localeManager->update($aValues, array('pk_c_code' => $i));
                 }
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 osc_add_flash_error_message(_m('There was a problem updating the languages. The language ids were lost'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         case 'delete':
             if (is_array(Params::getParam('id'))) {
                 $default_lang = osc_language();
                 foreach (Params::getParam('id') as $code) {
                     if ($default_lang != $code) {
                         $this->localeManager->deleteLocale($code);
                         if (!osc_deleteDir(osc_translations_path() . $code)) {
                             osc_add_flash_error_message(sprintf(_m('Directory "%s" couldn\'t be removed'), $code), 'admin');
                         } else {
                             osc_add_flash_ok_message(sprintf(_m('Directory "%s" has been successfully removed'), $code), 'admin');
                         }
                     } else {
                         osc_add_flash_error_message(sprintf(_m('Directory "%s" couldn\'t be removed because it\'s the default language. Set another language as default first and try again'), $code), 'admin');
                     }
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=languages');
             break;
         default:
             $locales = OSCLocale::newInstance()->listAll();
             $this->_exportVariableToView("locales", $locales);
             $this->doView('languages/index.php');
             break;
     }
 }
Exemplo n.º 6
0
/**
 * Tries to delete the directory recursivaly.
 * @return true on success.
 */
function osc_deleteDir($path)
{
    if (strpos($path, "../") !== false || strpos($path, "..\\") !== false) {
        return false;
    }
    if (!is_dir($path)) {
        return false;
    }
    $fd = @opendir($path);
    if (!$fd) {
        return false;
    }
    while ($file = @readdir($fd)) {
        if ($file != '.' && $file != '..') {
            if (!is_dir($path . '/' . $file)) {
                @chmod($path . "/" . $file, 0777);
                if (!@unlink($path . '/' . $file)) {
                    closedir($fd);
                    return false;
                } else {
                    osc_deleteDir($path . '/' . $file);
                }
            } else {
                osc_deleteDir($path . '/' . $file);
            }
        }
    }
    closedir($fd);
    return @rmdir($path);
}
Exemplo n.º 7
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("plugins/add.php");
             break;
         case 'add_post':
             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=plugins');
             }
             osc_csrf_check();
             $package = Params::getFiles("package");
             if (isset($package['size']) && $package['size'] != 0) {
                 $path = osc_plugins_path();
                 (int) ($status = osc_unzip_file($package['tmp_name'], $path));
                 @unlink($package['tmp_name']);
             } else {
                 $status = 3;
             }
             switch ($status) {
                 case 0:
                     $msg = _m('The plugin folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 1:
                     $msg = _m('The plugin has been uploaded correctly');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case 3:
                     $msg = _m('No file was uploaded');
                     osc_add_flash_error_message($msg, 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=plugins&action=add");
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the plugin');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'install':
             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=plugins');
             }
             osc_csrf_check();
             $pn = Params::getParam('plugin');
             // set header just in case it's triggered some fatal error
             header("Location: " . osc_admin_base_url(true) . "?page=plugins&error=" . $pn, true, '302');
             $installed = Plugins::install($pn);
             if (is_array($installed)) {
                 switch ($installed['error_code']) {
                     case 'error_output':
                         osc_add_flash_error_message(sprintf(_m('The plugin generated %d characters of <strong>unexpected output</strong> during the installation. Output: "%s"'), strlen($installed['output']), $installed['output']), 'admin');
                         break;
                     case 'error_installed':
                         osc_add_flash_error_message(_m('Plugin is already installed'), 'admin');
                         break;
                     case 'error_file':
                         osc_add_flash_error_message(_m("Plugin couldn't be installed because their files are missing"), 'admin');
                         break;
                     case 'custom_error':
                         osc_add_flash_error_message(sprintf(_m("Plugin couldn't be installed because of: %s"), $installed['msg']), 'admin');
                         break;
                     default:
                         osc_add_flash_error_message(_m("Plugin couldn't be installed"), 'admin');
                         break;
                 }
             } else {
                 osc_add_flash_ok_message(_m('Plugin installed'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             break;
         case 'uninstall':
             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=plugins');
             }
             osc_csrf_check();
             if (Plugins::uninstall(Params::getParam("plugin"))) {
                 osc_add_flash_ok_message(_m('Plugin uninstalled'), 'admin');
             } else {
                 osc_add_flash_error_message(_m("Plugin couldn't be uninstalled"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             break;
         case 'enable':
             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=plugins');
             }
             osc_csrf_check();
             if (Plugins::activate(Params::getParam('plugin'))) {
                 osc_add_flash_ok_message(_m('Plugin enabled'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('Plugin is already enabled'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             break;
         case 'disable':
             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=plugins');
             }
             osc_csrf_check();
             if (Plugins::deactivate(Params::getParam('plugin'))) {
                 osc_add_flash_ok_message(_m('Plugin disabled'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('Plugin is already disabled'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             break;
         case 'admin':
             $plugin = Params::getParam("plugin");
             if ($plugin != "") {
                 osc_run_hook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             osc_run_hook('admin_post');
             break;
         case 'renderplugin':
             if (Params::existParam('route')) {
                 $routes = Rewrite::newInstance()->getRoutes();
                 $rid = Params::getParam('route');
                 $file = '../';
                 if (isset($routes[$rid]) && isset($routes[$rid]['file'])) {
                     $file = $routes[$rid]['file'];
                 }
             } else {
                 // DEPRECATED: Disclosed path in URL is deprecated, use routes instead
                 // This will be REMOVED in 3.4
                 $file = Params::getParam('file');
                 // We pass the GET variables (in case we have somes)
                 if (preg_match('|(.+?)\\?(.*)|', $file, $match)) {
                     $file = $match[1];
                     if (preg_match_all('|&([^=]+)=([^&]*)|', urldecode('&' . $match[2] . '&'), $get_vars)) {
                         for ($var_k = 0; $var_k < count($get_vars[1]); $var_k++) {
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = Params::getParam('file');
                 }
             }
             osc_run_hook('renderplugin_controller');
             if (stripos($file, '../') === false && stripos($file, '..\\') === false && $file != "") {
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 $this->doView("plugins/view.php");
             }
             break;
         case 'configure':
             $plugin = Params::getParam("plugin");
             if ($plugin != '') {
                 $plugin_data = Plugins::getInfo($plugin);
                 $this->_exportVariableToView("categories", Category::newInstance()->toTreeAll());
                 $this->_exportVariableToView("selected", PluginCategory::newInstance()->listSelected($plugin_data['short_name']));
                 $this->_exportVariableToView("plugin_data", $plugin_data);
                 $this->doView("plugins/configuration.php");
             } else {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             }
             break;
         case 'configure_post':
             osc_csrf_check();
             $plugin_short_name = Params::getParam("plugin_short_name");
             $categories = Params::getParam("categories");
             if ($plugin_short_name != "") {
                 Plugins::cleanCategoryFromPlugin($plugin_short_name);
                 if (isset($categories)) {
                     Plugins::addToCategoryPlugin($categories, $plugin_short_name);
                 }
                 osc_run_hook('plugin_categories_' . Params::getParam('plugin'), $categories);
                 osc_add_flash_ok_message(_m('Configuration was saved'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             }
             osc_add_flash_error_message(_m('No plugin selected'), 'admin');
             $this->doView('plugins/index.php');
             break;
         case 'delete':
             osc_csrf_check();
             $plugin = str_replace('/index.php', '', Params::getParam("plugin"));
             $path = preg_replace('([\\/]+)', '/', CONTENT_PATH . 'plugins/' . $plugin);
             if ($plugin != "" && strpos($plugin, '../') === false && strpos($plugin, '..\\') === false && $path != CONTENT_PATH . 'plugins/') {
                 if (osc_deleteDir($path)) {
                     osc_add_flash_ok_message(_m('The files were deleted'), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m('There were an error deleting the files, please check the permissions of the files in %s'), $path . "/"), 'admin');
                 }
                 $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             }
             osc_add_flash_error_message(_m('No plugin selected'), 'admin');
             $this->doView('plugins/index.php');
             break;
         case 'error_plugin':
             // force php errors and simulate plugin installation to show the errors in the iframe
             if (!OSC_DEBUG) {
                 error_reporting(E_ALL | E_STRICT);
             }
             @ini_set('display_errors', 1);
             include osc_plugins_path() . Params::getParam('plugin');
             Plugins::install(Params::getParam('plugin'));
             exit;
             break;
         default:
             if (Params::getParam('checkUpdated') != '') {
                 osc_admin_toolbar_update_plugins(true);
             }
             if (Params::getParam('iDisplayLength') == '') {
                 Params::setParam('iDisplayLength', 25);
             }
             $this->_exportVariableToView('iDisplayLength', Params::getParam('iDisplayLength'));
             $p_iPage = 1;
             if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') >= 1) {
                 $p_iPage = Params::getParam('iPage');
             }
             Params::setParam('iPage', $p_iPage);
             $aPlugin = Plugins::listAll();
             $active_plugins = osc_get_plugins();
             // pagination
             $start = ($p_iPage - 1) * Params::getParam('iDisplayLength');
             $limit = Params::getParam('iDisplayLength');
             $count = count($aPlugin);
             $displayRecords = $limit;
             if ($start + $limit > $count) {
                 $displayRecords = $start + $limit - $count;
             }
             // --------------------------------------------------------
             $aData = array();
             $aInfo = array();
             $max = $start + $limit;
             if ($max > $count) {
                 $max = $count;
             }
             $aPluginsToUpdate = json_decode(osc_get_preference('plugins_to_update'));
             $bPluginsToUpdate = is_array($aPluginsToUpdate) ? true : false;
             for ($i = $start; $i < $max; $i++) {
                 $plugin = $aPlugin[$i];
                 $row = array();
                 $pInfo = osc_plugin_get_info($plugin);
                 // prepare row 1
                 $installed = 0;
                 if (osc_plugin_is_installed($plugin)) {
                     $installed = 1;
                 }
                 $enabled = 0;
                 if (osc_plugin_is_enabled($plugin)) {
                     $enabled = 1;
                 }
                 // prepare row 2
                 $sUpdate = '';
                 // get plugins to update from t_preference
                 if ($bPluginsToUpdate) {
                     if (in_array(@$pInfo['plugin_update_uri'], $aPluginsToUpdate)) {
                         $sUpdate = '<a class="market_update market-popup" href="#' . htmlentities($pInfo['plugin_update_uri']) . '">' . __("There's a new update available") . '</a>';
                     }
                 }
                 // prepare row 4
                 $sConfigure = '';
                 if (isset($active_plugins[$plugin . '_configure'])) {
                     $sConfigure = '<a href="' . osc_admin_base_url(true) . '?page=plugins&amp;action=admin&amp;plugin=' . $pInfo['filename'] . "&amp;" . osc_csrf_token_url() . '">' . __('Configure') . '</a>';
                 }
                 // prepare row 5
                 $sEnable = '';
                 if ($installed) {
                     if ($enabled) {
                         $sEnable = '<a href="' . osc_admin_base_url(true) . '?page=plugins&amp;action=disable&amp;plugin=' . $pInfo['filename'] . "&amp;" . osc_csrf_token_url() . '">' . __('Disable') . '</a>';
                     } else {
                         $sEnable = '<a href="' . osc_admin_base_url(true) . '?page=plugins&amp;action=enable&amp;plugin=' . $pInfo['filename'] . "&amp;" . osc_csrf_token_url() . '">' . __('Enable') . '</a>';
                     }
                 }
                 // prepare row 6
                 if ($installed) {
                     $sInstall = '<a onclick="javascript:return uninstall_dialog(\'' . $pInfo['filename'] . '\', \'' . $pInfo['plugin_name'] . '\');" href="' . osc_admin_base_url(true) . '?page=plugins&amp;action=uninstall&amp;plugin=' . $pInfo['filename'] . "&amp;" . osc_csrf_token_url() . '">' . __('Uninstall') . '</a>';
                 } else {
                     $sInstall = '<a href="' . osc_admin_base_url(true) . '?page=plugins&amp;action=install&amp;plugin=' . $pInfo['filename'] . "&amp;" . osc_csrf_token_url() . '">' . __('Install') . '</a>';
                 }
                 $sDelete = '';
                 if (!$installed) {
                     $sDelete = '<a href="javascript:delete_plugin(\'' . $pInfo['filename'] . '\');" >' . __('Delete') . '</a>';
                 }
                 $sHelp = '';
                 if ($pInfo['support_uri'] != '') {
                     $sHelp = '<span class="plugin-support-icon plugin-tooltip" ><a target="_blank" href="' . osc_sanitize_url($pInfo['support_uri']) . '" ><img src="' . osc_current_admin_theme_url('images/question.png') . '" alt="' . osc_esc_html(__('Problems with this plugin? Ask for support.')) . '" ></a></span>';
                 }
                 $sSiteUrl = '';
                 if ($pInfo['plugin_uri'] != '') {
                     $sSiteUrl = ' | <a target="_blank" href="' . $pInfo['plugin_uri'] . '">' . __('Plugins Site') . '</a>';
                 }
                 if ($pInfo['author_uri'] != '') {
                     $sAuthor = __('By') . ' <a target="_blank" href="' . $pInfo['author_uri'] . '">' . $pInfo['author'] . '</a>';
                 } else {
                     $sAuthor = __('By') . ' ' . $pInfo['author'];
                 }
                 $row[] = '<input type="hidden" name="installed" value="' . $installed . '" enabled="' . $enabled . '" />' . $pInfo['plugin_name'] . $sHelp . '<div>' . $sUpdate . '</div>';
                 $row[] = $pInfo['description'] . '<br />' . __('Version:') . $pInfo['version'] . ' | ' . $sAuthor . $sSiteUrl;
                 $row[] = $sUpdate != '' ? $sUpdate : '&nbsp;';
                 $row[] = $sConfigure != '' ? $sConfigure : '&nbsp;';
                 $row[] = $sEnable != '' ? $sEnable : '&nbsp;';
                 $row[] = $sInstall != '' ? $sInstall : '&nbsp;';
                 $row[] = $sDelete != '' ? $sDelete : '&nbsp;';
                 $aData[] = $row;
                 if (@$pInfo['plugin_update_uri'] != '') {
                     $aInfo[@$pInfo['plugin_update_uri']] = $pInfo;
                 } else {
                     $aInfo[$i] = $pInfo;
                 }
             }
             $array['iTotalRecords'] = $displayRecords;
             $array['iTotalDisplayRecords'] = count($aPlugin);
             $array['iDisplayLength'] = $limit;
             $array['aaData'] = $aData;
             $array['aaInfo'] = $aInfo;
             // --------------------------------------------------------
             $page = (int) Params::getParam('iPage');
             if (count($array['aaData']) == 0 && $page != 1) {
                 $total = (int) $array['iTotalDisplayRecords'];
                 $maxPage = ceil($total / (int) $array['iDisplayLength']);
                 $url = osc_admin_base_url(true) . '?' . Params::getServerParam('QUERY_STRING', false, false);
                 if ($maxPage == 0) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url);
                     $this->redirectTo($url);
                 }
                 if ($page > 1) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url);
                     $this->redirectTo($url);
                 }
             }
             $this->_exportVariableToView('aPlugins', $array);
             $this->doView("plugins/index.php");
             break;
     }
 }