common.php ➔ codeDump()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XOOPS Project http://xoops.org
14
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author          Richard Griffith <[email protected]>
16
 * @author          trabis <[email protected]>
17
 */
18
19
/**
20
 * Dumps selected code from a PHP file with syntax highlighting.
21
 *
22
 * Sections to be dumped should be surrounded with comment lines:
23
 * // code marker
24
 * // code end
25
 *
26
 * @param string $fileName file name to dump
27
 *
28
 * @return void
29
 */
30
function codeDump($fileName)
31
{
32
    $code = file_get_contents($fileName);
33
    $matches = array();
34
    if (0 < (int) preg_match_all("#.*// code marker[\\s]*(.*)// code end.*#sU", $code, $matches)) {
35
        echo '<h2>' . _MA_XMFDEMO_SAMPLE_CODE . '</h2><hr>';
36
        $code = highlight_string("<?php\n" . implode("\n", $matches[1]), true);
37
        echo $code;
38
    }
39
    echo '<hr><br>';
40
    if (1 !== preg_match('#/admin/[a-z]*\.php$#', $fileName)) {
41
        echo '<a href="index.php">' . _MA_XMFDEMO_EXAMPLE_LIST . '</a>';
42
    }
43
}
44
45
/**
46
 * Show the title and description for a page
47
 *
48
 * @param string $name the name of the file to describe
49
 *
50
 * @return void
51
 */
52
function describeThis($name)
53
{
54
    $title = 'XMF XOOPS Module Framework Demo';
55
    $body = 'This is a coding example using XMF, the XOOPS module framework ';
56
57
    $name = strtoupper($name);
58
59
    $defTitle = '_MA_XMFDEMO_PAGE_TITLE_' . $name;
60
    if (defined($defTitle)) {
61
        $title = constant($defTitle);
62
        echo "<h1>{$title}</h1>";
63
    }
64
65
    $defBody = '_MA_XMFDEMO_PAGE_BODY_' . $name;
66
    if (defined($defBody)) {
67
        $body = constant($defBody);
68
        echo $body . '<br><br>';
69
    }
70
71
    echo "\n<hr>\n";
72
    \Xmf\Metagen::generateMetaTags($title, $body, 10, 4, 20);
73
}
74
75
/**
76
 * Get a list of files in a directory
77
 *
78
 * @param string $dir directory name containing the files to be listed.
79
 *
80
 * @return string[] array of file names
81
 */
82
function getFileList($dir)
83
{
84
    XoopsLoad::load('xoopslists');
85
    $files = XoopsLists::getFileListAsArray($dir);
86
    return $files;
87
}
88