Completed
Push — master ( bbda49...c5c3b2 )
by Michael
02:49
created

main.php ➔ edit()   F

Complexity

Conditions 54
Paths > 20000

Size

Total Lines 318
Code Lines 232

Duplication

Lines 25
Ratio 7.86 %

Importance

Changes 0
Metric Value
cc 54
eloc 232
nc 4294967295
nop 1
dl 25
loc 318
rs 2
c 0
b 0
f 0

How to fix   Long Method    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 19 and the first side effect is on line 12.

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
 * $Id: main.php v 1.00 21 June 2005 John N Exp $
4
 * Module: WF-Links
5
 * Version: v1.0.3
6
 * Release Date: 21 June 2005
7
 * Developer: John N
8
 * Team: WF-Projects
9
 * Licence: GNU
10
 */
11
12
include 'admin_header.php';
13
14
$mytree = new XoopsTree( $xoopsDB -> prefix( 'wflinks_cat' ), 'cid', 'pid' );
15
16
$op = wfl_cleanRequestVars( $_REQUEST, 'op', '' );
17
$lid = intval( wfl_cleanRequestVars( $_REQUEST, 'lid', 0 ) );
18
19
function edit( $lid = 0 )
20
{
21
    global $xoopsDB, $wfmyts, $mytree, $imagearray, $xoopsConfig, $xoopsModuleConfig, $xoopsModule, $xoopsUser;
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...
22
23
    $sql = "SELECT * FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE lid=" . $lid;
24
    if ( !$result = $xoopsDB -> query( $sql ) ) {
25
        XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
26
27
        return false;
28
    }
29
    $link_array = $xoopsDB -> fetchArray( $xoopsDB -> query( $sql ) );
30
31
    $directory = $xoopsModuleConfig['screenshots'];
32
    $lid = $link_array['lid'] ? $link_array['lid'] : 0;
33
    $cid = $link_array['cid'] ? $link_array['cid'] : 0;
34
    $title = $link_array['title'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['title'] ) : '';
35
    $url = $link_array['url'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['url'] ) : 'http://';
36
    $publisher = $link_array['publisher'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['publisher'] ) : '';
37
    $submitter = $link_array['submitter'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['submitter'] ) : '';
38
    $screenshot = $link_array['screenshot'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['screenshot'] ) : '';
39
    $descriptionb = $link_array['description'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['description'] ) : '';
40
    $published = $link_array['published'] ? $link_array['published'] : time();
41
    $expired = $link_array['expired'] ? $link_array['expired'] : 0;
42
    $updated = $link_array['updated'] ? $link_array['updated'] : 0;
43
    $offline = $link_array['offline'] ? $link_array['offline'] : 0;
44
    $forumid = $link_array['forumid'] ? $link_array['forumid'] : 0;
45
    $ipaddress = $link_array['ipaddress'] ? $link_array['ipaddress'] : 0;
46
    $notifypub = $link_array['notifypub'] ? $link_array['notifypub'] : 0;
47
    $country = $link_array['country'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['country'] ) : '-';
48
    $keywords = $link_array['keywords'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['keywords'] ) : '';
49
    $item_tag = $link_array['item_tag'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['item_tag'] ) : '';
50
    $googlemap = $link_array['googlemap'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['googlemap'] ) : 'http://maps.google.com';
51
    $yahoomap = $link_array['yahoomap'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['yahoomap'] ) : 'http://maps.yahoo.com';
52
    $multimap = $link_array['multimap'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['multimap'] ) : 'http://www.multimap.com';
53
    $street1 = $link_array['street1'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['street1'] ) : '';
54
    $street2 = $link_array['street2'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['street2'] ) : '';
55
    $town = $link_array['town'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['town'] ) : '';
56
    $state = $link_array['state'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['state'] ) : '';
57
    $zip = $link_array['zip'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['zip'] ) : '';
58
    $tel = $link_array['tel'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['tel'] ) : '';
59
    $mobile = $link_array['mobile'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['mobile'] ) : '';
60
    $voip = $link_array['voip'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['voip'] ) : '';
61
    $fax = $link_array['fax'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['fax'] ) : '';
62
    $email = $link_array['email'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['email'] ) : '';
63
    $vat = $link_array['vat'] ? $wfmyts -> htmlSpecialCharsStrip( $link_array['vat'] ) : '';
64
65
    include 'admin_header.php';
66
    xoops_cp_header();
67
    xoops_load('XoopsUserUtility');
68
    //wfl_adminmenu( _AM_WFL_MLINKS );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
69
70
      if ($lid > 0) {
71
        $_vote_data = wfl_getVoteDetails( $lid );
72
        $text_info = "<table width='100%'>
73
             <tr>
74
              <td width='33%' valign='top'>
75
               <div><b>" . _AM_WFL_LINK_ID . " </b>" . $lid . "</div>
76
               <div><b>" . _AM_WFL_MINDEX_SUBMITTED . ": </b>" . formatTimestamp( $link_array['date'], $xoopsModuleConfig['dateformat'] ) . "</div>
77
               <div><b>" . _AM_WFL_LINK_SUBMITTER . " </b>" . XoopsUserUtility::getUnameFromId( $submitter ) . "</div>
78
               <div><b>" . _AM_WFL_LINK_IP . " </b>" . $ipaddress . "</div>
79
               <div><b>" . _AM_WFL_PAGERANK . " </b>" . pagerank($link_array['url']) . "</div>
80
               <div><b>" . _AM_WFL_HITS . " </b>" . $link_array['hits'] . "</div>
81
82
              </td>
83
              <td valign='top'>
84
               <div><b>" . _AM_WFL_VOTE_TOTALRATE . ": </b>" . intval( $_vote_data['rate'] ) . "</div>
85
               <div><b>" . _AM_WFL_VOTE_USERAVG . ": </b>" . intval( round( $_vote_data['avg_rate'], 2 ) ) . "</div>
86
               <div><b>" . _AM_WFL_VOTE_MAXRATE . ": </b>" . intval( $_vote_data['min_rate'] ) . "</div>
87
               <div><b>" . _AM_WFL_VOTE_MINRATE . ": </b>" . intval( $_vote_data['max_rate'] ) . "</div>
88
              </td>
89
              <td valign='top'>
90
               <div><b>" . _AM_WFL_VOTE_MOSTVOTEDTITLE . ": </b>" . intval( $_vote_data['max_title'] ) . "</div>
91
                   <div><b>" . _AM_WFL_VOTE_LEASTVOTEDTITLE . ": </b>" . intval( $_vote_data['min_title'] ) . "</div>
92
               <div><b>" . _AM_WFL_VOTE_REGISTERED . ": </b>" . ( intval( $_vote_data['rate'] - $_vote_data['null_ratinguser'] ) ) . "</div>
93
               <div><b>" . _AM_WFL_VOTE_NONREGISTERED . ": </b>" . intval( $_vote_data['null_ratinguser'] ) . "</div>
94
              </td>
95
             </tr>
96
            </table>";
97
        echo "<fieldset style='border: #e8e8e8 1px solid;'><legend style='display: inline; font-weight: bold; color: #0A3760;'>" . _AM_WFL_INFORMATION . "</legend>\n
98
            <div style='padding: 8px;'>" . $text_info . "</div>\n
99
        <!--	<div style='padding: 8px;'><li>" . $imagearray['deleteimg'] . " " . _AM_WFL_VOTE_DELETEDSC . "</li></div>\n  -->
100
            </fieldset>\n
101
            <br />\n";
102
    }
103
    unset( $_vote_data );
104
105
    $caption = ( $lid ) ? _AM_WFL_LINK_MODIFYFILE : _AM_WFL_LINK_CREATENEWFILE;
106
    $sform = new XoopsThemeForm( $caption, "storyform", xoops_getenv( 'PHP_SELF' ) );
107
    $sform -> setExtra( 'enctype="multipart / form - data"' );
108
109
    if ($submitter == '') {
110
      $sform -> addElement( new XoopsFormHidden( 'submitter', $submitter ) );
111
    }
112
113
// Link publisher form
114
    if ($publisher) {
115
      $sform -> addElement( new XoopsFormText( _AM_WFL_LINK_PUBLISHER, 'publisher', 70, 255, $publisher ) );
116
      //$sform -> addElement( new XoopsFormHidden( 'publisher', $publisher ) ) ;
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...
117
    } else {
118
      $publisher = $xoopsUser -> uname();
119
      $sform -> addElement( new XoopsFormHidden( 'publisher', $publisher ) );
120
    }
121
122
// Link title form
123
    $sform -> addElement( new XoopsFormText( _AM_WFL_LINK_TITLE, 'title', 70, 255, $title ), true );
124
125
// Link url form
126
    $url_text = new XoopsFormText('', 'url', 70, 255, $url);
127
    $url_tray = new XoopsFormElementTray(_AM_WFL_LINK_DLURL, '');
128
    $url_tray -> addElement( $url_text, true) ;
129
    $url_tray -> addElement( new XoopsFormLabel( "&nbsp;<img src='../assets/images/icon/world.png' onClick=\"window.open(document.storyform.url.value,'','');return(false);\" alt='Check URL' />" ));
130
    $sform -> addElement( $url_tray );
131
132
// Category form
133
    ob_start();
134
    $mytree -> makeMySelBox( 'title', 'title', $cid, 0 );
135
    $sform -> addElement( new XoopsFormLabel( _AM_WFL_LINK_CATEGORY, ob_get_contents() ) );
136
    ob_end_clean();
137
138
// Link description form
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
139
//    $editor = wfl_getWysiwygForm( _AM_WFL_LINK_DESCRIPTION, 'descriptionb', $descriptionb, 15, 60 );
140
//    $sform -> addElement($editor, false);
141
    $optionsTrayNote = new XoopsFormElementTray(_AM_WFL_LINK_DESCRIPTION, '<br />');
142 View Code Duplication
    if (class_exists('XoopsFormEditor')) {
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...
143
        $options['name']   = 'descriptionb';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = 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...
144
        $options['value']  = $descriptionb;
145
        $options['rows']   = 5;
146
        $options['cols']   = '100%';
147
        $options['width']  = '100%';
148
        $options['height'] = '200px';
149
        $descriptionb      = new XoopsFormEditor('', $xoopsModuleConfig['form_options'], $options, $nohtml = FALSE, $onfailure = 'textarea');
150
        $optionsTrayNote->addElement($descriptionb);
151
    } else {
152
        $descriptionb = new XoopsFormDhtmlTextArea('', 'descriptionb', $item->getVar('descriptionb', 'e'), '100%', '100%');
0 ignored issues
show
Bug introduced by
The variable $item does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
153
        $optionsTrayNote->addElement($descriptionb);
154
    }
155
156
    $sform->addElement($optionsTrayNote, FALSE);
157
158
// Meta keywords form
159
    $keywords = new XoopsFormTextArea( _AM_WFL_KEYWORDS, 'keywords', $keywords, 7, 60, false );
160
    $keywords -> setDescription( "<small>" . _AM_WFL_KEYWORDS_NOTE . "</small>");
161
    $sform -> addElement($keywords);
162
163
// Insert tags if Tag-module is installed
164 View Code Duplication
    if (wfl_tag_module_included()) {
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...
165
      include_once XOOPS_ROOT_PATH . "/modules/tag/include/formtag.php";
166
      $text_tags = new XoopsFormTag("item_tag", 70, 255, $link_array['item_tag'], 0);
167
      $sform -> addElement( $text_tags );
168
    } else {
169
      $sform -> addElement( new XoopsFormHidden( 'item_tag', $link_array['item_tag'] ) );
170
    }
171
172
// Screenshot
173
    $graph_array = &wflLists :: getListTypeAsArray( XOOPS_ROOT_PATH . "/" . $xoopsModuleConfig['screenshots'], $type = "images" );
174
    $indeximage_select = new XoopsFormSelect( '', 'screenshot', $screenshot );
175
    $indeximage_select -> addOptionArray( $graph_array );
176
    $indeximage_select -> setExtra( "onchange = 'showImgSelected(\"image\", \"screenshot\", \"" . $xoopsModuleConfig['screenshots'] . "\", \"\", \"" . XOOPS_URL . "\")'" );
177
    $indeximage_tray = new XoopsFormElementTray( _AM_WFL_LINK_SHOTIMAGE, '&nbsp;' );
178
    $indeximage_tray -> setDescription( sprintf( _AM_WFL_LINK_MUSTBEVALID, "<b>" . $directory . "</b>" ));
179
    $indeximage_tray -> addElement( $indeximage_select );
180 View Code Duplication
    if ( !empty( $imgurl ) ) {
0 ignored issues
show
Bug introduced by
The variable $imgurl seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
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...
181
        $indeximage_tray -> addElement( new XoopsFormLabel( '', " <br /><br />< img src='" . XOOPS_URL . "/" . $xoopsModuleConfig['screenshots'] . "/" . $screenshot . "' name = 'image' id = 'image' alt = '' / > " ) );
182
    } else {
183
        $indeximage_tray -> addElement( new XoopsFormLabel( '', " <br /><br /><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt='' / > " ) );
184
    }
185
    $sform -> addElement( $indeximage_tray );
186
187
if ($xoopsModuleConfig['useaddress']) {
188
    $sform -> insertBreak( _AM_WFL_LINK_CREATEADDRESS, "bg3" );
189
// Google Maps
190
    $googlemap_text = new XoopsFormText( '', 'googlemap', 70, 1024, $googlemap );
191
    $googlemap_tray = new XoopsFormElementTray( _AM_WFL_LINK_GOOGLEMAP, '' );
192
    $googlemap_tray -> addElement( $googlemap_text , false ) ;
193
    $googlemap_tray -> addElement( new XoopsFormLabel( "&nbsp;<img src='../assets/images/icon/google_map.png' onClick=\"window.open(document.storyform.googlemap.value,'','');return(false);\" alt='"._AM_WFL_LINK_CHECKMAP."' />" ) );
194
    $sform -> addElement( $googlemap_tray );
195
// Yahoo Maps
196
    $yahoomap_text = new XoopsFormText( '', 'yahoomap', 70, 1024, $yahoomap );
197
    $yahoomap_tray = new XoopsFormElementTray( _AM_WFL_LINK_YAHOOMAP, '' );
198
    $yahoomap_tray -> addElement( $yahoomap_text , false ) ;
199
    $yahoomap_tray -> addElement( new XoopsFormLabel( "&nbsp;<img src='../assets/images/icon/yahoo_map.png' onClick=\"window.open(document.storyform.yahoomap.value,'','');return(false);\" alt='"._AM_WFL_LINK_CHECKMAP."' />" ) );
200
    $sform -> addElement( $yahoomap_tray );
201
// MS Live Maps
202
    $multimap_text = new XoopsFormText( '', 'multimap', 70, 1024, $multimap );
203
    $multimap_tray = new XoopsFormElementTray( _AM_WFL_LINK_MULTIMAP, '' );
204
    $multimap_tray -> addElement( $multimap_text , false ) ;
205
    $multimap_tray -> addElement( new XoopsFormLabel( "&nbsp;<img src='../assets/images/icon/multimap.png' onClick=\"window.open(document.storyform.multimap.value,'','');return(false);\" alt='"._AM_WFL_LINK_CHECKMAP."' />" ) );
206
    $sform -> addElement( $multimap_tray );
207
208
// Address
209
    $street1 = new XoopsFormText( _AM_WFL_STREET1, 'street1', 70, 255, $street1 );
210
    $sform -> addElement( $street1, false );
211
    $street2 = new XoopsFormText( _AM_WFL_STREET2, 'street2', 70, 255, $street2 );
212
    $sform -> addElement( $street2, false );
213
    $town = new XoopsFormText( _AM_WFL_TOWN, 'town', 70, 255, $town );
214
    $sform -> addElement( $town, false );
215
    $state = new XoopsFormText( _AM_WFL_STATE, 'state', 70, 255, $state );
216
    $sform -> addElement( $state, false );
217
    $zip = new XoopsFormText( _AM_WFL_ZIPCODE, 'zip', 25, 25, $zip );
218
    $sform -> addElement( $zip, false );
219
    $tel = new XoopsFormText( _AM_WFL_TELEPHONE, 'tel', 25, 25, $tel );
220
    $sform -> addElement( $tel, false );
221
    $mobile = new XoopsFormText( _AM_WFL_MOBILE, 'mobile', 25, 25, $mobile );
222
    $sform -> addElement( $mobile, false );
223
    $voip = new XoopsFormText( _AM_WFL_VOIP, 'voip', 25, 25, $voip );
224
    $sform -> addElement( $voip, false );
225
    $fax = new XoopsFormText( _AM_WFL_FAX, 'fax', 25, 25, $fax );
226
    $sform -> addElement( $fax, false );
227
    $email = new XoopsFormText( _AM_WFL_EMAIL, 'email', 25, 60, $email );
228
    $sform -> addElement( $email, false );
229
    $vat = new XoopsFormText( _AM_WFL_VAT, 'vat', 25, 25, $vat );
230
    $vat -> setDescription( _AM_WFL_VATWIKI );
231
    $sform -> addElement( $vat, false );
232
//  $sform -> addElement( new XoopsFormHidden( 'vat', $link_array['vat'] ) ); /* If you don't want to use the VAT form,  */
233
                                                                              /* use this line and comment-out the 3 lines above  */
234
}
235
236
// Country form
237
    $country_select = new XoopsFormSelectCountry( _AM_WFL_COUNTRY, 'country', $country );
238
    $sform -> addElement( $country_select, false );
239
240
// Miscellaneous Link settings
241
    $sform -> insertBreak( _AM_WFL_LINK_MISCLINKSETTINGS, 'bg3' );
242
243
// Set Publish date
244
    $sform -> addElement( new XoopsFormDateTime( _AM_WFL_LINK_SETPUBLISHDATE, 'published', $size = 15, $published ));
245
246
    if ($lid) {
247
        $sform -> addElement( new XoopsFormHidden( 'was_published', $published ) );
248
        $sform -> addElement( new XoopsFormHidden( 'was_expired', $expired ) );
249
    }
250
251
// Set Expire date
252
    $isexpired = ( $expired > time() ) ? 1: 0 ;
253
    $expiredates = ( $expired > time() ) ? _AM_WFL_LINK_EXPIREDATESET . formatTimestamp( $expired, $xoopsModuleConfig['dateformat'] ) : _AM_WFL_LINK_SETDATETIMEEXPIRE;
254
    $warning = ( $published > $expired && $expired > time() ) ? _AM_WFL_LINK_EXPIREWARNING : '';
255
    $expiredate_checkbox = new XoopsFormCheckBox( '', 'expiredateactivate', $isexpired );
256
    $expiredate_checkbox -> addOption( 1, $expiredates . " <br /> <br /> " );
257
258
    $expiredate_tray = new XoopsFormElementTray( _AM_WFL_LINK_EXPIREDATE . $warning, '' );
259
    $expiredate_tray -> addElement( $expiredate_checkbox );
260
    $expiredate_tray -> addElement( new XoopsFormDateTime( _AM_WFL_LINK_SETEXPIREDATE . " <br /> ", 'expired', 15, $expired ) );
261
    $expiredate_tray -> addElement( new XoopsFormRadioYN( _AM_WFL_LINK_CLEAREXPIREDATE, 'clearexpire', 0, ' ' . _YES . '', ' ' . _NO . '' ) );
262
    $sform -> addElement( $expiredate_tray );
263
264
// Set Link offline
265
    $linkstatus_radio = new XoopsFormRadioYN( _AM_WFL_LINK_FILESSTATUS, 'offline', $offline, ' ' . _YES . '', ' ' . _NO . '' );
266
    $sform -> addElement( $linkstatus_radio );
267
268
// Set Link updated
269
    $up_dated = ( $updated == 0 ) ? 0 : 1;
270
    $link_updated_radio = new XoopsFormRadioYN( _AM_WFL_LINK_SETASUPDATED, 'up_dated', $up_dated, ' ' . _YES . '', ' ' . _NO . '' );
271
    $sform -> addElement( $link_updated_radio );
272
273
    $result = $xoopsDB -> query( "SELECT COUNT( * ) FROM " . $xoopsDB -> prefix( 'wflinks_broken' ) . " WHERE lid = " . $lid );
274
    list ( $broken_count ) = $xoopsDB -> fetchRow( $result );
275
    if ($broken_count > 0) {
276
        $link_updated_radio = new XoopsFormRadioYN( _AM_WFL_LINK_DELEDITMESS, 'delbroken', 1, ' ' . _YES . '', ' ' . _NO . '' );
0 ignored issues
show
Unused Code introduced by
$link_updated_radio is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
277
        $sform -> addElement( $editmess_radio );
0 ignored issues
show
Bug introduced by
The variable $editmess_radio does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
278
    }
279
280
// Select forum
281
    ob_start();
282
    wflLists :: getforum( $xoopsModuleConfig['selectforum'], $forumid );
283
    $sform -> addElement( new XoopsFormLabel( _AM_WFL_LINK_DISCUSSINFORUM, ob_get_contents() ) );
284
    ob_end_clean();
285
286
//Create News Story
287
    if (wfl_news_module_included()) {
288
      $sform -> insertBreak( _AM_WFL_LINK_CREATENEWSSTORY, "bg3" );
289
      $submitNews_radio = new XoopsFormRadioYN( _AM_WFL_LINK_SUBMITNEWS, 'submitnews', 0, ' ' . _YES . '', ' ' . _NO . '' );
290
      $sform -> addElement( $submitNews_radio );
291
292
      include_once XOOPS_ROOT_PATH . '/class/xoopstopic.php';
293
      $xt = new XoopsTopic( $xoopsDB -> prefix( 'topics' ) );
294
      ob_start();
295
         $xt -> makeTopicSelBox( 1, 0, "newstopicid" );
296
         $sform -> addElement( new XoopsFormLabel( _AM_WFL_LINK_NEWSCATEGORY, ob_get_contents() ) );
297
      ob_end_clean();
298
      $sform -> addElement( new XoopsFormText( _AM_WFL_LINK_NEWSTITLE, 'newsTitle', 70, 255, '' ), false );
299
    }
300
301
    if ($lid && $published == 0) {
302
        $approved = ( $published == 0 ) ? 0 : 1;
0 ignored issues
show
Unused Code introduced by
$approved is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
303
        $approve_checkbox = new XoopsFormCheckBox( _AM_WFL_LINK_EDITAPPROVE, "approved", 1 );
304
        $approve_checkbox -> addOption( 1, " " );
305
        $sform -> addElement( $approve_checkbox );
306
    }
307
308
    if (!$lid) {
309
        $button_tray = new XoopsFormElementTray( '', '' );
310
        $button_tray -> addElement( new XoopsFormHidden( 'status', 1 ) );
311
        $button_tray -> addElement( new XoopsFormHidden( 'notifypub', $notifypub ) );
312
        $button_tray -> addElement( new XoopsFormHidden( 'op', 'save' ) );
313
        $button_tray -> addElement( new XoopsFormButton( '', '', _AM_WFL_BSAVE, 'submit' ) );
314
        $sform -> addElement( $button_tray );
315
    } else {
316
        $button_tray = new XoopsFormElementTray( '', '' );
317
        $button_tray -> addElement( new XoopsFormHidden( 'lid', $lid ) );
318
        $button_tray -> addElement( new XoopsFormHidden( 'status', 2 ) );
319
        $hidden = new XoopsFormHidden( 'op', 'save' );
320
        $button_tray -> addElement( $hidden );
321
322
        $butt_dup = new XoopsFormButton( '', '', _AM_WFL_BMODIFY, 'submit' );
323
        $butt_dup -> setExtra( 'onclick="this . form . elements . op . value = \'save\'"' );
324
        $button_tray -> addElement( $butt_dup );
325
        $butt_dupct = new XoopsFormButton( '', '', _AM_WFL_BDELETE, 'submit' );
326
        $butt_dupct -> setExtra( 'onclick="this.form.elements.op.value=\'delete\'"' );
327
        $button_tray -> addElement( $butt_dupct );
328
        $butt_dupct2 = new XoopsFormButton( '', '', _AM_WFL_BCANCEL, 'submit' );
329
        $butt_dupct2 -> setExtra( 'onclick="this.form.elements.op.value=\'linksConfigMenu\'"' );
330
        $button_tray -> addElement( $butt_dupct2 );
331
        $sform -> addElement( $button_tray );
332
    }
333
    $sform -> display();
334
    unset( $hidden );
335
    include_once 'admin_footer.php';
336
}
337
338
function fetchURL( $url, $timeout = 2 )
339
{
340
    $url = urldecode( $url );
341
    $url_parsed = parse_url( $url );
342
    if ( !isset( $url_parsed["host"] ) ) {
343
        return '';
344
    }
345
346
    $host = $url_parsed["host"];
347
    $host = preg_replace( "#http://#", "", $host );
348
    $port = ( isset( $url_parsed["port"] ) ) ? $url_parsed["port"]: 80;
349
    // Open the socket
350
    $handle = @fsockopen( 'http://' . $host, $port, $errno, $errstr, $timeout );
351
    if (!$handle) {
352
        return null;
353
    } else {
354
        // Set read timeout
355
        stream_set_timeout( $handle, $timeout );
356
        for ($i = 0;$i < 1;++$i) {
0 ignored issues
show
Unused Code introduced by
++$i; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
357
            // Time the responce
358
            list( $usec, $sec ) = explode( " ", microtime( true ) );
359
            $start = (float) $usec + (float) $sec;
360
            // send somthing
361
            $write = fwrite( $handle, "return ping\n" );
362
            if (!$write) {
363
                return '';
364
            }
365
            fread( $handle, 1024 );
366
            // Work out if we got a responce and time it
367
            list( $usec, $sec ) = explode( " ", microtime( true ) );
368
            $laptime = ( (float) $usec + (float) $sec ) - $start;
369
            if ($laptime > $timeout) {
370
                return 'No Reply';
371
            } else {
372
                return round( $laptime, 3 );
373
            }
374
        }
375
        fclose( $handle );
376
    }
377
}
378
379
switch ( strtolower( $op ) ) {
380
    case "pingtime";
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

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

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

Loading history...
381
    case "is_broken";
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

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

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

Loading history...
382
383
        $_type = ( $op == "pingtime" ) ? "is_broken" : "pingtime";
384
385
        $start = wfl_cleanRequestVars( $_REQUEST, 'start', 0 );
386
        $ping = wfl_cleanRequestVars( $_REQUEST, 'ping', 0 );
387
        $cid = wfl_cleanRequestVars( $_REQUEST, 'cid', 0 );
388
389
        $sql = "SELECT * FROM " . $xoopsDB -> prefix( 'wflinks_links' );
390
        if ($cid > 0) {
391
            $sql .= " WHERE cid=" . $cid;
392
        }
393
        $sql .= " ORDER BY lid DESC";
394
        if ( !$result = $xoopsDB -> query( $sql ) ) {
395
            XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
396
397
            return false;
398
        }
399
        $broken_array = $xoopsDB -> query( $sql, $xoopsModuleConfig['admin_perpage'], $start );
400
        $broken_array_count = $xoopsDB -> getRowsNum( $result );
401
402
        $heading = ( $op == "pingtime" ) ? _AM_WFL_PINGTIMES : _AM_WFL_LISTBROKEN;
403
404
        include 'admin_header.php';
405
        xoops_cp_header();
406
//        wfl_adminmenu( _AM_WFL_BINDEX, '', $heading );
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...
407
        echo "
408
            <table width='100%' cellspacing='1' cellpadding='2' border='0' class='outer'>\n
409
            <tr>\n
410
            <th style='text-align: center;'>" . _AM_WFL_MINDEX_ID . "</th>\n
411
            <th style='text-align: left;'><b>" . _AM_WFL_MINDEX_TITLE . "</th>\n
412
            <th style='text-align: center;'>"._AM_WFL_MINDEX_POSTER."</th>\n
413
            <th style='text-align: center;'>" . _AM_WFL_MINDEX_PUBLISHED . "</th>\n
414
                    <th style='text-align: center;'>" . _AM_WFL_MINDEX_RESPONSE . "</th>\n
415
                        <th style='text-align: center;'>PR</th>\n
416
                    <th style='text-align: center;'>" . _AM_WFL_MINDEX_ACTION . "</th>\n
417
            </tr>\n
418
        ";
419
420
        if ($broken_array_count > 0) {
421
            while ( $published = $xoopsDB -> fetchArray( $broken_array ) ) {
422
                $_ping_results = fetchURL( $published['url'] );
423
424
                if (!$_ping_results) {
425
                    $_ping_results = _AM_WFL_LINK_NORESPONSE;
426
                } else {
427
                    $_ping_results = $_ping_results . '(s)';
428
                }
429
430
                $lid = $published['lid'];
431
                $cid = $published['cid'];
432
                $title = "<a href='../singlelink.php?cid=" . $published['cid'] . "&amp;lid=" . $published['lid'] . "'>" . $wfmyts -> htmlSpecialCharsStrip( trim( $published['title'] ) ) . "</a>";;
433
                $maintitle = urlencode( $wfmyts -> htmlSpecialChars( trim( $published['title'] ) ) );
434
                $submitter = XoopsUserUtility::getUnameFromId( $published['submitter'] );
435
                $publish = formatTimestamp( $published['published'], $xoopsModuleConfig['dateformatadmin'] );
436
                $status = ( $published['published'] > 0 ) ? $imagearray['online'] : "<a href='newlinks.php'>" . $imagearray['offline'] . "</a>";
437
                $icon = "<a href='main.php?op=edit&amp;lid=" . $lid . "'>" . $imagearray['editimg'] . "</a>&nbsp;";
438
                $icon .= "<a href='main.php?op=delete&amp;lid=" . $lid . "'>" . $imagearray['deleteimg'] . "</a>";
439
                echo "<tr style='text-align: center;'>\n
440
                        <td class='head'><small>" . $lid . "</small></td>\n
441
                        <td class='even' style='text-align: left;'><small>" . $title . "</small></td>\n
442
                        <td class='even'><small>" . $submitter . "</small></td>\n
443
                        <td class='even'><small>" . $publish . "</small></td>\n
444
                        <td class='even'><small>" . $_ping_results . "</small></td>\n
445
                        <td class='even'><small>" . pagerank($published['url']) . "</small></td>\n
446
                        <td class='even'>$icon</td>\n
447
                        </tr>\n";
448
                unset( $published );
449
            }
450
        } else {
451
            wfl_linklistfooter();
452
        }
453
        wfl_linklistpagenav( $broken_array_count, $start, 'art', 'op=' . $op );
454
        include_once 'admin_footer.php';
455
        break;
456
457
    case "edit":
458
        edit( $lid );
459
        break;
460
461
    case "save":
462
        $groups = isset( $_POST['groups'] ) ? $_POST['groups'] : array();
463
        $lid = ( !empty( $_POST['lid'] ) ) ? $_POST['lid'] : 0;
464
        $cid = ( !empty( $_POST['cid'] ) ) ? $_POST['cid'] : 0;
465
        $urlrating = ( !empty( $_POST['urlrating'] ) ) ? $_POST['urlrating'] : 6;
466
        $status = ( !empty( $_POST['status'] ) ) ? $_POST['status'] : 2;
467
        $url = ( $_POST["url"] != "http://" ) ? $wfmyts -> addslashes( $_POST["url"] ) : '';
468
        $title = $wfmyts -> addslashes( trim( $_POST["title"] ) );
469
470
// Get data from form
471
        $screenshot = ( $_POST["screenshot"] != "blank.gif" ) ? $wfmyts -> addslashes( $_POST["screenshot"] ) : '';
472
        $descriptionb = $wfmyts -> addslashes( trim( $_POST["descriptionb"] ) );
473
        $country = $wfmyts -> addslashes( trim( $_POST["country"] ) );
474
        $keywords = $wfmyts -> addslashes( trim(substr($_POST["keywords"], 0, $xoopsModuleConfig['keywordlength']) ) );
475
        $item_tag = $wfmyts -> addslashes( trim( $_POST["item_tag"] ) );
476
        $forumid = ( isset( $_POST["forumid"] ) && $_POST["forumid"] > 0 ) ? intval( $_POST["forumid"] ) : 0;
477 View Code Duplication
        if ($xoopsModuleConfig['useaddress']) {
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...
478
           $googlemap = ( $_POST["googlemap"] != "http://maps.google.com" ) ? $wfmyts -> addslashes( $_POST["googlemap"] ) : '';
479
           $yahoomap = ( $_POST["yahoomap"] != "http://maps.yahoo.com" ) ? $wfmyts -> addslashes( $_POST["yahoomap"] ) : '';
480
           $multimap = ( $_POST["multimap"] != "http://www.multimap.com" ) ? $wfmyts -> addslashes( $_POST["multimap"] ) : '';
481
           $street1 = $wfmyts -> addslashes( trim( $_POST["street1"] ) );
482
           $street2 = $wfmyts -> addslashes( trim( $_POST["street2"] ) );
483
           $town = $wfmyts -> addslashes( trim( $_POST["town"] ) );
484
           $state = $wfmyts -> addslashes( trim( $_POST["state"] ) );
485
           $zip = $wfmyts -> addslashes( trim( $_POST["zip"] ) );
486
           $tel = $wfmyts -> addslashes( trim( $_POST["tel"] ) );
487
           $fax = $wfmyts -> addslashes( trim( $_POST["fax"] ) );
488
           $voip = $wfmyts -> addslashes( trim( $_POST["voip"] ) );
489
           $mobile = $wfmyts -> addslashes( trim( $_POST["mobile"] ) );
490
           $email = emailcnvrt($wfmyts -> addslashes( trim( $_POST["email"] ) ));
491
           $vat = $wfmyts -> addslashes( trim( $_POST["vat"] ) );
492
        } else {
493
           $googlemap = $yahoomap = $multimap = $street1 = $street2 = $town = $state = $zip = $tel = $fax = $voip = $mobile = $email = $vat = '';
494
        }
495
496
        $submitter = $xoopsUser -> uid();
497
        $publisher = $wfmyts -> addslashes( trim( $_POST["publisher"] ) );
498
499
        $published =  strtotime($_POST['published']['date'] ) + $_POST['published']['time'];
500
        $updated = ( isset( $_POST['was_published'] ) && $_POST['was_published'] == 0 ) ? 0 : time();
501
        if ($_POST['up_dated'] == 0) {
502
            $updated = 0;
503
            $status = 1;
504
        }
505
        $offline = ( $_POST['offline'] == 1 ) ? 1 : 0;
506
        $approved = ( isset( $_POST['approved'] ) && $_POST['approved'] == 1 ) ? 1 : 0;
507
        $notifypub = ( isset( $_POST['notifypub'] ) && $_POST['notifypub'] == 1 );
508
        if (!$lid) {
509
            $date = time();
510
            $publishdate = time();
511
            $expiredate = '0';
512
        } else {
513
            $publishdate = $_POST['was_published'];
514
            $expiredate = $_POST['was_expired'];
515
        }
516
        if ( $approved == 1 && empty( $publishdate ) ) {
517
            $publishdate = time();
518
        }
519
        if ( isset( $_POST['expiredateactivate'] ) ) {
520
            $expiredate = strtotime( $_POST['expired']['date'] ) + $_POST['expired']['time'];
521
        }
522
        if ($_POST['clearexpire']) {
523
            $expiredate = '0';
524
        }
525
526
// Update or insert linkload data into database
527
        if (!$lid) {
528
            $date = time();
529
            $publishdate = time();
530
            $ipaddress = $_SERVER['REMOTE_ADDR'];
531
            $sql = "INSERT INTO " . $xoopsDB -> prefix( 'wflinks_links' ) . " (lid, cid, title, url, screenshot, submitter, publisher, status, date, hits, rating, votes, comments, forumid, published, expired, updated, offline, description, ipaddress, notifypub, urlrating, country, keywords, item_tag, googlemap, yahoomap, multimap, street1, street2, town, state, zip, tel, fax, voip, mobile, email, vat )";
532
            $sql .= " VALUES 	('', $cid, '$title', '$url', '$screenshot', '$submitter', '$publisher','$status', '$date', 0, 0, 0, 0, '$forumid', '$published', '$expiredate', '$updated', '$offline', '$descriptionb', '$ipaddress', '0', '$urlrating', '$country', '$keywords', '$item_tag', '$googlemap', '$yahoomap', '$multimap', '$street1', '$street2', '$town', '$state', '$zip', '$tel', '$fax', '$voip', '$mobile', '$email', '$vat' )";
533
           // $newid = $xoopsDB -> getInsertId();
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
534
        } else {
535
            $sql = "UPDATE " . $xoopsDB -> prefix( 'wflinks_links' ) . " SET cid = $cid, title='$title', url='$url', screenshot='$screenshot', publisher='$publisher', status='$status', forumid='$forumid', published='$published', expired='$expiredate', updated='$updated', offline='$offline', description='$descriptionb', urlrating='$urlrating', country='$country', keywords='$keywords', item_tag='$item_tag', googlemap='$googlemap', yahoomap='$yahoomap', multimap='$multimap', street1='$street1', street2='$street2', town='$town', state='$state',  zip='$zip', tel='$tel', fax='$fax', voip='$voip', mobile='$mobile', email='$email', vat='$vat' WHERE lid=" . $lid;
536
        }
537
        if ( !$result = $xoopsDB -> queryF( $sql ) ) {
538
          XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
539
540
          return false;
541
        }
542
543
        $newid = mysql_insert_id();
544
545
// Add item_tag to Tag-module
546 View Code Duplication
        if (!$lid) {
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...
547
          $tagupdate = wfl_tagupdate($newid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as wfl_tagupdate($newid, $item_tag) (which targets wfl_tagupdate()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
548
        } else {
549
          $tagupdate = wfl_tagupdate($lid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as wfl_tagupdate($lid, $item_tag) (which targets wfl_tagupdate()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
550
        }
551
552
// Send notifications
553
        if (!$lid) {
554
            $tags = array();
555
            $tags['LINK_NAME'] = $title;
556
            $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule -> getVar( 'dirname' ) . '/singlelink.php?cid=' . $cid . '&amp;lid=' . $newid;
557
            $sql = "SELECT title FROM " . $xoopsDB -> prefix( 'wflinks_cat' ) . " WHERE cid=" . $cid;
558
            $result = $xoopsDB -> query( $sql );
559
            $row = $xoopsDB -> fetchArray( $xoopsDB -> query( $sql ) );
560
            $tags['CATEGORY_NAME'] = $row['title'];
561
            $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule -> getVar( 'dirname' ) . '/viewcat.php?cid=' . $cid;
562
            $notification_handler = &xoops_gethandler( 'notification' );
563
            $notification_handler -> triggerEvent( 'global', 0, 'new_link', $tags );
564
            $notification_handler -> triggerEvent( 'category', $cid, 'new_link', $tags );
565
        }
566
        if ($lid && $approved && $notifypub) {
567
            $tags = array();
568
            $tags['LINK_NAME'] = $title;
569
            $tags['LINK_URL'] = XOOPS_URL . '/modules/' . $xoopsModule -> getVar( 'dirname' ) . '/singlelink.php?cid=' . $cid . '&amp;lid=' . $lid;
570
            $sql = "SELECT title FROM " . $xoopsDB -> prefix( 'wflinks_cat' ) . " WHERE cid=" . $cid;
571
            $result = $xoopsDB -> query( $sql );
572
            $row = $xoopsDB -> fetchArray( $result );
573
            $tags['CATEGORY_NAME'] = $row['title'];
574
            $tags['CATEGORY_URL'] = XOOPS_URL . '/modules/' . $xoopsModule -> getVar( 'dirname' ) . '/viewcat.php?cid=' . $cid;
575
            $notification_handler = &xoops_gethandler( 'notification' );
576
            $notification_handler -> triggerEvent( 'global', 0, 'new_link', $tags );
577
            $notification_handler -> triggerEvent( 'category', $cid, 'new_link', $tags );
578
            $notification_handler -> triggerEvent( 'link', $lid, 'approve', $tags );
579
        }
580
        $message = ( !$lid ) ? _AM_WFL_LINK_NEWFILEUPLOAD : _AM_WFL_LINK_FILEMODIFIEDUPDATE ;
581
        $message = ( $lid && !$_POST['was_published'] && $approved ) ? _AM_WFL_LINK_FILEAPPROVED : $message;
582
        if ( wfl_cleanRequestVars( $_REQUEST, 'delbroken', 0 ) ) {
583
            $sql = "DELETE FROM " . $xoopsDB -> prefix( 'wflinks_broken' ) . " WHERE lid=" . $lid;
584
            if ( !$result = $xoopsDB -> queryF( $sql ) ) {
585
                XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
586
587
                return false;
588
            }
589
        }
590
        if ( wfl_cleanRequestVars( $_REQUEST, 'submitnews', 0 ) ) {
591
            include_once 'newstory.php';
592
        }
593
        redirect_header( "main.php", 1, $message );
594
        break;
595
596
    case "delete":
597
        if ( wfl_cleanRequestVars( $_REQUEST, 'confirm', 0 ) ) {
598
            $title = wfl_cleanRequestVars( $_REQUEST, 'title', 0 );
599
600
            // delete link
601
            $sql = "DELETE FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE lid=" . $lid;
602
            if ( !$result = $xoopsDB -> query( $sql ) ) {
603
                XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
604
605
                return false;
606
            }
607
608
            // delete from altcat
609
            $sql = "DELETE FROM " . $xoopsDB -> prefix( 'wflinks_altcat' ) . " WHERE lid=" . $lid;
610
            if ( !$result = $xoopsDB -> query( $sql ) ) {
611
                XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
612
613
                return false;
614
            }
615
616
            // delete vote data
617
            $sql = "DELETE FROM " . $xoopsDB -> prefix( 'wflinks_votedata' ) . " WHERE lid=" . $lid;
618
            if ( !$result = $xoopsDB -> query( $sql ) ) {
619
                XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
620
621
                return false;
622
            }
623
624
            // delete comments
625
            xoops_comment_delete( $xoopsModule -> getVar( 'mid' ), $lid );
626
            redirect_header( "main.php", 1, sprintf( _AM_WFL_LINK_FILEWASDELETED, $title ) );
627
            exit();
628
        } else {
629
            $sql = "SELECT lid, title, item_tag, url FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE lid=" . $lid;
630
            if ( !$result = $xoopsDB -> query( $sql ) ) {
631
                XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
632
633
                return false;
634
            }
635
            list( $lid, $title ) = $xoopsDB -> fetchrow( $result );
636
            $item_tag = $result['item_tag'];
637
            include 'admin_header.php';
638
            xoops_cp_header();
639
            //wfl_adminmenu( _AM_WFL_BINDEX );
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
640
            xoops_confirm( array( 'op' => 'delete', 'lid' => $lid, 'confirm' => 1, 'title' => $title ), 'main.php', _AM_WFL_LINK_REALLYDELETEDTHIS . "<br /><br>" . $title, _DELETE );
641
642
            // Remove item_tag from Tag-module
643
            $tagupdate = wfl_tagupdate($lid, $item_tag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tagupdate is correct as wfl_tagupdate($lid, $item_tag) (which targets wfl_tagupdate()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
644
645
            include_once 'admin_footer.php';
646
        }
647
        break;
648
649
    case "delvote":
650
        $rid = wfl_cleanRequestVars( $_REQUEST, 'rid', 0 );
651
        $sql = "DELETE FROM " . $xoopsDB -> prefix( 'wflinks_votedata' ) . " WHERE ratingid=" . $rid;
652
        if ( !$result = $xoopsDB -> queryF( $sql ) ) {
653
            XoopsErrorHandler_HandleError( E_USER_WARNING, $sql, __FILE__, __LINE__ );
654
655
            return false;
656
        }
657
        wfl_updaterating( $rid );
658
        redirect_header( "main.php", 1, _AM_WFL_VOTE_VOTEDELETED );
659
        break;
660
661
    case 'main':
662
    default:
663
        $start = wfl_cleanRequestVars( $_REQUEST, 'start', 0 );
664
        $start1 = wfl_cleanRequestVars( $_REQUEST, 'start1', 0 );
665
        $start2 = wfl_cleanRequestVars( $_REQUEST, 'start2', 0 );
666
        $start3 = wfl_cleanRequestVars( $_REQUEST, 'start3', 0 );
667
        $start4 = wfl_cleanRequestVars( $_REQUEST, 'start4', 0 );
668
        $totalcats = wfl_totalcategory();
669
670
        $result = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( 'wflinks_broken' ) );
671
        list( $totalbrokenlinks ) = $xoopsDB -> fetchRow( $result );
672
        $result2 = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( 'wflinks_mod' ) );
673
        list( $totalmodrequests ) = $xoopsDB -> fetchRow( $result2 );
674
        $result3 = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE published = 0" );
675
        list( $totalnewlinks ) = $xoopsDB -> fetchRow( $result3 );
676
        $result4 = $xoopsDB -> query( "SELECT COUNT(*) FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE published > 0" );
677
        list( $totallinks ) = $xoopsDB -> fetchRow( $result4 );
678
679
        xoops_cp_header();
680
681
        $indexAdmin = new ModuleAdmin();
682
        echo $indexAdmin->addNavigation('main.php');
683
        $indexAdmin->addItemButton(_MI_WFL_ADD_LINK, 'main.php?op=edit', 'add', '');
684
        $indexAdmin->addItemButton(_MI_WFL_ADD_CATEGORY, 'category.php', 'add', '');
685
        echo $indexAdmin->renderButton('right', '');
686
687
        //wfl_adminmenu( _AM_WFL_BINDEX );
688
//        echo "
689
//			<fieldset style='border: #e8e8e8 1px solid;'><legend style='display: inline; font-weight: bold; color: #0A3760;'>" . _AM_WFL_MINDEX_LINKSUMMARY . "</legend>\n
690
//			<div style='padding: 8px;'><small>\n
691
//			<a href='category.php'>" . _AM_WFL_SCATEGORY . "</a><b>" . $totalcats . "</b> | \n
692
//			<a href='main.php'>" . _AM_WFL_SFILES . "</a><b>" . $totallinks . "</b> | \n
693
//			<a href='newlinks.php'>" . _AM_WFL_SNEWFILESVAL . "</a><b>" . $totalnewlinks . "</b> | \n
694
//			<a href='modifications.php'>" . _AM_WFL_SMODREQUEST . "</a><b>" . $totalmodrequests . "</b> | \n
695
//			<a href='brokenlink.php'>" . _AM_WFL_SBROKENSUBMIT . "</a><b>" . $totalbrokenlinks . "</b>\n
696
//			</small></div></fieldset><br />\n
697
//		";
698
699
//        if ($totalcats > 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
700
//            $sform = new XoopsThemeForm( _AM_WFL_CCATEGORY_MODIFY, "category", "category.php" );
701
//            ob_start();
702
//            $mytree -> makeMySelBox( "title", "title" );
703
//            $sform -> addElement( new XoopsFormLabel( _AM_WFL_CCATEGORY_MODIFY_TITLE, ob_get_contents() ) );
704
//            ob_end_clean();
705
//            $dup_tray = new XoopsFormElementTray( '', '' );
706
//            $dup_tray -> addElement( new XoopsFormHidden( 'op', 'modCat' ) );
707
//            $butt_dup = new XoopsFormButton( '', '', _AM_WFL_BMODIFY, 'submit' );
708
//            $butt_dup -> setExtra( 'onclick="this.form.elements.op.value=\'modCat\'"' );
709
//            $dup_tray -> addElement( $butt_dup );
710
//            $butt_dupct = new XoopsFormButton( '', '', _AM_WFL_BDELETE, 'submit' );
711
//            $butt_dupct -> setExtra( 'onclick="this.form.elements.op.value=\'del\'"' );
712
//            $dup_tray -> addElement( $butt_dupct );
713
//            $sform -> addElement( $dup_tray );
714
//            $sform -> display();
715
//        }
716
717
        if ($totallinks > 0) {
718
            $sql = "SELECT * FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE published > 0  ORDER BY lid DESC" ;
719
            $published_array = $xoopsDB -> query( $sql, $xoopsModuleConfig['admin_perpage'], $start );
720
            $published_array_count = $xoopsDB -> getRowsNum( $xoopsDB -> query( $sql ) );
721
            wfl_linklistheader( _AM_WFL_MINDEX_PUBLISHEDLINK );
722
            wfl_linklistpagenavleft( $published_array_count, $start, 'art' );
723
            if ($published_array_count > 0) {
724
                while ( $published = $xoopsDB -> fetchArray( $published_array ) ) {
725
                    wfl_linklistbody( $published );
726
                }
727
            } else {
728
                wfl_linklistfooter();
729
            }
730
            wfl_linklistpagenav( $published_array_count, $start, 'art' );
731
        }
732
        include_once 'admin_footer.php';
733
        break;
734
}
735