[ Index ] |
PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 // general functions used in backend only 24 25 function update_cache() { 26 // used to update cache setting all current cache entries 27 // will be forced to update cache but will not be deleted 28 //$sql = "UPDATE ".DB_PREPEND."phpwcms_cache SET cache_timeout='0'"; 29 //mysql_query($sql, $GLOBALS['db']) or die("error while updating cache"); 30 } 31 32 function set_chat_focus($do, $p) { //set_chat_focus("chat", 1) 33 if($do == "chat" && $p == 1) { 34 echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\n"; 35 echo "document.sendchatmessage.chatmsg.focus();\ndocument.sendchatmessage.chatmsg.value=get_cookie('chatstring');\n"; 36 echo "timer = chat_reload(20000);\nfunction chat_reload(zeit) {\n"; 37 echo "timer=setTimeout(\"write_cookie(1);self.location.href='phpwcms.php?do=chat&p=1&l=".$chatlist."'\", zeit);\n"; 38 echo "return timer;\n}\nfunction restart_reload(timer) {\n"; 39 echo "if(timer != null) { clearTimeout(timer); timer=null; timer = chat_reload(20000); }\nreturn timer;\n}\n//-->\n</script>\n"; 40 } 41 } 42 43 function forward_to($to, $link, $time=2500) { //Javascript forwarding 44 if($to) echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\n setTimeout(\"document.location.href='".$link."'\", ".(intval($time))."); \n //-->\n</script>\n"; 45 } 46 47 function subnavtext($text, $link, $is, $should, $getback=1, $js='') { 48 //generate subnavigation based on text 49 $id = "subnavid".randpassword(5); 50 $sn = ''; 51 if($is == $should) { 52 $sn .= '<tr><td><img src="img/subnav/subnav_B.gif" width="15" height="13" border="0" alt="" /></td>'; 53 $sn .= '<td class="subnavactive"><a href="'.$link.'">'.$text.'</a></td></tr>'; 54 } else { 55 $sn .= "<tr><td><img name=\"".$id."\" src=\"img/subnav/subnav_A.gif\" width=\"15\" height=\"13\" border=\"0\" alt=\"\" /></td>"; 56 $sn .= "<td class=\"subnavinactive\"><a href=\"".$link."\" ".$js; 57 $sn .= "onMouseOver=\"".$id.".src='img/subnav/subnav_B.gif'\" onMouseOut=\"".$id; 58 $sn .= ".src='img/subnav/subnav_A.gif'\">".$text."</a></td></tr>"; 59 } 60 $sn .= "\n"; 61 if(!$getback) { 62 return $sn; 63 } else { 64 echo $sn; 65 } 66 } 67 68 function subnavtextext($text, $link, $target='_blank', $getback=1) { 69 //generate subnavigation based on text and links to new page 70 $id = 'subnavid'.randpassword(5); 71 $sn = '<tr><td><img src="img/subnav/subnav_A.gif" width="15" height="13" border="0" name="'.$id.'" alt="" /></td>'; 72 $sn .= '<td class="subnavinactive"><a href="'.$link.'" target="'.$target.'" '; 73 $sn .= "onMouseOver=\"".$id.".src='img/subnav/subnav_B.gif'\" onMouseOut=\"".$id.".src='img/subnav/subnav_A.gif'\""; 74 $sn .= '>'.$text.'</a></td></tr>'; 75 $sn .= "\n"; 76 if(!$getback) { return $sn; } else { echo $sn; } 77 } 78 79 function subnavback($text, $link, $h_before=0, $h_after=0) { 80 $id = "subbackid".randpassword(5); 81 $sn = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"; 82 $sn .= (intval($h_before)) ? "<tr><td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"".intval($h_before)."\" alt=\"\" /></td></tr>\n" : ""; 83 $sn .= "<tr>"; 84 $sn .= "<td><img name=\"".$id."\" src=\"img/subnav/subnav_back_0.gif\" width=\"9\" height=\"9\" border=\"0\" alt=\"\" /></td>"; 85 $sn .= "<td class=\"subnavinactive\"> <a href=\"".$link."\" onMouseOver=\"".$id.".src='img/subnav/subnav_back_1.gif'\" "; 86 $sn .= "onMouseOut=\"".$id.".src='img/subnav/subnav_back_0.gif'\"><strong>".$text."</strong></a></td>"; 87 $sn .= "</tr>\n"; 88 $sn .= (intval($h_after)) ? "<tr><td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"".intval($h_after)."\" alt=\"\" /></td></tr>\n" : ""; 89 $sn .= "</table>\n"; 90 echo $sn; 91 } 92 93 function clearfilename($formvar) { 94 //Filename anpassen und säubern 95 $formvar = trim($formvar); 96 if( get_magic_quotes_gpc() ) $formvar = stripslashes ($formvar); 97 $formvar = str_replace(array("'", ':', '/', '\\', '"'), '_', $formvar); 98 return $formvar; 99 } 100 101 function check_image_extension($file, $filename='') { 102 // only checks against correct image extension 103 $image_info = getimagesize($file); 104 $result = false; 105 if(false != $image_info) { 106 switch($image_info[2]) { 107 case 1: $result = 'gif'; break; 108 case 2: $result = 'jpg'; break; 109 case 3: $result = 'png'; break; 110 case 4: $result = 'swf'; break; 111 case 5: $result = 'psd'; break; 112 case 6: $result = 'bmp'; break; 113 case 7: $result = 'tif'; break; //(intel byte order), 114 case 8: $result = 'tif'; break; //(motorola byte order), 115 case 9: $result = 'jpc'; break; 116 case 10: $result = 'jp2'; break; 117 case 11: $result = 'jpx'; break; 118 case 12: $result = 'jb2'; break; 119 120 case 13: // there is a problem in some cases swf -> swc ? why ever! 121 // do an additional extension check and compare against swf 122 $result = (strtolower(which_ext($file)) == 'swf') ? 'swf' : 'swc'; 123 break; 124 125 case 14: $result = 'iff'; break; 126 127 case 15: // there seems to be a problem with getimagesize and Quicktime VR 128 // mov -> wmbf ? why ever! 129 // do an additional extension check and compare against mov 130 $result = (strtolower(which_ext( empty($filename) ? $file : $filename )) == 'mov') ? 'mov' : 'wbmp'; 131 break; 132 133 case 16: $result = 'xbm'; break; 134 } 135 } 136 return $result; 137 } 138 139 function getParentStructArray($structID) { 140 $structID = intval($structID); 141 $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_id=".$structID." LIMIT 1"; 142 if($result = mysql_query($sql, $GLOBALS['db'])) { 143 if($row = mysql_fetch_assoc($result)) { 144 return $row; 145 } 146 mysql_free_result($result); 147 } 148 return $GLOBALS['indexpage']; 149 } 150 151 /* 152 * Get sort value for an article based on category 153 */ 154 function getArticleSortValue($cat_id=0) { 155 156 // default sort value 157 $sort = 0; 158 $cat_id = intval($cat_id); 159 $count = 0; 160 $max_sort = 0; 161 // Count all articles within the given structure ID 162 $sql = "SELECT article_id, article_sort FROM ".DB_PREPEND."phpwcms_article "; 163 $sql .= "WHERE article_cid=".$cat_id." "; 164 $sql .= "ORDER BY article_sort DESC"; 165 if($result = mysql_query($sql, $GLOBALS['db'])) { 166 // this is the max articles in structure 167 $count = mysql_num_rows($result); 168 // but neccessary trying to get the highest article sort value 169 if($row = mysql_fetch_assoc($result)) { 170 $max_sort = $row['article_sort']; 171 } 172 mysql_free_result($result); 173 } 174 $count = ($count + 1) * 10; 175 $count = ($max_sort < $count) ? $count : $max_sort + 10; 176 return $count; 177 } 178 179 /* 180 * Make a re-sort for given structure ID and 181 * return new sorted articles as array 182 */ 183 function getArticleReSorted(& $cat_id, & $ordered_by) { 184 185 // get all articles including deleted and update sorting 186 // in correct sort order by adding sort + 10 187 $sort = 10; 188 $sort_multiply_by = 1; 189 $count_article = 0; 190 $ao = get_order_sort($ordered_by); 191 192 $sql = "SELECT article_id, article_cid, article_title, article_public, article_aktiv, article_uid, "; 193 $sql .= "date_format(article_tstamp, '%Y-%m-%d %H:%i:%s') AS article_date, article_sort, article_deleted, article_tstamp "; 194 $sql .= "FROM ".DB_PREPEND."phpwcms_article "; 195 $sql .= "WHERE article_cid='".$cat_id."' ORDER BY ".$ao[2]; 196 197 if($result = mysql_query($sql, $GLOBALS['db'])) { 198 199 // now check if it's sorted manually and DESC 200 // then sort has to be lowerd by -10 201 if($ao[0] == 0 && $ao[1] == 1) { 202 $max_article_count = mysql_num_rows($result); 203 $sort = ($max_article_count + 1) * 10; 204 $sort_multiply_by = -1; 205 } 206 207 // take all entries and build new array with it 208 while($row = mysql_fetch_assoc($result)) { 209 210 // SQL update query with new sort value 211 $update_sql = "UPDATE ".DB_PREPEND."phpwcms_article SET "; 212 $update_sql .= "article_sort=".$sort.", "; 213 $update_sql .= "article_tstamp='".$row['article_tstamp']."' "; 214 $update_sql .= "WHERE article_id=".$row['article_id']." LIMIT 1"; 215 @mysql_query($update_sql, $GLOBALS['db']); 216 217 // add entry to the returning array only for article_deleted=0 218 // drops all deleted articles or articles having another status 219 if($row['article_deleted'] == 0) { 220 221 $article[$count_article] = $row; 222 $article[$count_article]['article_sort'] = $sort; 223 224 // count up for article array index 225 $count_article++; 226 227 } 228 229 // count sort up by 10 230 $sort = $sort + (10 * $sort_multiply_by); 231 232 } 233 mysql_free_result($result); 234 } 235 236 return $article; 237 238 } 239 240 function phpwcmsversionCheck() { 241 242 // Check for new version 243 244 global $phpwcms; 245 global $BL; 246 247 if(empty($phpwcms['version_check'])) return ''; 248 249 $errno = 0; 250 $errstr = ''; 251 $version_info = ''; 252 253 if ($fsock = @fsockopen('www.phpwcms.de', 80, $errno, $errstr, 10)) { 254 255 $identify = '?version='.rawurlencode($phpwcms["release"].'-'.str_replace('/', '', $phpwcms["release_date"])).'&hash='.md5($_SERVER['REQUEST_URI']); 256 257 @fputs($fsock, "GET /versioncheck/phpwcms_releaseinfo.txt".$identify." HTTP/1.1\r\n"); 258 @fputs($fsock, "HOST: www.phpwcms.de\r\n"); 259 @fputs($fsock, "Connection: close\r\n\r\n"); 260 261 $get_info = false; 262 while (!@feof($fsock)) { 263 if ($get_info) { 264 $version_info .= @fread($fsock, 1024); 265 } else { 266 if (@fgets($fsock, 1024) == "\r\n") { 267 $get_info = true; 268 } 269 } 270 } 271 @fclose($fsock); 272 273 $version_info = explode("\n", $version_info); 274 275 $latest_version = trim($version_info[0]); 276 $latest_revdate = trim($version_info[1]); 277 $latest_revision = intval(trim($version_info[2])); 278 279 // do version check 280 $check = $latest_revision > $phpwcms['revision'] ? false : true; 281 282 283 if ($check) { 284 $version_info = '<p class="valid">' . $BL['Version_up_to_date'] . '</p>'; 285 $version_info .= '<p class="valid">'.sprintf($BL['Latest_version_info'], $latest_version.' ('.$latest_revdate.', r'.$latest_revision.')'). ' '; 286 $version_info .= sprintf($BL['Current_version_info'], $phpwcms["release"].' ('.$phpwcms["release_date"].', r'.$phpwcms["revision"].')') . '</p>'; 287 288 } else { 289 290 $this_version = implode('.', $latest_revision); 291 $this_version .= ' ('.date('Y/m/d', $latest_revdate[0]).')'; 292 293 $version_info = '<p class="error">' . $BL['Version_not_up_to_date'] . '</p>'; 294 $version_info .= '<p class="error">'.sprintf($BL['Latest_version_info'], $this_version). ' '; 295 $version_info .= sprintf($BL['Current_version_info'], $phpwcms["release"].' ('.$phpwcms["release_date"].')') . '</p>'; 296 297 } 298 299 300 } else { 301 302 if ($errstr) { 303 $version_info = '<p class="error">' . sprintf($BL['Connect_socket_error'], $errstr) . '</p>'; 304 } else { 305 $version_info = '<p>' . $BL['Socket_functions_disabled'] . '</p>'; 306 } 307 } 308 309 //$version_info .= '<p>' . $BL['Mailing_list_subscribe_reminder'] . '</p>'; 310 311 return '<div class="versioncheck"><h1>'.$BL['Version_information'].'</h1> '.$version_info.'</div>'; 312 313 } 314 315 316 function createOptionTransferSelectList($id='', $leftData, $rightData, $option = array()) { 317 // used to create 318 319 global $BL; 320 321 $id_left = $id.'_left'; 322 $id_right = $id.'_right'; 323 $id_left_box = $id_left.'list'; 324 $id_right_box = $id_right.'list'; 325 $option_object = generic_string(4, 4); 326 327 $table = ''; 328 329 $option['rows'] = empty($option['rows']) || !intval($option['rows']) ? 5 : $option['rows']; 330 $option['delimeter'] = empty($option['delimeter']) ? ',' : $option['delimeter']; 331 $option['encode'] = (isset($option['encode']) && $option['encode'] === false) ? false : true; 332 $option['style'] = empty($option['style']) ? '' : ' style="'.$option['style'].'"'; 333 $option['class'] = empty($option['class']) ? ' class="#SIDE#"' : ' class="#SIDE# '.$option['class'].'"'; 334 $option['formname'] = empty($option['formname']) ? 'document.forms[0]' : 'document.getElementById(\''.$option['formname'].'\')'; 335 336 337 $GLOBALS['BE']['HEADER']['optionselect.js'] = getJavaScriptSourceLink('include/inc_js/optionselect.js'); 338 339 $table .= '<table border="0" cellspacing="0" cellpadding="0">'.LF.'<tr>'.LF; 340 341 // left select list 342 $table .= '<td valign><select name="'.$id_left_box.'" id="'.$id_left_box.'" size="'.$option['rows'].'" multiple="multiple"'; 343 $table .= $option['style'].str_replace('#SIDE#', 'leftSide', $option['class']).' ondblclick="'.$option_object.'.transferRight()">'.LF; 344 if(!empty($leftData) && is_array($leftData)) { 345 foreach($leftData as $key => $value) { 346 $table .= ' <option value="'.$key.'">'.$value.'</option>'.LF; 347 } 348 } $table .= '</select></td>'.LF; 349 350 // left <-> right buttons 351 $table .= '<td'.$option['style'].$option['class'].'>'; 352 $table .= '<img src="img/leer.gif" alt="" width="1" height="1" />'.LF; 353 $table .= '</td>'.LF; 354 355 // right select list 356 $table .= '<td><select name="'.$id_right_box.'" id="'.$id_right_box.'" size="'.$option['rows'].'" multiple="multiple"'; 357 $table .= $option['style'].str_replace('#SIDE#', 'rightSide', $option['class']).' ondblclick="'.$option_object.'.transferLeft()">'.LF; 358 if(!empty($rightData) && is_array($rightData)) { 359 foreach($rightData as $key => $value) { 360 $table .= ' <option value="'.$key.'">'.$value.'</option>'.LF; 361 } 362 } 363 $table .= '</select></td>'.LF; 364 $table .= '</tr>'.LF; 365 366 $table .= '<tr>'.LF.'<td>'; 367 $table .= '<img src="img/button/list_pos_up.gif" alt="" border="0" onclick="moveOptionUp('.$option['formname'].'.'.$id_left_box.');'.$option_object.'.update();">'; 368 $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />'; 369 $table .= '<img src="img/button/list_pos_down.gif" alt="" border="0" onclick="moveOptionDown('.$option['formname'].'.'.$id_left_box.');'.$option_object.'.update();">'; 370 $table .= '<img src="img/leer.gif" width="4" height="4" alt="" />'; 371 $table .= '<img src="img/button/put_right_a.gif" alt="Move selected to right" border="0" onclick="'.$option_object.'.transferRight();" />'; 372 $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />'; 373 $table .= '<img src="img/button/put_right.gif" alt="Move all to right" border="0" onclick="'.$option_object.'.transferAllRight();"/>'; 374 $table .= '</td>'.LF; 375 376 $table .= '<td><img src="img/leer.gif" alt="" width="1" height="1" /></td>'.LF; 377 378 $table .= '<td>'; 379 $table .= '<img src="img/button/put_left_a.gif" alt="Move selected to left" border="0" onclick="'.$option_object.'.transferLeft();" />'; 380 $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />'; 381 $table .= '<img src="img/button/put_left.gif" alt="Move all to left" border="0" onclick="'.$option_object.'.transferAllLeft();" />'; 382 $table .= '</td>'.LF; 383 384 $table .= '</tr>'.LF.'</table>'.LF; 385 386 $table .= '<input type="hidden" name="'.$id_left.'" id="'.$id_left.'" value="" />'; 387 $table .= '<input type="hidden" name="'.$id_right.'" id="'.$id_right.'" value="" />'; 388 389 $table .= '<script language="javascript">'.LF; 390 $table .= SCRIPT_CDATA_START.LF; 391 $table .= ' var '.$option_object.' = new OptionTransfer("'.$id_left_box.'","'.$id_right_box.'");'.LF; 392 $table .= ' '.$option_object.'.setAutoSort(false);'.LF; 393 $table .= ' '.$option_object.'.setDelimiter("'.$option['delimeter'].'");'.LF; 394 $table .= ' '.$option_object.'.saveNewLeftOptions("'.$id_left.'");'.LF; 395 $table .= ' '.$option_object.'.saveNewRightOptions("'.$id_right.'");'.LF; 396 $table .= ' '.$option_object.'.init('.$option['formname'].');'.LF; 397 398 $table .= LF.SCRIPT_CDATA_END.LF; 399 $table .= '</script>'.LF; 400 401 return $table; 402 } 403 404 function countNewsletterRecipients($target) { 405 // try to count all recipients for special newsletter 406 $recipients = _dbQuery('SELECT * FROM '.DB_PREPEND.'phpwcms_address WHERE address_verified=1'); 407 $counter = 0; 408 $check = (empty($target) || !is_array($target) || !count($target)) ? false : true; 409 foreach($recipients as $value) { 410 if(empty($value['address_subscription'])) { 411 $counter++; 412 continue; 413 } elseif($check) { 414 $value['address_subscription'] = unserialize($value['address_subscription']); 415 if(is_array($value['address_subscription'])) { 416 foreach($value['address_subscription'] as $subscr) { 417 if(in_array(intval($subscr), $target)) { 418 $counter++; 419 break; 420 } 421 } 422 } 423 } 424 } 425 return $counter; 426 } 427 428 function getContentPartOptionTag($value='', $text='', $selected='', $module='') { 429 430 $result = ''; 431 432 433 // neccessary plugin check 434 if($value == 30) { 435 436 if(!isset($GLOBALS['temp_count'])) { 437 $GLOBALS['temp_count'] = 0; 438 } 439 440 foreach($GLOBALS['phpwcms']['modules'] as $module_value) { 441 442 if($module_value['cntp'] && file_exists($module_value['path'].'inc/cnt.list.php')) { 443 $result .= '<option value="'.$value.':'.$module_value['name'].'"'; 444 if($value == $selected && $module_value['name'] == $module) { 445 $result .= ' selected="selected"'; 446 $GLOBALS['contentpart_temp_selected'] = $GLOBALS['temp_count']; 447 } 448 $result .= '>'.$text; 449 $result .= ': '.$GLOBALS['BL']['modules'][ $module_value['name'] ]['listing_title']; 450 $result .= '</option>'.LF; 451 $GLOBALS['temp_count']++; 452 } 453 454 } 455 456 } else { 457 458 $result .= '<option value="'.$value.'"'; 459 if($value == $selected) { 460 $result .= ' selected="selected"'; 461 $GLOBALS['contentpart_temp_selected'] = $GLOBALS['temp_count']; 462 } 463 $result .= '>'.$text.'</option>'.LF; 464 465 } 466 467 return $result; 468 469 } 470 471 function isContentPartSet($value='') { 472 473 $value = explode(':', $value); 474 $value[0] = intval($value[0]); 475 476 // check for set module 477 if(empty($value[1])) { 478 479 $value[1] = 1; 480 481 } elseif( isset($GLOBALS['phpwcms']['modules'][$value[1]]) 482 && $GLOBALS['phpwcms']['modules'][$value[1]]['cntp'] 483 && file_exists($GLOBALS['phpwcms']['modules'][$value[1]]['path'].'inc/cnt.list.php')) { 484 485 $value[1] = 1; 486 487 } else { 488 489 $value[1] = 0; 490 491 } 492 493 // check if content part ID exists 494 if(isset($GLOBALS['wcs_content_type'][ $value[0] ]) && $value[1]) { 495 496 return true; 497 498 } else { 499 500 return false; 501 502 } 503 504 } 505 506 /* 507 * Show System Status Message 508 */ 509 function show_status_message($return_status=false) { 510 if(empty($_SESSION['system_status']['msg'])) { 511 $status = ''; 512 } else { 513 $status = '<div class="status_message_' . $_SESSION['system_status']['type'] .'">'; 514 $status .= nl2br( trim( html_specialchars($_SESSION['system_status']['msg']) ) ) . '</div>'; 515 $_SESSION['system_status']['msg'] = ''; 516 } 517 if($return_status) { 518 return $status; 519 } else { 520 echo $status; 521 return NULL; 522 } 523 } 524 /* 525 * Set System Status Message 526 */ 527 function set_status_message($msg='', $type='info', $replace=array()) { 528 if(is_array($replace) && count($replace)) { 529 foreach($replace as $key => $item) { 530 $msg = str_replace('{'.strtoupper($key).'}', $item, $msg); 531 } 532 } 533 $_SESSION['system_status']['msg'] = $msg; 534 switch($type) { 535 case 'success': 536 case 'info': 537 case 'help': 538 case 'error': 539 case 'warning': break; 540 default: $type = 'info'; 541 } 542 $_SESSION['system_status']['type'] = $type; 543 return NULL; 544 } 545 546 function set_language_cookie() { 547 setcookie('phpwcmsBELang', $_SESSION["wcs_user_lang"], time()+(3600*24*365), '/', getCookieDomain() ); 548 } 549 550 // checks for alias and sets unique value 551 function proof_alias($current_id, $alias='', $mode='CATEGORY') { 552 553 $current_id = intval($current_id); 554 $alias = clean_slweg(strtolower($alias), 150); 555 $alias = pre_remove_accents($alias); 556 $alias = get_alnum_dashes($alias, true); 557 $alias = trim($alias); 558 if($alias != '') { 559 $alias = trim( preg_replace('/\-\-+/', '-', $alias), '-' ); 560 $alias = trim( preg_replace('/__+/', '_', $alias), '_' ); 561 } 562 563 $reserved = array( 564 'print', 565 'newsdetail', 566 'newspage', 567 'id', 568 'aid', 569 'subgallery', 570 'listpage', 571 'page', 572 'subscribe', 573 'unsubscribe', 574 'email', 575 'u', 576 's', 577 'q' 578 ); 579 580 if($mode == 'CATEGORY' && $alias == '' && isset($_POST["acat_name"])) { 581 $alias = $_POST["acat_name"]; 582 $set = true; 583 } elseif($mode == 'ARTICLE' && $alias == '' && isset($_POST["article_title"])) { 584 $alias = $_POST["article_title"]; 585 $set = true; 586 } elseif($mode == 'CONTENT' && $alias == '' && ( isset($_POST["cnt_title"]) || isset($_POST["cnt_name"]) )) { 587 $alias = trim($_POST["cnt_title"]) == '' ? $_POST["cnt_name"] : $_POST["cnt_title"]; 588 $set = true; 589 } else { 590 $set = false; 591 } 592 593 if($set) { 594 $alias = clean_slweg(strtolower($alias), 150); 595 $alias = pre_remove_accents($alias); 596 $alias = get_alnum_dashes($alias, true); 597 if($alias != '') { 598 $alias = trim( preg_replace('/\-\-+/', '-', $alias), '-' ); 599 $alias = trim( preg_replace('/__+/', '_', $alias), '_' ); 600 } 601 } 602 603 // new reserved alias can be defined in $phpwcms['reserved_alias'] 604 if( isset($phpwcms['reserved_alias']) && is_array($phpwcms['reserved_alias']) && count($phpwcms['reserved_alias']) ) { 605 $reserved = array_merge($reserved, $phpwcms['reserved_alias']); 606 } 607 608 if( $alias == '' || in_array($alias, $reserved) || ($alias == 'index' && $current_id != 'index') ) { 609 610 if($mode == 'CONTENT') { 611 $alias .= date('-Y-n-j'); 612 } else { 613 $alias .= '-view'; 614 } 615 } 616 617 $alias = trim( $alias, '-' ); 618 619 /* 620 $where_acat = 'acat_id != '.$current_id.' AND '; 621 $where_article = 'article_id != '.$current_id.' AND '; 622 $where_content = 'cnt_id != '.$current_id.' AND '; 623 624 switch($mode) { 625 case 'CATEGORY': $where_article = ''; break; 626 case 'ARTICLE': $where_acat = ''; break; 627 case 'CONTENT': $where_content = ''; break; 628 } 629 */ 630 $where_acat = ''; 631 $where_article = ''; 632 $where_content = ''; 633 634 switch($mode) { 635 case 'CATEGORY': $where_acat = 'acat_id != '.$current_id.' AND '; break; 636 case 'ARTICLE': $where_article = 'article_id != '.$current_id.' AND '; break; 637 case 'CONTENT': $where_content = 'cnt_id != '.$current_id.' AND '; break; 638 } 639 640 // check alias against all structure alias 641 $sql = "SELECT COUNT(acat_id) FROM ".DB_PREPEND."phpwcms_articlecat WHERE "; 642 $sql .= $where_acat; 643 $sql .= "acat_alias='".aporeplace($alias)."'"; 644 $acat_count = _dbQuery($sql, 'COUNT'); 645 646 // check alias against all articles 647 $sql = "SELECT COUNT(article_id) FROM ".DB_PREPEND."phpwcms_article WHERE "; 648 $sql .= $where_article; 649 $sql .= "article_alias='".aporeplace($alias)."'"; 650 $article_count = _dbQuery($sql, 'COUNT'); 651 652 // check alias against all "sub" contents like news 653 $sql = "SELECT COUNT(cnt_id) FROM ".DB_PREPEND."phpwcms_content WHERE "; 654 $sql .= $where_content; 655 $sql .= "cnt_alias='".aporeplace($alias)."'"; 656 $content_count = _dbQuery($sql, 'COUNT'); 657 658 if( $acat_count > 0 || $article_count > 0 || $content_count > 0 ) { 659 660 $sql = "SELECT acat_alias FROM ".DB_PREPEND."phpwcms_articlecat WHERE "; 661 $sql .= $where_acat; 662 $sql .= "acat_alias LIKE '".aporeplace($alias)."%'"; 663 $all_acat_alias = _dbQuery($sql); 664 665 $sql = "SELECT article_alias FROM ".DB_PREPEND."phpwcms_article WHERE "; 666 $sql .= $where_article; 667 $sql .= "article_alias LIKE '".aporeplace($alias)."%'"; 668 $all_article_alias = _dbQuery($sql); 669 670 $sql = "SELECT cnt_alias FROM ".DB_PREPEND."phpwcms_content WHERE "; 671 $sql .= $where_content; 672 $sql .= "cnt_alias LIKE '".aporeplace($alias)."%'"; 673 $all_content_alias = _dbQuery($sql); 674 675 $all_alias = array(); 676 foreach($all_acat_alias as $item) { 677 $item = $item['acat_alias']; 678 $all_alias[$item] = $item; 679 } 680 foreach($all_article_alias as $item) { 681 $item = $item['article_alias']; 682 $all_alias[$item] = $item; 683 } 684 foreach($all_content_alias as $item) { 685 $item = $item['cnt_alias']; 686 $all_alias[$item] = $item; 687 } 688 $all_alias_count = count($all_alias); 689 while( isset( $all_alias[ $alias.'-'.$all_alias_count ] ) ) { 690 $all_alias_count++; 691 } 692 693 if(preg_match('/\-(\d+)$/', $alias)) { 694 $alias .= $all_alias_count; 695 } else { 696 $alias .= '-'.$all_alias_count; 697 } 698 } 699 700 return $alias; 701 } 702 703 function _getTime($time='', $delimeter=':', $default_time='H:i:s') { 704 705 $timeformat = explode($delimeter, trim($default_time)); 706 $time = explode($delimeter, trim($time)); 707 708 $hour = 0; 709 $minute = 0; 710 $second = 0; 711 712 for($x=0; $x<=2; $x++) { 713 714 if(isset($timeformat[$x])) { 715 716 $value = trim($timeformat[$x]); 717 switch( $value{0} ) { 718 719 case 'H': if(isset($time[$x])) { 720 $hour = intval($time[$x]); 721 if($hour < 0 || $hour > 23) $hour = 0; 722 } 723 break; 724 725 case 'i': if(isset($time[$x])) { 726 $minute = intval($time[$x]); 727 if($minute < 0 || $minute > 59) $minute = 0; 728 } 729 break; 730 731 case 's': if(isset($time[$x])) { 732 $second = intval($time[$x]); 733 if($second < 0 || $second > 59) $second = 0; 734 } 735 break; 736 } 737 738 } 739 740 } 741 742 $time = str_replace($delimeter, ':', $default_time); 743 $time = str_replace('H', $hour, $time); 744 $time = str_replace('i', $minute, $time); 745 $time = str_replace('s', $second, $time); 746 747 return $time; 748 } 749 750 function _getDate($date='', $delimeter='', $default_date='') { 751 752 global $BL; 753 754 $delimeter = $delimeter == '' ? $BL['default_date_delimiter'] : $delimeter; 755 $default_date = $default_date == '' ? $BL['default_date'] : $default_date; 756 757 $dateformat = explode($delimeter, trim($default_date)); 758 $date = explode($delimeter, trim($date)); 759 760 $day = ''; 761 $month = ''; 762 $year = ''; 763 764 for($x=0; $x<=2; $x++) { 765 766 if(isset($dateformat[$x])) { 767 768 $value = trim($dateformat[$x]); 769 $value = strtolower($value); 770 switch( $value{0} ) { 771 772 case 'y': if(isset($date[$x])) { 773 $year = intval($date[$x]); 774 if($year < 0) $year = ''; 775 } 776 break; 777 778 case 'd': if(isset($date[$x])) { 779 $day = intval($date[$x]); 780 if($day < 1 || $day > 31) $day = ''; 781 } 782 break; 783 784 case 'm': if(isset($date[$x])) { 785 $month = intval($date[$x]); 786 if($month < 1 || $month > 12) $month = ''; 787 } 788 break; 789 790 } 791 792 } 793 794 } 795 796 if($year && $month && $day) { 797 798 return $year.'-'.$month.'-'.$day; 799 800 } else { 801 802 return '0000-00-00'; 803 804 } 805 806 } 807 808 function _dbSaveCategories($categories=array(), $type='', $pid=0, $seperator=',') { 809 810 $pid = intval($pid); 811 $type = trim($type); 812 813 if(is_string($categories)) { 814 $categories = convertStringToArray($categories, $seperator); 815 } 816 817 // delete all related categories first 818 if($type && $pid) { 819 820 $sql = 'DELETE FROM '.DB_PREPEND.'phpwcms_categories WHERE cat_pid='.$pid." AND cat_type='".aporeplace( $type )."'"; 821 _dbQuery($sql, 'DELETE'); 822 823 } 824 825 if(is_array($categories) && count($categories) && $type && $pid) { 826 827 $data = array( 'cat_type' => $type, 828 'cat_pid' => $pid, 829 'cat_status' => 1, 830 'cat_createdate' => date('Y-m-d H:i:s'), 831 'cat_changedate' => date('Y-m-d H:i:s'), 832 'cat_name' => '', 833 'cat_info' => '' 834 ); 835 836 foreach($categories as $value) { 837 $value = trim($value); 838 if($value != '') { 839 840 $data['cat_name'] = $value; 841 _dbInsert('phpwcms_categories', $data); 842 843 } 844 } 845 } 846 } 847 848 function setItemsPerPage($default=25) { 849 if( isset($_GET['showipp']) ) { 850 $ipp = intval( is_numeric($_GET['showipp']) ? $_GET['showipp'] : $default ); 851 setcookie('phpwcmsBEItemsPerPage', $ipp, time()+157680000, '/', getCookieDomain() ); 852 } elseif(isset($_SESSION['PAGE_FILTER'])) { 853 $ipp = $_SESSION['PAGE_FILTER']['IPP']; 854 } elseif( isset($_COOKIE['phpwcmsBEItemsPerPage']) ) { 855 $ipp = intval( $_COOKIE['phpwcmsBEItemsPerPage'] ); 856 } else { 857 $ipp = $default; 858 } 859 860 if(!isset($_SESSION['PAGE_FILTER'])) { 861 $_SESSION['PAGE_FILTER'] = array(); 862 } 863 864 $_SESSION['PAGE_FILTER']['IPP'] = $ipp; 865 866 return $ipp; 867 } 868 869 function getItemsPerPageMenu($base_url='', $steps=array(10,25,50,100,250,0), $separator=' ') { 870 871 $ipp = isset($_SESSION['PAGE_FILTER']['IPP']) ? $_SESSION['PAGE_FILTER']['IPP'] : setItemsPerPage(); 872 873 if(!in_array($ipp, $steps)) { 874 array_unshift($steps, $ipp); 875 } 876 877 $menu = array(); 878 $x = 0; 879 foreach($steps as $item) { 880 881 $menu[$x] = '<a href="'.$base_url.'&showipp='.$item.'"'; 882 if($ipp == $item) { 883 $menu[$x] .= ' class="active"'; 884 } 885 $menu[$x] .= '>'; 886 $menu[$x] .= $item == 0 ? $GLOBALS['BL']['be_ftptakeover_all'] : $item; 887 $menu[$x] .= '</a>'; 888 889 $x++; 890 } 891 892 return implode($separator, $menu); 893 } 894 895 function initJsCalendar() { 896 $GLOBALS['BE']['HEADER']['date.js'] = getJavaScriptSourceLink('include/inc_js/date.js'); 897 $GLOBALS['BE']['HEADER']['dynCalendar.js'] = getJavaScriptSourceLink('include/inc_js/dynCalendar.js'); 898 } 899 function initMootools($mode='1.1') { 900 switch($mode) { 901 case '1.1': 902 $GLOBALS['BE']['HEADER']['mootools.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools.js'); 903 break; 904 case 'COMPAT': 905 $GLOBALS['BE']['HEADER']['mootools-1.2-core.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools-1.2-core.js'); 906 $GLOBALS['BE']['HEADER']['mootools-1.2-more.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools-1.2-more.js'); 907 $GLOBALS['BE']['HEADER']['compat-mootools-core.js'] = getJavaScriptSourceLink('include/inc_js/mootools/compat-mootools-core.js'); 908 $GLOBALS['BE']['HEADER']['compat-mootools-more.js'] = getJavaScriptSourceLink('include/inc_js/mootools/compat-mootools-more.js'); 909 $GLOBALS['BE']['HEADER']['mootools-compat-custom.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools-compat-custom.js'); 910 break; 911 default: // 1.2 912 $GLOBALS['BE']['HEADER']['mootools-1.2-core.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools-1.2-core.js'); 913 $GLOBALS['BE']['HEADER']['mootools-1.2-more.js'] = getJavaScriptSourceLink('include/inc_js/mootools/mootools-1.2-more.js'); 914 } 915 } 916 function initMootoolsAutocompleter($mode='1.1') { 917 initMootools($mode); 918 $GLOBALS['BE']['HEADER']['Autocompleter.js'] = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Autocompleter.js'); 919 $GLOBALS['BE']['HEADER']['Autocompleter.Remote.js'] = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Autocompleter.Remote.js'); 920 $GLOBALS['BE']['HEADER']['Observer.js'] = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Observer.js'); 921 } 922 function initJsOptionSelect() { 923 $GLOBALS['BE']['HEADER']['optionselect.js'] = getJavaScriptSourceLink('include/inc_js/optionselect.js'); 924 } 925 function initMultipleUpload() { 926 initMootools(); 927 $GLOBALS['BE']['HEADER']['Swiff.Base.js'] = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/Swiff.Base.js'); 928 $GLOBALS['BE']['HEADER']['Swiff.Uploader.js'] = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/Swiff.Uploader.js'); 929 $GLOBALS['BE']['HEADER']['FancyUpload.js'] = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/FancyUpload.js'); 930 } 931 932 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 30 05:55:15 2009 | Cross-referenced by PHPXref 0.7 |