Plugin Directory

Changeset 816479


Ignore:
Timestamp:
12/07/2013 03:29:19 PM (12 years ago)
Author:
suboptimist
Message:

Version 0.2.2

  • fixed bug that always forwarded pretty permalinks to startpage
  • fixed bug that added division twice to pretty permalinks in menu
  • added method get_current_division() to plugin item for external use
Location:
divisions/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • divisions/trunk/divisions.php

    r783523 r816479  
    44Plugin URI: http://www.nachstedt.com/en/divisions-wordpress-plugin-en
    55Description: Create multiple divisions in your site with individual menus, sidebars and header images. Divisions may easily change share content of all types while maintaining a consistent look.
    6 Version: 0.2.1
     6Version: 0.2.2
    77Author: Timo Nachstedt
    88Author URI: http://www.nachstedt.com
     
    9494            // register filters
    9595            add_filter(
    96                 'post_link',
    97                 array(&$this, 'post_link_filter'), 1, 2);
    98             add_filter(
    9996                    'wp_edit_nav_menu_walker',
    10097                    array( &$this, 'wp_edit_nav_menu_walker_filter' ) );
     
    163160            }
    164161            update_option(dvs_Constants::DATABASE_VERSION_OPTION, $my_version);
     162        }
     163       
     164        public function get_current_division()
     165        {
     166            return $this->current_division;
    165167        }
    166168
     
    191193                : $this->current_division->get_id();
    192194
    193             $division = $division_enabled
    194                 ? $chosen_division
    195                 : $current_division_id;
    196 
    197             // chosen_division <0 means "no division"
    198             if ($division >= 0)
    199             {
    200                 $menu_item->url = dvs_LinkModification::add_division_to_url(
    201                     $menu_item->url,
    202                     $division);
    203             }
    204 
    205             if ($division_enabled && $division==$current_division_id)
    206             {
    207                 $menu_item->classes[] =
    208                     dvs_Constants::CSS_CLASS_MENU_ITEM_CURRENT_DIVISION;
    209             }
     195            if ($division_enabled)
     196            {
     197                // chosen_division <0 means "no division"
     198                if ($chosen_division >= 0 && $current_division_id >=0)
     199                {
     200                    $menu_item->url =
     201                        dvs_LinkModification::replace_division_in_url(
     202                            $menu_item->url,
     203                            $chosen_division);
     204                }
     205                if ($chosen_division >= 0 && $current_division_id < 0)
     206                {
     207                    $menu_item->url =
     208                        dvs_LinkModification::add_division_to_url(
     209                            $menu_item->url,
     210                            $chosen_division);
     211                }
     212                else
     213                if ($chosen_division < 0 && $current_division_id >=0)
     214                {
     215                    $menu_item->url =
     216                        dvs_LinkModification::remove_division_from_url(
     217                            $menu_item->url);
     218                }
     219                if ($chosen_division==$current_division_id)
     220                {
     221                    $menu_item->classes[] =
     222                        dvs_Constants::CSS_CLASS_MENU_ITEM_CURRENT_DIVISION;
     223                }
     224               
     225            }
     226
    210227            return $menu_item;
    211228        }
     
    282299                $this->current_division = new dvs_Division($division_id);
    283300            }
    284         }
    285 
    286         /**
    287          * Filter links to posts
    288          *
    289          * This method filters links to posts in page and adds the current division
    290          * as query argument
    291          *
    292          * @param string $permalink_url original post link url
    293          * @param array $post_data meta data of the linke post
    294          * @return string modified link url
    295          */
    296         public function post_link_filter($permalink_url, $post_data)  {
    297             if ($this->current_division==NULL) {return $permalink_url;}
    298             return dvs_LinkModification::add_division_to_url(
    299                 $permalink_url,
    300                 $this->current_division->get_id());
    301301        }
    302302
  • divisions/trunk/includes/dvs_constants.php

    r783523 r816479  
    66    class dvs_Constants {
    77
    8         const VERSION = '0.2.1';
     8        const VERSION = '0.2.2';
    99        const DATABASE_VERSION_OPTION = "divisions_plugion_version";
    1010
  • divisions/trunk/includes/dvs_link_modification.php

    r783523 r816479  
    4242                array(__CLASS__, 'deactivation_hook'));
    4343        }
     44        else
     45        {
     46            add_filter(
     47                'page_link',
     48                array(__CLASS__, 'page_link_filter'));
     49            add_filter(
     50                'post_link',
     51                array(__CLASS__, 'post_link_filter'), 1, 2);           
     52        }
    4453    }
    4554
     
    93102        }
    94103    }
     104   
     105    public static function page_link_filter($permalink_url)
     106    {
     107        global $tn_divisions_plugin;
     108        $current_division = $tn_divisions_plugin->get_current_division();
     109        if ($current_division==NULL)
     110        {
     111            return $permalink_url;
     112        }
     113        return self::add_division_to_url(
     114            $permalink_url,
     115            $current_division->get_id());
     116    }
     117       
     118    /**
     119     * Filter links to posts
     120     *
     121     * This method filters links to posts in page and adds the current division
     122     * as query argument
     123     *
     124     * @param string $permalink_url original post link url
     125     * @param array $post_data meta data of the linke post
     126     * @return string modified link url
     127     */
     128    public static function post_link_filter($permalink_url, $post_data)  {
     129        global $tn_divisions_plugin;
     130        $current_division = $tn_divisions_plugin->get_current_division();
     131        if ($current_division==NULL)
     132        {
     133            return $permalink_url;
     134        }
     135        return self::add_division_to_url(
     136            $permalink_url,
     137            $current_division->get_id());
     138    }       
     139   
     140    public static function remove_division_from_url($url)
     141    {
     142        if (dvs_Settings::get_use_permalinks()
     143                && get_option('permalink_structure'))
     144        {
     145            $site_url = get_site_url();
     146            $relative_url = substr($url, strlen($site_url)+1);
     147            $first_slash = strpos($relative_url, '/');
     148            if ($first_slash)
     149            {
     150                return $site_url . substr($relative_url, $first_slash);
     151            }
     152            else
     153            {
     154                return $url;
     155            }
     156        }
     157        else
     158        {
     159            return add_query_arg(
     160                dvs_Constants::QUERY_ARG_NAME_DIVISION,
     161                FALSE,
     162                $url);
     163        }
     164
     165        return $url;
     166    }
     167   
     168    public static function replace_division_in_url($url, $division_id)
     169    {
     170        return self::add_division_to_url(
     171                self::remove_division_from_url($url), $division_id);
     172    }
    95173
    96174    public static function rewrite_rules_array_filter($rules)
     
    117195        foreach  ($divisions as $division)
    118196        {
    119             $url = $division->get_permalink_slug();
     197            $url = $division->get_permalink_slug() . "$";
    120198            $rewrite = '/index.php?division=' . $division->get_id();
    121199            $newrules[$url] = $rewrite;
  • divisions/trunk/readme.txt

    r783523 r816479  
    55Requires at least: 3.6
    66Tested up to: 3.6
    7 Stable tag: 0.2.1
     7Stable tag: 0.2.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4343== Changelog ==
    4444
     45= 0.2.2 =
     46* fixed bug that always forwarded pretty permalinks to startpage
     47* fixed bug that added division twice to pretty permalinks in menu
     48* added method get_current_division() to plugin item for external use
     49
    4550= 0.2.1 =
    4651* Division permalinks for homepages work
     
    6772== Upgrade Notice ==
    6873
     74= 0.2.2 =
     75Fixed severe bugs related to pretty permalinks
     76
    6977= 0.2.1 =
    7078Fixed bugs related to new permalink option
Note: See TracChangeset for help on using the changeset viewer.