RouteMatrix::CTX_FIRST_PAGE, 'other'=>RouteMatrix::CTX_OTHER_PAGES ); $arguments[] = $type2context[$type]; return call_user_func_array(array($this, 'routeMacro'.$status), $arguments); } } function routeMacro1($value, RouteMatrix $matrix, $context) { foreach ($matrix->getMacroIterator() as $key=>$macros) { $macro = "%{$macros}%"; $state = $matrix->getMacroState($key, $context); if ($state == RouteMatrix::STATE_REQUIRED) { if (strpos($value, $macro) === false) { return false; } else { $value = str_replace($macro, '!', $value); } } } return true; } function routeMacro2($value, RouteMatrix $matrix, $context) { foreach ($matrix->getMacroIterator() as $key=>$macros) { $macro = "%{$macros}%"; $state = $matrix->getMacroState($key, $context); if ($state == RouteMatrix::STATE_INAPPLICABLE) { if (strpos($value, $macro) !== false) { return false; } else { $value = str_replace($macro, '!', $value); } } } return true; } static function local_dir_rw($directory) { $full_path = DOCROOT . $directory; if (file_exists($full_path)) { $perms = fileperms($full_path); return ($perms & 0777) == 0777; } } static function setting_name ($name) { return (bool)preg_match('/^[A-Z][A-Z_\d]*$/', $name); } static function table_prefix ($name) { return (bool)preg_match('/^[A-Z][A-Z_\d]*$/i', $name); } static function common_name ($name) { return (bool)preg_match('/^[A-Z][A-Z_\-\d]*$/i', $name); } static function url_name ($name) { return (bool) preg_match('/^[A-Z][A-Z\-\d\.]*$/i', $name); } static function url_package_name ($name) { return (bool) preg_match('/^[A-Z\d][A-Z\-\d\.]*$/i', $name); } static function existing_constant ($name) { return !defined($name); } static function filterUppercase ($a) { return strtoupper($a); } static function datetime ($datetime) { if (is_array($datetime)) { if (isset($datetime['Y'])) { if (isset($datetime['m'])) { if (isset($datetime['d'])) { list($day, $month, $year) = array((int)$datetime['d'], (int)$datetime['m'], (int)$datetime['Y']); if ($day + $month + $year) { return checkdate($month, $day, $year); } else { return true; } } } } } } static function dateonly ($date) { if (is_array($datetime)) { if (isset($datetime['Y'])) { if (isset($datetime['m'])) { if (isset($datetime['d'])) { list($day, $month, $year) = array((int)$datetime['d'], (int)$datetime['m'], (int)$datetime['Y']); if ($day + $month + $year) { return checkdate($month, $day, $year); } else { return true; } } } } } } static function sanitize_url ($string) { return filter_var ($string, FILTER_SANITIZE_URL); } static function unique_table_field_value ($table_name, $unique_field_name, $record_id, $incoming_value, $id_field_name = 'id') { $result = Database::instance () ->select (new String ('COUNT(*) AS cnt')) ->from ($table_name) ->where ($unique_field_name, $incoming_value) ->where ("$id_field_name!=", $record_id) ->get () ; foreach ($result as $row) { if ($row->cnt > 0) { return false; } } return true; } static function unique_orm_field_value ($orm, $unique_field_name, $incoming_value) { $table_name = $orm->getRawTableName (); $record_id = $orm->getId (); $id_field_name = $orm->primary_key; return self::unique_table_field_value ($table_name, $unique_field_name, $record_id, $incoming_value, $id_field_name); } static function comma_separeted_values ($string) { return join (',', preg_grep('/./', preg_split('/\D/', (string) $string))); } public static function url($url) { $w = "a-zA-Z0-9"; $pattern = "#((?:f|ht)tps?://(?:www.)?(?:[$w\\-.]+/?\\.[a-z]{2,4})/?(?:[$w\\-./\\#]+)?(?:\\?[$w\\-&=;\\#]+)?)#xi"; return preg_match($pattern, $url); } }