Esempio n. 1
0
function jr_mt_convert_url_arrays($settings)
{
    global $jr_mt_url_types;
    foreach ($jr_mt_url_types as $setting_key) {
        if (isset($settings[$setting_key]) && is_array($settings[$setting_key])) {
            foreach ($settings[$setting_key] as $url_key => $url_array) {
                $url = $url_array['url'];
                if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                    $new_url_array['url'] = $url_array['url'];
                    $new_url_array['theme'] = $url_array['theme'];
                    $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                    $new_url_array['rel'] = $rel_url;
                    /*	Create the URL Prep array for each of the current Site Aliases,
                    				including the Current Site URL
                    			*/
                    $new_url_array['prep'] = array();
                    foreach ($settings['aliases'] as $index => $alias) {
                        $new_url_array['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                    }
                    /*	Only for URL type Setting, not Prefix types.
                     */
                    if ('url' === $setting_key) {
                        /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                         */
                        if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                            $id = attachment_url_to_postid($url);
                        }
                        if (!empty($id)) {
                            $new_url_array['id'] = (string) $id;
                            if (NULL !== ($post = get_post($id))) {
                                switch ($post->post_type) {
                                    case 'post':
                                        $new_url_array['id_kw'] = 'p';
                                        break;
                                    case 'page':
                                        $new_url_array['id_kw'] = 'page_id';
                                        break;
                                    case 'attachment':
                                        $new_url_array['id_kw'] = 'attachment_id';
                                        break;
                                }
                            }
                        }
                    }
                    $settings[$setting_key][$url_key] = $new_url_array;
                } else {
                    /*	Error:
                    				Cannot convert, as URL is from a different Site Home URL,
                    				so have to delete this URL entry.
                    			*/
                    unset($settings[$setting_key][$url_key]);
                    jr_mt_messages('Setting deleted during Conversion to Version 6 format because Site URL has changed');
                }
            }
        }
    }
    return $settings;
}
Esempio n. 2
0
function jr_mt_validate_settings($input)
{
    global $jr_mt_kwvalsep;
    $valid = array();
    $prefix_types = array('false' => 'url', 'prefix' => 'url_prefix', '*' => 'url_asterisk');
    $settings = get_option('jr_mt_settings');
    $query = $settings['query'];
    $aliases = $settings['aliases'];
    /*	Begin by deciding which Tab to display on the plugin's Settings page
    	
    		Default value should never be used if plugin is written correctly.
    	*/
    $tab = 1;
    for ($i = 1; $i <= 6; $i++) {
        if (isset($input["tab{$i}"])) {
            $tab = $i;
            break;
        }
    }
    set_transient('jr_mt_' . get_current_user_id() . '_tab', $tab, 5);
    if (isset($input['permalink'])) {
        $internal_settings = get_option('jr_mt_internal_settings');
        $internal_settings['permalink'] = get_option('permalink_structure');
        update_option('jr_mt_internal_settings', $internal_setting);
    }
    foreach (array('all_pages', 'all_posts', 'site_home', 'current') as $thing) {
        $valid[$thing] = $input[$thing];
    }
    foreach ($prefix_types as $key => $thing) {
        $valid[$thing] = $settings[$thing];
    }
    $remember = array('query' => array());
    if (isset($input['sticky_query_entry'])) {
        foreach ($input['sticky_query_entry'] as $query_entry) {
            list($keyword, $value) = explode($jr_mt_kwvalsep, $query_entry);
            /*	Data Sanitization not required as
            				Keyword and Value are not entered by a human,
            				but extracted from previously-generated HTML.
            			*/
            $remember['query'][$keyword][$value] = TRUE;
        }
    }
    $override = array('query' => array());
    if (isset($input['override_query_entry'])) {
        foreach ($input['override_query_entry'] as $query_entry) {
            list($keyword, $value) = explode($jr_mt_kwvalsep, $query_entry);
            /*	Data Sanitization not required as
            				Keyword and Value are not entered by a human,
            				but extracted from previously-generated HTML.
            			*/
            $override['query'][$keyword][$value] = TRUE;
        }
    }
    if (isset($input['del_entry'])) {
        foreach ($input['del_entry'] as $del_entry) {
            $del_array = explode('=', $del_entry, 3);
            if ('query' === $del_array[0]) {
                unset($query[$del_array[1]][$del_array[2]]);
                if (empty($query[$del_array[1]])) {
                    unset($query[$del_array[1]]);
                }
                /*	unset() does nothing if a variable or array element does not exist.
                 */
                unset($remember['query'][$del_array[1]][$del_array[2]]);
                if (empty($remember['query'][$del_array[1]])) {
                    unset($remember['query'][$del_array[1]]);
                }
                unset($override['query'][$del_array[1]][$del_array[2]]);
                if (empty($override['query'][$del_array[1]])) {
                    unset($override['query'][$del_array[1]]);
                }
            } else {
                /*	Check for a URL entry
                 */
                if ('url' === jr_mt_substr($del_array[0], 0, 3)) {
                    foreach ($valid[$del_array[0]] as $i => $entry_array) {
                        if ($entry_array['url'] === $del_array[2]) {
                            /*	Cannot unset $entry_array, even if prefixed by & in foreach
                             */
                            unset($valid[$del_array[0]][$i]);
                            break;
                        }
                    }
                } else {
                    /*	Must be Home, All Pages or Posts, or Everything
                     */
                    $valid[$del_array[0]] = '';
                }
            }
        }
    }
    /*	Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
     */
    $url = jr_mt_sanitize_url($input['add_path_id']);
    if (empty($input['add_theme']) && !empty($url) || !empty($input['add_theme']) && empty($url)) {
        add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Both URL and Theme must be specified to add an Individual entry', 'error');
    } else {
        if (!empty($url)) {
            if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                if ('*' !== $input['add_is_prefix'] && FALSE !== strpos($url, '*')) {
                    add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>', 'error');
                } else {
                    $prep_url = jr_mt_prep_url($url);
                    if ('false' === $input['add_is_prefix']) {
                        if (jr_mt_same_url($prep_url, JR_MT_HOME_URL)) {
                            add_settings_error('jr_mt_settings', 'jr_mt_homeerror', 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.', 'error');
                        } else {
                            if (jr_mt_same_prefix_url($prep_url, admin_url())) {
                                add_settings_error('jr_mt_settings', 'jr_mt_adminerror', 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>', 'error');
                            }
                        }
                    } else {
                        if ('*' === $input['add_is_prefix']) {
                            $url_dirs = explode('/', str_replace('\\', '/', $url));
                            foreach ($url_dirs as $dir) {
                                if (FALSE !== strpos($dir, '*')) {
                                    $asterisk_found = TRUE;
                                    if ('*' !== $dir) {
                                        $asterisk_not_alone = TRUE;
                                    }
                                    break;
                                }
                            }
                            if (isset($asterisk_found)) {
                                if (isset($asterisk_not_alone)) {
                                    add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>', 'error');
                                }
                            } else {
                                add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>', 'error');
                            }
                        }
                    }
                    function jr_mt_settings_errors()
                    {
                        $errors = get_settings_errors();
                        if (!empty($errors)) {
                            foreach ($errors as $error_array) {
                                if ('error' === $error_array['type']) {
                                    return TRUE;
                                }
                            }
                        }
                        return FALSE;
                    }
                    /*	If there have been no errors detected,
                    				create the new URL setting entry.
                    			*/
                    if (!jr_mt_settings_errors()) {
                        /*	['url'], ['url_prefix'] or ['url_asterisk']
                         */
                        $key = $prefix_types[$input['add_is_prefix']];
                        $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                        $valid[$key][] = array('url' => $url, 'rel_url' => $rel_url, 'theme' => $input['add_theme']);
                        /*	Get index of element just added to array $valid[ $key ]
                         */
                        end($valid[$key]);
                        $valid_key = key($valid[$key]);
                        /*	Create the URL Prep array for each of the current Site Aliases,
                        				including the Current Site URL
                        			*/
                        foreach ($aliases as $index => $alias) {
                            $valid[$key][$valid_key]['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                        }
                        /*	Only for URL type Setting, not Prefix types.
                         */
                        if ('url' === $key) {
                            /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                             */
                            if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                                $id = attachment_url_to_postid($url);
                            }
                            if (!empty($id)) {
                                $valid[$key][$valid_key]['id'] = $id;
                                if (NULL !== ($post = get_post($id))) {
                                    switch ($post->post_type) {
                                        case 'post':
                                            $valid[$key][$valid_key]['id_kw'] = 'p';
                                            break;
                                        case 'page':
                                            $valid[$key][$valid_key]['id_kw'] = 'page_id';
                                            break;
                                        case 'attachment':
                                            $valid[$key][$valid_key]['id_kw'] = 'attachment_id';
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                add_settings_error('jr_mt_settings', 'jr_mt_urlerror', ' URL specified is not part of current WordPress web site: <code>' . $url . '</code>.  URL must begin with <code>' . JR_MT_HOME_URL . '</code>.', 'updated');
            }
        }
    }
    /*	Make sure reserved characters are not used
    		in URL Query keyword or value fields on Settings page.
    	*/
    function jr_mt_query_chars($element, $where)
    {
        foreach (array('=' => 'Equals Sign', '?' => 'Question Mark', '&' => 'Ampersand', ' ' => 'Blank', '#' => 'Number Sign', '/' => 'Slash', '\\' => 'Backslash', '[' => 'Square Bracket', ']' => 'Square Bracket') as $char => $name) {
            if (FALSE !== strpos($element, $char)) {
                add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'Illegal character used in ' . $where . ': ' . $name . ' ("' . $char . '") in "' . $element . '"', 'error');
                return FALSE;
            }
        }
        return TRUE;
    }
    /*	Data Sanitization needed here
     */
    $keyword = jr_mt_prep_query_keyword($input['add_querykw_keyword']);
    if (!empty($input['add_querykw_theme']) && !empty($keyword)) {
        if (jr_mt_query_chars($keyword, 'Query Keyword')) {
            /*	If there is an existing entry for the Keyword,
            				then replace it.
            				Otherwise, create a new entry.
            			*/
            $query[$keyword]['*'] = $input['add_querykw_theme'];
        }
    } else {
        if (!(empty($input['add_querykw_theme']) && empty($keyword))) {
            add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry', 'error');
        }
    }
    /*	Data Sanitization needed here
     */
    $keyword = jr_mt_prep_query_keyword($input['add_query_keyword']);
    $value = jr_mt_prep_query_value($input['add_query_value']);
    if (!empty($input['add_query_theme']) && !empty($keyword) && !empty($value)) {
        if (jr_mt_query_chars($keyword, 'Query Keyword') && jr_mt_query_chars($value, 'Query Value')) {
            /*	If there is an existing entry for the Keyword and Value pair,
            				then replace it.
            				Otherwise, create a new entry.
            			*/
            $query[$keyword][$value] = $input['add_query_theme'];
        }
    } else {
        if (!(empty($input['add_query_theme']) && empty($keyword) && empty($value))) {
            add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Query Keyword, Value and Theme must all be specified to add an Individual Query entry', 'error');
        }
    }
    if ('true' === $input['query_present']) {
        $valid['query_present'] = TRUE;
    } else {
        if ('false' === $input['query_present']) {
            $valid['query_present'] = FALSE;
        }
    }
    /*	Handle Alias tab
    	
    		Always handle Delete first, to allow Replacement (Delete then Add)
    	*/
    if (isset($input['del_alias_entry'])) {
        foreach ($input['del_alias_entry'] as $del_alias_entry) {
            $int_key = (int) $del_alias_entry;
            unset($aliases[$int_key]);
            /*	Now go through all the URL-based Settings,
            				and delete the Prep for the deleted Alias.
            					
            				$int_key is the array integer key of the just-deleted
            				Alias, as that will also be the array key for each of the
            				Settings ['prep'] arrays.
            			*/
            foreach ($prefix_types as $form_prefix => $settings_prefix) {
                foreach ($valid[$settings_prefix] as $key => $url_entry) {
                    unset($valid[$settings_prefix][$key]['prep'][$int_key]);
                }
            }
        }
    }
    $alias_url = jr_mt_sanitize_url($input['add_alias']);
    if (!empty($alias_url)) {
        /*	URL has been trimmed but Case has not been altered
         */
        if (0 !== substr_compare($alias_url, 'http://', 0, 7, TRUE) && 0 !== substr_compare($alias_url, 'https://', 0, 8, TRUE) || FALSE === ($parse_url = parse_url($alias_url))) {
            add_settings_error('jr_mt_settings', 'jr_mt_badurlerror', "Alias URL specified is invalid: <code>{$url}</code>", 'error');
        } else {
            $url_ok = TRUE;
            foreach (array('user', 'pass', 'query', 'fragment') as $component) {
                if (isset($parse_url[$component])) {
                    $url_ok = FALSE;
                    break;
                }
            }
            if ($url_ok) {
                /*	Be sure there is NOT a trailing slash
                 */
                $alias_url = rtrim($alias_url, '/\\');
                $aliases[] = array('url' => $alias_url, 'prep' => jr_mt_prep_url($alias_url), 'home' => FALSE);
                /*	Now go through all the URL-based Settings,
                				and add a Prep for the new Alias.
                				
                				First, determine the array integer key of the newly-added
                				Alias, as that will also be the array key for each of the
                				Settings ['prep'] arrays.
                			*/
                end($aliases);
                $prep_key = key($aliases);
                foreach ($prefix_types as $form_prefix => $settings_prefix) {
                    foreach ($valid[$settings_prefix] as $key => $url_entry) {
                        $valid[$settings_prefix][$key]['prep'][$prep_key] = jr_mt_prep_url($alias_url . '/' . $valid[$settings_prefix][$key]['rel_url']);
                    }
                }
            } else {
                add_settings_error('jr_mt_settings', 'jr_mt_badurlerror', 'Alias URL cannot contain user, password, query ("?") or fragment ("#"): <code>' . "{$url}</code>", 'error');
            }
        }
    }
    $errors = get_settings_errors();
    if (empty($errors)) {
        add_settings_error('jr_mt_settings', 'jr_mt_saved', 'Settings Saved', 'updated');
    }
    $valid['query'] = $query;
    $valid['remember'] = $remember;
    $valid['override'] = $override;
    $valid['aliases'] = $aliases;
    return $valid;
}
Esempio n. 3
0
/**
 * Returns FALSE for Current Theme
 * 
 */
function jr_mt_chosen()
{
    $settings = get_option('jr_mt_settings');
    /*	$queries - array of [keyword] => array( value, value, ... )
    			in the current URL.
    	*/
    $queries = jr_mt_query_array();
    /*	P2 free Theme special processing:
    		for both Admin and Public site,
    		check for P2 keyword p2ajax=,
    		and select P2 theme, if present.
    	*/
    if (isset($queries['p2ajax']) && array_key_exists('p2', jr_mt_all_themes())) {
        return 'p2';
    }
    /*	Otherwise, Admin gets current ("Active") WordPress Theme
     */
    if (is_admin()) {
        return FALSE;
    }
    /*	KnowHow ThemeForest Paid Theme special processing:
    		if s= is present, and 'knowhow' is either the active WordPress Theme
    		or is specified in any Settings, then automatically select the KnowHow theme.
    	*/
    if (isset($queries['s']) && in_array('knowhow', jr_mt_themes_defined())) {
        return 'knowhow';
    }
    /*	Non-Admin page, i.e. - Public Site, etc.
    	
    		Begin by checking for any Query keywords specified by the Admin in Settings,
    		complicated by the fact that Override entries take precedence.
    	*/
    if (!empty($settings['query'])) {
        if (!empty($_SERVER['QUERY_STRING'])) {
            /*	Check Override entries
             */
            foreach ($settings['override']['query'] as $override_keyword => $override_value_array) {
                if (isset($queries[$override_keyword])) {
                    foreach ($override_value_array as $override_value => $bool) {
                        if (in_array($override_value, $queries[$override_keyword])) {
                            $override_found[] = array($override_keyword, $override_value);
                        }
                    }
                }
            }
            if (!isset($overrides_found)) {
                /*	Look for both keyword=value settings and keyword=* settings,
                				with keyword=value taking precedence (sorted out later).
                			*/
                foreach ($settings['query'] as $query_settings_keyword => $value_array) {
                    if (isset($queries[$query_settings_keyword])) {
                        foreach ($value_array as $query_settings_value => $theme) {
                            if (in_array($query_settings_value, $queries[$query_settings_keyword])) {
                                $query_found[] = array($query_settings_keyword, $query_settings_value);
                            }
                        }
                        if (isset($value_array['*'])) {
                            $keyword_found[] = $query_settings_keyword;
                        }
                    }
                }
            }
        }
    }
    /*	Handle Overrides:
    		First, for Override keyword=value query in URL.
    		Second, for previous Override detected by PHP cookie.
    	*/
    if (isset($override_found)) {
        /*	If sticky, create JavaScript Sticky Cookie,
        			and PHP Sticky Cookie.
        			No matter what:
        			return Theme from the first Override found.
        		*/
        $keyword = $override_found[0][0];
        $value = $override_found[0][1];
        if (isset($settings['remember']['query'][$keyword][$value])) {
            jr_mt_js_sticky_query($keyword, $value);
            jr_mt_cookie('php', 'put', "{$keyword}={$value}");
        }
        return $settings['query'][$keyword][$value];
    } else {
        /*	Is there a previous Override Query for this Site Visitor?
        			If so, use it, but only if it is still valid.
        		*/
        if (FALSE !== ($cookie = jr_mt_cookie('php', 'get'))) {
            list($keyword, $value) = explode('=', $cookie);
            if (isset($settings['override']['query'][$keyword][$value])) {
                /*	If sticky, create JavaScript Sticky Cookie,
                				and renew PHP Sticky Cookie.
                				No matter what:
                				Return Theme
                			*/
                if (isset($settings['remember']['query'][$keyword][$value])) {
                    jr_mt_js_sticky_query($keyword, $value);
                    jr_mt_cookie('php', 'put', "{$keyword}={$value}");
                }
                return $settings['query'][$keyword][$value];
            }
        }
    }
    /*	Handle Non-Overrides:
    		keyword=value query in URL with matching setting entry.
    	*/
    if (isset($query_found)) {
        $query_keyword_found = $query_found[0][0];
        $query_value_found = $query_found[0][1];
        /*	Probably makes sense to give preference to the Sticky ones
         */
        foreach ($query_found as $query_kwval_array) {
            if (isset($settings['remember']['query'][$query_kwval_array[0]][$query_kwval_array[1]])) {
                $query_keyword_found = $query_kwval_array[0];
                $query_value_found = $query_kwval_array[1];
                /*	Create JavaScript Sticky Cookie,
                				and PHP Sticky Cookie.
                			*/
                jr_mt_js_sticky_query($query_keyword_found, $query_value_found);
                jr_mt_cookie('php', 'put', "{$query_keyword_found}={$query_value_found}");
                break;
            }
        }
        /*	Return Theme
         */
        return $settings['query'][$query_keyword_found][$query_value_found];
    }
    /*	Handle Keyword wildcards:
    		keyword=* setting entry that matches keyword in URL query.
    	*/
    if (isset($keyword_found)) {
        return $settings['query'][$keyword_found[0]]['*'];
    }
    /*	Now look at URL entries: $settings['url'] and ['url_prefix']
    		
    		Version 6.0 Logic Design to maximize performance on high traffic sites without Caching:
    			For current URL, determine Site Alias in use
    				- Best Match - from an array of matching Site Aliases, determine "Best", some measure of Longest
    			Prep current URL for matching
    			Check for match in "URL" plugin entries that have been pre-prepped with this Site Alias
    			Check for match in "URL Prefix" plugin entries that have been pre-prepped with this Site Alias
    			Check for match in "URL Prefix with Asterisk" plugin entries that have been pre-prepped with this Site Alias
    	*/
    $prep_url = jr_mt_prep_url($current_url = parse_url(JR_MT_HOME_URL, PHP_URL_SCHEME) . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
    $match = array();
    foreach ($settings['aliases'] as $key => $alias_array) {
        if (jr_mt_same_prefix_url($alias_array['prep'], $prep_url)) {
            $match[] = $key;
        }
    }
    if (empty($match)) {
        /*	Maybe not the best thing to do,
        			but if Site Alias is not defined,
        			always use Current Theme.
        		*/
        return FALSE;
    }
    $site_alias_key = jr_mt_best_match_alias($settings['aliases'], $match);
    foreach ($settings['url'] as $settings_array) {
        if (jr_mt_same_url($settings_array['prep'][$site_alias_key], $prep_url)) {
            return $settings_array['theme'];
        }
    }
    foreach ($settings['url_prefix'] as $settings_array) {
        if (jr_mt_same_prefix_url($settings_array['prep'][$site_alias_key], $prep_url)) {
            return $settings_array['theme'];
        }
    }
    foreach ($settings['url_asterisk'] as $settings_array) {
        if (jr_mt_same_prefix_url_asterisk($settings_array['prep'][$site_alias_key], $prep_url)) {
            return $settings_array['theme'];
        }
    }
    /*	Must check for Home near the end as queries override
    	
    		Home is determined in an odd way:
    		(1) Remove all Queries
    		(2) Match against Site Address (URL) specified in Admin General Settings
    		(3) Check if any non-Permalink keywords are present, such as p= or page_id=
    			and cause a non-match if present
    	*/
    if ('' !== $settings['site_home']) {
        /*	Check for Home Page,
        			with or without Query.
        		*/
        $prep_url_no_query = $prep_url;
        $prep_url_no_query['query'] = array();
        if (jr_mt_same_url(JR_MT_HOME_URL, $prep_url_no_query)) {
            $home = TRUE;
            if (FALSE !== ($internal_settings = get_option('jr_mt_internal_settings')) && isset($internal_settings['query_vars']) && is_array($internal_settings['query_vars'])) {
                foreach ($prep_url['query'] as $keyword => $value) {
                    /*	Check for any non-Permalink Query Keyword
                     */
                    if (in_array($keyword, $internal_settings['query_vars'])) {
                        $home = FALSE;
                        break;
                    }
                }
            }
            if ($home) {
                return $settings['site_home'];
            } else {
                /*	Check for Settings specifying the current Page, Post or Attachment
                				specified with kw=val Query default Permalinks.
                			*/
                foreach ($settings['url'] as $settings_array) {
                    if (isset($settings_array['id_kw']) && isset($prep_url['query'][$settings_array['id_kw']]) && $prep_url['query'][$settings_array['id_kw']] === $settings_array['id']) {
                        return $settings_array['theme'];
                    }
                }
            }
        }
    }
    /*	All Pages and All Posts settings are checked second to last, 
    		just before Everything Else.
    		
    		url_to_postid() only works after JR_MT_PAGE_CONDITIONAL is set.
    		But alternate means can be used with default Permalinks.
    		
    		First, see if any All Pages or All Posts setting exists.
    	*/
    if (jr_mt_all_posts_pages()) {
        if (defined('JR_MT_PAGE_CONDITIONAL')) {
            if (0 !== ($id = url_to_postid($current_url))) {
                if (NULL !== ($post = get_post($id))) {
                    $type = $post->post_type;
                    if ('post' === $type) {
                        if ('' !== $settings['all_posts']) {
                            return $settings['all_posts'];
                        }
                    } else {
                        if ('page' === $type) {
                            if ('' !== $settings['all_pages']) {
                                return $settings['all_pages'];
                            }
                        }
                    }
                }
            }
        } else {
            $permalink = get_option('permalink_structure');
            if (empty($permalink)) {
                if ('' !== $settings['all_posts']) {
                    if (isset($queries['p'])) {
                        return $settings['all_posts'];
                    }
                }
                if ('' !== $settings['all_pages']) {
                    if (isset($queries['page_id'])) {
                        return $settings['all_pages'];
                    }
                }
            }
        }
    }
    /*	This is the Theme for Everything Advanced Setting.
    		A Setting of Blank uses WordPress Current Theme value,
    		i.e. - the Setting is not set.
    	*/
    if ('' === $settings['current']) {
        return FALSE;
    } else {
        return $settings['current'];
    }
}
Esempio n. 4
0
function jr_mt_make_relative($url, $aliases)
{
    if (is_string($url)) {
        $url = jr_mt_prep_url($url);
    }
    $return = FALSE;
    foreach ($aliases as $alias) {
        if (jr_mt_same_prefix_url($alias, $url)) {
            $return = array('alias' => $alias, 'rel_url' => $rel_url, 'rel_url_prep' => $rel_url_prep);
            break;
        }
    }
    return $return;
}
Esempio n. 5
0
function jr_mt_convert_url_arrays()
{
    $internal_settings = get_option('jr_mt_internal_settings');
    if (isset($internal_settings['v6conv'])) {
        unset($internal_settings['v6conv']);
        update_option('jr_mt_internal_settings', $internal_settings);
        $settings = get_option('jr_mt_settings');
        /*	Check if conversion is needed:
        			- see if [url*] are all empty arrays - no conversion required
        			- look for any [url*]['rel_url'] - already converted from pre-V6
        		*/
        if (is_array($settings)) {
            foreach ($settings as $setting_key => $arrays) {
                if ('url' === substr($setting_key, 0, 3)) {
                    if (!empty($arrays)) {
                        foreach ($arrays as $url_array) {
                            if (isset($url_array['rel_url'])) {
                                /*	Already been converted, so don't do it again.
                                 */
                                return;
                            }
                        }
                        foreach ($arrays as $url_key => $url_array) {
                            $url = $url_array['url'];
                            if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                                $new_url_array['url'] = $url_array['url'];
                                $new_url_array['theme'] = $url_array['theme'];
                                $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                                $new_url_array['rel'] = $rel_url;
                                /*	Create the URL Prep array for each of the current Site Aliases,
                                				including the Current Site URL
                                			*/
                                $new_url_array['prep'] = array();
                                foreach ($settings['aliases'] as $index => $alias) {
                                    $new_url_array['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                                }
                                /*	Only for URL type Setting, not Prefix types.
                                 */
                                if ('url' === $setting_key) {
                                    /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                                     */
                                    if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                                        $id = attachment_url_to_postid($url);
                                    }
                                    if (!empty($id)) {
                                        $new_url_array['id'] = $id;
                                        if (NULL !== ($post = get_post($id))) {
                                            switch ($post->post_type) {
                                                case 'post':
                                                    $new_url_array['id_kw'] = 'p';
                                                    break;
                                                case 'page':
                                                    $new_url_array['id_kw'] = 'page_id';
                                                    break;
                                                case 'attachment':
                                                    $new_url_array['id_kw'] = 'attachment_id';
                                                    break;
                                            }
                                        }
                                    }
                                }
                                $settings[$setting_key][$url_key] = $new_url_array;
                            } else {
                                /*	Error:
                                				Cannot convert, as URL is from a different Site Home URL,
                                				so have to delete this URL entry.
                                			*/
                                unset($settings[$setting_key][$url_key]);
                            }
                        }
                    }
                }
            }
            update_option('jr_mt_settings', $settings);
        }
    }
}