splitTags() public static method

public static splitTags ( $TagsString ) : array
$TagsString
return array
Exemplo n.º 1
0
 /**
  * Validate tags when saving a discussion.
  */
 public function discussionModel_beforeSaveDiscussion_handler($Sender, $Args)
 {
     $reservedTags = [];
     $Sender->EventArguments['ReservedTags'] =& $reservedTags;
     $Sender->FireEvent('ReservedTags');
     $FormPostValues = val('FormPostValues', $Args, array());
     $TagsString = trim(strtolower(val('Tags', $FormPostValues, '')));
     $NumTagsMax = c('Plugin.Tagging.Max', 5);
     // Tags can only contain unicode and the following ASCII: a-z 0-9 + # _ .
     if (stringIsNullOrEmpty($TagsString) && c('Plugins.Tagging.Required')) {
         $Sender->Validation->addValidationResult('Tags', 'You must specify at least one tag.');
     } else {
         $Tags = TagModel::splitTags($TagsString);
         // Handle upper/lowercase
         $Tags = array_map('strtolower', $Tags);
         $reservedTags = array_map('strtolower', $reservedTags);
         if ($reservedTags = array_intersect($Tags, $reservedTags)) {
             $names = implode(', ', $reservedTags);
             $Sender->Validation->addValidationResult('Tags', '@' . sprintf(t('These tags are reserved and cannot be used: %s'), $names));
         }
         if (!TagModel::validateTags($Tags)) {
             $Sender->Validation->addValidationResult('Tags', '@' . t('ValidateTag', 'Tags cannot contain commas.'));
         } elseif (count($Tags) > $NumTagsMax) {
             $Sender->Validation->addValidationResult('Tags', '@' . sprintf(t('You can only specify up to %s tags.'), $NumTagsMax));
         } else {
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Validate tags when saving a discussion.
  */
 public function discussionModel_beforeSaveDiscussion_handler($Sender, $Args)
 {
     $FormPostValues = val('FormPostValues', $Args, array());
     $TagsString = trim(strtolower(val('Tags', $FormPostValues, '')));
     $NumTagsMax = c('Plugin.Tagging.Max', 5);
     // Tags can only contain unicode and the following ASCII: a-z 0-9 + # _ .
     if (stringIsNullOrEmpty($TagsString) && c('Plugins.Tagging.Required')) {
         $Sender->Validation->addValidationResult('Tags', 'You must specify at least one tag.');
     } else {
         $Tags = TagModel::splitTags($TagsString);
         if (!TagModel::validateTags($Tags)) {
             $Sender->Validation->addValidationResult('Tags', '@' . t('ValidateTag', 'Tags cannot contain commas.'));
         } elseif (count($Tags) > $NumTagsMax) {
             $Sender->Validation->addValidationResult('Tags', '@' . sprintf(t('You can only specify up to %s tags.'), $NumTagsMax));
         } else {
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Validate tags when saving a discussion.
  *
  * @param DiscussionModel $Sender
  * @param array $Args
  */
 public function discussionModel_beforeSaveDiscussion_handler($Sender, $Args)
 {
     // Allow an addon to set disallowed tag names.
     $reservedTags = [];
     $Sender->EventArguments['ReservedTags'] =& $reservedTags;
     $Sender->fireEvent('ReservedTags');
     // Set some tagging requirements.
     $TagsString = trim(strtolower(valr('FormPostValues.Tags', $Args, '')));
     if (stringIsNullOrEmpty($TagsString) && c('Plugins.Tagging.Required')) {
         $Sender->Validation->addValidationResult('Tags', 'You must specify at least one tag.');
     } else {
         // Break apart our tags and lowercase them all for comparisons.
         $Tags = TagModel::splitTags($TagsString);
         $Tags = array_map('strtolower', $Tags);
         $reservedTags = array_map('strtolower', $reservedTags);
         $maxTags = c('Plugin.Tagging.Max', 5);
         // Validate our tags.
         if ($reservedTags = array_intersect($Tags, $reservedTags)) {
             $names = implode(', ', $reservedTags);
             $Sender->Validation->addValidationResult('Tags', '@' . sprintf(t('These tags are reserved and cannot be used: %s'), $names));
         }
         if (!TagModel::validateTags($Tags)) {
             $Sender->Validation->addValidationResult('Tags', '@' . t('ValidateTag', 'Tags cannot contain commas.'));
         }
         if (count($Tags) > $maxTags) {
             $Sender->Validation->addValidationResult('Tags', '@' . sprintf(t('You can only specify up to %s tags.'), $maxTags));
         }
     }
 }