コード例 #1
0
ファイル: str_pad.php プロジェクト: azuya/Wi3
/**
 * UTF8::str_pad
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2010 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (UTF8::is_ascii($str) and UTF8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = UTF8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = UTF8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return UTF8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return UTF8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = UTF8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = UTF8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_right);
        return $pad_left . $str . $pad_right;
    }
    trigger_error('UTF8::str_pad: Unknown padding type (' . $pad_type . ')', E_USER_ERROR);
}
コード例 #2
0
ファイル: str_pad.php プロジェクト: s4urp8n/kohana-admin
/**
 * UTF8::str_pad
 *
 * @package        Kohana
 * @author         Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
    if (UTF8::is_ascii($str) and UTF8::is_ascii($pad_str)) {
        return str_pad($str, $final_str_length, $pad_str, $pad_type);
    }
    $str_length = UTF8::strlen($str);
    if ($final_str_length <= 0 or $final_str_length <= $str_length) {
        return $str;
    }
    $pad_str_length = UTF8::strlen($pad_str);
    $pad_length = $final_str_length - $str_length;
    if ($pad_type == STR_PAD_RIGHT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return UTF8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
    }
    if ($pad_type == STR_PAD_LEFT) {
        $repeat = ceil($pad_length / $pad_str_length);
        return UTF8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
    }
    if ($pad_type == STR_PAD_BOTH) {
        $pad_length /= 2;
        $pad_length_left = floor($pad_length);
        $pad_length_right = ceil($pad_length);
        $repeat_left = ceil($pad_length_left / $pad_str_length);
        $repeat_right = ceil($pad_length_right / $pad_str_length);
        $pad_left = UTF8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
        $pad_right = UTF8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_right);
        return $pad_left . $str . $pad_right;
    }
    throw new UTF8_Exception("UTF8::str_pad: Unknown padding type (:pad_type)", [':pad_type' => $pad_type]);
}
コード例 #3
0
ファイル: Ajax.php プロジェクト: HappyKennyD/teest
 public function action_ent()
 {
     $answers = Security::xss_clean(Arr::get($_POST, 'answers', ''));
     $answers = UTF8::substr($answers, 0, UTF8::strlen($answers) - 1);
     $list = explode(',', $answers);
     $total = 0;
     $right = 0;
     $points = array();
     foreach ($list as $item) {
         $total++;
         $e = explode('.', $item);
         $quest = ORM::factory('Ent_Quest', (int) $e[0]);
         if ($quest->loaded()) {
             $variant = ORM::factory('Quest_Variant')->where('quest_id', '=', $quest->id)->and_where('id', '=', (int) $e[1])->and_where('right', '=', '1')->find();
             if ($variant->loaded()) {
                 $right++;
                 $points[] = array('quest' => $quest->id, 'right' => 1);
             } else {
                 $points[] = array('quest' => $quest->id, 'right' => 0);
             }
         }
     }
     $data = array('total' => $total, 'right' => $right, 'points' => $points);
     $this->response->body(json_encode($data));
 }
コード例 #4
0
ファイル: Metadata.php プロジェクト: HappyKennyD/teest
 public function snippet($text = '')
 {
     $description = '';
     $chars = array('.', '!', '?', ':', '"');
     if (!empty($text)) {
         $text = strip_tags($text);
         $arr = explode(' ', $text);
         foreach ($arr as $k => $v) {
             if (!empty($v)) {
                 $countdescription = UTF8::strlen($description);
                 $countword = UTF8::strlen($v);
                 if ($countdescription - 1 + $countword > 140) {
                     break;
                 } else {
                     $description .= $v . ' ';
                 }
             }
         }
         $description = rtrim($description);
         if (!empty($description)) {
             $lastchar = $description[UTF8::strlen($description) - 1];
             if ($lastchar == ',') {
                 $description = UTF8::substr($description, 0, UTF8::strlen($description) - 1);
             }
             if (!in_array($lastchar, $chars)) {
                 $description .= '...';
             }
         }
     }
     $this->description = $description;
     return $this;
 }
コード例 #5
0
ファイル: modifier.shorter.php プロジェクト: Tomeno/lulcobang
/**
 * Smarty string_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     shorter<br>
 * Purpose:  shorter strings to lenght
 * @link http://smarty.php.net/manual/en/language.modifier.string.format.php
 *          string_format (Smarty online manual)
 * @author   Monte Ohrt <monte at ohrt dot com>
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_shorter($string, $lenght = 30)
{
    return UTF8::substr($string, 0, $lenght);
    if (strlen($string) > $lenght) {
        return ParseHTMLText::shortenText($string, $lenght);
    }
    return $string;
}
コード例 #6
0
/**
 * UTF8::wordwrap
 * Taken and adapted form Zend Framework by Ivan Tcholakov, 2015.
 *
 * @param       string          The input string.
 * @param       int             The number of characters at which the string will be wrapped.
 * @param       string          The line is broken using the optional break parameter.
 * @param       bool            If the cut is set to TRUE, the string is always wrapped at or before the specified width.
 * @return      string|false
 * @license     @license        http://framework.zend.com/license/new-bsd New BSD License
 */
function _wordwrap($string, $width = 75, $break = "\n", $cut = false)
{
    $string = @(string) $string;
    if ($string === '') {
        return '';
    }
    $break = @(string) $break;
    if ($break === '') {
        trigger_error('UTF8::wordwrap(): Break string cannot be empty.', E_USER_WARNING);
        return false;
    }
    $width = (int) $width;
    if ($width === 0 && $cut) {
        trigger_error('UTF8::wordwrap(): Cannot force cut when width is zero.', E_USER_WARNING);
        return false;
    }
    $string_length = UTF8::strlen($string);
    $break_length = UTF8::strlen($break);
    $result = '';
    $last_start = 0;
    $last_space = 0;
    for ($current = 0; $current < $string_length; $current++) {
        $char = UTF8::substr($string, $current, 1);
        $possible_break = $char;
        if ($break_length !== 1) {
            $possible_break = UTF8::substr($string, $current, $break_length);
        }
        if ($possible_break === $break) {
            $result .= UTF8::substr($string, $last_start, $current - $last_start + $break_length);
            $current += $break_length - 1;
            $last_start = $last_space = $current + 1;
            continue;
        }
        if ($char === ' ') {
            if ($current - $last_start >= $width) {
                $result .= UTF8::substr($string, $last_start, $current - $last_start) . $break;
                $last_start = $current + 1;
            }
            $last_space = $current;
            continue;
        }
        if ($current - $last_start >= $width && $cut && $last_start >= $last_space) {
            $result .= UTF8::substr($string, $last_start, $current - $last_start) . $break;
            $last_start = $last_space = $current;
            continue;
        }
        if ($current - $last_start >= $width && $last_start < $last_space) {
            $result .= UTF8::substr($string, $last_start, $last_space - $last_start) . $break;
            $last_start = $last_space = $last_space + 1;
            continue;
        }
    }
    if ($last_start !== $current) {
        $result .= UTF8::substr($string, $last_start, $current - $last_start);
    }
    return $result;
}
コード例 #7
0
ファイル: strpos.php プロジェクト: s4urp8n/kohana-admin
/**
 * UTF8::strpos
 *
 * @package        Kohana
 * @author         Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
        return strpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, 2);
        return isset($array[1]) ? UTF8::strlen($array[0]) : false;
    }
    $str = UTF8::substr($str, $offset);
    $pos = UTF8::strpos($str, $search);
    return $pos === false ? false : $pos + $offset;
}
コード例 #8
0
ファイル: strrpos.php プロジェクト: EhteshamMehmood/BlogMVC
/**
 * UTF8::strrpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strrpos($str, $search, $offset = 0)
{
    $offset = (int) $offset;
    if (UTF8::is_ascii($str) and UTF8::is_ascii($search)) {
        return strrpos($str, $search, $offset);
    }
    if ($offset == 0) {
        $array = explode($search, $str, -1);
        return isset($array[0]) ? UTF8::strlen(implode($search, $array)) : FALSE;
    }
    $str = UTF8::substr($str, $offset);
    $pos = UTF8::strrpos($str, $search);
    return $pos === FALSE ? FALSE : $pos + $offset;
}
コード例 #9
0
ファイル: File.php プロジェクト: eok8177/shopCMS
 /**
  * Create new filename
  *
  * @param $filename
  * @param $generate_uniq_filename
  *
  * @return string
  */
 public static function create_filename($filename, $generate_uniq_filename = false)
 {
     $path_parts = pathinfo($filename);
     if ($path_parts['extension']) {
         $path_parts['extension'] = '.' . $path_parts['extension'];
     }
     if ($generate_uniq_filename) {
         return sha1(uniqid(null, true)) . $path_parts['extension'];
     }
     $filename = Inflector::slug($path_parts['filename'], '_');
     $filename = $filename . '_' . uniqid();
     $filename = UTF8::substr($filename, 0, 250);
     return $filename . $path_parts['extension'];
 }
コード例 #10
0
ファイル: text.php プロジェクト: Normull/core
 /**
  * Limits a phrase to a given number of characters.
  *
  * @param   string   phrase to limit characters of
  * @param   integer  number of characters to limit to
  * @param   string   end character or entity
  * @param   boolean  enable or disable the preservation of words while limiting
  * @return  string
  */
 public static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
 {
     $end_char = $end_char === NULL ? '&#8230;' : $end_char;
     $limit = (int) $limit;
     if (trim($str) === '' or UTF8::strlen($str) <= $limit) {
         return $str;
     }
     if ($limit <= 0) {
         return $end_char;
     }
     if ($preserve_words == FALSE) {
         return rtrim(UTF8::substr($str, 0, $limit)) . $end_char;
     }
     preg_match('/^.{' . ($limit - 1) . '}\\S*/us', $str, $matches);
     return rtrim($matches[0]) . (strlen($matches[0]) == strlen($str) ? '' : $end_char);
 }
コード例 #11
0
ファイル: strcspn.php プロジェクト: Wildboard/WbWebApp
/**
 * UTF8::strcspn
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2012 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strcspn($str, $mask, $offset = NULL, $length = NULL)
{
    if ($str == '' or $mask == '') {
        return 0;
    }
    if (UTF8::is_ascii($str) and UTF8::is_ascii($mask)) {
        return $offset === NULL ? strcspn($str, $mask) : ($length === NULL ? strcspn($str, $mask, $offset) : strcspn($str, $mask, $offset, $length));
    }
    if ($offset !== NULL or $length !== NULL) {
        $str = UTF8::substr($str, $offset, $length);
    }
    // Escape these characters:  - [ ] . : \ ^ /
    // The . and : are escaped to prevent possible warnings about POSIX regex elements
    $mask = preg_replace('#[-[\\].:\\\\^/]#', '\\\\$0', $mask);
    preg_match('/^[^' . $mask . ']+/u', $str, $matches);
    return isset($matches[0]) ? UTF8::strlen($matches[0]) : 0;
}
コード例 #12
0
ファイル: strpos.php プロジェクト: nevermlnd/cv
/**
 * UTF8::strpos
 *
 * @package    Kohana
 * @author     Kohana Team
 * @copyright  (c) 2007-2010 Kohana Team
 * @copyright  (c) 2005 Harry Fuecks
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 */
function _strpos($str, $search, $offset = 0)
{
	$offset = (int) $offset;

	if (UTF8::is_ascii($str) AND UTF8::is_ascii($search))
		return strpos($str, $search, $offset);

	if ($offset == 0)
	{
		$array = explode($search, $str, 2);
		return isset($array[1]) ? UTF8::strlen($array[0]) : FALSE;
	}

	$str = UTF8::substr($str, $offset);
	$pos = UTF8::strpos($str, $search);
	return ($pos === FALSE) ? FALSE : ($pos + $offset);
}
コード例 #13
0
ファイル: text.php プロジェクト: jshaw86/core
 /**
  * Limits a phrase to a given number of characters.
  *
  *     $text = Text::limit_chars($text);
  *
  * @param   string   phrase to limit characters of
  * @param   integer  number of characters to limit to
  * @param   string   end character or entity
  * @param   boolean  enable or disable the preservation of words while limiting
  * @return  string
  * @uses    UTF8::strlen
  */
 public static function limit_chars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE)
 {
     $end_char = $end_char === NULL ? '…' : $end_char;
     $limit = (int) $limit;
     if (trim($str) === '' or UTF8::strlen($str) <= $limit) {
         return $str;
     }
     if ($limit <= 0) {
         return $end_char;
     }
     if ($preserve_words === FALSE) {
         return rtrim(UTF8::substr($str, 0, $limit)) . $end_char;
     }
     // Don't preserve words. The limit is considered the top limit.
     // No strings with a length longer than $limit should be returned.
     if (!preg_match('/^.{0,' . $limit . '}\\s/us', $str, $matches)) {
         return $end_char;
     }
     return rtrim($matches[0]) . (strlen($matches[0]) === strlen($str) ? '' : $end_char);
 }
コード例 #14
0
ファイル: Shezhire.php プロジェクト: HappyKennyD/teest
 public function action_zhuz()
 {
     $zhuz_type = $this->request->param('id', 'old');
     switch ($zhuz_type) {
         case 'old':
             $id = 6;
             break;
         case 'mid':
             $id = 3;
             break;
         case 'jr':
             $id = 4;
             break;
     }
     $all = ORM::factory('Zhuze')->where('parent_id', '=', $id)->order_by('name_' . strtolower(I18n::lang()))->find_all();
     $words = array();
     if (count($all) > 0) {
         $letter = 'А';
         foreach ($all as $one) {
             if (UTF8::strtoupper(UTF8::substr($one->name, 0, 1)) != $letter) {
                 $letter = UTF8::strtoupper(UTF8::substr($one->name, 0, 1));
             }
             $words[$letter][] = array('letter' => UTF8::strtoupper(UTF8::substr($one->name, 0, 1)), 'word' => $one->name, 'id' => $one->id_publication);
         }
     }
     //var_dump($words);
     $this->add_cumb(i18n::get('Шежире – древо единства казахов'), 'shezhire');
     if ($zhuz_type == 'old') {
         $this->add_cumb(i18n::get('Старший жуз'), '');
     } elseif ($zhuz_type == 'mid') {
         $this->add_cumb(i18n::get('Средний жуз'), '');
     } else {
         $this->add_cumb(i18n::get('Младший жуз'), '');
     }
     $this->set('nomer', 0);
     $this->set('zhuz', $zhuz_type);
     $this->set('words', $words);
 }
コード例 #15
0
ファイル: basic.php プロジェクト: ZerGabriel/cms-1
 /**
  * Outputs the Captcha image.
  *
  * @param boolean $html HTML output
  * @return mixed
  */
 public function render($html = TRUE)
 {
     // Creates $this->image
     $this->image_create(Captcha::$config['background']);
     // Add a random gradient
     if (empty(Captcha::$config['background'])) {
         $color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $this->image_gradient($color1, $color2);
     }
     // Add a few random lines
     for ($i = 0, $count = mt_rand(5, Captcha::$config['complexity'] * 4); $i < $count; $i++) {
         $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(100, 255), mt_rand(50, 120));
         imageline($this->image, mt_rand(0, Captcha::$config['width']), 0, mt_rand(0, Captcha::$config['width']), Captcha::$config['height'], $color);
     }
     // Calculate character font-size and spacing
     $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (UTF8::strlen($this->response) + 1);
     $spacing = (int) (Captcha::$config['width'] * 0.9 / UTF8::strlen($this->response));
     // Draw each Captcha character with varying attributes
     for ($i = 0, $strlen = UTF8::strlen($this->response); $i < $strlen; $i++) {
         // Use different fonts if available
         $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
         // Allocate random color, size and rotation attributes to text
         $color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150));
         $angle = mt_rand(-40, 20);
         // Scale the character size on image height
         $size = $default_size / 10 * mt_rand(8, 12);
         $box = imageftbbox($size, $angle, $font, UTF8::substr($this->response, $i, 1));
         // Calculate character starting coordinates
         $x = $spacing / 4 + $i * $spacing;
         $y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
         // Write text character to image
         imagefttext($this->image, $size, $angle, $x, $y, $color, $font, UTF8::substr($this->response, $i, 1));
     }
     // Output
     return $this->image_render($html);
 }
コード例 #16
0
ファイル: core.php プロジェクト: abdul-baten/hbcms
 /**
  * Helper for Kohana::dump(), handles recursion in arrays and objects.
  *
  * @param   mixed    variable to dump
  * @param   integer  maximum length of strings
  * @param   integer  recursion level (internal)
  * @return  string
  */
 protected static function _dump(&$var, $length = 128, $level = 0)
 {
     if ($var === NULL) {
         return '<small>NULL</small>';
     } elseif (is_bool($var)) {
         return '<small>bool</small> ' . ($var ? 'TRUE' : 'FALSE');
     } elseif (is_float($var)) {
         return '<small>float</small> ' . $var;
     } elseif (is_resource($var)) {
         if (($type = get_resource_type($var)) === 'stream' and $meta = stream_get_meta_data($var)) {
             $meta = stream_get_meta_data($var);
             if (isset($meta['uri'])) {
                 $file = $meta['uri'];
                 if (function_exists('stream_is_local')) {
                     // Only exists on PHP >= 5.2.4
                     if (stream_is_local($file)) {
                         $file = Kohana::debug_path($file);
                     }
                 }
                 return '<small>resource</small><span>(' . $type . ')</span> ' . htmlspecialchars($file, ENT_NOQUOTES, Kohana::$charset);
             }
         } else {
             return '<small>resource</small><span>(' . $type . ')</span>';
         }
     } elseif (is_string($var)) {
         if (UTF8::strlen($var) > $length) {
             // Encode the truncated string
             $str = htmlspecialchars(UTF8::substr($var, 0, $length), ENT_NOQUOTES, Kohana::$charset) . '&nbsp;&hellip;';
         } else {
             // Encode the string
             $str = htmlspecialchars($var, ENT_NOQUOTES, Kohana::$charset);
         }
         return '<small>string</small><span>(' . strlen($var) . ')</span> "' . $str . '"';
     } elseif (is_array($var)) {
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         static $marker;
         if ($marker === NULL) {
             // Make a unique marker
             $marker = uniqid("");
         }
         if (empty($var)) {
             // Do nothing
         } elseif (isset($var[$marker])) {
             $output[] = "(\n{$space}{$s}*RECURSION*\n{$space})";
         } elseif ($level < 5) {
             $output[] = "<span>(";
             $var[$marker] = TRUE;
             foreach ($var as $key => &$val) {
                 if ($key === $marker) {
                     continue;
                 }
                 if (!is_int($key)) {
                     $key = '"' . htmlspecialchars($key, ENT_NOQUOTES, self::$charset) . '"';
                 }
                 $output[] = "{$space}{$s}{$key} => " . Kohana::_dump($val, $length, $level + 1);
             }
             unset($var[$marker]);
             $output[] = "{$space})</span>";
         } else {
             // Depth too great
             $output[] = "(\n{$space}{$s}...\n{$space})";
         }
         return '<small>array</small><span>(' . count($var) . ')</span> ' . implode("\n", $output);
     } elseif (is_object($var)) {
         // Copy the object as an array
         $array = (array) $var;
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         $hash = spl_object_hash($var);
         // Objects that are being dumped
         static $objects = array();
         if (empty($var)) {
             // Do nothing
         } elseif (isset($objects[$hash])) {
             $output[] = "{\n{$space}{$s}*RECURSION*\n{$space}}";
         } elseif ($level < 10) {
             $output[] = "<code>{";
             $objects[$hash] = TRUE;
             foreach ($array as $key => &$val) {
                 if ($key[0] === "") {
                     // Determine if the access is protected or protected
                     $access = '<small>' . ($key[1] === '*' ? 'protected' : 'private') . '</small>';
                     // Remove the access level from the variable name
                     $key = substr($key, strrpos($key, "") + 1);
                 } else {
                     $access = '<small>public</small>';
                 }
                 $output[] = "{$space}{$s}{$access} {$key} => " . Kohana::_dump($val, $length, $level + 1);
             }
             unset($objects[$hash]);
             $output[] = "{$space}}</code>";
         } else {
             // Depth too great
             $output[] = "{\n{$space}{$s}...\n{$space}}";
         }
         return '<small>object</small> <span>' . get_class($var) . '(' . count($array) . ')</span> ' . implode("\n", $output);
     } else {
         return '<small>' . gettype($var) . '</small> ' . htmlspecialchars(print_r($var, TRUE), ENT_NOQUOTES, Kohana::$charset);
     }
 }
コード例 #17
0
ファイル: structure.php プロジェクト: bobpps/kohana-alive-cms
 /**
  * 
  * @param array $column_params
  * @param array $matching_params
  * @return boolean
  */
 private function check_column_matching_rules(array $column_params, array $matching_params)
 {
     foreach ($matching_params as $key => $value) {
         if (array_key_exists($key, $column_params)) {
             // Регулярка
             if (UTF8::substr($value, 0, 1) == '#') {
                 if (!(bool) preg_match($value, $column_params[$key])) {
                     return FALSE;
                 }
             } else {
                 if ($column_params[$key] != $value) {
                     return FALSE;
                 }
             }
         } else {
             return FALSE;
         }
     }
     return TRUE;
 }
コード例 #18
0
ファイル: form.php プロジェクト: greor/satin-spb
    echo $class;
    ?>
">
				<td><?php 
    echo $_orm->id;
    ?>
</td>
				<td>
<?php 
    echo HTML::chars($_orm->email);
    ?>
				</td>
				<td>
					<div class="list-text-preview">
<?php 
    echo UTF8::substr($_orm->text, 0, 255);
    ?>
					</div>
				</td>
				<td>
<?php 
    if ($_orm->created != '0000-00-00 00:00:00') {
        echo $_orm->created;
    }
    ?>
				</td>
				<td>
<?php 
    echo '<div class="btn-group">';
    echo HTML::anchor(str_replace('{id}', $_orm->id, $view_tpl), '<i class="icon-file"></i> ' . __('View'), array('class' => 'btn', 'title' => __('View')));
    if ($_orm->new) {
コード例 #19
0
 private function _bigram_exists($word, $lang)
 {
     $word = $lang === 'en' ? strtolower($word) : UTF8::lowercase($word);
     #шаг 0.
     #проверяем слова в списке слов-исключений
     if (array_key_exists($word, $this->words_exceptions[$lang])) {
         return false;
     }
     #шаг 1.
     #проверка на 4 согласные буквы подряд; пример: больши{нств}о, юрисконсу{льтс}тво
     if (preg_match('/(?:' . $this->consonant_lc[$lang] . '){4}/sxSX', $word, $m) && !array_key_exists($m[0], $this->consonants4_lc[$lang])) {
         return true;
     }
     #шаг 2.
     #проверка на 3 гласные буквы подряд; пример: длиннош{еее}, зм{еео}бразный
     if (preg_match('/(?:' . $this->vowel_lc[$lang] . '){3}/sxSX', $word, $m) && !array_key_exists($m[0], $this->vowels3_lc[$lang])) {
         return true;
     }
     #шаг 3.
     $length = UTF8::strlen($word);
     for ($pos = 0, $limit = $length - 1; $pos < $limit; $pos++) {
         /*
                     TODO  Качество проверки по несуществующим биграммам можно немного повысить,
                     если учитывать не только начало и конец слова, но и все позиции биграмм в слове.
         */
         $ss = UTF8::substr($word, $pos, 2);
         if ($pos === 0) {
             $ss = ' ' . $ss;
         } elseif ($pos === $limit - 1) {
             $ss = $ss . ' ';
         }
         #ending of word
         if (array_key_exists($ss, $this->bigrams)) {
             return true;
         }
     }
     return false;
 }
コード例 #20
0
ファイル: Mango.php プロジェクト: tscms/mangodb
 /**
  * Formats a value into correct a valid value for the specific field
  *
  * @param   string  field name
  * @param   mixed   field value
  * @param   boolean is value clean (from Db)
  * @return  mixed   formatted value
  */
 protected function load_field($name, $value, $clean = FALSE)
 {
     // Load field data
     $field = $this->_fields[$name];
     if (!$clean) {
         // Apply filters
         $value = $this->run_filters($name, $value);
         // Empty string
         if (is_string($value) && $value === '') {
             $value = NULL;
         }
     }
     if ($value !== NULL || $clean === TRUE) {
         switch ($field['type']) {
             case 'MongoId':
                 if ($value !== NULL and !$value instanceof MongoId) {
                     $value = new MongoId($value);
                 }
                 break;
             case 'date':
                 if (!$value instanceof MongoDate) {
                     $value = new MongoDate(is_int($value) ? $value : strtotime($value));
                 }
                 break;
             case 'enum':
                 if ($clean) {
                     $value = isset($field['values'][$value]) ? $value : NULL;
                 } else {
                     $value = ($key = array_search($value, $field['values'])) !== FALSE ? $key : NULL;
                 }
                 break;
             case 'int':
                 if ((double) $value > PHP_INT_MAX) {
                     // This number cannot be represented by a PHP integer, so we convert it to a float
                     $value = (double) $value;
                 } else {
                     $value = (int) $value;
                 }
                 break;
             case 'float':
                 $value = (double) $value;
                 break;
             case 'timestamp':
                 if (!is_int($value)) {
                     $value = ctype_digit($value) ? (int) $value : strtotime($value);
                 }
                 break;
             case 'boolean':
                 $value = (bool) $value;
                 break;
             case 'email':
                 if (!$clean) {
                     $value = strtolower(trim((string) $value));
                 }
                 break;
             case 'string':
                 $value = trim((string) $value);
                 if (!$clean && strlen($value)) {
                     $max_size = Arr::get($field, 'max_size', Mango::MAX_SIZE_STRING);
                     if (UTF8::strlen($value) > $max_size) {
                         $value = UTF8::substr($value, 0, $max_size);
                     }
                     if (Arr::get($field, 'xss_clean') && !empty($value)) {
                         $value = Security::xss_clean($value);
                     }
                 }
                 break;
             case 'has_one':
                 if (is_array($value)) {
                     $value = Mango::factory($field['model'], $value, $clean ? Mango::CLEAN : Mango::CHANGE);
                 }
                 if (!$value instanceof Mango) {
                     $value = NULL;
                 } else {
                     $value->set_parent($this);
                 }
                 break;
             case 'has_many':
                 $value = new Mango_Set($value, $field['model'], Arr::get($field, 'duplicates', FALSE), $clean);
                 foreach ($value as $model) {
                     $model->set_parent($this);
                 }
                 break;
             case 'counter':
                 $value = new Mango_Counter($value);
                 break;
             case 'array':
                 $value = new Mango_Array($value, Arr::get($field, 'type_hint'), $clean);
                 break;
             case 'set':
                 $value = new Mango_Set($value, Arr::get($field, 'type_hint'), Arr::get($field, 'duplicates', TRUE), $clean);
                 break;
             case 'mixed':
                 $value = !is_object($value) ? $value : NULL;
                 break;
         }
         if (!$clean && is_string($value) && $value === '') {
             $value = NULL;
         }
     }
     return $value;
 }
コード例 #21
0
 private function Load()
 {
     $buf = "";
     $buf .= "/******************************************************************************\n";
     $buf .= "* Class for " . $this->table . "." . $this->table_descriptor->getTable() . "\n";
     $buf .= "*******************************************************************************/\n\n";
     $table_name = UTF8::strtoupper(UTF8::substr($this->table_descriptor->getTable(), 0, 1)) . UTF8::substr($this->table_descriptor->getTable(), 1, UTF8::strlen($this->table_descriptor->getTable()) - 1);
     $buf .= "class Entity_{$table_name}\n{\n";
     foreach ($this->table_descriptor->getColumns() as $column) {
         $column_name = str_replace('-', '_', $column['column_name']);
         $buf .= "\t/**\n";
         $buf .= "\t* @var {$this->variable_types[$column['type']]}\n";
         if ($column['column_name'] == $this->table_descriptor->getPrimaryKey()) {
             $buf .= "\t* Class Unique ID\n";
         }
         //$buf .= "\t* Class Unique ID\n";
         $buf .= "\t* comment\t\"" . $column['comment'] . "\"\n";
         $buf .= "\t*/\n";
         $buf .= "\tpublic \${$column_name};\n\n";
         //      if ( UTF8::strpos($column['column_name'], '_id') !=FALSE )
         //      {
         //        $related_table_name=UTF8::substr($column['column_name'], 0, UTF8::strlen($column['column_name'])-3)."_list";
         //        $buf .= "\t/**\n";
         //        $buf .= "\t* comment\t\"".$column['comment']."\"\n";
         //        $buf .= "\t*/\n";
         //        $buf .= "\tprivate $related_table_name=array()\n\n";
         //
         //        $buf .= "\tpublic function get_$related_table_name())\n";
         //        $buf .= "\t{\n";
         //        $buf .= "\t\t return \$this->$related_table_name\n";
         //        $buf .= "\t}\n\n";
         //
         //        $buf .= "\tpublic function set_$related_table_name(\$$related_table_name))\n";
         //        $buf .= "\t{\n";
         //        $buf .= "\t\t \$this->$related_table_name=\$$related_table_name\n";
         //        $buf .= "\t}\n\n";
         //      }
     }
     $relations = Kohana::config('cb_relations.relations');
     foreach ($relations as $relation) {
         $child_table_name = $relation['child_table'];
         if ($relation['parent_table'] == $this->table_descriptor->getTable()) {
             $buf .= "\t/**\n";
             $buf .= "\t* object related to table \t\"" . $child_table_name . "\"\n";
             $buf .= "\t*/\n";
             $buf .= "\tprivate \${$child_table_name}=array();\n\n";
             $buf .= "\tpublic function get_{$child_table_name}(\$filter=NULL)\n";
             $buf .= "\t{\n";
             $buf .= "\t\t if ( \$filter != NULL AND count(\$this->{$child_table_name})>0 ) return {$child_table_name};\n";
             $buf .= "\t\t \$sql=\"select id from {$child_table_name}\";\n";
             $buf .= "\t\t\t\$first_filter=TRUE;\n";
             $buf .= "\t\t\tif ( \$filter != NULL )\n";
             $buf .= "\t\t\t{\n";
             $buf .= "\t\t\t\tforeach (array_keys(\$filter) as \$key)\n";
             $buf .= "\t\t\t\t{\n";
             $buf .= "\t\t\t\tif ( ! empty( \$filter[\$key] ) )\n";
             $buf .= "\t\t\t\t{\n";
             $buf .= "\t\t\t\t\tif ( \$first_filter == TRUE )\n";
             $buf .= "\t\t\t\t\t{\n";
             $buf .= "\t\t\t\t\t\t\$sql .= ' where '.\$key.' '.\$filter[\$key];\n";
             $buf .= "\t\t\t\t\t\t\$first_filter = false;\n";
             $buf .= "\t\t\t\t\t}else\n";
             $buf .= "\t\t\t\t\t{\n";
             $buf .= "\t\t\t\t\t\t\$sql .= ' AND '.\$key.' '.\$filter[\$key];\n";
             $buf .= "\t\t\t\t\t}\n";
             $buf .= "\t\t\t\t}\n";
             $buf .= "\t\t\t\t}\n";
             $buf .= "\t\t\t}\n\n";
             $buf .= "\t\t\$result = Database::instance()->query(Database::SELECT, \$sql, FALSE);\n";
             $buf .= "\t\tforeach (\$result as \${$child_table_name})\n";
             $buf .= "\t\t{\n";
             $buf .= "\t\t\t\$this->{$child_table_name}" . '[]' . " = new Entity_{$table_name}(\$" . $child_table_name . "['id']);\n";
             $buf .= "\t\t}\n";
             $buf .= "\t\treturn \$this->{$child_table_name};\n";
             $buf .= "\t}\n\n";
             $buf .= "\tpublic function set_{$child_table_name}(\${$child_table_name})\n";
             $buf .= "\t{\n";
             $buf .= "\t\t \$this->{$child_table_name}=\${$child_table_name};\n";
             $buf .= "\t}\n\n";
         }
     }
     //правила проверки модели
     $rules = array();
     foreach ($this->table_descriptor->getColumns() as $column) {
         $column_rule = array();
         if ($column['column_name'] != $this->table_descriptor->getPrimaryKey()) {
             $column_rule['type'] = $column['type'];
             $column_rule['is_nullable'] = $column['is_nullable'];
             if ($column['type'] == 'string') {
                 $column_rule['character_maximum_length'] = $column['character_maximum_length'];
             }
             $rules[$column['column_name']] = $column_rule;
         }
     }
     $buf .= "\t/**\n";
     $buf .= "\t*\tПравила для проверки модели\n";
     $buf .= "\t*/\n";
     $buf .= "\tpublic \$rules=array(\n";
     foreach ($rules as $name => $rule) {
         $buf .= "\t\t'" . $name . "'=>array(";
         foreach ($rule as $rkey => $rvalue) {
             $buf .= "'{$rkey}'=>'{$rvalue}'" . ",";
         }
         $buf .= "),\n";
     }
     $buf .= "\t);\n\n";
     if ($this->table_descriptor->getPrimaryKey() != '') {
         $pk = $this->table_descriptor->getPrimaryKey();
         $buf .= "\tpublic function __construct(\${$pk}='')\n";
         $buf .= "\t{\n";
         $buf .= "\t\t\$this->{$pk}=\${$pk};\n";
         $buf .= "\t\t\$this->Load();\n";
         $buf .= "\t}\n\n";
         $buf .= "\tprivate function Load()\n";
         $buf .= "\t{\n";
         $buf .= "\t\t if (\$this->{$pk} =='') return FALSE;\n";
         $buf .= "\t\t\$query = \"SELECT * FROM " . $this->table_descriptor->getTable() . " WHERE `{$pk}`='{\$this->{$pk}}'\";\n\n";
         $buf .= "\t\t\$result=Database::instance()->query(Database::SELECT, \$query, FALSE);\n";
         $buf .= "\t\tforeach(\$result as \$row )\n";
         $buf .= "\t\t\tforeach(\$row as \$key => \$value)\n";
         $buf .= "\t\t\t{\n";
         $buf .= "\t\t\t\t\$column_name = str_replace('-','_',\$key);\n";
         $buf .= "\t\t\t\t\$this->\${$column_name}=\$value;\n\n";
         $buf .= "\t\t\t}\n";
         $buf .= "\t}\n\n";
         $update_columns = "";
         foreach ($this->table_descriptor->getColumns() as $column) {
             if ($column['column_name'] != $this->table_descriptor->getPrimaryKey()) {
                 $column_name = str_replace('-', '_', $column['column_name']);
                 $update_columns .= "\n\t\t\t\t\t\t`{$column['column_name']}` = '\" . DB::expr(\$this->get{$column_name}(),\$dblink) . \"',";
             }
         }
         $update_columns = rtrim($update_columns, ',');
         $buf .= "\tpublic function Save()\n";
         $buf .= "\t{\n";
         $buf .= "\t\t\$dblink = null;\n\n";
         $buf .= "\t\t\$query = \"UPDATE " . $this->table_descriptor->getTable() . " SET {$update_columns} \n\t\t\t\t\t\tWHERE `{$pk}`='{\$this->get{$pk}()}'\";\n\n";
         $buf .= "\t\t\$result=Database::instance()->query(Database::UPDATE , \$query, FALSE);\n";
         $buf .= "\t\treturn \$result;";
         $buf .= "\t}\n\n";
     }
     $insert_columns = "";
     $insert_values = "";
     foreach ($this->table_descriptor->getColumns() as $column) {
         if ($column['column_name'] != $this->table_descriptor->getPrimaryKey()) {
             $column_name = str_replace('-', '_', $column['column_name']);
             $insert_columns .= "`{$column['column_name']}`,";
             $insert_values .= "'\" . DB::expr(\$this->get{$column_name}(),\$dblink) . \"',";
         }
     }
     $insert_columns = rtrim($insert_columns, ',');
     $insert_values = rtrim($insert_values, ',');
     $buf .= "\tpublic function Create()\n";
     $buf .= "\t{\n";
     //$buf .= "\t\t\$dblink = null;\n\n";
     $buf .= "\t\t\$query =\"INSERT INTO {$this->table_descriptor->getTable()} ({$insert_columns}) VALUES ({$insert_values});\";\n";
     $buf .= "\t\t\$result=Database::instance()->query(Database::INSERT, \$query, FALSE);\n";
     $buf .= "\t\t return \$result;";
     $buf .= "\t}\n\n";
     //validate
     $buf .= "\tpublic function Validate()\n";
     $buf .= "\t{\n";
     $buf .= "\t\t return validate_model(\$this->rules,\$this);\n";
     $buf .= "\t}\n\n";
     $buf .= "} // END class {$this->table_descriptor->getTable()}\n\n";
     $this->buffer = $buf;
 }
コード例 #22
0
ファイル: lib-utf8.php プロジェクト: hatone/zenphoto-1.4.1.4
 /**
  * Get truncated string with specified width
  * Compatible with mb_strimwidth()
  */
 function strimwidth($str, $start, $width, $trimmarker = '')
 {
     $str = UTF8::substr($str, $start);
     $width = $width - UTF8::strwidth($trimmarker);
     for ($i = 0; $i < strlen($str); $i++) {
         $b1 = (int) ord($str[$i]);
         if ($b1 < 0x80 || $b1 > 0xbf) {
             $c++;
             if ($b1 > 0xe2) {
                 $b2 = (int) ord($str[$i + 1]);
                 $b3 = (int) ord($str[$i + 2]);
                 if ($b2 == 0xbd && $b3 >= 0xa1 || $b2 == 0xbe && $b3 <= 0x9f) {
                     $count++;
                 } else {
                     $count = $count + 2;
                 }
             } else {
                 $count++;
             }
         }
         if ($count > $width) {
             return UTF8::substr($str, 0, $c - 1) . $trimmarker;
         }
     }
 }
コード例 #23
0
ファイル: debug.php プロジェクト: MenZil-Team/cms
 /**
  * Helper for Debug::dump(), handles recursion in arrays and objects.
  *
  * @param   mixed    $var     Variable to dump
  * @param   integer  $length  Maximum length of strings [Optional]
  * @param   integer  $limit   Recursion limit [Optional]
  * @param   integer  $level   Current recursion level (internal usage only!) [Optional]
  *
  * @return  string
  */
 protected static function _dump(&$var, $length = 128, $limit = 10, $level = 0)
 {
     if ($var === NULL) {
         return '<small style="color: #3465a4">NULL</small>';
     } elseif (is_bool($var)) {
         return '<small>bool</small> <span style="color:#4e9a06">' . ($var ? 'TRUE' : 'FALSE') . '</span>';
     } elseif (is_float($var)) {
         return '<small>float</small> <span style="color:#4e9a06">' . $var . '</span>';
     } elseif (is_integer($var)) {
         return '<small>int</small> <span style="color:#4e9a06">' . $var . '</span>';
     } elseif (is_resource($var)) {
         if (($type = get_resource_type($var)) === 'stream' and $meta = stream_get_meta_data($var)) {
             $meta = stream_get_meta_data($var);
             if (isset($meta['uri'])) {
                 $file = $meta['uri'];
                 if (stream_is_local($file)) {
                     $file = Debug::path($file);
                 }
                 return '<small>resource</small><span>(' . $type . ')</span> ' . htmlspecialchars($file, ENT_NOQUOTES, Kohana::$charset);
             }
         } else {
             return '<small>resource</small><span>(' . $type . ')</span>';
         }
     } elseif (is_string($var)) {
         // Clean invalid multibyte characters. iconv is only invoked
         // if there are non ASCII characters in the string, so this
         // isn't too much of a hit.
         $var = UTF8::clean($var, Kohana::$charset);
         if (UTF8::strlen($var) > $length) {
             // Encode the truncated string
             $str = htmlspecialchars(UTF8::substr($var, 0, $length), ENT_NOQUOTES, Kohana::$charset) . '&nbsp;&hellip;';
         } else {
             // Encode the string
             $str = htmlspecialchars($var, ENT_NOQUOTES, Kohana::$charset);
         }
         return '<small>string</small> <span style="color:#cc0000">\'' . $str . '\'</span>(<span style="font-style:italic">length=' . strlen($var) . '</span>)';
     } elseif (is_array($var)) {
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         static $marker;
         if ($marker === NULL) {
             // Make a unique marker
             $marker = uniqid("");
         }
         if (empty($var)) {
             // Do nothing
         } elseif (isset($var[$marker])) {
             $output[] = "\n{$space}{$s}*RECURSION*\n{$space}";
         } elseif ($level < $limit) {
             $output[] = "<span>";
             $var[$marker] = TRUE;
             foreach ($var as $key => &$val) {
                 if ($key === $marker) {
                     continue;
                 }
                 if (!is_int($key)) {
                     $key = '"' . htmlspecialchars($key, ENT_NOQUOTES, Kohana::$charset) . '"';
                 }
                 $output[] = "{$space}{$s}{$key} => " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($var[$marker]);
             $output[] = "{$space}</span>";
         } else {
             // Depth too great
             $output[] = "\n{$space}{$s}...\n{$space}";
         }
         return '<strong>array</strong> <span style="font-style:italic">(size=' . count($var) . ')</span> ' . implode(PHP_EOL, $output);
     } elseif (is_object($var)) {
         // Copy the object as an array
         $array = (array) $var;
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         $hash = spl_object_hash($var);
         // Objects that are being dumped
         static $objects = array();
         if (empty($var)) {
             // Do nothing
         } elseif (isset($objects[$hash])) {
             $output[] = "{\n{$space}{$s}*RECURSION*\n{$space}}";
         } elseif ($level < $limit) {
             $output[] = "<code>";
             $objects[$hash] = TRUE;
             foreach ($array as $key => &$val) {
                 if ($key[0] === "") {
                     // Determine if the access is protected or protected
                     $access = '<span style="font-style:italic">' . ($key[1] === '*' ? 'protected' : 'private') . '</span>';
                     // Remove the access level from the variable name
                     $key = substr($key, strrpos($key, "") + 1);
                 } else {
                     $access = '<span style="font-style:italic">public</span>';
                 }
                 $output[] = "{$space}{$s}{$access} '{$key}' <span style='color:#888a85'>=&gt;</span> " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($objects[$hash]);
             $output[] = "{$space}</code>";
         } else {
             // Depth too great
             $output[] = "{\n{$space}{$s}...\n{$space}}";
         }
         return '<strong>object</strong>(<span style="font-style:italic">' . get_class($var) . '</span>)' . '[<span style="font-style:italic">' . count($array) . '</span>]' . implode(PHP_EOL, $output);
     } else {
         return '<small>' . gettype($var) . '</small> ' . htmlspecialchars(print_r($var, TRUE), ENT_NOQUOTES, Kohana::$charset);
     }
 }
コード例 #24
0
 /**
  * Ellipsize String (UTF-8 compatible version)
  *
  * This function will strip tags from a string, split it at its max_length and ellipsize
  *
  * @param   string      string to ellipsize
  * @param   int         max length of string
  * @param   mixed       int (1|0) or float, .5, .2, etc for position to split
  * @param   string      ellipsis ; Default '...'
  * @return  string      ellipsized string
  */
 function ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
 {
     // Strip tags
     $str = trim(strip_tags($str));
     // Added by Ivan Tcholakov, 07-JAN-2014.
     $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
     //
     // Is the string long enough to ellipsize?
     if (UTF8::strlen($str) <= $max_length) {
         return $str;
     }
     $beg = UTF8::substr($str, 0, floor($max_length * $position));
     $position = $position > 1 ? 1 : $position;
     if ($position === 1) {
         $end = UTF8::substr($str, 0, -($max_length - UTF8::strlen($beg)));
     } else {
         $end = UTF8::substr($str, -($max_length - UTF8::strlen($beg)));
     }
     return $beg . $ellipsis . $end;
 }
コード例 #25
0
ファイル: Library.php プロジェクト: HappyKennyD/teest
 public function action_editbook()
 {
     //die('lol');
     $id = (int) $this->request->param('id', 0);
     $book = ORM::factory('Book', $id);
     $selected = (int) Arr::get($_GET, 'category', 0);
     $this->set('selected', $selected);
     $this->set('book', $book);
     $cats = ORM::factory('Library_Category')->fulltree;
     $this->set('cats', $cats);
     $uploader = View::factory('storage/pdf')->set('user_id', $this->user->id)->render();
     $this->set('uploader', $uploader);
     $pdf = $book->pdf;
     if ($pdf->loaded()) {
         $this->set('pdf', $pdf);
     } else {
         $this->set('pdf', FALSE);
     }
     if ($this->request->method() == 'POST') {
         $type = Security::xss_clean(Arr::get($_POST, 'type', ''));
         $language = Security::xss_clean(Arr::get($_POST, 'language', ''));
         $subject = Security::xss_clean(Arr::get($_POST, 'subject', ''));
         $class = Security::xss_clean(Arr::get($_POST, 'class', ''));
         $title = Security::xss_clean(Arr::get($_POST, 'title', ''));
         $storage_id = (int) Arr::get($_POST, 'storage_id', 0);
         $cover_id = (int) Arr::get($_POST, 'cover_id', 0);
         $description = Security::xss_clean(Arr::get($_POST, 'description', ''));
         $category_id = (int) Arr::get($_POST, 'category_id', 0);
         $published = (int) Arr::get($_POST, 'published', 0);
         $letter = UTF8::strtoupper(UTF8::substr($title, 0, 1));
         $author = Security::xss_clean(Arr::get($_POST, 'author', ''));
         $publisher = Security::xss_clean(Arr::get($_POST, 'publisher', ''));
         $year = (int) Arr::get($_POST, 'year', 0);
         $RandomNum = time();
         $i = 0;
         // $post = $this->request->post();
         // $post['date'] = date('Y-m-d H:i:s',strtotime($post['date']));
         //$date =  $post['date'];
         $message = "";
         try {
             $book->file_path = $RandomNum;
             $book->kol = $i;
             $book->type = $type;
             $book->language = $language;
             $book->subject = $subject;
             $book->class = $class;
             $book->title = $title;
             $book->storage_id = $storage_id;
             $book->cover_id = $cover_id;
             $book->description = $description;
             $book->category_id = $category_id;
             $book->published = $published;
             $book->author = $author;
             $book->year = $year;
             $book->publisher = $publisher;
             $book->letter = $letter;
             $book->save();
             if ($_FILES) {
                 $output_dir = "media/upload/" . $RandomNum . "/";
                 mkdir($output_dir, 0777);
                 if (isset($_FILES["myfile"])) {
                     $ImageName = str_replace(' ', '-', strtolower($_FILES['myfile']['name']));
                     $ImageType = $_FILES['myfile']['type'];
                     //"image/png", image/jpeg etc.
                     $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
                     $ImageExt = str_replace('.', '', $ImageExt);
                     if ($ImageExt != "pdf") {
                         $message = "Invalid file format only <b>\"PDF\"</b> allowed.";
                     } else {
                         $ImageName = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $ImageName);
                         $NewImageName = $RandomNum . '.' . $ImageExt;
                         move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $NewImageName);
                         $location = "convert -density 200";
                         $name = $output_dir . $NewImageName;
                         $pdftext = file_get_contents($name);
                         $num = preg_match_all("/\\/Page\\W/", $pdftext, $dummy);
                         for ($i = 0; $i < $num; ++$i) {
                             $nameto = $output_dir . $RandomNum . "-" . $i . ".png";
                             $convert = $location . " " . $name . "[" . $i . "]" . " " . "-append -resize 850" . $nameto;
                             exec($convert);
                         }
                         $dir = opendir($output_dir);
                         $i = 0;
                         while (false !== ($file = readdir($dir))) {
                             if (strpos($file, '.png', 1)) {
                                 $i++;
                             }
                         }
                     }
                 }
             }
             $event = $id ? 'edit' : 'create';
             $loger = new Loger($event, $book->title);
             $loger->log($book);
             $this->set('RandomNum', $RandomNum);
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors($e->alias());
             $this->set('errors', $errors);
         }
     }
 }
コード例 #26
0
ファイル: Debug.php プロジェクト: braf/phalcana-core
 /**
  * Helper for Debug::dump(), handles recursion in arrays and objects.
  *
  * @param   mixed   $var    variable to dump
  * @param   integer $length maximum length of strings
  * @param   integer $limit  recursion limit
  * @param   integer $level  current recursion level (internal usage only!)
  * @return  string
  */
 protected static function _dump(&$var, $length = 128, $limit = 10, $level = 0)
 {
     if ($var === null) {
         return '<small>null</small>';
     } elseif (is_int($var)) {
         return '<small>integer</small> <span class="int">' . $var . '</span>';
     } elseif (is_bool($var)) {
         return '<small>bool</small> <span class="bool">' . ($var ? 'true' : 'false') . '</span>';
     } elseif (is_float($var)) {
         return '<small>float</small> <span class="float">' . $var . '</span>';
     } elseif (is_resource($var)) {
         if (($type = get_resource_type($var)) === 'stream' && ($meta = stream_get_meta_data($var))) {
             $meta = stream_get_meta_data($var);
             if (isset($meta['uri'])) {
                 $file = $meta['uri'];
                 // Only exists on PHP >= 5.2.4
                 if (stream_is_local($file)) {
                     $file = Debug::path($file);
                 }
                 return '<small>resource</small><span>(' . $type . ')</span> ' . htmlspecialchars($file, ENT_NOQUOTES, \Phalcana\Phalcana::$charset);
             }
         } else {
             return '<small>resource</small><span>(' . $type . ')</span>';
         }
     } elseif (is_string($var)) {
         // Clean invalid multibyte characters. iconv is only invoked
         // if there are non ASCII characters in the string, so this
         // isn't too much of a hit.
         $var = UTF8::clean($var, \Phalcana\Phalcana::$charset);
         if (UTF8::strlen($var) > $length) {
             // Encode the truncated string
             $str = htmlspecialchars(UTF8::substr($var, 0, $length), ENT_NOQUOTES, \Phalcana\Phalcana::$charset) . '&nbsp;&hellip;';
             //$str = htmlspecialchars(substr($var, 0, $length), ENT_NOQUOTES, \Phalcana\Phalcana::$charset).'&nbsp;&hellip;';
         } else {
             // Encode the string
             $str = htmlspecialchars($var, ENT_NOQUOTES, \Phalcana\Phalcana::$charset);
         }
         return '<small>string</small><span class="len">(' . strlen($var) . ')</span> <span class="string">"' . $str . '"</span>';
     } elseif (is_array($var)) {
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         static $marker;
         if ($marker === null) {
             // Make a unique marker - force it to be alphanumeric so that it is always treated as a string array key
             $marker = uniqid("") . "x";
         }
         if (empty($var)) {
             // Do nothing
         } elseif (isset($var[$marker])) {
             $output[] = "(\n{$space}{$s}*RECURSION*\n{$space})";
         } elseif ($level < $limit) {
             $output[] = "<span>(";
             $var[$marker] = true;
             foreach ($var as $key => &$val) {
                 if ($key === $marker) {
                     continue;
                 }
                 if (!is_int($key)) {
                     $key = '<span class="string">"' . htmlspecialchars($key, ENT_NOQUOTES, \Phalcana\Phalcana::$charset) . '"</span>';
                 } else {
                     $key = '<span class="int">' . $key . '</span>';
                 }
                 $output[] = "{$space}{$s}{$key} <span class=\"pointer\">=></span> " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($var[$marker]);
             $output[] = "{$space})</span>";
         } else {
             // Depth too great
             $output[] = "(\n{$space}{$s}...\n{$space})";
         }
         return '<small>array</small><span class="len">(' . count($var) . ')</span> ' . implode("\n", $output);
     } elseif (is_object($var)) {
         // Copy the object as an array
         $array = (array) $var;
         $output = array();
         // Indentation for this variable
         $space = str_repeat($s = '    ', $level);
         $hash = spl_object_hash($var);
         // Objects that are being dumped
         static $objects = array();
         if (empty($var)) {
             // Do nothing
         } elseif ($var instanceof \Phalcon\DI) {
             $output[] = "{\n{$space}{$s}*DEPENDENCY INJECTOR IGNORED*\n{$space}}";
         } elseif (isset($objects[$hash])) {
             $output[] = "{\n{$space}{$s}*RECURSION*\n{$space}}";
         } elseif ($level < $limit) {
             $output[] = "<code>{";
             $objects[$hash] = true;
             foreach ($array as $key => &$val) {
                 if ($key[0] === "") {
                     // Determine if the access is protected or protected
                     $access = '<small>' . ($key[1] === '*' ? 'protected' : 'private') . '</small>';
                     // Remove the access level from the variable name
                     $key = substr($key, strrpos($key, "") + 1);
                 } else {
                     $access = '<small>public</small>';
                 }
                 $output[] = "{$space}{$s}{$access} {$key} <span class=\"pointer\">=></span> " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($objects[$hash]);
             $output[] = "{$space}}</code>";
         } else {
             // Depth too great
             $output[] = "{\n{$space}{$s}...\n{$space}}";
         }
         return '<small>object</small> <span>' . get_class($var) . '(' . count($array) . ')</span> ' . implode("\n", $output);
     } else {
         return '<small>' . gettype($var) . '</small> ' . htmlspecialchars(print_r($var, true), ENT_NOQUOTES, \Phalcana\Phalcana::$charset);
     }
 }
コード例 #27
0
 protected static function _dump(&$var, $length = 128, $limit = 10, $level = 0)
 {
     if ($var === NULL) {
         return "<small>NULL</small>";
     } elseif (is_bool($var)) {
         return "<small>bool</small> " . ($var ? "TRUE" : "FALSE");
     } elseif (is_float($var)) {
         return "<small>float</small> " . $var;
     } elseif (is_resource($var)) {
         if (($type = get_resource_type($var)) === "stream" and $meta = stream_get_meta_data($var)) {
             $meta = stream_get_meta_data($var);
             if (isset($meta["uri"])) {
                 $file = $meta["uri"];
                 if (function_exists("stream_is_local")) {
                     // Only exists on PHP >= 5.2.4
                     if (stream_is_local($file)) {
                         $file = Debug::path($file);
                     }
                 }
                 return "<small>resource</small><span>(" . $type . ")</span> " . htmlspecialchars($file, ENT_NOQUOTES, JsonApiApplication::$charset);
             }
         } else {
             return "<small>resource</small><span>(" . $type . ")</span>";
         }
     } elseif (is_string($var)) {
         $var = UTF8::clean($var, JsonApiApplication::$charset);
         if (UTF8::strlen($var) > $length) {
             $str = htmlspecialchars(UTF8::substr($var, 0, $length), ENT_NOQUOTES, JsonApiApplication::$charset) . "&nbsp;&hellip;";
         } else {
             $str = htmlspecialchars($var, ENT_NOQUOTES, JsonApiApplication::$charset);
         }
         return '<small>string</small><span>(' . strlen($var) . ')</span> "' . $str . '"';
     } elseif (is_array($var)) {
         $output = array();
         $space = str_repeat($s = "    ", $level);
         static $marker;
         if ($marker === NULL) {
             $marker = uniqid("") . "x";
         }
         if (empty($var)) {
             // Do nothing
         } elseif (isset($var[$marker])) {
             $output[] = "(\n{$space}{$s}*RECURSION*\n{$space})";
         } elseif ($level < $limit) {
             $output[] = "<span>(";
             $var[$marker] = TRUE;
             foreach ($var as $key => &$val) {
                 if ($key === $marker) {
                     continue;
                 }
                 if (!is_int($key)) {
                     $key = '"' . htmlspecialchars($key, ENT_NOQUOTES, JsonApiApplication::$charset) . '"';
                 }
                 $output[] = "{$space}{$s}{$key} => " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($var[$marker]);
             $output[] = "{$space})</span>";
         } else {
             $output[] = "(\n{$space}{$s}...\n{$space})";
         }
         return "<small>array</small><span>(" . count($var) . ")</span> " . implode("\n", $output);
     } elseif (is_object($var)) {
         $array = (array) $var;
         $output = array();
         $space = str_repeat($s = "    ", $level);
         $hash = spl_object_hash($var);
         static $objects = array();
         if (empty($var)) {
             // Do nothing
         } elseif (isset($objects[$hash])) {
             $output[] = "{\n{$space}{$s}*RECURSION*\n{$space}}";
         } elseif ($level < $limit) {
             $output[] = "<code>{";
             $objects[$hash] = TRUE;
             foreach ($array as $key => &$val) {
                 if ($key[0] === "") {
                     $access = "<small>" . ($key[1] === "*" ? "protected" : "private") . "</small>";
                     $key = substr($key, strrpos($key, "") + 1);
                 } else {
                     $access = "<small>public</small>";
                 }
                 $output[] = "{$space}{$s}{$access} {$key} => " . Debug::_dump($val, $length, $limit, $level + 1);
             }
             unset($objects[$hash]);
             $output[] = "{$space}}</code>";
         } else {
             // Depth too great
             $output[] = "{\n{$space}{$s}...\n{$space}}";
         }
         return "<small>object</small> <span>" . get_class($var) . "(" . count($array) . ")</span> " . implode("\n", $output);
     } else {
         return "<small>" . gettype($var) . "</small> " . htmlspecialchars(print_r($var, TRUE), ENT_NOQUOTES, JsonApiApplication::$charset);
     }
 }
コード例 #28
0
 /**
  * Word Wrap
  *
  * Wraps text at the specified character. Maintains the integrity of words.
  * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
  * will URLs.
  *
  * @param       string      $str                the text string
  * @param       int         $charlim = 76       the number of characters to wrap at
  * @return      string
  */
 function word_wrap($str, $charlim = 76)
 {
     // Set the character limit
     is_numeric($charlim) or $charlim = 76;
     // Reduce multiple spaces
     $str = preg_replace('| +|' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), ' ', $str);
     // Standardize newlines
     if (strpos($str, "\r") !== FALSE) {
         $str = str_replace(array("\r\n", "\r"), "\n", $str);
     }
     // If the current word is surrounded by {unwrap} tags we'll
     // strip the entire chunk and replace it with a marker.
     $unwrap = array();
     if (preg_match_all('|\\{unwrap\\}(.+?)\\{/unwrap\\}|s' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), $str, $matches)) {
         for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
             $unwrap[] = $matches[1][$i];
             $str = str_replace($matches[0][$i], '{{unwrapped' . $i . '}}', $str);
         }
     }
     // Use PHP's native function to do the initial wordwrap.
     // We set the cut flag to FALSE so that any individual words that are
     // too long get left alone. In the next step we'll deal with them.
     $str = UTF8::wordwrap($str, $charlim, "\n", FALSE);
     // Split the string into individual lines of text and cycle through them
     $output = '';
     foreach (explode("\n", $str) as $line) {
         // Is the line within the allowed character count?
         // If so we'll join it to the output and continue
         if (UTF8::strlen($line) <= $charlim) {
             $output .= $line . "\n";
             continue;
         }
         $temp = '';
         while (UTF8::strlen($line) > $charlim) {
             // If the over-length word is a URL we won't wrap it
             if (preg_match('!\\[url.+\\]|://|www\\.!' . (IS_UTF8_CHARSET && PCRE_UTF8_INSTALLED ? 'u' : ''), $line)) {
                 break;
             }
             // Trim the word down
             $temp .= UTF8::substr($line, 0, $charlim - 1);
             $line = UTF8::substr($line, $charlim - 1);
         }
         // If $temp contains data it means we had to split up an over-length
         // word into smaller chunks so we'll add it back to our current line
         if ($temp !== '') {
             $output .= $temp . "\n" . $line . "\n";
         } else {
             $output .= $line . "\n";
         }
     }
     // Put our markers back
     if (count($unwrap) > 0) {
         foreach ($unwrap as $key => $val) {
             $output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
         }
     }
     return $output;
 }
コード例 #29
0
ファイル: UTF8Test.php プロジェクト: azuya/Wi3
 /**
  * Tests UTF8::substr
  *
  * @test
  * @dataProvider provider_substr
  */
 public function test_substr($input, $offset, $length, $expected)
 {
     $this->assertSame($expected, UTF8::substr($input, $offset, $length));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
     $this->assertSame($expected, UTF8::substr($input, $offset, $length));
     UTF8::$server_utf8 = !UTF8::$server_utf8;
 }
コード例 #30
0
ファイル: error.php プロジェクト: tscms/profilertoolbar
      <div class="type"><?php 
    echo $class;
    ?>
 <span class="typeCode">[ <?php 
    echo $code;
    ?>
 ]</span></div>
      <div class="message">
      <?php 
    if ($class == 'Database_Exception') {
        ?>
      <?php 
        $start = UTF8::strpos($message, '[ ');
        $end = UTF8::strpos($message, ' ]');
        $sql = UTF8::substr($message, $start + 2, $end - $start - 2);
        $message = UTF8::substr($message, 0, $start);
        ?>
        <?php 
        echo $message;
        ?>
        <?php 
        if ($highlightSQL) {
            ?>
          <pre class="source sql"><?php 
            echo ProfilerToolbar::highlight($sql, 'sql');
            ?>
</pre>
        <?php 
        } else {
            ?>
          <pre class="source"><?php