/** * Returns the template file * @return string */ protected function TemplateFile() { $class = new \ReflectionClass($this); $classFile = String::Replace('\\', '/', $class->getFileName()); $templatePath = String::Replace('/Snippets/', '/Templates/Snippets/', $classFile); return Path::AddExtension($templatePath, 'phtml', true); }
/** * The bundle name * @return string */ static function MyBundle() { $className = \get_class(new static()); $endPos = strpos($className, '\\Modules\\'); $bundleNS = String::Start($className, $endPos); $startPos = strrpos($bundleNS, '\\'); return String::Part($bundleNS, $startPos + 1); }
function Parse($file) { $contents = File::GetContents($file); foreach ($this->replacements as $placeholder => $text) { $contents = String::Replace($this->phStart . $placeholder . $this->phEnd, $text, $contents); } return $contents; }
/** * Set the current content to retrieve customized wording texts * @param Content $content The content */ public function SetContent(Content $content) { $this->texts = array(); $wordings = ContentWording::Schema()->FetchByContent(false, $content); foreach ($wordings as $wording) { $prefix = String::Replace('-', '.', $content->GetType()); $this->texts[$prefix . '.' . $wording->GetPlaceholder()] = $wording->GetText(); } }
public function Check($value) { $isArray = is_array($value); $this->error = ''; if ($this->trimValue && !$isArray) { $value = String::Trim($value); } if ($value === '' || $isArray && count($value) == 0) { $this->error = self::Missing; } return $this->error == ''; }
function Check($value) { $isEqual = String::Compare($value, $this->compareValue, $this->ignoreCase); if ($this->equalsNot && $isEqual) { $this->error = self::Equals; } else { if (!$this->equalsNot && !$isEqual) { $this->error = self::EqualsNot; } } return $this->error == ''; }
/** * Checks each line of the given value with the given validators * @param string $value * @return bool */ function Check($value) { $success = true; $strings = System\String::SplitLines($value); foreach ($strings as $string) { $success = parent::Check($string); if (!$success) { break; } } //The value is temporarily set to the substrings //when calling the parent check function above, //so we have to store it here, not before the loop: $this->SetValue($value); return $success; }
/** * Checks the given value * @param string $value * @return bool True if check was passed */ function Check($value) { if (!ctype_digit(String::TrimLeft($value, '-'))) { $this->error = self::HasNonDigits; } else { $floatValue = (double) $value; if ($floatValue < $this->min) { $this->error = self::ExceedsMin; } else { if ($floatValue > $this->max) { $this->error = self::ExceedsMax; } } } return $this->error == ''; }
protected function OnSuccess() { $this->member = new Member(); $this->member->SetEMail($this->Value('EMail')); $this->member->SetName($this->Value('Name')); $password = $this->Value('Password'); $salt = String::Start(md5(uniqid(microtime())), 8); $pwHash = hash('sha256', $password . $salt); $this->member->SetPassword($pwHash); $this->member->SetPasswordSalt($salt); $this->member->SetCreated(Date::Now()); $this->member->Save(); $this->SendConfirmMail(); if ($this->register->GetNextUrl()) { Response::Redirect(FrontendRouter::Url($this->register->GetNextUrl())); } }
function Check($value) { $value = (string) $value; if ($this->trimValue) { $value = trim($value); } $length = System\String::Length($value); if ($this->IsTooShort($length)) { $this->error = self::TooShort; } else { if ($this->IsTooLong($length)) { $this->error = self::TooLong; } else { $this->error = ''; } } return $this->error == ''; }
/** * Fetches the lines of a text and serializes them to an array of key value pairs * @param string $text The text representation of the array * @return array Returns the array representation as associative array */ function LinesToArray($text) { $result = array(); $lines = String::SplitLines($text); foreach ($lines as $line) { $line = trim($line); if (!$line) { continue; } $pos = strpos($line, $this->separator); $key = $line; $value = ''; if ($pos !== false) { $key = substr($line, 0, $pos); $value = substr($line, $pos + strlen($this->separator)); } $result[trim($key)] = trim($value); } return $result; }
protected function PostedGroupIDs() { $result = array(); $post = Request::PostArray(); foreach ($post as $name => $value) { if (!String::StartsWith('Usergroup_', $name)) { continue; } $result[] = $value; } return $result; }
/** * Returns a quoted string usable as javascipt variable * @param string $string * @param boolean $htmlEncode True if shall be hmtl encoded before */ function JsVarOut($string, $htmlEncode = false) { echo String::ToJavascript($string, $htmlEncode); }
private function WordingFieldName($name) { return String::Replace('.', '-', $name); }
public function RelativeNamespace($tableName) { foreach ($this->prefixNamespaces as $prefix => $namespace) { if (System\String::StartsWith($prefix, $tableName, !$this->prefixesCaseSensitive)) { return $namespace; } } return ''; }
/** * Adds given extension, leading dot is optional. * @param string $path * @param string $extension * @param bool $replaceExisting If true and extension exists, it is replaced. * @return string */ static function AddExtension($path, $extension, $replaceExisting = false) { $result = $path; if ($replaceExisting) { $result = self::RemoveExtension($path); } return join('.', array($result, System\String::TrimLeft($extension, '.'))); }
/** * The url protocol string without versioning * @return string returns either http or https */ static function Protocol() { $sp = Server::Variable('SERVER_PROTOCOL'); $protocol = substr($sp, 0, strpos($sp, '/')); if (self::IsHttps() && !String::EndsWith('s', $protocol)) { $protocol .= 's'; } return String::ToLower($protocol); }
function HtmlAttributesAsString() { $result = ''; foreach ($this->attributes as $key => $val) { if ($result) { $result .= ' '; } $result .= System\String::ToHtml($key) . '="' . System\String::ToHtml($val) . '"'; } return $result; }
/** * Gets the translations folder for a module * @param ModuleBase $module * @return string Returns the folder of the module translationss */ static function ModuleTranslationsFolder(ModuleBase $module) { $class = new \ReflectionClass($module); $classFile = String::Replace('\\', '/', $class->getFileName()); return String::Replace('/Modules/', '/Translations/', Path::RemoveExtension($classFile)); }
/** * The form value as submitted * @param string $name The field name * @param boolean $trim If false, no string trimming is performed * @return string Returns the submitted field value */ protected function Value($name, $trim = true) { $value = Request::MethodData($this->Method(), $name); if ($trim) { return String::Trim($value); } return $value; }
private function CleanAllForeignKeys() { $tables = $this->connection->GetTables(); foreach ($tables as $table) { if (String::StartsWith('pc_' . String::ToLower($this->manifest->BundleName() . '_'), $table)) { $this->CleanForeignKeys($table); } } }
/** * * @return string * @throws \LogicException Raises an error if no different redirect page is found */ private function NextUrl() { $nextUrl = String::Trim(Request::GetData('nextUrl')); if ($nextUrl) { return $nextUrl; } $nextPageUrl = $this->login->GetNextUrl(); if ($nextPageUrl) { return FrontendRouter::Url($nextPageUrl); } return ''; }
/** * Gets the value by pure name * @param string $name The name without prefix * @return string Returns the value */ private function Value($name) { $value = Request::PostData($this->prefix . $name); return String::Trim($value); }
private function SavePassword() { $password = $this->Value('Password'); if ($password) { $salt = String::Start(md5(uniqid(microtime())), 8); $pwHash = hash('sha256', $password . $salt); $this->user->SetPassword($pwHash); $this->user->SetPasswordSalt($salt); } }
/** * Realizes a wording placeholder with formatting arguments as array * @param string $placeholder The placeholder for the wording * @param array $args Optional array of format arguments * @return string The realized placeholder string */ function RealizeArgs($placeholder, array $args = array()) { $result = $this->GetReplacement($placeholder); return System\String::FormatArgs($result, $args); }
private function SaveAreas() { $names = explode(',', $this->Value('Areas')); $prev = null; foreach ($names as $name) { $name = String::Trim($name); if (!$this->AreaNameExists($name)) { $area = new Area(); $area->SetPrevious($prev); $area->SetLayout($this->layout); $area->SetName($name); $area->Save(); $prev = $area; } } }
private function ParseProperty($tokenString, &$nextStop) { $trimString = trim(substr($tokenString, $nextStop)); if (!String::StartsWith(self::PropertySeparator, $trimString)) { return false; } $propStart = strpos($tokenString, self::PropertySeparator, $nextStop) + strlen(self::PropertySeparator); $nextStart = strpos($tokenString, self::ParamsStart, $propStart); if ($nextStart === false) { $nextStart = strpos($tokenString, self::FilterSeparator, $propStart); } $propEnd = $nextStart ?: false; $strProp = $propEnd !== false ? substr($tokenString, $propStart, $propEnd - $propStart) : substr($tokenString, $propStart); $prop = trim($strProp); $nextStop = $nextStart ?: false; $result = ctype_alnum($prop) ? $prop : ''; return $result; }
private function GetNiceName($name) { $reader = new System\StringReader($name); $result = ''; $prevIsLower = false; $idx = 0; while (false !== ($ch = $reader->ReadChar())) { if ($idx == 0) { $result .= System\String::ToLower($ch); } else { if (ctype_upper($ch)) { if ($prevIsLower) { $result .= ' ' . System\String::ToLower($ch); } else { $result .= System\String::ToLower($ch); } } else { $result .= $ch; } } $prevIsLower = ctype_lower($ch); ++$idx; } return $result; }
/** * Sets element html content as a typical action of a modal form call * @param string $element The element specifier; typically starting with '#' * @param string $html The html string */ protected function SetJSHtml($element, $html) { $jsElement = String::ToJavascript($element, false); $jsHtml = String::ToJavascript($html, false); echo "<script>\$({$jsElement}).html({$jsHtml});</script>"; }