Esempio n. 1
1
 public function encode(string $input)
 {
     $output = "";
     $prevc = NULL;
     for ($i = 0; $i < \strlen($input); $i++) {
         $c = $input[$i];
         if ("" < $c) {
             if ($this->errorOnNonASCII) {
                 throw new \Exception("Error at position {$i}: non-ASCII byte '{$c}'");
             }
         } else {
             $c = strtolower($c);
         }
         $replacement = $this->letters[$c] ?? $this->digits[$c] ?? NULL;
         if ($replacement !== NULL && !($c === "." && $replacement === ($this->digits[$c] ?? NULL) && !ctype_digit($prevc))) {
             // Insert spaces at word boundaries
             if ($prevc !== NULL && !ctype_space($prevc) && !ctype_punct($prevc) || $prevc === '.' && ctype_digit($c)) {
                 $output .= ' ';
             }
             $output .= $replacement;
         } else {
             $output .= $c;
         }
         $prevc = $c;
     }
     return $output;
 }
Esempio n. 2
0
 protected function split($uInput)
 {
     $tParts = [[], []];
     $tBuffer = "";
     $tQuote = false;
     for ($tPosition = 0, $tLen = strlen($uInput); $tPosition < $tLen; $tPosition++) {
         if ($uInput[$tPosition] === "\"") {
             $tQuote = !$tQuote;
             continue;
         } elseif (ctype_space($uInput[$tPosition])) {
             if (strlen($tBuffer) == 0) {
                 continue;
             }
             if (!$tQuote) {
                 if (strncmp($tBuffer, "--", 2) === 0) {
                     $tParts[1][] = $tBuffer;
                 } else {
                     $tParts[0][] = $tBuffer;
                 }
                 $tBuffer = "";
                 continue;
             }
         }
         $tBuffer .= $uInput[$tPosition];
     }
     if (strlen($tBuffer) > 0) {
         if (strncmp($tBuffer, "--", 2) === 0) {
             $tParts[1][] = $tBuffer;
         } else {
             $tParts[0][] = $tBuffer;
         }
     }
     return $tParts;
 }
 /**
  * Get tokens as string[] extracted from a QTI file
  * XML inside qti.xml is parsed and all text is tokenized
  *
  * @param \core_kernel_classes_Resource $resource
  * @return array
  */
 public function getStrings(\core_kernel_classes_Resource $resource)
 {
     try {
         $ontologyFiles = $resource->getPropertyValues($this->getProperty(TAO_ITEM_CONTENT_PROPERTY));
         if (empty($ontologyFiles)) {
             return [];
         }
     } catch (\core_kernel_classes_EmptyProperty $e) {
         return [];
     }
     $file = $this->getFileReferenceSerializer()->unserializeDirectory(reset($ontologyFiles))->getFile(Service::QTI_ITEM_FILE);
     if (!$file->exists()) {
         return [];
     }
     $content = $file->read();
     if (empty($content)) {
         return [];
     }
     $dom = new \DOMDocument();
     $dom->loadXML($content);
     $xpath = new \DOMXPath($dom);
     $textNodes = $xpath->query('//text()');
     unset($xpath);
     $contentStrings = array();
     foreach ($textNodes as $textNode) {
         if (ctype_space($textNode->wholeText) === false) {
             $contentStrings[] = trim($textNode->wholeText);
         }
     }
     return $contentStrings;
 }
Esempio n. 4
0
 /**
  * Ensure that text is no longer than $maxLength. If so, truncate $subject at word boundary
  * closest before $maxLength and replace with $suffix
  * @param string $subject Original text to summarize
  * @param int $maxLength
  * @param string $suffix Text to append at end if $subject is longer than $maxLength,
  * @return string Truncated text followed by $suffix if necessary
  */
 public static function summarize($subject, $maxLength, $suffix = '...')
 {
     if (!$subject) {
         return '';
     }
     if (strlen($subject) <= $maxLength) {
         return $subject;
     }
     $suffixLen = strlen($suffix);
     // Leave space for the suffix
     $index = $maxLength - $suffixLen;
     // Look for a natural break after which to append the suffix
     while ($index > 0) {
         if (ctype_space($subject[$index])) {
             break;
         }
         $index -= 1;
     }
     // Maybe it's just one very long word
     // NOTE not covering case where $maxLength <= $suffixLen
     if ($index <= 0) {
         return substr($subject, 0, $maxLength - $suffixLen) . $suffix;
     }
     return substr($subject, 0, $index) . $suffix;
 }
Esempio n. 5
0
 /**
  * Constructor, accepts data and determines if it is whitespace.
  *
  * @param $data String parsed character data.
  */
 public function __construct($data, $line = null, $col = null)
 {
     $this->data = $data;
     $this->is_whitespace = ctype_space($data);
     $this->line = $line;
     $this->col = $col;
 }
function raefftec_userlist()
{
    $users = get_users(array('meta_key' => 'last_name', 'orderby' => 'meta_value'));
    $fields = array('avatar' => '', 'user_lastname' => __('Lastname', 'raefftec-userlist'), 'user_firstname' => __('Firstname', 'raefftec-userlist'), 'address' => __('Address', 'raefftec-userlist'), 'zip' => __('ZIP', 'raefftec-userlist'), 'city' => __('City', 'raefftec-userlist'), 'user_email' => __('E-Mail', 'raefftec-userlist'));
    $content = '<table id="raefftec_userlist">';
    $content = $content . '<thead>';
    $content = $content . '<tr>';
    foreach ($fields as $key => $value) {
        $content = $content . '<th class="' . $key . '">' . $value . '</th>';
    }
    $content = $content . '</tr>';
    $content = $content . '</thead>';
    $content = $content . '<tbody>';
    foreach ($users as $user) {
        $content = $content . '<tr>';
        foreach ($fields as $key => $value) {
            $content = $content . '<td class="' . $key . '" data-th="' . $value . '">';
            if ($key == 'avatar') {
                $content = $content . get_avatar($user->ID, 48);
            } else {
                $data = get_the_author_meta($key, $user->ID);
                $content = $content . (ctype_space($data) || $data == '' ? '&nbsp' : $data);
            }
            $content = $content . '</td>';
        }
        $content = $content . '</tr>';
    }
    $content = $content . '</tbody>';
    $content = $content . '</table>';
    return $content;
}
Esempio n. 7
0
 public function validate($string, $config, $context)
 {
     $string = $this->parseCDATA($string);
     if ($string === '') {
         return false;
     }
     $parts = explode(' ', $string);
     // parseCDATA replaced \r, \t and \n
     $length = count($parts);
     $final = '';
     for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
         if (ctype_space($parts[$i])) {
             continue;
         }
         $result = $this->single->validate($parts[$i], $config, $context);
         if ($result !== false) {
             $final .= $result . ' ';
             $num++;
         }
     }
     if ($final === '') {
         return false;
     }
     return rtrim($final);
 }
Esempio n. 8
0
/**
 * Returns whether or not the $value of a given password option $key is valid.
 */
function isOptionValid($key, $value)
{
    $is_option_valid = TRUE;
    // check if letter_case function does not exist
    if ($key == "letter_case" && !function_exists($value)) {
        $is_option_valid = FALSE;
    }
    // check if min_password_length is not within range
    if ($key == "min_password_length" && (!ctype_digit($value) || $value < 8 || $value > 32)) {
        $is_option_valid = FALSE;
    }
    // check if min_words is not within range
    if ($key == "min_words" && (!ctype_digit($value) || $value < 2 || $value > 9)) {
        $is_option_valid = FALSE;
    }
    // check if num_digits is not within range
    if ($key == "num_digits" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
        $is_option_valid = FALSE;
    }
    // check if num_symbols is not within range
    if ($key == "num_symbols" && (!ctype_digit($value) || $value < 0 || $value > 3)) {
        $is_option_valid = FALSE;
    }
    // check if separator is not an empty string, whitespace or punctuation
    if ($key == "separator" && !($value === "" || ctype_space($value) || ctype_punct($value))) {
        $is_option_valid = FALSE;
    }
    return $is_option_valid;
}
function get_real_previous_sibling($node)
{
    if ($node->previousSibling && $node->previousSibling->nodeName == '#text' && ctype_space($node->previousSibling->nodeValue)) {
        return $node->previousSibling->previousSibling;
    }
    return $node->previousSibling;
}
Esempio n. 10
0
 function getTokens($string)
 {
     $tokens = array();
     $len = strlen($string);
     $current = '';
     for ($i = 0; $len > $i; ++$i) {
         $chr = $string[$i];
         $end = false;
         $extra = null;
         if (ctype_space($chr)) {
             $end = true;
         } elseif ($chr == '(' || $chr == ')') {
             $extra = $chr;
             $end = true;
         } else {
             $current .= $chr;
         }
         if ($end && 0 != strlen($current)) {
             $tokens[] = $current;
             $current = '';
         }
         if ($extra) {
             $tokens[] = $extra;
         }
     }
     if (strlen($current) != 0) {
         $tokens[] = $current;
     }
     return $tokens;
 }
Esempio n. 11
0
 /**
  * @param string $item_as_text the Node or tree in string form, ie: (NP (DT the) (JJ lazy) (NN dog))
  */
 public function __construct($item_as_text)
 {
     $this->children = [];
     $this->is_leaf = true;
     $item_as_text = trim(str_replace("\n", ' ', $item_as_text));
     $l = strlen($item_as_text) - 1;
     if ($item_as_text[0] != '(' || $item_as_text[$l] != ')') {
         throw new \Exception("Bad node format [{$item_as_text}]");
     }
     $t = substr($item_as_text, 1, $l - 1) . ' ';
     $last_stop = 0;
     $space_prev = false;
     $deep = 0;
     for ($i = 0; $i < $l; $i++) {
         $space = ctype_space($t[$i]) && $deep == 0;
         if ($space_prev && !$space) {
             $last_stop = $i;
         }
         if ($t[$i] == '(') {
             $deep++;
         } else {
             if ($t[$i] == ')') {
                 $deep--;
             } else {
                 if ($space && !$space_prev) {
                     $this->addItem(substr($t, $last_stop, $i - $last_stop));
                 }
             }
         }
         $space_prev = $space;
     }
     $this->n = array_shift($this->children);
 }
 function finalize()
 {
     // get parent's output
     parent::finalize();
     $output = parent::getOutput();
     $tex_output = '';
     foreach ($output as $token) {
         if ($this->_enumerated) {
             $class = $token[0];
             $content = $token[1];
         } else {
             $key = key($token);
             $class = $key;
             $content = $token[$key];
         }
         $iswhitespace = ctype_space($content);
         if (!$iswhitespace) {
             if ($class === 'special') {
                 $class = 'code';
             }
             $tex_output .= sprintf('\\textcolor{%s}{%s}', $class, $this->escape($content));
         } else {
             $tex_output .= $content;
         }
     }
     $this->_output = "\\begin{alltt}\n" . $tex_output . "\\end{alltt}";
 }
Esempio n. 13
0
 function tokenize($string)
 {
     $tokens = array();
     $open = false;
     $current = '';
     $length = strlen($string);
     for ($i = 0; $length > $i; ++$i) {
         $char = $string[$i];
         if ($open) {
             if ($char === self::QUOTE) {
                 $this->addToken($tokens, $current);
                 $open = false;
             } else {
                 $current .= $char;
             }
         } else {
             if ($char === self::QUOTE) {
                 $open = true;
             } elseif ($char === self::OPEN || $char === self::CLOSE) {
                 $this->addToken($tokens, $current);
                 $this->addToken($tokens, $char);
             } elseif (ctype_space($char)) {
                 $this->addToken($tokens, $current);
             } else {
                 $current .= $char;
             }
         }
     }
     $this->addToken($tokens, $current);
     return $tokens;
 }
Esempio n. 14
0
 public function validate_not_whitespace($string, $param)
 {
     $errors = array();
     if (ctype_space($string)) {
         $errors[] = $param . ' ei tule olla pelkkää whitespacea';
     }
     return $errors;
 }
 /**
  * @param array $value
  *
  */
 protected function __construct(array $value)
 {
     /** @var \AGmakonts\STL\String\String $contents */
     $contents = $value[0];
     if (TRUE === ctype_space($contents->value()) || TRUE === $contents->length()->isZero()) {
         throw new InvalidDescriptionException();
     }
 }
Esempio n. 16
0
 /**
  * @param string $class
  * @return string
  */
 public function render($class)
 {
     $content = $this->renderChildren();
     if (ctype_space($content) || $content === '') {
         return '';
     }
     return '<div class="' . htmlspecialchars($class) . '">' . $content . '</div>';
 }
Esempio n. 17
0
 /**
  * @inheritdoc
  */
 public function validate($input)
 {
     if (!is_scalar($input) || $input === '') {
         return false;
     }
     $input = str_replace(str_split($this->params['additionalChars']), '', (string) $input);
     return $input === '' || ctype_space($input);
 }
Esempio n. 18
0
/**
 * Comprehensive text/textarea/wysiwyg checker
 * Looks to see if field exists and if it's not empty space
 * @param type $field
 * @return boolean
 */
function bootsavvy_field_verification($field)
{
    $return_value = NULL;
    if ($field && !ctype_space($field) && $field !== '') {
        $return_value = true;
    }
    return $return_value;
}
 public static function isFilledString($string = '', $min_length = 0)
 {
     if ($min_length == 0) {
         return !ctype_space($string);
     }
     // end if
     return (bool) (strlen(trim($string)) > $min_length) ? TRUE : FALSE;
 }
Esempio n. 20
0
 protected function getFirstNonSpaceCharPos($string)
 {
     $length = strlen($string);
     for ($i = 0; $i < $length; $i++) {
         if (!ctype_space($string[$i])) {
             return $i;
         }
     }
 }
 public static function checkIfValidParagraph($html_string)
 {
     $allowable_tags = '<a><b><i><br><em><strong><p><h3><ul><ol><li><span><center>';
     $stripped_string = strip_tags($html_string, $allowable_tags);
     $test = $html_string == $stripped_string;
     if (ctype_space(strip_tags(html_entity_decode($html_string, ENT_HTML5, 'iso-8859-1')))) {
         return false;
     }
     return $test;
 }
Esempio n. 22
0
 public function breakLine()
 {
     if ($this->_nl) {
         $this->newParagraph();
     } elseif (isset($this->_paragraphs[$this->_pos]) && !ctype_space($this->_paragraphs[$this->_pos])) {
         // line break can only be placed in a non-empty paragraph
         $this->_nl = true;
     }
     return $this;
 }
Esempio n. 23
0
 /**
  * @param HTMLPurifier_Token $token
  */
 public function handleElement(&$token)
 {
     if (!$token instanceof HTMLPurifier_Token_Start) {
         return;
     }
     $next = false;
     $deleted = 1;
     // the current tag
     for ($i = count($this->inputZipper->back) - 1; $i >= 0; $i--, $deleted++) {
         $next = $this->inputZipper->back[$i];
         if ($next instanceof HTMLPurifier_Token_Text) {
             if ($next->is_whitespace) {
                 continue;
             }
             if ($this->removeNbsp && !isset($this->removeNbspExceptions[$token->name])) {
                 $plain = str_replace(" ", "", $next->data);
                 $isWsOrNbsp = $plain === '' || ctype_space($plain);
                 if ($isWsOrNbsp) {
                     continue;
                 }
             }
         }
         break;
     }
     if (!$next || $next instanceof HTMLPurifier_Token_End && $next->name == $token->name) {
         $this->attrValidator->validateToken($token, $this->config, $this->context);
         $token->armor['ValidateAttributes'] = true;
         if (isset($this->exclude[$token->name])) {
             $r = true;
             foreach ($this->exclude[$token->name] as $elem) {
                 if (!isset($token->attr[$elem])) {
                     $r = false;
                 }
             }
             if ($r) {
                 return;
             }
         }
         if (isset($token->attr['id']) || isset($token->attr['name'])) {
             return;
         }
         $token = $deleted + 1;
         for ($b = 0, $c = count($this->inputZipper->front); $b < $c; $b++) {
             $prev = $this->inputZipper->front[$b];
             if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) {
                 continue;
             }
             break;
         }
         // This is safe because we removed the token that triggered this.
         $this->rewindOffset($b + $deleted);
         return;
     }
 }
Esempio n. 24
0
 public function validateKey($key)
 {
     for ($i = 0; $i < strlen($key); ++$i) {
         if (ctype_cntrl($key[$i])) {
             throw new \Hoard\InvalidArgumentException("Keys cannot contain control characters.");
         }
         if (ctype_space($key[$i])) {
             throw new \Hoard\InvalidArgumentException("Keys cannot contain whitespace characters.");
         }
     }
 }
 /**
  * createTopics-funktio lähettää Topic-mallille kutsun luoda uusi keskustelu ja Message-mallille lisätä uusi viesti
  */
 public static function createTopic()
 {
     $params = $_POST;
     if ($params['title'] != null && $params['content'] != null && !ctype_space($params['title']) && !ctype_space($params['content'])) {
         $topic = Topic::createTopic($params['title'], $params['category']);
         $message = Message::createMessage($topic->id, $params['content']);
         $messages = Message::all($topic->id);
         View::make('keskustelu.html', array('topic' => $topic, 'messages' => $messages));
     }
     $categories = Category::all();
     View::make('luokeskustelu.html', array('categories' => $categories, 'error' => "Otsikko tai aloitusviestisi oli tyhjä"));
 }
Esempio n. 26
0
 /**
  * Method static validateNoEmpty check the input value is not empty
  *
  * @param string $input_value # user input value
  *
  * @return boolean $is_validate
  */
 public static function validateNoEmpty($input_value)
 {
     $validate_set = isset($input_value);
     $validate_no_empty = !empty($input_value);
     $validate_no_only_whitespace = !ctype_space($input_value);
     if ($validate_set && $validate_no_empty && $validate_no_only_whitespace) {
         return true;
     } else {
         return false;
     }
     // end if
 }
Esempio n. 27
0
 function _readTo($fp, $char)
 {
     $ch = null;
     $buf = '';
     $string = '';
     $state = '';
     while (false !== ($ch = fgetc($fp))) {
         if (!ctype_space($ch)) {
             break;
         }
     }
     do {
         /*
                     if ($state) {
                         if ($ch == '@') {
                             $ch=fgetc($fp);
                             if ($ch == '@') {
                                 $string.=$ch;
                                 continue;
                             } else {
                                 $state='';
                                 if ($char == '@') break;
                             }
                         } else {
                             $string.=$ch;
                             continue;
                         }
                     } else if( $ch == '@' ) {
                         $state = 1;
                         continue;
                     }
         //*/
         //*
         if ($ch == '@') {
             list($str, $ch) = $this->_readString($fp);
             $string .= $str;
             if ($char == '@') {
                 break;
             }
         }
         //*/
         $buf .= $ch;
         if ($ch == $char) {
             break;
         }
     } while (false !== ($ch = fgetc($fp)));
     $buf = preg_replace('/\\s+/', ' ', $buf);
     if ($buf == '') {
         $buf = null;
     }
     return array($buf, $string);
 }
Esempio n. 28
0
function myRenderDnaSequence($input, $args, $parser)
{
    if ($input == null) {
        return "";
    }
    $len = strlen($input);
    $n = 0;
    $html = "<div style='padding: 10px; font-size:10px; border-width: thin; border: 1px black solid; white-space: pre;background-color: white;font-family: courier, monospace;line-height:13px; font-size:12px;'>";
    for ($i = 0; $i < $len; $i++) {
        $c = $input[$i];
        if (ctype_space($c) || ctype_digit($c)) {
            continue;
        }
        if ($n % 60 == 0) {
            if ($n != 0) {
                $html .= "<br/>";
            }
            $html .= sprintf("%06d  ", $n + 1);
        } else {
            if ($n % 10 == 0) {
                $html .= " ";
            }
        }
        $n++;
        switch (strtolower($c)) {
            case "a":
                $html .= "<span style='color:green;'>" . $c . "</span>";
                break;
            case "c":
                $html .= "<span style='color:blue;'>" . $c . "</span>";
                break;
            case "g":
                $html .= "<span style='color:black;'>" . $c . "</span>";
                break;
            case "t":
            case "u":
                $html .= "<span style='color:red'>" . $c . "</span>";
                break;
            default:
                $html .= "<span style='text-decoration: blink;color:gray'>" . $c . "</span>";
                break;
        }
        if ($n % 60 == 0) {
            $html .= sprintf("  %06d", $n);
        }
    }
    $html .= "</div>";
    return $html;
}
Esempio n. 29
0
 public function __construct(Twig_NodeInterface $body, $lineno, $tag = null)
 {
     parent::__construct(array('body' => $body), array(), $lineno, $tag);
     // in a sandbox tag, only include tags are allowed
     if (!$this->getNode('body') instanceof Twig_Node_Include) {
         foreach ($this->getNode('body') as $node) {
             if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
                 continue;
             }
             if (!$node instanceof Twig_Node_Include) {
                 throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section', $node->getLine());
             }
         }
     }
 }
 public static function shortcode($atts, $content = null, $code)
 {
     extract(shortcode_atts(array('count' => 1, 'cat' => '', 'pagination' => false), $atts));
     $pagination = wpv_sanitize_bool($pagination);
     $query = array('post_type' => 'wpv_sermon', 'posts_per_page' => (int) $count);
     if ($pagination) {
         $query['paged'] = get_query_var('paged') > 1 ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1);
     }
     if (!empty($cat) && !ctype_space($cat[0])) {
         $query['tax_query'] = array(array('taxonomy' => 'wpv_sermons_category', 'field' => 'slug', 'terms' => explode(',', $cat)));
     }
     $query = new WP_Query($query);
     ob_start();
     include locate_template("templates/sermons/loop.php");
     return ob_get_clean();
 }