@@ -3,175 +3,175 @@ |
||
3 | 3 | final class Loader |
4 | 4 | { |
5 | 5 | |
6 | - private $root; |
|
7 | - private $is_live; |
|
8 | - private $included_files = array(); |
|
9 | - |
|
10 | - private static $instance; |
|
11 | - |
|
12 | - private function __construct() |
|
13 | - { |
|
14 | - $this->is_live = (isset($_SERVER['HTTP_HOST']) && substr($_SERVER['HTTP_HOST'], 0, 4) !== 'dev.'); |
|
15 | - return $this; |
|
16 | - } |
|
17 | - |
|
18 | - public static function instance() |
|
19 | - { |
|
20 | - if(!isset(self::$instance)) |
|
21 | - self::$instance = new Loader(); |
|
22 | - return self::$instance; |
|
23 | - } |
|
24 | - |
|
25 | - private function get_root() |
|
26 | - { |
|
27 | - if(!isset($this->root)) |
|
28 | - { |
|
29 | - $current_directory = dirname(__FILE__); |
|
30 | - $current_directory = substr($current_directory, 0, -7); |
|
31 | - $this->root = $current_directory; |
|
32 | - } |
|
6 | + private $root; |
|
7 | + private $is_live; |
|
8 | + private $included_files = array(); |
|
9 | + |
|
10 | + private static $instance; |
|
11 | + |
|
12 | + private function __construct() |
|
13 | + { |
|
14 | + $this->is_live = (isset($_SERVER['HTTP_HOST']) && substr($_SERVER['HTTP_HOST'], 0, 4) !== 'dev.'); |
|
15 | + return $this; |
|
16 | + } |
|
17 | + |
|
18 | + public static function instance() |
|
19 | + { |
|
20 | + if(!isset(self::$instance)) |
|
21 | + self::$instance = new Loader(); |
|
22 | + return self::$instance; |
|
23 | + } |
|
24 | + |
|
25 | + private function get_root() |
|
26 | + { |
|
27 | + if(!isset($this->root)) |
|
28 | + { |
|
29 | + $current_directory = dirname(__FILE__); |
|
30 | + $current_directory = substr($current_directory, 0, -7); |
|
31 | + $this->root = $current_directory; |
|
32 | + } |
|
33 | 33 | |
34 | - return $this->root; |
|
35 | - } |
|
36 | - |
|
37 | - private function get_delimiter() |
|
38 | - { |
|
39 | - return (true || $this->is_live) ? '/' : '\\'; |
|
40 | - } |
|
41 | - |
|
42 | - private function check_delimiters($path) |
|
43 | - { |
|
44 | - return (true || $this->is_live) ? $path : str_replace('/', '\\', $path); |
|
45 | - } |
|
46 | - |
|
47 | - private static function get_class_name($path) |
|
48 | - { |
|
49 | - $path_array = explode('/', $path); |
|
50 | - return array_pop($path_array); |
|
51 | - } |
|
52 | - |
|
53 | - private static function get_extension($type) |
|
54 | - { |
|
55 | - switch($type) |
|
56 | - { |
|
57 | - case 'collector' : |
|
58 | - case 'controller' : |
|
59 | - case 'model' : |
|
60 | - case 'module' : |
|
61 | - case 'router' : |
|
62 | - case 'utility' : |
|
63 | - $extension = '.class.inc.php'; |
|
64 | - break; |
|
65 | - case 'view' : |
|
66 | - $extension = '.tpl.php'; |
|
67 | - break; |
|
68 | - } |
|
69 | - return $extension; |
|
70 | - } |
|
71 | - |
|
72 | - public static function getImagePath($type, $file) |
|
73 | - { |
|
74 | - $path = self::instance()->get_root(); |
|
75 | - $path .= 'public'; |
|
76 | - $path .= self::instance()->get_delimiter(); |
|
77 | - $path .= $type; |
|
78 | - $path .= self::instance()->get_delimiter(); |
|
79 | - $path .= self::instance()->check_delimiters($file); |
|
34 | + return $this->root; |
|
35 | + } |
|
36 | + |
|
37 | + private function get_delimiter() |
|
38 | + { |
|
39 | + return (true || $this->is_live) ? '/' : '\\'; |
|
40 | + } |
|
41 | + |
|
42 | + private function check_delimiters($path) |
|
43 | + { |
|
44 | + return (true || $this->is_live) ? $path : str_replace('/', '\\', $path); |
|
45 | + } |
|
46 | + |
|
47 | + private static function get_class_name($path) |
|
48 | + { |
|
49 | + $path_array = explode('/', $path); |
|
50 | + return array_pop($path_array); |
|
51 | + } |
|
52 | + |
|
53 | + private static function get_extension($type) |
|
54 | + { |
|
55 | + switch($type) |
|
56 | + { |
|
57 | + case 'collector' : |
|
58 | + case 'controller' : |
|
59 | + case 'model' : |
|
60 | + case 'module' : |
|
61 | + case 'router' : |
|
62 | + case 'utility' : |
|
63 | + $extension = '.class.inc.php'; |
|
64 | + break; |
|
65 | + case 'view' : |
|
66 | + $extension = '.tpl.php'; |
|
67 | + break; |
|
68 | + } |
|
69 | + return $extension; |
|
70 | + } |
|
71 | + |
|
72 | + public static function getImagePath($type, $file) |
|
73 | + { |
|
74 | + $path = self::instance()->get_root(); |
|
75 | + $path .= 'public'; |
|
76 | + $path .= self::instance()->get_delimiter(); |
|
77 | + $path .= $type; |
|
78 | + $path .= self::instance()->get_delimiter(); |
|
79 | + $path .= self::instance()->check_delimiters($file); |
|
80 | 80 | |
81 | - return $path; |
|
82 | - } |
|
83 | - |
|
84 | - private static function get_path($type, $file) |
|
85 | - { |
|
86 | - $path = self::instance()->get_root(); |
|
87 | - $path .= $type; |
|
88 | - $path .= self::instance()->get_delimiter(); |
|
89 | - $path .= self::instance()->check_delimiters($file); |
|
90 | - $path .= self::get_extension($type); |
|
81 | + return $path; |
|
82 | + } |
|
83 | + |
|
84 | + private static function get_path($type, $file) |
|
85 | + { |
|
86 | + $path = self::instance()->get_root(); |
|
87 | + $path .= $type; |
|
88 | + $path .= self::instance()->get_delimiter(); |
|
89 | + $path .= self::instance()->check_delimiters($file); |
|
90 | + $path .= self::get_extension($type); |
|
91 | 91 | |
92 | - return $path; |
|
93 | - } |
|
94 | - |
|
95 | - private function get_included_files() |
|
96 | - { |
|
97 | - return $this->included_files; |
|
98 | - } |
|
99 | - |
|
100 | - private function add_included_file($path) |
|
101 | - { |
|
102 | - $this->included_files[] = $path; |
|
103 | - } |
|
104 | - |
|
105 | - public static function load($type, $files, $data = array()) |
|
106 | - { |
|
107 | - foreach((array) $files as $file) |
|
108 | - { |
|
109 | - $file_path = self::instance()->get_path($type, $file); |
|
110 | - if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | - continue; |
|
92 | + return $path; |
|
93 | + } |
|
94 | + |
|
95 | + private function get_included_files() |
|
96 | + { |
|
97 | + return $this->included_files; |
|
98 | + } |
|
99 | + |
|
100 | + private function add_included_file($path) |
|
101 | + { |
|
102 | + $this->included_files[] = $path; |
|
103 | + } |
|
104 | + |
|
105 | + public static function load($type, $files, $data = array()) |
|
106 | + { |
|
107 | + foreach((array) $files as $file) |
|
108 | + { |
|
109 | + $file_path = self::instance()->get_path($type, $file); |
|
110 | + if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | + continue; |
|
112 | 112 | |
113 | - self::instance()->add_included_file($file_path); |
|
113 | + self::instance()->add_included_file($file_path); |
|
114 | 114 | |
115 | - switch($type) |
|
116 | - { |
|
117 | - case 'images' : |
|
118 | - case 'scripts' : |
|
119 | - case 'styles' : |
|
120 | - echo file_get_contents($file_path); |
|
121 | - break; |
|
122 | - case 'view' : |
|
123 | - extract($data); |
|
124 | - include($file_path); |
|
125 | - break; |
|
126 | - default : |
|
127 | - include_once($file_path); |
|
128 | - break; |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - private static function create_reflection_class($file) |
|
134 | - { |
|
135 | - $class_name = self::instance()->get_class_name($file); |
|
136 | - return new ReflectionClass($class_name); |
|
137 | - } |
|
138 | - |
|
139 | - public static function loadInstance($type, $file) |
|
140 | - { |
|
141 | - self::load($type, $file); |
|
115 | + switch($type) |
|
116 | + { |
|
117 | + case 'images' : |
|
118 | + case 'scripts' : |
|
119 | + case 'styles' : |
|
120 | + echo file_get_contents($file_path); |
|
121 | + break; |
|
122 | + case 'view' : |
|
123 | + extract($data); |
|
124 | + include($file_path); |
|
125 | + break; |
|
126 | + default : |
|
127 | + include_once($file_path); |
|
128 | + break; |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + private static function create_reflection_class($file) |
|
134 | + { |
|
135 | + $class_name = self::instance()->get_class_name($file); |
|
136 | + return new ReflectionClass($class_name); |
|
137 | + } |
|
138 | + |
|
139 | + public static function loadInstance($type, $file) |
|
140 | + { |
|
141 | + self::load($type, $file); |
|
142 | 142 | |
143 | - $reflectionObject = self::create_reflection_class($file); |
|
143 | + $reflectionObject = self::create_reflection_class($file); |
|
144 | 144 | |
145 | - if( |
|
146 | - $reflectionObject->hasMethod('instance') && |
|
147 | - $reflectionObject->getMethod('instance')->isStatic()) |
|
148 | - { |
|
149 | - return $reflectionObject->getMethod('instance')->invoke(null); |
|
150 | - } |
|
151 | - trigger_error("Requested class cannot be instance'd: {$type}, {$file}"); |
|
152 | - } |
|
153 | - |
|
154 | - public static function loadNew($type, $file, $data = array()) |
|
155 | - { |
|
156 | - self::load($type, $file); |
|
145 | + if( |
|
146 | + $reflectionObject->hasMethod('instance') && |
|
147 | + $reflectionObject->getMethod('instance')->isStatic()) |
|
148 | + { |
|
149 | + return $reflectionObject->getMethod('instance')->invoke(null); |
|
150 | + } |
|
151 | + trigger_error("Requested class cannot be instance'd: {$type}, {$file}"); |
|
152 | + } |
|
153 | + |
|
154 | + public static function loadNew($type, $file, $data = array()) |
|
155 | + { |
|
156 | + self::load($type, $file); |
|
157 | 157 | |
158 | - $reflectionObject = self::create_reflection_class($file); |
|
158 | + $reflectionObject = self::create_reflection_class($file); |
|
159 | 159 | |
160 | - if($reflectionObject->hasMethod('__construct')) |
|
161 | - return $reflectionObject->newInstanceArgs($data); |
|
162 | - else |
|
163 | - return $reflectionObject->newInstance(); |
|
164 | - } |
|
165 | - |
|
166 | - public static function getRoot() |
|
167 | - { |
|
168 | - return self::instance()->get_root(); |
|
169 | - } |
|
170 | - |
|
171 | - public static function isLive() |
|
172 | - { |
|
173 | - return self::instance()->is_live; |
|
174 | - } |
|
160 | + if($reflectionObject->hasMethod('__construct')) |
|
161 | + return $reflectionObject->newInstanceArgs($data); |
|
162 | + else |
|
163 | + return $reflectionObject->newInstance(); |
|
164 | + } |
|
165 | + |
|
166 | + public static function getRoot() |
|
167 | + { |
|
168 | + return self::instance()->get_root(); |
|
169 | + } |
|
170 | + |
|
171 | + public static function isLive() |
|
172 | + { |
|
173 | + return self::instance()->is_live; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | public static function getRootURL($site = '') |
177 | 177 | { |
@@ -3,71 +3,71 @@ |
||
3 | 3 | final class Search |
4 | 4 | { |
5 | 5 | |
6 | - private $query; |
|
7 | - private $result; |
|
8 | - private $weight; |
|
6 | + private $query; |
|
7 | + private $result; |
|
8 | + private $weight; |
|
9 | 9 | |
10 | - function __construct() |
|
11 | - { |
|
12 | - return $this; |
|
13 | - } |
|
10 | + function __construct() |
|
11 | + { |
|
12 | + return $this; |
|
13 | + } |
|
14 | 14 | |
15 | - public function setQuery($query) |
|
16 | - { |
|
17 | - $this->query = $query; |
|
18 | - return $this; |
|
19 | - } |
|
15 | + public function setQuery($query) |
|
16 | + { |
|
17 | + $this->query = $query; |
|
18 | + return $this; |
|
19 | + } |
|
20 | 20 | |
21 | - public function setResult($array) |
|
22 | - { |
|
23 | - $this->result = $array; |
|
24 | - return $this; |
|
25 | - } |
|
21 | + public function setResult($array) |
|
22 | + { |
|
23 | + $this->result = $array; |
|
24 | + return $this; |
|
25 | + } |
|
26 | 26 | |
27 | - public function setWeight($weight) |
|
28 | - { |
|
29 | - $this->weight = $weight; |
|
30 | - return $this; |
|
31 | - } |
|
27 | + public function setWeight($weight) |
|
28 | + { |
|
29 | + $this->weight = $weight; |
|
30 | + return $this; |
|
31 | + } |
|
32 | 32 | |
33 | - public static function instance() |
|
34 | - { |
|
35 | - $reflection = new ReflectionClass('Search'); |
|
36 | - return $reflection->newInstance(); |
|
37 | - } |
|
33 | + public static function instance() |
|
34 | + { |
|
35 | + $reflection = new ReflectionClass('Search'); |
|
36 | + return $reflection->newInstance(); |
|
37 | + } |
|
38 | 38 | |
39 | - public function perform() |
|
40 | - { |
|
41 | - $weighted_array = array(); |
|
42 | - foreach($this->result as $row) |
|
43 | - { |
|
44 | - $weight = $this->get_search_weight($row); |
|
45 | - if($weight > 0) |
|
46 | - $weighted_array[$row['id']] = $weight; |
|
47 | - } |
|
48 | - arsort($weighted_array); |
|
39 | + public function perform() |
|
40 | + { |
|
41 | + $weighted_array = array(); |
|
42 | + foreach($this->result as $row) |
|
43 | + { |
|
44 | + $weight = $this->get_search_weight($row); |
|
45 | + if($weight > 0) |
|
46 | + $weighted_array[$row['id']] = $weight; |
|
47 | + } |
|
48 | + arsort($weighted_array); |
|
49 | 49 | |
50 | - $final_array = array(); |
|
51 | - foreach($weighted_array as $id => $weight) |
|
52 | - { |
|
53 | - foreach($this->result as $row) |
|
54 | - { |
|
55 | - if($row['id'] == $id) |
|
56 | - $final_array[] = $row; |
|
57 | - } |
|
58 | - } |
|
59 | - return $final_array; |
|
60 | - } |
|
50 | + $final_array = array(); |
|
51 | + foreach($weighted_array as $id => $weight) |
|
52 | + { |
|
53 | + foreach($this->result as $row) |
|
54 | + { |
|
55 | + if($row['id'] == $id) |
|
56 | + $final_array[] = $row; |
|
57 | + } |
|
58 | + } |
|
59 | + return $final_array; |
|
60 | + } |
|
61 | 61 | |
62 | - private function get_search_weight($row) |
|
63 | - { |
|
64 | - $weight = 0; |
|
65 | - foreach($this->weight as $weight_array) |
|
66 | - { |
|
67 | - $text = $row[$weight_array['field']]; |
|
68 | - $weight += $weight_array['weight'] * substr_count(strtolower($text), strtolower($this->query)); |
|
69 | - } |
|
70 | - return $weight; |
|
71 | - } |
|
62 | + private function get_search_weight($row) |
|
63 | + { |
|
64 | + $weight = 0; |
|
65 | + foreach($this->weight as $weight_array) |
|
66 | + { |
|
67 | + $text = $row[$weight_array['field']]; |
|
68 | + $weight += $weight_array['weight'] * substr_count(strtolower($text), strtolower($this->query)); |
|
69 | + } |
|
70 | + return $weight; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
@@ -5,9 +5,9 @@ |
||
5 | 5 | class URLSafeContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - protected function execute() |
|
9 | - { |
|
10 | - $this->content = strtolower(str_replace(' ', '-', $this->content)); |
|
11 | - } |
|
8 | + protected function execute() |
|
9 | + { |
|
10 | + $this->content = strtolower(str_replace(' ', '-', $this->content)); |
|
11 | + } |
|
12 | 12 | |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -5,53 +5,53 @@ |
||
5 | 5 | final class MarkupCodeContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $MARKUP_DELIMITER = '@<pre( rel="(.*?)")?>(.*?)</pre>@s'; |
|
8 | + private static $MARKUP_DELIMITER = '@<pre( rel="(.*?)")?>(.*?)</pre>@s'; |
|
9 | 9 | |
10 | - protected function execute($title = '') |
|
11 | - { |
|
12 | - preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
|
13 | - if(count($matches[1]) == 0) |
|
14 | - return; |
|
10 | + protected function execute($title = '') |
|
11 | + { |
|
12 | + preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
|
13 | + if(count($matches[1]) == 0) |
|
14 | + return; |
|
15 | 15 | |
16 | - foreach($matches[3] as $key => $match) |
|
17 | - { |
|
18 | - $replacement = $match; |
|
19 | - $replacement = $this->wrap_in_list($replacement); |
|
20 | - $replacement = $this->highlight_code($replacement, $matches[2][$key]); |
|
16 | + foreach($matches[3] as $key => $match) |
|
17 | + { |
|
18 | + $replacement = $match; |
|
19 | + $replacement = $this->wrap_in_list($replacement); |
|
20 | + $replacement = $this->highlight_code($replacement, $matches[2][$key]); |
|
21 | 21 | |
22 | - $this->content = str_replace($match, $replacement, $this->content); |
|
23 | - } |
|
22 | + $this->content = str_replace($match, $replacement, $this->content); |
|
23 | + } |
|
24 | 24 | |
25 | - return; |
|
26 | - } |
|
25 | + return; |
|
26 | + } |
|
27 | 27 | |
28 | - private function wrap_in_list($content) |
|
29 | - { |
|
30 | - $content_array = explode("\n", $content); |
|
28 | + private function wrap_in_list($content) |
|
29 | + { |
|
30 | + $content_array = explode("\n", $content); |
|
31 | 31 | |
32 | - foreach($content_array as $key => $row) |
|
33 | - { |
|
34 | - $new_row = ($key % 2 == 0) ? '<li class="even">' : '<li class="odd">'; |
|
35 | - $new_row .= '<p>'; |
|
36 | - $new_row .= $row; |
|
37 | - $new_row .= '</p>'; |
|
38 | - $new_row .= '</li>'; |
|
39 | - $content_array[$key] = $new_row; |
|
40 | - } |
|
32 | + foreach($content_array as $key => $row) |
|
33 | + { |
|
34 | + $new_row = ($key % 2 == 0) ? '<li class="even">' : '<li class="odd">'; |
|
35 | + $new_row .= '<p>'; |
|
36 | + $new_row .= $row; |
|
37 | + $new_row .= '</p>'; |
|
38 | + $new_row .= '</li>'; |
|
39 | + $content_array[$key] = $new_row; |
|
40 | + } |
|
41 | 41 | |
42 | - $content = implode($content_array); |
|
43 | - $content = "<ol>{$content}</ol>"; |
|
44 | - return $content; |
|
45 | - } |
|
42 | + $content = implode($content_array); |
|
43 | + $content = "<ol>{$content}</ol>"; |
|
44 | + return $content; |
|
45 | + } |
|
46 | 46 | |
47 | - private function highlight_code($content, $type) |
|
48 | - { |
|
49 | - switch($type) |
|
50 | - { |
|
51 | - default : |
|
52 | - return $content; |
|
53 | - break; |
|
54 | - } |
|
55 | - } |
|
47 | + private function highlight_code($content, $type) |
|
48 | + { |
|
49 | + switch($type) |
|
50 | + { |
|
51 | + default : |
|
52 | + return $content; |
|
53 | + break; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | \ No newline at end of file |
@@ -5,143 +5,143 @@ |
||
5 | 5 | class SmartTrimContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $EXCLUDE_TAGS = array( |
|
9 | - 'a', |
|
10 | - 'div', |
|
11 | - 'h4', |
|
12 | - 'pre'); |
|
13 | - private static $INCLUDE_TAGS = array( |
|
14 | - 'li', |
|
15 | - 'ol', |
|
16 | - 'p', |
|
17 | - 'ul'); |
|
18 | - private static $PHOTO_PLACEHOLDER_MATCH = '/{{photo="(.*)"}}/'; |
|
19 | - private static $HTML_TAG_PATTERN = '/<[^>]+>/'; |
|
20 | - private static $CUT_MARKER = '/*/ CUT HERE /*/'; |
|
21 | - private static $RIGHT_BRACKET = '>'; |
|
22 | - private static $LEFT_BRACKET = '<'; |
|
23 | - private static $ETC = '…'; |
|
8 | + private static $EXCLUDE_TAGS = array( |
|
9 | + 'a', |
|
10 | + 'div', |
|
11 | + 'h4', |
|
12 | + 'pre'); |
|
13 | + private static $INCLUDE_TAGS = array( |
|
14 | + 'li', |
|
15 | + 'ol', |
|
16 | + 'p', |
|
17 | + 'ul'); |
|
18 | + private static $PHOTO_PLACEHOLDER_MATCH = '/{{photo="(.*)"}}/'; |
|
19 | + private static $HTML_TAG_PATTERN = '/<[^>]+>/'; |
|
20 | + private static $CUT_MARKER = '/*/ CUT HERE /*/'; |
|
21 | + private static $RIGHT_BRACKET = '>'; |
|
22 | + private static $LEFT_BRACKET = '<'; |
|
23 | + private static $ETC = '…'; |
|
24 | 24 | |
25 | - private $is_trimmed; |
|
25 | + private $is_trimmed; |
|
26 | 26 | |
27 | - protected function execute() |
|
28 | - { |
|
29 | - $args = func_get_args(); |
|
30 | - if(count($args) < 1) |
|
31 | - { |
|
32 | - trigger_error('Someone called SmartTrimContent w/o defining a length... bad!'); |
|
33 | - return; |
|
34 | - } |
|
27 | + protected function execute() |
|
28 | + { |
|
29 | + $args = func_get_args(); |
|
30 | + if(count($args) < 1) |
|
31 | + { |
|
32 | + trigger_error('Someone called SmartTrimContent w/o defining a length... bad!'); |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - if(count($args) == 2) |
|
37 | - $etc = $args[1]; |
|
38 | - else |
|
39 | - $etc = self::$ETC; |
|
36 | + if(count($args) == 2) |
|
37 | + $etc = $args[1]; |
|
38 | + else |
|
39 | + $etc = self::$ETC; |
|
40 | 40 | |
41 | - $length = $args[0]; |
|
41 | + $length = $args[0]; |
|
42 | 42 | |
43 | - if($length < strlen($this->content)) |
|
44 | - $this->trim_string($length); |
|
43 | + if($length < strlen($this->content)) |
|
44 | + $this->trim_string($length); |
|
45 | 45 | else |
46 | 46 | $etc = ''; |
47 | - $this->check_exclude_tags(); |
|
48 | - $this->close_tags($etc); |
|
49 | - } |
|
47 | + $this->check_exclude_tags(); |
|
48 | + $this->close_tags($etc); |
|
49 | + } |
|
50 | 50 | |
51 | - private function trim_string($length) |
|
52 | - { |
|
53 | - $content = $this->trim_html_string($this->content, $length); |
|
51 | + private function trim_string($length) |
|
52 | + { |
|
53 | + $content = $this->trim_html_string($this->content, $length); |
|
54 | 54 | |
55 | - $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
|
56 | - $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
|
57 | - if($last_left_bracket_position > $last_right_bracket_position) |
|
58 | - $content = substr($content, 0, $last_left_bracket_position); |
|
59 | - $content = trim($content); |
|
55 | + $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
|
56 | + $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
|
57 | + if($last_left_bracket_position > $last_right_bracket_position) |
|
58 | + $content = substr($content, 0, $last_left_bracket_position); |
|
59 | + $content = trim($content); |
|
60 | 60 | |
61 | - $this->content = $content; |
|
62 | - $this->is_trimmed = true; |
|
63 | - } |
|
61 | + $this->content = $content; |
|
62 | + $this->is_trimmed = true; |
|
63 | + } |
|
64 | 64 | |
65 | - private function trim_html_string($content, $length) |
|
66 | - { |
|
67 | - $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
|
68 | - preg_match_all(self::$HTML_TAG_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE); |
|
69 | - $content = strip_tags($content); |
|
65 | + private function trim_html_string($content, $length) |
|
66 | + { |
|
67 | + $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
|
68 | + preg_match_all(self::$HTML_TAG_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE); |
|
69 | + $content = strip_tags($content); |
|
70 | 70 | |
71 | - $content = wordwrap($content, $length, self::$CUT_MARKER); |
|
72 | - $content = explode(self::$CUT_MARKER, $content); |
|
73 | - $content = current($content); |
|
71 | + $content = wordwrap($content, $length, self::$CUT_MARKER); |
|
72 | + $content = explode(self::$CUT_MARKER, $content); |
|
73 | + $content = current($content); |
|
74 | 74 | |
75 | - $max_length = $length; |
|
76 | - foreach($matches[0] as $match) |
|
77 | - { |
|
78 | - $max_length += strlen($match[0]); |
|
79 | - if($max_length <= $match[1]) |
|
80 | - break; |
|
75 | + $max_length = $length; |
|
76 | + foreach($matches[0] as $match) |
|
77 | + { |
|
78 | + $max_length += strlen($match[0]); |
|
79 | + if($max_length <= $match[1]) |
|
80 | + break; |
|
81 | 81 | |
82 | - $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
|
83 | - } |
|
82 | + $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
|
83 | + } |
|
84 | 84 | |
85 | - if(substr($content, -7) == '</p><p>') |
|
86 | - $content = substr($content, 0, -7); |
|
85 | + if(substr($content, -7) == '</p><p>') |
|
86 | + $content = substr($content, 0, -7); |
|
87 | 87 | |
88 | - return $content; |
|
89 | - } |
|
88 | + return $content; |
|
89 | + } |
|
90 | 90 | |
91 | - private function check_exclude_tags() |
|
92 | - { |
|
93 | - $content = $this->content; |
|
94 | - $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
|
95 | - preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
|
91 | + private function check_exclude_tags() |
|
92 | + { |
|
93 | + $content = $this->content; |
|
94 | + $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
|
95 | + preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
|
96 | 96 | |
97 | - if(count($matches[1]) % 2 == 1) |
|
98 | - { |
|
99 | - $cut_tag = end($matches[1]); |
|
100 | - $cut_tag_position = $cut_tag[1] - 1; |
|
101 | - $content = substr($content, 0, $cut_tag_position); |
|
102 | - } |
|
103 | - $content = trim($content); |
|
97 | + if(count($matches[1]) % 2 == 1) |
|
98 | + { |
|
99 | + $cut_tag = end($matches[1]); |
|
100 | + $cut_tag_position = $cut_tag[1] - 1; |
|
101 | + $content = substr($content, 0, $cut_tag_position); |
|
102 | + } |
|
103 | + $content = trim($content); |
|
104 | 104 | |
105 | - $this->content = $content; |
|
106 | - } |
|
105 | + $this->content = $content; |
|
106 | + } |
|
107 | 107 | |
108 | - private function close_tags($etc) |
|
109 | - { |
|
110 | - $content = $this->content; |
|
111 | - $tags_preg = $this->get_tags_preg(self::$INCLUDE_TAGS); |
|
112 | - preg_match_all($tags_preg, $content, $matches); |
|
113 | - $open_tags = array(); |
|
108 | + private function close_tags($etc) |
|
109 | + { |
|
110 | + $content = $this->content; |
|
111 | + $tags_preg = $this->get_tags_preg(self::$INCLUDE_TAGS); |
|
112 | + preg_match_all($tags_preg, $content, $matches); |
|
113 | + $open_tags = array(); |
|
114 | 114 | |
115 | - foreach($matches[1] as $tag) |
|
116 | - { |
|
117 | - if(in_array($tag, $open_tags)) |
|
118 | - { |
|
119 | - $key = array_search($tag, $open_tags); |
|
120 | - unset($open_tags[$key]); |
|
121 | - } |
|
122 | - else |
|
123 | - $open_tags[] = $tag; |
|
124 | - } |
|
115 | + foreach($matches[1] as $tag) |
|
116 | + { |
|
117 | + if(in_array($tag, $open_tags)) |
|
118 | + { |
|
119 | + $key = array_search($tag, $open_tags); |
|
120 | + unset($open_tags[$key]); |
|
121 | + } |
|
122 | + else |
|
123 | + $open_tags[] = $tag; |
|
124 | + } |
|
125 | 125 | |
126 | - $open_tags = array_reverse($open_tags); |
|
127 | - if(count($open_tags) > 0) |
|
128 | - { |
|
129 | - foreach($open_tags as $key => $open_tag) |
|
130 | - { |
|
131 | - if($key == count($open_tags) - 1) |
|
132 | - $content .= $etc; |
|
133 | - $content .= "</{$open_tag}>"; |
|
134 | - } |
|
135 | - } |
|
136 | - else |
|
137 | - $content .= $etc; |
|
126 | + $open_tags = array_reverse($open_tags); |
|
127 | + if(count($open_tags) > 0) |
|
128 | + { |
|
129 | + foreach($open_tags as $key => $open_tag) |
|
130 | + { |
|
131 | + if($key == count($open_tags) - 1) |
|
132 | + $content .= $etc; |
|
133 | + $content .= "</{$open_tag}>"; |
|
134 | + } |
|
135 | + } |
|
136 | + else |
|
137 | + $content .= $etc; |
|
138 | 138 | |
139 | - $this->content = $content; |
|
140 | - } |
|
139 | + $this->content = $content; |
|
140 | + } |
|
141 | 141 | |
142 | - private function get_tags_preg($tag_array) |
|
143 | - { |
|
144 | - return '@</?(' . implode('|', $tag_array) . ')@'; |
|
145 | - } |
|
142 | + private function get_tags_preg($tag_array) |
|
143 | + { |
|
144 | + return '@</?(' . implode('|', $tag_array) . ')@'; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
@@ -5,104 +5,104 @@ |
||
5 | 5 | final class CleanCommentContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $LINK_PATTERN = '@<a.*href=["\']([^"\']*)["\'].*>(.*)</a>@i'; |
|
9 | - private static $BOLD_PATTERN = '@<b.*>(.*)</b>@i'; |
|
10 | - private static $ITALIC_PATTERN = '@<i.*>(.*)</i>@i'; |
|
11 | - private static $CODE_PATTERN = '@<pre[^>]*>(.*)</pre>@is'; |
|
8 | + private static $LINK_PATTERN = '@<a.*href=["\']([^"\']*)["\'].*>(.*)</a>@i'; |
|
9 | + private static $BOLD_PATTERN = '@<b.*>(.*)</b>@i'; |
|
10 | + private static $ITALIC_PATTERN = '@<i.*>(.*)</i>@i'; |
|
11 | + private static $CODE_PATTERN = '@<pre[^>]*>(.*)</pre>@is'; |
|
12 | 12 | |
13 | - private static $LINK_REPLACE = '<a href="%s" rel="nofollow" target="_blank">%s</a>'; |
|
14 | - private static $BOLD_REPLACE = '<b>%s</b>'; |
|
15 | - private static $ITALIC_REPLACE = '<i>%s</i>'; |
|
16 | - private static $CODE_REPLACE = '<pre>%s</pre>'; |
|
13 | + private static $LINK_REPLACE = '<a href="%s" rel="nofollow" target="_blank">%s</a>'; |
|
14 | + private static $BOLD_REPLACE = '<b>%s</b>'; |
|
15 | + private static $ITALIC_REPLACE = '<i>%s</i>'; |
|
16 | + private static $CODE_REPLACE = '<pre>%s</pre>'; |
|
17 | 17 | |
18 | - private static $URL_PATTERN = '@(https?://[a-z0-9\.-]+\.[a-z]{2,6}[^\s]*[^\.,\?\!;\s]+)@i'; |
|
19 | - private static $LINE_BREAK_PATTERN = '@([\r\n]+)@'; |
|
18 | + private static $URL_PATTERN = '@(https?://[a-z0-9\.-]+\.[a-z]{2,6}[^\s]*[^\.,\?\!;\s]+)@i'; |
|
19 | + private static $LINE_BREAK_PATTERN = '@([\r\n]+)@'; |
|
20 | 20 | |
21 | - private static $LINE_BREAK_REPLACE = '<br />'; |
|
21 | + private static $LINE_BREAK_REPLACE = '<br />'; |
|
22 | 22 | |
23 | - private $replacement_array = array(); |
|
23 | + private $replacement_array = array(); |
|
24 | 24 | |
25 | - protected function execute() |
|
26 | - { |
|
27 | - $this->process_element(self::$CODE_PATTERN, self::$CODE_REPLACE); |
|
28 | - $this->process_element(self::$LINK_PATTERN, self::$LINK_REPLACE); |
|
29 | - $this->process_element(self::$ITALIC_PATTERN, self::$ITALIC_REPLACE); |
|
30 | - $this->process_element(self::$BOLD_PATTERN, self::$BOLD_REPLACE); |
|
25 | + protected function execute() |
|
26 | + { |
|
27 | + $this->process_element(self::$CODE_PATTERN, self::$CODE_REPLACE); |
|
28 | + $this->process_element(self::$LINK_PATTERN, self::$LINK_REPLACE); |
|
29 | + $this->process_element(self::$ITALIC_PATTERN, self::$ITALIC_REPLACE); |
|
30 | + $this->process_element(self::$BOLD_PATTERN, self::$BOLD_REPLACE); |
|
31 | 31 | |
32 | - $this->strip_extra_tags(); |
|
32 | + $this->strip_extra_tags(); |
|
33 | 33 | |
34 | - $this->link_unlinked_urls(self::$URL_PATTERN, self::$LINK_REPLACE); |
|
35 | - $this->add_line_breaks(); |
|
36 | - $this->replace_element_patterns(); |
|
37 | - } |
|
38 | - |
|
39 | - private function process_element($pattern, $replace) |
|
40 | - { |
|
41 | - $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
34 | + $this->link_unlinked_urls(self::$URL_PATTERN, self::$LINK_REPLACE); |
|
35 | + $this->add_line_breaks(); |
|
36 | + $this->replace_element_patterns(); |
|
37 | + } |
|
38 | + |
|
39 | + private function process_element($pattern, $replace) |
|
40 | + { |
|
41 | + $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
42 | 42 | |
43 | - if($match_count < 1) |
|
44 | - return; |
|
43 | + if($match_count < 1) |
|
44 | + return; |
|
45 | 45 | |
46 | - foreach($matches as $match) |
|
47 | - { |
|
48 | - $full_match = array_shift($match); |
|
49 | - $placeholder = $this->create_placeholder($full_match); |
|
50 | - $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
46 | + foreach($matches as $match) |
|
47 | + { |
|
48 | + $full_match = array_shift($match); |
|
49 | + $placeholder = $this->create_placeholder($full_match); |
|
50 | + $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
51 | 51 | |
52 | - $this->content = preg_replace($full_match_pattern, $placeholder, $this->content, 1); |
|
53 | - $this->replacement_array[$placeholder] = vsprintf($replace, $match); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - private function create_placeholder($text) |
|
58 | - { |
|
59 | - return md5($text . rand()); |
|
60 | - } |
|
61 | - |
|
62 | - private function create_full_match_pattern($text) |
|
63 | - { |
|
64 | - $pattern = ''; |
|
65 | - $pattern .= '@'; |
|
66 | - $pattern .= preg_quote($text, '@'); |
|
67 | - $pattern .= '@'; |
|
68 | - $pattern .= 'i'; |
|
52 | + $this->content = preg_replace($full_match_pattern, $placeholder, $this->content, 1); |
|
53 | + $this->replacement_array[$placeholder] = vsprintf($replace, $match); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + private function create_placeholder($text) |
|
58 | + { |
|
59 | + return md5($text . rand()); |
|
60 | + } |
|
61 | + |
|
62 | + private function create_full_match_pattern($text) |
|
63 | + { |
|
64 | + $pattern = ''; |
|
65 | + $pattern .= '@'; |
|
66 | + $pattern .= preg_quote($text, '@'); |
|
67 | + $pattern .= '@'; |
|
68 | + $pattern .= 'i'; |
|
69 | 69 | |
70 | - return $pattern; |
|
71 | - } |
|
70 | + return $pattern; |
|
71 | + } |
|
72 | 72 | |
73 | - private function strip_extra_tags() |
|
74 | - { |
|
75 | - $this->content = strip_tags($this->content); |
|
76 | - } |
|
73 | + private function strip_extra_tags() |
|
74 | + { |
|
75 | + $this->content = strip_tags($this->content); |
|
76 | + } |
|
77 | 77 | |
78 | - private function link_unlinked_urls($pattern, $replace) |
|
79 | - { |
|
80 | - $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
78 | + private function link_unlinked_urls($pattern, $replace) |
|
79 | + { |
|
80 | + $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
81 | 81 | |
82 | - if($match_count < 1) |
|
83 | - return; |
|
82 | + if($match_count < 1) |
|
83 | + return; |
|
84 | 84 | |
85 | - foreach($matches as $match) |
|
86 | - { |
|
87 | - $full_match = array_shift($match); |
|
88 | - $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
89 | - $replace = sprintf($replace, $match[0], $match[0]); |
|
85 | + foreach($matches as $match) |
|
86 | + { |
|
87 | + $full_match = array_shift($match); |
|
88 | + $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
89 | + $replace = sprintf($replace, $match[0], $match[0]); |
|
90 | 90 | |
91 | - $this->content = preg_replace($full_match_pattern, $replace, $this->content, 1); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - private function add_line_breaks() |
|
96 | - { |
|
97 | - $this->content = preg_replace(self::$LINE_BREAK_PATTERN, self::$LINE_BREAK_REPLACE, $this->content); |
|
98 | - } |
|
99 | - |
|
100 | - private function replace_element_patterns() |
|
101 | - { |
|
102 | - foreach($this->replacement_array as $key => $replace) |
|
103 | - { |
|
104 | - $this->content = str_replace($key, $replace, $this->content); |
|
105 | - } |
|
106 | - } |
|
91 | + $this->content = preg_replace($full_match_pattern, $replace, $this->content, 1); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + private function add_line_breaks() |
|
96 | + { |
|
97 | + $this->content = preg_replace(self::$LINE_BREAK_PATTERN, self::$LINE_BREAK_REPLACE, $this->content); |
|
98 | + } |
|
99 | + |
|
100 | + private function replace_element_patterns() |
|
101 | + { |
|
102 | + foreach($this->replacement_array as $key => $replace) |
|
103 | + { |
|
104 | + $this->content = str_replace($key, $replace, $this->content); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | 108 | } |
109 | 109 | \ No newline at end of file |
@@ -5,47 +5,47 @@ |
||
5 | 5 | final class FetchFirstPhotoContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
9 | - private static $IMAGE_NODE = '<img src="%sphoto/%s/%s-size-%s.%s" height="%d" width="%d" alt="%s" />'; |
|
10 | - private static $DEFAULT_RETURN = ''; |
|
11 | - |
|
12 | - protected function execute($is_absolute = false, $size = 'thumb') |
|
13 | - { |
|
14 | - if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
15 | - $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
16 | - else |
|
17 | - $this->content = self::$DEFAULT_RETURN; |
|
18 | - return; |
|
19 | - } |
|
20 | - |
|
21 | - private function get_file_path($category, $photo, $size, $extension) |
|
22 | - { |
|
23 | - $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
24 | - return Loader::getImagePath('photo', $path); |
|
25 | - } |
|
26 | - |
|
27 | - private function get_thumb($string, $is_absolute, $size) |
|
28 | - { |
|
29 | - list($category, $file_name) = explode('/', $string); |
|
30 | - list($photo, $extension) = explode('.', $file_name); |
|
8 | + private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
9 | + private static $IMAGE_NODE = '<img src="%sphoto/%s/%s-size-%s.%s" height="%d" width="%d" alt="%s" />'; |
|
10 | + private static $DEFAULT_RETURN = ''; |
|
11 | + |
|
12 | + protected function execute($is_absolute = false, $size = 'thumb') |
|
13 | + { |
|
14 | + if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
15 | + $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
16 | + else |
|
17 | + $this->content = self::$DEFAULT_RETURN; |
|
18 | + return; |
|
19 | + } |
|
20 | + |
|
21 | + private function get_file_path($category, $photo, $size, $extension) |
|
22 | + { |
|
23 | + $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
24 | + return Loader::getImagePath('photo', $path); |
|
25 | + } |
|
26 | + |
|
27 | + private function get_thumb($string, $is_absolute, $size) |
|
28 | + { |
|
29 | + list($category, $file_name) = explode('/', $string); |
|
30 | + list($photo, $extension) = explode('.', $file_name); |
|
31 | 31 | |
32 | - $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
33 | - $file_size = getimagesize($file_path); |
|
32 | + $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
33 | + $file_size = getimagesize($file_path); |
|
34 | 34 | |
35 | - Loader::load('collector', 'image/PhotoCollector'); |
|
36 | - $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
37 | - if($photo_result == false) |
|
38 | - return ''; |
|
35 | + Loader::load('collector', 'image/PhotoCollector'); |
|
36 | + $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
37 | + if($photo_result == false) |
|
38 | + return ''; |
|
39 | 39 | |
40 | - $height = $file_size[1]; |
|
41 | - $width = $file_size[0]; |
|
42 | - $description = $photo_result->description; |
|
40 | + $height = $file_size[1]; |
|
41 | + $width = $file_size[0]; |
|
42 | + $description = $photo_result->description; |
|
43 | 43 | |
44 | - $domain = '/'; |
|
45 | - if($is_absolute) |
|
46 | - $domain = Loader::getRootURL(URLDecode::getSite()); |
|
44 | + $domain = '/'; |
|
45 | + if($is_absolute) |
|
46 | + $domain = Loader::getRootURL(URLDecode::getSite()); |
|
47 | 47 | |
48 | - return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
|
49 | - } |
|
48 | + return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -5,50 +5,50 @@ |
||
5 | 5 | final class FixPhotoContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
9 | - private static $ERROR_CONTENT = '<div class="photo-holder"><p class="photo-caption">Image (%s) could not be found!</p></div>'; |
|
10 | - private static $PHOTO_CONTENT = '<div class="photo-holder"><img src="%sphoto/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" /><p class="photo-caption">%s</p></div>'; |
|
8 | + private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
9 | + private static $ERROR_CONTENT = '<div class="photo-holder"><p class="photo-caption">Image (%s) could not be found!</p></div>'; |
|
10 | + private static $PHOTO_CONTENT = '<div class="photo-holder"><img src="%sphoto/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" /><p class="photo-caption">%s</p></div>'; |
|
11 | 11 | |
12 | - protected function execute($is_absolute = false, $size = 'medium') |
|
13 | - { |
|
14 | - preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
|
15 | - foreach($matches[1] as $key => $match) |
|
16 | - { |
|
17 | - $photo_content = $this->get_photo_content($match, $size, $is_absolute); |
|
18 | - $this->content = str_replace($matches[0][$key], $photo_content, $this->content); |
|
19 | - } |
|
20 | - return; |
|
21 | - } |
|
12 | + protected function execute($is_absolute = false, $size = 'medium') |
|
13 | + { |
|
14 | + preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
|
15 | + foreach($matches[1] as $key => $match) |
|
16 | + { |
|
17 | + $photo_content = $this->get_photo_content($match, $size, $is_absolute); |
|
18 | + $this->content = str_replace($matches[0][$key], $photo_content, $this->content); |
|
19 | + } |
|
20 | + return; |
|
21 | + } |
|
22 | 22 | |
23 | - private function get_file_path($category, $photo, $size, $extension) |
|
24 | - { |
|
25 | - $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
26 | - return Loader::getImagePath('photo', $path); |
|
27 | - } |
|
23 | + private function get_file_path($category, $photo, $size, $extension) |
|
24 | + { |
|
25 | + $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
26 | + return Loader::getImagePath('photo', $path); |
|
27 | + } |
|
28 | 28 | |
29 | - private function get_photo_content($string, $size, $is_absolute) |
|
30 | - { |
|
31 | - list($category, $file_name) = explode('/', $string); |
|
32 | - list($photo, $extension) = explode('.', $file_name); |
|
29 | + private function get_photo_content($string, $size, $is_absolute) |
|
30 | + { |
|
31 | + list($category, $file_name) = explode('/', $string); |
|
32 | + list($photo, $extension) = explode('.', $file_name); |
|
33 | 33 | |
34 | - $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
34 | + $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
35 | 35 | |
36 | - $file_size = getimagesize($file_path); |
|
36 | + $file_size = getimagesize($file_path); |
|
37 | 37 | |
38 | - Loader::load('collector', 'image/PhotoCollector'); |
|
39 | - $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
40 | - if($photo_result == false) |
|
41 | - return ''; |
|
38 | + Loader::load('collector', 'image/PhotoCollector'); |
|
39 | + $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
40 | + if($photo_result == false) |
|
41 | + return ''; |
|
42 | 42 | |
43 | - $height = $file_size[1]; |
|
44 | - $width = $file_size[0]; |
|
45 | - $description = $photo_result->description; |
|
43 | + $height = $file_size[1]; |
|
44 | + $width = $file_size[0]; |
|
45 | + $description = $photo_result->description; |
|
46 | 46 | |
47 | - $domain = '/'; |
|
48 | - if($is_absolute) |
|
49 | - $domain = Loader::getRootUrl('blog'); |
|
47 | + $domain = '/'; |
|
48 | + if($is_absolute) |
|
49 | + $domain = Loader::getRootUrl('blog'); |
|
50 | 50 | |
51 | - return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
|
52 | - } |
|
51 | + return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -5,69 +5,69 @@ |
||
5 | 5 | final class ElapsedTimeContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - protected function execute() |
|
9 | - { |
|
10 | - $previous_time = strtotime($this->content); |
|
11 | - $current_time = time(); |
|
8 | + protected function execute() |
|
9 | + { |
|
10 | + $previous_time = strtotime($this->content); |
|
11 | + $current_time = time(); |
|
12 | 12 | |
13 | - if($current_time <= $previous_time) |
|
14 | - $this->content = 'few seconds ago'; |
|
15 | - else if(($current_time - $previous_time) < 30) |
|
16 | - $this->content = 'few seconds ago'; |
|
17 | - else if(($current_time - $previous_time) < 1.5 * 60) |
|
18 | - $this->content = 'a minute ago'; |
|
19 | - else if(($current_time - $previous_time) < 4 * 60) |
|
20 | - $this->content = 'few minutes ago'; |
|
21 | - else if(($current_time - $previous_time) < 7 * 60) |
|
22 | - $this->content = 'five minutes ago'; |
|
23 | - else if(($current_time - $previous_time) < 12 * 60) |
|
24 | - $this->content = 'ten minutes ago'; |
|
25 | - else if(($current_time - $previous_time) < 17 * 60) |
|
26 | - $this->content = 'fifteen minutes ago'; |
|
27 | - else if(($current_time - $previous_time) < 22 * 60) |
|
28 | - $this->content = 'twenty minutes ago'; |
|
29 | - else if(($current_time - $previous_time) < 37 * 60) |
|
30 | - $this->content = 'half hour ago'; |
|
31 | - else if(($current_time - $previous_time) < 52 * 60) |
|
32 | - $this->content = 'forty-five minutes ago'; |
|
33 | - else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
34 | - $this->content = 'an hour ago'; |
|
35 | - else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
36 | - $this->content = 'two hours ago'; |
|
37 | - else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
38 | - $this->content = 'three hours ago'; |
|
39 | - else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
40 | - $this->content = 'few hours ago'; |
|
41 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
42 | - $this->content = 'this afternoon'; |
|
43 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
44 | - $this->content = 'this morning'; |
|
45 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
46 | - $this->content = 'yesterday evening'; |
|
47 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
48 | - $this->content = 'yesterday afternoon'; |
|
49 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
50 | - $this->content = 'yesterday morning'; |
|
51 | - else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
52 | - $this->content = 'two days ago'; |
|
53 | - else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
54 | - $this->content = 'three days ago'; |
|
55 | - else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
56 | - $this->content = 'earlier this week'; |
|
57 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
58 | - $this->content = 'late last week'; |
|
59 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
60 | - $this->content = 'early last week'; |
|
61 | - else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
62 | - $this->content = 'few weeks ago'; |
|
63 | - else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
64 | - $this->content = 'earlier this month'; |
|
65 | - else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
66 | - $this->content = 'last month'; |
|
67 | - else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
68 | - $this->content = 'several months ago'; |
|
69 | - else |
|
70 | - $this->content = 'long ago'; |
|
71 | - } |
|
13 | + if($current_time <= $previous_time) |
|
14 | + $this->content = 'few seconds ago'; |
|
15 | + else if(($current_time - $previous_time) < 30) |
|
16 | + $this->content = 'few seconds ago'; |
|
17 | + else if(($current_time - $previous_time) < 1.5 * 60) |
|
18 | + $this->content = 'a minute ago'; |
|
19 | + else if(($current_time - $previous_time) < 4 * 60) |
|
20 | + $this->content = 'few minutes ago'; |
|
21 | + else if(($current_time - $previous_time) < 7 * 60) |
|
22 | + $this->content = 'five minutes ago'; |
|
23 | + else if(($current_time - $previous_time) < 12 * 60) |
|
24 | + $this->content = 'ten minutes ago'; |
|
25 | + else if(($current_time - $previous_time) < 17 * 60) |
|
26 | + $this->content = 'fifteen minutes ago'; |
|
27 | + else if(($current_time - $previous_time) < 22 * 60) |
|
28 | + $this->content = 'twenty minutes ago'; |
|
29 | + else if(($current_time - $previous_time) < 37 * 60) |
|
30 | + $this->content = 'half hour ago'; |
|
31 | + else if(($current_time - $previous_time) < 52 * 60) |
|
32 | + $this->content = 'forty-five minutes ago'; |
|
33 | + else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
34 | + $this->content = 'an hour ago'; |
|
35 | + else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
36 | + $this->content = 'two hours ago'; |
|
37 | + else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
38 | + $this->content = 'three hours ago'; |
|
39 | + else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
40 | + $this->content = 'few hours ago'; |
|
41 | + else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
42 | + $this->content = 'this afternoon'; |
|
43 | + else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
44 | + $this->content = 'this morning'; |
|
45 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
46 | + $this->content = 'yesterday evening'; |
|
47 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
48 | + $this->content = 'yesterday afternoon'; |
|
49 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
50 | + $this->content = 'yesterday morning'; |
|
51 | + else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
52 | + $this->content = 'two days ago'; |
|
53 | + else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
54 | + $this->content = 'three days ago'; |
|
55 | + else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
56 | + $this->content = 'earlier this week'; |
|
57 | + else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
58 | + $this->content = 'late last week'; |
|
59 | + else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
60 | + $this->content = 'early last week'; |
|
61 | + else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
62 | + $this->content = 'few weeks ago'; |
|
63 | + else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
64 | + $this->content = 'earlier this month'; |
|
65 | + else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
66 | + $this->content = 'last month'; |
|
67 | + else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
68 | + $this->content = 'several months ago'; |
|
69 | + else |
|
70 | + $this->content = 'long ago'; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
74 | 74 | \ No newline at end of file |