@@ -1,98 +1,98 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! function_exists('Markdown')) { |
| 4 | - require_once('markdown_helper.php'); |
|
| 4 | + require_once('markdown_helper.php'); |
|
| 5 | 5 | } |
| 6 | 6 | define('MARKDOWNEXTRAEXTENDED_VERSION', "0.3"); |
| 7 | 7 | |
| 8 | 8 | function MarkdownExtended($text, $default_classes = array()) |
| 9 | 9 | { |
| 10 | - $parser = new MarkdownExtraExtended_Parser($default_classes); |
|
| 11 | - return $parser->transform($text); |
|
| 10 | + $parser = new MarkdownExtraExtended_Parser($default_classes); |
|
| 11 | + return $parser->transform($text); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class MarkdownExtraExtended_Parser extends MarkdownExtra_Parser |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - # Tags that are always treated as block tags: |
|
| 18 | - var $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; |
|
| 19 | - |
|
| 20 | - var $default_classes; |
|
| 21 | - |
|
| 22 | - function MarkdownExtraExtended_Parser($default_classes = array()) |
|
| 23 | - { |
|
| 24 | - $default_classes = $default_classes; |
|
| 25 | - |
|
| 26 | - $this->block_gamut += array( |
|
| 27 | - "doFencedFigures" => 7, |
|
| 28 | - ); |
|
| 29 | - |
|
| 30 | - parent::MarkdownExtra_Parser(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - function transform($text) |
|
| 34 | - { |
|
| 35 | - $text = parent::transform($text); |
|
| 36 | - return $text; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - function doHardBreaks($text) |
|
| 40 | - { |
|
| 41 | - # Do hard breaks: |
|
| 42 | - # EXTENDED: changed to allow breaks without two spaces and just one new line |
|
| 43 | - # original code /* return preg_replace_callback('/ {2,}\n/', */ |
|
| 44 | - return preg_replace_callback( |
|
| 45 | - '/ *\n/', |
|
| 46 | - array(&$this, '_doHardBreaks_callback'), |
|
| 47 | - $text |
|
| 48 | - ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - function doBlockQuotes($text) |
|
| 52 | - { |
|
| 53 | - $text = preg_replace_callback( |
|
| 54 | - '/ |
|
| 17 | + # Tags that are always treated as block tags: |
|
| 18 | + var $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; |
|
| 19 | + |
|
| 20 | + var $default_classes; |
|
| 21 | + |
|
| 22 | + function MarkdownExtraExtended_Parser($default_classes = array()) |
|
| 23 | + { |
|
| 24 | + $default_classes = $default_classes; |
|
| 25 | + |
|
| 26 | + $this->block_gamut += array( |
|
| 27 | + "doFencedFigures" => 7, |
|
| 28 | + ); |
|
| 29 | + |
|
| 30 | + parent::MarkdownExtra_Parser(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + function transform($text) |
|
| 34 | + { |
|
| 35 | + $text = parent::transform($text); |
|
| 36 | + return $text; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + function doHardBreaks($text) |
|
| 40 | + { |
|
| 41 | + # Do hard breaks: |
|
| 42 | + # EXTENDED: changed to allow breaks without two spaces and just one new line |
|
| 43 | + # original code /* return preg_replace_callback('/ {2,}\n/', */ |
|
| 44 | + return preg_replace_callback( |
|
| 45 | + '/ *\n/', |
|
| 46 | + array(&$this, '_doHardBreaks_callback'), |
|
| 47 | + $text |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + function doBlockQuotes($text) |
|
| 52 | + { |
|
| 53 | + $text = preg_replace_callback( |
|
| 54 | + '/ |
|
| 55 | 55 | (?>^[ ]*>[ ]? |
| 56 | 56 | (?:\((.+?)\))? |
| 57 | 57 | [ ]*(.+\n(?:.+\n)*) |
| 58 | 58 | )+ |
| 59 | 59 | /xm', |
| 60 | - array(&$this, '_doBlockQuotes_callback'), |
|
| 61 | - $text |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - return $text; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - function _doBlockQuotes_callback($matches) |
|
| 68 | - { |
|
| 69 | - $cite = $matches[1]; |
|
| 70 | - $bq = '> ' . $matches[2]; |
|
| 71 | - # trim one level of quoting - trim whitespace-only lines |
|
| 72 | - $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 73 | - $bq = $this->runBlockGamut($bq); # recurse |
|
| 74 | - |
|
| 75 | - $bq = preg_replace('/^/m', " ", $bq); |
|
| 76 | - # These leading spaces cause problem with <pre> content, |
|
| 77 | - # so we need to fix that: |
|
| 78 | - $bq = preg_replace_callback( |
|
| 79 | - '{(\s*<pre>.+?</pre>)}sx', |
|
| 80 | - array(&$this, '_doBlockQuotes_callback2'), |
|
| 81 | - $bq |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - $res = "<blockquote"; |
|
| 85 | - $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
|
| 86 | - $res .= "\n$bq\n</blockquote>"; |
|
| 87 | - return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - function doFencedCodeBlocks($text) |
|
| 91 | - { |
|
| 92 | - $less_than_tab = $this->tab_width; |
|
| 93 | - |
|
| 94 | - $text = preg_replace_callback( |
|
| 95 | - '{ |
|
| 60 | + array(&$this, '_doBlockQuotes_callback'), |
|
| 61 | + $text |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + return $text; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + function _doBlockQuotes_callback($matches) |
|
| 68 | + { |
|
| 69 | + $cite = $matches[1]; |
|
| 70 | + $bq = '> ' . $matches[2]; |
|
| 71 | + # trim one level of quoting - trim whitespace-only lines |
|
| 72 | + $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
|
| 73 | + $bq = $this->runBlockGamut($bq); # recurse |
|
| 74 | + |
|
| 75 | + $bq = preg_replace('/^/m', " ", $bq); |
|
| 76 | + # These leading spaces cause problem with <pre> content, |
|
| 77 | + # so we need to fix that: |
|
| 78 | + $bq = preg_replace_callback( |
|
| 79 | + '{(\s*<pre>.+?</pre>)}sx', |
|
| 80 | + array(&$this, '_doBlockQuotes_callback2'), |
|
| 81 | + $bq |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + $res = "<blockquote"; |
|
| 85 | + $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
|
| 86 | + $res .= "\n$bq\n</blockquote>"; |
|
| 87 | + return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + function doFencedCodeBlocks($text) |
|
| 91 | + { |
|
| 92 | + $less_than_tab = $this->tab_width; |
|
| 93 | + |
|
| 94 | + $text = preg_replace_callback( |
|
| 95 | + '{ |
|
| 96 | 96 | (?:\n|\A) |
| 97 | 97 | # 1: Opening marker |
| 98 | 98 | ( |
@@ -112,34 +112,34 @@ discard block |
||
| 112 | 112 | # Closing marker. |
| 113 | 113 | \1 [ ]* \n |
| 114 | 114 | }xm', |
| 115 | - array(&$this, '_doFencedCodeBlocks_callback'), |
|
| 116 | - $text |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - return $text; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - function _doFencedCodeBlocks_callback($matches) |
|
| 123 | - { |
|
| 124 | - $codeblock = $matches[4]; |
|
| 125 | - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 126 | - $codeblock = preg_replace_callback( |
|
| 127 | - '/^\n+/', |
|
| 128 | - array(&$this, '_doFencedCodeBlocks_newlines'), |
|
| 129 | - $codeblock |
|
| 130 | - ); |
|
| 131 | - //$codeblock = "<pre><code>$codeblock</code></pre>"; |
|
| 132 | - //$cb = "<pre><code"; |
|
| 133 | - $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
|
| 134 | - $cb .= empty($matches[2]) ? ">" : " class=\"language-$matches[2]\">"; |
|
| 135 | - $cb .= "$codeblock</code></pre>"; |
|
| 136 | - return "\n\n" . $this->hashBlock($cb) . "\n\n"; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - function doFencedFigures($text) |
|
| 140 | - { |
|
| 141 | - $text = preg_replace_callback( |
|
| 142 | - '{ |
|
| 115 | + array(&$this, '_doFencedCodeBlocks_callback'), |
|
| 116 | + $text |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + return $text; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + function _doFencedCodeBlocks_callback($matches) |
|
| 123 | + { |
|
| 124 | + $codeblock = $matches[4]; |
|
| 125 | + $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); |
|
| 126 | + $codeblock = preg_replace_callback( |
|
| 127 | + '/^\n+/', |
|
| 128 | + array(&$this, '_doFencedCodeBlocks_newlines'), |
|
| 129 | + $codeblock |
|
| 130 | + ); |
|
| 131 | + //$codeblock = "<pre><code>$codeblock</code></pre>"; |
|
| 132 | + //$cb = "<pre><code"; |
|
| 133 | + $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
|
| 134 | + $cb .= empty($matches[2]) ? ">" : " class=\"language-$matches[2]\">"; |
|
| 135 | + $cb .= "$codeblock</code></pre>"; |
|
| 136 | + return "\n\n" . $this->hashBlock($cb) . "\n\n"; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + function doFencedFigures($text) |
|
| 140 | + { |
|
| 141 | + $text = preg_replace_callback( |
|
| 142 | + '{ |
|
| 143 | 143 | (?:\n|\A) |
| 144 | 144 | # 1: Opening marker |
| 145 | 145 | ( |
@@ -159,41 +159,41 @@ discard block |
||
| 159 | 159 | # Closing marker. |
| 160 | 160 | \1 [ ]?(?:\[([^\]]+)\])?[ ]* \n |
| 161 | 161 | }xm', |
| 162 | - array(&$this, '_doFencedFigures_callback'), |
|
| 163 | - $text |
|
| 164 | - ); |
|
| 165 | - |
|
| 166 | - return $text; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - function _doFencedFigures_callback($matches) |
|
| 170 | - { |
|
| 171 | - # get figcaption |
|
| 172 | - $topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]); |
|
| 173 | - $bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]); |
|
| 174 | - $figure = $matches[3]; |
|
| 175 | - $figure = $this->runBlockGamut($figure); # recurse |
|
| 176 | - |
|
| 177 | - $figure = preg_replace('/^/m', " ", $figure); |
|
| 178 | - # These leading spaces cause problem with <pre> content, |
|
| 179 | - # so we need to fix that - reuse blockqoute code to handle this: |
|
| 180 | - $figure = preg_replace_callback( |
|
| 181 | - '{(\s*<pre>.+?</pre>)}sx', |
|
| 182 | - array(&$this, '_doBlockQuotes_callback2'), |
|
| 183 | - $figure |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $res = "<figure>"; |
|
| 187 | - if (!empty($topcaption)) { |
|
| 188 | - $res .= "\n<figcaption>$topcaption</figcaption>"; |
|
| 189 | - } |
|
| 190 | - $res .= "\n$figure\n"; |
|
| 191 | - if (!empty($bottomcaption) && empty($topcaption)) { |
|
| 192 | - $res .= "<figcaption>$bottomcaption</figcaption>"; |
|
| 193 | - } |
|
| 194 | - $res .= "</figure>"; |
|
| 195 | - return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 196 | - } |
|
| 162 | + array(&$this, '_doFencedFigures_callback'), |
|
| 163 | + $text |
|
| 164 | + ); |
|
| 165 | + |
|
| 166 | + return $text; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + function _doFencedFigures_callback($matches) |
|
| 170 | + { |
|
| 171 | + # get figcaption |
|
| 172 | + $topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]); |
|
| 173 | + $bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]); |
|
| 174 | + $figure = $matches[3]; |
|
| 175 | + $figure = $this->runBlockGamut($figure); # recurse |
|
| 176 | + |
|
| 177 | + $figure = preg_replace('/^/m', " ", $figure); |
|
| 178 | + # These leading spaces cause problem with <pre> content, |
|
| 179 | + # so we need to fix that - reuse blockqoute code to handle this: |
|
| 180 | + $figure = preg_replace_callback( |
|
| 181 | + '{(\s*<pre>.+?</pre>)}sx', |
|
| 182 | + array(&$this, '_doBlockQuotes_callback2'), |
|
| 183 | + $figure |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $res = "<figure>"; |
|
| 187 | + if (!empty($topcaption)) { |
|
| 188 | + $res .= "\n<figcaption>$topcaption</figcaption>"; |
|
| 189 | + } |
|
| 190 | + $res .= "\n$figure\n"; |
|
| 191 | + if (!empty($bottomcaption) && empty($topcaption)) { |
|
| 192 | + $res .= "<figcaption>$bottomcaption</figcaption>"; |
|
| 193 | + } |
|
| 194 | + $res .= "</figure>"; |
|
| 195 | + return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 196 | + } |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | ?> |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! function_exists('Markdown')) { |
|
| 3 | +if ( ! function_exists('Markdown')) { |
|
| 4 | 4 | require_once('markdown_helper.php'); |
| 5 | 5 | } |
| 6 | 6 | define('MARKDOWNEXTRAEXTENDED_VERSION', "0.3"); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | function _doBlockQuotes_callback($matches) |
| 68 | 68 | { |
| 69 | 69 | $cite = $matches[1]; |
| 70 | - $bq = '> ' . $matches[2]; |
|
| 70 | + $bq = '> '.$matches[2]; |
|
| 71 | 71 | # trim one level of quoting - trim whitespace-only lines |
| 72 | 72 | $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); |
| 73 | 73 | $bq = $this->runBlockGamut($bq); # recurse |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $res = "<blockquote"; |
| 85 | 85 | $res .= empty($cite) ? ">" : " cite=\"$cite\">"; |
| 86 | 86 | $res .= "\n$bq\n</blockquote>"; |
| 87 | - return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 87 | + return "\n".$this->hashBlock($res)."\n\n"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function doFencedCodeBlocks($text) |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | $cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code"; |
| 134 | 134 | $cb .= empty($matches[2]) ? ">" : " class=\"language-$matches[2]\">"; |
| 135 | 135 | $cb .= "$codeblock</code></pre>"; |
| 136 | - return "\n\n" . $this->hashBlock($cb) . "\n\n"; |
|
| 136 | + return "\n\n".$this->hashBlock($cb)."\n\n"; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | function doFencedFigures($text) |
@@ -184,15 +184,15 @@ discard block |
||
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | $res = "<figure>"; |
| 187 | - if (!empty($topcaption)) { |
|
| 187 | + if ( ! empty($topcaption)) { |
|
| 188 | 188 | $res .= "\n<figcaption>$topcaption</figcaption>"; |
| 189 | 189 | } |
| 190 | 190 | $res .= "\n$figure\n"; |
| 191 | - if (!empty($bottomcaption) && empty($topcaption)) { |
|
| 191 | + if ( ! empty($bottomcaption) && empty($topcaption)) { |
|
| 192 | 192 | $res .= "<figcaption>$bottomcaption</figcaption>"; |
| 193 | 193 | } |
| 194 | 194 | $res .= "</figure>"; |
| 195 | - return "\n" . $this->hashBlock($res) . "\n\n"; |
|
| 195 | + return "\n".$this->hashBlock($res)."\n\n"; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $lang['cron.invalid_task'] = 'Not a valid task.'; |
| 36 | 36 | $lang['cron.running_task'] = "Running task: %s..."; |
| 37 | 37 | $lang['cron.done_with_msg'] = "Done with message:\n%s\n"; |
| 38 | -$lang['cron.not_scheduled_until'] = "'%s' Not scheduled to run until %s."; |
|
| 38 | +$lang['cron.not_scheduled_until'] = "'%s' Not scheduled to run until %s."; |
|
| 39 | 39 | $lang['cron.nothing_scheduled'] = "No Tasks scheduled to run currently."; |
| 40 | 40 | |
| 41 | 41 | // Forge |
@@ -3,117 +3,117 @@ |
||
| 3 | 3 | if (! class_exists('MY_Form_validation')) |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - class MY_Form_validation extends CI_Form_validation { |
|
| 7 | - /** |
|
| 8 | - * @var object The CodeIgniter core object. |
|
| 9 | - */ |
|
| 10 | - public $CI; |
|
| 11 | - |
|
| 12 | - //-------------------------------------------------------------------- |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Check if the field has an error associated with it. |
|
| 16 | - * |
|
| 17 | - * @param string $field The name of the field |
|
| 18 | - * |
|
| 19 | - * @return bool |
|
| 20 | - */ |
|
| 21 | - public function has_error( $field = NULL ) |
|
| 22 | - { |
|
| 23 | - if ( empty( $field ) ) |
|
| 24 | - { |
|
| 25 | - return FALSE; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - return ! empty( $this->_field_data[ $field ]['error'] ); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - //-------------------------------------------------------------------- |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Performs the actual form validation |
|
| 35 | - * |
|
| 36 | - * @param string $module Name of the module |
|
| 37 | - * @param string $group Name of the group array containing the rules |
|
| 38 | - * |
|
| 39 | - * @return bool Success or Failure |
|
| 40 | - */ |
|
| 41 | - public function run($group = '', $module = '') |
|
| 42 | - { |
|
| 43 | - is_object($module) && $this->CI =& $module; |
|
| 44 | - return parent::run($group); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - //-------------------------------------------------------------------- |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------- |
|
| 50 | - // Validation Rules |
|
| 51 | - //-------------------------------------------------------------------- |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Checks that a value is unique in the database. |
|
| 55 | - * |
|
| 56 | - * i.e. '…|required|unique[users.name,users.id]|trim…' |
|
| 57 | - * |
|
| 58 | - * <code> |
|
| 59 | - * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]" |
|
| 60 | - * </code> |
|
| 61 | - * |
|
| 62 | - * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/> |
|
| 63 | - * |
|
| 64 | - * @param mixed $value The value to be checked. |
|
| 65 | - * @param mixed $params The table and field to check against, if a second |
|
| 66 | - * field is passed in this is used as "AND NOT EQUAL". |
|
| 67 | - * |
|
| 68 | - * @return bool True if the value is unique for that field, else false. |
|
| 69 | - */ |
|
| 70 | - public function is_unique( $value, $params ) |
|
| 71 | - { |
|
| 72 | - if ( empty( $this->CI->db ) ) |
|
| 73 | - { |
|
| 74 | - $this->CI->load->database(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // Allow for more than 1 parameter. |
|
| 78 | - $fields = explode( ",", $params ); |
|
| 79 | - |
|
| 80 | - // Extract the table and field from the first parameter. |
|
| 81 | - list( $table, $field ) = explode( '.', $fields[0], 2 ); |
|
| 82 | - |
|
| 83 | - // Setup the db request. |
|
| 84 | - $this->CI->db->select( $field ) |
|
| 85 | - ->from( $table ) |
|
| 86 | - ->where( $field, $value ) |
|
| 87 | - ->limit( 1 ); |
|
| 88 | - |
|
| 89 | - // Check whether a second parameter was passed to be used as an |
|
| 90 | - // "AND NOT EQUAL" where clause |
|
| 91 | - // eg "select * from users where users.name='test' AND users.id != 4 |
|
| 92 | - if ( isset( $fields[1] ) ) |
|
| 93 | - { |
|
| 94 | - // Extract the table and field from the second parameter |
|
| 95 | - list( $where_table, $where_field ) = explode( '.', $fields[1], 2 ); |
|
| 96 | - |
|
| 97 | - // Get the value from the post's $where_field. If the value is set, |
|
| 98 | - // add "AND NOT EQUAL" where clause. |
|
| 99 | - $where_value = $this->CI->input->post( $where_field ); |
|
| 100 | - if ( isset( $where_value ) ) |
|
| 101 | - { |
|
| 102 | - $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // If any rows are returned from the database, validation fails |
|
| 107 | - $query = $this->CI->db->get(); |
|
| 108 | - if ( $query->row() ) |
|
| 109 | - { |
|
| 110 | - $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' ); |
|
| 111 | - |
|
| 112 | - return FALSE; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return TRUE; |
|
| 116 | - } |
|
| 117 | - } |
|
| 6 | + class MY_Form_validation extends CI_Form_validation { |
|
| 7 | + /** |
|
| 8 | + * @var object The CodeIgniter core object. |
|
| 9 | + */ |
|
| 10 | + public $CI; |
|
| 11 | + |
|
| 12 | + //-------------------------------------------------------------------- |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Check if the field has an error associated with it. |
|
| 16 | + * |
|
| 17 | + * @param string $field The name of the field |
|
| 18 | + * |
|
| 19 | + * @return bool |
|
| 20 | + */ |
|
| 21 | + public function has_error( $field = NULL ) |
|
| 22 | + { |
|
| 23 | + if ( empty( $field ) ) |
|
| 24 | + { |
|
| 25 | + return FALSE; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + return ! empty( $this->_field_data[ $field ]['error'] ); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + //-------------------------------------------------------------------- |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Performs the actual form validation |
|
| 35 | + * |
|
| 36 | + * @param string $module Name of the module |
|
| 37 | + * @param string $group Name of the group array containing the rules |
|
| 38 | + * |
|
| 39 | + * @return bool Success or Failure |
|
| 40 | + */ |
|
| 41 | + public function run($group = '', $module = '') |
|
| 42 | + { |
|
| 43 | + is_object($module) && $this->CI =& $module; |
|
| 44 | + return parent::run($group); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + //-------------------------------------------------------------------- |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------- |
|
| 50 | + // Validation Rules |
|
| 51 | + //-------------------------------------------------------------------- |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Checks that a value is unique in the database. |
|
| 55 | + * |
|
| 56 | + * i.e. '…|required|unique[users.name,users.id]|trim…' |
|
| 57 | + * |
|
| 58 | + * <code> |
|
| 59 | + * "unique[tablename.fieldname,tablename.(primaryKey-used-for-updates)]" |
|
| 60 | + * </code> |
|
| 61 | + * |
|
| 62 | + * @author Adapted from Burak Guzel <http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/> |
|
| 63 | + * |
|
| 64 | + * @param mixed $value The value to be checked. |
|
| 65 | + * @param mixed $params The table and field to check against, if a second |
|
| 66 | + * field is passed in this is used as "AND NOT EQUAL". |
|
| 67 | + * |
|
| 68 | + * @return bool True if the value is unique for that field, else false. |
|
| 69 | + */ |
|
| 70 | + public function is_unique( $value, $params ) |
|
| 71 | + { |
|
| 72 | + if ( empty( $this->CI->db ) ) |
|
| 73 | + { |
|
| 74 | + $this->CI->load->database(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // Allow for more than 1 parameter. |
|
| 78 | + $fields = explode( ",", $params ); |
|
| 79 | + |
|
| 80 | + // Extract the table and field from the first parameter. |
|
| 81 | + list( $table, $field ) = explode( '.', $fields[0], 2 ); |
|
| 82 | + |
|
| 83 | + // Setup the db request. |
|
| 84 | + $this->CI->db->select( $field ) |
|
| 85 | + ->from( $table ) |
|
| 86 | + ->where( $field, $value ) |
|
| 87 | + ->limit( 1 ); |
|
| 88 | + |
|
| 89 | + // Check whether a second parameter was passed to be used as an |
|
| 90 | + // "AND NOT EQUAL" where clause |
|
| 91 | + // eg "select * from users where users.name='test' AND users.id != 4 |
|
| 92 | + if ( isset( $fields[1] ) ) |
|
| 93 | + { |
|
| 94 | + // Extract the table and field from the second parameter |
|
| 95 | + list( $where_table, $where_field ) = explode( '.', $fields[1], 2 ); |
|
| 96 | + |
|
| 97 | + // Get the value from the post's $where_field. If the value is set, |
|
| 98 | + // add "AND NOT EQUAL" where clause. |
|
| 99 | + $where_value = $this->CI->input->post( $where_field ); |
|
| 100 | + if ( isset( $where_value ) ) |
|
| 101 | + { |
|
| 102 | + $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // If any rows are returned from the database, validation fails |
|
| 107 | + $query = $this->CI->db->get(); |
|
| 108 | + if ( $query->row() ) |
|
| 109 | + { |
|
| 110 | + $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' ); |
|
| 111 | + |
|
| 112 | + return FALSE; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return TRUE; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! class_exists('MY_Form_validation')) |
|
| 3 | +if ( ! class_exists('MY_Form_validation')) |
|
| 4 | 4 | { |
| 5 | 5 | |
| 6 | 6 | class MY_Form_validation extends CI_Form_validation { |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return bool |
| 20 | 20 | */ |
| 21 | - public function has_error( $field = NULL ) |
|
| 21 | + public function has_error($field = NULL) |
|
| 22 | 22 | { |
| 23 | - if ( empty( $field ) ) |
|
| 23 | + if (empty($field)) |
|
| 24 | 24 | { |
| 25 | 25 | return FALSE; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - return ! empty( $this->_field_data[ $field ]['error'] ); |
|
| 28 | + return ! empty($this->_field_data[$field]['error']); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | //-------------------------------------------------------------------- |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function run($group = '', $module = '') |
| 42 | 42 | { |
| 43 | - is_object($module) && $this->CI =& $module; |
|
| 43 | + is_object($module) && $this->CI = & $module; |
|
| 44 | 44 | return parent::run($group); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -67,47 +67,47 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @return bool True if the value is unique for that field, else false. |
| 69 | 69 | */ |
| 70 | - public function is_unique( $value, $params ) |
|
| 70 | + public function is_unique($value, $params) |
|
| 71 | 71 | { |
| 72 | - if ( empty( $this->CI->db ) ) |
|
| 72 | + if (empty($this->CI->db)) |
|
| 73 | 73 | { |
| 74 | 74 | $this->CI->load->database(); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Allow for more than 1 parameter. |
| 78 | - $fields = explode( ",", $params ); |
|
| 78 | + $fields = explode(",", $params); |
|
| 79 | 79 | |
| 80 | 80 | // Extract the table and field from the first parameter. |
| 81 | - list( $table, $field ) = explode( '.', $fields[0], 2 ); |
|
| 81 | + list($table, $field) = explode('.', $fields[0], 2); |
|
| 82 | 82 | |
| 83 | 83 | // Setup the db request. |
| 84 | - $this->CI->db->select( $field ) |
|
| 85 | - ->from( $table ) |
|
| 86 | - ->where( $field, $value ) |
|
| 87 | - ->limit( 1 ); |
|
| 84 | + $this->CI->db->select($field) |
|
| 85 | + ->from($table) |
|
| 86 | + ->where($field, $value) |
|
| 87 | + ->limit(1); |
|
| 88 | 88 | |
| 89 | 89 | // Check whether a second parameter was passed to be used as an |
| 90 | 90 | // "AND NOT EQUAL" where clause |
| 91 | 91 | // eg "select * from users where users.name='test' AND users.id != 4 |
| 92 | - if ( isset( $fields[1] ) ) |
|
| 92 | + if (isset($fields[1])) |
|
| 93 | 93 | { |
| 94 | 94 | // Extract the table and field from the second parameter |
| 95 | - list( $where_table, $where_field ) = explode( '.', $fields[1], 2 ); |
|
| 95 | + list($where_table, $where_field) = explode('.', $fields[1], 2); |
|
| 96 | 96 | |
| 97 | 97 | // Get the value from the post's $where_field. If the value is set, |
| 98 | 98 | // add "AND NOT EQUAL" where clause. |
| 99 | - $where_value = $this->CI->input->post( $where_field ); |
|
| 100 | - if ( isset( $where_value ) ) |
|
| 99 | + $where_value = $this->CI->input->post($where_field); |
|
| 100 | + if (isset($where_value)) |
|
| 101 | 101 | { |
| 102 | - $this->CI->db->where( "{$where_table}.{$where_field} !=", $where_value ); |
|
| 102 | + $this->CI->db->where("{$where_table}.{$where_field} !=", $where_value); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // If any rows are returned from the database, validation fails |
| 107 | 107 | $query = $this->CI->db->get(); |
| 108 | - if ( $query->row() ) |
|
| 108 | + if ($query->row()) |
|
| 109 | 109 | { |
| 110 | - $this->CI->form_validation->set_message( 'unique', 'The %s field is already in use.' ); |
|
| 110 | + $this->CI->form_validation->set_message('unique', 'The %s field is already in use.'); |
|
| 111 | 111 | |
| 112 | 112 | return FALSE; |
| 113 | 113 | } |
@@ -2,33 +2,33 @@ |
||
| 2 | 2 | |
| 3 | 3 | class CronMailer extends \Myth\Mail\BaseMailer { |
| 4 | 4 | |
| 5 | - protected $from = null; |
|
| 6 | - protected $to = null; |
|
| 7 | - |
|
| 8 | - public function __construct() |
|
| 9 | - { |
|
| 10 | - $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | - $this->to = config_item('site.auth_email'); |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - //-------------------------------------------------------------------- |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * Sends the output from the cronjob to the admin. |
|
| 18 | - * |
|
| 19 | - * @param $output |
|
| 20 | - */ |
|
| 21 | - public function results($output=null) |
|
| 22 | - { |
|
| 23 | - $data = [ |
|
| 24 | - 'output' => $output, |
|
| 25 | - 'site_name' => config_item('site.name') |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - // Send it immediately - don't queue. |
|
| 29 | - return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - //-------------------------------------------------------------------- |
|
| 5 | + protected $from = null; |
|
| 6 | + protected $to = null; |
|
| 7 | + |
|
| 8 | + public function __construct() |
|
| 9 | + { |
|
| 10 | + $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | + $this->to = config_item('site.auth_email'); |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + //-------------------------------------------------------------------- |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * Sends the output from the cronjob to the admin. |
|
| 18 | + * |
|
| 19 | + * @param $output |
|
| 20 | + */ |
|
| 21 | + public function results($output=null) |
|
| 22 | + { |
|
| 23 | + $data = [ |
|
| 24 | + 'output' => $output, |
|
| 25 | + 'site_name' => config_item('site.name') |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + // Send it immediately - don't queue. |
|
| 29 | + return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + //-------------------------------------------------------------------- |
|
| 33 | 33 | |
| 34 | 34 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | public function __construct() |
| 9 | 9 | { |
| 10 | - $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 10 | + $this->from = [config_item('site.auth_email'), config_item('site.name')]; |
|
| 11 | 11 | $this->to = config_item('site.auth_email'); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @param $output |
| 20 | 20 | */ |
| 21 | - public function results($output=null) |
|
| 21 | + public function results($output = null) |
|
| 22 | 22 | { |
| 23 | 23 | $data = [ |
| 24 | 24 | 'output' => $output, |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | ]; |
| 27 | 27 | |
| 28 | 28 | // Send it immediately - don't queue. |
| 29 | - return $this->send($this->to, "Cron Results from ". config_item('site.name'), $data); |
|
| 29 | + return $this->send($this->to, "Cron Results from ".config_item('site.name'), $data); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | //-------------------------------------------------------------------- |
@@ -2,85 +2,85 @@ |
||
| 2 | 2 | |
| 3 | 3 | class UserMailer extends \Myth\Mail\BaseMailer { |
| 4 | 4 | |
| 5 | - protected $from = null; |
|
| 6 | - protected $to = null; |
|
| 5 | + protected $from = null; |
|
| 6 | + protected $to = null; |
|
| 7 | 7 | |
| 8 | - public function __construct() |
|
| 9 | - { |
|
| 10 | - $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | - } |
|
| 8 | + public function __construct() |
|
| 9 | + { |
|
| 10 | + $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - //-------------------------------------------------------------------- |
|
| 13 | + //-------------------------------------------------------------------- |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Sends the output from the cronjob to the admin. |
|
| 17 | - * |
|
| 18 | - * The params array contains: |
|
| 19 | - * - user_id |
|
| 20 | ||
| 21 | - * - token |
|
| 22 | - * |
|
| 23 | - * @param $params |
|
| 24 | - * @return bool |
|
| 25 | - */ |
|
| 26 | - public function didRegister($params=null) |
|
| 27 | - { |
|
| 28 | - $data = [ |
|
| 29 | - 'user_id' => $params['user_id'], |
|
| 30 | - 'email' => $params['email'], |
|
| 31 | - 'link' => site_url( \Myth\Route::named('activate_user') ), |
|
| 32 | - 'token' => $params['token'], |
|
| 33 | - 'site_name' => config_item('site.name'), |
|
| 34 | - 'site_link' => site_url() |
|
| 35 | - ]; |
|
| 15 | + /** |
|
| 16 | + * Sends the output from the cronjob to the admin. |
|
| 17 | + * |
|
| 18 | + * The params array contains: |
|
| 19 | + * - user_id |
|
| 20 | ||
| 21 | + * - token |
|
| 22 | + * |
|
| 23 | + * @param $params |
|
| 24 | + * @return bool |
|
| 25 | + */ |
|
| 26 | + public function didRegister($params=null) |
|
| 27 | + { |
|
| 28 | + $data = [ |
|
| 29 | + 'user_id' => $params['user_id'], |
|
| 30 | + 'email' => $params['email'], |
|
| 31 | + 'link' => site_url( \Myth\Route::named('activate_user') ), |
|
| 32 | + 'token' => $params['token'], |
|
| 33 | + 'site_name' => config_item('site.name'), |
|
| 34 | + 'site_link' => site_url() |
|
| 35 | + ]; |
|
| 36 | 36 | |
| 37 | - // Send it immediately - don't queue. |
|
| 38 | - return $this->send($params['email'], lang('auth.register_subject'), $data); |
|
| 39 | - } |
|
| 37 | + // Send it immediately - don't queue. |
|
| 38 | + return $this->send($params['email'], lang('auth.register_subject'), $data); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - //-------------------------------------------------------------------- |
|
| 41 | + //-------------------------------------------------------------------- |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Sends the Password Reset Instructions email. |
|
| 45 | - * |
|
| 46 | - * @param array $user |
|
| 47 | - * @param string $token |
|
| 48 | - * @return bool |
|
| 49 | - */ |
|
| 50 | - public function remindUser($user, $token) |
|
| 51 | - { |
|
| 52 | - $data = [ |
|
| 53 | - 'email' => $user['email'], |
|
| 54 | - 'code' => $token, |
|
| 55 | - 'link' => site_url( \Myth\Route::named('reset_pass') ), |
|
| 56 | - 'site_name' => config_item('site.name'), |
|
| 57 | - 'site_link' => site_url() |
|
| 58 | - ]; |
|
| 43 | + /** |
|
| 44 | + * Sends the Password Reset Instructions email. |
|
| 45 | + * |
|
| 46 | + * @param array $user |
|
| 47 | + * @param string $token |
|
| 48 | + * @return bool |
|
| 49 | + */ |
|
| 50 | + public function remindUser($user, $token) |
|
| 51 | + { |
|
| 52 | + $data = [ |
|
| 53 | + 'email' => $user['email'], |
|
| 54 | + 'code' => $token, |
|
| 55 | + 'link' => site_url( \Myth\Route::named('reset_pass') ), |
|
| 56 | + 'site_name' => config_item('site.name'), |
|
| 57 | + 'site_link' => site_url() |
|
| 58 | + ]; |
|
| 59 | 59 | |
| 60 | - // Send it immediately - don't queue. |
|
| 61 | - return $this->send($user['email'], lang('auth.remind_subject'), $data); |
|
| 62 | - } |
|
| 60 | + // Send it immediately - don't queue. |
|
| 61 | + return $this->send($user['email'], lang('auth.remind_subject'), $data); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - //-------------------------------------------------------------------- |
|
| 64 | + //-------------------------------------------------------------------- |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Sends the Password Reset Confirmation email. |
|
| 68 | - * |
|
| 69 | - * @param array $user |
|
| 70 | - * @return bool |
|
| 71 | - */ |
|
| 72 | - public function resetPassword($user) |
|
| 73 | - { |
|
| 74 | - $data = [ |
|
| 75 | - 'email' => $user['email'], |
|
| 76 | - 'link' => site_url( \Myth\Route::named('forgot_pass') ), |
|
| 77 | - 'site_name' => config_item('site.name'), |
|
| 78 | - 'site_link' => site_url() |
|
| 79 | - ]; |
|
| 66 | + /** |
|
| 67 | + * Sends the Password Reset Confirmation email. |
|
| 68 | + * |
|
| 69 | + * @param array $user |
|
| 70 | + * @return bool |
|
| 71 | + */ |
|
| 72 | + public function resetPassword($user) |
|
| 73 | + { |
|
| 74 | + $data = [ |
|
| 75 | + 'email' => $user['email'], |
|
| 76 | + 'link' => site_url( \Myth\Route::named('forgot_pass') ), |
|
| 77 | + 'site_name' => config_item('site.name'), |
|
| 78 | + 'site_link' => site_url() |
|
| 79 | + ]; |
|
| 80 | 80 | |
| 81 | - // Send it immediately - don't queue. |
|
| 82 | - return $this->send($user['email'], lang('auth.reset_subject'), $data); |
|
| 83 | - } |
|
| 81 | + // Send it immediately - don't queue. |
|
| 82 | + return $this->send($user['email'], lang('auth.reset_subject'), $data); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - //-------------------------------------------------------------------- |
|
| 85 | + //-------------------------------------------------------------------- |
|
| 86 | 86 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | public function __construct() |
| 9 | 9 | { |
| 10 | - $this->from = [ config_item('site.auth_email'), config_item('site.name') ]; |
|
| 10 | + $this->from = [config_item('site.auth_email'), config_item('site.name')]; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | //-------------------------------------------------------------------- |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | * @param $params |
| 24 | 24 | * @return bool |
| 25 | 25 | */ |
| 26 | - public function didRegister($params=null) |
|
| 26 | + public function didRegister($params = null) |
|
| 27 | 27 | { |
| 28 | 28 | $data = [ |
| 29 | 29 | 'user_id' => $params['user_id'], |
| 30 | 30 | 'email' => $params['email'], |
| 31 | - 'link' => site_url( \Myth\Route::named('activate_user') ), |
|
| 31 | + 'link' => site_url(\Myth\Route::named('activate_user')), |
|
| 32 | 32 | 'token' => $params['token'], |
| 33 | 33 | 'site_name' => config_item('site.name'), |
| 34 | 34 | 'site_link' => site_url() |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $data = [ |
| 53 | 53 | 'email' => $user['email'], |
| 54 | 54 | 'code' => $token, |
| 55 | - 'link' => site_url( \Myth\Route::named('reset_pass') ), |
|
| 55 | + 'link' => site_url(\Myth\Route::named('reset_pass')), |
|
| 56 | 56 | 'site_name' => config_item('site.name'), |
| 57 | 57 | 'site_link' => site_url() |
| 58 | 58 | ]; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $data = [ |
| 75 | 75 | 'email' => $user['email'], |
| 76 | - 'link' => site_url( \Myth\Route::named('forgot_pass') ), |
|
| 76 | + 'link' => site_url(\Myth\Route::named('forgot_pass')), |
|
| 77 | 77 | 'site_name' => config_item('site.name'), |
| 78 | 78 | 'site_link' => site_url() |
| 79 | 79 | ]; |
@@ -1,310 +1,310 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @name CodeIgniter HMVC Modules |
|
| 4 | - * @author Jens Segers |
|
| 5 | - * @link http://www.jenssegers.be |
|
| 6 | - * @license MIT License Copyright (c) 2012 Jens Segers |
|
| 7 | - * |
|
| 8 | - * @author hArpanet |
|
| 9 | - * @link http://harpanet.com |
|
| 10 | - * Updated for CI 3.0-dev. |
|
| 11 | - * Added _set_default_controller() to allow default_controller |
|
| 12 | - * (specified in config/routes.php) to reside in a module of the same name. |
|
| 13 | - * |
|
| 14 | - * Inspired by wiredesignz's HMVC Router. |
|
| 15 | - * https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/ |
|
| 16 | - * |
|
| 17 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 18 | - * of this software and associated documentation files (the "Software"), to deal |
|
| 19 | - * in the Software without restriction, including without limitation the rights |
|
| 20 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 21 | - * copies of the Software, and to permit persons to whom the Software is |
|
| 22 | - * furnished to do so, subject to the following conditions: |
|
| 23 | - * |
|
| 24 | - * The above copyright notice and this permission notice shall be included in |
|
| 25 | - * all copies or substantial portions of the Software. |
|
| 26 | - * |
|
| 27 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 28 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 29 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 30 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 31 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 32 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 33 | - * THE SOFTWARE. |
|
| 34 | - */ |
|
| 3 | + * @name CodeIgniter HMVC Modules |
|
| 4 | + * @author Jens Segers |
|
| 5 | + * @link http://www.jenssegers.be |
|
| 6 | + * @license MIT License Copyright (c) 2012 Jens Segers |
|
| 7 | + * |
|
| 8 | + * @author hArpanet |
|
| 9 | + * @link http://harpanet.com |
|
| 10 | + * Updated for CI 3.0-dev. |
|
| 11 | + * Added _set_default_controller() to allow default_controller |
|
| 12 | + * (specified in config/routes.php) to reside in a module of the same name. |
|
| 13 | + * |
|
| 14 | + * Inspired by wiredesignz's HMVC Router. |
|
| 15 | + * https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/ |
|
| 16 | + * |
|
| 17 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
| 18 | + * of this software and associated documentation files (the "Software"), to deal |
|
| 19 | + * in the Software without restriction, including without limitation the rights |
|
| 20 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
| 21 | + * copies of the Software, and to permit persons to whom the Software is |
|
| 22 | + * furnished to do so, subject to the following conditions: |
|
| 23 | + * |
|
| 24 | + * The above copyright notice and this permission notice shall be included in |
|
| 25 | + * all copies or substantial portions of the Software. |
|
| 26 | + * |
|
| 27 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
| 28 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
| 29 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
| 30 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
| 31 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
| 32 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
| 33 | + * THE SOFTWARE. |
|
| 34 | + */ |
|
| 35 | 35 | |
| 36 | 36 | if (!defined("BASEPATH")) |
| 37 | - exit("No direct script access allowed"); |
|
| 37 | + exit("No direct script access allowed"); |
|
| 38 | 38 | |
| 39 | 39 | class HMVC_Router extends CI_Router { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Current module name |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - * @access public |
|
| 46 | - */ |
|
| 47 | - var $module = ''; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Constructor |
|
| 51 | - * |
|
| 52 | - * Runs the route mapping function. |
|
| 53 | - */ |
|
| 54 | - function __construct() { |
|
| 55 | - |
|
| 56 | - $this->config =& load_class('Config', 'core'); |
|
| 57 | - |
|
| 58 | - // Process 'modules_locations' from config |
|
| 59 | - $locations = $this->config->item('modules_locations'); |
|
| 60 | - |
|
| 61 | - if (!$locations) { |
|
| 62 | - $locations = array(APPPATH . 'modules/'); |
|
| 63 | - } else if (!is_array($locations)) { |
|
| 64 | - $locations = array($locations); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // Make sure all paths are the same format |
|
| 68 | - foreach ($locations as &$location) { |
|
| 69 | - $location = realpath($location); |
|
| 70 | - $location = str_replace('\\', '/', $location); |
|
| 71 | - $location = rtrim($location, '/') . '/'; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $this->config->set_item('modules_locations', $locations); |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - parent::__construct(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Validates the supplied segments. Attempts to determine the path to |
|
| 82 | - * the controller. |
|
| 83 | - * |
|
| 84 | - * @access private |
|
| 85 | - * @param array |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - function _validate_request($segments) { |
|
| 89 | - if (count($segments) == 0) { |
|
| 90 | - return $segments; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Locate the controller with modules support |
|
| 94 | - if ($located = $this->locate($segments)) { |
|
| 95 | - return $located; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Is there a 404 override? |
|
| 99 | - if (!empty($this->routes['404_override'])) { |
|
| 100 | - $segments = explode('/', $this->routes['404_override']); |
|
| 101 | - if ($located = $this->locate($segments)) { |
|
| 102 | - return $located; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Nothing else to do at this point but show a 404 |
|
| 107 | - show_404($segments[0]); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Parse Routes |
|
| 112 | - * |
|
| 113 | - * This function matches any routes that may exist in |
|
| 114 | - * the config/routes.php file against the URI to |
|
| 115 | - * determine if the class/method need to be remapped. |
|
| 116 | - * |
|
| 117 | - * NOTE: The first segment must stay the name of the |
|
| 118 | - * module, otherwise it is impossible to detect |
|
| 119 | - * the current module in this method. |
|
| 120 | - * |
|
| 121 | - * @access private |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - function _parse_routes() { |
|
| 125 | - // Apply the current module's routing config |
|
| 126 | - |
|
| 127 | - // CI v3.x has URI starting at segment 1 |
|
| 128 | - $segstart = (intval(substr(CI_VERSION,0,1)) > 2) ? 1 : 0; |
|
| 129 | - |
|
| 130 | - if ($module = $this->uri->segment($segstart)) { |
|
| 131 | - foreach ($this->config->item('modules_locations') as $location) { |
|
| 132 | - if (is_file($file = $location . $module . '/config/routes.php')) { |
|
| 133 | - include ($file); |
|
| 134 | - |
|
| 135 | - $route = (!isset($route) or !is_array($route)) ? array() : $route; |
|
| 136 | - $this->routes = array_merge($this->routes, $route); |
|
| 137 | - unset($route); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Let parent do the heavy routing |
|
| 143 | - return parent::_parse_routes(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * The logic of locating a controller is grouped in this function |
|
| 148 | - * |
|
| 149 | - * @param array |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - function locate($segments) { |
|
| 153 | - // anon function to ucfirst a string if CI ver > 2 (for backwards compatibility) |
|
| 154 | - $_ucfirst = function($cn) {return (intval(substr(CI_VERSION,0,1)) > 2) ? ucfirst($cn) : $cn;}; |
|
| 155 | - |
|
| 156 | - list($module, $directory, $controller) = array_pad($segments, 3, NULL); |
|
| 157 | - |
|
| 158 | - // Look for it in the standar APPPATH/controllers first so that it can override modules. |
|
| 159 | - $c = count($segments); |
|
| 160 | - $s = $segments; |
|
| 161 | - // Loop through our segments and return as soon as a controller |
|
| 162 | - // is found or when such a directory doesn't exist |
|
| 163 | - while ($c-- > 0) |
|
| 164 | - { |
|
| 165 | - $test = $this->directory |
|
| 166 | - .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $s[0]) : $s[0]); |
|
| 167 | - |
|
| 168 | - if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$s[0])) |
|
| 169 | - { |
|
| 170 | - $this->set_directory(array_shift($s), TRUE); |
|
| 171 | - continue; |
|
| 172 | - } |
|
| 173 | - elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
| 174 | - { |
|
| 175 | - return $s; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - unset($s); |
|
| 180 | - |
|
| 181 | - // Now look for it in all of our modules. |
|
| 182 | - foreach ($this->config->item('modules_locations') as $location) { |
|
| 183 | - $relative = $location; |
|
| 184 | - |
|
| 185 | - // Make path relative to controllers directory |
|
| 186 | - $start = rtrim(realpath(APPPATH), '/'); |
|
| 187 | - $parts = explode('/', str_replace('\\', '/', $start)); |
|
| 188 | - |
|
| 189 | - // Iterate all parts and replace absolute part with relative part |
|
| 190 | - for ($i = 1; $i <= count($parts); $i++) { |
|
| 191 | - $relative = str_replace(implode('/', $parts) . '/', str_repeat('../', $i), $relative, $count); |
|
| 192 | - array_pop($parts); |
|
| 193 | - |
|
| 194 | - // Stop iteration if found |
|
| 195 | - if ($count) |
|
| 196 | - break; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // Does a module exist? (/modules/xyz/controllers/) |
|
| 200 | - if (is_dir($source = $location . $module . '/controllers/')) { |
|
| 201 | - $this->module = $module; |
|
| 202 | - $this->directory = $relative . $module . '/controllers/'; |
|
| 203 | - |
|
| 204 | - // Module root controller? |
|
| 205 | - if ($directory && is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 206 | - $this->class = $directory; |
|
| 207 | - return array_slice($segments, 1); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Module sub-directory? |
|
| 211 | - if ($directory && is_dir($source . $directory . '/')) { |
|
| 212 | - $source = $source . $directory . '/'; |
|
| 213 | - $this->directory .= $directory . '/'; |
|
| 214 | - |
|
| 215 | - // Module sub-directory controller? |
|
| 216 | - if (is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 217 | - return array_slice($segments, 1); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // Module sub-directory default controller? |
|
| 221 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 222 | - $segments[1] = $this->default_controller; |
|
| 223 | - return array_slice($segments, 1); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Module sub-directory sub-controller? |
|
| 227 | - if ($controller && is_file($source . $_ucfirst($controller) . '.php')) { |
|
| 228 | - return array_slice($segments, 2); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Module controller? |
|
| 233 | - if (is_file($source . $_ucfirst($module) . '.php')) { |
|
| 234 | - return $segments; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Module default controller? |
|
| 238 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 239 | - $segments[0] = $this->default_controller; |
|
| 240 | - return $segments; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Default controller? |
|
| 246 | - if (is_file(APPPATH . 'controllers/' . $module . '/' . $_ucfirst($this->default_controller) . '.php')) { |
|
| 247 | - $segments[0] = $this->default_controller; |
|
| 248 | - return $segments; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Set the module name |
|
| 254 | - * |
|
| 255 | - * @param string |
|
| 256 | - * @return void |
|
| 257 | - */ |
|
| 258 | - function set_module($module) { |
|
| 259 | - $this->module = $module; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Set default controller |
|
| 264 | - * |
|
| 265 | - * First we check in normal APPPATH/controller's location, |
|
| 266 | - * then in Modules named after the default_controller |
|
| 267 | - * @author hArpanet - based on system/core/Router.php |
|
| 268 | - * |
|
| 269 | - * @return void |
|
| 270 | - */ |
|
| 271 | - protected function _set_default_controller() |
|
| 272 | - { |
|
| 273 | - // controller in APPPATH/controllers takes priority over module with same name |
|
| 274 | - parent::_set_default_controller(); |
|
| 275 | - |
|
| 276 | - // see if parent found a controller |
|
| 277 | - $class = $this->fetch_class(); |
|
| 278 | - |
|
| 279 | - if (empty($class)) { |
|
| 280 | - |
|
| 281 | - // no 'normal' controller found, |
|
| 282 | - // get the class/method from the default_controller route |
|
| 283 | - if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) |
|
| 284 | - { |
|
| 285 | - $method = 'index'; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // try to locate default controller in modules |
|
| 289 | - if ($located = $this->locate(array($class, $class, $method))) { |
|
| 290 | - |
|
| 291 | - log_message('debug', 'No URI present. Default module controller set.'); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // Nothing found - this will trigger 404 later |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // -------------------------------------------------------------------- |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Fetch the module |
|
| 303 | - * |
|
| 304 | - * @access public |
|
| 305 | - * @return string |
|
| 306 | - */ |
|
| 307 | - function fetch_module() { |
|
| 308 | - return $this->module; |
|
| 309 | - } |
|
| 41 | + /** |
|
| 42 | + * Current module name |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + * @access public |
|
| 46 | + */ |
|
| 47 | + var $module = ''; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Constructor |
|
| 51 | + * |
|
| 52 | + * Runs the route mapping function. |
|
| 53 | + */ |
|
| 54 | + function __construct() { |
|
| 55 | + |
|
| 56 | + $this->config =& load_class('Config', 'core'); |
|
| 57 | + |
|
| 58 | + // Process 'modules_locations' from config |
|
| 59 | + $locations = $this->config->item('modules_locations'); |
|
| 60 | + |
|
| 61 | + if (!$locations) { |
|
| 62 | + $locations = array(APPPATH . 'modules/'); |
|
| 63 | + } else if (!is_array($locations)) { |
|
| 64 | + $locations = array($locations); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // Make sure all paths are the same format |
|
| 68 | + foreach ($locations as &$location) { |
|
| 69 | + $location = realpath($location); |
|
| 70 | + $location = str_replace('\\', '/', $location); |
|
| 71 | + $location = rtrim($location, '/') . '/'; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $this->config->set_item('modules_locations', $locations); |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + parent::__construct(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Validates the supplied segments. Attempts to determine the path to |
|
| 82 | + * the controller. |
|
| 83 | + * |
|
| 84 | + * @access private |
|
| 85 | + * @param array |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + function _validate_request($segments) { |
|
| 89 | + if (count($segments) == 0) { |
|
| 90 | + return $segments; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Locate the controller with modules support |
|
| 94 | + if ($located = $this->locate($segments)) { |
|
| 95 | + return $located; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Is there a 404 override? |
|
| 99 | + if (!empty($this->routes['404_override'])) { |
|
| 100 | + $segments = explode('/', $this->routes['404_override']); |
|
| 101 | + if ($located = $this->locate($segments)) { |
|
| 102 | + return $located; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Nothing else to do at this point but show a 404 |
|
| 107 | + show_404($segments[0]); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Parse Routes |
|
| 112 | + * |
|
| 113 | + * This function matches any routes that may exist in |
|
| 114 | + * the config/routes.php file against the URI to |
|
| 115 | + * determine if the class/method need to be remapped. |
|
| 116 | + * |
|
| 117 | + * NOTE: The first segment must stay the name of the |
|
| 118 | + * module, otherwise it is impossible to detect |
|
| 119 | + * the current module in this method. |
|
| 120 | + * |
|
| 121 | + * @access private |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + function _parse_routes() { |
|
| 125 | + // Apply the current module's routing config |
|
| 126 | + |
|
| 127 | + // CI v3.x has URI starting at segment 1 |
|
| 128 | + $segstart = (intval(substr(CI_VERSION,0,1)) > 2) ? 1 : 0; |
|
| 129 | + |
|
| 130 | + if ($module = $this->uri->segment($segstart)) { |
|
| 131 | + foreach ($this->config->item('modules_locations') as $location) { |
|
| 132 | + if (is_file($file = $location . $module . '/config/routes.php')) { |
|
| 133 | + include ($file); |
|
| 134 | + |
|
| 135 | + $route = (!isset($route) or !is_array($route)) ? array() : $route; |
|
| 136 | + $this->routes = array_merge($this->routes, $route); |
|
| 137 | + unset($route); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Let parent do the heavy routing |
|
| 143 | + return parent::_parse_routes(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * The logic of locating a controller is grouped in this function |
|
| 148 | + * |
|
| 149 | + * @param array |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + function locate($segments) { |
|
| 153 | + // anon function to ucfirst a string if CI ver > 2 (for backwards compatibility) |
|
| 154 | + $_ucfirst = function($cn) {return (intval(substr(CI_VERSION,0,1)) > 2) ? ucfirst($cn) : $cn;}; |
|
| 155 | + |
|
| 156 | + list($module, $directory, $controller) = array_pad($segments, 3, NULL); |
|
| 157 | + |
|
| 158 | + // Look for it in the standar APPPATH/controllers first so that it can override modules. |
|
| 159 | + $c = count($segments); |
|
| 160 | + $s = $segments; |
|
| 161 | + // Loop through our segments and return as soon as a controller |
|
| 162 | + // is found or when such a directory doesn't exist |
|
| 163 | + while ($c-- > 0) |
|
| 164 | + { |
|
| 165 | + $test = $this->directory |
|
| 166 | + .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $s[0]) : $s[0]); |
|
| 167 | + |
|
| 168 | + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$s[0])) |
|
| 169 | + { |
|
| 170 | + $this->set_directory(array_shift($s), TRUE); |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 173 | + elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
| 174 | + { |
|
| 175 | + return $s; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + unset($s); |
|
| 180 | + |
|
| 181 | + // Now look for it in all of our modules. |
|
| 182 | + foreach ($this->config->item('modules_locations') as $location) { |
|
| 183 | + $relative = $location; |
|
| 184 | + |
|
| 185 | + // Make path relative to controllers directory |
|
| 186 | + $start = rtrim(realpath(APPPATH), '/'); |
|
| 187 | + $parts = explode('/', str_replace('\\', '/', $start)); |
|
| 188 | + |
|
| 189 | + // Iterate all parts and replace absolute part with relative part |
|
| 190 | + for ($i = 1; $i <= count($parts); $i++) { |
|
| 191 | + $relative = str_replace(implode('/', $parts) . '/', str_repeat('../', $i), $relative, $count); |
|
| 192 | + array_pop($parts); |
|
| 193 | + |
|
| 194 | + // Stop iteration if found |
|
| 195 | + if ($count) |
|
| 196 | + break; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // Does a module exist? (/modules/xyz/controllers/) |
|
| 200 | + if (is_dir($source = $location . $module . '/controllers/')) { |
|
| 201 | + $this->module = $module; |
|
| 202 | + $this->directory = $relative . $module . '/controllers/'; |
|
| 203 | + |
|
| 204 | + // Module root controller? |
|
| 205 | + if ($directory && is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 206 | + $this->class = $directory; |
|
| 207 | + return array_slice($segments, 1); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Module sub-directory? |
|
| 211 | + if ($directory && is_dir($source . $directory . '/')) { |
|
| 212 | + $source = $source . $directory . '/'; |
|
| 213 | + $this->directory .= $directory . '/'; |
|
| 214 | + |
|
| 215 | + // Module sub-directory controller? |
|
| 216 | + if (is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 217 | + return array_slice($segments, 1); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // Module sub-directory default controller? |
|
| 221 | + if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 222 | + $segments[1] = $this->default_controller; |
|
| 223 | + return array_slice($segments, 1); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Module sub-directory sub-controller? |
|
| 227 | + if ($controller && is_file($source . $_ucfirst($controller) . '.php')) { |
|
| 228 | + return array_slice($segments, 2); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Module controller? |
|
| 233 | + if (is_file($source . $_ucfirst($module) . '.php')) { |
|
| 234 | + return $segments; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Module default controller? |
|
| 238 | + if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 239 | + $segments[0] = $this->default_controller; |
|
| 240 | + return $segments; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Default controller? |
|
| 246 | + if (is_file(APPPATH . 'controllers/' . $module . '/' . $_ucfirst($this->default_controller) . '.php')) { |
|
| 247 | + $segments[0] = $this->default_controller; |
|
| 248 | + return $segments; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Set the module name |
|
| 254 | + * |
|
| 255 | + * @param string |
|
| 256 | + * @return void |
|
| 257 | + */ |
|
| 258 | + function set_module($module) { |
|
| 259 | + $this->module = $module; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Set default controller |
|
| 264 | + * |
|
| 265 | + * First we check in normal APPPATH/controller's location, |
|
| 266 | + * then in Modules named after the default_controller |
|
| 267 | + * @author hArpanet - based on system/core/Router.php |
|
| 268 | + * |
|
| 269 | + * @return void |
|
| 270 | + */ |
|
| 271 | + protected function _set_default_controller() |
|
| 272 | + { |
|
| 273 | + // controller in APPPATH/controllers takes priority over module with same name |
|
| 274 | + parent::_set_default_controller(); |
|
| 275 | + |
|
| 276 | + // see if parent found a controller |
|
| 277 | + $class = $this->fetch_class(); |
|
| 278 | + |
|
| 279 | + if (empty($class)) { |
|
| 280 | + |
|
| 281 | + // no 'normal' controller found, |
|
| 282 | + // get the class/method from the default_controller route |
|
| 283 | + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) |
|
| 284 | + { |
|
| 285 | + $method = 'index'; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // try to locate default controller in modules |
|
| 289 | + if ($located = $this->locate(array($class, $class, $method))) { |
|
| 290 | + |
|
| 291 | + log_message('debug', 'No URI present. Default module controller set.'); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // Nothing found - this will trigger 404 later |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // -------------------------------------------------------------------- |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Fetch the module |
|
| 303 | + * |
|
| 304 | + * @access public |
|
| 305 | + * @return string |
|
| 306 | + */ |
|
| 307 | + function fetch_module() { |
|
| 308 | + return $this->module; |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * THE SOFTWARE. |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | -if (!defined("BASEPATH")) |
|
| 36 | +if ( ! defined("BASEPATH")) |
|
| 37 | 37 | exit("No direct script access allowed"); |
| 38 | 38 | |
| 39 | 39 | class HMVC_Router extends CI_Router { |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | function __construct() { |
| 55 | 55 | |
| 56 | - $this->config =& load_class('Config', 'core'); |
|
| 56 | + $this->config = & load_class('Config', 'core'); |
|
| 57 | 57 | |
| 58 | 58 | // Process 'modules_locations' from config |
| 59 | 59 | $locations = $this->config->item('modules_locations'); |
| 60 | 60 | |
| 61 | - if (!$locations) { |
|
| 62 | - $locations = array(APPPATH . 'modules/'); |
|
| 63 | - } else if (!is_array($locations)) { |
|
| 61 | + if ( ! $locations) { |
|
| 62 | + $locations = array(APPPATH.'modules/'); |
|
| 63 | + } else if ( ! is_array($locations)) { |
|
| 64 | 64 | $locations = array($locations); |
| 65 | 65 | } |
| 66 | 66 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | foreach ($locations as &$location) { |
| 69 | 69 | $location = realpath($location); |
| 70 | 70 | $location = str_replace('\\', '/', $location); |
| 71 | - $location = rtrim($location, '/') . '/'; |
|
| 71 | + $location = rtrim($location, '/').'/'; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $this->config->set_item('modules_locations', $locations); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Is there a 404 override? |
| 99 | - if (!empty($this->routes['404_override'])) { |
|
| 99 | + if ( ! empty($this->routes['404_override'])) { |
|
| 100 | 100 | $segments = explode('/', $this->routes['404_override']); |
| 101 | 101 | if ($located = $this->locate($segments)) { |
| 102 | 102 | return $located; |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | // Apply the current module's routing config |
| 126 | 126 | |
| 127 | 127 | // CI v3.x has URI starting at segment 1 |
| 128 | - $segstart = (intval(substr(CI_VERSION,0,1)) > 2) ? 1 : 0; |
|
| 128 | + $segstart = (intval(substr(CI_VERSION, 0, 1)) > 2) ? 1 : 0; |
|
| 129 | 129 | |
| 130 | 130 | if ($module = $this->uri->segment($segstart)) { |
| 131 | 131 | foreach ($this->config->item('modules_locations') as $location) { |
| 132 | - if (is_file($file = $location . $module . '/config/routes.php')) { |
|
| 132 | + if (is_file($file = $location.$module.'/config/routes.php')) { |
|
| 133 | 133 | include ($file); |
| 134 | 134 | |
| 135 | - $route = (!isset($route) or !is_array($route)) ? array() : $route; |
|
| 135 | + $route = ( ! isset($route) or ! is_array($route)) ? array() : $route; |
|
| 136 | 136 | $this->routes = array_merge($this->routes, $route); |
| 137 | 137 | unset($route); |
| 138 | 138 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | function locate($segments) { |
| 153 | 153 | // anon function to ucfirst a string if CI ver > 2 (for backwards compatibility) |
| 154 | - $_ucfirst = function($cn) {return (intval(substr(CI_VERSION,0,1)) > 2) ? ucfirst($cn) : $cn;}; |
|
| 154 | + $_ucfirst = function($cn) {return (intval(substr(CI_VERSION, 0, 1)) > 2) ? ucfirst($cn) : $cn; }; |
|
| 155 | 155 | |
| 156 | 156 | list($module, $directory, $controller) = array_pad($segments, 3, NULL); |
| 157 | 157 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | $this->set_directory(array_shift($s), TRUE); |
| 171 | 171 | continue; |
| 172 | 172 | } |
| 173 | - elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
| 173 | + elseif (file_exists(APPPATH.'controllers/'.$test.'.php')) |
|
| 174 | 174 | { |
| 175 | 175 | return $s; |
| 176 | 176 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // Iterate all parts and replace absolute part with relative part |
| 190 | 190 | for ($i = 1; $i <= count($parts); $i++) { |
| 191 | - $relative = str_replace(implode('/', $parts) . '/', str_repeat('../', $i), $relative, $count); |
|
| 191 | + $relative = str_replace(implode('/', $parts).'/', str_repeat('../', $i), $relative, $count); |
|
| 192 | 192 | array_pop($parts); |
| 193 | 193 | |
| 194 | 194 | // Stop iteration if found |
@@ -197,45 +197,45 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Does a module exist? (/modules/xyz/controllers/) |
| 200 | - if (is_dir($source = $location . $module . '/controllers/')) { |
|
| 200 | + if (is_dir($source = $location.$module.'/controllers/')) { |
|
| 201 | 201 | $this->module = $module; |
| 202 | - $this->directory = $relative . $module . '/controllers/'; |
|
| 202 | + $this->directory = $relative.$module.'/controllers/'; |
|
| 203 | 203 | |
| 204 | 204 | // Module root controller? |
| 205 | - if ($directory && is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 205 | + if ($directory && is_file($source.$_ucfirst($directory).'.php')) { |
|
| 206 | 206 | $this->class = $directory; |
| 207 | 207 | return array_slice($segments, 1); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Module sub-directory? |
| 211 | - if ($directory && is_dir($source . $directory . '/')) { |
|
| 212 | - $source = $source . $directory . '/'; |
|
| 213 | - $this->directory .= $directory . '/'; |
|
| 211 | + if ($directory && is_dir($source.$directory.'/')) { |
|
| 212 | + $source = $source.$directory.'/'; |
|
| 213 | + $this->directory .= $directory.'/'; |
|
| 214 | 214 | |
| 215 | 215 | // Module sub-directory controller? |
| 216 | - if (is_file($source . $_ucfirst($directory) . '.php')) { |
|
| 216 | + if (is_file($source.$_ucfirst($directory).'.php')) { |
|
| 217 | 217 | return array_slice($segments, 1); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // Module sub-directory default controller? |
| 221 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 221 | + if (is_file($source.$_ucfirst($this->default_controller).'.php')) { |
|
| 222 | 222 | $segments[1] = $this->default_controller; |
| 223 | 223 | return array_slice($segments, 1); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Module sub-directory sub-controller? |
| 227 | - if ($controller && is_file($source . $_ucfirst($controller) . '.php')) { |
|
| 227 | + if ($controller && is_file($source.$_ucfirst($controller).'.php')) { |
|
| 228 | 228 | return array_slice($segments, 2); |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Module controller? |
| 233 | - if (is_file($source . $_ucfirst($module) . '.php')) { |
|
| 233 | + if (is_file($source.$_ucfirst($module).'.php')) { |
|
| 234 | 234 | return $segments; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Module default controller? |
| 238 | - if (is_file($source . $_ucfirst($this->default_controller) . '.php')) { |
|
| 238 | + if (is_file($source.$_ucfirst($this->default_controller).'.php')) { |
|
| 239 | 239 | $segments[0] = $this->default_controller; |
| 240 | 240 | return $segments; |
| 241 | 241 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Default controller? |
| 246 | - if (is_file(APPPATH . 'controllers/' . $module . '/' . $_ucfirst($this->default_controller) . '.php')) { |
|
| 246 | + if (is_file(APPPATH.'controllers/'.$module.'/'.$_ucfirst($this->default_controller).'.php')) { |
|
| 247 | 247 | $segments[0] = $this->default_controller; |
| 248 | 248 | return $segments; |
| 249 | 249 | } |
@@ -33,8 +33,9 @@ discard block |
||
| 33 | 33 | * THE SOFTWARE. |
| 34 | 34 | */ |
| 35 | 35 | |
| 36 | -if (!defined("BASEPATH")) |
|
| 36 | +if (!defined("BASEPATH")) { |
|
| 37 | 37 | exit("No direct script access allowed"); |
| 38 | +} |
|
| 38 | 39 | |
| 39 | 40 | class HMVC_Router extends CI_Router { |
| 40 | 41 | |
@@ -169,8 +170,7 @@ discard block |
||
| 169 | 170 | { |
| 170 | 171 | $this->set_directory(array_shift($s), TRUE); |
| 171 | 172 | continue; |
| 172 | - } |
|
| 173 | - elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
| 173 | + } elseif (file_exists(APPPATH .'controllers/'. $test .'.php')) |
|
| 174 | 174 | { |
| 175 | 175 | return $s; |
| 176 | 176 | } |
@@ -192,8 +192,9 @@ discard block |
||
| 192 | 192 | array_pop($parts); |
| 193 | 193 | |
| 194 | 194 | // Stop iteration if found |
| 195 | - if ($count) |
|
| 196 | - break; |
|
| 195 | + if ($count) { |
|
| 196 | + break; |
|
| 197 | + } |
|
| 197 | 198 | } |
| 198 | 199 | |
| 199 | 200 | // Does a module exist? (/modules/xyz/controllers/) |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | <p>If that was you - then click the link below to activate your account:</p> |
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | - <a href="<?= $link ."?e={$email}&code={$token}" ?>"> |
|
| 15 | - <?= $link ."?e={$email}&code={$token}" ?> |
|
| 14 | + <a href="<?= $link."?e={$email}&code={$token}" ?>"> |
|
| 15 | + <?= $link."?e={$email}&code={$token}" ?> |
|
| 16 | 16 | </a> |
| 17 | 17 | </p> |
| 18 | 18 | |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | |
| 6 | 6 | If that was you - then click the link below to activate your account: |
| 7 | 7 | |
| 8 | -<?= $link ."?e={$email}&code={$token}" ?> |
|
| 8 | +<?= $link."?e={$email}&code={$token}" ?> |
|
| 9 | 9 | |
| 10 | 10 | If the link does not work, please visit the following page: <?= $link ?> and enter the following token when asked: |
| 11 | 11 | |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | <p>If you do need to reset your password, please visit the following link:</p> |
| 12 | 12 | |
| 13 | 13 | <p> |
| 14 | - <a href="<?= $link ."?e={$email}&code={$code}" ?>"> |
|
| 15 | - <?= $link ."?e={$email}&code={$code}" ?> |
|
| 14 | + <a href="<?= $link."?e={$email}&code={$code}" ?>"> |
|
| 15 | + <?= $link."?e={$email}&code={$code}" ?> |
|
| 16 | 16 | </a> |
| 17 | 17 | </p> |
| 18 | 18 | |