diff --git a/system/admin/admin.php b/system/admin/admin.php index 24cc1cbf..3fa6a75d 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -31,6 +31,14 @@ function session($user, $pass, $str = null) { } } +// Clean URLs +function remove_accent($str) +{ + $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); + $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); + return str_replace($a, $b, $str); +} + // Edit blog posts function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) { @@ -40,11 +48,7 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag); $post_tag = str_replace(' ', '-',$post_tag); $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); - $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); - $post_url = str_replace(' ', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { @@ -90,11 +94,7 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) { $dir = substr($oldfile, 0, strrpos($oldfile, '/')); $post_title = $title; - $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); - $post_url = str_replace(' ', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { @@ -131,11 +131,7 @@ function add_post($title, $tag, $url, $content, $user) { $post_title = $title; $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag); $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); - $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); - $post_url = str_replace(' ', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = rtrim(ltrim($post_url, ' \,\.\-'), ' \,\.\-'); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { @@ -161,11 +157,7 @@ function add_post($title, $tag, $url, $content, $user) { function add_page($title, $url, $content) { $post_title = $title; - $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); - $post_url = str_replace(' ', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); $post_content = '' . "\n\n" . $content; if(!empty($post_title) && !empty($post_url) && !empty($post_content)) { @@ -251,11 +243,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) { $post_title = $title; $post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tags); $post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-'); - $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); - $post_url = str_replace(' ', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = str_replace('--', '-',$post_url); - $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); + $post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url))); if(!empty($source)) { $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; } @@ -306,12 +294,7 @@ function get_feed($feed_url, $credit, $message=null) { $title = rtrim($entry->title, ' \,\.\-'); $title = ltrim($title, ' \,\.\-'); $user = $_SESSION['user']; - $url = preg_replace('/[^A-Za-z0-9 .-]/u', '', strtolower($title)); - $url = str_replace(' ', '-',$url); - $url = str_replace('--', '-',$url); - $url = str_replace('--', '-',$url); - $url = rtrim($url, ',\.\-'); - $url = ltrim($url, ',\.\-'); + $url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($title))); if ($credit == 'yes') { $source = $entry->link; } diff --git a/system/includes/functions.php b/system/includes/functions.php index aabeaa8b..18c1c691 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -261,6 +261,7 @@ function get_tag($tag, $page, $perpage, $random){ $etag = explode(',', $tag); foreach ($mtag as $t) { foreach ($etag as $e) { + $e = trim($e); if($t === $e){ $tmp[] = $v; } @@ -272,6 +273,8 @@ function get_tag($tag, $page, $perpage, $random){ not_found(); } + $tmp = array_unique($tmp, SORT_REGULAR); + return $tmp = get_posts($tmp, $page, $perpage); } @@ -476,7 +479,7 @@ function get_related($tag) { $posts = get_tag(strip_tags($tag), 1, $perpage+1, true); $tmp = array(); $req = $_SERVER['REQUEST_URI']; - + foreach ($posts as $post) { $url = $post->url; if( strpos($url, $req) === false){ @@ -1469,7 +1472,7 @@ function Zip($source, $destination, $include_dir = false) { // TRUE if the current page is the front page. function is_front() { $req = $_SERVER['REQUEST_URI']; - if($req == site_path() . '/') { + if($req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false) { return true; } else { @@ -1480,7 +1483,7 @@ function is_front() { // TRUE if the current page is an index page like frontpage, tag index, archive index and search index. function is_index() { $req = $_SERVER['REQUEST_URI']; - if(strpos($req, '/archive/') !== false || strpos($req, '/tag/') !== false || strpos($req, '/search/') !== false || $req == site_path() . '/'){ + if(strpos($req, '/archive/') !== false || strpos($req, '/tag/') !== false || strpos($req, '/search/') !== false || $req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false){ return true; } else { @@ -1516,11 +1519,10 @@ function authorinfo($title=null, $body=null) { } function head_contents($title, $description, $canonical) { - $styleImage = config('lightbox'); $jq = config('jquery'); $output = ''; - + $title = '