diff options
-rw-r--r-- | application/Url.php | 32 | ||||
-rw-r--r-- | index.php | 15 | ||||
-rw-r--r-- | tests/Url/UrlTest.php | 7 | ||||
-rw-r--r-- | tpl/tagcloud.html | 4 |
4 files changed, 50 insertions, 8 deletions
diff --git a/application/Url.php b/application/Url.php index a4ac2e73..af38c4d9 100644 --- a/application/Url.php +++ b/application/Url.php | |||
@@ -118,7 +118,8 @@ class Url | |||
118 | */ | 118 | */ |
119 | public function __construct($url) | 119 | public function __construct($url) |
120 | { | 120 | { |
121 | $this->parts = parse_url(trim($url)); | 121 | $url = self::cleanupUnparsedUrl(trim($url)); |
122 | $this->parts = parse_url($url); | ||
122 | 123 | ||
123 | if (!empty($url) && empty($this->parts['scheme'])) { | 124 | if (!empty($url) && empty($this->parts['scheme'])) { |
124 | $this->parts['scheme'] = 'http'; | 125 | $this->parts['scheme'] = 'http'; |
@@ -126,6 +127,35 @@ class Url | |||
126 | } | 127 | } |
127 | 128 | ||
128 | /** | 129 | /** |
130 | * Clean up URL before it's parsed. | ||
131 | * ie. handle urlencode, url prefixes, etc. | ||
132 | * | ||
133 | * @param string $url URL to clean. | ||
134 | * | ||
135 | * @return string cleaned URL. | ||
136 | */ | ||
137 | protected static function cleanupUnparsedUrl($url) | ||
138 | { | ||
139 | return self::removeFirefoxAboutReader($url); | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * Remove Firefox Reader prefix if it's present. | ||
144 | * | ||
145 | * @param string $input url | ||
146 | * | ||
147 | * @return string cleaned url | ||
148 | */ | ||
149 | protected static function removeFirefoxAboutReader($input) | ||
150 | { | ||
151 | $firefoxPrefix = 'about://reader?url='; | ||
152 | if (startsWith($input, $firefoxPrefix)) { | ||
153 | return urldecode(ltrim($input, $firefoxPrefix)); | ||
154 | } | ||
155 | return $input; | ||
156 | } | ||
157 | |||
158 | /** | ||
129 | * Returns a string representation of this URL | 159 | * Returns a string representation of this URL |
130 | */ | 160 | */ |
131 | public function toString() | 161 | public function toString() |
@@ -1015,11 +1015,16 @@ function renderPage() | |||
1015 | return strcasecmp($a, $b); | 1015 | return strcasecmp($a, $b); |
1016 | }); | 1016 | }); |
1017 | 1017 | ||
1018 | $tagList=array(); | 1018 | $tagList = array(); |
1019 | foreach($tags as $key=>$value) | 1019 | foreach($tags as $key => $value) { |
1020 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. | 1020 | // Tag font size scaling: |
1021 | { | 1021 | // default 15 and 30 logarithm bases affect scaling, |
1022 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); | 1022 | // 22 and 6 are arbitrary font sizes for max and min sizes. |
1023 | $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8; | ||
1024 | $tagList[$key] = array( | ||
1025 | 'count' => $value, | ||
1026 | 'size' => number_format($size, 2, '.', ''), | ||
1027 | ); | ||
1023 | } | 1028 | } |
1024 | 1029 | ||
1025 | $data = array( | 1030 | $data = array( |
diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php index 425327ed..a64a73ea 100644 --- a/tests/Url/UrlTest.php +++ b/tests/Url/UrlTest.php | |||
@@ -128,6 +128,13 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
128 | self::$baseUrl.'?my=stuff&is=kept#again', | 128 | self::$baseUrl.'?my=stuff&is=kept#again', |
129 | $url->cleanup() | 129 | $url->cleanup() |
130 | ); | 130 | ); |
131 | |||
132 | // test firefox reader url | ||
133 | $url = new Url( | ||
134 | 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') | ||
135 | ); | ||
136 | $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); | ||
137 | |||
131 | } | 138 | } |
132 | 139 | ||
133 | /** | 140 | /** |
diff --git a/tpl/tagcloud.html b/tpl/tagcloud.html index 5891cd25..e449f293 100644 --- a/tpl/tagcloud.html +++ b/tpl/tagcloud.html | |||
@@ -12,8 +12,8 @@ | |||
12 | 12 | ||
13 | <div id="cloudtag"> | 13 | <div id="cloudtag"> |
14 | {loop="tags"} | 14 | {loop="tags"} |
15 | <span class="count">{$value.count}</span> | 15 | <span class="count">{$value.count}</span><a |
16 | <a href="?searchtags={$key|urlencode}" style="font-size:{$value.size}pt;">{$key}</a> | 16 | href="?searchtags={$key|urlencode}" style="font-size:{$value.size}em;">{$key}</a> |
17 | {loop="$value.tag_plugin"} | 17 | {loop="$value.tag_plugin"} |
18 | {$value} | 18 | {$value} |
19 | {/loop} | 19 | {/loop} |