Файловый менеджер - Редактировать - /var/www/html/administrator/components/com_community/controllers/templates.php
Ðазад
<?php /** * @copyright (C) 2013 iJoomla, Inc. - All rights reserved. * @license GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) * @author iJoomla.com <webmaster@ijoomla.com> * @url https://www.jomsocial.com/license-agreement * The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 * More info at https://www.jomsocial.com/license-agreement */ use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; use Joomla\Filesystem\File; use Joomla\Filesystem\Folder; use Joomla\Registry\Registry; // Disallow direct access to this file defined('_JEXEC') or die('Restricted access'); jimport( 'joomla.application.component.controller' ); /** * JomSocial Component Controller */ class CommunityControllerTemplates extends CommunityController { public function __construct() { parent::__construct(); } public function publish() { Session::checkToken() or jexit( 'Invalid Token' ); $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $template = $jinput->post->get('template', NULL, 'NONE'); // set as default if (!$jinput->post->get('uploadTheme', NULL, 'NONE')) { $model = $this->getModel('Configuration'); $model->updateTemplate($template); return $this->setRedirect(Route::_('index.php?option=com_community&view=templates', false) , Text::sprintf('COM_COMMUNITY_TEMPLATE_CONFIGURATION_UPDATED', $template ), 'message'); } else { // theme upload $themefile = $jinput->files->get('new-theme-upload', array(), 'raw'); if ($themefile['type'] == 'application/zip' || $themefile['type'] == 'application/x-zip-compressed' || $themefile['type'] == 'application/octet-stream') { $config = Factory::getConfig(); $tmp_dest = $config->get('tmp_path') . '/' . $themefile['name']; // move uploaded file to tmp folder. if (move_uploaded_file($themefile['tmp_name'], $tmp_dest)) { jimport('joomla.filesystem.*'); jimport('joomla.filesystem.archive'); $templateName = explode('_', basename($themefile['name'], '.zip')); $templateName = $templateName[0]; $templatefolder = COMMUNITY_TEMPLATE_PATH . '/' . $templateName; JArchive::extract($tmp_dest, $templatefolder); $path = $templatefolder .'/assets/css/style.css'; if (file_exists($path)) { return $this->setRedirect(Route::_('index.php?option=com_community&view=templates', false) , Text::_('COM_COMMUNITY_THEME_UPLOADED'), 'message'); } else { Folder::delete($templatefolder); return $this->setRedirect(Route::_('index.php?option=com_community&view=templates', false) , Text::_('COM_COMMUNITY_THEME_INVALID_FILE'), 'error'); } } else { return $this->setRedirect(Route::_('index.php?option=com_community&view=templates', false) , Text::_('COM_COMMUNITY_THEME_UNABLE_UPLOAD'), 'error'); } } else { return $this->setRedirect(Route::_('index.php?option=com_community&view=templates', false) , Text::_('COM_COMMUNITY_THEME_INVALID_FILE'), 'error'); } } } public function ajaxChangeTemplate( $templateName ) { $response = new JAXResponse(); if( $templateName == 'none' ) { // Previously user might already selected a template, hide the files $response->addScriptCall( 'azcommunity.resetTemplateFiles();' ); // Close all files if it is already editing $response->addScriptCall( 'azcommunity.resetTemplateForm();' ); } else { $html = '<div id="template-files">'; $html .= '<h3>' . Text::_('COM_COMMUNITY_SELECT_FILE') . '</h3>'; $templatePath = COMMUNITY_BASE_PATH . '/templates/'. JString::strtolower( $templateName ); $files = array(); if( $handle = @opendir($templatePath) ) { while( false !== ( $file = readdir( $handle ) ) ) { $filePath = $templatePath .'/'. $file; // Do not get '.' or '..' or '.svn' since we only want folders. if( $file != '.' && $file != '..' && $file != '.svn' && !(JString::stristr( $file , '.js')) && !is_dir($filePath) ) { $files[] = $file; } } } sort($files); $html .= '<select name="file" onchange="azcommunity.editTemplate(\'' . $templateName . '\',this.value);">'; $html .= '<option value="none" selected="true">' . Text::_('COM_COMMUNITY_SELECT_FILE') . '</option>'; for( $i = 0; $i < count( $files ); $i++ ) { $html .= '<option value="' . $files[$i] . '">' . $files[$i] . '</option>'; } $html .= '</select>'; $html .= '</div>'; $response->addAssign( 'templates-files-container' , 'innerHTML' , $html ); } return $response->sendResponse(); } /** * Ajax method to load a template file * * @param $templateName The template name * @param $fileName The file name **/ public function ajaxLoadTemplateFile( $templateName , $fileName , $override ) { $response = new JAXResponse(); if( $fileName == 'none') { $response->addScriptCall( 'azcommunity.resetTemplateForm();' ); } else { $filePath = COMMUNITY_BASE_PATH . '/templates/'. JString::strtolower( $templateName ) .'/'. JString::strtolower( $fileName ); if( $override ) $filePath = JPATH_ROOT . '/templates/'. JString::strtolower( $templateName ) . '/html/com_community/'. JString::strtolower( $fileName ); jimport('joomla.filesystem.file'); $contents = file_get_contents( $filePath ); $response->addAssign( 'data' , 'value' , $contents ); $response->addAssign( 'fileName' , 'value' , $fileName ); $response->addAssign( 'templateName' , 'value' , $templateName ); $response->addAssign( 'filePath' , 'innerHTML' , $filePath ); } return $response->sendResponse(); } public function ajaxSaveTemplateFile( $templateName , $fileName , $fileData , $override ) { $response = new JAXResponse(); $filePath = COMMUNITY_BASE_PATH . '/templates/'. JString::strtolower( $templateName ) .'/'. JString::strtolower( $fileName ); if( $override ) $filePath = JPATH_ROOT . '/templates/'. JString::strtolower( $templateName ) . '/html/com_community/'. JString::strtolower( $fileName ); jimport( 'joomla.filesystem.file' ); if( File::write( $filePath , $fileData ) ) { $response->addScriptCall('joms.jQuery("#status").remove();'); $response->addScriptCall('joms.jQuery("<div id=\'status\'></div>") .html("' . Text::sprintf('%1$s saved successfully.' , $fileName ) . '") .attr("class","alert alert-success") .css({"float": "left", "width": "97%"}) .insertAfter("textarea");'); } else { $response->addScriptCall( 'alert' , Text::_('COM_COMMUNITY_TEMPLATES_FILE_SAVE_ERROR') ); } return $response->sendResponse(); } public function save() { $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $params = $jinput->post->get('params', array(), 'array'); $element = $jinput->getString( 'id' ); $override = $jinput->get('override',NULL,'NONE') ; $heroImage = $jinput->files->get('hero_image' , '', 'NONE'); $task = $jinput->get( 'task' ); if( $override ) { $xml = JPATH_ROOT . '/templates/'. $element . '/html/com_community/'. COMMUNITY_TEMPLATE_XML; $file = JPATH_ROOT . '/templates/'. $element . '/html/com_community/params.ini'; if( !is_file( $xml ) ) { $file = JPATH_ROOT . '/templates/'. $element . '/params.ini'; } } else { $file = JPATH_ROOT . '/components/com_community/templates/'. $element . '/params.ini'; } jimport('joomla.filesystem.file'); $registry = new Registry(); $registry->loadArray($params); $raw = $registry->toString(); if( !empty( $raw ) ) { if( !File::write( $file , $raw ) ) { return $this->setRedirect( 'index.php?option=com_community&view=templates&layout=edit&id=' . $element , Text::_('COM_COMMUNITY_TEMPLATES_PARAMETERS_SAVE_ERROR') , 'error' ); } } //hero image here if( !empty($heroImage['tmp_name']) && isset($heroImage['name']) && !empty($heroImage['name']) ){ $imagePath = COMMUNITY_PATH_ASSETS; // same as the image path //check the file extension first and only allow jpg or png $ext = strtolower(pathinfo($heroImage['name'], PATHINFO_EXTENSION)); if(!in_array( $ext, array('jpg','png') ) || ($heroImage['type'] != 'image/png' && $heroImage['type'] != 'image/jpeg') ){ return $this->setRedirect( 'index.php?option=com_community&view=templates&layout=edit&id=' . $element , Text::_('COM_COMMUNITY_TEMPLATES_PARAMETERS_SAVE_ERROR') , 'error' ); } //check if existing hero image exist, if yes, delete it if(file_exists($imagePath.'/hero-image.jpg')){ unlink($imagePath.'/hero-image.jpg'); }else if(file_exists($imagePath.'/hero-image.png')){ unlink($imagePath.'/hero-image.png'); } //let move the tmp image to the actual path move_uploaded_file($heroImage['tmp_name'],$imagePath.'hero-image.'.$ext); } switch($task){ case 'apply'; $link = 'index.php?option=com_community&view=templates&layout=edit&override='.$override.'&id='.$element; break; case 'save'; default: $link = 'index.php?option=com_community&view=templates'; break; } return $this->setRedirect( $link , Text::_('COM_COMMUNITY_TEMPLATES_PARAMETERS_SAVED'), 'message' ); } public function apply() { $this->save(); } public function edit() { $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $id = $jinput->get('cid', NULL, 'NONE'); $mainframe->redirect( 'index.php?option=com_community&view=templates&layout=edit&id=' . $id[0] ); } }
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка