@@ -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 |
@@ -5,74 +5,74 @@ discard block |
||
5 | 5 | final class FixInternalLinkContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $LINK_PLACEHOLDER_MATCH = '@{{link="([a-z0-9/-]*)"( anchor="([a-zA-Z0-9\s]*)")?}}@'; |
|
9 | - private static $ERROR_CONTENT = '<span>%s</span>'; |
|
10 | - private static $LINK_CONTENT = '<a href="%s" target="_blank" />%s</a>'; |
|
8 | + private static $LINK_PLACEHOLDER_MATCH = '@{{link="([a-z0-9/-]*)"( anchor="([a-zA-Z0-9\s]*)")?}}@'; |
|
9 | + private static $ERROR_CONTENT = '<span>%s</span>'; |
|
10 | + private static $LINK_CONTENT = '<a href="%s" target="_blank" />%s</a>'; |
|
11 | 11 | |
12 | - protected function execute($is_absolute = true) |
|
13 | - { |
|
14 | - preg_match_all(self::$LINK_PLACEHOLDER_MATCH, $this->content, $matches); |
|
15 | - foreach($matches[1] as $key => $match) |
|
16 | - { |
|
17 | - if(isset($matches[3][$key])) |
|
18 | - $link_content = $this->get_link($match, $is_absolute, $matches[3][$key]); |
|
19 | - else |
|
20 | - $link_content = $this->get_link($match, $is_absolute); |
|
21 | - $this->content = str_replace($matches[0][$key], $link_content, $this->content); |
|
22 | - } |
|
23 | - return; |
|
24 | - } |
|
12 | + protected function execute($is_absolute = true) |
|
13 | + { |
|
14 | + preg_match_all(self::$LINK_PLACEHOLDER_MATCH, $this->content, $matches); |
|
15 | + foreach($matches[1] as $key => $match) |
|
16 | + { |
|
17 | + if(isset($matches[3][$key])) |
|
18 | + $link_content = $this->get_link($match, $is_absolute, $matches[3][$key]); |
|
19 | + else |
|
20 | + $link_content = $this->get_link($match, $is_absolute); |
|
21 | + $this->content = str_replace($matches[0][$key], $link_content, $this->content); |
|
22 | + } |
|
23 | + return; |
|
24 | + } |
|
25 | 25 | |
26 | - private function get_link($string, $is_absolute, $anchor = '') |
|
27 | - { |
|
28 | - list($type, $uri) = explode('/', $string, 2); |
|
26 | + private function get_link($string, $is_absolute, $anchor = '') |
|
27 | + { |
|
28 | + list($type, $uri) = explode('/', $string, 2); |
|
29 | 29 | |
30 | - $link = ''; |
|
30 | + $link = ''; |
|
31 | 31 | |
32 | - switch($type) |
|
33 | - { |
|
34 | - case 'blog' : |
|
32 | + switch($type) |
|
33 | + { |
|
34 | + case 'blog' : |
|
35 | 35 | global $container; |
36 | 36 | $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
37 | 37 | $post = $repository->findPostByPath($uri); |
38 | 38 | |
39 | - if($post === NULL) |
|
40 | - return; |
|
39 | + if($post === NULL) |
|
40 | + return; |
|
41 | 41 | |
42 | - $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
|
43 | - $link .= "{$post['category']}/{$post['path']}/"; |
|
42 | + $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
|
43 | + $link .= "{$post['category']}/{$post['path']}/"; |
|
44 | 44 | |
45 | - if($anchor == '') |
|
46 | - $anchor = $post['title']; |
|
45 | + if($anchor == '') |
|
46 | + $anchor = $post['title']; |
|
47 | 47 | |
48 | - break; |
|
49 | - case 'blog-tag' : |
|
50 | - $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
|
51 | - $link .= "tag/{$uri}/"; |
|
48 | + break; |
|
49 | + case 'blog-tag' : |
|
50 | + $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
|
51 | + $link .= "tag/{$uri}/"; |
|
52 | 52 | |
53 | - if($anchor == '') |
|
54 | - { |
|
55 | - $anchor = $uri; |
|
56 | - $anchor = str_replace('-', ' ', $anchor); |
|
57 | - $anchor = ucwords($anchor); |
|
58 | - } |
|
53 | + if($anchor == '') |
|
54 | + { |
|
55 | + $anchor = $uri; |
|
56 | + $anchor = str_replace('-', ' ', $anchor); |
|
57 | + $anchor = ucwords($anchor); |
|
58 | + } |
|
59 | 59 | |
60 | - break; |
|
61 | - case 'journal' : |
|
62 | - Loader::load('collector', 'waterfall/LogCollector'); |
|
63 | - $log = LogCollector::getByAlias($uri); |
|
60 | + break; |
|
61 | + case 'journal' : |
|
62 | + Loader::load('collector', 'waterfall/LogCollector'); |
|
63 | + $log = LogCollector::getByAlias($uri); |
|
64 | 64 | |
65 | - if($log === NULL) |
|
66 | - return; |
|
65 | + if($log === NULL) |
|
66 | + return; |
|
67 | 67 | |
68 | - $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
69 | - $link .= "journal/{$log->alias}/"; |
|
68 | + $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
69 | + $link .= "journal/{$log->alias}/"; |
|
70 | 70 | |
71 | - if($anchor == '') |
|
72 | - $anchor = $log->title; |
|
71 | + if($anchor == '') |
|
72 | + $anchor = $log->title; |
|
73 | 73 | |
74 | - break; |
|
75 | - case 'falls' : |
|
74 | + break; |
|
75 | + case 'falls' : |
|
76 | 76 | $pieces = explode('/', $uri); |
77 | 77 | if (count($pieces) == 1) { |
78 | 78 | Loader::load('collector', 'waterfall/WatercourseCollector'); |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | $anchor = $waterfall->name; |
106 | 106 | } |
107 | 107 | } |
108 | - break; |
|
109 | - default : |
|
110 | - break; |
|
111 | - } |
|
108 | + break; |
|
109 | + default : |
|
110 | + break; |
|
111 | + } |
|
112 | 112 | |
113 | - return sprintf(self::$LINK_CONTENT, $link, $anchor); |
|
114 | - } |
|
113 | + return sprintf(self::$LINK_CONTENT, $link, $anchor); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |