Apply PSR1/PSR2 coding standards.
Mostly - use consistent indentation. Currently some methods in Pico class are indented with space ( get_files() ), some with tabs.
This commit is contained in:
parent
83a3313e53
commit
577160b109
70
lib/pico.php
70
lib/pico.php
@ -8,7 +8,8 @@
|
||||
* @license http://opensource.org/licenses/MIT
|
||||
* @version 0.8
|
||||
*/
|
||||
class Pico {
|
||||
class Pico
|
||||
{
|
||||
|
||||
private $config;
|
||||
private $plugins;
|
||||
@ -33,17 +34,26 @@ class Pico {
|
||||
$script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
|
||||
|
||||
// Get our url path and trim the / of the left and the right
|
||||
if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/');
|
||||
if ($request_url != $script_url) {
|
||||
$url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '',
|
||||
$request_url, 1), '/');
|
||||
}
|
||||
$url = preg_replace('/\?.*/', '', $url); // Strip query string
|
||||
$this->run_hooks('request_url', array(&$url));
|
||||
|
||||
// Get the file path
|
||||
if($url) $file = $settings['content_dir'] . $url;
|
||||
else $file = $settings['content_dir'] .'index';
|
||||
if ($url) {
|
||||
$file = $settings['content_dir'] . $url;
|
||||
} else {
|
||||
$file = $settings['content_dir'] . 'index';
|
||||
}
|
||||
|
||||
// Load the file
|
||||
if(is_dir($file)) $file = $settings['content_dir'] . $url .'/index'. CONTENT_EXT;
|
||||
else $file .= CONTENT_EXT;
|
||||
if (is_dir($file)) {
|
||||
$file = $settings['content_dir'] . $url . '/index' . CONTENT_EXT;
|
||||
} else {
|
||||
$file .= CONTENT_EXT;
|
||||
}
|
||||
|
||||
$this->run_hooks('before_load_content', array(&$file));
|
||||
if (file_exists($file)) {
|
||||
@ -65,7 +75,8 @@ class Pico {
|
||||
$this->run_hooks('content_parsed', array(&$content)); // Depreciated @ v0.8
|
||||
|
||||
// Get all the pages
|
||||
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'], $settings['excerpt_length']);
|
||||
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'],
|
||||
$settings['excerpt_length']);
|
||||
$prev_page = array();
|
||||
$current_page = array();
|
||||
$next_page = array();
|
||||
@ -173,7 +184,9 @@ class Pico {
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($headers['date'])) $headers['date_formatted'] = utf8_encode(strftime($config['date_format'], strtotime($headers['date'])));
|
||||
if (isset($headers['date'])) {
|
||||
$headers['date_formatted'] = utf8_encode(strftime($config['date_format'], strtotime($headers['date'])));
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
@ -200,8 +213,11 @@ class Pico {
|
||||
'content_dir' => 'content-sample/',
|
||||
);
|
||||
|
||||
if(is_array($this->config)) $this->config = array_merge($defaults, $this->config);
|
||||
else $this->config = $defaults;
|
||||
if (is_array($this->config)) {
|
||||
$this->config = array_merge($defaults, $this->config);
|
||||
} else {
|
||||
$this->config = $defaults;
|
||||
}
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
@ -245,7 +261,8 @@ class Pico {
|
||||
'url' => $url,
|
||||
'author' => isset($page_meta['author']) ? $page_meta['author'] : '',
|
||||
'date' => isset($page_meta['date']) ? $page_meta['date'] : '',
|
||||
'date_formatted' => isset($page_meta['date']) ? utf8_encode(strftime($config['date_format'], strtotime($page_meta['date']))) : '',
|
||||
'date_formatted' => isset($page_meta['date']) ? utf8_encode(strftime($config['date_format'],
|
||||
strtotime($page_meta['date']))) : '',
|
||||
'content' => $page_content,
|
||||
'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length),
|
||||
//this addition allows the 'description' meta to be picked up in content areas... specifically to replace 'excerpt'
|
||||
@ -259,12 +276,16 @@ class Pico {
|
||||
if ($order_by == 'date' && isset($page_meta['date'])) {
|
||||
$sorted_pages[$page_meta['date'] . $date_id] = $data;
|
||||
$date_id++;
|
||||
} else {
|
||||
$sorted_pages[$page] = $data;
|
||||
}
|
||||
else $sorted_pages[$page] = $data;
|
||||
}
|
||||
|
||||
if($order == 'desc') krsort($sorted_pages);
|
||||
else ksort($sorted_pages);
|
||||
if ($order == 'desc') {
|
||||
krsort($sorted_pages);
|
||||
} else {
|
||||
ksort($sorted_pages);
|
||||
}
|
||||
|
||||
return $sorted_pages;
|
||||
}
|
||||
@ -295,14 +316,20 @@ class Pico {
|
||||
{
|
||||
$config = $this->config;
|
||||
|
||||
if(isset($config['base_url']) && $config['base_url']) return $config['base_url'];
|
||||
if (isset($config['base_url']) && $config['base_url']) {
|
||||
return $config['base_url'];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
|
||||
$script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : '';
|
||||
if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/');
|
||||
if ($request_url != $script_url) {
|
||||
$url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '',
|
||||
$request_url, 1), '/');
|
||||
}
|
||||
|
||||
$protocol = $this->get_protocol();
|
||||
|
||||
return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/');
|
||||
}
|
||||
|
||||
@ -317,6 +344,7 @@ class Pico {
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' && $_SERVER['HTTPS'] != '') {
|
||||
$protocol = 'https';
|
||||
}
|
||||
|
||||
return $protocol;
|
||||
}
|
||||
|
||||
@ -340,12 +368,15 @@ class Pico {
|
||||
$array_items = array_merge($array_items, $this->get_files($directory . "/" . $file, $ext));
|
||||
} else {
|
||||
$file = $directory . "/" . $file;
|
||||
if(!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file);
|
||||
if (!$ext || strstr($file, $ext)) {
|
||||
$array_items[] = preg_replace("/\/\//si", "/", $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
return $array_items;
|
||||
}
|
||||
|
||||
@ -360,7 +391,10 @@ class Pico {
|
||||
{
|
||||
$words = explode(' ', $string);
|
||||
$excerpt = trim(implode(' ', array_splice($words, 0, $word_limit)));
|
||||
if(count($words) > $word_limit) $excerpt .= '…';
|
||||
if (count($words) > $word_limit) {
|
||||
$excerpt .= '…';
|
||||
}
|
||||
|
||||
return $excerpt;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @link http://picocms.org
|
||||
* @license http://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Pico_Plugin {
|
||||
class Pico_Plugin
|
||||
{
|
||||
|
||||
public function plugins_loaded()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user