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
Example #1
0
 /**
  * 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;
 }
Example #2
0
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;
}
Example #3
0
 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;
 }
 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/'));
 }
 public function value()
 {
     $value = InputListField::value();
     if (is_array($value)) {
         return $value;
     } else {
         return str::split($value, ',');
     }
 }
Example #6
0
 public function value()
 {
     $value = parent::value();
     if (is_array($value)) {
         return $value;
     } else {
         return str::split($value, ',');
     }
 }
Example #7
0
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);
}
Example #8
0
/**
 * 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);
}
Example #9
0
 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);
 }
 /**
  * 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);
 }
Example #11
0
/**
 * 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);
}
Example #12
0
 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;
 }
Example #13
0
 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;
 }
 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));
     }
 }
Example #15
0
 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();
 }
Example #16
0
 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;
     }
 }
Example #17
0
        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 
        }
        ?>
Example #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 
    }
    ?>
Example #19
0
 /**
  * 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;
 }
Example #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) {
    ?>
Example #21
0
 // 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)));
 }
Example #22
0
 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;
 }
Example #23
0
 /**
  * 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;
 }
Example #24
0
 /**
  * @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;
 }
Example #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);
 }
Example #26
0
 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;
 }
Example #27
0
  <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 
Example #28
0
    <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 
            }
            ?>
Example #29
0
 /**
  * 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);
 }
Example #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;
 }