-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel.php
More file actions
249 lines (248 loc) · 11.6 KB
/
Copy pathpanel.php
File metadata and controls
249 lines (248 loc) · 11.6 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* Panel
*
* @package Morfy
* @subpackage Plugins
* @author Moncho Varela / Nakome
* @copyright 2014 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// define root in plugin
define('ROOT',PLUGINS_PATH.'/panel/');
// debug
$debug = false;
if($debug){
ini_set('display_errors',1);
error_reporting(E_ALL);
}else{
ini_set('display_errors',0);
error_reporting(E_ALL);
}
// include class panel
require('library/class/class.panel.php');
// Call scripts and styles in theme header
Morfy::factory()->addAction('theme_header', function () {
$editor_styles = '
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
<link rel="stylesheet" href="'.Morfy::$config['site_url'].'/plugins/panel/assets/css/panel.css" />
<script rel="javascript" src="'.Morfy::$config['site_url'].'/plugins/panel/assets/js/panel.js"></script>';
// only load in panel
if(trim(Morfy::factory()->getUrl(), '/') == 'panel') {
echo $editor_styles;
};
});
Morfy::factory()->addAction('theme_content_after', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
if(trim(Morfy::factory()->getUrl(), '/') == 'panel') {
Morfy::factory()->runAction('panel');
// use default if empty in config.php
$password = Panel::Config(Morfy::$config['password'],'demo');
$secret_key1 = Panel::Config(Morfy::$config['secret_key_1'],'secret_key1');
$secret_key2 = Panel::Config(Morfy::$config['secret_key_2'],'secret_key2');
$hash = md5($secret_key1.$password.$secret_key2);
// get actions
if (Panel::Request_Get('action')) {
$action = Panel::Request_Get('action');
// swich
switch ($action) {
case 'login':
// isset
if ((Panel::Request_Post('password')) && (Panel::Request_Post('token')) && (Panel::Request_Post('password') === $password)) {
$_SESSION['login'] = $hash;
Panel::Cookie_set('login',10);
Panel::isLogin();
// redirect if true
Panel::Notification('success','Success',$lang['Hello Admin'],Panel::Root('panel'));
}else{
Panel::Notification('error','Error',$lang['You need provide a password'],Panel::Root('panel'));
}
break;
case 'logout':
Panel::Cookie_delete('login');
Panel::isLogout();
Panel::redirect(Panel::Root());
break;
}
}
// Delete images function
Morfy::factory()->runAction('deleteImages');
}
});
// Call plugin with echo Morfy::factory()->runAction('files');
Morfy::factory()->addAction('files', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
// edit File ?editFile= file
if (Panel::Request_Get('editFile')) {
// get file
$file = Panel::getContent(CONTENT_PATH.'/'.$_GET['editFile'].'.md');
$filename = Panel::Request_Get('editFile');
require_once('library/includes/update.php');
}else if (Panel::Request_Get('deleteFile')) {
// get delete file
$file = CONTENT_PATH.'/'.Panel::Request_Get('deleteFile').'.md';
if (!empty($file) || (!Panel::Request_Post('token'))) {
unlink($file);
// show Notification
Panel::Notification('success','Success',$lang['The File'].' '.Panel::Request_Get('deleteFile').' '.$lang['has been deleted'],Panel::Root('panel'));
}
}else if (Panel::Request_Get('saveFile')) {
// get content
if(Panel::Request_Post('filename')) $filename = Panel::Request_Post('filename'); else $filename = '';
if(Panel::Request_Post('content')) $content = Panel::Request_Post('content'); else $content = '';
if(Panel::Request_Post('isBlog')){
// save
Panel::setContent(CONTENT_PATH.'/blog/'.Panel::seoLink($filename).'.md',$content);
}else if(Panel::Request_Post('isPortfolio')){
$folder = 'portfolio';
// save in folder
Panel::setContent(CONTENT_PATH.'/'.$folder.'/'.Panel::seoLink($filename).'.md',$content);
}else{
// save
Panel::setContent(CONTENT_PATH.'/'.Panel::seoLink($filename).'.md',$content);
}
// show Notification
Panel::Notification('success','Success',$lang['The File'].' '.$filename.' '.$lang['has been save'],Panel::Root('panel'));
}else if (Panel::Request_Get('updateFile')) {
// name of file
$filename = Panel::Request_Get('updateFile');
// get content
if(Panel::Request_Post('content')) $content = Panel::Request_Post('content'); else $content = '';
// save
Panel::setContent(CONTENT_PATH.'/'.$filename.'.md',$content);
// show Notification
Panel::Notification('success','Success',$lang['The File'].' '.$filename.' '.$lang['has been save'],Panel::Root('panel'));
}else{
Morfy::factory()->runAction('getPages');
Morfy::factory()->runAction('getBlogPages');
Morfy::factory()->runAction('getPortfolioPages');
}
});
// Call plugin with echo Morfy::factory()->runAction('getPages');
Morfy::factory()->addAction('getPages', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
// content folder
$content_path_dir = CONTENT_PATH;
// show pages
$files = Panel::File_scan($content_path_dir);
$html = '<h5 class="divider">'.$lang['Pages'].':</h5>';
foreach ($files as $file) {
if(is_file($content_path_dir.'/'.$file)){
// get only name
$filename = str_replace('.md','',$file);
if($filename != 'panel' && $filename != 'blog'){
$html .= '<div class="tumb-grid">
<a target="_blank" href="'.Morfy::$config['site_url'].'/'.$filename .'" class="tumb">'.$filename .'</a>
<div class="desc">
<ul>
<li><a class="btn btn-primary btn-sm" href="?editFile='.$filename .'"><i class="fa fa-edit"></i> '.$lang['Edit'].'</a></li>
<li><a onclick="return confirmDelete(\' '.$lang['Are you sure'].' \')" class="btn btn-danger btn-sm" href="?deleteFile='.$filename .'"><i class="fa fa-trash-o"></i> '.$lang['Delete'].'</a></li>
</ul>
</div>
</div>';
}
}
}
$html .= '<div class="clearfix"></div>';
echo $html;
});
// Call plugin with echo Morfy::factory()->runAction('getBlogPages');
Morfy::factory()->addAction('getBlogPages', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
$folder = 'blog'; // name of new folder here
// show blog files
$folder_path_dir = CONTENT_PATH.'/'.$folder;
$folder_files = Panel::File_scan($folder_path_dir);
$html = '<h5 class="divider">'.$lang['Blog'].':</h5>';
foreach ($folder_files as $folder_file) {
if(is_file($folder_path_dir.'/'.$folder_file)){
// get blog pages
$folder_filename = str_replace('.md','',$folder_file);
// not show index
if($folder_filename != 'index'){
$html .= '<div class="tumb-grid">
<a target="_blank" href="'.Morfy::$config['site_url'].'/'.$folder.'/'.$folder_filename .'" class="tumb">'.$folder_filename .'</a>
<div class="desc">
<ul>
<li><a class="btn btn-primary btn-sm" href="?editFile='.$folder.'/'.$folder_filename .'"><i class="fa fa-edit"></i> '.$lang['Edit'].'</a></li>
<li><a onclick="return confirmDelete(\' '.$lang['Are you sure'].'\')" class="btn btn-danger btn-sm" href="?deleteFile='.$folder.'/'.$folder_filename .'"><i class="fa fa-trash-o"></i> '.$lang['Delete'].'</a></li>
</ul>
</div>
</div>';
}
}
}
$html .= '<div class="clearfix"></div>';
echo $html;
});
// Call plugin with echo Morfy::factory()->runAction('getPortfolioPages');
Morfy::factory()->addAction('getPortfolioPages', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
$folder = 'portfolio'; // This is the name of folder
// show folder files
$folder_path_dir = CONTENT_PATH.'/'.$folder;
$folder_files = Panel::File_scan($folder_path_dir);
$html = '<h5 class="divider">Portfolio:</h5>'; // this is the title
foreach ($folder_files as $folder_file) {
if(is_file($folder_path_dir.'/'.$folder_file)){
// get blog pages
$folder_filename = str_replace('.md','',$folder_file);
$html .= '<div class="tumb-grid">
<a target="_blank" href="'.Morfy::$config['site_url'].'/'.$folder.'/'.$folder_filename .'" class="tumb">'.$folder_filename .'</a>
<div class="desc">
<ul>
<li><a class="btn btn-primary btn-sm" href="?editFile='.$folder.'/'.$folder_filename .'"><i class="fa fa-edit"></i> '.$lang['Edit'].'</a></li>
<li><a onclick="return confirmDelete(\' '.$lang['Are you sure'].'\')" class="btn btn-danger btn-sm" href="?deleteFile='.$folder.'/'.$folder_filename .'"><i class="fa fa-trash-o"></i> '.$lang['Delete'].'</a></li>
</ul>
</div>
</div>';
}
}
$html .= '<div class="clearfix"></div>';
echo $html;
});
// Call plugin with Morfy::factory()->runAction('deleteImages');
Morfy::factory()->addAction('deleteImages', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
// delete image file
if(Panel::Request_Get('deleteImage')){
// Remove full an tumb image
unlink('public/images/full/'.Panel::Request_Get('deleteImage'));
unlink('public/images/tumb/'.Panel::Request_Get('deleteImage'));
// show Notification
Panel::Notification('success','Success',$lang['The File'].' '.Panel::Request_Get('deleteImage').' '.$lang['has been deleted'],Panel::Root('panel?get=images'));
}
});
// Call plugin with echo Morfy::factory()->runAction('add');
Morfy::factory()->addAction('add', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
require_once('library/add.php');
});
// Call plugin with echo Morfy::factory()->runAction('auth');
Morfy::factory()->addAction('auth', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
require('library/login.php');
});
// Call plugin with echo Morfy::factory()->runAction('panel');
Morfy::factory()->addAction('panel', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
require('library/panel.php');
});
// Call plugin with echo Morfy::factory()->runAction('content');
Morfy::factory()->addAction('content', function () {
// require language
require('library/language/'.Panel::Config(Morfy::$config['Panel_lang'],'es').'.php');
require('library/content.php');
});
?>