Completed
Push — master ( 26776f...d9604e )
by Michael
11:31
created

admin/faqAdapter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 29 and the first side effect is on line 3.

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
// $ID:$
3
include('../../../include/cp_header.php');
4
include_once('admin_header.php');
5
include_once(XOOPS_ROOT_PATH . '/class/pagenav.php');
6
require_once(XHELP_CLASS_PATH . '/faqAdapterFactory.php');
7
include_once(XHELP_CLASS_PATH . '/faqAdapter.php');
8
9
$op = 'default';
10
11
if ( isset( $_REQUEST['op'] ) )
12
{
13
    $op = $_REQUEST['op'];
14
}
15
16
switch ( $op )
17
{
18
    case "updateActive":
19
        updateActive();
20
        break;
21
22
    case "manage":
23
    default:
24
        manage();
25
        break;
26
27
}
28
29
function manage()
30
{
31
    global $imagearray;
32
    $faqAdapters =& xhelpFaqAdapterFactory::installedAdapters();
33
    $myAdapter =& xhelpFaqAdapterFactory::getFaqAdapter();
34
    xoops_cp_header();
35
    //echo $oAdminButton->renderButtons('manFaqAdapters');
36
    $indexAdmin = new ModuleAdmin();
37
    echo $indexAdmin->addNavigation('faqAdapter.php');
38
39
    echo "<form method='post' action='".XHELP_ADMIN_URL."/faqAdapter.php?op=updateActive'>";
40
    echo "<table width='100%' cellspacing='1' class='outer'>";
41
42
    if(!empty($faqAdapters)){
43
        echo "<tr><th colspan='5'>"._AM_XHELP_MENU_MANAGE_FAQ."</th></tr>";
44
        echo "<tr class='head'>
45
                  <td>"._AM_XHELP_TEXT_NAME."</td>
46
                  <td>"._AM_XHELP_TEXT_PLUGIN_VERSION."</td>
47
                  <td>"._AM_XHELP_TEXT_TESTED_VERSIONS."</td>
48
                  <td>"._AM_XHELP_TEXT_AUTHOR."</td>
49
                  <td>"._AM_XHELP_TEXT_ACTIVE."</td>
50
              </tr>";
51
52
        $activeAdapter = xhelpGetMeta('faq_adapter');
53
        foreach($faqAdapters as $name=>$oAdapter){
54
            $modname = $name;
55
            $author = $oAdapter->meta['author'];
56
            $author_name = $author;
57
58
            if($oAdapter->meta['url'] != ''){   // If a website is specified
59
                $name = "<a href='".$oAdapter->meta['url']."'>".$oAdapter->meta['name']."</a>"; // Add link to module name
60
            }
61
            if($oAdapter->meta['author_email'] != ''){
62
                $author = "<a href='mailto:".$oAdapter->meta['author_email']."'>".$author_name."</a>";  // Add link to email author
63
            }
64
            echo "<tr class='even'>
65
                      <td>".$name."</td>
66
                      <td>".$oAdapter->meta['version']."</td>
67
                      <td>".$oAdapter->meta['tested_versions']."</td>
68
                      <td>".$author."</td>
69
                      <td>
70
                          <input type='image' src='".($activeAdapter == $modname ? XHELP_IMAGE_URL .'/on.png' : XHELP_IMAGE_URL .'/off.png')."' name='modname' value='".$modname."' style='border:0;background:transparent' />
71
                      </td>
72
                  </tr>";
73
        }
74
    } else {
75
        // Display "no adapters found" message
76
        echo "<tr><th>"._AM_XHELP_MENU_MANAGE_FAQ."</th></tr>";
77
        echo "<tr><td class='even'>". _AM_XHELP_TEXT_NO_FILES ."</td></tr>";
78
    }
79
    echo "</table></form>";
80
81
    if(is_object($myAdapter)){
82
        $faq = $myAdapter->createFaq();
83
    }
84
85
include_once "admin_footer.php";
86
}
87
88
function updateActive()
89
{
90
    if(!isset($_POST['modname'])){
91
        redirect_header(XHELP_ADMIN_URL."/faqAdapter.php", 3, _AM_XHELP_MESSAGE_NO_NAME);
92
    } else {
93
        $modname = $_POST['modname'];
94
    }
95
96
    $currentAdapter = xhelpGetMeta('faq_adapter');
97
    if($currentAdapter == $modname){    // Deactivate current adapter?
98
        $ret = xhelpDeleteMeta('faq_adapter');
99
    } else {
100
        $ret = xhelpFaqAdapterFactory::setFaqAdapter($modname);
101
    }
102
103
    if($ret){
104
        header("Location: ".XHELP_ADMIN_URL."/faqAdapter.php");
105
    } else {
106
        redirect_header(XHELP_ADMIN_URL."/faqAdapter.php", 3, _AM_XHELP_MSG_INSTALL_MODULE);
107
    }
108
}
109