name = 'editorial'; $this->tab = 'Tools'; $this->version = '1.5'; parent::__construct(); $this->displayName = $this->l('Home text editor'); $this->description = $this->l('A text editor module for your homepage'); } function install() { if (!parent::install()) return false; return $this->registerHook('home'); } function putContent($xml_data, $key, $field, $forbidden, $section) { foreach ($forbidden AS $line) if ($key == $line) return 0; if (!preg_match('/^'.$section.'_/i', $key)) return 0; $key = preg_replace('/^'.$section.'_/i', '', $key); $field = htmlspecialchars($field); if (!$field) return 0; return ("\n".' <'.$key.'>'.$field.''); } function getContent() { /* display the module name */ $this->_html = '

'.$this->displayName.'

'; $errors = ''; /* update the editorial xml */ if (isset($_POST['submitUpdate'])) { // Forbidden key $forbidden = array('submitUpdate'); foreach ($_POST AS $key => $value) if (!Validate::isString($_POST[$key])) { $this->_html .= $this->displayError($this->l('Invalid html field, javascript is forbidden')); $this->_displayForm(); return $this->_html; } // Generate new XML data $newXml = ''."\n"; $newXml .= ''."\n"; $newXml .= '
'; // Making header data foreach ($_POST AS $key => $field) if ($line = $this->putContent($newXml, $key, $field, $forbidden, 'header')) $newXml .= $line; $newXml .= "\n".'
'."\n"; $newXml .= ' '; // Making body data foreach ($_POST AS $key => $field) if ($line = $this->putContent($newXml, $key, $field, $forbidden, 'body')) $newXml .= $line; $newXml .= "\n".' '."\n"; $newXml .= '
'."\n"; /* write it into the editorial xml file */ if ($fd = @fopen(dirname(__FILE__).'/editorial.xml', 'w')) { if (!@fwrite($fd, $newXml)) $errors .= $this->displayError($this->l('Unable to write to the editor file.')); if (!@fclose($fd)) $errors .= $this->displayError($this->l('Can\'t close the editor file.')); } else $errors .= $this->displayError($this->l('Unable to update the editor file.
Please check the editor file\'s writing permissions.')); /* upload the image */ if (isset($_FILES['body_homepage_logo']) AND isset($_FILES['body_homepage_logo']['tmp_name']) AND !empty($_FILES['body_homepage_logo']['tmp_name'])) { Configuration::set('PS_IMAGE_GENERATION_METHOD', 1); if ($error = checkImage($_FILES['body_homepage_logo'], $this->maxImageSize)) $errors .= $error; elseif (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['body_homepage_logo']['tmp_name'], $tmpName)) return false; elseif (!imageResize($tmpName, dirname(__FILE__).'/homepage_logo.jpg')) $errors .= $this->displayError($this->l('An error occurred during the image upload.')); unlink($tmpName); } $this->_html .= $errors == '' ? $this->displayConfirmation('Settings updated successfully') : $errors; } /* display the editorial's form */ $this->_displayForm(); return $this->_html; } private function _displayForm() { global $cookie; /* Languages preliminaries */ $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $iso = Language::getIsoById(intval($cookie->id_lang)); $divLangName = 'title¤subheading¤cpara¤logo_subheading'; /* xml loading */ $xml = false; if (file_exists(dirname(__FILE__).'/editorial.xml')) if (!$xml = simplexml_load_file(dirname(__FILE__).'/editorial.xml')) $this->_html .= $this->displayError($this->l('Your editor file is empty.')); $this->_html .= '
'.$this->displayName.'
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'title', true); $this->_html .= '

'.$this->l('Appears along top of homepage').'

'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'subheading', true); $this->_html .= '
'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cpara', true); $this->_html .= '

'.$this->l('Text of your choice; for example, explain your mission, highlight a new product, or describe a recent event').'


'.$this->l('Will appear next to the Introductory Text above').'

'.$this->l('Link used on the 2nd logo').'

'; foreach ($languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'logo_subheading', true); $this->_html .= '
'; } function hookHome($params) { if (file_exists('modules/editorial/editorial.xml')) { if ($xml = simplexml_load_file('modules/editorial/editorial.xml')) { global $cookie, $smarty; $smarty->assign(array( 'xml' => $xml, 'homepage_logo' => file_exists('modules/editorial/homepage_logo.jpg'), 'logo_subheading' => 'logo_subheading_'.$cookie->id_lang, 'title' => 'title_'.$cookie->id_lang, 'subheading' => 'subheading_'.$cookie->id_lang, 'paragraph' => 'paragraph_'.$cookie->id_lang, 'this_path' => $this->_path )); return $this->display(__FILE__, 'editorial.tpl'); } } return false; } }