Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file modified README.md
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions config/modules/files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
return array(
'module' => array(
'class' => 'application.modules.files.FilesModule',
),
'import' => array(),
'component' => array(),
'rules' => array(),
);
Empty file modified config/modules/social.php
100644 → 100755
Empty file.
Empty file modified exceptions/YAccessDeniedException.php
100644 → 100755
Empty file.
Empty file modified exceptions/YPageNotFoundException.php
100644 → 100755
Empty file.
Empty file modified exceptions/YServerErrorException.php
100644 → 100755
Empty file.
Empty file modified modules/documentation/install/documentation.php
100644 → 100755
Empty file.
146 changes: 146 additions & 0 deletions modules/files/FilesModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php
/**
*Класс модуля редактирования файлов - Files
*@category filemanagement
*@package YupeCMS
*@author SergeyMiracle <[email protected]>
*@version 1.0
**/

class FilesModule extends YWebModule
{
/**
* Категория модуля:
*
* @return string category
*/
public function getCategory()
{
return Yii::t('FilesModule.files', 'Юпи!');
}

/**
* Название модуля:
*
* @return string module name
*/
public function getName()
{
return Yii::t('FilesModule.files', 'Файловый редактор');
}

/**
* Описание модуля:
*
* @return string module description
*/
public function getDescription()
{
return Yii::t('FilesModule.files', 'Модуль для просмотра и редактирования файлов');
}

/**
* Автор модуля:
*
* @return string module author
*/
public function getAuthor()
{
return Yii::t('FilesModule.files', 'SergeyMiracle');
}

/**
* E-mail адрес автора модуля:
*
* @return string module author email
*/
public function getAuthorEmail()
{
return Yii::t('FilesModule.files', '[email protected]');
}

/**
* Домашняя страница модуля:
*
* @return string module homepage
*/
public function getUrl()
{
return Yii::t('FilesModule.files', 'https://github.com/SergeyMiracle/Yupe-file-editor');
}

/**
* Иконка модуля:
*
* @return string module icon
*/
public function getIcon()
{
return "folder-open";
}

/**
* Версия модуля:
*
* @return string module version
*/
public function getVersion()
{
return Yii::t('FilesModule.files', '0.1');
}

/**
* Меню для "верхушки" (возможно с чайлдами)
*
* @return array меню для "верхушки"
**/
public function getTopMenu()
{
return array(
array(
'label' => Yii::t('FilesModule.files', 'Файловый редактор'),
'url' => array('/files/show/index', 'file' => 'index'),
'icon' => 'folder-open',
),
);
}

/**
* Меню для сайдбара
*
* @return array меню для сайдбара
**/
public function getLeftMenu()
{
return array(
array(
'label' => Yii::t('FilesModule.files', 'Файловый редактор'),
'url' => array('/files/show/index', 'file' => 'index'),
'icon' => 'home',
),
);
}

public function init()
{
parent::init();

$this->setImport(array(
'files.models.*',
'files.components.*',
));
}

public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}

}
69 changes: 69 additions & 0 deletions modules/files/controllers/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

class DefaultController extends YBackController
{

public function actionIndex()
{
$this->render('index');
}

/*
*Функция возвращает json ответ для плагина dynatree
*/
public function actionInit($key)
{
$dir = $key;
if ($handle = opendir($dir)) {
$dirs = array();
$files = array();
while (false !== ($entry = readdir($handle))) {

if ($entry{0} == '.') continue;
if (is_dir($dir.'/'.$entry)) {
/*Массив директорий*/
$dirs[] = array('title'=>$entry, 'isFolder' => true, 'isLazy' => true, 'url' => $dir.'/'.$entry);
} else {
/*Массив файлов*/
$files[] = array('title'=>$entry, 'url' => $dir.'/'.$entry);
}
}
}
sort($dirs);
sort($files);
$output = array_merge($dirs, $files);
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode($output);
Yii::app()->end();
}
}

/* Получаем контент файла*/
public function actiongetFileContent($key) {
$fcontent = file_get_contents($key);
if (Yii::app()->request->isAjaxRequest)
{
/*избегаем повторной загрузки скриптов*/
Yii::app()->clientScript->scriptMap['*.js'] = false;
Yii::app()->clientScript->scriptMap['*.css'] = false;
$this->renderPartial('_form', array('fcontent'=>$fcontent, 'path' => $key), false, true);
}
}
/*Сохраняем изменения в файл*/
public function actionUpdateFile()
{ if (Yii::app()->request->isAjaxRequest){
$c = $_POST['codemirror'];
$file = $_POST['path'];
if(!$file)
{
return false;
Yii::app()->end();
} else {
file_put_contents($file, $c);
Yii::app()->end();
}
}
}

}
60 changes: 60 additions & 0 deletions modules/files/views/default/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--Инициализация Codemirror, c registerscript чет не захотел работать-->
<script>
$(function() {
var editor = CodeMirror.fromTextArea(document.getElementById("codemirror"), {
lineNumbers: true,
matchBrackets: true,
lineWrapping: true,
mode: "application/x-httpd-php",
indentUnit: 4,
indentWithTabs: true,
enterMode: "keep",
tabMode: "shift",
});
$("<?php md5($path).time() ?>").click (function (){ <!--Генерирует уникальный id для избежания повторного запроса-->
editor.save();
});
});
</script>

<div id="flash" class="flash" style="position: relative; min-width: 287px; float: right; top: -100px; left:314px; display: none; margin-left: -1000px;">
<div class="alert alert-success">
<a class="close" data-dismiss="alert">×</a>
<b>Файл успешно сохранен!</b>
</div>
</div>
<div id="flash_error" class="flash" style="position: relative; min-width: 287px; float: right; top: -100px; left:330px; display: none; margin-left: -1000px;">
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
<b>Ошибка! Проверьте права на запись!</b>
</div>
</div>
</div>
</div>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'cd-form',
'enableAjaxValidation'=>false,
)); ?>
<?php echo CHtml::textArea('codemirror', $fcontent, array()); ?>
<input type="hidden" id="path" name="path" value="<?php echo $path ?>" >
<div style="position: relative; left: 27px; top: 23px;">
<?php
echo CHtml::ajaxSubmitButton('Submit', '/files/default/updatefile', array(
'type' => 'POST',
'update' => '#codemirror',
'success' => 'function(data) {
$("#flash").clearQueue().fadeIn(1000).delay(1000).fadeOut(4000);
}',
'error' => 'function(data) {
$("#flash_error").clearQueue().fadeIn(1000).delay(1000).fadeOut(4000);
}',
),
array(
'type' => 'submit',
'id' => md5($path).time(),
'name' => 'cd-form',
'class' => 'btn btn-primary',
));

?>
<?php $this->endWidget(); ?>
32 changes: 32 additions & 0 deletions modules/files/views/default/assets/addon/dialog/dialog.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.CodeMirror-dialog {
position: absolute;
left: 0; right: 0;
background: white;
z-index: 15;
padding: .1em .8em;
overflow: hidden;
color: #333;
}

.CodeMirror-dialog-top {
border-bottom: 1px solid #eee;
top: 0;
}

.CodeMirror-dialog-bottom {
border-top: 1px solid #eee;
bottom: 0;
}

.CodeMirror-dialog input {
border: none;
outline: none;
background: transparent;
width: 20em;
color: inherit;
font-family: monospace;
}

.CodeMirror-dialog button {
font-size: 70%;
}
Loading