-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
executable file
·99 lines (86 loc) · 4.11 KB
/
Copy pathplugin.php
File metadata and controls
executable file
·99 lines (86 loc) · 4.11 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
<?php
class pluginOGFileManager extends Plugin {
private $loadOnController = array(
'new-content',
'edit-content'
);
public function init() {
//Create Documents Folder
mkdir(PATH_UPLOADS . 'documents' . DS, 0755);
//define constants
define('OGFM_PATH_DOCUMENTS_REL', HTML_PATH_UPLOADS . 'documents' . DS);
define('OGFM_PATH_DOCUMENTS_ABS', PATH_UPLOADS . 'documents' . DS);
}
public function adminBodyEnd() {
echo '<!-- OGFileManager Start -->';
global $L;
// Load the plugin only in the controllers setted in $this->loadOnController
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
return false;
}
include($this->phpPath() . 'php/dialog.php');
$html .= '<script>';
$html .= '$("#jseditorToolbarRight").prepend(\'<button type="button" class="btn btn-light" id="jsDocumentManagerOpenModal" data-toggle="modal" data-target="#jsDocumentManagerModal"><span class="fa fa-file"></span>' . $L->g('FileManager') . '</button>\');' . PHP_EOL;
$html .= '$(document).ready(function() {' . PHP_EOL;
$html .= ' if (typeof editorInsertDocument != "function") {' . PHP_EOL;
$html .= ' window.editorInsertDocument = function(filename){' . PHP_EOL;
$html .= ' var placeholder = "DOC{"+filename+";' . $L->g("Insert name of file") . ';' . $L->g("Insert description") . '}";' . PHP_EOL;
//No Editor-Plugin selected
$html .= ' $("#jseditor").val($(\'#jseditor\').val()+placeholder);' . PHP_EOL;
//TinyMCE as editor selected
$html .= ' if (typeof tinymce !== \'undefined\') {' . PHP_EOL;
$html .= ' tinymce.activeEditor.insertContent(placeholder);' . PHP_EOL;
$html .= ' };' . PHP_EOL;
//Easy MDE as plugin selected
$html .= ' if (typeof easymde !== \'undefined\') {' . PHP_EOL;
$html .= ' var text = easymde.value();' . PHP_EOL;
$html .= ' easymde.value(text + placeholder + "\\n");' . PHP_EOL;
$html .= ' easymde.codemirror.refresh();' . PHP_EOL;
$html .= ' };' . PHP_EOL;
$html .= ' };' . PHP_EOL;
$html .= ' }' . PHP_EOL;
$html .= '});' . PHP_EOL;
$html .= '</script>' . PHP_EOL;
$html .= '<!-- OGFileManager End -->' . PHP_EOL;
return $html;
}
// Load CSS for contact form
public function siteHead() {
$html = '';
$css = THEME_DIR_CSS . 'ogfm-style.css';
if (file_exists($css)) {
$html .= Theme::css('css' . DS . 'ogfm-style.css');
} else {
$html .= '<link rel="stylesheet" href="' . $this->htmlPath() . 'css' . DS . 'ogfm-style.css">' . PHP_EOL;
}
return $html;
}
public function pageBegin() {
global $page;
//Replace Patterns with links
//Check if we have a page with content
if ($GLOBALS['WHERE_AM_I'] === 'page') {
$page->setField('content', $this->replaceLinks($page->content()));
}
}
/**
* Replaces all placeholders with configured download button
*/
private function replaceLinks($contentOfPage) {
include 'php/LinkTemplateHelper.php';
//Pattern to find
$regex = '/DOC{(?<FILENAME>[a-zA-Z0-9_.-]+);(?<NAME>.*);(?<DESCRIPTION>.*)}/';
preg_match_all($regex, $contentOfPage, $matches, PREG_OFFSET_CAPTURE);
//Replace all matches
for ($i = 0; $i <= count($matches[0]); $i++) {
$total = $matches[0][$i][0];
$filename = $matches["FILENAME"][$i][0];
$name = $matches["NAME"][$i][0];
$description = $matches["DESCRIPTION"][$i][0];
$link = LinkTemplateHelper::buildLink(OGFM_PATH_DOCUMENTS_REL . $filename, $name, $description);
$contentOfPage = str_replace($total, $link, $contentOfPage);
}
return $contentOfPage;
}
}
?>