Changeset 534
- Timestamp:
- Jul 27, 2015 7:56:08 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/acl.cli.php
r533 r534 44 44 require_once CODEBASE_PATH . '/lib/ACL.inc.php'; 45 45 $acl =& ACL::getInstance(); 46 $acl->setParam(array('create_table' => false)); 46 $acl->setParam(array( 47 'create_table' => false, 48 'enable_cache' => false, 49 )); 47 50 48 51 … … 65 68 case 'aco' : 66 69 case 'axo' : 67 listObjects( 'root',$type);70 listObjects($type); 68 71 break; 69 72 case 'all' : 70 listObjects(' root', 'aro');71 listObjects(' root', 'aco');72 listObjects(' root', 'axo');73 listObjects('aro'); 74 listObjects('aco'); 75 listObjects('axo'); 73 76 break; 74 77 case 'perms' : … … 244 247 * 245 248 * @access public 249 * @param string $type Table to call, one of: aro, aco, or axo. 246 250 * @param string $root Root node from which to begin calculating. 247 * @param string $type Table to call, one of: aro, aco, or axo.248 251 * @return bool Returns false on error. 249 252 * @author Quinn Comendant <quinn@strangecode.com> … … 251 254 * @since 17 Jun 2006 23:41:22 252 255 */ 253 function listObjects($ root, $type)256 function listObjects($type, $root=null) 254 257 { 258 global $acl; 259 255 260 $app =& App::getInstance(); 256 261 $db =& DB::getInstance(); 257 262 258 echo "\n";259 260 263 switch ($type) { 261 264 case 'aro' : 262 $tbl = 'aro_tbl'; 263 printf("%-45s %s\n", 'Request objects', 'Added'); 265 printf("\n%-45s %s\n", 'Request objects', 'Added'); 264 266 break; 265 267 case 'aco' : 266 $tbl = 'aco_tbl'; 267 printf("%-45s %s\n", 'Control objects', 'Added'); 268 printf("\n%-45s %s\n", 'Control objects', 'Added'); 268 269 break; 269 270 case 'axo' : 270 $tbl = 'axo_tbl'; 271 printf("%-45s %s\n", 'Xtra objects', 'Added'); 271 printf("\n%-45s %s\n", 'Xtra objects', 'Added'); 272 272 break; 273 273 default : 274 274 $app->logMsg(sprintf('Invalid access object type: %s', $type), LOG_ERR, __FILE__, __LINE__); 275 275 return false; 276 break;277 276 } 278 277 279 278 echo "---------------------------------------------------------------------\n"; 280 279 281 // Retrieve the left and right value of the $root node. 282 $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($root) . "'"); 283 list($lft, $rgt) = mysql_fetch_row($qid); 284 285 $depth = array(); 286 287 // Retrieve all descendants of the root node 288 $qid = $db->query("SELECT name, lft, rgt, added_datetime FROM $tbl WHERE lft BETWEEN $lft AND $rgt ORDER BY lft ASC"); 289 while (list($name, $lft, $rgt, $added_datetime) = mysql_fetch_row($qid)) { 290 // If the last element of $depth is less than the current rgt it means we finished with a set of children nodes. 291 while (sizeof($depth) > 0 && end($depth) < $rgt) { 292 array_pop($depth); 293 } 294 280 foreach ($acl->getList($type, $root) as $o) { 295 281 // Display indented node title. 296 printf("%-45s %s\n", str_repeat(' ', sizeof($depth)) . $name, date($app->getParam('date_format') . ' ' . $app->getParam('time_format'), strtotime($added_datetime))); 297 298 // Add this node to the stack. 299 $depth[] = $rgt; 300 } 282 printf("%-45s %s\n", str_repeat(' ', $o['depth']) . $o['name'], date($app->getParam('date_format') . ' ' . $app->getParam('time_format'), strtotime($o['added_datetime']))); 283 } 284 285 echo "\n"; 301 286 } 302 287 -
trunk/bin/module_maker/validation.cli.php
r533 r534 73 73 $field = $col[0]; 74 74 $title = ucfirst(str_replace('_', ' ', $field)); 75 $type = preg_replace('/^(\w+).*$/', '\\1', $col[1]); 75 $type = preg_replace('/^(\w+).*$/', '$1', $col[1]); 76 $max_dig = preg_replace('/^\w+\((\d+)(?:,\d+)?\).*$/', '$1', $col[1]); 77 $max_dec = preg_replace('/^\w+\((?:\d+)(?:,(\d+))?\).*$/', '$1', $col[1]); 76 78 $is_primary_key = ('PRI' == $col[3]); 77 79 $unsigned = preg_match('/\s+unsigned\s*$/i', $col[1]); … … 110 112 case 'varchar' : 111 113 $len_type = 'string'; 112 $max_length = 255;114 $max_length = '' != $max_dig ? $max_dig : 255; 113 115 break; 114 116 … … 131 133 break; 132 134 135 case 'bit' : 136 $len_type = 'num'; 137 $min = 0; 138 $max = '' != $max_dig ? $max_dig : 64; 139 break; 140 133 141 case 'tinyint' : 134 case 'bit' :135 142 case 'bool' : 136 143 $len_type = 'num'; … … 191 198 case 'float' : 192 199 $len_type = 'num'; 193 $min = -3.40282E+38; 194 $max = 3.40282E+38; 200 if ($unsigned) { 201 $min = 0; 202 $max = 3.40282E+38; 203 } else { 204 $min = -3.40282E+38; 205 $max = 3.40282E+38; 206 } 195 207 break; 196 208 197 209 case 'double' : 198 210 case 'double precision' : 211 $len_type = 'num'; 212 if ($unsigned) { 213 $min = 0; 214 $max = 1.7976931348623157E+308; 215 } else { 216 $min = -1.7976931348623157E+308; 217 $max = 1.7976931348623157E+308; 218 } 219 break; 220 199 221 case 'real' : 200 222 case 'decimal' : 201 223 case 'dec' : 202 224 case 'numeric' : 203 $len_type = 'num'; 204 $min = -1.79769E+308; 205 $max = 1.79769E+308; 225 case 'fixed' : 226 $len_type = 'decimal'; // This doesn't match anything, on purpose. 206 227 break; 207 228 … … 255 276 256 277 case 'float' : 257 case 'float' :258 278 case 'double' : 259 case 'double' : 279 $negative_ok = $unsigned ? '' : ', true'; 280 $o[] = "\$fv->isFloat('$field', sprintf(_(\"%s must be a valid number.\"), _(\"$title\"))$negative_ok);"; 281 break; 282 260 283 case 'real' : 261 284 case 'decimal' : 262 285 case 'dec' : 263 286 case 'numeric' : 264 $negative_ok = $unsigned ? '' : ', true'; 265 $o[] = "\$fv->isFloat('$field', sprintf(_(\"%s must be a valid number.\"), _(\"$title\"))$negative_ok);"; 287 case 'float' : 288 $max = str_repeat('9', $max_dig - $max_dec); 289 if ($max_dec > 0) { 290 $max .= '.' . str_repeat('9', $max_dec); 291 } 292 if ($unsigned) { 293 $negative_ok = 'false'; 294 $min = 0; 295 } else { 296 $negative_ok = 'true'; 297 $min = -$max; 298 } 299 $negative_ok = $unsigned ? 'false' : 'true'; 300 $o[] = "\$fv->isDecimal('$field', sprintf(_(\"%s must be a number between %d and %d.\"), _(\"$title\"), $min, $max), $negative_ok, $max_dig, $max_dec);"; 266 301 break; 267 302 -
trunk/lib/ACL.inc.php
r506 r534 65 65 // Configure the cache object. 66 66 $this->cache = new Cache('acl'); 67 $this->cache->setParam(array('enabled' => true));68 67 69 68 // Get create tables config from global context. … … 101 100 102 101 if (isset($params) && is_array($params)) { 102 // Some params require special processing. Catch those in a loop and process individually. 103 foreach ($params as $key => $val) { 104 switch ($key) { 105 case 'enable_cache': 106 $this->cache->setParam(array('enabled' => $val)); 107 break; 108 } 109 110 } 111 unset($key, $value); 112 103 113 // Merge new parameters with old overriding only those passed. 104 114 $this->_params = array_merge($this->_params, $params); … … 675 685 676 686 $cache_hash = $aro . '|' . $aco . '|' . $axo; 677 if ( $this->cache->exists($cache_hash) && true === $this->getParam('enable_cache')) {687 if (true === $this->getParam('enable_cache') && $this->cache->exists($cache_hash)) { 678 688 // Access value is cached. 679 689 $access = $this->cache->get($cache_hash); … … 694 704 if (!list($access) = mysql_fetch_row($qid)) { 695 705 $this->cache->set($cache_hash, 'deny'); 696 $app->logMsg(sprintf('Access denied: %s -> %s -> %s (no records found).', $aro, $aco, $axo), LOG_ DEBUG, __FILE__, __LINE__);706 $app->logMsg(sprintf('Access denied: %s -> %s -> %s (no records found).', $aro, $aco, $axo), LOG_WARNING, __FILE__, __LINE__); 697 707 return false; 698 708 } … … 704 714 return true; 705 715 } else { 706 $app->logMsg(sprintf('Access denied: %s -> %s -> %s', $aro, $aco, $axo), LOG_ DEBUG, __FILE__, __LINE__);716 $app->logMsg(sprintf('Access denied: %s -> %s -> %s', $aro, $aco, $axo), LOG_NOTICE, __FILE__, __LINE__); 707 717 return false; 708 718 } … … 736 746 } 737 747 748 /* 749 * Returns an array of the specified object type starting specified root. 750 * 751 * @access public 752 * @param string $type Table to list, one of: aro, aco, or axo. 753 * @param string $root Root node from which to begin from. 754 * @return mixed Returns a multidimensional array of objects, or false on error. 755 * @author Quinn Comendant <quinn@strangecode.com> 756 * @version 1.0 757 * @since 17 Jun 2006 23:41:22 758 */ 759 function getList($type, $root=null) 760 { 761 $app =& App::getInstance(); 762 $db =& DB::getInstance(); 763 764 switch ($type) { 765 case 'aro' : 766 $tbl = 'aro_tbl'; 767 break; 768 case 'aco' : 769 $tbl = 'aco_tbl'; 770 break; 771 case 'axo' : 772 $tbl = 'axo_tbl'; 773 break; 774 default : 775 $app->logMsg(sprintf('Invalid access object type: %s', $type), LOG_ERR, __FILE__, __LINE__); 776 return false; 777 } 778 779 // By default start with the 'root' node. 780 $root = !isset($root) ? 'root' : $root; 781 782 // Retrieve the left and right value of the $root node. 783 $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($root) . "'"); 784 list($lft, $rgt) = mysql_fetch_row($qid); 785 786 $results = array(); 787 $depth = array(); 788 789 // Retrieve all descendants of the root node 790 $qid = $db->query("SELECT name, lft, rgt, added_datetime FROM $tbl WHERE lft BETWEEN $lft AND $rgt ORDER BY lft ASC"); 791 while (list($name, $lft, $rgt, $added_datetime) = mysql_fetch_row($qid)) { 792 // If the last element of $depth is less than the current rgt it means we finished with a set of children nodes. 793 while (sizeof($depth) > 0 && end($depth) < $rgt) { 794 array_pop($depth); 795 } 796 797 $results[] = array( 798 'name' => $name, 799 'added_datetime' => $added_datetime, 800 'depth' => sizeof($depth), 801 ); 802 803 // Add this node to the stack. 804 $depth[] = $rgt; 805 } 806 807 return $results; 808 } 809 738 810 } // End class. -
trunk/lib/App.inc.php
r532 r534 416 416 $_SESSION['_app'][$this->_ns] = array( 417 417 'messages' => array(), 418 'boomerang' => array('url' ),418 'boomerang' => array('url' => array()), 419 419 ); 420 420 } … … 539 539 540 540 if (!$this->running) { 541 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);541 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 542 542 return false; 543 543 } 544 544 545 545 if (!$this->getParam('enable_session')) { 546 $this->logMsg(sprintf('Canceled method call %s, session not enabled.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);546 $this->logMsg(sprintf('Canceled %s, session not enabled.', â ), LOG_NOTICE, __FILE__, __LINE__); 547 547 return false; 548 548 } … … 609 609 { 610 610 if (!$this->running) { 611 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);611 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 612 612 return false; 613 613 } … … 625 625 { 626 626 if (!$this->running) { 627 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);627 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 628 628 return false; 629 629 } … … 647 647 648 648 if (!$this->running) { 649 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);649 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 650 650 return false; 651 651 } … … 968 968 { 969 969 if (!$this->running) { 970 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);970 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 971 971 return false; 972 972 } … … 1095 1095 { 1096 1096 if (!$this->running) { 1097 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1097 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1098 1098 return false; 1099 1099 } … … 1203 1203 * 1204 1204 * @access public 1205 * @param string $user_submitted_csrf_token The user-submitted token to compare with the session token. 1205 1206 * @param string $csrf_token The token to compare with the session token. 1206 1207 * @return bool True if the tokens match, false otherwise. … … 1213 1214 1214 1215 if (!$this->getParam('csrf_token_enabled')) { 1215 $this->logMsg(sprintf('%s method called, but csrf_token_enabled=false', __FUNCTION__), LOG_ERR, __FILE__, __LINE__);1216 $this->logMsg(sprintf('%s called, but csrf_token_enabled=false', __METHOD__), LOG_ERR, __FILE__, __LINE__); 1216 1217 return true; 1217 1218 } … … 1238 1239 * 1239 1240 * @access public 1240 * @param string $user_submitted_csrf_token The user-submitted token to compare with the session token.1241 1241 * @param string $message Optional message to display to the user (otherwise default message will display). Set to an empty string to display no message. 1242 1242 * @param int $type The type of message: MSG_NOTICE, … … 1274 1274 { 1275 1275 if (!$this->running) { 1276 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1276 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1277 1277 return false; 1278 1278 } … … 1327 1327 { 1328 1328 if (!$this->running) { 1329 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1329 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1330 1330 return false; 1331 1331 } … … 1369 1369 { 1370 1370 if (!$this->running) { 1371 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1371 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1372 1372 return false; 1373 1373 } … … 1377 1377 if ('' != $url && is_string($url)) { 1378 1378 // Delete any boomerang request keys in the query string (along with any trailing delimiters after the deletion). 1379 $url = preg_replace(array('/([&?])boomerang= \w+[&?]?/', '/[&?]$/'), array('$1', ''), $url);1379 $url = preg_replace(array('/([&?])boomerang=[^&?]+[&?]?/', '/[&?]$/'), array('$1', ''), $url); 1380 1380 1381 1381 if (isset($_SESSION['_app'][$this->_ns]['boomerang']['url']) && is_array($_SESSION['_app'][$this->_ns]['boomerang']['url']) && !empty($_SESSION['_app'][$this->_ns]['boomerang']['url'])) { 1382 // If the URL currently exists in the boomerang array, delete. 1383 while ($existing_key = array_search($url, $_SESSION['_app'][$this->_ns]['boomerang']['url'])) { 1384 unset($_SESSION['_app'][$this->_ns]['boomerang']['url'][$existing_key]); 1382 // If the ID=>URL pair currently exists in the boomerang array, delete. 1383 foreach (array_keys($_SESSION['_app'][$this->_ns]['boomerang']['url'], $url) as $existing_key) { 1384 if ($existing_key == $id) { 1385 $this->logMsg(sprintf('Found and deleting existing ID=>URL pair: %s=>%s', $id, $url), LOG_DEBUG, __FILE__, __LINE__); 1386 unset($_SESSION['_app'][$this->_ns]['boomerang']['url'][$existing_key]); 1387 } 1385 1388 } 1386 1389 } … … 1407 1410 { 1408 1411 if (!$this->running) { 1409 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1412 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1410 1413 return false; 1411 1414 } … … 1432 1435 { 1433 1436 if (!$this->running) { 1434 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1437 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1435 1438 return false; 1436 1439 } … … 1454 1457 { 1455 1458 if (!$this->running) { 1456 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);1459 $this->logMsg(sprintf('Canceled %s, application not running.', __METHOD__), LOG_NOTICE, __FILE__, __LINE__); 1457 1460 return false; 1458 1461 } … … 1490 1493 // Last boomerang direction was less than 2 seconds ago. 1491 1494 $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s seconds', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__); 1495 return false; 1496 } 1497 if ($boomerang_time < (time() - 72000)) { 1498 // Last boomerang direction was more than 20 minutes ago. 1499 $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too long: %s seconds', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__); 1492 1500 return false; 1493 1501 } -
trunk/lib/Cache.inc.php
r523 r534 26 26 * Provides an API for storing a limited amount of data 27 27 * intended to have a short lifetime in a user's session. 28 * 29 * Disable cache per-request by adding '_disable_cache=1' to a GET or POST parameter. 28 30 * 29 31 * @author Quinn Comendant <quinn@strangecode.com> … … 80 82 if (true !== $app->getParam('enable_session')) { 81 83 // Force disable the cache because there is no session to save to. 82 $app->logMsg('Cache disabled, enable_session is false.', LOG_DEBUG, __FILE__, __LINE__);84 $app->logMsg('Cache disabled, enable_session != true.', LOG_DEBUG, __FILE__, __LINE__); 83 85 $this->setParam(array('enabled' => false)); 84 86 } else if (!isset($_SESSION['_cache'][$this->_ns])) { … … 154 156 $app =& App::getInstance(); 155 157 156 if (true !== $this->getParam('enabled') ) {158 if (true !== $this->getParam('enabled') || getFormData('_disable_cache')) { 157 159 $app->logMsg(sprintf('Cache disabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__); 158 160 return false; … … 207 209 $app =& App::getInstance(); 208 210 209 if (true !== $this->getParam('enabled') ) {211 if (true !== $this->getParam('enabled') || getFormData('_disable_cache')) { 210 212 $app->logMsg(sprintf('Cache disabled, not getting data.', null), LOG_DEBUG, __FILE__, __LINE__); 211 213 return false; … … 236 238 $app =& App::getInstance(); 237 239 238 if (true !== $this->getParam('enabled') ) {240 if (true !== $this->getParam('enabled') || getFormData('_disable_cache')) { 239 241 $app->logMsg(sprintf('Cache disabled on exist assertion.', null), LOG_DEBUG, __FILE__, __LINE__); 240 242 return false; … … 254 256 $app =& App::getInstance(); 255 257 256 if (true !== $this->getParam('enabled') ) {258 if (true !== $this->getParam('enabled') || getFormData('_disable_cache')) { 257 259 $app->logMsg(sprintf('Cache disabled, skipping delete of %s', $key), LOG_DEBUG, __FILE__, __LINE__); 258 260 return false; -
trunk/lib/FormValidator.inc.php
r502 r534 384 384 385 385 /** 386 * Check whether input is a Decimal or Fixed type. Check values to be stored in mysql decimal, numeric, num, or fixed types. 387 * Note: some integers and floats will also pass this test. 388 * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html 389 * 390 * @param string $form_name the name of the incoming form variable 391 * @param string $msg the message to display on error 392 * @param string $val The input data to validate. 393 * @param bool $negative_ok If the value can be unsigned. 394 * @param int $max Total max number of digits. 395 * @param int $dec Total max number of digits after the decimal place. 396 * @return bool true if value is a float 397 */ 398 public function isDecimal($form_name, $msg='', $negative_ok=false, $max=10, $dec=2) 399 { 400 if (Validator::isDecimal(getFormData($form_name), $negative_ok, $max, $dec)) { 401 return true; 402 } else { 403 $this->addError($form_name, $msg); 404 return false; 405 } 406 } 407 408 /** 386 409 * Check whether input is an array. 387 410 * -
trunk/lib/HTML.inc.php
r502 r534 154 154 } 155 155 156 /* 157 * 158 * 159 * @access public 160 * @param array $options Array of options, with keys: value, selected, text 161 * @param array $deselected Array of values to disable in options. 162 * @return array Same options, but those with a value matching an element in $deselected will have a 'disabled' element of true. 163 * @author Quinn Comendant <quinn@strangecode.com> 164 * @version 1.0 165 * @since 24 Jul 2015 01:41:33 166 */ 167 static public function disableSelectOptions($options, $deselected) 168 { 169 $app =& App::getInstance(); 170 $n = sizeof($options); 171 for ($i=0; $i < $n; $i++) { 172 $app->logMsg(sprintf('Disable check: %s == %s', $options[$i]['value'], getDump($deselected)), LOG_DEBUG, __FILE__, __LINE__); 173 $options[$i]['disabled'] = in_array($options[$i]['value'], $deselected); 174 } 175 return $options; 176 } 177 156 178 /** 157 179 * Prints option fields for a select form. Works only with enum or set … … 219 241 220 242 foreach ($options as $o) { 221 printf('<option value="%s"%s >%s</option>',243 printf('<option value="%s"%s%s>%s</option>', 222 244 oTxt($o['value']), 223 ($o['selected'] ? ' selected' : ''), 245 (isset($o['selected']) && $o['selected'] ? ' selected' : ''), 246 (isset($o['disabled']) && $o['disabled'] ? ' disabled' : ''), 224 247 oTxt($o['text']) 225 248 ); 226 249 } 227 250 } 251 252 /** 253 * Get a Gravatar URL for a specified email address. 254 * 255 * @param string $email The email address 256 * @param string $size Size in pixels, defaults to 80px [ 1 - 2048 ] 257 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] 258 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] 259 * @return String containing a URL to a gravatar image. 260 * @source http://gravatar.com/site/implement/images/php/ 261 */ 262 static public function getGravatarURL($email, $size=80, $defset='mm', $rating='g') { 263 return sprintf('https://www.gravatar.com/avatar/%s?s=%s&d=%s&r=%s', 264 md5(strtolower(trim($email))), 265 $size, 266 $defset, 267 $rating 268 ); 269 } 228 270 } -
trunk/lib/Navigation.inc.php
r523 r534 48 48 'path_delimiter' => ' / ', 49 49 'last_crumb_format' => '%s', 50 'current_page_url' => null, // This should be set at runtime using, e.g., $_SERVER['REQUEST_URI'] 50 51 ); 51 52 public $pages = array(); … … 57 58 { 58 59 $app =& App::getInstance(); 60 61 // Define current_page_url here because _SERVER, not a static scalar, cannot be defined in the defaults above. 62 // Using PHP_SELF for legacy compatability, but it might make sense to override this with REQUEST_URI. 63 // This could be overwritten by passed params. 64 $this->_params['current_page_url'] = $_SERVER['PHP_SELF']; 59 65 60 66 if (isset($params) && is_array($params)) { … … 72 78 * @access public 73 79 * @param string $title The title of the page. 74 * @param string $url The URL to the page. Set to null to use PHP_SELF.80 * @param string $url The URL to the page. Set to null to use REQUEST_URI. 75 81 * @param array $vars Additional page variables. 76 82 */ … … 81 87 'head_title' => $title, 82 88 'body_title' => $title, 83 'url' => is_null($url) ? $ _SERVER['PHP_SELF'] : $url,89 'url' => is_null($url) ? $this->_params['current_page_url'] : $url, 84 90 ); 85 $this->pages[] = array_merge($page, $vars); 91 // An "unformed page element" has settings applied (via ->set()) but no page added (via ->add()). 92 if (empty($this->pages) || isset(end($this->pages)['title'])) { 93 // There are no unformed page elements; add a whole new page. 94 $this->pages[] = array_merge($page, $vars); 95 } else { 96 // Append the new page to the unformed page element. 97 $curr_page =& $this->pages[key($this->pages)]; 98 $curr_page = array_merge($curr_page, $page, $vars); 99 } 86 100 } 87 101 … … 143 157 { 144 158 // Set params of current page. 145 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 159 if (empty($this->pages)) { 160 // If we're setting a value on an empty pages array, we need to add one "unformed" element first. 161 $this->pages[] = array(); 162 } 163 end($this->pages); 164 $curr_page =& $this->pages[key($this->pages)]; 146 165 $curr_page[$key] = $val; 147 166 } … … 157 176 public function get($key, $default='') 158 177 { 159 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 178 end($this->pages); 179 $curr_page =& $this->pages[key($this->pages)]; 160 180 161 181 switch ($key) { … … 375 395 * @access public 376 396 * 377 * @param string $test_uri A URIto test against the current page.397 * @param mixed $test_uri A URI, or an array of URIs, to test against the current page. 378 398 * @param mixed $true_return The value to return if the current page matches the test URI. 379 399 * @param mixed $false_return The value to return if the current page does not match the test URI. … … 387 407 { 388 408 $app =& App::getInstance(); 409 410 // If given an array, test each URI recursively returning TRUE on a first match, or FALSE if none match. 411 if (is_array($test_uri)) { 412 foreach ($test_uri as $uri) { 413 if ($this->currentPage($uri, $true_return, $false_return, $include_query)) { 414 return true; 415 } 416 } 417 return false; 418 } 389 419 390 420 $actual_uri = $include_query ? $_SERVER['REQUEST_URI'] : strtok($_SERVER['REQUEST_URI'], '?'); -
trunk/lib/Utilities.inc.php
r532 r534 275 275 * @return string A hexadecimal html color. 276 276 */ 277 function getTextColor($text, $method=1 )277 function getTextColor($text, $method=1, $n=0.87) 278 278 { 279 279 $hash = md5($text); … … 291 291 default : 292 292 // Reduce all hex values slightly to avoid all white. 293 array_walk($rgb, create_function('&$v', '$v = dechex(round(hexdec($v) * 0.87));'));293 array_walk($rgb, create_function('&$v', "\$v = dechex(round(hexdec(\$v) * $n));")); 294 294 break; 295 295 case 2 : -
trunk/lib/Validator.inc.php
r523 r534 120 120 * 121 121 * @param string $val The input data to validate. 122 * @param bool $negative_ok If the value can be unsigned. 122 123 * @return bool true if value is a float 123 124 */ … … 126 127 $pattern = $negative_ok ? '/^-?[[:digit:]]*(?:\.?[[:digit:]]+)$/' : '/^[[:digit:]]*(?:\.?[[:digit:]]+)$/'; 127 128 return '' == trim((string)$val) || (is_numeric($val) && preg_match($pattern, $val)); 129 } 130 131 /** 132 * Check whether input is a Decimal or Fixed type. Check values to be stored in mysql decimal, numeric, num, or fixed types. 133 * Note: some integers and floats will also pass this test. 134 * https://dev.mysql.com/doc/refman/5.5/en/fixed-point-types.html 135 * 136 * @param string $val The input data to validate. 137 * @param bool $negative_ok If the value can be unsigned. 138 * @param int $max Total max number of digits (for mysql max is 65). 139 * @param int $dec Total max number of digits after the decimal place (for mysql max is 30). 140 * @return bool true if value is a float 141 */ 142 static public function isDecimal($val, $negative_ok=false, $max=10, $dec=2) 143 { 144 if ('' == trim((string)$val)) { 145 return true; 146 } 147 if (!$negative_ok && is_numeric($val) && $val < 0) { 148 return false; 149 } 150 // Get the length of the part after any decimal point, or zero. 151 $num_parts = explode('.', $val); 152 $dec_count = sizeof($num_parts) <= 1 ? 0 : mb_strlen(end($num_parts)); 153 // Must be numeric, total digits <= $max, dec digits <= $dec. 154 return is_numeric($val) && mb_strlen(str_replace(['-', '.'], '', $val)) <= $max && $dec_count <= $dec; 128 155 } 129 156 -
trunk/services/templates/lock.ihtml
r497 r534 23 23 ); ?> 24 24 </p> 25 <?php if ($lock->getSecondsElapsed() >= $lock->getParam('timeout')) { ?>26 <p class="sc-msg-notice"><?php printf(_("You can forcibly unlock the record if you believe the editing session has expired. You might want to confirm with %s before doing this."), $lock->getEditor()) ?></p>27 <div class="sc-msg-notice">28 <?php29 HTML::printButtons(array(30 array('name' => 'unlock', 'value' => _("Unlock"), 'class' => 'small button alert', 'accesskey' => 'u'),31 array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'),32 ));33 ?>34 </div>35 <?php } else { ?>36 <div class="sc-msg-notice">37 <?php38 HTML::printButtons(array(39 array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'),40 ));41 ?>42 </div>43 <?php } ?>44 25 </div> 45 26 </div> 27 <?php if ($lock->getSecondsElapsed() >= $lock->getParam('timeout')) { ?> 28 <div id="sc-msg" class="sc-msg row"> 29 <div class="large-12 columns"> 30 <p class="sc-msg-notice"><?php printf(_("You can forcibly unlock the record if you believe the editing session has expired. You might want to confirm with %s before doing this."), $lock->getEditor()) ?></p> 31 </div> 32 </div> 33 <div class="row sc-submit-buttons"> 34 <div class="large-12 columns"> 35 <?php 36 HTML::printButtons(array( 37 array('name' => 'unlock', 'value' => _("Unlock"), 'class' => 'small button alert', 'accesskey' => 'u'), 38 array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'), 39 )); 40 ?> 41 </div> 42 </div> 43 <?php } else { ?> 44 <div class="row sc-submit-buttons"> 45 <div class="large-12 columns"> 46 <?php 47 HTML::printButtons(array( 48 array('name' => 'cancel', 'value' => _("Cancel"), 'class' => 'small button secondary', 'accesskey' => 'c'), 49 )); 50 ?> 51 </div> 52 </div> 53 <?php } ?> 46 54 </form> 47 55 </main>
Note: See TracChangeset
for help on using the changeset viewer.