Changeset 467 for branches/eli_branch/lib
- Timestamp:
- Feb 19, 2014 2:28:00 AM (10 years ago)
- Location:
- branches/eli_branch
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eli_branch
-
branches/eli_branch/lib/ACL.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 23 23 /* 24 24 * ACL.inc.php 25 * 25 * 26 26 * Uses the ARO/ACO/AXO model of Access Control Lists. 27 27 * Uses Modified Preorder Tree Traversal to maintain a tree-structure. 28 28 * See: http://www.sitepoint.com/print/hierarchical-data-database 29 29 * Includes a command-line tool for managing rights (codebase/bin/acl.cli.php). 30 * 30 * 31 31 * 32 32 * @author Quinn Comendant <quinn@strangecode.com> … … 41 41 // Configuration parameters for this object. 42 42 private $_params = array( 43 43 44 44 // If false nothing will be cached or retrieved. Useful for testing realtime data requests. 45 45 'enable_cache' => true, … … 94 94 { 95 95 $app =& App::getInstance(); 96 96 97 97 if (isset($params) && is_array($params)) { 98 98 // Merge new parameters with old overriding only those passed. … … 113 113 { 114 114 $app =& App::getInstance(); 115 115 116 116 if (isset($this->_params[$param])) { 117 117 return $this->_params[$param]; … … 145 145 $app->logMsg(sprintf('Dropping and recreating tables acl_tbl, aro_tbl, aco_tbl, axo_tbl.', null), LOG_INFO, __FILE__, __LINE__); 146 146 } 147 147 148 148 // acl_tbl 149 149 $db->query(" … … 171 171 $qid = $db->query("SELECT 1 FROM acl_tbl"); 172 172 if (mysql_num_rows($qid) == 0) { 173 $qid = $db->query("REPLACE INTO acl_tbl VALUES ('1', '1', '1', 'deny', NOW())"); 174 } 173 $qid = $db->query("REPLACE INTO acl_tbl VALUES ('1', '1', '1', 'deny', NOW())"); 174 } 175 175 } 176 176 … … 202 202 $qid = $db->query("SELECT 1 FROM {$a_o}_tbl WHERE name = 'root'"); 203 203 if (mysql_num_rows($qid) == 0) { 204 $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())"); 205 } 204 $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())"); 205 } 206 206 } 207 207 … … 228 228 $app =& App::getInstance(); 229 229 $db =& DB::getInstance(); 230 230 231 231 $this->initDB(); 232 232 233 233 switch ($type) { 234 234 case 'aro' : … … 246 246 break; 247 247 } 248 248 249 249 // If $parent is null, use root object. 250 250 if (is_null($parent)) { 251 251 $parent = 'root'; 252 252 } 253 253 254 254 // Ensure node and parent name aren't empty. 255 255 if ('' == trim($name) || '' == trim($parent)) { … … 257 257 return false; 258 258 } 259 259 260 260 // Ensure node is unique. 261 261 $qid = $db->query("SELECT 1 FROM $tbl WHERE name = '" . $db->escapeString($name) . "'"); … … 264 264 return false; 265 265 } 266 266 267 267 // Select the rgt of $parent. 268 268 $qid = $db->query("SELECT rgt FROM $tbl WHERE name = '" . $db->escapeString($parent) . "'"); … … 275 275 $db->query("UPDATE $tbl SET lft = lft + 2 WHERE lft >= $parent_rgt"); 276 276 $db->query("UPDATE $tbl SET rgt = rgt + 2 WHERE rgt >= $parent_rgt"); 277 277 278 278 // Insert new node just below parent. Lft is parent's old rgt. 279 279 $db->query(" 280 INSERT INTO $tbl (name, lft, rgt, added_datetime) 280 INSERT INTO $tbl (name, lft, rgt, added_datetime) 281 281 VALUES ('" . $db->escapeString($name) . "', $parent_rgt, $parent_rgt + 1, NOW()) 282 282 "); … … 315 315 $app =& App::getInstance(); 316 316 $db =& DB::getInstance(); 317 317 318 318 $this->initDB(); 319 319 … … 336 336 break; 337 337 } 338 338 339 339 // Ensure node name isn't empty. 340 340 if ('' == trim($name)) { … … 342 342 return false; 343 343 } 344 344 345 345 // Select the lft and rgt of $name to use for selecting children and reordering transversals. 346 346 $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'"); … … 349 349 return false; 350 350 } 351 351 352 352 // Remove node and all children of node, as well as acl_tbl links. 353 353 $db->query(" 354 DELETE $tbl, acl_tbl 354 DELETE $tbl, acl_tbl 355 355 FROM $tbl 356 356 LEFT JOIN acl_tbl ON ($tbl.$primary_key = acl_tbl.$primary_key) … … 366 366 return true; 367 367 } 368 368 369 369 // Alias functions for the different object types. 370 370 public function removeRequestObject($name) … … 397 397 $app =& App::getInstance(); 398 398 $db =& DB::getInstance(); 399 399 400 400 $this->initDB(); 401 401 … … 418 418 break; 419 419 } 420 420 421 421 // If $new_parent is null, use root object. 422 422 if (is_null($new_parent)) { 423 423 $new_parent = 'root'; 424 424 } 425 425 426 426 // Ensure node and parent name aren't empty. 427 427 if ('' == trim($name) || '' == trim($new_parent)) { … … 429 429 return false; 430 430 } 431 431 432 432 // Select the lft and rgt of $name to use for selecting children and reordering transversals. 433 433 $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'"); … … 436 436 return false; 437 437 } 438 438 439 439 // Total number of transversal values (that is, the count of self plus all children times two). 440 440 $total_transversal_value = ($rgt - $lft + 1); … … 446 446 return false; 447 447 } 448 448 449 449 // Ensure the new parent is not a child of the node being moved. 450 450 if ($new_parent_rgt <= $rgt && $new_parent_rgt >= $lft) { … … 452 452 return false; 453 453 } 454 454 455 455 // Collect unique ids of all nodes being moved. The transversal numbers will become duplicated so these will be needed to identify these. 456 456 $qid = $db->query(" … … 472 472 // Apply transformation to new parent rgt also. 473 473 $new_parent_rgt = $new_parent_rgt > $rgt ? $new_parent_rgt - $total_transversal_value : $new_parent_rgt; 474 474 475 475 // Update transversal values of moved node and children. 476 476 $db->query(" 477 UPDATE $tbl SET 477 UPDATE $tbl SET 478 478 lft = lft - ($lft - $new_parent_rgt), 479 479 rgt = rgt - ($lft - $new_parent_rgt) … … 488 488 return true; 489 489 } 490 490 491 491 // Alias functions for the different object types. 492 492 public function moveRequestObject($name, $new_parent=null) … … 502 502 return $this->move($name, $new_parent, 'axo'); 503 503 } 504 504 505 505 /* 506 506 * Add an entry to the acl_tbl to allow (or deny) a truple with the specified … … 528 528 $aco = is_null($aco) ? 'root' : $aco; 529 529 $axo = is_null($axo) ? 'root' : $axo; 530 530 531 531 // Flush old cached values. 532 532 $cache_hash = $aro . '|' . $aco . '|' . $axo; … … 552 552 // Access must be 'allow' or 'deny'. 553 553 $allow = 'allow' == $access ? 'allow' : 'deny'; 554 554 555 555 $db->query("REPLACE INTO acl_tbl VALUES ('$aro_id', '$aco_id', '$axo_id', '$allow', NOW())"); 556 556 $app->logMsg(sprintf('Set %s: %s -> %s -> %s.', $allow, $aro, $aco, $axo), LOG_INFO, __FILE__, __LINE__); 557 557 558 558 return true; 559 559 } … … 577 577 return $this->grant($aro, $aco, $axo, 'deny'); 578 578 } 579 579 580 580 /* 581 581 * Delete an entry from the acl_tbl completely to allow other permissions to cascade down. … … 610 610 $aco = is_null($aco) ? 'root' : $aco; 611 611 $axo = is_null($axo) ? 'root' : $axo; 612 612 613 613 // Flush old cached values. 614 614 $cache_hash = $aro . '|' . $aco . '|' . $axo; … … 621 621 return false; 622 622 } 623 623 624 624 $qid = $db->query(" 625 625 DELETE acl_tbl … … 632 632 633 633 $app->logMsg(sprintf('Deleted %s acl_tbl links: %s -> %s -> %s', mysql_affected_rows($db->getDBH()), $aro, $aco, $axo), LOG_INFO, __FILE__, __LINE__); 634 634 635 635 return true; 636 636 } 637 637 638 638 /* 639 639 * Calculates the most specific cascading privilege found for a requested 640 * ARO -> ACO -> AXO entry. Returns FALSE if the entry is denied. By default, 640 * ARO -> ACO -> AXO entry. Returns FALSE if the entry is denied. By default, 641 641 * all entries are denied, unless some point in the hierarchy is set to "allow." 642 642 * … … 654 654 $app =& App::getInstance(); 655 655 $db =& DB::getInstance(); 656 656 657 657 $this->initDB(); 658 658 … … 661 661 $aco = is_null($aco) || '' == trim($aco) ? 'root' : $aco; 662 662 $axo = is_null($axo) || '' == trim($axo) ? 'root' : $axo; 663 663 664 664 $cache_hash = $aro . '|' . $aco . '|' . $axo; 665 665 if ($this->cache->exists($cache_hash) && true === $this->getParam('enable_cache')) { … … 687 687 $this->cache->set($cache_hash, $access); 688 688 } 689 689 690 690 if ('allow' == $access) { 691 691 $app->logMsg(sprintf('Access granted: %s -> %s -> %s.', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__); … … 697 697 } 698 698 699 /* 700 * Bounce user if they are denied access. Because this function calls dieURL() it must be called before any other HTTP header output. 701 * 702 * @access public 703 * @param string $aro Identifier of an existing ARO object. 704 * @param string $aco Identifier of an existing ACO object (or null to use root). 705 * @param string $axo Identifier of an existing AXO object (or null to use root). 706 * @param string $message The text description of a message to raise. 707 * @param int $type The type of message: MSG_NOTICE, 708 * MSG_SUCCESS, MSG_WARNING, or MSG_ERR. 709 * @param string $file __FILE__. 710 * @param string $line __LINE__. 711 * @author Quinn Comendant <quinn@strangecode.com> 712 * @version 1.0 713 * @since 20 Jan 2014 12:09:03 714 */ 715 public function requireAllow($aro, $aco=null, $axo=null, $message='', $type=MSG_NOTICE, $file=null, $line=null) 716 { 717 $app =& App::getInstance(); 718 719 if (!$this->check($aro, $aco, $axo)) { 720 $message = '' == trim($message) ? sprintf(_("You have insufficient privileges to view <em>%s %s</em>"), $aco, $axo) : $message; 721 $app->raiseMsg($message, $type, $file, $line); 722 $app->dieBoomerangURL(); 723 } 724 } 725 699 726 } // End class. 700 701 -
branches/eli_branch/lib/App.inc.php
r449 r467 403 403 $this->db->close(); 404 404 } 405 $mem_current = memory_get_usage(); 406 $mem_peak = memory_get_peak_usage(); 405 407 $this->timer->stop('_app'); 406 $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s. ', $this->timer->getTime('_app'), $num_queries), LOG_DEBUG, __FILE__, __LINE__);408 $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s. Memory usage: %s. Peak memory: %s.', $this->timer->getTime('_app'), $num_queries, $mem_current, $mem_peak), LOG_DEBUG, __FILE__, __LINE__); 407 409 } 408 410 … … 961 963 // urlencode is not used here, not for form data! 962 964 $query_args = array_merge($this->_carry_queries, $one_time_carry_queries); 963 foreach ($query_args as $key=>$val) { 964 printf('<input type="hidden" name="%s" value="%s" />', $key, $val); 965 } 965 foreach ($query_args as $key => $val) { 966 if (is_array($val)) { 967 foreach ($val as $subval) { 968 printf('<input type="hidden" name="%s[]" value="%s" />', $key, $subval); 969 } 970 } else { 971 printf('<input type="hidden" name="%s" value="%s" />', $key, $val); 972 } 973 } 974 unset($query_args, $key, $val, $subval); 966 975 } 967 976 … … 1238 1247 } 1239 1248 } 1240 1241 1242 1249 } // End. -
branches/eli_branch/lib/Auth_SQL.inc.php
r449 r467 424 424 // No login: failed authentication! 425 425 return false; 426 } 427 428 // Convert 'priv' to 'user_type' nomenclature to support older implementations. 429 if (isset($user_data['priv'])) { 430 $user_data['user_type'] = $user_data['priv']; 426 431 } 427 432 … … 649 654 } 650 655 $app->logMsg(sprintf('User_id %s (%s) session expired: %s', $this->get('user_id'), $this->get('username'), join(', ', $expire_reasons)), LOG_INFO, __FILE__, __LINE__); 651 } else {652 $app->logMsg(sprintf('Session not authenticated: %s', getDump($_SESSION['_auth_sql'][$this->_ns])), LOG_DEBUG, __FILE__, __LINE__);653 656 } 654 657 -
branches/eli_branch/lib/Cache.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 31 31 * @since 2001 32 32 */ 33 33 34 34 // Flags. 35 35 define('CACHE_ALLOW_OVERSIZED', 1); … … 42 42 // Configuration parameters for this object. 43 43 private $_params = array( 44 44 45 45 // If false nothing will be cached or retrieved. Useful for testing realtime data requests. 46 46 'enabled' => true, … … 48 48 // The maximum size in bytes of any one variable. 49 49 'item_size_limit' => 4194304, // 4 MB 50 50 51 51 // The maximum size in bytes before the cache will begin flushing out old items. 52 52 'stack_size_limit' => 4194304, // 4 MB 53 53 54 54 // The minimum items to keep in the cache regardless of item or cache size. 55 55 'min_items' => 5, 56 56 ); 57 57 58 58 /* 59 59 * Constructor … … 68 68 { 69 69 $app =& App::getInstance(); 70 70 71 71 $this->_ns = $namespace; 72 72 … … 75 75 $this->setParam(array('enabled' => false)); 76 76 } 77 77 78 78 if (!isset($_SESSION['_cache'][$this->_ns])) { 79 79 $this->clear(); … … 127 127 { 128 128 $app =& App::getInstance(); 129 129 130 130 if (isset($this->_params[$param])) { 131 131 return $this->_params[$param]; … … 138 138 /** 139 139 * Stores a new variable in the session cache. The $key should not be numeric 140 * because the array_shift function will reset the key to the next largest 140 * because the array_shift function will reset the key to the next largest 141 141 * int key. Weird behavior I can't understand. For example $cache["123"] will become $cache[0] 142 142 * … … 168 168 $app->logMsg(sprintf('Serialized variable (%s bytes) more than stack_size_limit (%s bytes).', $var_len, $this->getParam('stack_size_limit')), LOG_NOTICE, __FILE__, __LINE__); 169 169 return false; 170 } 170 } 171 171 172 172 // Remove any value already stored under this key. … … 253 253 } 254 254 } 255 255 256 256 /* 257 257 * Delete all existing items from the cache. -
branches/eli_branch/lib/Email.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. 21 21 */ 22 22 23 /** 24 * Email.inc.php 25 * 26 * Easy email template usage. 27 * 28 * @author Quinn Comendant <quinn@strangecode.com> 29 * @version 1.0 30 * 31 32 // Example. 23 /* 24 * Email.inc.php 25 * 26 * Easy email template usage. 27 * 28 * @author Quinn Comendant <quinn@strangecode.com> 29 * @version 1.0 30 * 31 * Example of use: 32 --------------------------------------------------------------------- 33 // Setup email object. 33 34 $email = new Email(array( 34 35 'to' => array($frm['email'], 'q@lovemachine.local'), … … 49 50 $app->logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__); 50 51 } 51 52 * 53 */ 52 --------------------------------------------------------------------- 53 */ 54 54 55 class Email { 55 56 … … 61 62 'headers' => null, 62 63 'regex' => null, 63 64 64 65 // A single carriage return (\n) should terminate lines for locally injected mail. 65 66 // A carriage return + line-feed (\r\n) should be used if sending mail directly with SMTP. 66 67 'crlf' => "\n", 67 68 68 69 // RFC 2822 says line length MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF. 69 70 // http://mailformat.dan.info/body/linelength.html … … 120 121 { 121 122 $app =& App::getInstance(); 122 123 123 124 if (isset($params) && is_array($params)) { 124 125 // Enforce valid email addresses. … … 147 148 { 148 149 $app =& App::getInstance(); 149 150 150 151 if (isset($this->_params[$param])) { 151 152 return $this->_params[$param]; … … 167 168 { 168 169 $app =& App::getInstance(); 169 170 170 171 // Load file, using include_path. 171 172 if (!$this->_template = file_get_contents($template, true)) { … … 191 192 { 192 193 $app =& App::getInstance(); 193 194 194 195 if ('' == trim($string)) { 195 196 $app->logMsg(sprintf('Empty string provided.', null), LOG_ERR, __FILE__, __LINE__); … … 215 216 { 216 217 $app =& App::getInstance(); 217 218 218 219 // Ensure template exists. 219 220 if (!isset($this->_template)) { … … 285 286 $final_body = isset($this->_template_replaced) ? $this->_template_replaced : $this->_template; 286 287 if (false !== $this->getParam('wrap')) { 287 $final_body = wordwrap($final_body, $this->getParam('line_length'), $this->getParam('crlf')); 288 $final_body = wordwrap($final_body, $this->getParam('line_length'), $this->getParam('crlf')); 288 289 } 289 290 … … 320 321 $envelope_sender_header = sprintf('-f %s', $envelope_sender_address); 321 322 } else { 322 $envelope_sender_header = ''; 323 $envelope_sender_header = ''; 323 324 } 324 325 … … 331 332 } 332 333 333 // Send email without 5th parameter if safemode is enabled. 334 // Send email without 5th parameter if safemode is enabled. 334 335 if (ini_get('safe_mode')) { 335 336 $ret = mb_send_mail($final_to, $this->_params['subject'], $final_body, $final_headers); … … 337 338 $ret = mb_send_mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header); 338 339 } 339 340 340 341 // Ensure message was successfully accepted for delivery. 341 342 if ($ret) { … … 345 346 $app->logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__); 346 347 return false; 347 } 348 } 348 349 } 349 350 … … 366 367 { 367 368 $app =& App::getInstance(); 368 369 369 370 // If an array, check values recursively. 370 371 if (is_array($email)) { -
branches/eli_branch/lib/FormValidator.inc.php
r450 r467 481 481 $app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__); 482 482 return false; 483 break;484 483 485 484 case parent::EMAIL_LENGTH_FAIL : … … 488 487 $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__); 489 488 return false; 490 break;491 489 492 490 case parent::EMAIL_MX_FAIL : … … 495 493 $app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_INFO, __FILE__, __LINE__); 496 494 return false; 497 break;498 495 499 496 case parent::EMAIL_SUCCESS : 500 497 default : 501 498 return true; 502 break;503 499 } 504 500 } … … 535 531 $app =& App::getInstance(); 536 532 537 if (parent::validateStrDate(getFormData($form_name ))) {533 if (parent::validateStrDate(getFormData($form_name, ''))) { 538 534 return true; 539 535 } else { -
branches/eli_branch/lib/Hierarchy.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 23 23 /** 24 24 * Hierarchy.inc.php 25 * 25 * 26 26 * Objective: This class provides the tools to organize pieces of data into a 27 27 * hierarchy of nodes. Any form of data (article, product, image) can be … … 116 116 { 117 117 $app =& App::getInstance(); 118 118 119 119 if (!isset($child_type) || !isset($child_id)) { 120 120 if ($this->node_init) { … … 150 150 { 151 151 $app =& App::getInstance(); 152 152 153 153 if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) { 154 154 return array('node_type' => $node_parts[1], 'node_id' => $node_parts[2]); … … 171 171 $app =& App::getInstance(); 172 172 $db =& DB::getInstance(); 173 173 174 174 if (!isset($child_type) || !isset($child_id)) { 175 175 if ($this->node_init) { … … 250 250 $app =& App::getInstance(); 251 251 $db =& DB::getInstance(); 252 252 253 253 if (!isset($child_type) || !isset($child_id)) { 254 254 if ($this->node_init) { … … 377 377 $app =& App::getInstance(); 378 378 $db =& DB::getInstance(); 379 379 380 380 if (!isset($child_type) || !isset($child_id)) { 381 381 if ($this->node_init) { … … 428 428 $app =& App::getInstance(); 429 429 $db =& DB::getInstance(); 430 430 431 431 if (!isset($child_type) || !isset($child_id)) { 432 432 if ($this->node_init) { … … 472 472 $app =& App::getInstance(); 473 473 $db =& DB::getInstance(); 474 474 475 475 if (!isset($child_type) || !isset($child_id)) { 476 476 if ($this->node_init) { … … 564 564 { 565 565 $app =& App::getInstance(); 566 566 567 567 if (!isset($child_type) || !isset($child_id)) { 568 568 if ($this->node_init) { … … 625 625 { 626 626 $db =& DB::getInstance(); 627 627 628 628 static $output = array(); 629 629 static $return_flag; … … 680 680 $app =& App::getInstance(); 681 681 $db =& DB::getInstance(); 682 682 683 683 if (!isset($child_type) || !isset($child_id)) { 684 684 if ($this->node_init) { … … 731 731 { 732 732 $app =& App::getInstance(); 733 733 734 734 static $output = array(); 735 735 static $is_a_leaf = array(); … … 804 804 { 805 805 $db =& DB::getInstance(); 806 806 807 807 // Reset all the category counters to zero. 808 808 $db->query("UPDATE node_tbl SET subnode_quantity = 0"); … … 828 828 { 829 829 $db =& DB::getInstance(); 830 830 831 831 $db->query(" 832 832 UPDATE node_tbl -
branches/eli_branch/lib/Image.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 49 49 // Pattern passed to glob() with $id to match image filenames. 50 50 'filename_pattern' => '%s*', 51 51 52 52 // The path to the image source directory. (Ex: /var/www/htdocs/images) 53 53 'base_path' => '', 54 54 55 55 // The URL to the image directory. (Ex: /images) 56 56 'base_url' => '', 57 57 58 58 // Image to use in the case of a missing image. 59 59 'default_image_file' => '', … … 61 61 $this->_params = array_merge($defaults, $params); 62 62 } 63 63 64 64 /** 65 65 * Tests if an image with specified id exists on the file system. … … 77 77 $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src; 78 78 // Use exif_imagetype to check not only file existence but that of a valid image. 79 // The return value is the same value that getimagesize() returns in index 2 but exif_imagetype() is much faster. 79 80 return false != @exif_imagetype($filepath); 80 81 } 81 82 82 83 /** 83 84 * Returns the value from getimagesize(). … … 85 86 * @access public 86 87 * @param string $id Unique image identifier. 87 * @param int $key Which element from the array returned by getimagesize: 88 * - Index 0 contains the width of the image in pixels. 89 * - Index 1 contains the height. 90 * - Index 2 is the type of the image. 88 * @param int $key Which element from the array returned by getimagesize: 89 * - Index 0 contains the width of the image in pixels. 90 * - Index 1 contains the height. 91 * - Index 2 is the type of the image. 91 92 * - Index 3 is height="yyy" width="xxx" string. 92 93 * @return mixed return value of getimagesize. … … 102 103 return isset($img_size[$key]) ? $img_size[$key] : false; 103 104 } 104 105 105 106 /** 106 107 * Returns the URL to the source of image specified by id. … … 126 127 127 128 /** 128 * Returns an HTML <img> tag with the src set to an image specified by id. 129 * Returns an HTML <img> tag with the src set to an image specified by id. 129 130 * Automatically prints image width and height. 130 131 * … … 142 143 $src = $this->oSrc($id); 143 144 $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src; 144 145 145 146 if (false === ($gis = @getimagesize($filepath)) || preg_match('/width|height/', $extra)) { 146 147 $image_size = ''; … … 148 149 $image_size = $gis[3]; 149 150 } 150 151 151 152 return sprintf('<img src="%s" %s alt="%s" %s />', 152 153 $src, -
branches/eli_branch/lib/Navigation.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 28 28 * and titles, as well as setting page params such as hiding the page title on 29 29 * some pages but not others, and storing vars like the page title itself. 30 * 30 * 31 31 * Note: this class was renamed from "Nav" because of the change in API and to be more descriptive. 32 32 * … … 37 37 38 38 // Configuration parameters for this object. 39 private $_params = array( 39 private $_params = array( 40 40 'head_title' => true, 41 41 'body_title' => true, … … 68 68 * current page added last. Vars can be specified for any page, but only vars 69 69 * from the "current" page will be accessed with Nav::get. 70 * 70 * 71 71 * @access public 72 72 * @param string $title The title of the page. … … 94 94 { 95 95 $app =& App::getInstance(); 96 96 97 97 if (isset($params) && is_array($params)) { 98 98 // Merge new parameters with old overriding only those passed. … … 113 113 { 114 114 $app =& App::getInstance(); 115 115 116 116 if (isset($this->_params[$param])) { 117 117 return $this->_params[$param]; … … 142 142 { 143 143 // Set params of current page. 144 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 144 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 145 145 $curr_page[$key] = $val; 146 146 } … … 157 157 { 158 158 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 159 159 160 160 switch ($key) { 161 161 case 'title' : … … 279 279 * @return mixed The value set for $return, TRUE by default. 280 280 */ 281 public function currentPage($page_uri, $return=true) 282 { 283 if (preg_match('/^' . preg_quote(urldecode($page_uri), '/') . '/i', $_SERVER['PHP_SELF'])) { 284 return $return; 285 } 281 public function currentPage($test_uri, $true_return=true, $false_return=false, $strip_query=false) 282 { 283 $actual_uri = $strip_query ? strtok($_SERVER['REQUEST_URI'], '?') : $_SERVER['REQUEST_URI']; 284 $test_uri = $strip_query ? strtok($test_uri, '?') : $test_uri; 285 if (preg_match('/^' . preg_quote(urldecode($test_uri), '/') . '$/i', $actual_uri)) { 286 return $true_return; 287 } 288 return $false_return; 286 289 } 287 290 -
branches/eli_branch/lib/PEdit.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 35 35 * and call printing/editing functions where you want data and forms to 36 36 * show up. 37 * 37 * 38 38 * @author Quinn Comendant <quinn@strangecode.com> 39 39 * @concept Beau Smith <beau@beausmith.com> 40 * @version 2.0 41 * 40 * @version 2.0 41 * 42 42 * Example of use: 43 43 44 44 // Initialize PEdit object. 45 45 require_once 'codebase/lib/PEdit.inc.php'; … … 48 48 'authorized' => true, 49 49 )); 50 50 51 51 // Setup content data types. 52 52 $pedit->set('title'); 53 53 $pedit->set('content', array('type' => 'textarea')); 54 54 55 55 // After setting all parameters and data, load the data. 56 56 $pedit->start(); 57 57 58 58 // Print content. 59 59 echo $pedit->get('title'); 60 60 echo $pedit->get('content'); 61 61 62 62 // Print additional PEdit functionality. 63 63 $pedit->formBegin(); … … 96 96 { 97 97 $this->setParam($params); 98 98 99 99 if ($this->getParam('authorized') === true) { 100 100 $this->_authorized = true; 101 101 } 102 102 103 103 // Setup PEAR XML libraries. 104 104 require_once 'XML/Serializer.php'; … … 114 114 )); 115 115 } 116 116 117 117 /** 118 118 * Set (or overwrite existing) parameters by passing an array of new parameters. … … 143 143 { 144 144 $app =& App::getInstance(); 145 145 146 146 if (isset($this->_params[$param])) { 147 147 return $this->_params[$param]; … … 151 151 } 152 152 } 153 153 154 154 /* 155 155 * Load the pedit data and run automatic functions. … … 166 166 trigger_error(sprintf('PEdit data directory not found: %s', $this->getParam('data_dir')), E_USER_WARNING); 167 167 } 168 168 169 169 // The location of the data file. (i.e.: "COMMON_DIR/html/_pedit_data/news/index.xml") 170 170 $this->_data_file = sprintf('%s%s.xml', $this->getParam('data_dir'), $_SERVER['SCRIPT_NAME']); 171 172 // Make certain the evaluated path matches the assumed path (realpath will expand /../../); 171 172 // Make certain the evaluated path matches the assumed path (realpath will expand /../../); 173 173 // if realpath returns FALSE we're not concerned because it means the file doesn't exist (_initializeDataFile() will create it). 174 174 if (false !== realpath($this->_data_file) && $this->_data_file !== realpath($this->_data_file)) { … … 199 199 break; 200 200 } 201 201 202 202 // Load data. 203 203 $this->_loadDataFile(); … … 258 258 return false; 259 259 } 260 ?> 260 ?> 261 261 <form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="post" id="sc-pedit-form"> 262 262 <input type="hidden" name="filename" value="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" /> … … 307 307 public function printForm($name, $type='text') 308 308 { 309 if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) { 309 if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) { 310 310 ?> 311 311 <div class="sc-pedit-item"> … … 468 468 } 469 469 $xml_file_contents = file_get_contents($this->_data_file); 470 $status = $this->xml_unserializer->unserialize($xml_file_contents, false); 470 $status = $this->xml_unserializer->unserialize($xml_file_contents, false); 471 471 if (PEAR::isError($status)) { 472 472 $app->logMsg(sprintf('XML_Unserialize error: %s', $status->getMessage()), LOG_WARNING, __FILE__, __LINE__); … … 487 487 return true; 488 488 } 489 489 490 490 /* 491 491 * Start a new data file. … … 535 535 return false; 536 536 } 537 537 538 538 // Collect posted data that is already specified in _data (by set()). 539 539 foreach ($new_data as $name => $content) { … … 542 542 } 543 543 } 544 544 545 545 if (is_array($this->_data) && !empty($this->_data)) { 546 546 $xml_file_contents = $this->xml_serializer->serialize($this->_data); … … 549 549 } 550 550 } 551 551 552 552 /* 553 553 * Writes content to the specified file. … … 587 587 if ($fp = fopen($filename, 'w')) { 588 588 if (flock($fp, LOCK_EX)) { 589 fwrite($fp, $content , mb_strlen($content));589 fwrite($fp, $content); 590 590 flock($fp, LOCK_UN); 591 591 } else { … … 639 639 return true; 640 640 } 641 641 642 642 /* 643 643 * Delete all versions older than versions_min_days if there are more than versions_min_qty or 100. … … 714 714 return false; 715 715 } 716 716 717 717 // The file to restore. 718 718 $version_file = sprintf('%s__%s.xml', preg_replace('/\.xml$/', '', $this->_data_file), $version); 719 719 720 720 // Ensure specified version exists. 721 721 if (!file_exists($version_file)) { -
branches/eli_branch/lib/Prefs.inc.php
r438 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 24 24 * Prefs.inc.php 25 25 * 26 * Prefs provides an API for saving arbitrary values in a user's session. 26 * Prefs provides an API for saving arbitrary values in a user's session. 27 27 * Session prefs can be stored into a database with the optional save() and load() methods. 28 28 * 29 29 * @author Quinn Comendant <quinn@strangecode.com> 30 30 * @version 2.1 31 * 31 * 32 32 * Example of use: 33 33 --------------------------------------------------------------------- … … 59 59 // Configuration parameters for this object. 60 60 var $_params = array( 61 61 62 62 // Enable database storage. If this is false, all prefs will live only as long as the session. 63 63 'persistent' => false, 64 64 65 65 // The current user_id for which to load/save persistent preferences. 66 66 'user_id' => null, 67 67 68 68 // How long before we force a reload of the persistent prefs data? 3600 = once every hour. 69 69 'load_timeout' => 3600, 70 70 71 71 // Name of database table to store persistent prefs. 72 72 'db_table' => 'pref_tbl', … … 85 85 86 86 $this->_ns = $namespace; 87 87 88 88 // Initialized the prefs array. 89 if (!isset($_SESSION['_prefs'][$this->_ns] )) {89 if (!isset($_SESSION['_prefs'][$this->_ns]['saved'])) { 90 90 $this->clear(); 91 91 } … … 160 160 { 161 161 $app =& App::getInstance(); 162 162 163 163 if (isset($this->_params[$param])) { 164 164 return $this->_params[$param]; … … 170 170 171 171 /** 172 * Sets the default values for preferences. If a preference is not explicitly 172 * Sets the default values for preferences. If a preference is not explicitly 173 173 * set, the value set here will be used. Can be called multiple times to merge additional 174 174 * defaults together. 175 175 * 176 * @param array $defaults Array of key-value pairs 176 * @param array $defaults Array of key-value pairs 177 177 */ 178 178 function setDefaults($defaults) … … 200 200 return false; 201 201 } 202 203 // Set a persistentpreference if...202 203 // Set a saved preference if... 204 204 // - there isn't a default. 205 // - the new value is different than the default 206 // - there is a previously existing persistent key. 207 if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val || isset($_SESSION['_prefs'][$this->_ns]['persistent'][$key])) { 208 $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val; 205 // - or the new value is different than the default 206 // - or there is a previously existing saved key. 207 if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) 208 || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val 209 || isset($_SESSION['_prefs'][$this->_ns]['saved'][$key])) { 210 $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val; 209 211 $app->logMsg(sprintf('Setting preference %s => %s', $key, truncate(getDump($val, true), 128, 'end')), LOG_DEBUG, __FILE__, __LINE__); 210 212 } else { … … 214 216 215 217 /** 216 * Returns the value of the requested preference. Persistentvalues take precedence, but if none is set218 * Returns the value of the requested preference. Saved values take precedence, but if none is set 217 219 * a default value is returned, or if not that, null. 218 220 * … … 224 226 { 225 227 $app =& App::getInstance(); 226 if (isset($_SESSION['_prefs'][$this->_ns][' persistent']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent'])) {227 $app->logMsg(sprintf('Found %s in persistent', $key), LOG_DEBUG, __FILE__, __LINE__);228 return $_SESSION['_prefs'][$this->_ns][' persistent'][$key];228 if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) { 229 $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__); 230 return $_SESSION['_prefs'][$this->_ns]['saved'][$key]; 229 231 } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) { 230 232 $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__); … … 244 246 function exists($key) 245 247 { 246 return array_key_exists($key, $_SESSION['_prefs'][$this->_ns][' persistent']);247 } 248 249 /** 250 * Clear a set preference value. This will also remove the value from the database. 248 return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']); 249 } 250 251 /** 252 * Clear a set preference value. This will also remove the value from the database. 251 253 * 252 254 * @param string $key The name of the preference to delete. … … 254 256 function delete($key) 255 257 { 256 unset($_SESSION['_prefs'][$this->_ns][' persistent'][$key]);257 } 258 259 /** 260 * Resets the $_SESSION cache. This should be executed with the same consideration 258 unset($_SESSION['_prefs'][$this->_ns]['saved'][$key]); 259 } 260 261 /** 262 * Resets the $_SESSION cache. This should be executed with the same consideration 261 263 * as $auth->clear(), such as when logging out. 262 264 */ … … 269 271 'load_datetime' => '1970-01-01', 270 272 'defaults' => array(), 271 ' persistent' => array(),273 'saved' => array(), 272 274 ); 273 275 break; … … 277 279 break; 278 280 279 case ' persistent' :280 $_SESSION['_prefs'][$this->_ns][' persistent'] = array();281 case 'saved' : 282 $_SESSION['_prefs'][$this->_ns]['saved'] = array(); 281 283 break; 282 284 } 283 285 } 284 286 285 287 /* 286 288 * Retrieves all prefs from the database and stores them in the $_SESSION. … … 297 299 $app =& App::getInstance(); 298 300 $db =& DB::getInstance(); 299 301 300 302 // Skip this method if not using the db. 301 303 if (true !== $this->getParam('persistent')) { … … 315 317 return false; 316 318 } 317 319 318 320 // Clear existing cache. 319 $this->clear(' persistent');320 321 $this->clear('saved'); 322 321 323 // Retrieve all prefs for this user and namespace. 322 324 $qid = $db->query(" … … 328 330 "); 329 331 while (list($key, $val) = mysql_fetch_row($qid)) { 330 $_SESSION['_prefs'][$this->_ns][' persistent'][$key] = unserialize($val);332 $_SESSION['_prefs'][$this->_ns]['saved'][$key] = unserialize($val); 331 333 } 332 334 333 335 $app->logMsg(sprintf('Loaded %s prefs from database.', mysql_num_rows($qid)), LOG_DEBUG, __FILE__, __LINE__); 334 336 335 337 // Data loaded only once per session. 336 338 $_SESSION['_prefs'][$this->_ns]['loaded'] = true; 337 339 $_SESSION['_prefs'][$this->_ns]['load_datetime'] = date('Y-m-d H:i:s'); 338 340 339 341 return true; 340 342 } 341 343 342 344 /* 343 345 * Returns true if the prefs had been loaded from the database into the $_SESSION recently. 344 346 * This function is simply a check so the database isn't access every page load. 345 * 347 * 346 348 * @access private 347 349 * @return bool True if prefs are loaded. … … 354 356 if (isset($_SESSION['_prefs'][$this->_ns]['load_datetime']) 355 357 && strtotime($_SESSION['_prefs'][$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout') 356 && isset($_SESSION['_prefs'][$this->_ns]['loaded']) 358 && isset($_SESSION['_prefs'][$this->_ns]['loaded']) 357 359 && true === $_SESSION['_prefs'][$this->_ns]['loaded']) { 358 360 return true; … … 361 363 } 362 364 } 363 365 364 366 /* 365 367 * Saves all prefs stored in the $_SESSION into the database. … … 375 377 $app =& App::getInstance(); 376 378 $db =& DB::getInstance(); 377 379 378 380 // Skip this method if not using the db. 379 381 if (true !== $this->getParam('persistent')) { 380 382 return true; 381 383 } 382 384 383 385 // User_id must not be empty. 384 386 if ('' == $this->getParam('user_id')) { … … 389 391 $this->initDB(); 390 392 391 if (isset($_SESSION['_prefs'][$this->_ns][' persistent']) && is_array($_SESSION['_prefs'][$this->_ns]['persistent']) && !empty($_SESSION['_prefs'][$this->_ns]['persistent'])) {393 if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && is_array($_SESSION['_prefs'][$this->_ns]['saved']) && !empty($_SESSION['_prefs'][$this->_ns]['saved'])) { 392 394 // Delete old prefs from database. 393 395 $db->query(" … … 396 398 AND pref_namespace = '" . $db->escapeString($this->_ns) . "' 397 399 "); 398 400 399 401 // Insert new prefs. 400 402 $insert_values = array(); 401 foreach ($_SESSION['_prefs'][$this->_ns][' persistent'] as $key => $val) {402 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", 403 $db->escapeString($this->getParam('user_id')), 404 $db->escapeString($this->_ns), 405 $db->escapeString($key), 403 foreach ($_SESSION['_prefs'][$this->_ns]['saved'] as $key => $val) { 404 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", 405 $db->escapeString($this->getParam('user_id')), 406 $db->escapeString($this->_ns), 407 $db->escapeString($key), 406 408 $db->escapeString(serialize($val)) 407 409 ); … … 409 411 // TODO: after MySQL 5.0.23 is released this query could benefit from INSERT DELAYED. 410 412 $db->query(" 411 INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " 413 INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " 412 414 (user_id, pref_namespace, pref_key, pref_value) 413 415 VALUES " . join(', ', $insert_values) . " 414 416 "); 415 417 416 418 $app->logMsg(sprintf('Saved %s prefs to database.', sizeof($insert_values)), LOG_DEBUG, __FILE__, __LINE__); 417 419 return true; 418 420 } 419 421 420 422 return false; 421 423 } -
branches/eli_branch/lib/SortOrder.inc.php
r451 r467 24 24 * SortOrder.inc.php 25 25 * 26 * SortOrder can determin ghow to sort results of a database query for display26 * SortOrder can determine how to sort results of a database query for display 27 27 * on a listing. It can print column headers that will be links to 28 28 * automatically change the sort and order. … … 139 139 * for example, for an alphabetical sort) 140 140 */ 141 public function set($sort = null, $order = null)141 public function set($sort=null, $order=null, $save_value=true) 142 142 { 143 143 // Set new sort value. 144 144 if (isset($sort)) { 145 145 $this->sort_by = $sort; 146 $this->prefs->set('sort_by', $this->sort_by); 146 if ($save_value) { 147 $this->prefs->set('sort_by', $this->sort_by); 148 } 147 149 } 148 150 … … 150 152 if (isset($order)) { 151 153 $this->order = $order; 152 $this->prefs->set('sort_order', $this->order); 154 if ($save_value) { 155 $this->prefs->set('sort_order', $this->order); 156 } 153 157 } 154 158 } -
branches/eli_branch/lib/Utilities.inc.php
r439 r467 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 33 33 * @param bool $var_dump Use var_dump instead of print_r. 34 34 */ 35 function dump($var, $display=false, $var_dump=false) 36 { 35 function dump($var, $display=false, $var_dump=false, $file='', $line='') 36 { 37 if (defined('_CLI')) { 38 echo "\n$file $line\n"; 39 } else { 40 echo $display ? "\n<br /><strong>$file $line</strong>\n<br /><pre>\n" : "\n\n\n<!--\n$file $line\n"; 41 } 42 if ($var_dump) { 43 var_dump($var); 44 } else { 45 print_r($var); 46 } 37 47 if (defined('_CLI')) { 38 48 echo "\n"; 39 } else { 40 echo $display ? "\n<br /><pre>\n" : "\n\n\n<!--\n"; 41 } 42 if ($var_dump) { 43 var_dump($var); 44 } else { 45 print_r($var); 46 } 47 if (defined('_CLI')) { 48 echo "\n"; 49 } else { 49 } else { 50 50 echo $display ? "\n</pre><br />\n" : "\n-->\n\n\n"; 51 51 } 52 52 } 53 53 54 /** 55 * Return dump as variable. 56 * 57 * @param mixed $var Variable to dump. 58 * @param bool $serialize Remove line-endings. Useful for logging variables. 59 * @return string Dump of var. 60 */ 54 /* 55 * Log a PHP variable to javascript console. Relies on getDump(), below. 56 * 57 * @access public 58 * @param mixed $var The variable to dump. 59 * @param string $prefix A short note to print before the output to make identifying output easier. 60 * @param string $file The value of __FILE__. 61 * @param string $line The value of __LINE__. 62 * @return null 63 * @author Quinn Comendant <quinn@strangecode.com> 64 */ 65 function jsDump($var, $prefix='jsDump', $file='-', $line='-') 66 { 67 if (!empty($var)) { 68 ?> 69 <script type="text/javascript" charset="utf-8"> 70 /* <![CDATA[ */ 71 window.console && console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>'); 72 /* ]]> */ 73 </script> 74 <?php 75 } 76 } 77 78 /* 79 * Return a string version of any variable, optionally serialized on one line. 80 * 81 * @access public 82 * @param mixed $var The variable to dump. 83 * @param bool $serialize If true, remove line-endings. Useful for logging variables. 84 * @return string The dumped variable. 85 * @author Quinn Comendant <quinn@strangecode.com> 86 */ 61 87 function getDump($var, $serialize=false) 62 88 { … … 65 91 $d = ob_get_contents(); 66 92 ob_end_clean(); 67 return $serialize ? preg_replace('/\s+/m', ' ', $d) : $d;93 return $serialize ? preg_replace('/\s+/m', ' ', $d) : $d; 68 94 } 69 95 … … 180 206 { 181 207 $words = preg_split('/[^\w]/', $search, -1, PREG_SPLIT_NO_EMPTY); 182 208 183 209 $search = array(); 184 210 $replace = array(); 185 211 186 212 foreach ($words as $w) { 187 213 if ('' != trim($w)) { … … 266 292 267 293 /** 268 * Turns "a really long string" into "a rea...string" 294 * Truncates "a really long string" into a string of specified length 295 * at the beginning: "âŠlong string" 296 * at the middle: "a reaâŠstring" 297 * or at the end: "a reallyâŠ". 298 * 299 * The regular expressions below first match and replace the string to the specified length and position, 300 * and secondly they remove any whitespace from around the delimiter (to avoid "this ⊠" from happening). 269 301 * 270 302 * @access public … … 272 304 * @param int $len Maximum string length. 273 305 * @param string $where Where to cut the string. One of: 'start', 'middle', or 'end'. 274 * @return string Truncated output string 306 * @return string Truncated output string. 275 307 * @author Quinn Comendant <quinn@strangecode.com> 276 308 * @since 29 Mar 2006 13:48:49 277 309 */ 278 function truncate($str, $len, $where='end', $delim='âŠ') 279 { 280 if ($len <= 3 || mb_strlen($str) <= 3) { 281 return ''; 282 } 283 $part1 = floor(($len - 3) / 2); 284 $part2 = ceil(($len - 3) / 2); 310 function truncate($str, $len=50, $where='end', $delim='âŠ') 311 { 312 $dlen = mb_strlen($delim); 313 if ($len <= $dlen || mb_strlen($str) <= $dlen) { 314 return substr($str, 0, $len); 315 } 316 $part1 = floor(($len - $dlen) / 2); 317 $part2 = ceil(($len - $dlen) / 2); 285 318 switch ($where) { 286 319 case 'start' : 287 return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str); 288 break; 320 return preg_replace(array(sprintf('/^.{%s,}(.{%s})$/sU', $dlen + 1, $part1 + $part2), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array($delim . '$1', $delim), $str); 321 322 case 'middle' : 323 return preg_replace(array(sprintf('/^(.{%s}).{%s,}(.{%s})$/sU', $part1, $dlen + 1, $part2), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array('$1' . $delim . '$2', $delim), $str); 324 325 case 'end' : 289 326 default : 290 case 'middle' : 291 return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str); 292 break; 293 case 'end' : 294 return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str); 295 break; 327 return preg_replace(array(sprintf('/^(.{%s}).{%s,}$/sU', $part1 + $part2, $dlen + 1), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array('$1' . $delim, $delim), $str); 296 328 } 297 329 } … … 307 339 * @since 06 Dec 2008 17:04:01 308 340 */ 309 if (!function_exists('mb_ucfirst')) { 341 if (!function_exists('mb_ucfirst')) { 310 342 function mb_ucfirst($string) 311 343 { … … 326 358 * @since 20 Jan 2013 12:33:26 327 359 */ 328 if (!function_exists('mb_strtr')) { 360 if (!function_exists('mb_strtr')) { 329 361 function mb_strtr($string, $from, $to) 330 362 { … … 367 399 /* 368 400 * Returns a human readable amount of time for the given amount of seconds. 369 * 401 * 370 402 * 45 seconds 371 403 * 12 minutes … … 374 406 * 1 week 375 407 * 4 months 376 * 408 * 377 409 * Months are calculated using the real number of days in a year: 365.2422 / 12. 378 410 * … … 400 432 'century' => array(3155692608, _("century"), _("centuries")), 401 433 ); 402 434 403 435 // Max unit to calculate. 404 436 $max_unit = isset($units[$max_unit]) ? $max_unit : 'year'; … … 416 448 } 417 449 $final_time = sprintf($format, $final_time); 418 return sprintf('%s %s', $final_time, (1 == $final_time ? $units[$final_unit][1] : $units[$final_unit][2])); 450 return sprintf('%s %s', $final_time, (1 == $final_time ? $units[$final_unit][1] : $units[$final_unit][2])); 419 451 } 420 452 … … 430 462 { 431 463 $app =& App::getInstance(); 432 464 433 465 foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { 434 466 $fullpath = $path . DIRECTORY_SEPARATOR . $file; … … 680 712 * escaped. This is useful for putting values coming in from posted 681 713 * checkboxes into a SET column of a database. 682 * 714 * 683 715 * 684 716 * @param array $in Array to convert. … … 688 720 { 689 721 $db =& DB::getInstance(); 690 722 691 723 if (is_array($in) && !empty($in)) { 692 724 return join($separator, array_map(array($db, 'escapeString'), $in)); … … 839 871 { 840 872 $app =& App::getInstance(); 841 873 842 874 if ('' == trim($val)) { 843 875 $app->logMsg(sprintf('Cannot add signature to an empty string.', null), LOG_INFO, __FILE__, __LINE__); … … 848 880 $salt = $app->getParam('signing_key'); 849 881 } 850 882 851 883 // TODO: consider using more bits-per-character, such as done with: 852 884 // http://www.php.net/manual/en/function.sha1.php#86239 … … 916 948 { 917 949 $app =& App::getInstance(); 918 950 919 951 $add_members = '/usr/lib/mailman/bin/add_members'; 920 952 /// FIXME: checking of executable is disabled. … … 948 980 { 949 981 $app =& App::getInstance(); 950 982 951 983 $remove_members = '/usr/lib/mailman/bin/remove_members'; 952 984 /// FIXME: checking of executable is disabled. -
branches/eli_branch/lib/Validator.inc.php
r450 r467 218 218 /** 219 219 * Verifies that date can be processed by the strtotime function. 220 * Empty strings are considered valid. Other values are tested on their return value from strtotime(). Null values will fail. 220 221 * 221 222 * @param string $val The input data to validate. … … 226 227 $app =& App::getInstance(); 227 228 228 if ( ''== trim($val)) {229 if (is_string($val) && '' === trim($val)) { 229 230 // Don't be too bothered about empty strings. 230 231 return true; … … 232 233 233 234 $timestamp = strtotime($val); 234 // Return values change between php4 and php5. 235 if ('' != trim($val) && ($timestamp === -1 || $timestamp === false)) { 235 if (!$timestamp || $timestamp < 1) { 236 236 return false; 237 237 } else { … … 239 239 } 240 240 } 241 242 241 243 242 /**
Note: See TracChangeset
for help on using the changeset viewer.