Completed
Pull Request — master (#4)
by Michael
01:27
created

functions.php ➔ myiframe_FieldExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * ****************************************************************************
4
 * MYIFRAME - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
6
 * ****************************************************************************
7
 */
8
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    die('XOOPS root path not defined');
11
}
12
13
/**
14
 * Returns a module's option
15
 *
16
 * Return's a module's option (for the myiframe module)
17
 *
18
 * @package      Myiframe
19
 * @author       Instant Zero (http://www.instant-zero.com)
20
 * @copyright    Instant Zero (http://www.instant-zero.com)
21
 * @param string $option module option's name
22
 * @param string $repmodule
23
 * @return bool
24
 */
25
function myiframe_getmoduleoption($option, $repmodule = 'myiframe')
26
{
27
    global $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
28
    static $tbloptions = array();
29
    if (is_array($tbloptions) && array_key_exists($option, $tbloptions)) {
30
        return $tbloptions[$option];
31
    }
32
33
    $retval = false;
34
    if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) {
35
        if (isset($xoopsModuleConfig[$option])) {
36
            $retval = $xoopsModuleConfig[$option];
37
        }
38
    } else {
39
        $moduleHandler = xoops_getHandler('module');
40
        $module        = $moduleHandler->getByDirname($repmodule);
41
        $configHandler = xoops_getHandler('config');
42
        if ($module) {
43
            $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
44
            if (isset($moduleConfig[$option])) {
45
                $retval = $moduleConfig[$option];
46
            }
47
        }
48
    }
49
    $tbloptions[$option] = $retval;
50
    return $retval;
51
}
52
53
/**
54
 * Verify that a field exists inside a mysql table
55
 *
56
 * @package      Myiframe
57
 * @author       Instant Zero (http://www.instant-zero.com)
58
 * @copyright    Instant Zero (http://www.instant-zero.com)
59
 * @param $fieldname
60
 * @param $table
61
 * @return bool
62
 */
63
function myiframe_FieldExists($fieldname, $table)
64
{
65
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
66
    $result = $xoopsDB->queryF("SHOW COLUMNS FROM	$table LIKE '$fieldname'");
67
    return ($xoopsDB->getRowsNum($result) > 0);
68
}
69
70
/**
71
 * Set the page's title, meta description and meta keywords
72
 * Datas are supposed to be sanitized
73
 *
74
 * @package          Myiframe
75
 * @author           Instant Zero http://www.instant-zero.com
76
 * @copyright    (c) Instant Zero http://www.instant-zero.com
77
 *
78
 * @param string $page_title       Page's Title
79
 * @param string $meta_description Page's meta description
80
 * @param string $meta_keywords    Page's meta keywords
81
 * @return none
0 ignored issues
show
Documentation introduced by
Should the return type not be none|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
82
 */
83
function myiframe_set_metas($page_title = '', $meta_description = '', $meta_keywords = '')
84
{
85
    global $xoTheme, $xoTheme, $xoopsTpl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
86
    $xoopsTpl->assign('xoops_pagetitle', $page_title);
87
    if (isset($xoTheme) && is_object($xoTheme)) {
88
        if (!empty($meta_keywords)) {
89
            $xoTheme->addMeta('meta', 'keywords', $meta_keywords);
90
        }
91
        if (!empty($meta_description)) {
92
            $xoTheme->addMeta('meta', 'description', $meta_description);
93
        }
94
    } elseif (isset($xoopsTpl) && is_object($xoopsTpl)) {    // Compatibility for old Xoops versions
95
        if (!empty($meta_keywords)) {
96
            $xoopsTpl->assign('xoops_meta_keywords', $meta_keywords);
97
        }
98
        if (!empty($meta_description)) {
99
            $xoopsTpl->assign('xoops_meta_description', $meta_description);
100
        }
101
    }
102
}
103