LastCharacter() final public static method

Returns the last character of a given string, or null if the given string is null.
final public static LastCharacter ( string $strString ) : string
$strString string
return string the last character, or null
Beispiel #1
0
 public static function StripQuotes($strText)
 {
     if (QString::FirstCharacter($strText) == '"' && QString::LastCharacter($strText) == '"' || QString::FirstCharacter($strText) == "'" && QString::LastCharacter($strText) == "'") {
         return substr($strText, 1, strlen($strText) - 2);
     }
     return $strText;
 }
 /**
  * Given a string, this will create a sanitized token for it
  * @param string $strTokenCandidate
  * @return string
  */
 public static function SanitizeForToken($strTokenCandidate)
 {
     $strTokenCandidate = trim(strtolower($strTokenCandidate));
     $intLength = strlen($strTokenCandidate);
     $strToReturn = '';
     for ($intChar = 0; $intChar < $intLength; $intChar++) {
         $strChar = $strTokenCandidate[$intChar];
         $intOrd = ord($strChar);
         if ($intOrd >= ord('a') && $intOrd <= ord('z')) {
             $strToReturn .= $strChar;
         } else {
             if ($intOrd >= ord('0') && $intOrd <= ord('9')) {
                 $strToReturn .= $strChar;
             } else {
                 if ($strChar == ' ' || $strChar == '.' || $strChar == ':' || $strChar == '-' || $strChar == '/' || $strChar == '(' || $strChar == ')' || $strChar == '_') {
                     $strToReturn .= '_';
                 }
             }
         }
     }
     // Cleanup leading and trailing underscores
     while (QString::FirstCharacter($strToReturn) == '_') {
         $strToReturn = substr($strToReturn, 1);
     }
     while (QString::LastCharacter($strToReturn) == '_') {
         $strToReturn = substr($strToReturn, 0, strlen($strToReturn) - 1);
     }
     // Cleanup Dupe Underscores
     while (strpos($strToReturn, '__') !== false) {
         $strToReturn = str_replace('__', '_', $strToReturn);
     }
     return $strToReturn;
 }
Beispiel #3
0
 protected function btnFirstSubmit_Click($strFormId, $strControlId, $strParameter)
 {
     if ($objPublicLogin = PublicLogin::LoadByUsername(trim(strtolower($this->txtUsername->Text)))) {
     } else {
         $this->txtUsername->Warning = 'Username does not exist';
         $this->txtUsername->Blink();
         $this->txtUsername->Focus();
         return;
     }
     $this->txtUsername->Visible = false;
     $this->btnFirstSubmit->Visible = false;
     $this->lblFirstMessage->Visible = true;
     $this->lblFirstMessage->HtmlEntities = false;
     $this->lblFirstMessage->Text = '<p>Before we can proceed, please answer the following security question that you specified when you registered for <strong>my.alcf</strong>.</p>';
     $this->lblQuestion->Visible = true;
     $this->lblQuestion->Name = 'Security Question';
     $this->lblQuestion->Text = $objPublicLogin->LostPasswordQuestion;
     if (QString::LastCharacter($objPublicLogin->LostPasswordQuestion) != '?') {
         $this->lblQuestion->Text .= '?';
     }
     $this->txtAnswer->Visible = true;
     $this->txtAnswer->Name = 'Your Answer';
     $this->txtAnswer->Required = true;
     $this->txtAnswer->CausesValidation = $this->txtAnswer;
     $this->txtAnswer->Focus();
     $this->btnFinalSubmit->Visible = true;
     $this->btnFinalSubmit->Text = 'Reset My Password';
     $this->btnFinalSubmit->CausesValidation = $this->txtAnswer;
     $this->txtAnswer->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnFinalSubmit_Click'));
     $this->txtAnswer->AddAction(new QEnterKeyEvent(), new QTerminateAction());
     $this->btnFinalSubmit->AddAction(new QClickEvent(), new QAjaxAction('btnFinalSubmit_Click'));
     $this->objPublicLogin = $objPublicLogin;
 }
 public function SetProperty($strName, $intState)
 {
     if (QString::FirstCharacter($strName) == '"' && QString::LastCharacter($strName) == '"') {
         $strName = substr($strName, 1, strlen($strName) - 2);
     } else {
         if (QString::FirstCharacter($strName) == "'" && QString::LastCharacter($strName) == "'") {
             $strName = substr($strName, 1, strlen($strName) - 2);
         }
     }
     if (array_key_exists($strName, $this->PropertyArray)) {
         $objProperty = $this->PropertyArray[$strName];
     } else {
         $objProperty = new QScriptParserProperty();
         $objProperty->Name = $strName;
         $this->PropertyArray[$strName] = $objProperty;
     }
     if ($intState == STATE_GET) {
         $objProperty->Read = true;
     } else {
         if ($intState == STATE_SET) {
             $objProperty->Write = true;
         }
     }
 }
Beispiel #5
0
 public function __construct($strJavaScript)
 {
     $this->strJavaScript = trim($strJavaScript);
     if (QString::LastCharacter($this->strJavaScript) == ';') {
         $this->strJavaScript = substr($this->strJavaScript, 0, strlen($this->strJavaScript) - 1);
     }
 }
Beispiel #6
0
 public static function RenderJavaScript($blnOutput = true)
 {
     $strScript = '';
     foreach (QApplication::$AlertMessageArray as $strAlert) {
         $strAlert = addslashes($strAlert);
         $strScript .= sprintf('alert("%s"); ', $strAlert);
     }
     foreach (QApplication::$JavaScriptArrayHighPriority as $strJavaScript) {
         $strJavaScript = trim($strJavaScript);
         if (QString::LastCharacter($strJavaScript) != ';') {
             $strScript .= sprintf('%s; ', $strJavaScript);
         } else {
             $strScript .= sprintf('%s ', $strJavaScript);
         }
     }
     foreach (QApplication::$JavaScriptArray as $strJavaScript) {
         $strJavaScript = trim($strJavaScript);
         if (QString::LastCharacter($strJavaScript) != ';') {
             $strScript .= sprintf('%s; ', $strJavaScript);
         } else {
             $strScript .= sprintf('%s ', $strJavaScript);
         }
     }
     QApplication::$AlertMessageArray = array();
     QApplication::$JavaScriptArrayHighPriority = array();
     QApplication::$JavaScriptArray = array();
     if ($strScript) {
         if ($blnOutput) {
             _p($strScript, false);
         } else {
             return $strScript;
         }
     } else {
         return null;
     }
 }
 protected function EvaluateTemplate($strTemplate, $strModuleName, $mixArgumentArray)
 {
     // First remove all \r from the template (for Win/*nix compatibility)
     $strTemplate = str_replace("\r", '', $strTemplate);
     // Get all the arguments and set them locally
     if ($mixArgumentArray) {
         foreach ($mixArgumentArray as $strName => $mixValue) {
             ${$strName} = $mixValue;
         }
     }
     // Of course, we also need to locally allow "objCodeGen"
     $objCodeGen = $this;
     // Look for the Escape Begin
     $intPosition = strpos($strTemplate, QCodeGen::$TemplateEscapeBegin);
     // Get Database Escape Identifiers
     $strEscapeIdentifierBegin = QApplication::$Database[$this->intDatabaseIndex]->EscapeIdentifierBegin;
     $strEscapeIdentifierEnd = QApplication::$Database[$this->intDatabaseIndex]->EscapeIdentifierEnd;
     // Evaluate All Escaped Clauses
     while ($intPosition !== false) {
         $intPositionEnd = strpos($strTemplate, QCodeGen::$TemplateEscapeEnd, $intPosition);
         // Get and cleanup the Eval Statement
         $strStatement = substr($strTemplate, $intPosition + QCodeGen::$TemplateEscapeBeginLength, $intPositionEnd - $intPosition - QCodeGen::$TemplateEscapeEndLength);
         $strStatement = trim($strStatement);
         if (substr($strStatement, 0, 1) == '=') {
             // Remove Trailing ';' if applicable
             if (substr($strStatement, strlen($strStatement) - 1) == ';') {
                 $strStatement = trim(substr($strStatement, 0, strlen($strStatement) - 1));
             }
             // Remove Head '='
             $strStatement = trim(substr($strStatement, 1));
             // Add 'return' eval
             $strStatement = sprintf('return (%s);', $strStatement);
         } else {
             if (substr($strStatement, 0, 1) == '@') {
                 // Remove Trailing ';' if applicable
                 if (substr($strStatement, strlen($strStatement) - 1) == ';') {
                     $strStatement = trim(substr($strStatement, 0, strlen($strStatement) - 1));
                 }
                 // Remove Head '@'
                 $strStatement = trim(substr($strStatement, 1));
                 // Calculate Template Filename
                 $intVariablePosition = strpos($strStatement, '(');
                 if ($intVariablePosition === false) {
                     throw new Exception('Invalid include subtemplate Command: ' . $strStatement);
                 }
                 $strTemplateFile = substr($strStatement, 0, $intVariablePosition);
                 $strVariableList = substr($strStatement, $intVariablePosition + 1);
                 // Remove trailing ')'
                 $strVariableList = trim(substr($strVariableList, 0, strlen($strVariableList) - 1));
                 $strVariableArray = explode(',', $strVariableList);
                 // Clean Each Variable
                 for ($intIndex = 0; $intIndex < count($strVariableArray); $intIndex++) {
                     // Trim
                     $strVariableArray[$intIndex] = trim($strVariableArray[$intIndex]);
                     // Remove trailing and head "'"
                     $strVariableArray[$intIndex] = substr($strVariableArray[$intIndex], 1, strlen($strVariableArray[$intIndex]) - 2);
                     // Trim Again
                     $strVariableArray[$intIndex] = trim($strVariableArray[$intIndex]);
                 }
                 // Ensure each variable exists!
                 foreach ($strVariableArray as $strVariable) {
                     if (!isset(${$strVariable})) {
                         throw new Exception(sprintf('Invalid Variable %s in include subtemplate command: %s', $strVariable, $strStatement));
                     }
                 }
                 // Setup the ArgumentArray for this subtemplate
                 $mixTemplateArgumentArray = array();
                 foreach ($strVariableArray as $strVariable) {
                     $mixTemplateArgumentArray[$strVariable] = ${$strVariable};
                 }
                 // Get the Evaluated Template!
                 $strEvaledStatement = $this->EvaluateSubTemplate($strTemplateFile . '.tpl', $strModuleName, $mixTemplateArgumentArray);
                 // Set Statement to NULL so that the method knows to that the statement we're replacing
                 // has already been eval'ed
                 $strStatement = null;
             }
         }
         if (substr($strStatement, 0, 1) == '-') {
             // Backup a number of characters
             $intPosition = $intPosition - strlen($strStatement);
             $strStatement = '';
             // Check if we're starting an open-ended statemen
         } else {
             if (substr($strStatement, strlen($strStatement) - 1) == '{') {
                 // We ARE in an open-ended statement
                 // SubTemplate is the contents of this open-ended template
                 $strSubTemplate = substr($strTemplate, $intPositionEnd + QCodeGen::$TemplateEscapeEndLength);
                 // Parse through the rest of the template, and pull the correct SubTemplate,
                 // Keeping in account nested open-ended statements
                 $intLevel = 1;
                 $intSubPosition = strpos($strSubTemplate, QCodeGen::$TemplateEscapeBegin);
                 while ($intLevel > 0 && $intSubPosition !== false) {
                     $intSubPositionEnd = strpos($strSubTemplate, QCodeGen::$TemplateEscapeEnd, $intSubPosition);
                     $strFragment = substr($strSubTemplate, $intSubPosition + QCodeGen::$TemplateEscapeEndLength, $intSubPositionEnd - $intSubPosition - QCodeGen::$TemplateEscapeEndLength);
                     $strFragment = trim($strFragment);
                     $strFragmentLastCharacter = substr($strFragment, strlen($strFragment) - 1);
                     if ($strFragmentLastCharacter == '{') {
                         $intLevel++;
                     } else {
                         if ($strFragmentLastCharacter == '}') {
                             $intLevel--;
                         }
                     }
                     if ($intLevel) {
                         $intSubPosition = strpos($strSubTemplate, QCodeGen::$TemplateEscapeBegin, $intSubPositionEnd);
                     }
                 }
                 if ($intLevel != 0) {
                     throw new Exception("Improperly Terminated OpenEnded Command following; {$strStatement}");
                 }
                 $strSubTemplate = substr($strSubTemplate, 0, $intSubPosition);
                 // Remove First Carriage Return (if applicable)
                 $intCrPosition = strpos($strSubTemplate, "\n");
                 if ($intCrPosition !== false) {
                     $strFragment = substr($strSubTemplate, 0, $intCrPosition + 1);
                     if (trim($strFragment) == '') {
                         // Nothing exists before the first CR
                         // Go ahead and chop it off
                         $strSubTemplate = substr($strSubTemplate, $intCrPosition + 1);
                     }
                 }
                 // Remove blank space after the last carriage return (if applicable)
                 $intCrPosition = strrpos($strSubTemplate, "\n");
                 if ($intCrPosition !== false) {
                     $strFragment = substr($strSubTemplate, $intCrPosition + 1);
                     if (trim($strFragment) == '') {
                         // Nothing exists after the last CR
                         // Go ahead and chop it off
                         $strSubTemplate = substr($strSubTemplate, 0, $intCrPosition + 1);
                     }
                 }
                 // Figure out the Command and calculate SubTemplate
                 $strCommand = substr($strStatement, 0, strpos($strStatement, ' '));
                 switch ($strCommand) {
                     case 'foreach':
                         $strFullStatement = $strStatement;
                         // Remove leading 'foreach' and trailing '{'
                         $strStatement = substr($strStatement, strlen('foreach'));
                         $strStatement = substr($strStatement, 0, strlen($strStatement) - 1);
                         $strStatement = trim($strStatement);
                         // Ensure that we've got a "(" and a ")"
                         if (QString::FirstCharacter($strStatement) != '(' || QString::LastCharacter($strStatement) != ')') {
                             throw new Exception("Improperly Formatted foreach: {$strFullStatement}");
                         }
                         $strStatement = trim(substr($strStatement, 1, strlen($strStatement) - 2));
                         // Pull out the two sides of the "as" clause
                         $strStatement = explode(' as ', $strStatement);
                         if (count($strStatement) != 2) {
                             throw new Exception("Improperly Formatted foreach: {$strFullStatement}");
                         }
                         $objArray = eval(sprintf('return %s;', trim($strStatement[0])));
                         $strSingleObjectName = trim($strStatement[1]);
                         $strNameKeyPair = explode('=>', $strSingleObjectName);
                         $mixArgumentArray['_INDEX'] = 0;
                         if (count($strNameKeyPair) == 2) {
                             $strSingleObjectKey = trim($strNameKeyPair[0]);
                             $strSingleObjectValue = trim($strNameKeyPair[1]);
                             // Remove leading '$'
                             $strSingleObjectKey = substr($strSingleObjectKey, 1);
                             $strSingleObjectValue = substr($strSingleObjectValue, 1);
                             // Iterate to setup strStatement
                             $strStatement = '';
                             if ($objArray) {
                                 foreach ($objArray as ${$strSingleObjectKey} => ${$strSingleObjectValue}) {
                                     $mixArgumentArray[$strSingleObjectKey] = ${$strSingleObjectKey};
                                     $mixArgumentArray[$strSingleObjectValue] = ${$strSingleObjectValue};
                                     $strStatement .= $this->EvaluateTemplate($strSubTemplate, $strModuleName, $mixArgumentArray);
                                     $mixArgumentArray['_INDEX']++;
                                 }
                             }
                         } else {
                             // Remove leading '$'
                             $strSingleObjectName = substr($strSingleObjectName, 1);
                             // Iterate to setup strStatement
                             $strStatement = '';
                             if ($objArray) {
                                 foreach ($objArray as ${$strSingleObjectName}) {
                                     $mixArgumentArray[$strSingleObjectName] = ${$strSingleObjectName};
                                     $strStatement .= $this->EvaluateTemplate($strSubTemplate, $strModuleName, $mixArgumentArray);
                                     $mixArgumentArray['_INDEX']++;
                                 }
                             }
                         }
                         break;
                     case 'if':
                         $strFullStatement = $strStatement;
                         // Remove leading 'if' and trailing '{'
                         $strStatement = substr($strStatement, strlen('if'));
                         $strStatement = substr($strStatement, 0, strlen($strStatement) - 1);
                         $strStatement = trim($strStatement);
                         if (eval(sprintf('return (%s);', $strStatement))) {
                             $strStatement = $this->EvaluateTemplate($strSubTemplate, $strModuleName, $mixArgumentArray);
                         } else {
                             $strStatement = '';
                         }
                         break;
                     default:
                         throw new Exception("Invalid OpenEnded Command: {$strStatement}");
                 }
                 // Reclculate intPositionEnd
                 $intPositionEnd = $intPositionEnd + QCodeGen::$TemplateEscapeEndLength + $intSubPositionEnd;
                 // If nothing but whitespace between $intPositionEnd and the next CR, then remove the CR
                 $intCrPosition = strpos($strTemplate, "\n", $intPositionEnd + QCodeGen::$TemplateEscapeEndLength);
                 if ($intCrPosition !== false) {
                     $strFragment = substr($strTemplate, $intPositionEnd + QCodeGen::$TemplateEscapeEndLength, $intCrPosition - ($intPositionEnd + QCodeGen::$TemplateEscapeEndLength));
                     if (trim($strFragment == '')) {
                         // Nothing exists after the escapeend and the next CR
                         // Go ahead and chop it off
                         $intPositionEnd = $intCrPosition - QCodeGen::$TemplateEscapeEndLength + 1;
                     }
                 } else {
                     $strFragment = substr($strTemplate, $intPositionEnd + QCodeGen::$TemplateEscapeEndLength);
                     if (trim($strFragment == '')) {
                         // Nothing exists after the escapeend and the end
                         // Go ahead and chop it off
                         $intPositionEnd = strlen($strTemplate);
                     }
                 }
                 // Recalcualte intPosition
                 // If nothing but whitespace between $intPosition and the previous CR, then remove the Whitespace (keep the CR)
                 $strFragment = substr($strTemplate, 0, $intPosition);
                 $intCrPosition = strrpos($strFragment, "\n");
                 if ($intCrPosition !== false) {
                     $intLfLength = 1;
                 } else {
                     $intLfLength = 0;
                     $intCrPosition = 0;
                 }
                 // Inlcude the previous "\r" if applicable
                 if ($intCrPosition > 1 && substr($strTemplate, $intCrPosition - 1, 1) == "\r") {
                     $intCrLength = 1;
                     $intCrPosition--;
                 } else {
                     $intCrLength = 0;
                 }
                 $strFragment = substr($strTemplate, $intCrPosition, $intPosition - $intCrPosition);
                 if (trim($strFragment) == '') {
                     // Nothing exists before the escapebegin and the previous CR
                     // Go ahead and chop it off (but not the CR or CR/LF)
                     $intPosition = $intCrPosition + $intLfLength + $intCrLength;
                 }
             } else {
                 if (is_null($strStatement)) {
                     $strStatement = $strEvaledStatement;
                 } else {
                     if (QCodeGen::DebugMode) {
                         _p("Evalling: {$strStatement}<br/>", false);
                     }
                     // Perform the Eval
                     $strStatement = eval($strStatement);
                 }
             }
         }
         // Do the Replace
         $strTemplate = substr($strTemplate, 0, $intPosition) . $strStatement . substr($strTemplate, $intPositionEnd + QCodeGen::$TemplateEscapeEndLength);
         // GO to the next Escape Marker (if applicable)
         $intPosition = strpos($strTemplate, QCodeGen::$TemplateEscapeBegin);
     }
     return $strTemplate;
 }
Beispiel #8
0
 public static function Run($strClassName, $strNamespace = null)
 {
     QApplication::$EncodingType = 'UTF-8';
     $objWsdlCache = new QCache('soap', QApplication::$ScriptName, 'wsdl', QApplication::$ScriptFilename);
     $objDiscoCache = new QCache('soap', QApplication::$ScriptName, 'disco', QApplication::$ScriptFilename);
     $objClassWrapperCache = new QCache('soap', QApplication::$ScriptName, 'class.php', QApplication::$ScriptFilename);
     // Reflect through this QSoapService
     $strDisco = $objDiscoCache->GetData();
     if ($strDisco === false || !$strNamespace) {
         $objReflection = new ReflectionClass($strClassName);
     }
     // Figure Out Namespace
     if (!$strNamespace) {
         $objReflectionProperties = $objReflection->getStaticProperties();
         $strNamespace = $objReflectionProperties['DefaultNamespace'];
     }
     $strNamespace = trim($strNamespace);
     if (QString::LastCharacter($strNamespace) == '/') {
         $strNamespace = substr($strNamespace, 0, strlen($strNamespace) - 1);
     }
     // Check for Cached Disco
     if ($strDisco === false) {
         // Instantiate Service and Setup new Soap Methods
         $objService = new $strClassName($strClassName, $strNamespace);
         // Setup SOAP Methods
         try {
             $objService->SetupSoapMethods($objReflection);
         } catch (QCallerException $objExc) {
             $objExc->IncrementOffset();
             throw $objExc;
         }
         // Get Disco, Wsdl and Wrapper, and cache them!
         $objWsdlCache->SaveData($objService->GetWsdl());
         $objDiscoCache->SaveData($objService->GetDisco());
         $objClassWrapperCache->SaveData($objService->GetClassWrapper());
     }
     // Process Service Browse (e.g. if accessed via GET)
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         if (array_key_exists('QUERY_STRING', $_SERVER)) {
             switch (strtolower($_SERVER['QUERY_STRING'])) {
                 case 'disco':
                     header('Content-Type: text/xml');
                     _p('<?xml version="1.0" encoding="' . QApplication::$EncodingType . '"?>', false);
                     _p($objDiscoCache->GetData(), false);
                     return;
                 case 'wsdl':
                     header('Content-Type: text/xml');
                     _p('<?xml version="1.0" encoding="' . QApplication::$EncodingType . '"?>', false);
                     _p($objWsdlCache->GetData(), false);
                     return;
             }
         }
         printf('<link rel="alternate" type="text/xml" href="%s?disco"/><a href="%s?disco">Web Service Discovery File</a> &nbsp;|&nbsp; <a href="%s?wsdl">Web Service Description File (WSDL)</a>', QApplication::$ScriptName, QApplication::$ScriptName, QApplication::$ScriptName);
         return;
     }
     // Process Service Execution (e.g. accessed via a POST)
     $objService = new $strClassName($strClassName, $strNamespace);
     // Get the Request
     $strRequest = file_get_contents("php://input");
     // Create the Service Class Wrapper
     require $objClassWrapperCache->GetFilePath();
     // Use PHP 5.1+'s SoapServer class to handle the actual work
     $objService->objSoapServer = new SoapServer($objWsdlCache->GetFilePath());
     $objService->objSoapServer->setClass($strClassName . 'Wrapper', $strClassName, $strNamespace);
     $objService->objSoapServer->handle($strRequest);
 }
Beispiel #9
0
 /**
  * A better version of strrpos which also allows for the use of RegExp-based matching
  * @param string $strHaystack the text content to search through
  * @param string $strNeedle either a plain-text item or a regexp pattern item to search for - if regexp used, this will update as the actual string of the content found
  * @param integer $intOffset optional position offset
  * @return mixed the position number OR false if not found
  */
 public static function StringReversePosition($strHaystack, &$strNeedle, $intOffset = null)
 {
     if (strlen($strNeedle) >= 3 && QString::FirstCharacter($strNeedle) == '/' && QString::LastCharacter($strNeedle) == '/') {
         $arrMatches = array();
         preg_match_all($strNeedle, $strHaystack, $arrMatches);
         $arrMatches = $arrMatches[0];
         if (count($arrMatches)) {
             $strNeedle = $arrMatches[count($arrMatches) - 1];
         } else {
             return false;
         }
     }
     if (is_null($intOffset)) {
         return strrpos($strHaystack, $strNeedle);
     } else {
         return strrpos($strHaystack, $strNeedle, $intOffset);
     }
 }
 public static function checkTrailingSlash($strConstantName, &$result)
 {
     if (QString::LastCharacter(constant($strConstantName)) == '/') {
         $obj = new QInstallationValidationResult();
         $obj->strMessage = 'Remove the trailing slash from the ' . $strConstantName . ' constant in ' . '/includes/configuration/configuration.inc.php. ';
         $result[] = $obj;
     }
 }
Beispiel #11
0
 /**
  * Generates and returns random Content based on "Lorem Ipsum" text.  Caller must specify
  * the number of paragraphs to be generated, where the word count for each individual
  * paragraph is a random number selected between intMinimumWordsPerParagraph and intMaximumWordsPerParagraph.
  *   
  * @param integer $intParagraphCount number of paragraphs to generate, 
  * @param integer $intMinimumWordsPerParagraph the minimum number of words per paragraph
  * @param integer $intMaximumWordsPerParagraph the maximum number of words per paragraph
  * @return string
  */
 public static function GenerateContent($intParagraphCount, $intMinimumWordsPerParagraph = 20, $intMaximumWordsPerParagraph = 150)
 {
     $strContent = null;
     for ($intParagraph = 0; $intParagraph < $intParagraphCount; $intParagraph++) {
         $intWordCount = rand($intMinimumWordsPerParagraph, $intMaximumWordsPerParagraph);
         $strParagraph = null;
         // Add Sentences
         while (str_word_count($strParagraph) < $intWordCount) {
             $strParagraph .= QDataGen::$LipsumArray[rand(0, count(QDataGen::$LipsumArray) - 1)] . '  ';
         }
         $strParagraph = trim($strParagraph);
         // Remove Words
         while (str_word_count($strParagraph) > $intWordCount) {
             $strParagraph = trim(substr($strParagraph, 0, strrpos($strParagraph, ' ')));
         }
         // Remove Comma (if applicable)
         if (QString::LastCharacter($strParagraph) == ',') {
             $strParagraph = trim(substr($strParagraph, 0, strlen($strParagraph) - 1));
         }
         // Add Period (if applicable)
         if (QString::LastCharacter($strParagraph) != '.') {
             $strParagraph .= '.';
         }
         $strContent .= $strParagraph . "\r\n\r\n";
     }
     return trim($strContent);
 }
 /**
  * @param $strDirectives the directives to process
  * @param $strStyle the calculated style based on the directives
  * @param $strOptions the calculated options based on the directives
  * @return boolean returns false if the directives are malformed at all
  */
 protected static function CalculateStyleAndOptionsFromDirectives($strDirectives, &$strStyle, &$strOptions)
 {
     if ($strDirectives) {
         $strDirectives = preg_replace('/([\\}\\]])([\\{\\[])/', '$1\\\\$2', $strDirectives);
         $strDirectives = explode('\\', $strDirectives);
         for ($intDirectiveIndex = 0; $intDirectiveIndex < count($strDirectives); $intDirectiveIndex++) {
             $strDirective = $strDirectives[$intDirectiveIndex];
             if (QString::FirstCharacter($strDirective) == '{' && QString::LastCharacter($strDirective) == '}') {
                 $strStyle .= substr($strDirective, 1, strlen($strDirective) - 2);
             } else {
                 if (QString::FirstCharacter($strDirective) == '[' && QString::LastCharacter($strDirective) == ']') {
                     $strOptions = substr($strDirective, 1, strlen($strDirective) - 2);
                 } else {
                     return false;
                 }
             }
         }
     }
     // If we made it here, then the directives are either null or correctly formed
     return true;
 }
Beispiel #13
0
 /**
  * Sanitizes any string to be used as a good-looking WikiItem path.
  * Result will only contain lower-case alphanumeric characters, 
  * underscores and forward-slashes.  If a type prefix exists,
  * (e.g. "file:" or "image:") then the type prefix is stripped
  * out and the type id is returned as an output parameter.  If
  * there is no valid type prefix, a type of Wiki Page is assumed.
  * @param string $strPath the path to sanitize
  * @param integer $intWikiItemTypeId the wiki item type is returned
  * @return string
  */
 public static function SanitizeForPath($strPath, &$intWikiItemTypeId)
 {
     $strPath = strtolower($strPath);
     $intWikiItemTypeId = null;
     // Figure out and strip any wiki type prefix
     foreach (WikiItemType::$NameArray as $intId => $strWikiType) {
         $strWikiTypePrefix = sprintf('/%s:', strtolower($strWikiType));
         if (substr($strPath, 0, strlen($strWikiTypePrefix)) == $strWikiTypePrefix) {
             $strPath = '/' . substr($strPath, strlen($strWikiTypePrefix));
             $intWikiItemTypeId = $intId;
             break;
         }
     }
     if (is_null($intWikiItemTypeId)) {
         $intWikiItemTypeId = WikiItemType::Page;
     }
     $strPathParts = explode('/', $strPath);
     $strToReturn = '/';
     foreach ($strPathParts as $strPathPart) {
         $strPathPart = trim($strPathPart);
         $intLength = strlen($strPathPart);
         if ($intLength) {
             $strPath = '';
             for ($intChar = 0; $intChar < $intLength; $intChar++) {
                 $strChar = $strPathPart[$intChar];
                 $intOrd = ord($strChar);
                 if ($intOrd >= ord('a') && $intOrd <= ord('z')) {
                     $strPath .= $strChar;
                 } else {
                     if ($intOrd >= ord('0') && $intOrd <= ord('9')) {
                         $strPath .= $strChar;
                     } else {
                         if ($strChar == ' ' || $strChar == '.' || $strChar == ':' || $strChar == '-' || $strChar == '/' || $strChar == '(' || $strChar == ')' || $strChar == '_') {
                             $strPath .= '_';
                         }
                     }
                 }
             }
             // Cleanup leading and trailing underscores
             while (QString::FirstCharacter($strPath) == '_') {
                 $strPath = substr($strPath, 1);
             }
             while (QString::LastCharacter($strPath) == '_') {
                 $strPath = substr($strPath, 0, strlen($strPath) - 1);
             }
             // Cleanup Dupe Underscores
             while (strpos($strPath, '__') !== false) {
                 $strPath = str_replace('__', '_', $strPath);
             }
             // At this pathpart to the path
             $strToReturn .= $strPath . '/';
         }
     }
     // Take off trailing '/' if applicable
     if (strlen($strToReturn) > 1) {
         $strToReturn = substr($strToReturn, 0, strlen($strToReturn) - 1);
     }
     // Any blank path MUST be set to an itemtype of wikipage
     if ($strToReturn == '/') {
         $intWikiItemTypeId = WikiItemType::Page;
     }
     return $strToReturn;
 }
Beispiel #14
0
function GetTableScript($objOdbc, $strTablePath, $strTableName, $strPrefix)
{
    $objResult = odbc_exec($objOdbc, "SELECT * FROM " . $strTablePath . ";");
    $intNumFields = odbc_num_fields($objResult);
    $strSql = 'CREATE TABLE `' . strtolower($strTableName) . "` (\r\n";
    $strSql .= "    pkid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\r\n";
    for ($intFieldNumber = 1; $intFieldNumber <= $intNumFields; $intFieldNumber++) {
        $strType = odbc_field_type($objResult, $intFieldNumber);
        switch ($strType) {
            case 'LONGVARCHAR':
            case 'LONGVARBINARY':
                $strType = 'TEXT';
                break;
            case 'VARCHAR':
            case 'WORD':
                $strType = 'VARCHAR(255)';
                break;
            case 'LARGEINT':
            case 'SMALLINT':
            case 'AUTOINC':
                $strType = 'INT';
                break;
            case 'Long':
                $strType = 'INT';
                break;
            case 'AlphaNumeric':
                $strType = 'VARCHAR(255)';
                break;
            case 'Timestamp':
                $strType = 'DATETIME';
                break;
            case 'Logical':
                $strType = 'VARCHAR(255)';
                break;
            case 'Memo':
                $strType = 'TEXT';
                break;
            case 'Number':
                $strType = 'DECIMAL(9,2)';
                break;
        }
        if (odbc_field_name($objResult, $intFieldNumber) == 'Family_Number') {
            $strType = 'INT';
        }
        $strFieldName = strtolower(odbc_field_name($objResult, $intFieldNumber));
        $strFieldName = str_replace('/', '_', $strFieldName);
        $strFieldName = str_replace('-', '_', $strFieldName);
        $strFieldName = str_replace(' ', '_', $strFieldName);
        $strFieldName = str_replace('#', '_', $strFieldName);
        // Cleanup Doubles
        while (strpos($strFieldName, '__') !== false) {
            $strFieldName = str_replace('__', '_', $strFieldName);
        }
        // Perform a "trim"
        if (QString::FirstCharacter($strFieldName) == '_') {
            $strFieldName = substr($strFieldName, 1);
        }
        if (QString::LastCharacter($strFieldName) == '_') {
            $strFieldName = substr($strFieldName, 0, strlen($strFieldName) - 1);
        }
        $strSql .= sprintf("    `%s%s` %s,\r\n", $strPrefix, $strFieldName, $strType);
    }
    $strSql .= "    PRIMARY KEY (pkid)\r\n);\r\n\r\n";
    return $strSql;
}