FirstCharacter() final public static method

Returns the first character of a given string, or null if the given string is null.
final public static FirstCharacter ( string $strString ) : string
$strString string
return string the first character, or null
 /**
  * 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 #2
0
 public function Validate()
 {
     if (parent::Validate()) {
         if (trim($this->strText) != "") {
             $this->strText = trim($this->strText);
             $strOriginal = $this->strText;
             $strFinal = '';
             while (strlen($strOriginal)) {
                 if (is_numeric(QString::FirstCharacter($strOriginal))) {
                     $strFinal .= QString::FirstCharacter($strOriginal);
                 }
                 if (strtolower(QString::FirstCharacter($strOriginal)) == 'x') {
                     $strFinal .= 'x';
                 }
                 $strOriginal = substr($strOriginal, 1);
             }
             if (strlen($strFinal) == 10 && strpos($strFinal, 'x') === false) {
                 $this->strText = substr($strFinal, 0, 3) . '-' . substr($strFinal, 3, 3) . '-' . substr($strFinal, 6);
                 $this->strValidationError = null;
                 return true;
             }
             if (strlen($strFinal) > 11 && strpos($strFinal, 'x') == 10 && strpos($strFinal, 'x', 11) === false && strlen($strFinal) <= 17) {
                 $this->strText = substr($strFinal, 0, 3) . '-' . substr($strFinal, 3, 3) . '-' . substr($strFinal, 6, 4) . ' ' . substr($strFinal, 10);
                 $this->strValidationError = null;
                 return true;
             }
             $this->strValidationError = 'For example "213-555-1212" or "213-555-1212 x123"';
             return false;
         }
     } else {
         return false;
     }
     $this->strValidationError = null;
     return true;
 }
 public static function DisplayAsHtml($strContent)
 {
     // Let's get started
     $strResult = null;
     // Normalize all linebreaks and tabs
     $strContent = str_replace("\r\n", "\n", $strContent);
     $strContent = str_replace("\t", "    ", $strContent);
     while ($strContent) {
         // See if we are declaring a special block
         $strMatches = array();
         // Any Blank Lines get processed as such
         if (QString::FirstCharacter($strContent) == "\n") {
             $strContent = substr($strContent, 1);
             $strResult .= "<br/>\n";
             // Any Blocks matched by the PatternBlock regexp should be processed as a block
         } else {
             if (preg_match(self::PatternBlock, $strContent, $strMatches) && count($strMatches) >= 3 && ($strProcessorResult = QTextStyleBlock::Process($strMatches, $strContent)) !== false) {
                 $strResult .= $strProcessorResult;
                 // Any ListBlocks matched by the PatternListBlock regexp should be processed as a listblock (uses the same QTSBP::Process method)
             } else {
                 if (preg_match(self::PatternListBlock, $strContent, $strMatches) && count($strMatches) >= 3 && ($strProcessorResult = QTextStyleBlock::Process($strMatches, $strContent)) !== false) {
                     $strResult .= $strProcessorResult;
                     // Finally, anything that doesn't match any of the above will be processed as "Default"
                 } else {
                     $strContent = QTextStyle::KeyDefault . '. ' . $strContent;
                 }
             }
         }
     }
     // Return the resulting HTML
     return $strResult;
 }
Beispiel #4
0
 public static function StripDollar($strText)
 {
     if (QString::FirstCharacter($strText) == '$') {
         return substr($strText, 1);
     } else {
         return $strText;
     }
 }
 public static function UnderscoreFromCamelCase($strName)
 {
     if (strlen($strName) == 0) {
         return '';
     }
     $strToReturn = QString::FirstCharacter($strName);
     for ($intIndex = 1; $intIndex < strlen($strName); $intIndex++) {
         $strChar = substr($strName, $intIndex, 1);
         if (strtoupper($strChar) == $strChar) {
             $strToReturn .= '_' . $strChar;
         } else {
             $strToReturn .= $strChar;
         }
     }
     return strtolower($strToReturn);
 }
 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 #7
0
 /**
  * Generates a single Individual record
  * @param boolean $blnMaleFlag
  * @param boolean $blnAdultFlag whether this Individual should be a child or an adult
  * @param string $strLastName optional last name
  * @return Person
  */
 protected static function GenerateIndividual($blnMaleFlag, $blnAdultFlag, $strLastName = null)
 {
     $objPerson = new Person();
     $objPerson->Gender = $blnMaleFlag ? 'M' : 'F';
     // Generate the name
     $objPerson->FirstName = $blnMaleFlag ? QDataGen::GenerateMaleFirstName() : QDataGen::GenerateFemaleFirstName();
     switch (rand(1, 10)) {
         case 1:
         case 2:
         case 3:
             $objPerson->MiddleName = chr(rand(ord('A'), ord('Z'))) . '.';
             break;
         case 4:
         case 5:
             $objPerson->MiddleName = $blnMaleFlag ? QDataGen::GenerateMaleFirstName() : QDataGen::GenerateFemaleFirstName();
             break;
     }
     $objPerson->LastName = $strLastName ? $strLastName : QDataGen::GenerateLastName();
     $objPerson->CanEmailFlag = rand(0, 1);
     $objPerson->CanMailFlag = rand(0, 1);
     $objPerson->CanPhoneFlag = rand(0, 1);
     if (!rand(0, 10)) {
         $objPerson->Nickname = $blnMaleFlag ? QDataGen::GenerateMaleFirstName() : QDataGen::GenerateFemaleFirstName();
     }
     if (!rand(0, 5) && !$blnMaleFlag) {
         $objPerson->PriorLastNames = QDataGen::GenerateLastName();
     }
     if (!rand(0, 10)) {
         $objPerson->MailingLabel = QString::FirstCharacter($objPerson->FirstName) . '. ' . $objPerson->LastName;
     }
     if (!rand(0, 10)) {
         $arrTitleArray = $blnMaleFlag ? array('Mr.', 'Dr.', 'Sir') : array('Ms.', 'Miss', 'Mrs.', 'Dr.', 'Lady');
         $objPerson->Title = QDataGen::GenerateFromArray($arrTitleArray);
     }
     if (!rand(0, 10)) {
         $arrSuffixArray = array('Sr.', 'Jr.', 'III', 'PhD', 'MD');
         $objPerson->Suffix = QDataGen::GenerateFromArray($arrSuffixArray);
     }
     // Date of Birth
     if ($blnAdultFlag) {
         if (rand(0, 1)) {
             $objPerson->DateOfBirth = QDataGen::GenerateDateTime(self::$LifeStartDate, self::$OldestChildBirthDate);
         }
     } else {
         $objPerson->DateOfBirth = QDataGen::GenerateDateTime(self::$OldestChildBirthDate, QDateTime::Now());
     }
     if ($objPerson->DateOfBirth) {
         $objPerson->DobGuessedFlag = !rand(0, 12);
         $objPerson->DobYearApproximateFlag = !rand(0, 12);
     }
     // Refresh Membership and Marital Statuses
     $objPerson->RefreshMembershipStatusTypeId(false);
     $objPerson->RefreshMaritalStatusTypeId(false);
     $objPerson->RefreshAge(false);
     // Setup Deceased Information
     $objPerson->DeceasedFlag = !rand(0, 200);
     if ($objPerson->DeceasedFlag && rand(0, 1)) {
         $objPerson->DateDeceased = QDataGen::GenerateDateTime(self::$LifeStartDate, QDateTime::Now());
     }
     $objPerson->Save();
     $objPerson->RefreshNameItemAssociations();
     // Head Shots
     $objHeadShotArray = array();
     $intHeadShotCount = rand(0, 3);
     for ($i = 0; $i < $intHeadShotCount; $i++) {
         $objHeadShotArray[] = $objPerson->SaveHeadShot(self::GetRandomHeadShot($objPerson->Gender == 'M'), QDataGen::GenerateDateTime(self::$SystemStartDate, QDateTime::Now()));
     }
     if (count($objHeadShotArray)) {
         $objPerson->SetCurrentHeadShot(QDataGen::GenerateFromArray($objHeadShotArray));
     }
     // Membership
     $intMembershipCount = 0;
     if ($blnAdultFlag) {
         if (!rand(0, 2)) {
             $intMembershipCount = rand(1, 3);
         }
     } else {
         if (!rand(0, 10)) {
             $intMembershipCount = rand(1, 2);
         }
     }
     if ($intMembershipCount) {
         $dttEarliestPossible = new QDateTime($objPerson->DateOfBirth ? $objPerson->DateOfBirth : self::$SystemStartDate);
         self::GenerateMembershipsForIndividual($objPerson, $dttEarliestPossible, $intMembershipCount);
     }
     // Past or non-defined marriage
     if ($blnAdultFlag && !rand(0, 10)) {
         $objMarriage = new Marriage();
         $objMarriage->Person = $objPerson;
         $objMarriage->MarriageStatusTypeId = QDataGen::GenerateFromArray(array_keys(MarriageStatusType::$NameArray));
         if (rand(0, 1)) {
             $dttStart = QDateTime::Now();
             $dttStart = QDataGen::GenerateDateTime(self::$LifeStartDate, $dttStart);
             $dttStart = QDataGen::GenerateDateTime(self::$LifeStartDate, $dttStart);
             $dttStart = QDataGen::GenerateDateTime(self::$LifeStartDate, $dttStart);
             $dttStart = QDataGen::GenerateDateTime(self::$LifeStartDate, $dttStart);
             $dttStart = QDataGen::GenerateDateTime(self::$LifeStartDate, $dttStart);
             $objMarriage->DateStart = $dttStart;
             switch ($objMarriage->MarriageStatusTypeId) {
                 case MarriageStatusType::Divorced:
                 case MarriageStatusType::Widowed:
                     $objMarriage->DateEnd = QDataGen::GenerateDateTime($dttStart, QDateTime::Now());
                     break;
             }
         }
         $objMarriage->Save();
         $objPerson->RefreshMaritalStatusTypeId();
     }
     // Comments
     $intCount = rand(0, 12);
     for ($intIndex = 0; $intIndex < $intCount; $intIndex++) {
         $dttPostDate = self::GenerateDateTime(self::$SystemStartDate, QDateTime::Now());
         $objLogin = self::GenerateFromArray(self::$UserArray);
         $objCommentCategory = self::GenerateFromArray(self::$CommentCategoryArray);
         $intCommentPrivacyTypeId = self::GenerateFromArray(array_keys(CommentPrivacyType::$NameArray));
         $strComment = self::GenerateContent(rand(1, 2), 5, 20);
         $dttActionDate = rand(0, 10) ? null : self::GenerateDateTime(self::$SystemStartDate, QDateTime::Now());
         $objPerson->SaveComment($objLogin, $strComment, $intCommentPrivacyTypeId, $objCommentCategory->Id, $dttPostDate, $dttActionDate);
     }
     // Addresses and Phone
     self::GenerateAddressesAndPhonesForPerson($objPerson);
     // Attributes
     self::GenerateAttributesForPerson($objPerson);
     return $objPerson;
 }
 public function objParticipationArray_Sort(GroupParticipation $objParticipation1, GroupParticipation $objParticipation2)
 {
     if ($objParticipation1->GroupRoleId != $objParticipation2->GroupRoleId) {
         return ord(QString::FirstCharacter($objParticipation1->GroupRole->Name)) < ord(QString::FirstCharacter($objParticipation2->GroupRole->Name)) ? -1 : 1;
     }
     return $objParticipation1->DateStart->IsEarlierThan($objParticipation2->DateStart) ? -1 : 1;
 }
Beispiel #9
0
 /**
  * Gets the value of the PathInfo item at index $intIndex.  Will return NULL if it doesn't exist.
  * If no $intIndex is given will return an array with PathInfo contents.
  *
  * The way PathInfo index is determined is, for example, given a URL '/folder/page.php/id/15/blue',
  * QApplication::PathInfo(0) will return 'id'
  * QApplication::PathInfo(1) will return '15'
  * QApplication::PathInfo(2) will return 'blue'
  *
  * @return mixed
  */
 public static function PathInfo($intIndex = null)
 {
     // Lookup PathInfoArray from cache, or create it into cache if it doesn't yet exist
     if (!isset(self::$arrPathInfo)) {
         $strPathInfo = QApplication::$PathInfo;
         self::$arrPathInfo = array();
         if ($strPathInfo != '') {
             if ($strPathInfo == '/') {
                 self::$arrPathInfo[0] = '';
             } else {
                 // Remove Trailing '/'
                 if (QString::FirstCharacter($strPathInfo) == '/') {
                     $strPathInfo = substr($strPathInfo, 1);
                 }
                 self::$arrPathInfo = explode('/', $strPathInfo);
             }
         }
     }
     if ($intIndex === null) {
         return self::$arrPathInfo;
     } elseif (array_key_exists($intIndex, self::$arrPathInfo)) {
         return self::$arrPathInfo[$intIndex];
     } else {
         return null;
     }
 }
 /**
  * Given the path of a directory, process all the directories and files in it that have NOT been seen in SeenRealPath.
  * Assumes: the path is a valid directory that exists and has NOT been SeenRealPath
  * @param string $strPath
  * @return void
  */
 protected function ProcessDirectory($strPath, QDirectoryToken $objDirectoryToken)
 {
     $strRealPath = realpath($strPath);
     $this->strSeenRealPath[$strRealPath] = true;
     $objDirectory = opendir($strPath);
     while ($strName = readdir($objDirectory)) {
         // Only Process Files/Folders that do NOT start with a single "."
         if (QString::FirstCharacter($strName) != '.') {
             // Put Together the Entire Full Path of the File in Question
             $strFullPath = $strPath . '/' . $strName;
             // Process if it's a file
             if (is_file($strFullPath)) {
                 $this->ProcessFile($strFullPath, $objDirectoryToken);
                 // Process if it's a directory
             } else {
                 if (is_dir($strFullPath)) {
                     // Only continue if we haven't visited it and it's not a folder that we are ignoring
                     $strRealPath = realpath($strFullPath);
                     if (!array_key_exists($strRealPath, $this->strSeenRealPath) && !array_key_exists(strtolower($strName), $this->blnIgnoreFolderArray)) {
                         $this->ProcessDirectory($strFullPath, $objDirectoryToken);
                     }
                     // It's neither a file nor a directory?!
                 } else {
                     throw new Exception('Not a valid file or folder: ' . $strFullPath);
                 }
             }
         }
     }
 }
		/**
		 * Gets the value of the PathInfo item at index $intIndex.  Will return NULL if it doesn't exist.
		 *
		 * The way PathInfo index is determined is, for example, given a URL '/folder/page.php/id/15/blue',
		 * QApplication::PathInfo(0) will return 'id'
		 * QApplication::PathInfo(1) will return '15'
		 * QApplication::PathInfo(2) will return 'blue'
		 *
		 * @return void
		 */
		public static function PathInfo($intIndex) {
			// TODO: Cache PathInfo
			$strPathInfo = QApplication::$PathInfo;
			
			// Remove Trailing '/'
			if (QString::FirstCharacter($strPathInfo) == '/')			
				$strPathInfo = substr($strPathInfo, 1);
			
			$strPathInfoArray = explode('/', $strPathInfo);

			if (array_key_exists($intIndex, $strPathInfoArray))
				return $strPathInfoArray[$intIndex];
			else
				return null;
		}
 protected static function ListBlockRecursion($strBlockContent, $strBlockIdentifier, $strStyle = null, $strOptions = null)
 {
     if (QString::FirstCharacter($strBlockIdentifier) == '#') {
         $strTag = 'ol';
     } else {
         $strTag = 'ul';
     }
     $strToReturn = sprintf("<%s%s>\n", $strTag, $strStyle);
     $strListItemArray = explode("\n" . $strBlockIdentifier . ' ', $strBlockContent);
     foreach ($strListItemArray as $strListItem) {
         $strToReturn .= '<li>' . QTextStyleBlock::ListBlockItem($strListItem, $strBlockIdentifier) . "</li>\n";
     }
     $strToReturn .= sprintf("</%s>\n\n", $strTag);
     return $strToReturn;
 }
 /**
  * Given a "-"-based argument, this will parse out the information, pulling out and validating any/all ShortIdentifiers.
  * If it is a single or clustered FlagParameter, it will set the flag(s) to true.
  * If it is a NamedParameter, then if a value is specified using "=", then the value will be applied to the ShortIdentifier, otherwise, it will set $intCurrentValueIndex to the ValueIndex of the ShortIdentifier.
  * @param string $strArgument the full "-"-based argument
  * @param integer $intCurrentValueIndex the new current ValueIndex that should be evaluated (if applicable)
  * @return string any error message (if any)
  */
 protected function ParseShortIdentifier($strArgument, &$intCurrentValueIndex)
 {
     // Parse out the leading "-"
     $strArgument = substr($strArgument, 1);
     // Clean Out and Verify the ShortIdentifier
     $chrShortIdentifier = substr($strArgument, 0, 1);
     try {
         $chrShortIdentifier = QCliParameterProcessor::CleanShortIdentifier($chrShortIdentifier);
     } catch (QCallerException $objExc) {
         return 'invalid argument "' . $chrShortIdentifier . '"';
     }
     // Get the ValueIndex
     if (array_key_exists($chrShortIdentifier, $this->chrShortIdentifierArray)) {
         $intValueIndex = $this->chrShortIdentifierArray[$chrShortIdentifier];
     } else {
         return 'invalid argument "' . $chrShortIdentifier . '"';
     }
     // See if this is a Flag- or a Named-Parameter
     if (array_key_exists($intValueIndex, $this->blnFlagArray)) {
         // Flag!  This also may be clustered, so go through all of the letters in the argument and set the flag value to true
         return $this->ParseShortIdentifierCluster($strArgument);
     } else {
         // NamedParameter -- Do we Have a Value?
         $strArgument = substr($strArgument, 1);
         if (strlen($strArgument)) {
             // Yes -- Set it
             // Take out any leading "="
             if (QString::FirstCharacter($strArgument) == '=') {
                 $strArgument = substr($strArgument, 1);
             }
             // Set the Value
             try {
                 $this->mixValueArray[$intValueIndex] = QCliParameterProcessor::CleanValue($strArgument, $this->intParameterTypeArray[$intValueIndex]);
             } catch (QCallerException $objExc) {
                 return $objExc->GetMessage();
             }
         } else {
             // No -- so let's update the Currently-processing ValueIndex
             $intCurrentValueIndex = $intValueIndex;
         }
     }
     // Success - no errors
     return null;
 }
Beispiel #14
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;
 }
 public static function Process($strInlineContent)
 {
     // Setup the Content
     QTextStyleInline::$strInlineContent = $strInlineContent;
     // Reset the stack
     QTextStyleInline::$objStateStack = new QTextStyleStateStack();
     QTextStyleInline::$objStateStack->Push(QTextStyle::StateText);
     QTextStyleInline::$objStateStack->Push(QTextStyle::StateWordStartHint);
     // Continue iterating while there is content to parse and items on the stack
     while (strlen(QTextStyleInline::$strInlineContent) || !QTextStyleInline::$objStateStack->IsEmpty()) {
         // If there is content, parse it!
         if (strlen(QTextStyleInline::$strInlineContent)) {
             // Figure out the current character we are attempting to parse with
             $chrCurrent = QString::FirstCharacter(QTextStyleInline::$strInlineContent);
             // Pull out the StateRules for the top-most stack's state
             $arrStateRules = QTextStyle::$StateRulesArray[QTextStyleInline::$objStateStack->PeekTop()->State];
             // Figure out the StateRule key to use based on the current character
             if (array_key_exists($chrCurrent, $arrStateRules)) {
                 $strKey = $chrCurrent;
             } else {
                 if (array_key_exists(QTextStyle::KeyAlpha, $arrStateRules) && preg_match('/[A-Za-z]/', $chrCurrent)) {
                     $strKey = QTextStyle::KeyAlpha;
                 } else {
                     if (array_key_exists(QTextStyle::KeyNumeric, $arrStateRules) && preg_match('/[0-9]/', $chrCurrent)) {
                         $strKey = QTextStyle::KeyNumeric;
                     } else {
                         if (array_key_exists(QTextStyle::KeyAlphaNumeric, $arrStateRules) && preg_match('/[A-Za-z0-9]/', $chrCurrent)) {
                             $strKey = QTextStyle::KeyAlphaNumeric;
                         } else {
                             $strKey = QTextStyle::KeyDefault;
                         }
                     }
                 }
             }
             // Go through the rules for our current state and key
             foreach ($arrStateRules[$strKey] as $mixRule) {
                 // Pull the Command and the parameters for the commad (if any)
                 if (is_array($mixRule)) {
                     $strCommand = $mixRule[0];
                     $strParameterArray = $mixRule;
                     array_shift($strParameterArray);
                 } else {
                     $strParameterArray = array();
                     $strCommand = $mixRule;
                 }
                 // Dump the stack to the output buffer (if requested)
                 if (QTextStyleInline::$OutputDebugMessages) {
                     if (is_array($mixRule)) {
                         $strDisplayCommand = implode(', ', $mixRule);
                     } else {
                         $strDisplayCommand = $strCommand;
                     }
                     QTextStyleInline::DumpStack(QTextStyleInline::$strInlineContent . ' - [' . $chrCurrent . '] - Key(' . $strKey . ') - Command(' . $strDisplayCommand . ')');
                 }
                 QTextStyleInline::$strCommand($chrCurrent, $strParameterArray);
             }
             // There is no Inline Content to process -- go ahead and call cancel on the top-most state
         } else {
             // Call the cancel method -- store any return vaue
             // If it is the last state on the stack, the return value will be returned
             $strToReturn = QTextStyleInline::CancelTopState();
         }
     }
     return $strToReturn;
 }
Beispiel #16
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);
     }
 }
 /**
  * Gets the value of the PathInfo item at index $intIndex.  Will return NULL if it doesn't exist.
  *
  * The way PathInfo index is determined is, for example, given a URL '/folder/page.php/id/15/blue',
  * QApplication::PathInfo(0) will return 'id'
  * QApplication::PathInfo(1) will return '15'
  * QApplication::PathInfo(2) will return 'blue'
  *
  * @param int $intIndex index
  * @return string|null
  */
 public static function PathInfo($intIndex)
 {
     // TODO: Cache PathInfo
     $strPathInfo = urldecode(QApplication::$PathInfo);
     // Remove Starting '/'
     if (QString::FirstCharacter($strPathInfo) == '/') {
         $strPathInfo = substr($strPathInfo, 1);
     }
     $strPathInfoArray = explode('/', $strPathInfo);
     if (array_key_exists($intIndex, $strPathInfoArray)) {
         return $strPathInfoArray[$intIndex];
     } else {
         return null;
     }
 }
Beispiel #18
0
 /**
  * Returns a randomly generated "username" based on a first name and last name.
  * @param string $strFirstName first name of the user
  * @param string $strLastName last name of the user
  * @return string
  */
 public static function GenerateUsername($strFirstName, $strLastName)
 {
     $strFirstName = trim(strtolower(str_replace("'", '', str_replace(' ', '', $strFirstName))));
     $strLastName = trim(strtolower(str_replace("'", '', str_replace(' ', '', $strLastName))));
     return QString::FirstCharacter($strFirstName) . $strLastName . rand(0, 9999);
 }
 protected function TypeTokenFromTypeName($strName)
 {
     $strToReturn = '';
     for ($intIndex = 0; $intIndex < strlen($strName); $intIndex++) {
         if (ord($strName[$intIndex]) >= ord('a') && ord($strName[$intIndex]) <= ord('z') || ord($strName[$intIndex]) >= ord('A') && ord($strName[$intIndex]) <= ord('Z') || ord($strName[$intIndex]) >= ord('0') && ord($strName[$intIndex]) <= ord('9') || $strName[$intIndex] == '_') {
             $strToReturn .= $strName[$intIndex];
         }
     }
     if (is_numeric(QString::FirstCharacter($strToReturn))) {
         $strToReturn = '_' . $strToReturn;
     }
     return $strToReturn;
 }
 protected function ParsePoData($strPoData)
 {
     $strPoData = str_replace("\r", '', trim($strPoData));
     $strPoLines = explode("\n", $strPoData);
     $strMatches = array();
     $intState = QTranslationPoParser::PoParseStateNone;
     $intLineCount = count($strPoLines);
     if (strlen($strPoLines[0]) == 0) {
         return;
     }
     for ($intLineNumber = 0; $intLineNumber < $intLineCount; $intLineNumber++) {
         $strPoLine = $strPoLines[$intLineNumber] = trim($strPoLines[$intLineNumber]);
         if (strlen($strPoLine) && QString::FirstCharacter($strPoLine) != '#') {
             switch ($intState) {
                 case QTranslationPoParser::PoParseStateNone:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $intLineNumber--;
                         $intState = QTranslationPoParser::PoParseStateMessageIdStart;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateNone on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QTranslationPoParser::PoParseStateMessageIdStart:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strMessageId = array('', '', '', '', '', '', '');
                         $strMessageString = array('', '', '', '', '', '', '');
                         $intArrayIndex = 0;
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] = $strContent;
                         $intState = QTranslationPoParser::PoParseStateMessageId;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateMessageIdStart on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QTranslationPoParser::PoParseStateMessageId:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId content for current MsgId on Line ' . $intLineNumber . ': ' . $strPoLine);
                         }
                         $intArrayIndex++;
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] = $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/"([\\S 	]*)"/', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[1][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageId[$intArrayIndex] .= $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId content for current MsgId on Line ' . $intLineNumber . ': ' . $strPoLine);
                         }
                         $intLineNumber--;
                         $intState = QTranslationPoParser::PoParseStateMessageStringStart;
                         break;
                     }
                     throw new QPoParserException('Invalid content for PoParseStateMessageId on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                 case QTranslationPoParser::PoParseStateMessageStringStart:
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $intArrayIndex = 0;
                         if (strlen($strMatches[1][0])) {
                             $intArrayIndex = intval(substr($strMatches[1][0], 1, strlen($strMatches[1][0]) - 2));
                         }
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] = $strContent;
                         $intState = QTranslationPoParser::PoParseStateMessageString;
                     } else {
                         throw new QPoParserException('Invalid content for PoParseStateMessageStringStart on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                     }
                     break;
                 case QTranslationPoParser::PoParseStateMessageString:
                     $intCount = preg_match_all('/msgid(_[a-z0-9]+)?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         for ($intIndex = 0; $intIndex < count($strMessageId); $intIndex++) {
                             if (strlen(trim($strMessageId[$intIndex]))) {
                                 if (!strlen(trim($strMessageString[$intIndex]))) {
                                     $this->SetTranslation($strMessageId[$intIndex], "");
                                 }
                                 $this->SetTranslation($strMessageId[$intIndex], $strMessageString[$intIndex]);
                             }
                         }
                         $intLineNumber--;
                         $intState = QTranslationPoParser::PoParseStateMessageIdStart;
                         break;
                     }
                     $intCount = preg_match_all('/"([\\S 	]*)"/', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[1][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] .= $strContent;
                         break;
                     }
                     $intCount = preg_match_all('/msgstr(\\[[0-9]+\\])?[\\s]+"([\\S 	]*)"/i', $strPoLine, $strMatches);
                     if ($intCount && $strMatches[0][0] == $strPoLine) {
                         if (strlen($strMatches[1][0])) {
                             $intArrayIndex = intval(substr($strMatches[1][0], 1, strlen($strMatches[1][0]) - 2));
                         } else {
                             throw new QPoParserException('No index specified for alternate MsgStr for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                         }
                         if (strlen(trim($strMessageId[$intArrayIndex])) == 0) {
                             throw new QPoParserException('No MsgId for MsgStr' . $strMatches[1][0] . ' for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                         }
                         $strContent = QTranslationPoParser::UnescapeContent($strMatches[2][0]);
                         if ($strContent === false) {
                             throw new QPoParserException('Invalid content on Line ' . ($intLineNumber + 1));
                         }
                         $strMessageString[$intArrayIndex] = $strContent;
                         break;
                     }
                     throw new QPoParserException('Invalid content for PoParseStateMessageString on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
                 default:
                     throw new QPoParserException('Invalid PoParseState on Line ' . ($intLineNumber + 1) . ': ' . $strPoLine);
             }
         }
     }
     for ($intIndex = 0; $intIndex < count($strMessageId); $intIndex++) {
         if (strlen(trim($strMessageId[$intIndex]))) {
             if (!strlen(trim($strMessageString[$intIndex]))) {
                 $this->SetTranslation($strMessageId[$intIndex], "");
             }
             $this->SetTranslation($strMessageId[$intIndex], $strMessageString[$intIndex]);
         }
     }
 }
Beispiel #21
0
 public function PullDataFromLdap()
 {
     $objResult = ldap_search($this->objLdap, 'OU=People,dc=ir,dc=alcf,dc=net', 'CN=*');
     $arrResults = ldap_get_entries($this->objLdap, $objResult);
     unset($arrResults['count']);
     $this->arrGroups = array();
     $this->arrPeople = array();
     $this->arrContacts = array();
     foreach ($arrResults as $intKey => $arrResult) {
         $blnIsPerson = false;
         $blnIsGroup = false;
         foreach ($arrResult["objectclass"] as $strClass) {
             if ($strClass == "user") {
                 $blnIsPerson = true;
             }
             if ($strClass == "group") {
                 $blnIsGroup = true;
             }
         }
         if (!array_key_exists('samaccountname', $arrResult)) {
             $this->arrContacts[] = $arrResult;
         } else {
             if ($blnIsPerson && $blnIsGroup) {
                 throw new Exception('Record appears to be BOTH person AND group');
             } else {
                 if ($blnIsPerson) {
                     $this->arrPeople[] = $arrResult;
                 } else {
                     if ($blnIsGroup) {
                         // Valid groups must have tokens that begin with gg_ and must have actual members
                         // and must have names that do NOT begin with "*"
                         $strArray = AlcfLdap::GetValuesFromPath($arrResult["distinguishedname"][0]);
                         $strHierarchyArray = $strArray['OU'];
                         $strGroupName = $strHierarchyArray[0];
                         $strToken = strtolower($arrResult['samaccountname'][0]);
                         if (array_key_exists('member', $arrResult) && substr($strToken, 0, 3) == 'gg_' && QString::FirstCharacter($strGroupName) != '*') {
                             $this->arrGroups[] = $arrResult;
                         }
                     } else {
                         throw new Exception('Record appears to be NEITHER person NOR group');
                     }
                 }
             }
         }
     }
 }
Beispiel #22
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;
}