| [ Index ] |
PHP Cross Reference of Nucleus CMS 3.32 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 4 * Copyright (C) 2002-2007 The Nucleus Group 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * (see nucleus/documentation/index.html#license for more info) 11 */ 12 /** 13 * Functions to create lists of things inside the admin are 14 * 15 * @license http://nucleuscms.org/license.txt GNU General Public License 16 * @copyright Copyright (C) 2002-2007 The Nucleus Group 17 * @version $Id: showlist.php 1197 2007-09-05 07:42:15Z kimitake $ 18 */ 19 20 21 // can take either an array of objects, or an SQL query 22 function showlist($query, $type, $template) { 23 24 if (is_array($query)) { 25 if (sizeof($query) == 0) 26 return 0; 27 28 call_user_func('listplug_' . $type, $template, 'HEAD'); 29 30 foreach ($query as $currentObj) { 31 $template['current'] = $currentObj; 32 call_user_func('listplug_' . $type, $template, 'BODY'); 33 } 34 35 call_user_func('listplug_' . $type, $template, 'FOOT'); 36 37 return sizeof($query); 38 39 } else { 40 $res = sql_query($query); 41 42 // don't do anything if there are no results 43 $numrows = mysql_num_rows($res); 44 if ($numrows == 0) 45 return 0; 46 47 call_user_func('listplug_' . $type, $template, 'HEAD'); 48 49 while($template['current'] = mysql_fetch_object($res)) 50 call_user_func('listplug_' . $type, $template, 'BODY'); 51 52 call_user_func('listplug_' . $type, $template, 'FOOT'); 53 54 mysql_free_result($res); 55 56 // return amount of results 57 return $numrows; 58 } 59 } 60 61 function listplug_select($template, $type) { 62 switch($type) { 63 case 'HEAD': 64 echo '<select name="' . ifset($template['name']) . '" tabindex="' . ifset($template['tabindex']) . '" ' . ifset($template['javascript']) . '>'; 65 66 // add extra row if needed 67 if (ifset($template['extra'])) { 68 echo '<option value="', ifset($template['extraval']), '">', $template['extra'], '</option>'; 69 } 70 71 break; 72 case 'BODY': 73 $current = $template['current']; 74 75 echo '<option value="' . htmlspecialchars($current->value) . '"'; 76 if ($template['selected'] == $current->value) 77 echo ' selected="selected" '; 78 if (isset($template['shorten']) && $template['shorten'] > 0) { 79 echo ' title="'. htmlspecialchars($current->text).'"'; 80 $current->text = shorten($current->text, $template['shorten'], $template['shortenel']); 81 } 82 echo '>' . htmlspecialchars($current->text) . '</option>'; 83 break; 84 case 'FOOT': 85 echo '</select>'; 86 break; 87 } 88 } 89 90 function listplug_table($template, $type) { 91 switch($type) { 92 case 'HEAD': 93 echo "<table>"; 94 echo "<thead><tr>"; 95 // print head 96 call_user_func("listplug_table_" . $template['content'] , $template, 'HEAD'); 97 echo "</tr></thead><tbody>"; 98 break; 99 case 'BODY': 100 // print tabletype specific thingies 101 echo "<tr onmouseover='focusRow(this);' onmouseout='blurRow(this);'>"; 102 call_user_func("listplug_table_" . $template['content'] , $template, 'BODY'); 103 echo "</tr>"; 104 break; 105 case 'FOOT': 106 call_user_func("listplug_table_" . $template['content'] , $template, 'FOOT'); 107 echo "</tbody></table>"; 108 break; 109 } 110 } 111 112 function listplug_table_memberlist($template, $type) { 113 switch($type) { 114 case 'HEAD': 115 echo '<th>' . _LIST_MEMBER_NAME . '</th><th>' . _LIST_MEMBER_RNAME . '</th><th>' . _LIST_MEMBER_URL . '</th><th>' . _LIST_MEMBER_ADMIN; 116 help('superadmin'); 117 echo "</th><th>" . _LIST_MEMBER_LOGIN; 118 help('canlogin'); 119 echo "</th><th colspan='2'>" . _LISTS_ACTIONS. "</th>"; 120 break; 121 case 'BODY': 122 $current = $template['current']; 123 124 echo '<td>'; 125 $id = listplug_nextBatchId(); 126 echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->mnumber,'" />'; 127 echo '<label for="batch',$id,'">'; 128 echo "<a href='mailto:", htmlspecialchars($current->memail), "' tabindex='".$template['tabindex']."'>", htmlspecialchars($current->mname), "</a>"; 129 echo '</label>'; 130 echo '</td>'; 131 echo '<td>', htmlspecialchars($current->mrealname), '</td>'; 132 echo "<td><a href='", htmlspecialchars($current->murl), "' tabindex='", $template['tabindex'] , "'>", htmlspecialchars($current->murl), "</a></td>"; 133 echo '<td>', ($current->madmin ? _YES : _NO),'</td>'; 134 echo '<td>', ($current->mcanlogin ? _YES : _NO), '</td>'; 135 echo "<td><a href='index.php?action=memberedit&memberid=$current->mnumber' tabindex='".$template['tabindex']."'>"._LISTS_EDIT."</a></td>"; 136 echo "<td><a href='index.php?action=memberdelete&memberid=$current->mnumber' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>"; 137 break; 138 } 139 } 140 141 function listplug_table_teamlist($template, $type) { 142 global $manager; 143 switch($type) { 144 case 'HEAD': 145 echo "<th>"._LIST_MEMBER_NAME."</th><th>"._LIST_MEMBER_RNAME."</th><th>"._LIST_TEAM_ADMIN; 146 help('teamadmin'); 147 echo "</th><th colspan='2'>"._LISTS_ACTIONS."</th>"; 148 break; 149 case 'BODY': 150 $current = $template['current']; 151 152 echo '<td>'; 153 $id = listplug_nextBatchId(); 154 echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->tmember,'" />'; 155 echo '<label for="batch',$id,'">'; 156 echo "<a href='mailto:", htmlspecialchars($current->memail), "' tabindex='".$template['tabindex']."'>", htmlspecialchars($current->mname), "</a>"; 157 echo '</label>'; 158 echo '</td>'; 159 echo '<td>', htmlspecialchars($current->mrealname), '</td>'; 160 echo '<td>', ($current->tadmin ? _YES : _NO) , '</td>'; 161 echo "<td><a href='index.php?action=teamdelete&memberid=$current->tmember&blogid=$current->tblog' tabindex='".$template['tabindex']."'>"._LISTS_DELETE."</a></td>"; 162 163 $url = 'index.php?action=teamchangeadmin&memberid=' . intval($current->tmember) . '&blogid=' . intval($current->tblog); 164 $url = $manager->addTicketToUrl($url); 165 echo "<td><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>"._LIST_TEAM_CHADMIN."</a></td>"; 166 break; 167 } 168 } 169 170 function listplug_table_pluginlist($template, $type) { 171 global $manager; 172 switch($type) { 173 case 'HEAD': 174 echo '<th>'._LISTS_INFO.'</th><th>'._LISTS_DESC.'</th>'; 175 echo '<th style="white-space:nowrap">'._LISTS_ACTIONS.'</th>'; 176 break; 177 case 'BODY': 178 $current = $template['current']; 179 180 $plug =& $manager->getPlugin($current->pfile); 181 if ($plug) { 182 echo '<td>'; 183 echo '<strong>' , htmlspecialchars($plug->getName()) , '</strong><br />'; 184 echo _LIST_PLUGS_AUTHOR, ' ' , htmlspecialchars($plug->getAuthor()) , '<br />'; 185 echo _LIST_PLUGS_VER, ' ' , htmlspecialchars($plug->getVersion()) , '<br />'; 186 if ($plug->getURL()) 187 echo '<a href="',htmlspecialchars($plug->getURL()),'" tabindex="'.$template['tabindex'].'">',_LIST_PLUGS_SITE,'</a><br />'; 188 echo '</td>'; 189 echo '<td>'; 190 echo _LIST_PLUGS_DESC .'<br/>'. encode_desc($plug->getDescription()); 191 if (sizeof($plug->getEventList()) > 0) { 192 echo '<br /><br />',_LIST_PLUGS_SUBS,'<br />',htmlspecialchars(implode($plug->getEventList(),', ')); 193 // check the database to see if it is up-to-date and notice the user if not 194 } 195 if (!$plug->subscribtionListIsUptodate()) { 196 echo '<br /><br /><strong>',_LIST_PLUG_SUBS_NEEDUPDATE,'</strong>'; 197 } 198 if (sizeof($plug->getPluginDep()) > 0) 199 echo '<br /><br />',_LIST_PLUGS_DEP,'<br />',htmlspecialchars(implode($plug->getPluginDep(),', ')); 200 echo '</td>'; 201 } else { 202 echo '<td colspan="2">Error: plugin file <b>',htmlspecialchars($current->pfile),'.php</b> could not be loaded, or it has been set inactive because it does not support some features (check the <a href="?action=actionlog">actionlog</a> for more info)</td>'; 203 } 204 echo '<td>'; 205 206 $baseUrl = 'index.php?plugid=' . intval($current->pid) . '&action='; 207 $url = $manager->addTicketToUrl($baseUrl . 'pluginup'); 208 echo "<a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_UP,"</a>"; 209 $url = $manager->addTicketToUrl($baseUrl . 'plugindown'); 210 echo "<br /><a href='",htmlspecialchars($url),"' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_DOWN,"</a>"; 211 echo "<br /><a href='index.php?action=plugindelete&plugid=$current->pid' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_UNINSTALL,"</a>"; 212 if ($plug && ($plug->hasAdminArea() > 0)) 213 echo "<br /><a href='".htmlspecialchars($plug->getAdminURL())."' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_ADMIN,"</a>"; 214 if ($plug && ($plug->supportsFeature('HelpPage') > 0)) 215 echo "<br /><a href='index.php?action=pluginhelp&plugid=$current->pid' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_HELP,"</a>"; 216 if (quickQuery('SELECT COUNT(*) AS result FROM '.sql_table('plugin_option_desc').' WHERE ocontext=\'global\' and opid='.$current->pid) > 0) 217 echo "<br /><a href='index.php?action=pluginoptions&plugid=$current->pid' tabindex='".$template['tabindex']."'>",_LIST_PLUGS_OPTIONS,"</a>"; 218 echo '</td>'; 219 break; 220 } 221 } 222 223 function listplug_table_plugoptionlist($template, $type) { 224 global $manager; 225 switch($type) { 226 case 'HEAD': 227 echo '<th>'._LISTS_INFO.'</th><th>'._LISTS_VALUE.'</th>'; 228 break; 229 case 'BODY': 230 $current = $template['current']; 231 listplug_plugOptionRow($current); 232 break; 233 case 'FOOT': 234 ?> 235 <tr> 236 <th colspan="2"><?php echo _PLUGS_SAVE?></th> 237 </tr><tr> 238 <td><?php echo _PLUGS_SAVE?></td> 239 <td><input type="submit" value="<?php echo _PLUGS_SAVE?>" /></td> 240 </tr> 241 <?php break; 242 } 243 } 244 245 function listplug_plugOptionRow($current) { 246 $varname = 'plugoption['.$current['oid'].']['.$current['contextid'].']'; 247 // retreive the optionmeta 248 $meta = NucleusPlugin::getOptionMeta($current['typeinfo']); 249 250 // only if it is not a hidden option write the controls to the page 251 if ($meta['access'] != 'hidden') { 252 echo '<td>',htmlspecialchars($current['description']?$current['description']:$current['name']),'</td>'; 253 echo '<td>'; 254 switch($current['type']) { 255 case 'yesno': 256 ADMIN::input_yesno($varname, $current['value'], 0, 'yes', 'no'); 257 break; 258 case 'password': 259 echo '<input type="password" size="40" maxlength="128" name="',htmlspecialchars($varname),'" value="',htmlspecialchars($current['value']),'" />'; 260 break; 261 case 'select': 262 echo '<select name="'.htmlspecialchars($varname).'">'; 263 $aOptions = NucleusPlugin::getOptionSelectValues($current['typeinfo']); 264 $aOptions = explode('|', $aOptions); 265 for ($i=0; $i<(count($aOptions)-1); $i+=2) { 266 echo '<option value="'.htmlspecialchars($aOptions[$i+1]).'"'; 267 if ($aOptions[$i+1] == $current['value']) 268 echo ' selected="selected"'; 269 echo '>'.htmlspecialchars($aOptions[$i]).'</option>'; 270 } 271 echo '</select>'; 272 break; 273 case 'textarea': 274 //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']); 275 echo '<textarea class="pluginoption" cols="30" rows="5" name="',htmlspecialchars($varname),'"'; 276 if ($meta['access'] == 'readonly') { 277 echo ' readonly="readonly"'; 278 } 279 echo '>',htmlspecialchars($current['value']),'</textarea>'; 280 break; 281 case 'text': 282 default: 283 //$meta = NucleusPlugin::getOptionMeta($current['typeinfo']); 284 285 echo '<input type="text" size="40" maxlength="128" name="',htmlspecialchars($varname),'" value="',htmlspecialchars($current['value']),'"'; 286 if ($meta['datatype'] == 'numerical') { 287 echo ' onkeyup="checkNumeric(this)" onblur="checkNumeric(this)"'; 288 } 289 if ($meta['access'] == 'readonly') { 290 echo ' readonly="readonly"'; 291 } 292 echo ' />'; 293 } 294 echo $current['extra']; 295 echo '</td>'; 296 } 297 } 298 299 function listplug_table_itemlist($template, $type) { 300 $cssclass = null; 301 302 switch($type) { 303 case 'HEAD': 304 echo "<th>"._LIST_ITEM_INFO."</th><th>"._LIST_ITEM_CONTENT."</th><th style=\"white-space:nowrap\" colspan='1'>"._LISTS_ACTIONS."</th>"; 305 break; 306 case 'BODY': 307 $current = $template['current']; 308 $current->itime = strtotime($current->itime); // string -> unix timestamp 309 310 if ($current->idraft == 1) 311 $cssclass = "class='draft'"; 312 313 // (can't use offset time since offsets might vary between blogs) 314 if ($current->itime > $template['now']) 315 $cssclass = "class='future'"; 316 317 echo "<td $cssclass>",_LIST_ITEM_BLOG,' ', htmlspecialchars($current->bshortname); 318 echo " <br />",_LIST_ITEM_CAT,' ', htmlspecialchars($current->cname); 319 echo " <br />",_LIST_ITEM_AUTHOR, ' ', htmlspecialchars($current->mname); 320 echo " <br />",_LIST_ITEM_DATE," " . date("Y-m-d",$current->itime); 321 echo "<br />",_LIST_ITEM_TIME," " . date("H:i",$current->itime); 322 echo "</td>"; 323 echo "<td $cssclass>"; 324 325 $id = listplug_nextBatchId(); 326 327 echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->inumber,'" />'; 328 echo '<label for="batch',$id,'">'; 329 echo "<b>" . htmlspecialchars(strip_tags($current->ititle)) . "</b>"; 330 echo '</label>'; 331 echo "<br />"; 332 333 334 $current->ibody = strip_tags($current->ibody); 335 $current->ibody = htmlspecialchars(shorten($current->ibody,300,'...')); 336 337 echo "$current->ibody</td>"; 338 echo "<td style=\"white-space:nowrap\" $cssclass>"; 339 echo "<a href='index.php?action=itemedit&itemid=$current->inumber'>"._LISTS_EDIT."</a>"; 340 echo "<br /><a href='index.php?action=itemcommentlist&itemid=$current->inumber'>"._LISTS_COMMENTS."</a>"; 341 echo "<br /><a href='index.php?action=itemmove&itemid=$current->inumber'>"._LISTS_MOVE."</a>"; 342 echo "<br /><a href='index.php?action=itemdelete&itemid=$current->inumber'>"._LISTS_DELETE."</a>"; 343 echo "</td>"; 344 break; 345 } 346 } 347 348 // for batch operations: generates the index numbers for checkboxes 349 function listplug_nextBatchId() { 350 static $id = 0; 351 return $id++; 352 } 353 354 function listplug_table_commentlist($template, $type) { 355 switch($type) { 356 case 'HEAD': 357 echo "<th>"._LISTS_INFO."</th><th>"._LIST_COMMENT."</th><th colspan='3'>"._LISTS_ACTIONS."</th>"; 358 break; 359 case 'BODY': 360 $current = $template['current']; 361 $current->ctime = strtotime($current->ctime); // string -> unix timestamp 362 363 echo '<td>'; 364 echo date("Y-m-d@H:i",$current->ctime); 365 echo '<br />'; 366 if ($current->mname) 367 echo htmlspecialchars($current->mname) ,' ', _LIST_COMMENTS_MEMBER; 368 else 369 echo htmlspecialchars($current->cuser); 370 if ($current->cmail != '') { 371 echo '<br />'; 372 echo htmlspecialchars($current->cmail); 373 } 374 if ($current->cemail != '') { 375 echo '<br />'; 376 echo htmlspecialchars($current->cemail); 377 } 378 echo '</td>'; 379 380 $current->cbody = strip_tags($current->cbody); 381 $current->cbody = htmlspecialchars(shorten($current->cbody, 300, '...')); 382 383 echo '<td>'; 384 $id = listplug_nextBatchId(); 385 echo '<input type="checkbox" id="batch',$id,'" name="batch[',$id,']" value="',$current->cnumber,'" />'; 386 echo '<label for="batch',$id,'">'; 387 echo $current->cbody; 388 echo '</label>'; 389 echo '</td>'; 390 391 echo "<td style=\"white-space:nowrap\"><a href='index.php?action=commentedit&commentid=$current->cnumber'>"._LISTS_EDIT."</a></td>"; 392 echo "<td style=\"white-space:nowrap\"><a href='index.php?action=commentdelete&commentid=$current->cnumber'>"._LISTS_DELETE."</a></td>"; 393 if ($template['canAddBan']) 394 echo "<td style=\"white-space:nowrap\"><a href='index.php?action=banlistnewfromitem&itemid=$current->citem&ip=", htmlspecialchars($current->cip), "' title='", htmlspecialchars($current->chost), "'>"._LIST_COMMENT_BANIP."</a></td>"; 395 break; 396 } 397 } 398 399 400 function listplug_table_bloglist($template, $type) { 401 switch($type) { 402 case 'HEAD': 403 echo "<th>" . _NAME . "</th><th colspan='7'>" ._LISTS_ACTIONS. "</th>"; 404 break; 405 case 'BODY': 406 $current = $template['current']; 407 408 echo "<td title='blogid:$current->bnumber shortname:$current->bshortname'><a href='$current->burl'><img src='images/globe.gif' width='13' height='13' alt='".