split() static public method

Better alternative for explode() It takes care of removing empty values and it has a built-in way to skip values which are too short.
static public split ( string $string, string $separator = ',', integer $length = 1 ) : array
$string string The string to split
$separator string The string to split by
$length integer The min length of values.
return array An array of found values
コード例 #1
0
ファイル: router.php プロジェクト: chrishiam/LVSL
 /**
  * Adds a new route
  *
  * @param object $route
  * @return object
  */
 public function register($pattern, $params = array(), $optional = array())
 {
     if (is_array($pattern)) {
         foreach ($pattern as $v) {
             $this->register($v['pattern'], $v);
         }
         return $this;
     }
     $defaults = array('pattern' => $pattern, 'https' => false, 'ajax' => false, 'filter' => null, 'method' => 'GET', 'arguments' => array());
     $route = new Obj(array_merge($defaults, $params, $optional));
     // convert single methods or methods separated by | to arrays
     if (is_string($route->method)) {
         if (strpos($route->method, '|') !== false) {
             $route->method = str::split($route->method, '|');
         } else {
             if ($route->method == 'ALL') {
                 $route->method = array_keys($this->routes);
             } else {
                 $route->method = array($route->method);
             }
         }
     }
     foreach ($route->method as $method) {
         $this->routes[strtoupper($method)][$route->pattern] = $route;
     }
     return $route;
 }
コード例 #2
0
ファイル: tagcloud.php プロジェクト: niklausgerber/themis
function tagcloud($parent, $options = array())
{
    global $site;
    // default values
    $defaults = array('limit' => false, 'field' => 'tags', 'children' => 'visible', 'baseurl' => $parent->url(), 'param' => 'tag', 'sort' => 'name', 'sortdir' => 'asc');
    // merge defaults and options
    $options = array_merge($defaults, $options);
    switch ($options['children']) {
        case 'invisible':
            $children = $parent->children()->invisible();
            break;
        case 'visible':
            $children = $parent->children()->visible();
            break;
        default:
            $children = $parent->children();
            break;
    }
    $cloud = array();
    foreach ($children as $p) {
        $tags = str::split($p->{$options}['field']());
        foreach ($tags as $t) {
            if (isset($cloud[$t])) {
                $cloud[$t]->results++;
            } else {
                $cloud[$t] = new obj(array('results' => 1, 'name' => $t, 'url' => $options['baseurl'] . '/' . $options['param'] . ':' . $t, 'isActive' => param($options['param']) == $t ? true : false));
            }
        }
    }
    $cloud = a::sort($cloud, $options['sort'], $options['sortdir']);
    if ($options['limit']) {
        $cloud = array_slice($cloud, 0, $options['limit']);
    }
    return $cloud;
}
コード例 #3
0
ファイル: uri.php プロジェクト: narrenfrei/kirbycms
 function crawl()
 {
     $path = url::strip_query($this->raw);
     $path = (array) str::split($path, '/');
     if (a::first($path) == 'index.php') {
         array_shift($path);
     }
     // parse params
     foreach ($path as $p) {
         if (str::contains($p, ':')) {
             $parts = explode(':', $p);
             if (count($parts) < 2) {
                 continue;
             }
             $this->params->{$parts}[0] = $parts[1];
         } else {
             $this->path->_[] = $p;
         }
     }
     // get the extension from the last part of the path
     $this->extension = f::extension($this->path->last());
     if ($this->extension != false) {
         // remove the last part of the path
         $last = array_pop($this->path->_);
         $this->path->_[] = f::name($last);
     }
     return $this->path;
 }
コード例 #4
0
 public function getDay($date)
 {
     $Date = str::split($date, '-');
     // If day folder doesn't exists, create it
     $this->field()->check_day($this->model(), $date);
     // Go to day edit page
     go(purl($this->model(), 'year-' . $Date[0] . '/day-' . $date . '/edit/'));
 }
コード例 #5
0
 public function value()
 {
     $value = InputListField::value();
     if (is_array($value)) {
         return $value;
     } else {
         return str::split($value, ',');
     }
 }
コード例 #6
0
ファイル: checkboxes.php プロジェクト: kompuser/panel
 public function value()
 {
     $value = parent::value();
     if (is_array($value)) {
         return $value;
     } else {
         return str::split($value, ',');
     }
 }
コード例 #7
0
ファイル: helpers.php プロジェクト: nsteiner/kdoc
function slugTable()
{
    $table = array();
    foreach (str::$ascii as $key => $value) {
        $key = trim($key, '/');
        foreach (str::split($key, '|') as $needle) {
            $table[$needle] = $value;
        }
    }
    return json_encode($table, JSON_UNESCAPED_UNICODE);
}
コード例 #8
0
ファイル: bgimage.php プロジェクト: veryrobert/altair
/**
 * imgsrc Plugin
 *
 * @author Marijn Tijhuis <*****@*****.**>
 * @author Jonathan van Wunnik <*****@*****.**>
 * @version 1.0.0
 */
function bgimage($image = false, $options = array())
{
    if (!$image) {
        return;
    }
    // Default key values
    $defaults = array('width' => null, 'height' => null, 'crop' => null, 'cropratio' => null, 'class' => '', 'alt' => '', 'quality' => c::get('thumbs.quality', 92), 'lazyload' => c::get('lazyload', false));
    // Merge defaults and options
    $options = array_merge($defaults, $options);
    // Without resrc, maximize thumb width, for speedier loading of page!
    if (c::get('resrc') == false) {
        if (!isset($options['width'])) {
            $thumbwidth = c::get('thumbs.width.default', 800);
        } else {
            $thumbwidth = $options['width'];
        }
    } else {
        // If resrc is enabled, use original image width
        $thumbwidth = $image->width();
    }
    // If no crop variable is defined *and* no cropratio
    // is set, the crop variable is set to false
    if (!isset($options['crop']) && !isset($options['cropratio'])) {
        $options['crop'] = false;
    }
    // When a cropratio is set, calculate the ratio based height
    if (isset($options['cropratio'])) {
        // If cropratio is a fraction string (e.g. 1/2), convert to decimal
        if (strpos($options['cropratio'], '/') !== false) {
            list($numerator, $denominator) = str::split($options['cropratio'], '/');
            $options['cropratio'] = $numerator / $denominator;
        }
        // Calculate new thumb height based on cropratio
        $thumbheight = round($thumbwidth * $options['cropratio']);
        // If a cropratio is set, the crop variable is always set to true
        $options['crop'] = true;
        // Manual set (crop)ratio
        $ratio = $options['cropratio'];
    } else {
        // Intrinsic image's ratio
        $ratio = 1 / $image->ratio();
        // Max. height of image
        $thumbheight = round($thumbwidth * $ratio);
    }
    // Create thumb url (create a new thumb object)
    $options['thumburl'] = thumb($image, array('width' => $thumbwidth, 'height' => $thumbheight, 'quality' => $options['quality'], 'crop' => $options['crop']), false);
    // Add more values to options array, for use in template
    $options['customwidth'] = $options['width'];
    $options['customquality'] = $options['quality'];
    $options['ratio'] = $ratio;
    // Return template HTML
    return tpl::load(__DIR__ . DS . 'template/bgimage.php', $options);
}
コード例 #9
0
ファイル: uri.php プロジェクト: o-github-o/jQuery-Ajax-Upload
 function path($key = null, $default = null)
 {
     $path = self::$path;
     if (!$path) {
         $path = url::strip_query(self::raw());
         $path = (array) str::split($path, '/');
         self::$path = $path;
     }
     if ($key === null) {
         return $path;
     }
     return a::get($path, $key, $default);
 }
コード例 #10
0
 /**
  * Returns a registry entry object by type
  * 
  * @param string $type
  * @param string $subtype
  * @return Kirby\Registry\Entry
  */
 public function entry($type, $subtype = null)
 {
     $class = 'kirby\\registry\\' . $type;
     if (!class_exists('kirby\\registry\\' . $type)) {
         if (str::contains($type, '::')) {
             $parts = str::split($type, '::');
             $subtype = $parts[0];
             $type = $parts[1];
             return $this->entry($type, $subtype);
         }
         throw new Exception('Unsupported registry entry type: ' . $type);
     }
     return new $class($this, $subtype);
 }
コード例 #11
0
ファイル: figure.php プロジェクト: igorqr/kirby-extensions
/**
 * Figure Plugin
 *
 * @author Marijn Tijhuis <*****@*****.**>
 * @author Jonathan van Wunnik <*****@*****.**>
 * @version 1.0.0
 */
function figure($image = false, $options = array())
{
    if (!$image) {
        return;
    }
    // default key values
    $defaults = array('crop' => null, 'cropratio' => null, 'class' => '', 'alt' => '', 'caption' => null, 'lazyload' => c::get('lazyload', false));
    // merge defaults and options
    $options = array_merge($defaults, $options);
    // without resrc, maximize thumb width, for speedier loading of page!
    if (c::get('resrc') == false) {
        $thumbwidth = c::get('thumb.dev.width', 800);
    } else {
        // with resrc use maximum (original) image width
        $thumbwidth = null;
    }
    // if no crop variable is defined *and* no cropratio
    // is set, the crop variable is set to false
    if (!isset($options['crop']) && !isset($options['cropratio'])) {
        $options['crop'] = false;
    }
    // when a cropratio is set, calculate the ratio based height
    if (isset($options['cropratio'])) {
        // if resrc is enabled (and therefor $thumbwidth is not set (e.g. `null`),
        // to use max width of image!), set thumbwidth to width of original image
        if (!isset($thumbwidth)) {
            $thumbwidth = $image->width();
        }
        // if cropratio is a fraction string (e.g. 1/2), convert to decimal
        // if(!is_numeric($options['cropratio'])) {
        if (strpos($options['cropratio'], '/') !== false) {
            list($numerator, $denominator) = str::split($options['cropratio'], '/');
            $options['cropratio'] = $numerator / $denominator;
        }
        // calculate new thumb height based on cropratio
        $thumbheight = round($thumbwidth * $options['cropratio']);
        // if a cropratio is set, the crop variable is always set to true
        $options['crop'] = true;
    } else {
        $thumbheight = null;
        // max height of image
    }
    // Create thumb url (create a new thumb object)
    $options['thumburl'] = thumb($image, array('width' => $thumbwidth, 'height' => $thumbheight, 'crop' => $options['crop']), false);
    // Add image object to options array, for use in template
    $options['image'] = $image;
    // Return template HTML
    return tpl::load(__DIR__ . DS . 'template.php', $options);
}
コード例 #12
0
ファイル: api.php プロジェクト: madebypost/Gulp-Neat-KirbyCMS
 public static function subpages($pages, $blueprint)
 {
     switch ($blueprint->pages()->sort()) {
         case 'flip':
             $pages = $pages->flip();
             break;
         default:
             $parts = str::split($blueprint->pages()->sort(), ' ');
             if (count($parts) > 0) {
                 $pages = call_user_func_array(array($pages, 'sortBy'), $parts);
             }
             break;
     }
     return $pages;
 }
コード例 #13
0
ファイル: api.php プロジェクト: muten84/luigibifulco.it
 public static function subpages($pages, $blueprint)
 {
     switch ($blueprint->pages()->sort()) {
         case 'flip':
             $pages = $pages->flip();
             break;
         default:
             $parts = str::split($blueprint->pages()->sort(), ' ');
             $field = a::get($parts, 0);
             $order = a::get($parts, 1);
             if ($field) {
                 $pages = $pages->sortBy($field, $order);
             }
             break;
     }
     return $pages;
 }
コード例 #14
0
 public function check_day($calendarboard_url, $date)
 {
     $Date = str::split($date, '-');
     $year = $Date[0];
     $month = $Date[1];
     $day = $Date[2];
     $year_folder = 'year-' . $year;
     $day_folder = 'day-' . $date;
     // Check Year folder existence
     if (!site()->find($calendarboard_url . '/' . $year_folder)) {
         page($calendarboard_url)->children()->create($year_folder, 'calendar-board-year', array('title' => 'year-' . $year));
     }
     // Check Day folder existence
     if (!site()->find($calendarboard_url . '/' . $year_folder . '/' . $day_folder)) {
         page($calendarboard_url . '/' . $year_folder)->children()->create($day_folder, 'calendar-board-day', array('title' => $day . '-' . $month . '-' . $year));
     }
 }
コード例 #15
0
ファイル: app.php プロジェクト: kompuser/panel
 public static function launch()
 {
     static::$route = static::$router->run(static::$path);
     // react on invalid routes
     if (!static::$route) {
         throw new Exception('Invalid route');
     }
     // let's find the controller and controller action
     $controllerParts = str::split(static::$route->action(), '::');
     $controllerUri = $controllerParts[0];
     $controllerAction = $controllerParts[1];
     $controllerFile = root('panel.app.controllers') . DS . strtolower(str_replace('Controller', '', $controllerUri)) . '.php';
     $controllerName = basename($controllerUri);
     // react on missing controllers
     if (!file_exists($controllerFile)) {
         throw new Exception('Invalid controller');
     }
     // load the controller
     require_once $controllerFile;
     // check for the called action
     if (!method_exists($controllerName, $controllerAction)) {
         throw new Exception('Invalid action');
     }
     // run the controller
     $controller = new $controllerName();
     try {
         // call the action and pass all arguments from the router
         $response = call(array($controller, $controllerAction), static::$route->arguments());
     } catch (Exception $e) {
         $file = root('panel.app.controllers') . DS . substr($controllerUri, 0, strpos($controllerUri, '/') + 1) . 'errors.php';
         require_once $file;
         $action = (isset(static::$route->modal) and static::$route->modal()) ? 'modal' : 'index';
         $controller = new ErrorsController();
         $response = call(array($controller, $action), array($e->getMessage()));
     }
     ob_start();
     // check for a valid response object
     if (is_a($response, 'Response')) {
         echo $response;
     } else {
         echo new Response($response);
     }
     ob_end_flush();
 }
コード例 #16
0
ファイル: children.php プロジェクト: nsteiner/kdoc
 public function __construct($page)
 {
     parent::__construct($page);
     $page->reset();
     $inventory = $page->inventory();
     foreach ($inventory['children'] as $dirname) {
         $child = new Page($page, $dirname);
         $this->data[$child->id()] = $child;
     }
     $sort = $page->blueprint()->pages()->sort();
     switch ($sort) {
         case 'flip':
             $cloned = $this->flip();
             $this->data = $cloned->data;
             break;
         default:
             $parts = str::split($sort, ' ');
             if (count($parts) > 0) {
                 $cloned = call(array($this, 'sortBy'), $parts);
                 $this->data = $cloned->data;
             }
             break;
     }
 }
コード例 #17
0
ファイル: product.php プロジェクト: samnabi/shopkit
        echo $variant->name();
        ?>
</h3>

								<div property="description">
									<?php 
        ecco(trim($variant->description()) != '', $variant->description()->kirbytext()->bidi());
        ?>
								</div>

								<?php 
        if ($variant->hasOptions) {
            ?>
									<select dir="auto" class="uk-width-1-1" name="option">
										<?php 
            foreach (str::split($variant->options()) as $option) {
                ?>
											<option value="<?php 
                echo str::slug($option);
                ?>
"><?php 
                echo str::ucfirst($option);
                ?>
</option>
										<?php 
            }
            ?>
									</select>
								<?php 
        }
        ?>
コード例 #18
0
</a></div>
						<time datetime="<?php 
echo $article->date('c');
?>
">
							<?php 
echo $article->date('d.m.Y');
?>
						</time>

						<?php 
if ($article->tags() != '') {
    ?>
							<ol class="tags">
								<?php 
    $tags = str::split($article->tags());
    sort($tags);
    ?>
								<?php 
    foreach ($tags as $tag) {
        ?>
									<li><a href="<?php 
        echo url('tag:' . urlencode($tag));
        ?>
">#<?php 
        echo $tag;
        ?>
</a></li>
								<?php 
    }
    ?>
コード例 #19
0
ファイル: cookie.php プロジェクト: williampan/w
 /**
  * Parses the hashed value from a cookie
  * and tries to extract the value 
  * 
  * @param string $hash
  * @return mixed
  */
 protected static function parse($string)
 {
     // extract hash and value
     $parts = str::split($string, '+');
     $hash = a::first($parts);
     $value = a::last($parts);
     // if the hash or the value is missing at all return null
     if (empty($hash) or empty($value)) {
         return null;
     }
     // compare the extracted hash with the hashed value
     if ($hash !== static::hash($value)) {
         return null;
     }
     return $value;
 }
コード例 #20
0
<?php

// do some prep
$splash_on = strtolower($site->splash_page());
$splash_on = $page->isHomePage() && ($splash_on === 'yes' || $splash_on == 'true' || $splash_on === 'on') ? true : false;
if ($splash_on) {
    $splash = $pages->find('/splash');
}
$categories_on = strtolower($site->categories_enabled());
$categories_on = $categories_on === 'yes' || $categories_on === 'true' || $categories_on === 'on' ? true : false;
global $category_name;
if ($categories_on) {
    $categories = str::split($site->categories(), ',');
    $n = array('all' => 'All');
    $s = array('\'', ' ');
    $r = array('-', '-');
    foreach ($categories as $c) {
        $n[str_replace($s, $r, trim($c))] = $c;
    }
    $categories = $n;
}
?>
<div class="container">

	<header>
		<div id="logo"><a href="">LANNINGSMITH</a></div>
	</header>

	<?php 
if ($splash_on == true) {
    ?>
コード例 #21
0
ファイル: figure.php プロジェクト: igorqr/kirby-extensions
 // if the crop variable is explicitly set to 'false' string *and*
 // no cropratio is set, the crop variable is always set to false
 if ($crop == 'false' && !isset($cropratio)) {
     $crop = false;
 }
 // when a cropratio is set, calculate the ratio based height
 if (isset($cropratio)) {
     // if resrc is enabled (and therefor $thumbwidth is not set (e.g. `null`),
     // to use max width of image!), set thumbwidth to width of original image
     if (!isset($thumbwidth)) {
         $thumbwidth = $image->width();
     }
     // if cropratio is a fraction string (e.g. 1/2), convert to decimal
     // if(!is_numeric($cropratio)) {
     if (strpos($cropratio, '/') !== false) {
         list($numerator, $denominator) = str::split($cropratio, '/');
         $cropratio = $numerator / $denominator;
     }
     // calculate new thumb height based on cropratio
     $thumbheight = round($thumbwidth * $cropratio);
     // if a cropratio is set, the crop variable is always set to true
     $crop = true;
 } else {
     $thumbheight = null;
     // max height of image
 }
 $thumburl = thumb($image, array('width' => $thumbwidth, 'height' => $thumbheight, 'quality' => $quality, 'crop' => $crop), false);
 // [1] Regular image; resized thumb (thumb.dev.width)
 if ($lazyload == false && c::get('resrc') == false) {
     $imagethumb = html::img($thumburl, array('class' => $class, 'alt' => html($alt)));
 }
コード例 #22
0
ファイル: pages.php プロジェクト: robeam/kirbycms
 function find()
 {
     $args = func_get_args();
     // find multiple pages
     if (count($args) > 1) {
         $result = array();
         foreach ($args as $arg) {
             $page = $this->find($arg);
             if ($page) {
                 $result[$page->uid] = $page;
             }
         }
         return empty($result) ? false : new pages($result);
     }
     // find a single page
     $path = a::first($args);
     $array = str::split($path, '/');
     $obj = $this;
     $page = false;
     foreach ($array as $p) {
         $next = $obj->{$p};
         if (!$next) {
             return $page;
         }
         $page = $next;
         $obj = $next->children();
     }
     return $page;
 }
コード例 #23
0
ファイル: selector.php プロジェクト: starckio/Userskit
 /**
  * Return the current value
  *
  * @since 1.0.0
  *
  * @return array
  */
 public function value()
 {
     if (is_string($this->value)) {
         $this->value = str::split($this->value, ',', 1);
     }
     return $this->value;
 }
コード例 #24
0
ファイル: kirby.php プロジェクト: sdvig/kirbycms
 /**
  * @todo rework
  */
 static function current()
 {
     if (s::get('language')) {
         return s::get('language');
     }
     $lang = str::split(server::get('http_accept_language'), '-');
     $lang = str::trim(a::get($lang, 0));
     $lang = l::sanitize($lang);
     s::set('language', $lang);
     return $lang;
 }
コード例 #25
0
 /**
  * Returns the dimensions of the file if possible
  *
  * @return Dimensions
  */
 public function dimensions()
 {
     if (isset($this->cache['dimensions'])) {
         return $this->cache['dimensions'];
     }
     if (in_array($this->mime(), array('image/jpeg', 'image/png', 'image/gif'))) {
         $size = (array) getimagesize($this->root);
         $width = a::get($size, 0, 0);
         $height = a::get($size, 1, 0);
     } else {
         if ($this->extension() == 'svg') {
             $content = $this->read();
             $xml = simplexml_load_string($content);
             $attr = $xml->attributes();
             $width = floatval($attr->width);
             $height = floatval($attr->height);
             if ($width == 0 or $height == 0 and !empty($attr->viewBox)) {
                 $box = str::split($attr->viewBox, ' ');
                 $width = floatval(a::get($box, 2, 0));
                 $height = floatval(a::get($box, 3, 0));
             }
         } else {
             $width = 0;
             $height = 0;
         }
     }
     return $this->cache['dimensions'] = new Dimensions($width, $height);
 }
コード例 #26
0
ファイル: brick.php プロジェクト: chrishiam/LVSL
 public function removeClass($class)
 {
     $classNames = $this->classNames();
     foreach (str::split($class, ' ') as $c) {
         $classNames = array_filter($classNames, function ($e) use($c) {
             return strtolower($e) !== strtolower($c);
         });
     }
     $this->attr['class'] = $classNames;
     return $this;
 }
コード例 #27
0
ファイル: footer-blog.php プロジェクト: aizlewood/2016
  <footer class="footer-blog cf" role="contentinfo">

 <main class="main blog" role="main">

  <div class="inner">
  	<div class="author">
  		<?php 
snippet('author');
?>
	
  	</div>

	<div class="tags">
		Tagged with: <?php 
foreach (str::split($page->tags()) as $tag) {
    ?>
			<a href="<?php 
    echo url('articles/tag:' . urlencode($tag));
    ?>
">#<?php 
    echo html($tag);
    ?>
</a>
		<?php 
}
?>
	</div>  

  </div>
  
  <?php 
コード例 #28
0
ファイル: blog.php プロジェクト: HypeReport/HypeReport-Blog
    <article>
      <header class="meta">
        <time datetime="<?php 
            echo $article->date('c');
            ?>
"><?php 
            echo $article->date('F dS, Y');
            ?>
</time>
        <?php 
            if ($article->tags() != '') {
                ?>
 |
        <ul class="tags">
          <?php 
                foreach (str::split($article->tags()) as $tag) {
                    ?>
          <li><a href="<?php 
                    echo url('tag:' . urlencode($tag));
                    ?>
">#<?php 
                    echo $tag;
                    ?>
</a></li>
          <?php 
                }
                ?>
        </ul>
        <?php 
            }
            ?>
コード例 #29
0
ファイル: remote.php プロジェクト: LucasFyl/korakia
 /**
  * Used by curl to parse incoming headers
  *
  * @param object $curl the curl connection
  * @param string $header the header line
  * @return int the length of the heade
  */
 protected function header($curl, $header)
 {
     $parts = str::split($header, ':');
     if (!empty($parts[0]) && !empty($parts[1])) {
         $this->headers[$parts[0]] = $parts[1];
     }
     return strlen($header);
 }
コード例 #30
0
 /**
  * Creates a new table
  *
  * @param string $table
  * @param array $columns
  * @return boolean
  */
 public function createTable($table, $columns = array())
 {
     $sql = new SQL($this);
     $query = $sql->createTable($table, $columns);
     $queries = str::split($query, ';');
     foreach ($queries as $query) {
         if (!$this->execute($query)) {
             return false;
         }
     }
     return true;
 }