예제 #1
0
 public function truncate($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('text' => '', 'offset' => 0, 'length' => 100, 'pad' => ' ...'));
     // Don't show endstring if actual string length is less than cutting length
     $config->endstr = KHelperString::strlen($config->text) < $config->length ? '' : $config->pad;
     return KHelperString::substr(strip_tags($config->text), $config->offset, $config->length) . $config->pad;
 }
예제 #2
0
 public function truncate($config = array())
 {
     $config = new KConfig($config);
     $config->append(array('text' => '', 'offset' => 0, 'length' => 100, 'path' => ' ...', 'allowed_tags' => ''));
     $text = strip_tags($config->text, $config->allowed_tags);
     if (KHelperString::strlen($config->text) > $config->length) {
         $text = KHelperString::substr($text, $config->offset, $config->length) . $config->path;
     }
     return $text;
 }
예제 #3
0
 /**
  * Adds a comment.
  *
  * @param string|ComBaseDomainEntityComment $comment The comment to add
  *
  * @return ComBaseDomainEntityComment
  */
 public function addComment($comment)
 {
     if (is_string($comment)) {
         $comment = KHelperString::trim($comment);
         $comment = array('author' => get_viewer(), 'body' => $comment, 'component' => $this->component);
     }
     $comment = $this->_mixer->comments->addNew($comment);
     if ($this->_mixer->isSubscribable() && !$this->_mixer->subscribed($comment->author)) {
         $this->_mixer->addSubscriber($comment->author);
     }
     return $comment;
 }
예제 #4
0
파일: string.php 프로젝트: stonyyi/anahita
 /**
  * Callback function for preg_replace_callback call in utf8_ucwords
  *
  * You don't need to call this yourself
  *
  * @param array of matches corresponding to a single word
  * @return string with first char of the word in uppercase
  * @see ucwords
  * @see strtoupper
  */
 public static function ucwords_callback($matches)
 {
     $leadingws = $matches[2];
     $ucfirst = KHelperString::strtoupper($matches[3]);
     $ucword = KHelperString::substr_replace(ltrim($matches[0]), $ucfirst, 0, 1);
     return $leadingws . $ucword;
 }
예제 #5
0
 /**
  * Removes the @ symbol from a username in the body of the node.
  * 
  * @param string username
  */
 protected function invalidateUsername($username)
 {
     $this->_mixer->set('body', KHelperString::str_ireplace('@' . $username, $username, $this->_mixer->body));
 }
예제 #6
0
 /**
  * Validate length.
  *
  * @param KConfig $config Configuration. Contains keys property,value,entity
  *
  * @return bool Return true if it's valid or false if it's not
  */
 protected function _validateLength(KConfig $config)
 {
     $property = $config->property;
     $value = $config->value;
     $entity = $config->entity;
     $options = KConfig::unbox($config->options);
     //if a number is just passed then treat it as max
     if (!is_array($options)) {
         $options = array('max' => $options);
     }
     if ($property->isAttribute() && $property->isScalar()) {
         $options = KConfig::unbox($options);
         if (is_array($options)) {
             //check the min/max length
             if (isset($options['max']) || isset($options['min'])) {
                 if (isset($options['max'])) {
                     $greater = KHelperString::strlen($value) > (int) $options['max'];
                     if ($greater) {
                         $entity->addError(array('message' => sprintf(JText::_('%s %s can not be greater than %d characters'), $this->getIdentifier()->name, $property->getName(), $options['max']), 'code' => AnError::INVALID_LENGTH, 'key' => $property->getName(), 'max_lenght' => $options['max']));
                         return false;
                     }
                 }
                 if (isset($options['min'])) {
                     $lesser = KHelperString::strlen($value) < (int) $options['min'];
                     if ($lesser) {
                         $entity->addError(array('message' => sprintf(JText::_('%s %s can not be less than %d characters'), $this->getIdentifier()->name, $property->getName(), $options['min']), 'code' => AnError::INVALID_LENGTH, 'key' => $property->getName(), 'min_length' => $options['min']));
                         return false;
                     }
                 }
             }
         } else {
             if (KHelperString::strlen($value) != (int) $options) {
                 $entity->addError(array('message' => sprintf(JText::_('%s %s must be %d characters'), $this->getIdentifier()->name, $property->getName(), $options), 'code' => AnError::INVALID_LENGTH, 'key' => $property->getName(), 'length' => (int) $options));
                 return false;
             }
         }
     }
 }
예제 #7
0
파일: signup.php 프로젝트: josefXXX/anahita
 /**
  * Instantiate a Merchant_Billing_CreditCard object
  *
  * @param  KConfig $data
  * @return Merchant_Billing_CreditCard
  */
 protected function _instantiateCreditCard($data)
 {
     if ($data->token) {
         unset($data['creditcard']);
         unset($data['contact']);
         return;
     }
     $data->append(array('creditcard' => new KConfig()));
     $creditcard = $data->creditcard;
     $name = trim($creditcard->name);
     $space = KHelperString::strpos($name, ' ');
     $creditcard_data = array('type' => $creditcard->type, "first_name" => KHelperString::ucwords(KHelperString::substr($name, 0, $space)), "last_name" => KHelperString::ucwords(KHelperString::substr($name, $space + 1)), "number" => $creditcard->number, "month" => $creditcard->month, "year" => $creditcard->year, "verification_value" => $creditcard->csv);
     $creditcard = new Merchant_Billing_CreditCard($creditcard_data);
     $this->creditcard = $creditcard;
     $contact = $this->_instantiateContact($data);
     $this->order->setPaymentMethod(new ComSubscriptionsDomainPaymentMethodCreditcard($creditcard, $contact));
     return $creditcard;
 }
예제 #8
0
파일: text.php 프로젝트: stonyyi/anahita
 /**
  * Return a sanitized version of a text which can be assigned to a javascript variable.
  *
  * @param string $text The text to sanitize
  * 
  * @return string
  */
 public function script($text)
 {
     return htmlspecialchars($this->getService('koowa:filter.string')->sanitize(KHelperString::str_ireplace(array("\r\n", "\n"), '', $text)), ENT_QUOTES);
 }
예제 #9
0
 /**
  * Draws an actor cover image
  * 
  * @param ComActorsDomainEntityActor $actor
  * @param string                    $size 
  * @param boolean                   $linked if true it returns a linked image tag of not just an image tag
  * @param array                     $attr link attributes
  * 
  * @return string
  */
 public function cover($actor, $size = 'large', $linked = true, $attr = array())
 {
     if (is_numeric($size)) {
         $width = "width=\"{$size}\"";
         $size = 'large';
     } else {
         $width = '';
     }
     if ($actor->coverSet()) {
         $src = $actor->getCoverURL($size);
         $name = KHelperString::ucwords($actor->name);
         $img = '<img ' . $width . ' alt="' . $name . '" class="cover" src="' . $src . '"  />';
     }
     if ($linked && $actor->authorize('access')) {
         $url = $this->getActorURL($actor);
         $img = '<a ' . $this->_buildAttribute($attr) . ' data-actor="' . $actor->id . '" href="' . $url . '" >' . $img . '</a>';
     }
     return $img;
 }