* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7665 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminGenerator extends AdminTab { public function __construct() { $this->_htFile = dirname(__FILE__).'/../../.htaccess'; $this->_rbFile = dirname(__FILE__).'/../../robots.txt'; $this->_smFile = dirname(__FILE__).'/../../sitemap.xml'; $this->_rbData = $this->_getRobotsContent(); return parent::__construct(); } public function display() { global $currentIndex; $languages = Language::getLanguages(false); // Htaccess echo '
'.$this->l('Htaccess file generation').'

'.$this->l('Warning:').' '.$this->l('this tool can ONLY be used if you are hosted by an Apache web server. Please ask your webhost.').'

'.$this->l('This tool will automatically generate a ".htaccess" file that will give you the ability to do URL rewriting and to catch 404 errors.').'

'.$this->l('If you do not have "Friendly URL" enabled when generating the ".htaccess" file, this feature won\'t be available.').'

'; if ($this->_checkConfiguration($this->_htFile)) echo '
 

'.$this->l('This will add directives to your .htaccess file which should improve caching and compression.').'

 

'.$this->l('Enable only if your server allows URL rewriting.').'

 

'.$this->l('Enable this option only if you have problems with some pages URL rewriting.').'

 

'.$this->l('Add here the specific directives of your host (SetEnv PHP_VER 5, AddType x-mapp-php5 .php...).').'

'.$this->l('Generate your ".htaccess" file by clicking on the following button:').'

'.$this->l('This will erase your').' '.$this->l('old').' '.$this->l('.htaccess file!').'

'; else echo '

'.$this->l('Before being able to use this tool, you need to:').'

'.$this->l('- create a').' '. $this->l('.htaccess').' '.$this->l('blank file in directory').' '.__PS_BASE_URI__.'
'.$this->l('- give it write permissions (CHMOD 666 on Unix system)').'

'; echo '

'; // Robots echo '

'.$this->l('Robots file generation').'

'.$this->l('Warning:').' '.$this->l('Your file robots.txt MUST be in your website\'s root directory and nowhere else.').'

'.$this->l('eg: http://www.yoursite.com/robots.txt').'.

'.$this->l('This tool will automatically generate a "robots.txt" file that you can configure to deny access to search engines for some pages.').'

'; if ($this->_checkConfiguration($this->_rbFile)) echo '

'.$this->l('Generate your "robots.txt" file by clicking on the following button:').'

'.$this->l('This will erase your').' '.$this->l('old').' '.$this->l('robots.txt file!').'

'; else echo '

'.$this->l('Before being able to use this tool, you need to:').'

'.$this->l('- create a').' '. $this->l('robots.txt').' '.$this->l('blank file in dir:').' '.__PS_BASE_URI__.'
'.$this->l('- give it write permissions (CHMOD 666 on Unix system)').'

'; echo '

'; } public function _checkConfiguration($file) { if (file_exists($file)) return is_writable($file); return is_writable(dirname($file)); } function postProcess() { global $currentIndex; if (Tools::isSubmit('submitHtaccess')) { if ($this->tabAccess['edit'] === '1') { Configuration::updateValue('PS_HTACCESS_CACHE_CONTROL', (int)Tools::getValue('PS_HTACCESS_CACHE_CONTROL')); Configuration::updateValue('PS_REWRITING_SETTINGS', (int)Tools::getValue('PS_REWRITING_SETTINGS')); Configuration::updateValue('PS_HTACCESS_DISABLE_MULTIVIEWS', (int)Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS')); Configuration::updateValue('PS_HTACCESS_SPECIFIC', Tools::getValue('ps_htaccess_specific'), true); if (Tools::generateHtaccess($this->_htFile, Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), Tools::getValue('ps_htaccess_specific'), Tools::getValue('PS_HTACCESS_DISABLE_MULTIVIEWS'))) Tools::redirectAdmin($currentIndex.'&conf=4&token='.$this->token); $this->_errors[] = $this->l('Cannot write into file:').' '.$this->_htFile.'
'.$this->l('Please check write permissions.'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } if (Tools::isSubmit('submitRobots')) { if ($this->tabAccess['edit'] === '1') { if (!$writeFd = @fopen($this->_rbFile, 'w')) die ($this->l('Cannot write into file:').' '.$this->_rbFile.'
'.$this->l('Please check write permissions.')); else { // PS Comments fwrite($writeFd, "# robots.txt automaticaly generated by PrestaShop e-commerce open-source solution\n"); fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n"); fwrite($writeFd, "# This file is to prevent the crawling and indexing of certain parts\n"); fwrite($writeFd, "# of your site by web crawlers and spiders run by sites like Yahoo!\n"); fwrite($writeFd, "# and Google. By telling these \"robots\" where not to go on your site,\n"); fwrite($writeFd, "# you save bandwidth and server resources.\n\n"); fwrite($writeFd, "# For more information about the robots.txt standard, see:\n"); fwrite($writeFd, "# http://www.robotstxt.org/wc/robots.html\n\n"); // User-Agent fwrite($writeFd, "User-agent: *\n"); // Directories fwrite($writeFd, "# Directories\n"); foreach ($this->_rbData['Directories'] as $dir) fwrite($writeFd, 'Disallow: '.__PS_BASE_URI__.$dir."\n"); // Files fwrite($writeFd, "# Files\n"); foreach ($this->_rbData['Files'] as $file) fwrite($writeFd, 'Disallow: '.__PS_BASE_URI__.$file."\n"); // Sitemap fwrite($writeFd, "# Sitemap\n"); if (file_exists($this->_smFile)) if (filesize($this->_smFile)) fwrite($writeFd, 'Sitemap: '.(Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://').$_SERVER['SERVER_NAME'].__PS_BASE_URI__.'sitemap.xml'."\n"); fwrite($writeFd, "\n"); fclose($writeFd); Tools::redirectAdmin($currentIndex.'&conf=4&token='.$this->token); } } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } public function _getRobotsContent() { $tab = array(); // Directories $tab['Directories'] = array('classes/', 'config/', 'download/', 'mails/', 'modules/', 'translations/', 'tools/', 'lang-'.Language::getIsoById(Configuration::get('PS_LANG_DEFAULT')).'/'); // Files $tab['Files'] = array('addresses.php', 'address.php', 'authentication.php', 'cart.php', 'discount.php', 'footer.php', 'get-file.php', 'header.php', 'history.php', 'identity.php', 'images.inc.php', 'init.php', 'my-account.php', 'order.php', 'order-opc.php', 'order-slip.php', 'order-detail.php', 'order-follow.php', 'order-return.php', 'order-confirmation.php', 'pagination.php', 'password.php', 'pdf-invoice.php', 'pdf-order-return.php', 'pdf-order-slip.php', 'product-sort.php', 'search.php', 'statistics.php','attachment.php', 'guest-tracking', '*orderby=','*orderway=','*tag=','*id_currency=','*search_query=','*id_lang=','*back=','*utm_source=','*utm_medium=','*utm_campaign=','*n='); return $tab; } }