<?php
/*
 * Copyright (c) 2014-2015 Aimy Extensions, Lingua-Systems Software GmbH
 *
 * http://www.aimy-extensions.com/
 *
 * License: GNU GPLv2, see LICENSE.txt within distribution and/or
 *          http://www.aimy-extensions.com/software-license.html
 */
 defined( '_JEXEC' ) or die(); require_once( JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'rights.php' ); require_once( JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'message.php' ); jimport( 'joomla.filesystem.file' ); class AimySitemapViewRobotsTxt extends JViewLegacy { protected $allow_save = false; protected $allow_config = false; protected $robotstxt = null; protected $robotstxt_default = null; public function display( $tpl = null ) { if ( count( $errors = $this->get( 'Errors' ) ) ) { JError::raiseError( 500, implode( "\n", $errors ) ); return false; } $rights = AimySitemapRightsHelper::getRights(); $this->allow_save = $rights->get( 'aimysitemap.write' ); $this->allow_config = $rights->get( 'core.admin' ); $this->read_robots_txt_default( JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'default-robots.txt' ); $this->read_robots_txt( JPATH_ROOT . DIRECTORY_SEPARATOR . 'robots.txt' ); $this->addToolbar(); parent::display( $tpl ); } protected function addToolbar() { $bar = JToolBar::getInstance( 'toolbar' ); JToolBarHelper::title( JText::_( 'AIMY_SM_ROBOTSTXT' ), '' ); if ( $this->allow_save ) { JToolBarHelper::custom( 'robotstxt.save', 'file', '', JText::_( 'JAPPLY' ), false ); JToolBarHelper::custom( 'robotstxt.load_default', 'puzzle', '', JText::_( 'AIMY_SM_ROBOTSTXT_LOAD_DEFAULT_LBL' ), false ); } if ( $this->allow_config ) { JToolBarHelper::preferences( 'com_aimysitemap' ); } } private function read_robots_txt_default( $path ) { $this->robotstxt_default = @file_get_contents( $path ); if ( $this->robotstxt_default === false ) { $this->robotstxt_default = ''; } } private function read_robots_txt( $path ) { $msg = new AimySitemapMessageHelper(); if ( JFile::exists( $path ) ) { $this->robotstxt = @file_get_contents( $path ); if ( $this->robotstxt === false ) { $msg->error( JText::_( 'AIMY_SM_ROBOTSTXT_FAILED_TO_READ' ) ); $this->robotstxt = ''; } } else { $msg->message( JText::_( 'AIMY_SM_ROBOTSTXT_DOES_NOT_EXIST' ) ); $msg->message( JText::_( 'AIMY_SM_ROBOTSTXT_LOADING_DEFAULT' ) ); $this->robotstxt = @file_get_contents( JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'default-robots.txt' ); if ( $this->robotstxt === false ) { $msg->error( JText::_( 'AIMY_SM_ROBOTSTXT_LOADING_DEFAULT_FAILED' ) ); $this->robotstxt = ''; } } } } 
