Completed
Pull Request — master (#5)
by Michael
03:10
created

qrcode.php (9 issues)

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

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: qrcode.php 11158 2013-03-05 14:10:36Z zyspec $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
include 'header.php';
29
include_once './class/utility.php';
30
//xoops_load('utility', $xoopsModule->getVar('dirname'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
32
$lid = mylinksUtility::mylinks_cleanVars($_GET, 'lid', 0, 'int', array('min'=>0));
0 ignored issues
show
'lid' is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
$cid = mylinksUtility::mylinks_cleanVars($_GET, 'cid', 0, 'int', array('min'=>0));
0 ignored issues
show
'cid' is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
if ( empty($lid) || empty($cid) ) {
35
    redirect_header('index.php', 3, _MD_MYLINKS_IDERROR);
36
}
37
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
$lid = isset($_GET['lid']) ? intval($_GET['lid']) : 0;
39
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
40
if ( empty($lid) ) {
41
  die("No lid!");
42
} elseif ( empty($cid) ) {
43
  die("No cid!");
44
}
45
*/
46
$result = $xoopsDB->query('SELECT l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . " t where l.lid={$lid} AND l.lid=t.lid and status>0");
47
if (!$result) {
48
    redirect_header('index.php', 3, _MD_MYLINKS_NORECORDFOUND);
49
    exit();
50
}
51
52
list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result);
53
54
//qrcode func
55 View Code Duplication
switch ($mylinks_can_qrcode) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    case _MD_MYLINKS_MEMBERONLY:
57
        $can_qrcode = $xoopsUser ? _MD_MYLINKS_ALLOW : _MD_MYLINKS_DISALLOW;
58
        break;
59
    case _MD_MYLINKS_ALLOW:
60
        $can_qrcode = _MD_MYLINKS_ALLOW;
61
        break;
62
    case _MD_MYLINKS_DISALLOW:
63
    default:
64
        $can_qrcode = _MD_MYLINKS_DISALLOW;
65
        break;
66
}
67
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
if ( _MD_MYLINKS_DISALLOW == $can_qrcode ) {
69
    $xoopsTpl->assign( 'mylinksextrafuncqrcode' , false );
70
} else {
71
    $xoopsTpl->assign( 'mylinksextrafuncqrcode' , true );
72
}
73
74
$can_qrcode = 0;
75
if ( $mylinks_can_qrcode == 0 ) {
76
  $can_qrcode = 0;
77
}
78
else if ( $mylinks_can_qrcode == 1) {
79
  $can_qrcode = 1;
80
}
81
else if ( $mylinks_can_qrcode == 2) {
82
  if ( $xoopsUser ) {
83
  $can_qrcode =1;
84
  }
85
  else {
86
  $can_qrcode =0;
87
  }
88
}
89
else {
90
  $can_qrcode = 0;
91
}
92
*/
93
if ( _MD_MYLINKS_DISALLOW == $can_qrcode ) {
94
    redirect_header('index.php', 3, _MD_MYLINKS_QRCODEDISALLOWED);
95
    exit();
96
}
97
98
$myts =& MyTextSanitizer::getInstance();
99
100 View Code Duplication
function mylinks_qrcode_convert_encoding($str, $to = 'SJIS', $from = _CHARSET)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
{
102
    if (function_exists('mb_convert_encoding')) {
103
        if (is_array($str)) {
104
            foreach ($str as $key=>$val) {
105
                $str[$key] = mylinks_qrcode_convert_encoding($val, $to, $from);
106
            }
107
108
            return $str;
109
        } else {
110
            return mb_convert_encoding($str, $to, $from);
111
        }
112
    } else {
113
        return $str;
114
    }
115
}
116
117
function mylinks_qrcode_encoding($data= '')
118
{
119
    $data = mylinks_qrcode_convert_encoding($data);
120
    $data = rawurlencode($data);
121
    $data = preg_replace('/%20/', '+', $data);
122
123
    return $data;
124
}
125
126
$link_data          = array();
127
$link_data['text']  = $myts->displayTarea($myts->stripSlashesGPC($description, 0));
128
$link_data['title'] = $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle));
129
$link_data['url']   = $myts->htmlSpecialChars($url);
130
$data       = "{$link_data['title']}\r\n{$link_data['url']}\r\n{$link_data['text']}";
131
$qrcodedata = mylinks_qrcode_encoding($data);
132
$linkqrcode = "<img alt='qrcode of linkdata' title='qrcode of linkdata'src='" . XOOPS_URL . "/modules/qrcode/qrcode_image.php?d={$qrcodedata}&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000'>\n";
133
134
echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n"
135
  ."<html>\n"
136
  ."<head>\n"
137
     . '<title>' . $xoopsConfig['sitename'] . "</title>\n"
138
    ."<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "'>\n"
139
    ."<meta name='AUTHOR' content='" . $xoopsConfig['sitename'] . "'>\n"
140
    ."<meta name='COPYRIGHT' content='Copyright (c) " . date('Y') . ' by ' . $xoopsConfig['sitename'] . "'>\n"
141
    ."<meta name='DESCRIPTION' content='" . $xoopsConfig['slogan'] . "'>\n"
142
    ."<meta name='GENERATOR' content='" . XOOPS_VERSION . "'>\n"
143
    ."</head>\n"
144
    ."<body style='background-color: #ffffff; color: #000000;'>\n"
145
    ."  <div style='width: 750px; border: 1px solid #000; padding: 20px;'>\n"
146
    ."    <div style='text-align: center; display: block; margin: 0 0 6px 0;'>\n"
147
    ."      <h2 style='margin: 0px;'>" . _MD_MYLINKS_SITETITLE . "&nbsp;{$link_data['title']}</h2>\n"
148
    ."    </div>\n"
149
    ."    <div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>\n"
150
    ."    <div style='text-align: left'>" . _MD_MYLINKS_SITEURL . "&nbsp;:&nbsp;{$link_data['url']}</div>\n"
151
    ."    <div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>\n"
152
    ."    <div style='text-align: left'>"._MD_MYLINKS_DESCRIPTIONC . '<br>' . $link_data['text'] . "</div>\n"
153
    ."    <div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>\n"
154
    ."    <div style='text-align: left'>LINK DATA QRCODE<br>{$linkqrcode}</div>\n"
155
    ."    <div style='padding-top: 12px; border-top: 2px solid #ccc;'></div>\n"
156
     . '      <p>From: &nbsp;' . XOOPSMYLINKURL . "/singlelink.php?cid={$cid}&amp;lid={$lid}</p>\n"
157
    ."    </div>\n"
158
    ."    <br>\n"
159
  ."    <br>\n"
160
  ."</body>\n"
161
     . '</html>';
162