Exemplo n.º 1
0
function theme_classified_actions_admin()
{
    switch (Params::getParam('action_specific')) {
        case 'upload_logo':
            $package = Params::getFiles('logo');
            if ($package['error'] == UPLOAD_ERR_OK) {
                if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                    osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'classified'), 'admin');
                } else {
                    osc_add_flash_error_message(__("An error has occurred, please try again", 'classified'), 'admin');
                }
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", 'classified'), 'admin');
            }
            header('Location: ' . osc_admin_render_theme_url('oc-content/themes/classified/admin/header.php'));
            exit;
            break;
        case 'remove':
            if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                @unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg");
                osc_add_flash_ok_message(__('The logo image has been removed', 'classified'), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", 'classified'), 'admin');
            }
            header('Location: ' . osc_admin_render_theme_url('oc-content/themes/classified/admin/header.php'));
            exit;
            break;
    }
}
Exemplo n.º 2
0
 function doModel()
 {
     switch ($this->action) {
         case 'contact_post':
             //contact_post
             $yourName = Params::getParam('yourName');
             $yourEmail = Params::getParam('yourEmail');
             $subject = Params::getParam('subject');
             $message = Params::getParam('message');
             if (osc_recaptcha_private_key() != '' && Params::existParam("recaptcha_challenge_field")) {
                 if (!osc_check_recaptcha()) {
                     osc_add_flash_error_message(_m('The Recaptcha code is wrong'));
                     Session::newInstance()->_setForm("yourName", $yourName);
                     Session::newInstance()->_setForm("yourEmail", $yourEmail);
                     Session::newInstance()->_setForm("subject", $subject);
                     Session::newInstance()->_setForm("message_body", $message);
                     $this->redirectTo(osc_contact_url());
                     return false;
                     // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                 }
             }
             if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) {
                 osc_add_flash_error_message(_m('Please enter a correct email'));
                 Session::newInstance()->_setForm("yourName", $yourName);
                 Session::newInstance()->_setForm("subject", $subject);
                 Session::newInstance()->_setForm("message_body", $message);
                 $this->redirectTo(osc_contact_url());
             }
             $message = sprintf(__("%s (%s) left this message : %s"), $yourName, $yourEmail, $message);
             $params = array('reply_to' => $yourEmail, 'subject' => '[' . osc_page_title() . '] ' . __('Contact form') . ': ' . $subject, 'to' => osc_contact_email(), 'to_name' => __('Administrator'), 'body' => $message, 'alt_body' => $message);
             if (osc_contact_attachment()) {
                 $attachment = Params::getFiles('attachment');
                 $resourceName = $attachment['name'];
                 $tmpName = $attachment['tmp_name'];
                 $resourceType = $attachment['type'];
                 $path = osc_content_path() . 'uploads/' . time() . '_' . $resourceName;
                 if (!is_writable(osc_content_path() . 'uploads/')) {
                     osc_add_flash_error_message(_m('There have been some errors sending the message'));
                     $this->redirectTo(osc_contact_url());
                 }
                 if (!move_uploaded_file($tmpName, $path)) {
                     unset($path);
                 }
             }
             if (isset($path)) {
                 $params['attachment'] = $path;
             }
             osc_sendMail($params);
             osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!'));
             $this->redirectTo(osc_contact_url());
             break;
         default:
             //contact
             $this->doView('contact.php');
     }
 }
Exemplo n.º 3
0
function digitalgoods_upload_files($item)
{
    if ($item['fk_i_category_id'] != null) {
        if (osc_is_this_category('digitalgoods', $item['fk_i_category_id'])) {
            $files = Params::getFiles('dg_files');
            if (count($files) > 0) {
                require LIB_PATH . 'osclass/mimes.php';
                $aMimesAllowed = array();
                $aExt = explode(',', osc_get_preference('allowed_ext', 'digitalgoods'));
                foreach ($aExt as $ext) {
                    $mime = $mimes[$ext];
                    if (is_array($mime)) {
                        foreach ($mime as $aux) {
                            if (!in_array($aux, $aMimesAllowed)) {
                                array_push($aMimesAllowed, $aux);
                            }
                        }
                    } else {
                        if (!in_array($mime, $aMimesAllowed)) {
                            array_push($aMimesAllowed, $mime);
                        }
                    }
                }
                $failed = false;
                $maxSize = osc_max_size_kb() * 1024;
                foreach ($files['error'] as $key => $error) {
                    $bool_img = false;
                    if ($error == UPLOAD_ERR_OK) {
                        $size = $files['size'][$key];
                        if ($size <= $maxSize) {
                            $fileMime = $files['type'][$key];
                            if (in_array($fileMime, $aMimesAllowed)) {
                                $date = date('YmdHis');
                                $file_name = $date . '_' . $item['pk_i_id'] . '_' . $files['name'][$key];
                                $path = osc_get_preference('upload_path', 'digitalgoods') . $file_name;
                                if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                                    DGModel::newInstance()->insertFile($item['pk_i_id'], $files['name'][$key], $date);
                                } else {
                                    $failed = true;
                                }
                            } else {
                                $failed = true;
                            }
                        } else {
                            $failed = true;
                        }
                    }
                }
                if ($failed) {
                    osc_add_flash_error_message(__('Some of the files were not uploaded because they have incorrect extension', 'digitalgoods'), 'admin');
                }
            }
        }
    }
}
Exemplo n.º 4
0
function theme_modern_actions_admin()
{
    if (Params::getParam('file') == 'oc-content/themes/modern/admin/settings.php') {
        if (Params::getParam('donation') == 'successful') {
            osc_set_preference('donation', '1', 'modern_theme');
            osc_reset_preferences();
        }
    }
    switch (Params::getParam('action_specific')) {
        case 'settings':
            $footerLink = Params::getParam('footer_link');
            $defaultLogo = Params::getParam('default_logo');
            osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'modern_theme');
            osc_set_preference('footer_link', $footerLink ? '1' : '0', 'modern_theme');
            osc_set_preference('default_logo', $defaultLogo ? '1' : '0', 'modern_theme');
            osc_add_flash_ok_message(__('Theme settings updated correctly', 'modern'), 'admin');
            header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/settings.php'));
            exit;
            break;
        case 'upload_logo':
            $package = Params::getFiles('logo');
            if ($package['error'] == UPLOAD_ERR_OK) {
                if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                    osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'modern'), 'admin');
                } else {
                    osc_add_flash_error_message(__("An error has occurred, please try again", 'modern'), 'admin');
                }
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", 'modern'), 'admin');
            }
            header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/header.php'));
            exit;
            break;
        case 'remove':
            if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                @unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg");
                osc_add_flash_ok_message(__('The logo image has been removed', 'modern'), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", 'modern'), 'admin');
            }
            header('Location: ' . osc_admin_render_theme_url('oc-content/themes/modern/admin/header.php'));
            exit;
            break;
    }
}
Exemplo n.º 5
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));
             } 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'), strlen($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 != "") {
                 Plugins::runHook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             Plugins::runHook('admin_post');
             break;
         case 'renderplugin':
             $file = Params::getParam("file");
             if ($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++) {
                             //$_GET[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             //$_REQUEST[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 //osc_renderPluginView($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_add_flash_ok_message(_m('Configuration was saved'), 'admin');
                 $this->redirectTo(osc_get_http_referer());
             }
             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:
             //                    $marketError = Params::getParam('marketError');
             //                    $slug = Params::getParam('slug');
             //                    if($marketError!='') {
             //                        if($marketError == '0') { // no error installed ok
             //                            $extra = '<br/><br/><b>' . __('You only need to install and configure the plugin.') . '</b>';
             //                            osc_add_flash_ok_message( __('Everything was OK!') . ' ( ' . $slug . ' ) ' . $extra , 'admin');
             //                        } else {
             //                            osc_add_flash_error_message( __('Error occurred') . ' ' . $slug , 'admin');
             //                        }
             //                    }
             if (Params::getParam('checkUpdated') != '') {
                 osc_admin_toolbar_update_plugins(true);
             }
             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);
             $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(getPreference('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
                 $sInstall = '';
                 if ($installed) {
                     $sInstall = '<a onclick="javascript:return uninstall_dialog(\'' . $pInfo['filename'] . '\');" 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>';
                 }
                 $row[] = '<input type="hidden" name="installed" value="' . $installed . '" enabled="' . $enabled . '" />' . $pInfo['plugin_name'] . '<div>' . $sUpdate . '</div>';
                 $row[] = $pInfo['description'];
                 $row[] = $sUpdate != '' ? $sUpdate : '&nbsp;';
                 $row[] = $sConfigure != '' ? $sConfigure : '&nbsp;';
                 $row[] = $sEnable != '' ? $sEnable : '&nbsp;';
                 $row[] = $sInstall != '' ? $sInstall : '&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) . '?' . $_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('aPlugins', $array);
             $this->doView("plugins/index.php");
             break;
     }
 }
Exemplo n.º 6
0
function theme_osclasswizards_actions_admin()
{
    if (Params::getParam('file') == 'oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php') {
        if (Params::getParam('donation') == 'successful') {
            osc_set_preference('donation', '1', 'osclasswizards_theme');
            osc_reset_preferences();
        }
    }
    switch (Params::getParam('action_specific')) {
        case 'settings':
            osc_set_preference('welcome_message', Params::getParam('welcome_message'), 'osclasswizards_theme');
            osc_set_preference('defaultShowAs@all', Params::getParam('defaultShowAs@all'), 'osclasswizards_theme');
            osc_set_preference('defaultShowAs@search', Params::getParam('defaultShowAs@all'));
            osc_add_flash_ok_message(__('Theme settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php'));
            break;
        case 'templates_home':
            osc_set_preference('show_banner', Params::getParam('show_banner') ? '1' : '0', 'osclasswizards_theme');
            osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'osclasswizards_theme');
            osc_set_preference('show_search_country', Params::getParam('show_search_country') ? '1' : '0', 'osclasswizards_theme');
            osc_set_preference('premium_listings_shown_home', Params::getParam('premium_listings_shown_home'), 'osclasswizards_theme');
            osc_set_preference('sub_cat_limit', Params::getParam('sub_cat_limit'), 'osclasswizards_theme');
            osc_set_preference('show_popular', Params::getParam('show_popular'), 'osclasswizards_theme');
            osc_set_preference('show_popular_regions', Params::getParam('show_popular_regions'), 'osclasswizards_theme');
            osc_set_preference('show_popular_cities', Params::getParam('show_popular_cities'), 'osclasswizards_theme');
            osc_set_preference('show_popular_searches', Params::getParam('show_popular_searches'), 'osclasswizards_theme');
            osc_set_preference('popular_regions_limit', Params::getParam('popular_regions_limit'), 'osclasswizards_theme');
            osc_set_preference('popular_cities_limit', Params::getParam('popular_cities_limit'), 'osclasswizards_theme');
            osc_set_preference('popular_searches_limit', Params::getParam('popular_searches_limit'), 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Templates settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#templates'));
            break;
        case 'templates_search':
            osc_set_preference('premium_listings_shown', Params::getParam('premium_listings_shown'), 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Templates settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#templates'));
            break;
        case 'templates_item_post':
            $locations_input_as = Params::getParam('locations_input_as', 'osclasswizards_theme');
            $locations_required = Params::getParam('locations_required', 'osclasswizards_theme');
            $category_multiple_selects = Params::getParam('category_multiple_selects', 'osclasswizards_theme');
            osc_set_preference('title_minimum_length', Params::getParam('title_minimum_length', 'osclasswizards_theme'), 'osclasswizards_theme');
            osc_set_preference('description_minimum_length', Params::getParam('description_minimum_length', 'osclasswizards_theme'), 'osclasswizards_theme');
            osc_set_preference('locations_input_as', $locations_input_as, 'osclasswizards_theme');
            osc_set_preference('locations_required', $locations_required ? '1' : '0', 'osclasswizards_theme');
            osc_set_preference('category_multiple_selects', $category_multiple_selects ? '1' : '0', 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Templates settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#templates'));
            break;
        case 'ads_mgmt':
            osc_set_preference('header-728x90', trim(Params::getParam('header-728x90', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('homepage-728x90', trim(Params::getParam('homepage-728x90', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('sidebar-300x250', trim(Params::getParam('sidebar-300x250', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('search-results-top-728x90', trim(Params::getParam('search-results-top-728x90', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('search-results-middle-728x90', trim(Params::getParam('search-results-middle-728x90', false, false, false)), 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Ads management updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#ads'));
            break;
        case 'categories_icons':
            $catsIcons = Params::getParam('cat-icons');
            foreach ($catsIcons as $catId => $iconName) {
                osc_set_preference('cat-icons-' . $catId, $iconName, 'osclasswizards_theme_cat_icons');
            }
            osc_add_flash_ok_message(__('Category icons settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#category-icons'));
            break;
        case 'theme_style':
            $color_mode = Params::getParam('theme_color_mode');
            osc_set_preference('theme_color_mode', $color_mode, 'osclasswizards_theme');
            osc_set_preference('google_fonts', Params::getParam('google_fonts'), 'osclasswizards_theme');
            $rtl_view = Params::getParam('rtl_view', 'osclasswizards_theme');
            osc_set_preference('rtl_view', $rtl_view ? '1' : '0', 'osclasswizards_theme');
            osc_set_preference('custom_css', trim(Params::getParam('custom_css', false, false, false)), 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Theme color settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#theme-style'));
            break;
        case 'facebook':
            osc_set_preference('facebook-url', trim(Params::getParam('facebook-url', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-width', trim(Params::getParam('facebook-width', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-height', trim(Params::getParam('facebook-height', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-hidecover', trim(Params::getParam('facebook-hidecover', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-showface', trim(Params::getParam('facebook-showface', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-showpost', trim(Params::getParam('facebook-showpost', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-showitem', trim(Params::getParam('facebook-showitem', false, false, false)), 'osclasswizards_theme');
            osc_set_preference('facebook-showsearch', trim(Params::getParam('facebook-showsearch', false, false, false)), 'osclasswizards_theme');
            osc_add_flash_ok_message(__('Facebook Page settings updated correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#facebook'));
            break;
        case 'upload_favicon':
            $package = Params::getFiles('favicon');
            if ($package['error'] == UPLOAD_ERR_OK) {
                $img = ImageResizer::fromFile($package['tmp_name']);
                $ext = $img->getExt();
                $logo_name = 'favicon';
                $logo_name .= '.' . $ext;
                $path = osc_uploads_path() . $logo_name;
                $img->saveToFile($path);
                osc_set_preference('favicon', $logo_name, 'osclasswizards_theme');
                osc_add_flash_ok_message(__('The favicon image has been uploaded correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#favicon'));
            break;
        case 'upload_logo':
            $package = Params::getFiles('logo');
            if ($package['error'] == UPLOAD_ERR_OK) {
                $img = ImageResizer::fromFile($package['tmp_name']);
                $ext = $img->getExt();
                $logo_name = 'logo';
                $logo_name .= '.' . $ext;
                $path = osc_uploads_path() . $logo_name;
                $img->saveToFile($path);
                osc_set_preference('logo', $logo_name, 'osclasswizards_theme');
                osc_add_flash_ok_message(__('The logo image has been uploaded correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#logo'));
            break;
        case 'remove_favicon':
            $logo = osc_get_preference('favicon', 'osclasswizards_theme');
            $path = osc_uploads_path() . $logo;
            if (file_exists($path)) {
                @unlink($path);
                osc_delete_preference('favicon', 'osclasswizards_theme');
                osc_reset_preferences();
                osc_add_flash_ok_message(__('The favicon image has been removed', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#favicon'));
            break;
        case 'remove':
            $logo = osc_get_preference('logo', 'osclasswizards_theme');
            $path = osc_uploads_path() . $logo;
            if (file_exists($path)) {
                @unlink($path);
                osc_delete_preference('logo', 'osclasswizards_theme');
                osc_reset_preferences();
                osc_add_flash_ok_message(__('The logo image has been removed', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#logo'));
            break;
        case 'upload_homeimage':
            $package = Params::getFiles('homeimage');
            if ($package['error'] == UPLOAD_ERR_OK) {
                $img = ImageResizer::fromFile($package['tmp_name']);
                $ext = $img->getExt();
                $logo_name = 'homeimage';
                $logo_name .= '.' . $ext;
                $path = osc_uploads_path() . $logo_name;
                $img->saveToFile($path);
                osc_set_preference('homeimage', $logo_name, 'osclasswizards_theme');
                osc_add_flash_ok_message(__('The banner image has been uploaded correctly', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#banner'));
            break;
        case 'remove_homeimage':
            $logo = osc_get_preference('homeimage', 'osclasswizards_theme');
            $path = osc_uploads_path() . $logo;
            if (file_exists($path)) {
                @unlink($path);
                osc_delete_preference('homeimage', 'osclasswizards_theme');
                osc_reset_preferences();
                osc_add_flash_ok_message(__('The banner image has been removed', OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", OSCLASSWIZARDS_THEME_FOLDER), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/' . OSCLASSWIZARDS_THEME_FOLDER . '/admin/settings.php#banner'));
            break;
    }
}
Exemplo n.º 7
0
<?php

if (Params::getParam("action_specific") != '') {
    switch (Params::getParam("action_specific")) {
        case 'upload_logo':
            $package = Params::getFiles("logo");
            if ($package['error'] == UPLOAD_ERR_OK) {
                if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                    osc_add_flash_ok_message(_m('The logo image has been uploaded correctly'), 'admin');
                } else {
                    osc_add_flash_error_message(_m("An error has occurred, please try again"), 'admin');
                }
            } else {
                osc_add_flash_error_message(_m("An error has occurred, please try again"), 'admin');
            }
            break;
        case 'remove':
            if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg");
                osc_add_flash_ok_message(_m('The logo image has been removed'), 'admin');
            } else {
                osc_add_flash_error_message(_m("Image not found"), 'admin');
            }
            break;
    }
}
?>
    <?php 
osc_show_flash_message('admin');
?>
    <div id="settings_form" style="border: 1px solid #ccc; background: #eee; ">
Exemplo n.º 8
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;
     }
 }
Exemplo n.º 9
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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=appearance');
             }
             $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 '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':
             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':
             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':
             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;
         case 'activate':
             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;
         default:
             $themes = WebThemes::newInstance()->getListThemes();
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             //preparing variables for the view
             $this->_exportVariableToView("themes", $themes);
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/index.php');
     }
 }
Exemplo n.º 10
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.º 11
0
 /**
  * Return an array with all data necessary for do the action (ADD OR EDIT)
  * @param <type> $is_add
  * @return array
  */
 public function prepareData($is_add)
 {
     $aItem = array();
     // prepare user
     $userId = null;
     if ($this->is_admin) {
         if (Params::getParam('userId') != '') {
             $userId = Params::getParam('userId');
         }
     } else {
         $userId = Session::newInstance()->_get('userId');
         if ($userId == '') {
             $userId = NULL;
         }
     }
     if ($is_add) {
         // ADD
         if ($this->is_admin) {
             $active = 'ACTIVE';
         } else {
             if (osc_moderate_items() > 0) {
                 // HAS TO VALIDATE
                 if (!osc_is_web_user_logged_in()) {
                     // NO USER IS LOGGED, VALIDATE
                     $active = 'INACTIVE';
                 } else {
                     // USER IS LOGGED
                     if (osc_logged_user_item_validation()) {
                         //USER IS LOGGED, BUT NO NEED TO VALIDATE
                         $active = 'ACTIVE';
                     } else {
                         // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS
                         $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
                         if ($user['i_items'] < osc_moderate_items()) {
                             $active = 'INACTIVE';
                         } else {
                             $active = 'ACTIVE';
                         }
                     }
                 }
             } else {
                 if (osc_moderate_items() == 0) {
                     if (osc_is_web_user_logged_in() && osc_logged_user_item_validation()) {
                         $active = 'ACTIVE';
                     } else {
                         $active = 'INACTIVE';
                     }
                 } else {
                     $active = 'ACTIVE';
                 }
             }
         }
         if ($userId != null) {
             $data = User::newInstance()->findByPrimaryKey($userId);
             $aItem['contactName'] = $data['s_name'];
             $aItem['contactEmail'] = $data['s_email'];
             Params::setParam('contactName', $data['s_name']);
             Params::setParam('contactEmail', $data['s_email']);
         } else {
             $aItem['contactName'] = Params::getParam('contactName');
             $aItem['contactEmail'] = Params::getParam('contactEmail');
         }
         $aItem['active'] = $active;
         $aItem['userId'] = $userId;
     } else {
         // EDIT
         $aItem['secret'] = Params::getParam('secret');
         $aItem['idItem'] = Params::getParam('id');
         if ($userId != null) {
             $data = User::newInstance()->findByPrimaryKey($userId);
             $aItem['contactName'] = $data['s_name'];
             $aItem['contactEmail'] = $data['s_email'];
             Params::setParam('contactName', $data['s_name']);
             Params::setParam('contactEmail', $data['s_email']);
         } else {
             $aItem['contactName'] = Params::getParam('contactName');
             $aItem['contactEmail'] = Params::getParam('contactEmail');
         }
         $aItem['userId'] = $userId;
     }
     // get params
     $aItem['catId'] = Params::getParam('catId');
     $aItem['countryId'] = Params::getParam('countryId');
     $aItem['country'] = Params::getParam('country');
     $aItem['region'] = Params::getParam('region');
     $aItem['regionId'] = Params::getParam('regionId');
     $aItem['city'] = Params::getParam('city');
     $aItem['cityId'] = Params::getParam('cityId');
     $aItem['price'] = Params::getParam('price') != '' ? Params::getParam('price') : null;
     $aItem['cityArea'] = Params::getParam('cityArea');
     $aItem['address'] = Params::getParam('address');
     $aItem['currency'] = Params::getParam('currency');
     $aItem['showEmail'] = Params::getParam('showEmail') != '' ? 1 : 0;
     $aItem['title'] = Params::getParam('title');
     $aItem['description'] = Params::getParam('description');
     $aItem['photos'] = Params::getFiles('photos');
     // check params
     $country = Country::newInstance()->findByCode($aItem['countryId']);
     if (count($country) > 0) {
         $countryId = $country['pk_c_code'];
         $countryName = $country['s_name'];
     } else {
         $countryId = null;
         $countryName = $aItem['country'];
     }
     $aItem['countryId'] = $countryId;
     $aItem['countryName'] = $countryName;
     if ($aItem['regionId'] != '') {
         if (intval($aItem['regionId'])) {
             $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']);
             if (count($region) > 0) {
                 $regionId = $region['pk_i_id'];
                 $regionName = $region['s_name'];
             }
         }
     } else {
         $regionId = null;
         $regionName = $aItem['region'];
         if ($aItem['countryId'] != '') {
             $auxRegion = Region::newInstance()->findByName($aItem['region'], $aItem['countryId']);
             if ($auxRegion) {
                 $regionId = $auxRegion['pk_i_id'];
                 $regionName = $auxRegion['s_name'];
             }
         }
     }
     $aItem['regionId'] = $regionId;
     $aItem['regionName'] = $regionName;
     if ($aItem['cityId'] != '') {
         if (intval($aItem['cityId'])) {
             $city = City::newInstance()->findByPrimaryKey($aItem['cityId']);
             if (count($city) > 0) {
                 $cityId = $city['pk_i_id'];
                 $cityName = $city['s_name'];
             }
         }
     } else {
         $cityId = null;
         $cityName = $aItem['city'];
         if ($aItem['countryId'] != '') {
             $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId']);
             if ($auxCity) {
                 $cityId = $auxCity['pk_i_id'];
                 $cityName = $auxCity['s_name'];
             }
         }
     }
     $aItem['cityId'] = $cityId;
     $aItem['cityName'] = $cityName;
     if ($aItem['cityArea'] == '') {
         $aItem['cityArea'] = null;
     }
     if ($aItem['address'] == '') {
         $aItem['address'] = null;
     }
     if (!is_null($aItem['price'])) {
         $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price']));
         $price = str_replace(osc_locale_dec_point(), '.', $price);
         $aItem['price'] = $price * 1000000;
         //$aItem['price'] = (float) $aItem['price'];
     }
     if ($aItem['catId'] == '') {
         $aItem['catId'] = 0;
     }
     if ($aItem['currency'] == '') {
         $aItem['currency'] = null;
     }
     $this->data = $aItem;
 }
Exemplo n.º 12
0
function fn_email_item_inquiry($aItem)
{
    $id = $aItem['id'];
    $yourEmail = $aItem['yourEmail'];
    $yourName = $aItem['yourName'];
    $phoneNumber = $aItem['phoneNumber'];
    $message = $aItem['message'];
    $path = NULL;
    $item = Item::newInstance()->findByPrimaryKey($id);
    View::newInstance()->_exportVariableToView('item', $item);
    $mPages = new Page();
    $aPage = $mPages->findByInternalName('email_item_inquiry');
    $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>';
    $words = array();
    $words[] = array('{CONTACT_NAME}', '{USER_NAME}', '{USER_EMAIL}', '{USER_PHONE}', '{WEB_URL}', '{ITEM_TITLE}', '{ITEM_URL}', '{COMMENT}');
    $words[] = array($item['s_contact_name'], $yourName, $yourEmail, $phoneNumber, '<a href="' . osc_base_url() . '" >' . osc_base_url() . '</a>', $item['s_title'], $item_url, $message);
    $title = osc_mailBeauty(osc_apply_filter('email_title', osc_apply_filter('email_item_inquiry_title', $content['s_title'])), $words);
    $body = osc_mailBeauty(osc_apply_filter('email_description', osc_apply_filter('email_item_inquiry_description', $content['s_text'])), $words);
    $from = osc_contact_email();
    $from_name = osc_page_title();
    $add_bbc = '';
    if (osc_notify_contact_item()) {
        $add_bbc = osc_contact_email();
    }
    $emailParams = array('add_bcc' => $add_bbc, 'from' => $from, 'from_name' => $from_name, 'subject' => $title, 'to' => $item['s_contact_email'], 'to_name' => $item['s_contact_name'], 'body' => $body, 'alt_body' => $body, 'reply_to' => $yourEmail);
    if (osc_item_attachment()) {
        $attachment = Params::getFiles('attachment');
        $resourceName = $attachment['name'];
        $tmpName = $attachment['tmp_name'];
        $resourceType = $attachment['type'];
        $path = osc_content_path() . 'uploads/' . time() . '_' . $resourceName;
        if (!is_writable(osc_content_path() . 'uploads/')) {
            osc_add_flash_error_message(_m('There has been some errors sending the message'));
            //$this->redirectTo( osc_base_url() );
        }
        if (!move_uploaded_file($tmpName, $path)) {
            unset($path);
        }
    }
    if (isset($path)) {
        $emailParams['attachment'] = $path;
    }
    osc_sendMail($emailParams);
    @unlink($path);
}
Exemplo n.º 13
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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             $package = Params::getFiles("package");
             if (isset($package['size']) && $package['size'] != 0) {
                 $path = osc_plugins_path();
                 (int) ($status = osc_unzip_file($package['tmp_name'], $path));
             } 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':
             $pn = Params::getParam("plugin");
             // CATCH FATAL ERRORS
             $old_value = error_reporting(0);
             register_shutdown_function(array($this, 'errorHandler'), $pn);
             $installed = Plugins::install($pn);
             if ($installed) {
                 //run this after installing the plugin
                 Plugins::runHook('install_' . $pn);
                 osc_add_flash_ok_message(_m('Plugin installed'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('Error: Plugin already installed'), 'admin');
             }
             error_reporting($old_value);
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'uninstall':
             $pn = Params::getParam("plugin");
             Plugins::runHook($pn . '_uninstall');
             Plugins::uninstall($pn);
             osc_add_flash_ok_message(_m('Plugin uninstalled'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'enable':
             $pn = Params::getParam("plugin");
             // CATCH FATAL ERRORS
             $old_value = error_reporting(0);
             register_shutdown_function(array($this, 'errorHandler'), $pn);
             $enabled = Plugins::activate($pn);
             if ($enabled) {
                 Plugins::runHook($pn . '_enable');
                 osc_add_flash_ok_message(_m('Plugin enabled'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('Error: Plugin already enabled'), 'admin');
             }
             error_reporting($old_value);
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'disable':
             $pn = Params::getParam("plugin");
             Plugins::runHook($pn . '_disable');
             Plugins::deactivate($pn);
             osc_add_flash_ok_message(_m('Plugin disabled'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'admin':
             global $active_plugins;
             $plugin = Params::getParam("plugin");
             if ($plugin != "") {
                 Plugins::runHook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             Plugins::runHook('admin_post');
         case 'renderplugin':
             global $active_plugins;
             $file = Params::getParam("file");
             if ($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++) {
                             //$_GET[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             //$_REQUEST[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 //osc_renderPluginView($file);
                 $this->doView("plugins/view.php");
             }
             break;
         case 'render':
             $file = Params::getParam("file");
             if ($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 = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", ABS_PATH . $file);
                 $this->doView("theme/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':
             $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);
                 }
             } else {
                 osc_add_flash_error_message(_m('No plugin selected'), 'admin');
                 $this->doView("plugins/index.php");
             }
             osc_add_flash_ok_message(_m('Configuration was saved'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         default:
             $this->_exportVariableToView("plugins", Plugins::listAll());
             $this->doView("plugins/index.php");
     }
 }
Exemplo n.º 14
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.º 15
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("appearance/add.php");
             break;
         case 'add_post':
             $filePackage = Params::getFiles('package');
             $path = osc_themes_path();
             (int) ($status = osc_unzip_file($filePackage['tmp_name'], $path));
             switch ($status) {
                 case 0:
                     $msg = _m('The theme folder is not writable');
                     break;
                 case 1:
                     $msg = _m('The theme has been installed correctly');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the theme');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
             /*case 'delete':
                   $themes = Params::getParam('theme') ;
                   if ( isset( $themes ) && is_array( $themes ) ) {
                       foreach ($themes as $theme) {
                           if (!osc_deleteDir(THEMES_PATH . $theme))
                               osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $theme);
                       }
                   } else if (isset( $themes )) {
                       if (!osc_deleteDir(THEMES_PATH . $themes)){
                           osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $themes);
                       }
                   } else {
                       osc_add_flash_message( _m('No theme selected'));
                   }
                   $this->redirectTo( osc_admin_base_url(true) . "?page=appearance" );
               break;*/
         /*case 'delete':
               $themes = Params::getParam('theme') ;
               if ( isset( $themes ) && is_array( $themes ) ) {
                   foreach ($themes as $theme) {
                       if (!osc_deleteDir(THEMES_PATH . $theme))
                           osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $theme);
                   }
               } else if (isset( $themes )) {
                   if (!osc_deleteDir(THEMES_PATH . $themes)){
                       osc_add_flash_message( _m('Directory "%s" can\'t be removed'), $themes);
                   }
               } else {
                   osc_add_flash_message( _m('No theme selected'));
               }
               $this->redirectTo( osc_admin_base_url(true) . "?page=appearance" );
           break;*/
         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 'delete_widget':
             Widget::newInstance()->delete(array('pk_i_id' => Params::getParam('id')));
             osc_add_flash_message(_m('Widget removed correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'add_widget_post':
             Widget::newInstance()->insert(array('s_location' => Params::getParam('location'), 'e_kind' => 'html', 's_description' => Params::getParam('description'), 's_content' => Params::getParam('content')));
             osc_add_flash_message(_m('Widget added correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance&action=widgets");
             break;
         case 'activate':
             Preference::newInstance()->update(array('s_value' => Params::getParam('theme')), array('s_section' => 'osclass', 's_name' => 'theme'));
             osc_add_flash_message(_m('Theme activated correctly'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=appearance");
             break;
         default:
             $themes = WebThemes::newInstance()->getListThemes();
             $info = WebThemes::newInstance()->loadThemeInfo(osc_theme());
             //preparing variables for the view
             $this->_exportVariableToView("themes", $themes);
             $this->_exportVariableToView("info", $info);
             $this->doView('appearance/index.php');
     }
 }
Exemplo n.º 16
0
<?php

switch (Params::getParam('action_specific')) {
    case 'upload_logo':
        $package = Params::getFiles('logo');
        if ($package['error'] == UPLOAD_ERR_OK) {
            if (move_uploaded_file($package['tmp_name'], WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
                osc_add_flash_ok_message(_m('The logo image has been uploaded correctly'), 'admin');
            } else {
                osc_add_flash_error_message(_m("An error has occurred, please try again"), 'admin');
            }
        } else {
            osc_add_flash_error_message(_m("An error has occurred, please try again"), 'admin');
        }
        break;
    case 'remove':
        if (file_exists(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg")) {
            @unlink(WebThemes::newInstance()->getCurrentThemePath() . "images/logo.jpg");
            osc_add_flash_ok_message(__('The logo image has been removed', 'newcorp'), 'admin');
        } else {
            osc_add_flash_error_message(__("Image not found", 'newcorp'), 'admin');
        }
        break;
}
osc_show_flash_message('admin');
?>
<div id="settings_form" style="border: 1px solid #ccc; background: #eee; padding: 20px;">
    <?php 
if (is_writable(WebThemes::newInstance()->getCurrentThemePath() . 'images/')) {
    ?>
        <p style="border-bottom: 1px black solid;padding-bottom: 10px;">
Exemplo n.º 17
0
function theme_bender_actions_admin()
{
    //if(OC_ADMIN)
    if (Params::getParam('file') == 'oc-content/themes/bender/admin/settings.php') {
        if (Params::getParam('donation') == 'successful') {
            osc_set_preference('donation', '1', 'bender');
            osc_reset_preferences();
        }
    }
    switch (Params::getParam('action_specific')) {
        case 'settings':
            $footerLink = Params::getParam('footer_link');
            osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'bender');
            osc_set_preference('footer_link', $footerLink ? '1' : '0', 'bender');
            osc_set_preference('defaultShowAs@all', Params::getParam('defaultShowAs@all'), 'bender');
            osc_set_preference('defaultShowAs@search', Params::getParam('defaultShowAs@all'));
            osc_set_preference('defaultLocationShowAs', Params::getParam('defaultLocationShowAs'), 'bender');
            osc_set_preference('header-728x90', trim(Params::getParam('header-728x90', false, false, false)), 'bender');
            osc_set_preference('homepage-728x90', trim(Params::getParam('homepage-728x90', false, false, false)), 'bender');
            osc_set_preference('sidebar-300x250', trim(Params::getParam('sidebar-300x250', false, false, false)), 'bender');
            osc_set_preference('search-results-top-728x90', trim(Params::getParam('search-results-top-728x90', false, false, false)), 'bender');
            osc_set_preference('search-results-middle-728x90', trim(Params::getParam('search-results-middle-728x90', false, false, false)), 'bender');
            osc_add_flash_ok_message(__('Theme settings updated correctly', 'bender'), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/bender/admin/settings.php'));
            break;
        case 'upload_logo':
            $package = Params::getFiles('logo');
            if ($package['error'] == UPLOAD_ERR_OK) {
                $img = ImageResizer::fromFile($package['tmp_name']);
                $ext = $img->getExt();
                $logo_name = 'bender_logo';
                $logo_name .= '.' . $ext;
                $path = osc_uploads_path() . $logo_name;
                $img->saveToFile($path);
                osc_set_preference('logo', $logo_name, 'bender');
                osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'bender'), 'admin');
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", 'bender'), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/bender/admin/header.php'));
            break;
        case 'remove':
            $logo = osc_get_preference('logo', 'bender');
            $path = osc_uploads_path() . $logo;
            if (file_exists($path)) {
                @unlink($path);
                osc_delete_preference('logo', 'bender');
                osc_reset_preferences();
                osc_add_flash_ok_message(__('The logo image has been removed', 'bender'), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", 'bender'), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/bender/admin/header.php'));
            break;
    }
}
Exemplo n.º 18
0
    function doModel()
    {
        switch ($this->action) {
            case 'contact_post':
                //contact_post
                osc_csrf_check();
                $yourName = Params::getParam('yourName');
                $yourEmail = Params::getParam('yourEmail');
                $subject = Params::getParam('subject');
                $message = Params::getParam('message');
                if (osc_recaptcha_private_key() != '') {
                    if (!osc_check_recaptcha()) {
                        osc_add_flash_error_message(_m('The Recaptcha code is wrong'));
                        Session::newInstance()->_setForm('yourName', $yourName);
                        Session::newInstance()->_setForm('yourEmail', $yourEmail);
                        Session::newInstance()->_setForm('subject', $subject);
                        Session::newInstance()->_setForm('message_body', $message);
                        $this->redirectTo(osc_contact_url());
                        return false;
                        // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                    }
                }
                if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) {
                    osc_add_flash_error_message(_m('Please enter a correct email'));
                    Session::newInstance()->_setForm('yourName', $yourName);
                    Session::newInstance()->_setForm('subject', $subject);
                    Session::newInstance()->_setForm('message_body', $message);
                    $this->redirectTo(osc_contact_url());
                }
                $message_name = sprintf(__('Name: %s'), $yourName);
                $message_email = sprintf(__('Email: %s'), $yourEmail);
                $message_subject = sprintf(__('Subject: %s'), $subject);
                $message_body = sprintf(__('Message: %s'), $message);
                $message_date = sprintf(__('Date: %s at %s'), date('l F d, Y'), date('g:i a'));
                $message_IP = sprintf(__('IP Address: %s'), get_ip());
                $message = <<<MESSAGE
{$message_name}
{$message_email}
{$message_subject}
{$message_body}

{$message_date}
{$message_IP}
MESSAGE;
                $params = array('from' => osc_contact_email(), 'to' => osc_contact_email(), 'to_name' => osc_page_title(), 'reply_to' => $yourEmail, 'subject' => '[' . osc_page_title() . '] ' . __('Contact'), 'body' => nl2br($message));
                if (osc_contact_attachment()) {
                    $attachment = Params::getFiles('attachment');
                    if (isset($attachment['tmp_name'])) {
                        $resourceName = $attachment['name'];
                        $tmpName = $attachment['tmp_name'];
                        $resourceType = $attachment['type'];
                        $path = osc_content_path() . 'uploads/' . time() . '_' . $resourceName;
                        if (!is_writable(osc_content_path() . 'uploads/')) {
                            osc_add_flash_error_message(_m('There have been some errors sending the message'));
                            $this->redirectTo(osc_contact_url());
                        }
                        if (!move_uploaded_file($tmpName, $path)) {
                            unset($path);
                        }
                    }
                }
                if (isset($path)) {
                    $params['attachment'] = $path;
                }
                osc_run_hook('pre_contact_post', $params);
                osc_sendMail(osc_apply_filter('contact_params', $params));
                osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!'));
                $this->redirectTo(osc_contact_url());
                break;
            default:
                //contact
                $this->doView('contact.php');
        }
    }
Exemplo n.º 19
0
 function doModel()
 {
     parent::doModel();
     switch ($this->action) {
         case 'import':
             // calling import view
             $this->doView('tools/import.php');
             break;
         case 'import_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             }
             // calling
             $sql = Params::getFiles('sql');
             if (isset($sql['size']) && $sql['size'] != 0) {
                 $content_file = file_get_contents($sql['tmp_name']);
                 $conn = DBConnectionClass::newInstance();
                 $c_db = $conn->getOsclassDb();
                 $comm = new DBCommandClass($c_db);
                 if ($comm->importSQL($content_file)) {
                     osc_add_flash_ok_message(_m('Import complete'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin');
                 }
             } else {
                 osc_add_flash_warning_message(_m('No file was uploaded'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             break;
         case 'images':
             // calling images view
             $this->doView('tools/images.php');
             break;
         case 'images_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images');
             }
             $preferences = Preference::newInstance()->toArray();
             $wat = new Watermark();
             $aResources = ItemResource::newInstance()->getAllResources();
             foreach ($aResources as $resource) {
                 osc_run_hook('regenerate_image', $resource);
                 $path = osc_content_path() . 'uploads/';
                 // comprobar que no haya original
                 $img_original = $path . $resource['pk_i_id'] . "_original*";
                 $aImages = glob($img_original);
                 // there is original image
                 if (count($aImages) == 1) {
                     $image_tmp = $aImages[0];
                 } else {
                     $img_normal = $path . $resource['pk_i_id'] . ".*";
                     $aImages = glob($img_normal);
                     if (count($aImages) == 1) {
                         $image_tmp = $aImages[0];
                     } else {
                         $img_thumbnail = $path . $resource['pk_i_id'] . "_thumbnail*";
                         $aImages = glob($img_thumbnail);
                         $image_tmp = $aImages[0];
                     }
                 }
                 // extension
                 preg_match('/\\.(.*)$/', $image_tmp, $matches);
                 if (isset($matches[1])) {
                     $extension = $matches[1];
                     // Create normal size
                     $path_normal = $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '.jpg';
                     $size = explode('x', osc_normal_dimensions());
                     ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1])->saveToFile($path);
                     if (osc_is_watermark_text()) {
                         $wat->doWatermarkText($path, osc_watermark_text_color(), osc_watermark_text(), 'image/jpeg');
                     } elseif (osc_is_watermark_image()) {
                         $wat->doWatermarkImage($path, 'image/jpeg');
                     }
                     // Create preview
                     $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_preview.jpg';
                     $size = explode('x', osc_preview_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     // Create thumbnail
                     $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_thumbnail.jpg';
                     $size = explode('x', osc_thumbnail_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     // update resource info
                     ItemResource::newInstance()->update(array('s_path' => 'oc-content/uploads/', 's_name' => osc_genRandomPassword(), 's_extension' => 'jpg', 's_content_type' => 'image/jpeg'), array('pk_i_id' => $resource['pk_i_id']));
                     osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id']));
                     // si extension es direfente a jpg, eliminar las imagenes con $extension si hay
                     if ($extension != 'jpg') {
                         $files_to_remove = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . "*" . $extension;
                         $fs = glob($files_to_remove);
                         if (is_array($fs)) {
                             array_map("unlink", $fs);
                         }
                     }
                     // ....
                 } else {
                     // no es imagen o imagen sin extesión
                 }
             }
             osc_add_flash_ok_message(_m('Re-generation complete'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images');
             break;
         case 'category':
             $this->doView('tools/category.php');
             break;
         case 'category_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category');
             }
             osc_update_cat_stats();
             osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category');
             break;
         case 'locations':
             $this->doView('tools/locations.php');
             break;
         case 'locations_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations');
             }
             $workToDo = LocationsTmp::newInstance()->count();
             if ($workToDo > 0) {
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations');
                 break;
             }
             // we need populate location tmp table
             $aCountry = Country::newInstance()->listAll();
             foreach ($aCountry as $country) {
                 $aRegionsCountry = Region::newInstance()->getByCountry($country['pk_c_code']);
                 LocationsTmp::newInstance()->insert(array('id_location' => $country['pk_c_code'], 'e_type' => 'COUNTRY'));
                 foreach ($aRegionsCountry as $region) {
                     $aCitiesRegion = City::newInstance()->getByRegion($region['pk_i_id']);
                     LocationsTmp::newInstance()->insert(array('id_location' => $region['pk_i_id'], 'e_type' => 'REGION'));
                     foreach ($aCitiesRegion as $city) {
                         LocationsTmp::newInstance()->insert(array('id_location' => $city['pk_i_id'], 'e_type' => 'CITY'));
                     }
                     unset($aCitiesRegion);
                 }
                 unset($aRegionsCountry);
             }
             unset($aCountry);
             $workToDo = LocationsTmp::newInstance()->count();
             Preference::newInstance()->replace('location_todo', $workToDo);
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations');
             break;
         case 'upgrade':
             $this->doView('tools/upgrade.php');
             break;
         case 'backup':
             $this->doView('tools/backup.php');
             break;
         case 'backup-sql':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //databasse dump...
             if (Params::getParam('bck_dir') != '') {
                 $path = trim(Params::getParam('bck_dir'));
                 if (substr($path, -1, 1) != "/") {
                     $path .= '/';
                 }
             } else {
                 $path = osc_base_path();
             }
             $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql';
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -2:
                     $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -3:
                     $msg = _m('There are no tables to back up');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -4:
                     $msg = _m('The folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 default:
                     $msg = _m('Backup completed successfully');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-sql_file':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //databasse dump...
             $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql';
             $path = sys_get_temp_dir() . "/";
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -2:
                     $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -3:
                     $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -4:
                     $msg = _m('There are no tables to back up');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -5:
                     $msg = _m('The folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 default:
                     $msg = _m('Backup completed successfully');
                     osc_add_flash_ok_message($msg, 'admin');
                     header('Content-Description: File Transfer');
                     header('Content-Type: application/octet-stream');
                     header('Content-Disposition: attachment; filename=' . basename($filename));
                     header('Content-Transfer-Encoding: binary');
                     header('Expires: 0');
                     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                     header('Pragma: public');
                     header('Content-Length: ' . filesize($path . $filename));
                     flush();
                     readfile($path . $filename);
                     exit;
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip_file':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             $filename = "OSClass_backup." . date('YmdHis') . ".zip";
             $path = sys_get_temp_dir() . "/";
             if (osc_zip_folder(osc_base_path(), $path . $filename)) {
                 $msg = _m('Archived successfully!');
                 osc_add_flash_ok_message($msg, 'admin');
                 header('Content-Description: File Transfer');
                 header('Content-Type: application/octet-stream');
                 header('Content-Disposition: attachment; filename=' . basename($filename));
                 header('Content-Transfer-Encoding: binary');
                 header('Expires: 0');
                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                 header('Pragma: public');
                 header('Content-Length: ' . filesize($path . $filename));
                 flush();
                 readfile($path . $filename);
                 exit;
             } else {
                 $msg = _m('Error, the zip file was not created in the specified directory');
                 osc_add_flash_error_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //zip of the code just to back it up
             if (Params::getParam('bck_dir') != '') {
                 $archive_name = trim(Params::getParam('bck_dir'));
                 if (substr(trim($archive_name), -1, 1) != "/") {
                     $archive_name .= '/';
                 }
                 $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip';
             } else {
                 $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip";
             }
             $archive_folder = osc_base_path();
             if (osc_zip_folder($archive_folder, $archive_name)) {
                 $msg = _m('Archived successfully!');
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 $msg = _m('Error, the zip file was not created in the specified directory');
                 osc_add_flash_error_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup_post':
             $this->doView('tools/backup.php');
             break;
         case 'maintenance':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin');
                 $this->doView('tools/maintenance.php');
                 break;
             }
             $mode = Params::getParam('mode');
             if ($mode == 'on') {
                 $maintenance_file = osc_base_path() . '.maintenance';
                 $fileHandler = @fopen($maintenance_file, 'w');
                 if ($fileHandler) {
                     osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin');
                 }
                 fclose($fileHandler);
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
             } else {
                 if ($mode == 'off') {
                     $deleted = @unlink(osc_base_path() . '.maintenance');
                     if ($deleted) {
                         osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin');
                     } else {
                         osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
                 }
             }
             $this->doView('tools/maintenance.php');
             break;
         default:
     }
 }
function theme_pop_actions_admin()
{
    //if(OC_ADMIN)
    if (Params::getParam('file') == 'oc-content/themes/pop/admin/settings.php') {
        if (Params::getParam('donation') == 'successful') {
            osc_set_preference('donation', '1', 'pop_theme');
            osc_reset_preferences();
        }
    }
    switch (Params::getParam('subaction')) {
        case 'color-update':
            /* theme color staff here */
            $aParams = Params::getParamsAsArray();
            unset($aParams['page']);
            unset($aParams['action']);
            unset($aParams['file']);
            unset($aParams['CSRFName']);
            unset($aParams['CSRFToken']);
            osc_set_preference('pop-theme-colors', json_encode($aParams), 'pop_theme');
            osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/color_settings.php'));
            break;
        case 'color-restore':
            $aParams = pop_getColorScheme(true);
            osc_set_preference('pop-theme-colors', json_encode($aParams), 'pop_theme');
            osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/color_settings.php'));
            break;
        default:
            break;
    }
    switch (Params::getParam('action_specific')) {
        case 'settings':
            $footerLink = Params::getParam('footer_link');
            osc_set_preference('pop_max_premium', Params::getParam('pop_max_premium'), 'pop_theme');
            osc_set_preference('keyword_placeholder', Params::getParam('keyword_placeholder'), 'pop_theme');
            osc_set_preference('footer_link', $footerLink ? '1' : '0', 'pop_theme');
            osc_set_preference('header-728x90', trim(Params::getParam('header-728x90', false, false, false)), 'pop_theme');
            osc_set_preference('search-results-300x250', trim(Params::getParam('search-results-300x250', false, false, false)), 'pop_theme');
            osc_set_preference('item-detail-300x250', trim(Params::getParam('item-detail-300x250', false, false, false)), 'pop_theme');
            osc_add_flash_ok_message(__('Theme settings updated correctly', 'pop'), 'admin');
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/settings.php'));
            break;
        case 'upload_logo':
            $package = Params::getFiles('logo');
            if ($package['error'] == UPLOAD_ERR_OK) {
                $img = ImageResizer::fromFile($package['tmp_name']);
                $ext = $img->getExt();
                $logo_name = 'pop_logo';
                $logo_name .= '.' . $ext;
                $path = osc_uploads_path() . $logo_name;
                move_uploaded_file($package['tmp_name'], $path);
                osc_set_preference('logo', $logo_name, 'pop_theme');
                osc_add_flash_ok_message(__('The logo image has been uploaded correctly', 'pop'), 'admin');
            } else {
                osc_add_flash_error_message(__("An error has occurred, please try again", 'pop'), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/header.php'));
            break;
        case 'remove':
            $logo = osc_get_preference('logo', 'pop_theme');
            $path = osc_uploads_path() . $logo;
            if (file_exists($path)) {
                @unlink($path);
                osc_delete_preference('logo', 'pop_theme');
                osc_reset_preferences();
                osc_add_flash_ok_message(__('The logo image has been removed', 'pop'), 'admin');
            } else {
                osc_add_flash_error_message(__("Image not found", 'pop'), 'admin');
            }
            osc_redirect_to(osc_admin_render_theme_url('oc-content/themes/pop/admin/header.php'));
            break;
    }
}
Exemplo n.º 21
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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             $package = Params::getFiles("package");
             if (isset($package['size']) && $package['size'] != 0) {
                 $path = osc_plugins_path();
                 (int) ($status = osc_unzip_file($package['tmp_name'], $path));
             } 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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             $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'), strlen($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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             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 cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=plugins');
             }
             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 != "") {
                 Plugins::runHook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             Plugins::runHook('admin_post');
         case 'renderplugin':
             $file = Params::getParam("file");
             if ($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++) {
                             //$_GET[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             //$_REQUEST[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 //osc_renderPluginView($file);
                 $this->doView("plugins/view.php");
             }
             break;
         case 'render':
             $file = Params::getParam("file");
             if ($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 = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", ABS_PATH . $file);
                 $this->doView("theme/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':
             $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);
                 }
             } else {
                 osc_add_flash_error_message(_m('No plugin selected'), 'admin');
                 $this->doView("plugins/index.php");
             }
             osc_add_flash_ok_message(_m('Configuration was saved'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             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:
             $this->_exportVariableToView("plugins", Plugins::listAll());
             $this->doView("plugins/index.php");
     }
 }
 *
 *       This program is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License
 *     as published by the Free Software Foundation, either version 3 of
 *            the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY; without even the implied warranty of
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *             GNU Affero General Public License for more details.
 *
 *      You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
if (Params::getParam('plugin_action') == 'done') {
    $file = Params::getFiles('xml');
    if (isset($file['error']) && $file['error'] == 0 && isset($file['size']) && $file['size'] > 0) {
        $tmpfile = osc_content_path() . 'uploads/adimporter_ads.temp';
        @unlink($tmpfile);
        if (move_uploaded_file($file['tmp_name'], $tmpfile)) {
            $num_ads = adimporter_countads($tmpfile);
        } else {
            $num_ads = 0;
        }
    } else {
        osc_add_flash_error_message(__('File uploaded was not valid', 'adimporter'), 'admin');
        osc_show_flash_message('admin');
        $num_ads = 0;
    }
    if ($num_ads > 0) {
        ?>
Exemplo n.º 23
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'add':
             $this->doView("plugins/add.php");
             break;
         case 'add_post':
             $package = Params::getFiles("package");
             $path = osc_plugins_path();
             (int) ($status = osc_unzip_file($package['tmp_name'], $path));
             switch ($status) {
                 case 0:
                     $msg = _m('The plugin folder is not writable');
                     break;
                 case 1:
                     $msg = _m('The plugin has been uploaded correctly');
                     break;
                 case 2:
                     $msg = _m('The zip file is not valid');
                     break;
                 case -1:
                 default:
                     $msg = _m('There was a problem adding the plugin');
                     break;
             }
             osc_add_flash_message($msg, 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'install':
             $pn = Params::getParam("plugin");
             Plugins::activate($pn);
             //run this after installing the plugin
             Plugins::runHook('install_' . $pn);
             osc_add_flash_message(_m('Plugin installed'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'uninstall':
             $pn = Params::getParam("plugin");
             Plugins::runHook($pn . '_uninstall');
             Plugins::deactivate($pn);
             osc_add_flash_message(_m('Plugin uninstalled'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         case 'admin':
             global $active_plugins;
             $plugin = Params::getParam("plugin");
             if ($plugin != "") {
                 Plugins::runHook($plugin . '_configure');
             }
             break;
         case 'admin_post':
             Plugins::runHook('admin_post');
         case 'renderplugin':
             global $active_plugins;
             $file = Params::getParam("file");
             if ($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++) {
                             //$_GET[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             //$_REQUEST[$get_vars[1][$var_k]] = $get_vars[2][$var_k];
                             Params::setParam($get_vars[1][$var_k], $get_vars[2][$var_k]);
                         }
                     }
                 } else {
                     $file = $_REQUEST['file'];
                 }
                 $this->_exportVariableToView("file", osc_plugins_path() . $file);
                 //osc_renderPluginView($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':
             $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);
                 }
             } else {
                 osc_add_flash_message(_m('No plugin selected'), 'admin');
                 $this->doView("plugins/index.php");
             }
             osc_add_flash_message(_m('Configuration was saved'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . "?page=plugins");
             break;
         default:
             $this->_exportVariableToView("plugins", Plugins::listAll());
             $this->doView("plugins/index.php");
     }
 }
Exemplo n.º 24
0
 function __construct()
 {
     $this->_file = Params::getFiles('qqfile');
 }
Exemplo n.º 25
0
    function doModel()
    {
        switch ($this->action) {
            case 'contact_post':
                //contact_post
                osc_csrf_check();
                $yourName = Params::getParam('yourName');
                $yourEmail = Params::getParam('yourEmail');
                $subject = Params::getParam('subject');
                $message = Params::getParam('message');
                if (osc_recaptcha_private_key() != '') {
                    if (!osc_check_recaptcha()) {
                        osc_add_flash_error_message(_m('The Recaptcha code is wrong'));
                        Session::newInstance()->_setForm('yourName', $yourName);
                        Session::newInstance()->_setForm('yourEmail', $yourEmail);
                        Session::newInstance()->_setForm('subject', $subject);
                        Session::newInstance()->_setForm('message_body', $message);
                        $this->redirectTo(osc_contact_url());
                        return false;
                        // BREAK THE PROCESS, THE RECAPTCHA IS WRONG
                    }
                }
                $banned = osc_is_banned($yourEmail);
                if ($banned == 1) {
                    osc_add_flash_error_message(_m('Your current email is not allowed'));
                    $this->redirectTo(osc_contact_url());
                } else {
                    if ($banned == 2) {
                        osc_add_flash_error_message(_m('Your current IP is not allowed'));
                        $this->redirectTo(osc_contact_url());
                    }
                }
                $user = User::newInstance()->newInstance()->findByEmail($yourEmail);
                if (isset($user['b_active']) && ($user['b_active'] == 0 || $user['b_enabled'] == 0)) {
                    osc_add_flash_error_message(_m('Your current email is not allowed'));
                    $this->redirectTo(osc_contact_url());
                }
                if (!preg_match('|.*?@.{2,}\\..{2,}|', $yourEmail)) {
                    osc_add_flash_error_message(_m('Please enter a correct email'));
                    Session::newInstance()->_setForm('yourName', $yourName);
                    Session::newInstance()->_setForm('subject', $subject);
                    Session::newInstance()->_setForm('message_body', $message);
                    $this->redirectTo(osc_contact_url());
                }
                $message_name = sprintf(__('Name: %s'), $yourName);
                $message_email = sprintf(__('Email: %s'), $yourEmail);
                $message_subject = sprintf(__('Subject: %s'), $subject);
                $message_body = sprintf(__('Message: %s'), $message);
                $message_date = sprintf(__('Date: %s at %s'), date('l F d, Y'), date('g:i a'));
                $message_IP = sprintf(__('IP Address: %s'), get_ip());
                $message = <<<MESSAGE
{$message_name}
{$message_email}
{$message_subject}
{$message_body}

{$message_date}
{$message_IP}
MESSAGE;
                $params = array('from' => osc_contact_email(), 'to' => osc_contact_email(), 'to_name' => osc_page_title(), 'reply_to' => $yourEmail, 'subject' => '[' . osc_page_title() . '] ' . __('Contact'), 'body' => nl2br($message));
                $error = false;
                if (osc_contact_attachment()) {
                    $attachment = Params::getFiles('attachment');
                    if (isset($attachment['error']) && $attachment['error'] == UPLOAD_ERR_OK) {
                        $mime_array = array('text/php', 'text/x-php', 'application/php', 'application/x-php', 'application/x-httpd-php', 'application/x-httpd-php-source', 'application/x-javascript');
                        $resourceName = $attachment['name'];
                        $tmpName = $attachment['tmp_name'];
                        $resourceType = $attachment['type'];
                        if (function_exists('mime_content_type')) {
                            $resourceType = mime_content_type($tmpName);
                        }
                        if (function_exists('finfo_open')) {
                            $finfo = finfo_open(FILEINFO_MIME);
                            $output = finfo_file($finfo, $tmpName);
                            finfo_close($finfo);
                            $output = explode("; ", $output);
                            if (is_array($output)) {
                                $output = $output[0];
                            }
                            $resourceType = $output;
                        }
                        // check mime file
                        if (!in_array($resourceType, $mime_array)) {
                            $emailAttachment = array('path' => $tmpName, 'name' => $resourceName);
                            $error = false;
                        } else {
                            $error = true;
                        }
                        // --- check mime file
                    } else {
                        $error = true;
                    }
                }
                if (!$error) {
                    if (isset($emailAttachment)) {
                        $params['attachment'] = $emailAttachment;
                    }
                    osc_run_hook('pre_contact_post', $params);
                    osc_sendMail(osc_apply_filter('contact_params', $params));
                    if (isset($tmpName)) {
                        @unlink($tmpName);
                    }
                    osc_add_flash_ok_message(_m('Your email has been sent properly. Thank you for contacting us!'));
                } else {
                    osc_add_flash_error_message(_m('The file you tried to upload does not have a valid extension'));
                }
                $this->redirectTo(osc_contact_url());
                break;
            default:
                //contact
                $this->doView('contact.php');
        }
    }
Exemplo n.º 26
0
 function doModel()
 {
     switch ($this->action) {
         case 'import':
             // calling import view
             $this->doView('tools/import.php');
             break;
         case 'import_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             }
             // calling
             $sql = Params::getFiles('sql');
             if (isset($sql['size']) && $sql['size'] != 0) {
                 $content_file = file_get_contents($sql['tmp_name']);
                 $conn = DBConnectionClass::newInstance();
                 $c_db = $conn->getOsclassDb();
                 $comm = new DBCommandClass($c_db);
                 if ($comm->importSQL($content_file)) {
                     osc_add_flash_ok_message(_m('Import complete'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin');
                 }
             } else {
                 osc_add_flash_error_message(_m('No file was uploaded'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import');
             break;
         case 'images':
             // calling images view
             $this->doView('tools/images.php');
             break;
         case 'images_post':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images');
             }
             $preferences = Preference::newInstance()->toArray();
             $wat = new Watermark();
             $aResources = ItemResource::newInstance()->getAllResources();
             foreach ($aResources as $resource) {
                 osc_run_hook('regenerate_image', $resource);
                 $path = osc_content_path() . 'uploads/';
                 // comprobar que no haya original
                 $img_original = $path . $resource['pk_i_id'] . "_original*";
                 $aImages = glob($img_original);
                 // there is original image
                 if (count($aImages) == 1) {
                     $image_tmp = $aImages[0];
                 } else {
                     $img_normal = $path . $resource['pk_i_id'] . ".*";
                     $aImages = glob($img_normal);
                     if (count($aImages) == 1) {
                         $image_tmp = $aImages[0];
                     } else {
                         $img_thumbnail = $path . $resource['pk_i_id'] . "_thumbnail*";
                         $aImages = glob($img_thumbnail);
                         $image_tmp = $aImages[0];
                     }
                 }
                 // extension
                 preg_match('/\\.(.*)$/', $image_tmp, $matches);
                 if (isset($matches[1])) {
                     $extension = $matches[1];
                     // Create normal size
                     $path_normal = $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '.jpg';
                     $size = explode('x', osc_normal_dimensions());
                     ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1])->saveToFile($path);
                     if (osc_is_watermark_text()) {
                         $wat->doWatermarkText($path, osc_watermark_text_color(), osc_watermark_text(), 'image/jpeg');
                     } elseif (osc_is_watermark_image()) {
                         $wat->doWatermarkImage($path, 'image/jpeg');
                     }
                     // Create preview
                     $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_preview.jpg';
                     $size = explode('x', osc_preview_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     // Create thumbnail
                     $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_thumbnail.jpg';
                     $size = explode('x', osc_thumbnail_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     // update resource info
                     ItemResource::newInstance()->update(array('s_path' => 'oc-content/uploads/', 's_name' => osc_genRandomPassword(), 's_extension' => 'jpg', 's_content_type' => 'image/jpeg'), array('pk_i_id' => $resource['pk_i_id']));
                     osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id']));
                     // si extension es direfente a jpg, eliminar las imagenes con $extension si hay
                     if ($extension != 'jpg') {
                         $files_to_remove = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . "*" . $extension;
                         $fs = glob($files_to_remove);
                         if (is_array($fs)) {
                             array_map("unlink", $fs);
                         }
                     }
                     // ....
                 } else {
                     // no es imagen o imagen sin extesión
                 }
             }
             osc_add_flash_ok_message(_m('Re-generation complete'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images');
             break;
         case 'upgrade':
             $this->doView('tools/upgrade.php');
             break;
         case 'backup':
             $this->doView('tools/backup.php');
             break;
         case 'backup-sql':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //databasse dump...
             if (Params::getParam('bck_dir') != '') {
                 $path = trim(Params::getParam('bck_dir'));
                 if (substr($path, -1, 1) != "/") {
                     $path .= '/';
                 }
             } else {
                 $path = osc_base_path();
             }
             $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql';
             switch (osc_dbdump($path, $filename)) {
                 case -1:
                     $msg = _m('Path is empty');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -2:
                     $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -3:
                     $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error());
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -4:
                     $msg = _m('There are no tables to back up');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 case -5:
                     $msg = _m('The folder is not writable');
                     osc_add_flash_error_message($msg, 'admin');
                     break;
                 default:
                     $msg = _m('Backup has been done properly');
                     osc_add_flash_ok_message($msg, 'admin');
                     break;
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup-zip':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             }
             //zip of the code just to back it up
             if (Params::getParam('bck_dir') != '') {
                 $archive_name = trim(Params::getParam('bck_dir'));
                 if (substr(trim($archive_name), -1, 1) != "/") {
                     $archive_name .= '/';
                 }
                 $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip';
             } else {
                 $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip";
             }
             $archive_folder = osc_base_path();
             if (osc_zip_folder($archive_folder, $archive_name)) {
                 $msg = _m('Archiving successful!');
                 osc_add_flash_ok_message($msg, 'admin');
             } else {
                 $msg = _m('Error, the zip file was not created at the specified directory');
                 osc_add_flash_error_message($msg, 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup');
             break;
         case 'backup_post':
             $this->doView('tools/backup.php');
             break;
         case 'maintenance':
             if (defined('DEMO')) {
                 osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin');
                 $this->doView('tools/maintenance.php');
                 break;
             }
             $mode = Params::getParam('mode');
             if ($mode == 'on') {
                 $maintenance_file = ABS_PATH . '.maintenance';
                 $fileHandler = @fopen($maintenance_file, 'w');
                 if ($fileHandler) {
                     osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m('There was an error creating .maintenance file, please create it manually at the root folder'), 'admin');
                 }
                 fclose($fileHandler);
                 $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
             } else {
                 if ($mode == 'off') {
                     $deleted = @unlink(ABS_PATH . '.maintenance');
                     if ($deleted) {
                         osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin');
                     } else {
                         osc_add_flash_error_message(_m('There was an error removing .maintenance file, please remove it manually from the root folder'), 'admin');
                     }
                     $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance');
                 }
             }
             $this->doView('tools/maintenance.php');
             break;
         default:
     }
 }
Exemplo n.º 27
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.º 28
0
 function doModel()
 {
     switch ($this->action) {
         case 'media':
             // calling the media view
             $max_upload = (int) ini_get('upload_max_filesize');
             $max_post = (int) ini_get('post_max_size');
             $memory_limit = (int) ini_get('memory_limit');
             $upload_mb = min($max_upload, $max_post, $memory_limit) * 1024;
             $this->_exportVariableToView('max_size_upload', $upload_mb);
             $this->doView('settings/media.php');
             break;
         case 'media_post':
             // updating the media config
             osc_csrf_check();
             $status = 'ok';
             $error = '';
             $iUpdated = 0;
             $maxSizeKb = Params::getParam('maxSizeKb');
             $dimThumbnail = strtolower(Params::getParam('dimThumbnail'));
             $dimPreview = strtolower(Params::getParam('dimPreview'));
             $dimNormal = strtolower(Params::getParam('dimNormal'));
             $keepOriginalImage = Params::getParam('keep_original_image');
             $forceAspectImage = Params::getParam('force_aspect_image');
             $forceJPEG = Params::getParam('force_jpeg');
             $use_imagick = Params::getParam('use_imagick');
             $type_watermark = Params::getParam('watermark_type');
             $watermark_color = Params::getParam('watermark_text_color');
             $watermark_text = Params::getParam('watermark_text');
             switch ($type_watermark) {
                 case 'none':
                     $iUpdated += osc_set_preference('watermark_text_color', '');
                     $iUpdated += osc_set_preference('watermark_text', '');
                     $iUpdated += osc_set_preference('watermark_image', '');
                     break;
                 case 'text':
                     $iUpdated += osc_set_preference('watermark_text_color', $watermark_color);
                     $iUpdated += osc_set_preference('watermark_text', $watermark_text);
                     $iUpdated += osc_set_preference('watermark_image', '');
                     $iUpdated += osc_set_preference('watermark_place', Params::getParam('watermark_text_place'));
                     break;
                 case 'image':
                     // upload image & move to path
                     $watermark_file = Params::getFiles('watermark_image');
                     if ($watermark_file['tmp_name'] != '' && $watermark_file['size'] > 0) {
                         if ($watermark_file['error'] == UPLOAD_ERR_OK) {
                             if ($watermark_file['type'] == 'image/png') {
                                 $tmpName = $watermark_file['tmp_name'];
                                 $path = osc_content_path() . 'uploads/watermark.png';
                                 if (move_uploaded_file($tmpName, $path)) {
                                     $iUpdated += osc_set_preference('watermark_image', $path);
                                 } else {
                                     $status = 'error';
                                     $error .= _m('There was a problem uploading the watermark image') . "<br />";
                                 }
                             } else {
                                 $status = 'error';
                                 $error .= _m('The watermark image has to be a .PNG file') . "<br />";
                             }
                         } else {
                             $status = 'error';
                             $error .= _m('There was a problem uploading the watermark image') . "<br />";
                         }
                     }
                     $iUpdated += osc_set_preference('watermark_text_color', '');
                     $iUpdated += osc_set_preference('watermark_text', '');
                     $iUpdated += osc_set_preference('watermark_place', Params::getParam('watermark_image_place'));
                     break;
                 default:
                     break;
             }
             // format parameters
             $maxSizeKb = trim(strip_tags($maxSizeKb));
             $dimThumbnail = trim(strip_tags($dimThumbnail));
             $dimPreview = trim(strip_tags($dimPreview));
             $dimNormal = trim(strip_tags($dimNormal));
             $keepOriginalImage = $keepOriginalImage != '' ? true : false;
             $forceAspectImage = $forceAspectImage != '' ? true : false;
             $forceJPEG = $forceJPEG != '' ? true : false;
             $use_imagick = $use_imagick != '' ? true : false;
             if (!preg_match('|([0-9]+)x([0-9]+)|', $dimThumbnail, $match)) {
                 $dimThumbnail = is_numeric($dimThumbnail) ? $dimThumbnail . "x" . $dimThumbnail : "100x100";
             }
             if (!preg_match('|([0-9]+)x([0-9]+)|', $dimPreview, $match)) {
                 $dimPreview = is_numeric($dimPreview) ? $dimPreview . "x" . $dimPreview : "100x100";
             }
             if (!preg_match('|([0-9]+)x([0-9]+)|', $dimNormal, $match)) {
                 $dimNormal = is_numeric($dimNormal) ? $dimNormal . "x" . $dimNormal : "100x100";
             }
             // is imagick extension loaded?
             if (!@extension_loaded('imagick')) {
                 $use_imagick = false;
             }
             // max size allowed by PHP configuration?
             $max_upload = (int) ini_get('upload_max_filesize');
             $max_post = (int) ini_get('post_max_size');
             $memory_limit = (int) ini_get('memory_limit');
             $upload_mb = min($max_upload, $max_post, $memory_limit) * 1024;
             // set maxSizeKB equals to PHP configuration if it's bigger
             if ($maxSizeKb > $upload_mb) {
                 $status = 'warning';
                 $maxSizeKb = $upload_mb;
                 // flash message text warning
                 $error .= sprintf(_m("You cannot set a maximum file size higher than the one allowed in the PHP configuration: <b>%d KB</b>"), $upload_mb);
             }
             $iUpdated += osc_set_preference('maxSizeKb', $maxSizeKb);
             $iUpdated += osc_set_preference('dimThumbnail', $dimThumbnail);
             $iUpdated += osc_set_preference('dimPreview', $dimPreview);
             $iUpdated += osc_set_preference('dimNormal', $dimNormal);
             $iUpdated += osc_set_preference('keep_original_image', $keepOriginalImage);
             $iUpdated += osc_set_preference('force_aspect_image', $forceAspectImage);
             $iUpdated += osc_set_preference('force_jpeg', $forceJPEG);
             $iUpdated += osc_set_preference('use_imagick', $use_imagick);
             if ($error != '') {
                 switch ($status) {
                     case 'error':
                         osc_add_flash_error_message($error, 'admin');
                         break;
                     case 'warning':
                         osc_add_flash_warning_message($error, 'admin');
                         break;
                     default:
                         osc_add_flash_ok_message($error, 'admin');
                         break;
                 }
             } else {
                 osc_add_flash_ok_message(_m('Media config has been updated'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=media');
             break;
         case 'images_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=settings&action=media');
             }
             osc_csrf_check();
             $aResources = ItemResource::newInstance()->getAllResources();
             foreach ($aResources as $resource) {
                 osc_run_hook('regenerate_image', $resource);
                 if (strpos($resource['s_content_type'], 'image') !== false) {
                     if (file_exists(osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "_original." . $resource['s_extension'])) {
                         $image_tmp = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "_original." . $resource['s_extension'];
                         $use_original = true;
                     } else {
                         if (file_exists(osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "." . $resource['s_extension'])) {
                             $image_tmp = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "." . $resource['s_extension'];
                             $use_original = false;
                         } else {
                             if (file_exists(osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "_preview." . $resource['s_extension'])) {
                                 $image_tmp = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . "_preview." . $resource['s_extension'];
                                 $use_original = false;
                             } else {
                                 $use_original = false;
                                 continue;
                             }
                         }
                     }
                     // Create normal size
                     $path_normal = $path = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . '.' . $resource['s_extension'];
                     $size = explode('x', osc_normal_dimensions());
                     $img = ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1]);
                     if ($use_original) {
                         if (osc_is_watermark_text()) {
                             $img->doWatermarkText(osc_watermark_text(), osc_watermark_text_color());
                         } elseif (osc_is_watermark_image()) {
                             $img->doWatermarkImage();
                         }
                     }
                     $img->saveToFile($path);
                     // Create preview
                     $path = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . '_preview.' . $resource['s_extension'];
                     $size = explode('x', osc_preview_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     // Create thumbnail
                     $path = osc_base_path() . $resource['s_path'] . $resource['pk_i_id'] . '_thumbnail.' . $resource['s_extension'];
                     $size = explode('x', osc_thumbnail_dimensions());
                     ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path);
                     osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id']));
                 } else {
                     // no es imagen o imagen sin extesión
                 }
             }
             osc_add_flash_ok_message(_m('Re-generation complete'), 'admin');
             $this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=media');
             break;
     }
 }
Exemplo n.º 29
0
        /**
         * Return an array with all data necessary for do the action (ADD OR EDIT)
         * @param <type> $is_add
         * @return array
         */
        public function prepareData( $is_add )
        {
            $aItem = array();
            $data = array();

            $userId = null;
            if( $this->is_admin ) {
                // user
                $data   = User::newInstance()->findByEmail(Params::getParam('contactEmail'));
                if( isset($data['pk_i_id']) && is_numeric($data['pk_i_id']) ) {
                    $userId = $data['pk_i_id'];
                }
            } else {
                $userId = Session::newInstance()->_get('userId');
                if( $userId == '' ) {
                    $userId = NULL;
                } elseif ($userId != NULL) {
                    $data   = User::newInstance()->findByPrimaryKey( $userId );
                }
            }

            if( $userId != null ) {
                $aItem['contactName']   = $data['s_name'];
                $aItem['contactEmail']  = $data['s_email'];
                Params::setParam('contactName', $data['s_name']);
                Params::setParam('contactEmail', $data['s_email']);
            } else {
                $aItem['contactName']   = Params::getParam('contactName');
                $aItem['contactEmail']  = Params::getParam('contactEmail');
            }
            $aItem['userId']        = $userId;

            if( $is_add ) {   // ADD
                if($this->is_admin) {
                    $active = 'ACTIVE';
                } else {
                    if(osc_moderate_items()>0) { // HAS TO VALIDATE
                        if(!osc_is_web_user_logged_in()) { // NO USER IS LOGGED, VALIDATE
                            $active = 'INACTIVE';
                        } else { // USER IS LOGGED
                            if(osc_logged_user_item_validation()) { //USER IS LOGGED, BUT NO NEED TO VALIDATE
                                $active = 'ACTIVE';
                            } else { // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS
                                $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
                                if($user['i_items']<osc_moderate_items()) {
                                    $active = 'INACTIVE';
                                } else {
                                    $active = 'ACTIVE';
                                }
                            }
                        }
                    } else if(osc_moderate_items()==0 ){
                        if(osc_is_web_user_logged_in() && osc_logged_user_item_validation() ) {
                            $active = 'ACTIVE';
                        } else {
                            $active = 'INACTIVE';
                        }
                    } else {
                        $active = 'ACTIVE';
                    }
                }
                $aItem['active']        = $active;
            } else {          // EDIT
                $aItem['secret']    = Params::getParam('secret');
                $aItem['idItem']    = Params::getParam('id');
            }

            // get params
            $aItem['catId']         = Params::getParam('catId');
            $aItem['countryId']     = Params::getParam('countryId');
            $aItem['country']       = Params::getParam('country');
            $aItem['region']        = Params::getParam('region');
            $aItem['regionId']      = Params::getParam('regionId');
            $aItem['city']          = Params::getParam('city');
            $aItem['cityId']        = Params::getParam('cityId');
            $aItem['price']         = (Params::getParam('price') != '') ? Params::getParam('price') : null;
            $aItem['cityArea']      = Params::getParam('cityArea');
            $aItem['address']       = Params::getParam('address');
            $aItem['currency']      = Params::getParam('currency');
            $aItem['showEmail']     = (Params::getParam('showEmail') != '') ? 1 : 0;
            $aItem['title']         = Params::getParam('title');
            $aItem['description']   = Params::getParam('description');
            $aItem['photos']        = Params::getFiles('photos');
            $ajax_photos            = Params::getParam('ajax_photos');
            $aItem['s_ip']          = get_ip();
            $aItem['d_coord_lat']   = (Params::getParam('d_coord_lat')  != '') ? Params::getParam('d_coord_lat') : null;
            $aItem['d_coord_long']  = (Params::getParam('d_coord_long') != '') ? Params::getParam('d_coord_long') : null;
            $aItem['s_zip']         = (Params::getParam('zip')  != '') ? Params::getParam('zip') : null;

            // $ajax_photos is an array of filenames of the photos uploaded by ajax to a temporary folder
            // fake insert them into the array of the form-uploaded photos
            if(is_array($ajax_photos)) {
                foreach($ajax_photos as $photo) {
                    if(file_exists(osc_content_path().'uploads/temp/'.$photo)) {
                        $aItem['photos']['name'][]      = $photo;
                        $aItem['photos']['type'][]      = 'image/*';
                        $aItem['photos']['tmp_name'][]  = osc_content_path().'uploads/temp/'.$photo;
                        $aItem['photos']['error'][]     = UPLOAD_ERR_OK;
                        $aItem['photos']['size'][]      = 0;
                    }
                }
            }

            if($is_add || $this->is_admin) {
                $dt_expiration = Params::getParam('dt_expiration');
                if($dt_expiration==-1) {
                    $aItem['dt_expiration'] = '';
                } else if($dt_expiration!='' && (preg_match('|^([0-9]+)$|', $dt_expiration, $match) || preg_match('|([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})|', $dt_expiration, $match))) {
                    $aItem['dt_expiration'] = $dt_expiration;
                } else {
                    $_category = Category::newInstance()->findByPrimaryKey($aItem['catId']);
                    $aItem['dt_expiration'] = $_category['i_expiration_days'];
                }
                unset($dt_expiration);
            } else {
                $aItem['dt_expiration'] = '';
            };

            // check params
            $country = Country::newInstance()->findByCode($aItem['countryId']);
            if( count($country) > 0 ) {
                $countryId = $country['pk_c_code'];
                $countryName = $country['s_name'];
            } else {
                $countryId = null;
                $countryName = $aItem['country'];
            }
            $aItem['countryId']   = $countryId;
            $aItem['countryName']   = $countryName;

            if( $aItem['regionId'] != '' ) {
                if( intval($aItem['regionId']) ) {
                    $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']);
                    if( count($region) > 0 ) {
                        $regionId = $region['pk_i_id'];
                        $regionName = $region['s_name'];
                    }
                }
            } else {
                $regionId = null;
                $regionName = $aItem['region'];
                if( $aItem['countryId'] != '' ) {
                    $auxRegion  = Region::newInstance()->findByName($aItem['region'], $aItem['countryId'] );
                    if($auxRegion){
                        $regionId   = $auxRegion['pk_i_id'];
                        $regionName = $auxRegion['s_name'];
                    }
                }
            }

            $aItem['regionId']      = $regionId;
            $aItem['regionName']    = $regionName;

            if( $aItem['cityId'] != '' ) {
                if( intval($aItem['cityId']) ) {
                    $city = City::newInstance()->findByPrimaryKey($aItem['cityId']);
                    if( count($city) > 0 ) {
                        $cityId = $city['pk_i_id'];
                        $cityName = $city['s_name'];
                    }
                }
            } else {
                $cityId = null;
                $cityName = $aItem['city'];
                if( $aItem['countryId'] != '' ) {
                    $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId'] );
                    if($auxCity){
                        $cityId   = $auxCity['pk_i_id'];
                        $cityName = $auxCity['s_name'];
                    }
                }
            }

            $aItem['cityId']      = $cityId;
            $aItem['cityName']    = $cityName;

            if( $aItem['cityArea'] == '' ) {
                $aItem['cityArea'] = null;
            }

            if( $aItem['address'] == '' ) {
                $aItem['address'] = null;
            }

            if( !is_null($aItem['price']) ) {
                $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price']));
                $price = str_replace(osc_locale_dec_point(), '.', $price);
                $aItem['price'] = $price*1000000;
                //$aItem['price'] = (float) $aItem['price'];
            }

            if( $aItem['catId'] == ''){
                $aItem['catId'] = 0;
            }

            if( $aItem['currency'] == '' ) {
                $aItem['currency'] = null;
            }

            $this->data = $aItem;
        }
Exemplo n.º 30
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;
     }
 }