Completed
Pull Request — master (#7)
by
unknown
03:31
created

bookmark.php ➔ GoogleCH()   C

Complexity

Conditions 14
Paths 48

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 30
nc 48
nop 3
dl 0
loc 38
rs 5.0864
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 103 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
3
include 'header.php';
4
include_once './class/utility.php';
5
//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...
6
$lid = mylinksUtility::mylinks_cleanVars($_GET, 'lid', 0, 'int', array('min'=>0));
0 ignored issues
show
Documentation introduced by
'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...
7
$cid = mylinksUtility::mylinks_cleanVars($_GET, 'cid', 0, 'int', array('min'=>0));
0 ignored issues
show
Documentation introduced by
'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...
8
if (empty($lid) || empty($cid)) {
9
    redirect_header('index.php', 3, _MD_MYLINKS_IDERROR);
10
}
11
/*
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...
12
$lid = isset($_GET['lid']) ? intval($_GET['lid']) : 0;
13
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
14
if ( empty($lid) ) {
15
  die("No lid!");
16
} elseif ( empty($cid) ) {
17
  die("No cid!");
18
}
19
*/
20
$result = $xoopsDB->query('SELECT l.lid, l.cid, l.title, l.url FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . " t where l.lid={$lid} AND l.lid=t.lid AND status>0");
21
if (!$result) {
22
    redirect_header('index.php', 3, _MD_MYLINKS_NORECORDFOUND);
23
    exit();
24
}
25
list($lid, $cid, $ltitle, $url) = $xoopsDB->fetchRow($result);
26
27
//bookmark func
28 View Code Duplication
switch ($mylinks_can_bookmark) {
0 ignored issues
show
Duplication introduced by
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...
29
    case _MD_MYLINKS_MEMBERONLY:
30
        $can_bookmark = $xoopsUser ? _MD_MYLINKS_ALLOW : _MD_MYLINKS_DISALLOW;
31
        break;
32
    case _MD_MYLINKS_ALLOW:
33
        $can_bookmark = _MD_MYLINKS_ALLOW;
34
        break;
35
    case _MD_MYLINKS_DISALLOW:
36
    default:
37
        $can_bookmark = _MD_MYLINKS_DISALLOW;
38
        break;
39
}
40
if ( _MD_MYLINKS_DISALLOW == $can_bookmark ) {
41
    redirect_header('index.php', 3, _MD_MYLINKS_BOOKMARKDISALLOWED);
42
    exit();
43
}
44
45
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
46
$can_bookmark = 0;
47
if ( $mylinks_can_bookmark == 0 ) {
48
  $can_bookmark = 0;
49
}
50
else if ( $mylinks_can_bookmark == 1) {
51
  $can_bookmark = 1;
52
}
53
else if ( $mylinks_can_bookmark == 2) {
54
  if ( $xoopsUser ) {
55
  $can_bookmark =1;
56
  }
57
  else {
58
  $can_bookmark =0;
59
  }
60
}
61
else {
62
  $can_bookmark = 0;
63
}
64
65
if ( empty($can_bookmark) ) {
66
  die("Not allowed now!");
67
}
68
69
$can_qrcode = 0;
70
if ( $mylinks_can_qrcode == 0 ) {
71
  $can_qrcode = 0;
72
}
73
else if ( $mylinks_can_qrcode == 1) {
74
  $can_qrcode = 1;
75
}
76
else if ( $mylinks_can_qrcode == 2) {
77
  if ( $xoopsUser ) {
78
  $can_qrcode =1;
79
  }
80
  else {
81
  $can_qrcode =0;
82
  }
83
}
84
else {
85
  $can_qrcode = 0;
86
}
87
88
if ( empty($can_qrcode) ) {
89
  die("Not allowed now!");
90
}
91
*/
92
93
xoops_header(false);
94
95
$myts =& MyTextSanitizer::getInstance();
96
97
$sitetitle = $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle));
98
$siteurl = $myts->htmlSpecialChars($url);
99
100
$siteurl_en   = urlencode(mb_convert_encoding($siteurl, 'UTF-8', _CHARSET));
101
$sitetitle_en = urlencode(mb_convert_encoding($sitetitle, 'UTF-8', _CHARSET));
102
103 View Code Duplication
function bookmark_convert_encoding($str, $to = 'SJIS', $from = _CHARSET)
0 ignored issues
show
Documentation introduced by
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...
Duplication introduced by
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...
104
{
105
    if (function_exists('mb_convert_encoding')) {
106
        if (is_array($str)) {
107
            foreach ($str as $key=>$val) {
108
                $str[$key] = bookmark_convert_encoding($val, $to, $from);
109
            }
110
111
            return $str;
112
        } else {
113
            return mb_convert_encoding($str, $to, $from);
114
        }
115
    } else {
116
        return $str;
117
    }
118
}
119
120
function bookmark_qrcode_encoding($data= '')
121
{
122
    $data = bookmark_convert_encoding($data);
123
    $data = rawurlencode($data);
124
    $data = str_replace('%20', '+', $data);
125
126
    return $data;
127
}
128
129
$qrcodedata_url = bookmark_qrcode_encoding($siteurl);
130
$siteqrcode = "<img alt='".$siteurl."' title='".$siteurl."'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_url&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000'>\n";
131
132
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
133
$qrcodedata_docomo_bookmark = bookmark_qrcode_encoding("MEBKM:TITLE:".$sitetitle.";URL:".$siteurl.";;");
134
$bookmarkqrcode_docomo = "<img alt='docomo' title='docomo'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_docomo_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000'>\n";
135
136
$qrcodedata_softbank_bookmark = bookmark_qrcode_encoding("TITLE:".$sitetitle."\r\nURL:".$siteurl."\r\n");
137
$bookmarkqrcode_softbank = "<img alt='softbank and au' title='softbank and au'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_softbank_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000'>\n";
138
139
$qrcodedata_bookmark = bookmark_qrcode_encoding("TITLE:\r\n".$sitetitle."\r\nURL:\r\n".$siteurl."\r\n");
140
$bookmarkqrcode = "<img alt='title and url' title='title and url'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata_bookmark&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000'>\n";
141
*/
142
143
//google pagerank
144
define('GOOGLE_MAGIC', 0xE6359A60);
145
146
function zeroFill($a, $b)
147
{
148
    $z = hexdec(80000000);
149
    if ($z & $a) {
150
        $a = ($a>>1);
151
        $a &= (~$z);
152
        $a |= 0x40000000;
153
        $a = ($a>>($b-1));
154
    } else {
155
        $a = ($a>>$b);
156
    }
157
158
    return $a;
159
}
160
161
function mix($a, $b, $c)
162
{
163
  $a -= $b; $a -= $c; $a ^= zeroFill($c, 13);
164
  $b -= $c; $b -= $a; $b ^= ($a<<8);
165
  $c -= $a; $c -= $b; $c ^= zeroFill($b, 13);
166
  $a -= $b; $a -= $c; $a ^= zeroFill($c, 12);
167
  $b -= $c; $b -= $a; $b ^= ($a<<16);
168
  $c -= $a; $c -= $b; $c ^= zeroFill($b, 5);
169
  $a -= $b; $a -= $c; $a ^= zeroFill($c, 3);
170
  $b -= $c; $b -= $a; $b ^= ($a<<10);
171
  $c -= $a; $c -= $b; $c ^= zeroFill($b, 15);
172
173
  return array($a, $b, $c);
174
}
175
176
function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC)
177
{
178
    if (is_null($length)) {
179
        $length = sizeof($url);
180
    }
181
    $a = $b = 0x9E3779B9;
182
    $c = $init;
183
    $k = 0;
184
    $len = $length;
185
    while ($len >= 12) {
186
        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
187
        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
188
        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
189
        $mix = mix($a, $b, $c);
190
        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
191
        $k += 12;
192
        $len -= 12;
193
    }
194
195
    $c += $length;
196
    switch($len)
197
    {
198
        case 11: $c+=($url[$k+10]<<24);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
199
        case 10: $c+=($url[$k+9]<<16);
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
200
        case 9 : $c+=($url[$k+8]<<8);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
201
        case 8 : $b+=($url[$k+7]<<24);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
202
        case 7 : $b+=($url[$k+6]<<16);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
203
        case 6 : $b+=($url[$k+5]<<8);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
204
        case 5 : $b+= $url[$k + 4];
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
205
        case 4 : $a+=($url[$k+3]<<24);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
206
        case 3 : $a+=($url[$k+2]<<16);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
207
        case 2 : $a+=($url[$k+1]<<8);
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
208
        case 1 : $a+= $url[$k + 0];
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
209
    }
210
    $mix = mix($a, $b, $c);
211
212
    return $mix[2];
213
}
214
215
function strord($string)
216
{
217
    for ($i=0; $i<strlen($string); $i++) {
218
        $result[$i] = ord($string{$i});
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
219
    }
220
221
    return $result;
0 ignored issues
show
Bug introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
222
}
223
224
function getrank($url)
225
{
226
    $pagerank = '0';
227
    $ch = '6' . GoogleCH(strord('info:' . $url));
228
229
    $fp = fsockopen('www.google.com', 80, $errno, $errstr, 30);
230
    if (!$fp) {
231
        $pagerank = '-1';
232
        //echo "$errstr ($errno)<br>\n";
233
    } else {
234
        $out = 'GET /search?client=navclient-auto&ch=' . $ch . '&features=Rank&q=info:' . $url . " HTTP/1.1\r\n";
235
        $out .= "Host: www.google.com\r\n";
236
        $out .= "Connection: Close\r\n\r\n";
237
238
        fwrite($fp, $out);
239
240
        while (!feof($fp)) {
241
            $data = fgets($fp, 128);
242
            $pos = strpos($data, 'Rank_');
243
            if($pos === false){} else{
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
244
                $pagerank = substr($data, $pos + 9);
245
            }
246
        }
247
        fclose($fp);
248
    }
249
250
    return $pagerank;
251
}
252
//
253
254
echo '
255
<script type="text/javascript">
256
<!--//
257
/***********************************************
258
* Bookmark site script-Dynamic Drive DHTML code library (www.dynamicdrive.com)
259
* This notice MUST stay intact for legal use
260
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
261
***********************************************/
262
/* Modified to support Opera */
263
function bookmarksite(title,url){
264
if (window.sidebar) // firefox
265
  window.sidebar.addPanel(title, url, "");
266
else if(window.opera && window.print){ // opera
267
  var elem = document.createElement("a");
268
  elem.setAttribute("href",url);
269
  elem.setAttribute("title",title);
270
  elem.setAttribute("rel","sidebar");
271
  elem.click();
272
}
273
else if(document.all)// ie
274
  window.external.AddFavorite(url, title);
275
}
276
//-->
277
</script>
278
</head>
279
<body>
280
<script type="text/javascript">
281
<!--//
282
var addtoMethod=0;
283
//-->
284
</script>
285
<script src="'.XOOPSMYLINKINCURL.'/addto-multi.js" type="text/javascript"></script>
286
287
  <table style="width: 95%; margin: auto;" class="outer">
288
    <tr><td colspan="2" style="text-align: center;"><h3>'._MD_MYLINKS_BOOKMARK_SERVICE.'</h3></td></tr>
289
    <tr><td class="head" style="text-align: center; font-weight: bold;">' . _MD_MYLINKS_SITETITLE . '</td><td class="even" style="text-align: center;">'.$sitetitle.'</td></tr>
290
    <tr><td class="head" style="text-align: center; font-weight: bold;">' . _MD_MYLINKS_SITEURL . '</td><td class="even" style="text-align: center;"><a href="'.$siteurl.'" target="_blank">'.$siteurl.'</a><br>(&nbsp;<strong>Google PageRank :</strong>&nbsp;<img src="'.XOOPSMYLINKIMGURL.'/addto/pr'.getrank($siteurl).'.gif" alt="pagerank">&nbsp;)</td></tr>';
291
if ( $mylinks_can_qrcode ) {
292
            echo '<tr><td  class="head" style="text-align: center; font-weight: bold;">' . _MD_MYLINKS_QRCODE . '<br>(' . _MD_MYLINKS_SITEURL . ')</td><td class="even" style="text-align: center;">'.$siteqrcode.'</td></tr>';
293
}
294
  echo '
295
    <tr><td class="head" style="text-align: center; font-weight: bold;">' . _MD_MYLINKS_WEBBROWSER . '</td><td  class="even" style="text-align: center;">
296
      <a href="javascript:void(0);" onclick="bookmarksite(\''.$sitetitle.'\', \''.$siteurl.'\');">' . _MD_MYLINKS_BROWSERBOOKMARK . '</a>
297
    </td></tr>
298
  </table>
299
  <br><br>
300
<table style="width: 90%; margin: auto;">
301
<tr class="foot"><td colspan="2" style="text-align: center; font-weight: bold;">'._MD_MYLINKS_BOOKMARK_ADDTO.'...</td></tr>
302
<tr><td class="even">
303
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Blink"><a style="cursor:pointer;" onclick="addto(1,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
304
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Blink.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Blink"> Blink</a></span>
305
<br>
306
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Delicious"><a style="cursor:pointer;" onclick="addto(2,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
307
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Delicious.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Del.icio.us"> Del.icio.us</a></span>
308
<br>
309
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Digg"><a style="cursor:pointer;" onclick="addto(3,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
310
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Digg.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Digg"> Digg</a></span>
311
<br>
312
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Furl"><a style="cursor:pointer;" onclick="addto(4,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
313
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Furl.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Furl"> Furl</a></span>
314
<br>
315
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Blue Dot"><a style="cursor:pointer;" onclick="addto(9,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
316
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Bluedot.png" style="width: 16px; height: 16px; border-width: 0px;" alt="Bluedot"> Blue Dot</a></span>
317
<br>
318
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' BookmarkTracker"><a style="cursor:pointer;" onclick="addto(11,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
319
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Bookmarktracker.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Bookmarktracker"> BookmarkTracker</a></span>
320
<br>
321
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Hatena"><a style="cursor:pointer;" onclick="addto(13,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
322
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Hatena.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Hatena"> Hatena</a></span>
323
<br>
324
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Magnolia"><a style="cursor:pointer;" onclick="addto(15,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
325
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Magnolia.png" style="width: 16px; height: 16px; border-width: 0px;" alt="Magnolia"> Magnolia</a></span>
326
<br>
327
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Nifty Clip"><a style="cursor:pointer;" onclick="addto(17,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
328
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Niftyclip.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Nifty Clip"> Nifty Clip</a></span>
329
<br>
330
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Pookmark"><a style="cursor:pointer;" onclick="addto(19,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
331
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Pookmark.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Pookmark"> Pookmark</a></span>
332
<br>
333
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Tailrank"><a style="cursor:pointer;" onclick="addto(21,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
334
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Tailrank.png" style="width: 16px; height: 16px; border-width: 0px;" alt="Tailrank"> Tailrank</a></span>
335
<br>
336
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Technorati"><a style="cursor:pointer;" onclick="addto(23,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
337
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Technorati.png" style="width: 16px; height: 16px; border-width: 0px;" alt="Technorati"> Technorati</a></span>
338
339
  </td>
340
  <td class="odd">
341
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Google"><a style="cursor:pointer;" onclick="addto(5,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
342
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Google.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Google"> Google</a></span>
343
<br>
344
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Simpy"><a style="cursor:pointer;" onclick="addto(6,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
345
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Simpy.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Simpy"> Simpy</a></span>
346
<br>
347
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Spurl"><a style="cursor:pointer;" onclick="addto(8,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
348
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Spurl.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Spurl"> Spurl</a></span>
349
<br>
350
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Yahoo! MyWeb"><a style="cursor:pointer;" onclick="addto(7,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
351
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Yahoo.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Y!MyWeb"> Y! MyWeb</a></span>
352
<br>
353
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Blogmarks"><a style="cursor:pointer;" onclick="addto(10,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
354
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Blogmarks.png" style="width: 16px; height: 16px; border-width: 0px;" alt="Blogmarks"> Blogmarks</a></span>
355
<br>
356
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' FC2"><a style="cursor:pointer;" onclick="addto(12,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
357
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_FC2.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="FC2"> FC2 Bookmark</a></span>
358
<br>
359
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Livedoor Clip"><a style="cursor:pointer;" onclick="addto(14,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
360
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Livedoorclip.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Livedoor Clip"> Livedoor Clip</a></span>
361
<br>
362
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Netscape"><a style="cursor:pointer;" onclick="addto(16,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
363
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Netscape.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Netscape"> Netscape</a></span>
364
<br>
365
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Newsvine"><a style="cursor:pointer;" onclick="addto(18,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
366
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Newsvine.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Newsvine"> Newsvine</a></span>
367
<br>
368
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Reddit"><a style="cursor:pointer;" onclick="addto(20,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
369
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Reddit.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Reddit"> Reddit</a></span>
370
<br>
371
<span title="' . _MD_MYLINKS_BOOKMARK_ADDTO . ' Windows Live"><a style="cursor:pointer;" onclick="addto(22,\''.$siteurl_en.'\', \''.$sitetitle_en.'\')">
372
<img src="'.XOOPSMYLINKIMGURL.'/addto/AddTo_Windowslive.gif" style="width: 16px; height: 16px; border-width: 0px;" alt="Windows Live"> Windows Live</a></span>
373
  </td>
374
  </tr></table>
375
<br><br>
376
';
377
378
xoops_footer();
379