예제 #1
0
 public function addInDB()
 {
     $cms = new CMS();
     foreach (Language::getLanguages() as $lang) {
         $cms->meta_title[$lang['id_lang']] = $this->title;
         $cms->meta_description[$lang['id_lang']] = $this->title;
         $cms->meta_keywords[$lang['id_lang']] = '';
         $cms->content[$lang['id_lang']] = $this->content;
         $cms->link_rewrite[$lang['id_lang']] = pSQL(preg_replace('/-(-)+/', '', preg_replace('/([^a-z\\-])+/', '', str_replace(' ', '-', Tools::strtolower($this->title)))));
     }
     $cms->id_cms_category = 1;
     $cms->indexation = 1;
     $cms->active = 1;
     $cms->add();
 }
예제 #2
0
 public function postProcess()
 {
     $this->_errors = array();
     // Generelle Einstellungen
     if (Tools::isSubmit('submitSaveOptions')) {
         // Global Settings
         if (!Configuration::updateGlobalValue('PS_EU_PAYMENT_API', (bool) Tools::getValue('PS_EU_PAYMENT_API'))) {
             $this->_errors[] = $this->l('Could not update') . ': PS_EU_PAYMENT_API';
         }
         $values = array();
         foreach ($this->languages as $language) {
             $values[$language['id_lang']] = Tools::getValue('SHOPPING_CART_TEXT_BEFORE_' . $language['id_lang']);
         }
         if (!Configuration::updateValue('SHOPPING_CART_TEXT_BEFORE', $values)) {
             $this->_errors[] = $this->l('Could not update') . ': SHOPPING_CART_TEXT_BEFORE';
         }
         $values = array();
         foreach ($this->languages as $language) {
             $values[$language['id_lang']] = Tools::getValue('SHOPPING_CART_TEXT_AFTER_' . $language['id_lang']);
         }
         if (!Configuration::updateValue('SHOPPING_CART_TEXT_AFTER', $values)) {
             $this->_errors[] = $this->l('Could not update') . ': SHOPPING_CART_TEXT_AFTER';
         }
         if (!Configuration::updateValue('LEGAL_SHIPTAXMETH', (bool) Tools::getValue('LEGAL_SHIPTAXMETH'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_SHIPTAXMETH';
         }
         // Produktverfügbarkeit
         $values = array();
         foreach ($this->languages as $language) {
             $values[$language['id_lang']] = Tools::getValue('LEGAL_DELIVERY_NOW_' . $language['id_lang']);
         }
         if (!Configuration::updateValue('LEGAL_DELIVERY_NOW', $values)) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_DELIVERY_NOW';
         }
         $values = array();
         foreach ($this->languages as $language) {
             $values[$language['id_lang']] = Tools::getValue('LEGAL_DELIVERY_LATER_' . $language['id_lang']);
         }
         if (!Configuration::updateValue('LEGAL_DELIVERY_LATER', $values)) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_DELIVERY_LATER';
         }
         if (!Configuration::updateValue('LEGAL_SHOW_WEIGHTS', (bool) Tools::getValue('LEGAL_SHOW_WEIGHTS'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_SHOW_WEIGHTS';
         }
         if (!Configuration::updateValue('LEGAL_SHOW_FANCY', (bool) Tools::getValue('LEGAL_SHOW_FANCY'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_SHOW_FANCY';
         }
         // CMS IDs festlegen
         if (!Configuration::updateValue('LEGAL_CMS_ID_LEGAL', (int) Tools::getValue('LEGAL_CMS_ID_LEGAL'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_LEGAL';
         }
         if (!Configuration::updateValue('PS_CONDITIONS_CMS_ID', (int) Tools::getValue('PS_CONDITIONS_CMS_ID'))) {
             $this->_errors[] = $this->l('Could not update') . ': PS_CONDITIONS_CMS_ID';
         }
         if (!Configuration::updateValue('LEGAL_CMS_ID_REVOCATION', (int) Tools::getValue('LEGAL_CMS_ID_REVOCATION'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_REVOCATION';
         }
         if (!Configuration::updateValue('LEGAL_CMS_ID_REVOCATIONFORM', (int) Tools::getValue('LEGAL_CMS_ID_REVOCATIONFORM'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_REVOCATIONFORM';
         }
         if (!Configuration::updateValue('LEGAL_CMS_ID_PRIVACY', (int) Tools::getValue('LEGAL_CMS_ID_PRIVACY'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_PRIVACY';
         }
         if (!Configuration::updateValue('LEGAL_CMS_ID_ENVIRONMENTAL', (int) Tools::getValue('LEGAL_CMS_ID_ENVIRONMENTAL'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_ENVIRONMENTAL';
         }
         if (!Configuration::updateValue('LEGAL_CMS_ID_SHIPPING', (int) Tools::getValue('LEGAL_CMS_ID_SHIPPING'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CMS_ID_SHIPPING';
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('Settings updated'));
         }
     } elseif (Tools::isSubmit('submitAddCMSPages')) {
         // install all cms pages
         foreach ($this->cms_pages as $cms_page) {
             if ($content = @Tools::file_get_contents($this->local_path . 'cms/' . $cms_page['name'] . '.txt')) {
                 $cms = new CMS();
                 $cms->active = true;
                 $cms->id_cms_category = 1;
                 $content = preg_replace('#src="(.*)"#u', 'src="' . Context::getContext()->shop->getBaseURL() . '\\1"', $content);
                 foreach ($this->languages as $language) {
                     $cms->meta_title[$language['id_lang']] = $cms_page['title'];
                     $cms->meta_description[$language['id_lang']] = $cms_page['title'];
                     $cms->meta_keywords[$language['id_lang']] = $cms_page['title'];
                     $cms->link_rewrite[$language['id_lang']] = Tools::link_rewrite($cms_page['title']);
                     $cms->content[$language['id_lang']] = trim($content);
                 }
                 if (!$cms->add()) {
                     $this->_errors[] = $this->l('Could not add new cms page') . ': ' . $cms_page['name'];
                 }
                 Configuration::updateValue($cms_page['config'], $cms->id);
                 $_POST[$cms_page['config']] = $cms->id;
             } else {
                 $this->_errors[] = $this->l('Could not open file') . ': cms/' . $cms_page['name'] . '.txt';
             }
         }
         // copy cms images
         try {
             $this->rcopy('modules/' . $this->name . '/img/cms/', 'img/cms/', array('root' => _PS_ROOT_DIR_));
         } catch (Exception $e) {
             $this->_errors[] = $this->l('Could not copy') . ': /img/cms/';
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('CMS Pages created'));
         }
     } elseif (Tools::isSubmit('submitSaveMail')) {
         if (!($theme = Tools::getValue('theme'))) {
             $this->_errors[] = $this->l('Please select a theme.');
         } else {
             if (!is_dir(_PS_ALL_THEMES_DIR_ . $theme . '/mails/') && !mkdir(_PS_ALL_THEMES_DIR_ . $theme . '/mails/', 0755, true)) {
                 $this->_errors[] = $this->l('Could not create mail dir.');
             } else {
                 try {
                     $this->rcopy('modules/' . $this->name . '/mails/', 'themes/' . $theme . '/mails/', array('root' => _PS_ROOT_DIR_));
                 } catch (Exception $e) {
                     $this->_errors[] = $this->l('Could not copy') . ': modules/' . $this->name . '/mails/';
                 }
             }
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('Mails saved'));
         }
     } elseif (Tools::isSubmit('submitSavePdf')) {
         if (!($theme = Tools::getValue('theme'))) {
             $this->_errors[] = $this->l('Please select a theme.');
         } else {
             if (!is_dir(_PS_ALL_THEMES_DIR_ . $theme . '/pdf/') && !mkdir(_PS_ALL_THEMES_DIR_ . $theme . '/pdf/', 0755, true)) {
                 $this->_errors[] = $this->l('Could not create pdf dir.');
             } else {
                 try {
                     $this->rcopy('modules/' . $this->name . '/pdf/', 'themes/' . $theme . '/pdf/', array('root' => _PS_ROOT_DIR_));
                 } catch (Exception $e) {
                     $this->_errors[] = $this->l('Could not copy') . ': modules/' . $this->name . '/pdf/';
                 }
             }
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('PDF files were saved'));
         }
     } elseif (Tools::isSubmit('submitSaveTheme')) {
         if (!Configuration::updateValue('LEGAL_CSS', (bool) Tools::getValue('LEGAL_CSS'))) {
             $this->_errors[] = $this->l('Could not update') . ': LEGAL_CSS';
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('Theme settings saved'));
         }
     } elseif (Tools::isSubmit('submitAddModules')) {
         $modules = Tools::getValue('modules');
         $dir = dirname(__FILE__) . '/modules/';
         foreach ($modules as $module) {
             if (!Tools::ZipExtract($dir . $module . '.zip', _PS_MODULE_DIR_)) {
                 $this->_errors[] = $this->l('Could not extract file') . ': ' . $module . '.zip';
                 continue;
             }
             if (!($instance = self::getInstanceByName($module))) {
                 $this->_errors[] = $this->l('Could not instance module') . ': ' . $module;
                 continue;
             }
             if (self::isInstalled($instance->name)) {
                 if ($instance->uninstall()) {
                     $instance->install();
                 }
             } elseif (!$instance->install()) {
                 if (is_array($instance->_errors)) {
                     $this->_errors = array_merge($this->_errors, $instance->_errors);
                 }
             }
             Cache::clean('Module::isInstalled' . $module);
             Cache::clean('Module::getModuleIdByName_' . $module);
             Cache::clean('Module::isEnabled' . $module);
         }
         if (count($this->_errors) <= 0) {
             return $this->displayConfirmation($this->l('Modules installed'));
         }
     }
     if (!empty($this->_errors)) {
         return $this->displayError(implode('<br>', $this->_errors));
     }
     return '';
 }
 public function generateAndLinkCMSPages()
 {
     $cms_pages = array(self::LEGAL_NOTICE => array('meta_title' => $this->l('Legal notice', 'ps_legalcompliance'), 'link_rewrite' => 'legal-notice', 'content' => $this->l('Please add your legal information to this site.', 'ps_legalcompliance')), self::LEGAL_CONDITIONS => array('meta_title' => $this->l('Terms of Service (ToS)', 'ps_legalcompliance'), 'link_rewrite' => 'terms-of-service-tos', 'content' => $this->l('Please add your Terms of Service (ToS) to this site.', 'ps_legalcompliance')), self::LEGAL_REVOCATION => array('meta_title' => $this->l('Revocation terms', 'ps_legalcompliance'), 'link_rewrite' => 'revocation-terms', 'content' => $this->l('Please add your Revocation terms to this site.', 'ps_legalcompliance')), self::LEGAL_PRIVACY => array('meta_title' => $this->l('Privacy', 'ps_legalcompliance'), 'link_rewrite' => 'privacy', 'content' => $this->l('Please insert here your content about privacy. If you have activated Social Media modules, please provide a notice about third-party access to data.', 'ps_legalcompliance')), self::LEGAL_SHIP_PAY => array('meta_title' => $this->l('Shipping and payment', 'ps_legalcompliance'), 'link_rewrite' => 'shipping-and-payment', 'content' => $this->l('Please add your Shipping and payment information to this site.', 'ps_legalcompliance')), self::LEGAL_ENVIRONMENTAL => array('meta_title' => $this->l('Environmental notice', 'ps_legalcompliance'), 'link_rewrite' => 'environmental-notice', 'content' => $this->l('Please add your Environmental information to this site.', 'ps_legalcompliance')));
     $cms_role_repository = $this->entity_manager->getRepository('CMSRole');
     $langs_repository = $this->entity_manager->getRepository('Language');
     $langs = $langs_repository->findAll();
     foreach ($cms_pages as $cms_page_role => $cms_page) {
         $cms_role = $cms_role_repository->findOneByName($cms_page_role);
         if ((int) $cms_role->id_cms == 0) {
             $cms = new CMS();
             $cms->id_cms_category = 1;
             foreach ($langs as $lang) {
                 $cms->meta_title[(int) $lang->id] = $cms_page['meta_title'];
                 $cms->link_rewrite[(int) $lang->id] = 'aeu-legal-' . $cms_page['link_rewrite'];
                 $cms->content[(int) $lang->id] = $cms_page['content'];
             }
             $cms->active = 1;
             $cms->add();
             $cms_role->id_cms = (int) $cms->id;
             $cms_role->update();
         }
     }
     return true;
 }
예제 #4
0
파일: cms_edit.php 프로젝트: yiuked/tmcart
<?php

if (Tools::P('saveCMS') == 'add') {
    $cms = new CMS();
    $cms->copyFromPost();
    if ($cms->add()) {
        if (!$cms->updateCategories($_POST['categoryBox']) or !$cms->updateTags($_POST['tags'])) {
            $cms->_errors = '添加CMS内容时发生了一个错误';
        }
    }
    if (is_array($cms->_errors) and count($cms->_errors) > 0) {
        $errors = $cms->_errors;
    } else {
        $_GET['id'] = $cms->id;
        UIAdminAlerts::conf('文章已添加');
    }
}
if (isset($_GET['id'])) {
    $id = (int) Tools::G('id');
    $obj = new CMS($id);
}
if (Tools::P('saveCMS') == 'edit') {
    if (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        if ($obj->update()) {
            if (!$obj->updateCategories($_POST['categoryBox']) or !$obj->updateTags($_POST['tags'])) {
                $obj->_errors = '更新CMS内容时发生了一个错误';
            }
        }
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
 protected function importCMS()
 {
     $new_path = new Sampledatainstall();
     $file = $new_path->sendPath() . 'input/cms_pages.csv';
     // do nothing if file is empty
     if (Tools::isEmpty(trim(file_get_contents($file)))) {
         return;
     }
     $this->truncateTables(array('cms', 'cms_lang', 'cms_shop'));
     $handle = $this->openCsvFile('cms_pages.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('CMS', $this->cms_pages_fields, $line);
         if (!isset($fields['id'])) {
             $cms = new CMS((int) $line[0]);
             $cms->id = $line[0];
         } else {
             $cms = new CMS((int) $fields['id']);
         }
         foreach ($fields as $key => $field) {
             if ($key == 'meta_title' || $key == 'meta_description' || $key == 'meta_keywords' || $key == 'content' || $key == 'link_rewrite') {
                 $cms->{$key} = $this->multilFild($field);
             } else {
                 $cms->{$key} = $field;
             }
         }
         $cms->force_id = true;
         if (!$res) {
             $cms->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }