summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-01-06 18:09:22 +0100
committerAndrey Andreev <narf@bofh.bg>2012-01-06 18:09:22 +0100
commit1e6b72cca80354619cf7ddceb2b5f23d37b972e9 (patch)
tree57613f7986517d22504bf637ff1c8ce4d78812fd /system
parent20b4fa2fc12d0630aa8c5d9ce09623e58d98f9ca (diff)
Improve html, inflector & language helpers
Diffstat (limited to 'system')
-rw-r--r--system/helpers/html_helper.php70
-rw-r--r--system/helpers/inflector_helper.php30
-rw-r--r--system/helpers/language_helper.php9
3 files changed, 33 insertions, 76 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 2a603a607..72970d9ca 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -54,8 +54,7 @@ if ( ! function_exists('heading'))
{
function heading($data = '', $h = '1', $attributes = '')
{
- $attributes = ($attributes != '') ? ' '.$attributes : $attributes;
- return "<h".$h.$attributes.">".$data."</h".$h.">";
+ return '<h'.$h.($attributes != '' ? ' ' : '').$attributes.'>'.$data.'</h'.$h.'>';
}
}
@@ -124,7 +123,7 @@ if ( ! function_exists('_list'))
}
// Set the indentation based on the depth
- $out = str_repeat(" ", $depth);
+ $out = str_repeat(' ', $depth);
// Were any attributes submitted? If so generate a string
if (is_array($attributes))
@@ -142,7 +141,7 @@ if ( ! function_exists('_list'))
}
// Write the opening list tag
- $out .= "<".$type.$attributes.">\n";
+ $out .= '<'.$type.$attributes.">\n";
// Cycle through the list elements. If an array is
// encountered we will recursively call _list()
@@ -152,8 +151,7 @@ if ( ! function_exists('_list'))
{
$_last_list_item = $key;
- $out .= str_repeat(" ", $depth + 2);
- $out .= "<li>";
+ $out .= str_repeat(' ', $depth + 2).'<li>';
if ( ! is_array($val))
{
@@ -161,21 +159,14 @@ if ( ! function_exists('_list'))
}
else
{
- $out .= $_last_list_item."\n";
- $out .= _list($type, $val, '', $depth + 4);
- $out .= str_repeat(" ", $depth + 2);
+ $out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2);
}
$out .= "</li>\n";
}
- // Set the indentation for the closing tag
- $out .= str_repeat(" ", $depth);
-
- // Write the closing list tag
- $out .= "</".$type.">\n";
-
- return $out;
+ // Set the indentation for the closing tag and apply it
+ return $out.str_repeat(' ', $depth).'</'.$type.">\n";
}
}
@@ -192,7 +183,7 @@ if ( ! function_exists('br'))
{
function br($num = 1)
{
- return str_repeat("<br />", $num);
+ return str_repeat('<br />', $num);
}
}
@@ -224,10 +215,9 @@ if ( ! function_exists('img'))
$img = '<img';
- foreach ($src as $k=>$v)
+ foreach ($src as $k => $v)
{
-
- if ($k == 'src' AND strpos($v, '://') === FALSE)
+ if ($k === 'src' AND strpos($v, '://') === FALSE)
{
$CI =& get_instance();
@@ -246,9 +236,7 @@ if ( ! function_exists('img'))
}
}
- $img .= '/>';
-
- return $img;
+ return $img.'/>';
}
}
@@ -290,14 +278,7 @@ if ( ! function_exists('doctype'))
}
}
- if (isset($_doctypes[$type]))
- {
- return $_doctypes[$type];
- }
- else
- {
- return FALSE;
- }
+ return (isset($_doctypes[$type])) ? $_doctypes[$type] : FALSE;
}
}
@@ -322,14 +303,13 @@ if ( ! function_exists('link_tag'))
function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
{
$CI =& get_instance();
-
$link = '<link ';
if (is_array($href))
{
- foreach ($href as $k=>$v)
+ foreach ($href as $k => $v)
{
- if ($k == 'href' AND strpos($v, '://') === FALSE)
+ if ($k === 'href' AND strpos($v, '://') === FALSE)
{
if ($index_page === TRUE)
{
@@ -346,11 +326,11 @@ if ( ! function_exists('link_tag'))
}
}
- $link .= "/>";
+ $link .= '/>';
}
else
{
- if ( strpos($href, '://') !== FALSE)
+ if (strpos($href, '://') !== FALSE)
{
$link .= 'href="'.$href.'" ';
}
@@ -365,21 +345,20 @@ if ( ! function_exists('link_tag'))
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
- if ($media != '')
+ if ($media != '')
{
$link .= 'media="'.$media.'" ';
}
- if ($title != '')
+ if ($title != '')
{
$link .= 'title="'.$title.'" ';
}
$link .= '/>';
}
- $link .= "\n";
- return $link;
+ return $link."\n";
}
}
@@ -439,10 +418,9 @@ if ( ! function_exists('nbs'))
{
function nbs($num = 1)
{
- return str_repeat("&nbsp;", $num);
+ return str_repeat('&nbsp;', $num);
}
}
-
/* End of file html_helper.php */
-/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/html_helper.php */
diff --git a/system/helpers/inflector_helper.php b/system/helpers/inflector_helper.php
index f093dd921..0bd1e112f 100644
--- a/system/helpers/inflector_helper.php
+++ b/system/helpers/inflector_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -85,16 +85,7 @@ if ( ! function_exists('singular'))
'/([^u])s$/' => '\1',
);
- foreach ($singular_rules as $rule => $replacement)
- {
- if (preg_match($rule, $result))
- {
- $result = preg_replace($rule, $replacement, $result);
- break;
- }
- }
-
- return $result;
+ return preg_replace(array_keys($singular_values), $singular_values, $result);
}
}
@@ -138,16 +129,7 @@ if ( ! function_exists('plural'))
'/$/' => 's',
);
- foreach ($plural_rules as $rule => $replacement)
- {
- if (preg_match($rule, $result))
- {
- $result = preg_replace($rule, $replacement, $result);
- break;
- }
- }
-
- return $result;
+ return preg_replace(array_keys($plural_rules), $plural_rules, $result);
}
}
@@ -166,9 +148,7 @@ if ( ! function_exists('camelize'))
{
function camelize($str)
{
- $str = 'x'.strtolower(trim($str));
- $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
- return substr(str_replace(' ', '', $str), 1);
+ return substr(str_replace(' ', '', ucwords(preg_replace('/[\s_]+/', ' ', $str))), 1);
}
}
@@ -212,4 +192,4 @@ if ( ! function_exists('humanize'))
}
/* End of file inflector_helper.php */
-/* Location: ./system/helpers/inflector_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/inflector_helper.php */
diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php
index ed17bfa4c..a83580a97 100644
--- a/system/helpers/language_helper.php
+++ b/system/helpers/language_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -65,6 +65,5 @@ if ( ! function_exists('lang'))
}
}
-// ------------------------------------------------------------------------
/* End of file language_helper.php */
-/* Location: ./system/helpers/language_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/language_helper.php */