-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlinks.php
More file actions
90 lines (81 loc) · 2.4 KB
/
Copy pathlinks.php
File metadata and controls
90 lines (81 loc) · 2.4 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
<?php
/**
* Editor Links Server Functions -- links.php
*
* PHP version 5
*
* @category CMSimple_XH
* @package Tinymce4
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 2009-2015 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @link http://cmsimple-xh.org/
*/
/**
* Get Images List.
*
* @param string $directory Path to image directory.
*
* @return JSON structured images list
*/
function get_images($directory)
{
$files = array();
$handle = opendir($directory);
if (!$handle) {
return '';
}
$i = 0;
while (false !== ($file = readdir($handle))) {
if (preg_match("/(\.jpg$|\.gif$|\.png$|\.jpeg$)/ui", $file)) {
$files[$i]['name'] = $file;
$files[$i]['path'] = $directory . "" . $file;
$i++;
}
}
closedir($handle);
sort($files);
$list = array();
foreach ($files as $i) {
$list[] = array('title'=> $i['name'], 'value'=>$i['path']);
}
return(XH_encodeJSON($list));
}
/**
* Get Internal Link List to Images/Downloads.
*
* @param array $h headings array.
* @param array $u URL array.
* @param array $l menulevel array.
* @param string $downloads_path downloads folder path.
*
* @return JSON structured images / downloads list
*/
function get_internal_links($h, $u, $l, $downloads_path)
{
$list = array();
for ($i = 0; $i < count($h); $i++) {
$spacer = '';
if ($l[$i] > 1) {
$spacer = str_repeat('__', $l[$i] - 1); // just for
// indenting lower level "pages"
}
$list[] = array('title' =>
$spacer .
html_entity_decode(addcslashes($h[$i], "\n\r\t\"\\")) ,
'value' =>'?' . $u[$i]);
}
if (is_dir($downloads_path)) {
$list[] = array('title' => 'DOWNLOADS:' , 'value' => " ");
$fs = sortdir($downloads_path);
foreach ($fs as $p) {
if (preg_match("/.+\..+$/u", $p)) {
$list[] = array('title' => '__' . utf8_substr($p, 0, 25) .
' (' .
intval(filesize($downloads_path . '/' . $p) / 1024) .
' KB)' , 'value' => './?download=' . $p);
}
}
}
return(XH_encodeJSON($list));
}