diff --git a/languages/fv_tlc-pl_PL.mo b/languages/fv_tlc-pl_PL.mo new file mode 100644 index 0000000..91686bc Binary files /dev/null and b/languages/fv_tlc-pl_PL.mo differ diff --git a/languages/fv_tlc-pl_PL.po b/languages/fv_tlc-pl_PL.po new file mode 100644 index 0000000..40afdf3 --- /dev/null +++ b/languages/fv_tlc-pl_PL.po @@ -0,0 +1,65 @@ +msgid "" +msgstr "" +"Project-Id-Version: FV-topl-level-categories\n" +"POT-Creation-Date: 2015-05-01 00:15+0100\n" +"PO-Revision-Date: 2015-05-01 00:30+0100\n" +"Last-Translator: Maciej Gryniuk \n" +"Language-Team: Maciej Gryniuk \n" +"Language: pl_PL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.8beta1\n" +"X-Poedit-Basepath: .\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " +"|| n%100>=20) ? 1 : 2);\n" +"X-Poedit-KeywordsList: __;_e;_n\n" +"X-Poedit-SearchPath-0: ..\n" + +#: top-level-cats.php:3 +msgid "FV Top Level Categories" +msgstr "FV Kategorie najwyższego poziomu" + +#: top-level-cats.php:5 +msgid "" +"Removes the prefix from the URL for a category. For instance, if your old " +"category link was /category/catname it will now be /" +"catname" +msgstr "" +"Usuwa prefiks kategorii z adresu URL. Przykładowo, jeżeli Twój stary link do " +"kategorii wyglądał tak: /category/nazwakategorii, teraz będzie " +"taki: /nazwakategorii" + +#: top-level-cats.php:380 +msgid "Adjust categories in your post URLs" +msgstr "Dostosuj kategorie w adresach URL wpisów" + +#: top-level-cats.php:388 +msgid "Only use top-level categories in URLs." +msgstr "Używaj w adresach URL tylko kategorii najwyższego poziomu." + +#: top-level-cats.php:396 +msgid "Only allow following categories in URLs:" +msgstr "Dozwól jedynie następujące kategorie w adresach URL:" + +#: top-level-cats.php:403 +msgid "Save Changes" +msgstr "Zapisz zmiany" + +#: top-level-cats.php:407 +msgid "" +"Are you having any problems or questions? Use our support forums." +msgstr "" +"Doświadczasz jakiś problemów lub masz pytania? Skorzytaj z naszego forum wsparcia." + +#: top-level-cats.php:412 +msgid "" +"Since you are not using %category% in your post permalinks, there is nothing " +"to adjust." +msgstr "" +"Ponieważ nie używasz %category% w bezpośrednich odnośnikach wpisów, nie " +"musisz nic dostosowywać." diff --git a/languages/fv_tlc-sk_SK.po b/languages/fv_tlc-sk_SK.po index 4cc0de0..7d6eafd 100644 --- a/languages/fv_tlc-sk_SK.po +++ b/languages/fv_tlc-sk_SK.po @@ -1,50 +1,50 @@ -msgid "" -msgstr "" -"Project-Id-Version: FV-topl-level-categories\n" -"POT-Creation-Date: 2014-09-19 11:37+0100\n" -"PO-Revision-Date: 2014-09-19 11:49+0100\n" -"Last-Translator: \n" -"Language-Team: \n" -"Language: sk_SK\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.6.9\n" -"X-Poedit-Basepath: .\n" -"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" -"X-Poedit-KeywordsList: __;_e;_n\n" -"X-Poedit-SearchPath-0: ..\n" - -#: ../top-level-cats.php:374 -msgid "Adjust categories in your post URLs" -msgstr "Nastavenie kategórií v URL adresách postov" - -#: ../top-level-cats.php:382 -msgid "Only use top-level catogories in URLs." -msgstr "Použiť iba hlavné kategórie v adresách URL." - -#: ../top-level-cats.php:390 -msgid "Only allow following categories in URLs:" -msgstr "V URL adresách povoliť iba nasledujúce kategórie:" - -#: ../top-level-cats.php:397 -msgid "Save Changes" -msgstr "Uložiť zmeny" - -#: ../top-level-cats.php:401 -msgid "" -"Are you having any problems or questions? Use our support forums." -msgstr "" -"Máte nejaké problémy alebo otázky? Použite naše forúm podpory." - -#: ../top-level-cats.php:406 -msgid "" -"Since you are not using %category% in your post permalinks, there is nothing " -"to adjust." -msgstr "" -"Keďže vo svojích post permalinkoch nepoužívate %category% nie je tu nič čo " -"by ste mohli nastaviť." +msgid "" +msgstr "" +"Project-Id-Version: FV-topl-level-categories\n" +"POT-Creation-Date: 2014-09-19 11:37+0100\n" +"PO-Revision-Date: 2014-09-19 11:49+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: sk_SK\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.6.9\n" +"X-Poedit-Basepath: .\n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" +"X-Poedit-KeywordsList: __;_e;_n\n" +"X-Poedit-SearchPath-0: ..\n" + +#: ../top-level-cats.php:374 +msgid "Adjust categories in your post URLs" +msgstr "Nastavenie kategórií v URL adresách postov" + +#: ../top-level-cats.php:382 +msgid "Only use top-level categories in URLs." +msgstr "Použiť iba hlavné kategórie v adresách URL." + +#: ../top-level-cats.php:390 +msgid "Only allow following categories in URLs:" +msgstr "V URL adresách povoliť iba nasledujúce kategórie:" + +#: ../top-level-cats.php:397 +msgid "Save Changes" +msgstr "Uložiť zmeny" + +#: ../top-level-cats.php:401 +msgid "" +"Are you having any problems or questions? Use our support forums." +msgstr "" +"Máte nejaké problémy alebo otázky? Použite naše forúm podpory." + +#: ../top-level-cats.php:406 +msgid "" +"Since you are not using %category% in your post permalinks, there is nothing " +"to adjust." +msgstr "" +"Keďže vo svojích post permalinkoch nepoužívate %category% nie je tu nič čo " +"by ste mohli nastaviť." \ No newline at end of file diff --git a/readme.txt b/readme.txt index a5f3eee..5786d43 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: FolioVision Donate link: http://foliovision.com/seo-tools/wordpress/plugins/fv-top-level-categories Tags: categories, permalink Requires at least: 3.2.1 -Tested up to: 4.1 +Tested up to: 4.2.1 Stable tag: trunk This is a fix of Top Level Categories plugin for Wordpress 3.1. and above. @@ -45,6 +45,11 @@ Make sure your categories have unique slugs - watch out for pages with the same == Changelog == += Version 1.7- May 12th, 2014 = + +* Added Polish translation - thanks to maciejka45@gmail.com +* Added Portuguese translation - thanks to Pedro Mendona + = Version 1.6 - September 19th, 2014 = * Adding support for translations ( Slovak language added ) diff --git a/top-level-cats.php b/top-level-cats.php index f215e3c..32912de 100644 --- a/top-level-cats.php +++ b/top-level-cats.php @@ -1,422 +1,434 @@ -/category/catname it will now be /catname -Version: 1.6 -Author: Foliovision -Author URI: http://foliovision.com/ -*/ - -register_activation_hook(__FILE__,'fv_top_level_categories_refresh_rules'); - -add_action('created_category','fv_top_level_categories_refresh_rules'); -add_action('edited_category','fv_top_level_categories_refresh_rules'); -add_action('delete_category','fv_top_level_categories_refresh_rules'); - -function fv_top_level_categories_refresh_rules() { - add_option('fv_top_level_categories_rewrite_rules_flush', 'true'); -} -register_deactivation_hook(__FILE__,'fv_top_level_categories_deactivate'); - -function fv_top_level_categories_deactivate() { - remove_filter('category_rewrite_rules', 'fv_top_level_categories_refresh_rules'); // We don't want to insert our custom rules again - delete_option('fv_top_level_categories_rewrite_rules_flush'); -} - -// Remove category base -add_action('init', 'fv_top_level_categories_permastruct'); -function fv_top_level_categories_permastruct() { - global $wp_rewrite; - $wp_rewrite->extra_permastructs['category'][0] = '%category%'; - - if (get_option('fv_top_level_categories_rewrite_rules_flush') == 'true') { - flush_rewrite_rules(); - delete_option('fv_top_level_categories_rewrite_rules_flush'); - } -} - -// Add our custom category rewrite rules -add_filter('category_rewrite_rules', 'fv_top_level_categories_rewrite_rules'); -function fv_top_level_categories_rewrite_rules($category_rewrite) { - //var_dump($category_rewrite); // For Debugging - - /// First we need to get full URLs of our pages - $pages = get_pages( 'number=0' ); - $pages_urls = array(); - foreach( $pages AS $pages_item ) { - $pages_urls[] = trim( str_replace( get_bloginfo( 'url' ), '', get_permalink( $pages_item->ID ) ), '/' ); - } - /// - - $category_rewrite=array(); - $categories=get_categories(array('hide_empty'=>false)); - foreach($categories as $category) { - $category_nicename = $category->slug; - if ( $category->parent == $category->cat_ID ) // recursive recursion - $category->parent = 0; - elseif ($category->parent != 0 ) - $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; - - /// Let's check if any of the category full URLs matches any of the pages - if( in_array( $category_nicename, $pages_urls ) ) { - continue; - } - /// - - - $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; - $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; - $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]'; - } - // Redirect support from Old Category Base - global $wp_rewrite; - $old_category_base = get_option('category_base') ? get_option('category_base') : 'category'; - $old_category_base = trim($old_category_base, '/'); - $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]'; - - //var_dump($category_rewrite); // For Debugging - return $category_rewrite; -} - -//Redirect to TL parent categ, if "Only use top-level catogories in URLs." is on -add_filter('template_redirect', 'fv_top_level_categories_tlc_redirect', 999, 2); -function fv_top_level_categories_tlc_redirect( $link ) { - if( FV_Top_Level_Cats::is_top_level_only() && is_single() ) { - global $wp_query; - $requested_url = is_ssl() ? 'https://' : 'http://'; - $requested_url .= $_SERVER['HTTP_HOST']; - $requested_url .= $_SERVER['REQUEST_URI']; - - $real_permalink = get_permalink($wp_query->queried_object_id); - - if( FALSE === stripos($requested_url, $real_permalink) ) { - - $bMached = preg_match('~/([^/:]+/?)$~',$real_permalink, $end_of_permalink); - if( $bMached && preg_match('~'.$end_of_permalink[1].'(.+)$~', $requested_url, $end_of_url) ) - wp_redirect( $real_permalink . $end_of_url[1], 301 ); - else - wp_redirect( $real_permalink, 301 ); - die(); - } - } - - return $link; -} - -// Add 'category_redirect' query variable -add_filter('query_vars', 'fv_top_level_categories_query_vars'); -function fv_top_level_categories_query_vars($public_query_vars) { - $public_query_vars[] = 'category_redirect'; - return $public_query_vars; -} - -// Redirect if 'category_redirect' is set -add_filter('request', 'fv_top_level_categories_request'); -function fv_top_level_categories_request($query_vars) { - //print_r($query_vars); // For Debugging - if(isset($query_vars['category_redirect'])) { - $catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' ); - status_header(301); - header("Location: $catlink"); - exit(); - } - return $query_vars; -} - -add_filter('category_link', 'top_level_cats_remove_cat_base'); -function top_level_cats_remove_cat_base($link) { - $category_base = get_option('category_base'); - - // WP uses "category/" as the default - if ($category_base == '') - $category_base = 'category'; - - // Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash) - if (substr($category_base, 0, 1) == '/') - $category_base = substr($category_base, 1); - - $category_base .= '/'; - - return preg_replace('|' . $category_base . '|', '', $link, 1); -} - - - - -function fv_top_level_cats_post_link_category_top_level_only( $cat ) { - if( !FV_Top_Level_Cats::is_category_permalinks() ) { - return $cat; - } - - while( FV_Top_Level_Cats::is_top_level_only() && $cat->parent != 0 ) { - $cat = get_term_by( 'id', $cat->parent, 'category' ); - } - - return $cat; -} -add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_top_level_only', 201, 3 ); - - - - -function fv_top_level_cats_post_link_category_restrict( $cat ) { - if( !FV_Top_Level_Cats::is_category_permalinks() || !FV_Top_Level_Cats::is_category_restriction() ) { - return $cat; - } - - $aArgs = func_get_args(); - - $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats(); - if( !count($aAllowedCats) ) { - return $cat; - } - - // check if the main category is allowed - if( in_array( $cat->term_id, $aAllowedCats ) ) { - return $cat; - } - - // check if any of the other categories is allowed! - $isOk = false; - foreach( $aArgs[1] AS $objCat ) { - if( in_array( $objCat->term_id, $aAllowedCats ) ) { - $isOk = true; - $cat = $objCat; - } - } - - // check if any of the parent categories is allowed - if( !$isOk ) { - foreach( $aArgs[1] AS $objCat ) { - while( $objCat->parent != 0 ) { - $objCat = get_term_by( 'id', $objCat->parent, 'category' ); - } - if( in_array( $objCat->term_id, $aAllowedCats ) ) { - $isOk = true; - $cat = $objCat; - } - } - } - - return $cat; -} -add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_restrict', 200, 3 ); - - - - -function fv_top_level_category_filter( $aCategories ) { - if( class_exists('FV_Top_Level_Cats') && method_exists('FV_Top_Level_Cats','get_allowed_cats') ) { - - $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats(); - if( !count($aAllowedCats) ) { - return $aCategories; - } - - // check if the main category is allowed - foreach( $aCategories AS $objCat ) { - if( in_array( $objCat->term_id, $aAllowedCats ) ) { - return array($objCat); - } - } - - foreach( $aCategories AS $objCat ) { - while( $objCat->parent != 0 ) { - $objCat = get_term_by( 'id', $objCat->parent, 'category' ); - } - if( in_array( $objCat->term_id, $aAllowedCats ) ) { - return array($objCat); - } - } - } - return $aCategories; -} - - - - - -function fv_top_level_category( $separator = '', $parents = '', $post_id = false ) { - add_filter( 'get_the_categories', 'fv_top_level_category_filter' ); - the_category( $separator, $parents, $post_id ); - remove_filter( 'get_the_categories', 'fv_top_level_category_filter' ); -} -add_action( 'fv_top_level_category', 'fv_top_level_category', 10, 3 ); - - - - -class FV_Top_Level_Cats { - - var $enabled; - var $default_form_code; - var $default_form_css; - - - - - public function __construct() { - add_action( 'admin_menu', array($this, 'admin_menu') ); - add_action('init',array($this,'load_languages')); - } - - - - - function admin_menu() { - add_options_page( 'FV Top Level Categories', 'FV Top Level Categories', 'manage_options', 'fv_top_level_cats', array($this, 'options_panel') ); - } - - - - - public static function get_allowed_cats() { - $options = get_option( 'fv_top_level_cats' ); - if( isset($options['category-allow']) ) { - return $options['category-allow']; - } else { - return false; - } - } - - - - - public static function is_category_permalinks() { - $sPermalinks = get_option( 'permalink_structure' ); - if( stripos($sPermalinks, '%category%/') !== false ) { - return true; - } else { - return false; - } - } - - - - - function load_languages(){ - // Localization - load_plugin_textdomain('fv_tlc', false, dirname(plugin_basename(__FILE__)) . "/languages"); - } - - - - - public static function is_top_level_only() { - $options = get_option( 'fv_top_level_cats' ); - if( isset($options['top-level-only']) && $options['top-level-only'] ) { - return true; - } else { - return false; - } - } - - - - - public static function is_category_restriction() { - $options = get_option( 'fv_top_level_cats' ); - if( isset($options['category-allow-enabled']) && $options['category-allow-enabled'] ) { - return true; - } else { - return false; - } - } - - - - - function options_panel() { - - if (!empty($_POST)) : - - check_admin_referer('fv_top_level_cats'); - - if( isset($_POST['fv_top_level_cats_submit'] ) ) : - $options = get_option( 'fv_top_level_cats', array() ); - - $options['category-allow'] = $_POST['post_category']; - $options['top-level-only'] = ( $_POST['top-level-only'] ) ? true : false; - $options['category-allow-enabled'] = ( $_POST['category-allow-enabled'] ) ? true : false; - - update_option( 'fv_top_level_cats', $options ); -?> -
-

- - Settings saved - -

-
- - -
-
- visit foliovision -
-
-

-

FV Top Level Categories

-
- - is_category_permalinks() ) : ?> - -
- -
-
-

- -

-
- - - - - - - -
- -
- -
-
-

- -

-
-
-

support forums.','fv_tlc'); ?>

-
- -
- -

- - -
- - -/category/catname it will now be /catname +Version: 1.7 +Author: Foliovision +Author URI: http://foliovision.com/ +Text Domain: fv_tlc +Domain Path: /languages/ +*/ + +register_activation_hook(__FILE__,'fv_top_level_categories_refresh_rules'); + +add_action('created_category','fv_top_level_categories_refresh_rules'); +add_action('edited_category','fv_top_level_categories_refresh_rules'); +add_action('delete_category','fv_top_level_categories_refresh_rules'); + +function fv_top_level_categories_refresh_rules() { + add_option('fv_top_level_categories_rewrite_rules_flush', 'true'); +} +register_deactivation_hook(__FILE__,'fv_top_level_categories_deactivate'); + +function fv_top_level_categories_deactivate() { + remove_filter('category_rewrite_rules', 'fv_top_level_categories_refresh_rules'); // We don't want to insert our custom rules again + delete_option('fv_top_level_categories_rewrite_rules_flush'); +} + +// Remove category base +add_action('init', 'fv_top_level_categories_permastruct'); +function fv_top_level_categories_permastruct() { + global $wp_rewrite; + $wp_rewrite->extra_permastructs['category'][0] = '%category%'; + + if (get_option('fv_top_level_categories_rewrite_rules_flush') == 'true') { + flush_rewrite_rules(); + delete_option('fv_top_level_categories_rewrite_rules_flush'); + } +} + +// Add our custom category rewrite rules +add_filter('category_rewrite_rules', 'fv_top_level_categories_rewrite_rules'); +function fv_top_level_categories_rewrite_rules($category_rewrite) { + //var_dump($category_rewrite); // For Debugging + + /// First we need to get full URLs of our pages + $pages = get_pages( 'number=0' ); + $pages_urls = array(); + foreach( $pages AS $pages_item ) { + $pages_urls[] = trim( str_replace( get_bloginfo( 'url' ), '', get_permalink( $pages_item->ID ) ), '/' ); + } + /// + + $category_rewrite=array(); + $categories=get_categories(array('hide_empty'=>false)); + foreach($categories as $category) { + $category_nicename = $category->slug; + if ( $category->parent == $category->cat_ID ) // recursive recursion + $category->parent = 0; + elseif ($category->parent != 0 ) + $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; + + /// Let's check if any of the category full URLs matches any of the pages + if( in_array( $category_nicename, $pages_urls ) ) { + continue; + } + /// + + + $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; + $category_rewrite['('.$category_nicename.')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; + $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]'; + } + // Redirect support from Old Category Base + global $wp_rewrite; + $old_category_base = get_option('category_base') ? get_option('category_base') : 'category'; + $old_category_base = trim($old_category_base, '/'); + $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]'; + + //var_dump($category_rewrite); // For Debugging + return $category_rewrite; +} + +//Redirect to TL parent categ, if "Only use top-level categories in URLs." is on +add_filter('template_redirect', 'fv_top_level_categories_tlc_redirect', 999, 2); +function fv_top_level_categories_tlc_redirect( $link ) { + if( FV_Top_Level_Cats::is_top_level_only() && is_single() ) { + global $wp_query; + $requested_url = is_ssl() ? 'https://' : 'http://'; + $requested_url .= $_SERVER['HTTP_HOST']; + $requested_url .= $_SERVER['REQUEST_URI']; + + $real_permalink = get_permalink($wp_query->queried_object_id); + + if( FALSE === stripos($requested_url, $real_permalink) ) { + + $bMached = preg_match('~/([^/:]+/?)$~',$real_permalink, $end_of_permalink); + if( $bMached && preg_match('~'.$end_of_permalink[1].'(.+)$~', $requested_url, $end_of_url) ) + wp_redirect( $real_permalink . $end_of_url[1], 301 ); + else + wp_redirect( $real_permalink, 301 ); + die(); + } + } + + return $link; +} + +// Add 'category_redirect' query variable +add_filter('query_vars', 'fv_top_level_categories_query_vars'); +function fv_top_level_categories_query_vars($public_query_vars) { + $public_query_vars[] = 'category_redirect'; + return $public_query_vars; +} + +// Redirect if 'category_redirect' is set +add_filter('request', 'fv_top_level_categories_request'); +function fv_top_level_categories_request($query_vars) { + //print_r($query_vars); // For Debugging + if(isset($query_vars['category_redirect'])) { + $catlink = trailingslashit(get_option( 'home' )) . user_trailingslashit( $query_vars['category_redirect'], 'category' ); + status_header(301); + header("Location: $catlink"); + exit(); + } + return $query_vars; +} + +add_filter('category_link', 'top_level_cats_remove_cat_base'); +function top_level_cats_remove_cat_base($link) { + $category_base = get_option('category_base'); + + // WP uses "category/" as the default + if ($category_base == '') + $category_base = 'category'; + + // Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash) + if (substr($category_base, 0, 1) == '/') + $category_base = substr($category_base, 1); + + $category_base .= '/'; + + return preg_replace('|' . $category_base . '|', '', $link, 1); +} + + + + +function fv_top_level_cats_post_link_category_top_level_only( $cat ) { + if( !FV_Top_Level_Cats::is_category_permalinks() ) { + return $cat; + } + + while( FV_Top_Level_Cats::is_top_level_only() && $cat->parent != 0 ) { + $cat = get_term_by( 'id', $cat->parent, 'category' ); + } + + return $cat; +} +add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_top_level_only', 201, 3 ); + + + + +function fv_top_level_cats_post_link_category_restrict( $cat ) { + if( !FV_Top_Level_Cats::is_category_permalinks() || !FV_Top_Level_Cats::is_category_restriction() ) { + return $cat; + } + + $aArgs = func_get_args(); + + $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats(); + if( !count($aAllowedCats) ) { + return $cat; + } + + // check if the main category is allowed + if( in_array( $cat->term_id, $aAllowedCats ) ) { + return $cat; + } + + // check if any of the other categories is allowed! + $isOk = false; + foreach( $aArgs[1] AS $objCat ) { + if( in_array( $objCat->term_id, $aAllowedCats ) ) { + $isOk = true; + $cat = $objCat; + } + } + + // check if any of the parent categories is allowed + if( !$isOk ) { + foreach( $aArgs[1] AS $objCat ) { + while( $objCat->parent != 0 ) { + $objCat = get_term_by( 'id', $objCat->parent, 'category' ); + } + if( in_array( $objCat->term_id, $aAllowedCats ) ) { + $isOk = true; + $cat = $objCat; + } + } + } + + return $cat; +} +add_filter( 'post_link_category', 'fv_top_level_cats_post_link_category_restrict', 200, 3 ); + + + + +function fv_top_level_category_filter( $aCategories ) { + if( class_exists('FV_Top_Level_Cats') && method_exists('FV_Top_Level_Cats','get_allowed_cats') ) { + + $aAllowedCats = FV_Top_Level_Cats::get_allowed_cats(); + if( !count($aAllowedCats) ) { + return $aCategories; + } + + // check if the main category is allowed + foreach( $aCategories AS $objCat ) { + if( in_array( $objCat->term_id, $aAllowedCats ) ) { + return array($objCat); + } + } + + foreach( $aCategories AS $objCat ) { + while( $objCat->parent != 0 ) { + $objCat = get_term_by( 'id', $objCat->parent, 'category' ); + } + if( in_array( $objCat->term_id, $aAllowedCats ) ) { + return array($objCat); + } + } + } + return $aCategories; +} + + + + + +function fv_top_level_category( $separator = '', $parents = '', $post_id = false ) { + add_filter( 'get_the_categories', 'fv_top_level_category_filter' ); + the_category( $separator, $parents, $post_id ); + remove_filter( 'get_the_categories', 'fv_top_level_category_filter' ); +} +add_action( 'fv_top_level_category', 'fv_top_level_category', 10, 3 ); + + + + +class FV_Top_Level_Cats { + + var $enabled; + var $default_form_code; + var $default_form_css; + + + + + public function __construct() { + add_action( 'admin_menu', array($this, 'admin_menu') ); + add_action('init',array($this,'load_languages')); + } + + + + + function admin_menu() { + add_options_page( __('FV Top Level Categories','fv_tlc'), __('FV Top Level Categories','fv_tlc'), 'manage_options', 'fv_top_level_cats', array($this, 'options_panel') ); + } + + + + + public static function get_allowed_cats() { + $options = get_option( 'fv_top_level_cats' ); + if( isset($options['category-allow']) ) { + return $options['category-allow']; + } else { + return false; + } + } + + + + + public static function is_category_permalinks() { + $sPermalinks = get_option( 'permalink_structure' ); + if( stripos($sPermalinks, '%category%/') !== false ) { + return true; + } else { + return false; + } + } + + + + + function load_languages(){ + // Localization + load_plugin_textdomain('fv_tlc', false, dirname(plugin_basename(__FILE__)) . "/languages"); + } + + + + + public static function is_top_level_only() { + $options = get_option( 'fv_top_level_cats' ); + if( isset($options['top-level-only']) && $options['top-level-only'] ) { + return true; + } else { + return false; + } + } + + + + + public static function is_category_restriction() { + $options = get_option( 'fv_top_level_cats' ); + if( isset($options['category-allow-enabled']) && $options['category-allow-enabled'] ) { + return true; + } else { + return false; + } + } + + + + + function options_panel() { + + if (!empty($_POST)) : + + check_admin_referer('fv_top_level_cats'); + + if( isset($_POST['fv_top_level_cats_submit'] ) ) : + $options = get_option( 'fv_top_level_cats', array() ); + + $options['category-allow'] = $_POST['post_category']; + $options['top-level-only'] = ( $_POST['top-level-only'] ) ? true : false; + $options['category-allow-enabled'] = ( $_POST['category-allow-enabled'] ) ? true : false; + + update_option( 'fv_top_level_cats', $options ); +?> +
+

+ + Settings saved + +

+
+ + +
+
+ visit foliovision +
+
+

+

+
+ + is_category_permalinks() ) : ?> + +
+ +
+
+

+ +

+
+ + + + + + + +
+ +
+ +
+
+

+ +

+
+
+

support forums.','fv_tlc'); ?>

+
+ +
+ +

+ + +
+ + +' . __('Settings') . ''; + array_unshift($links, $settings_link); + return $links; +} + +$plugin = plugin_basename(__FILE__); +add_filter("plugin_action_links_$plugin", 'fv_top_level_categories_settings_link' );