forked from marekmurawski/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAceController.php
128 lines (112 loc) · 4.32 KB
/
AceController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* Wolf CMS - Content Management Simplified. <http://www.wolfcms.org>
* Copyright (C) 2008-2010 Martijn van der Kleijn <[email protected]>
*
* Ace filter for Wolf CMS
* Code editor and syntax highlighter based on Ajax.org Cloud9 Editor.
*
* @package Plugins
* @subpackage ace
*
* @author Marek Murawski <http://marekmurawski.pl>
* @copyright Marek Murawski, 2012
* @license http://www.gnu.org/licenses/gpl.html GPLv3 license
* @license Ace http://opensource.org/licenses/BSD-3-Clause BSD
*
*/
if (!defined('IN_CMS')) { exit(); }
class AceController extends PluginController {
public function __construct() {
AuthUser::load();
if ( ! AuthUser::isLoggedIn()) {
redirect(get_url('login'));
}
$this->setLayout('backend');
$this->assignToLayout('sidebar', new View('../../plugins/ace/views/sidebar'));
}
public function index() {
$this->settings();
}
function settings() {
$settings = Plugin::getAllSettings('ace');
if (!$settings) {
Flash::set('error', 'Ace - '.__('unable to retrieve plugin settings.'));
redirect(get_url('setting'));
}
$this->display('ace/views/settings', array(
'settings' => $settings,
'themes' => $this->getThemes(),
'modes' => $this->getModes(),
));
}
public function save() {
$configFile = PLUGINS_ROOT.DS.'ace'.DS.'ace_config.js';
echo PLUGINS_ROOT.DS.'ace'.DS.'ace_config.js'.'<br/>';
$conf = '
/*
* THIS FILE IS AUTOMATICALLY GENERATED IN SETTINGS PANEL OF ACE PLUGIN
* IT SHOULD BE WRITABLE FOR PHP - chmod 0777
* DO NOT MODIFY THESE SETTINGS MANUALLY
*/
var aceMode = "'. strip_tags($_POST['aceMode']) .'";
var aceTheme = "'. strip_tags($_POST['aceTheme']) .'";
var aceFontSize = '. intval($_POST['aceFontSize']) .';
var aceScrollSpeed = '. intval($_POST['aceScrollSpeed']) .';
var aceEditorHeight = '. intval($_POST['aceEditorHeight']) .';
var aceWrapLines = '. strip_tags($_POST['aceWrapLines']) .';
var aceWrapRange = '. strip_tags($_POST['aceWrapRange']) .';
var aceLayoutIntegrate = '. strip_tags($_POST['aceLayoutIntegrate']) .';
var aceCookieLife = '. intval($_POST['aceCookieLife']) .';
var aceHighlightActiveLine = '. strip_tags($_POST['aceHighlightActiveLine']) .';
';
if (file_exists($configFile)) {
if (@!chmod($configFile, octdec('0777')))
Flash::set('error', __('Could not change ace_config.js file permissions to 0777. Do it manually!'));
}
if (file_put_contents($configFile, $conf)) {
if (Plugin::setAllSettings($_POST, 'ace')) {
Flash::set('success', __('Ace - settings saved!'));
} else {
Flash::set('error', __('Ace - unable to store settings in database!'));
}
} else {
Flash::set('error', __('Ace - unable to save ace_config.js file. Check permissions!'));
}
redirect(get_url('plugin/ace/settings'));
}
/**
* getModes
*
*/
protected function getThemes()
{
$scandir = scandir(ACEDIR.'/build/src-min/');
foreach($scandir as $k => $v)
{
if($v != '.' && $v != '..' && startsWith($v, 'theme-'))
{
$themes[$v]['id'] = str_replace('.js','',str_replace('theme-','',$v));
$themes[$v]['label'] = Inflector::humanize(str_replace('.js','',str_replace('theme-','',$v)));
}
}
return $themes;
}
/**
* getModes
*
*/
protected function getModes()
{
$scandir = scandir(ACEDIR.'/build/src-min/');
foreach($scandir as $k => $v)
{
if($v != '.' && $v != '..' && startsWith($v, 'mode-'))
{
$modes[$v]['id'] = str_replace('.js','',str_replace('mode-','',$v));
$modes[$v]['label'] = Inflector::humanize(str_replace('.js','',str_replace('mode-','',$v)));
}
}
return $modes;
}
}