Source of file link-template.php
Size: 9,700 Bytes - Last Modified: 2017-07-17T16:46:02+00:00
/home/travis/build/Limych/GeniBase/src/gb/link-template.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 | <?php /** * GeniBase Link Template Functions * * @package GeniBase * @subpackage Template * * @copyright Copyright © 2015, Andrey Khrolenok (andrey@khrolenok.ru) * @copyright Partially copyright © WordPress Team */ // Direct execution forbidden for this script if (! defined('GB_VERSION') || count(get_included_files()) == 1) die('<b>ERROR:</b> Direct execution forbidden!'); /** * Retrieve the home url for the current site. * * Returns the 'home_url' option with the appropriate protocol, 'https' if * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is * overridden. * * @since 2.1.1 * * @param string $path * Path relative to the home url. * @param string $scheme * Scheme to give the home url context. See set_url_scheme(). * @return string url link with optional path appended. */ function home_url($path = '', $scheme = null) { return get_site_url($path, $scheme); } /** * Retrieve the site url for the current site. * * Returns the 'site_url' option with the appropriate protocol, 'https' if * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is * overridden. * * @since 2.0.1 * * @param string $path * Optional. Path relative to the site url. * @param string $scheme * Optional. Scheme to give the site url context. See set_url_scheme(). * @return string Site url link with optional path appended. */ function site_url($path = '', $scheme = null) { return get_site_url($path, $scheme); } /** * Retrieve the site url for a given site. * * Returns the 'site_url' option with the appropriate protocol, 'https' if * {@see is_ssl()} and 'http' otherwise. If `$scheme` is 'http' or 'https', * `is_ssl()` is overridden. * * @since 2.0.1 * * @param string $path * Optional. Path relative to the site url. Default empty. * @param string $scheme * Optional. Scheme to give the site url context. Accepts * 'http', 'https', 'login', 'login_post', 'admin', or * 'relative'. Default null. * @return string Site url link with optional path appended. */ function get_site_url($path = '', $scheme = null) { $url = GB_Options::get('site_url'); $url = set_url_scheme($url, $scheme); if ($path && is_string($path)) $url .= '/' . ltrim($path, '/'); if (class_exists('GB_Hooks')) { /** * Filter the site URL. * * @since 2.1.1 * * @param string $url * The complete site URL including scheme and path. * @param string $path * Path relative to the site URL. Blank string if no path is specified. * @param string|null $scheme * Scheme to give the site URL context. Accepts 'http', 'https', 'login', * 'login_post', 'admin', 'relative' or null. */ $url = GB_Hooks::apply_filters('site_url', $url, $path, $scheme); } return $url; } /** * Retrieve the url to the admin area for the current site. * * @since 2.0.1 * * @param string $path * Optional path relative to the admin url. * @param string $scheme * The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. * @return string Admin url link with optional path appended. */ function admin_url($path = '', $scheme = 'admin') { return get_admin_url($path, $scheme); } /** * Retrieves the url to the admin area for a given site. * * @since 2.0.1 * * @param string $path * Optional. Path relative to the admin url. Default empty. * @param string $scheme * Optional. The scheme to use. Accepts 'http' or 'https', * to force those schemes. Default 'admin', which obeys * {@see force_ssl_admin()} and {@see is_ssl()}. * @return string Admin url link with optional path appended. */ function get_admin_url($path = '', $scheme = 'admin') { $url = get_site_url('gb-admin/', $scheme); if ($path && is_string($path)) $url .= ltrim($path, '/'); if (class_exists('GB_Hooks')) { /** * Filter the admin area URL. * * @since 2.1.1 * * @param string $url * The complete admin area URL including scheme and path. * @param string $path * Path relative to the admin area URL. Blank string if no path is specified. */ $url = GB_Hooks::apply_filters('admin_url', $url, $path); } return $url; } /** * Set the scheme for a URL * * @since 2.0.1 * * @param string $url * Absolute url that includes a scheme * @param string $scheme * Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. * @return string $url URL with chosen scheme. */ function set_url_scheme($url, $scheme = null) { $orig_scheme = $scheme; if (! $scheme) { $scheme = is_ssl() ? 'https' : 'http'; } elseif ($scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc') { $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http'; } elseif ($scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative') { $scheme = is_ssl() ? 'https' : 'http'; } $url = trim($url); if (substr($url, 0, 2) === '//') $url = 'http:' . $url; if ('relative' == $scheme) { $url = ltrim(preg_replace('#^\w+://[^/]*#', '', $url)); if ($url !== '' && $url[0] === '/') $url = '/' . ltrim($url, "/ \t\n\r\0\x0B"); } else { $url = preg_replace('#^\w+://#', $scheme . '://', $url); } if (class_exists('GB_Hooks')) { /** * Filter the resulting URL after setting the scheme. * * @since 2.1.1 * * @param string $url * The complete URL including scheme and path. * @param string $scheme * Scheme applied to the URL. One of 'http', 'https', or 'relative'. * @param string $orig_scheme * Scheme requested for the URL. One of 'http', 'https', 'login', * 'login_post', 'admin', 'rpc', or 'relative'. */ $url = GB_Hooks::apply_filters('set_url_scheme', $url, $scheme, $orig_scheme); } return $url; } /** * Output rel=canonical for current page. * * @since 2.1.1 */ function rel_canonical() { $link = get_site_url($_SERVER['REQUEST_URI']); if (class_exists('GB_Hooks')) { /** * Filter rel=canonical link. * * @since 2.1.1 * * @param string $link * Full URL of rel=canonical link */ $link = GB_Hooks::apply_filters('rel_canonical', $link); } if (! empty($link)) echo "<link rel='canonical' href='$link' />\n"; } /** * Retrieve links for page numbers. * * @since 2.2.3 * * @param int $pagenum * Page number. * @param bool $escape * Whether to escape the URL for display, with esc_url(). * Defaults to true. Otherwise, prepares the URL with esc_url_raw(). * @return string link URL for the given page number. */ function get_pagenum_link($pagenum = 1, $escape = true) { // TODO: rewrite // global $gb_rewrite; $pagenum = (int) $pagenum; $request = remove_query_arg('pg'); $home_root = parse_url(home_url()); $home_root = (isset($home_root['path'])) ? $home_root['path'] : ''; $home_root = preg_quote($home_root, '|'); $request = preg_replace('|^' . $home_root . '|i', '', $request); $request = preg_replace('|^/+|', '', $request); // TODO: rewrite // if ( !$gb_rewrite->using_permalinks() || is_admin() ) { $base = trailingslashit(home_url()); if ($pagenum > 1) { $result = add_query_arg('pg', $pagenum, $base . $request); } else { $result = $base . $request; } // TODO: rewrite // } else { // $qs_regex = '|\?.*?$|'; // preg_match( $qs_regex, $request, $qs_match ); // if ( !empty( $qs_match[0] ) ) { // $query_string = $qs_match[0]; // $request = preg_replace( $qs_regex, '', $request ); // } else { // $query_string = ''; // } // $request = preg_replace( "|$gb_rewrite->pagination_base/\d+/?$|", '', $request); // $request = preg_replace( '|^' . preg_quote( $gb_rewrite->index, '|' ) . '|i', '', $request); // $request = ltrim($request, '/'); // $base = trailingslashit( get_bloginfo( 'url' ) ); // if ( $gb_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) // $base .= $gb_rewrite->index . '/'; // if ( $pagenum > 1 ) { // $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $gb_rewrite->pagination_base . "/" . $pagenum, 'paged' ); // } // $result = $base . $request . $query_string; // } if (class_exists('GB_Hooks')) { /** * Filter the page number link for the current request. * * @since 2.2.3 * * @param string $result * The page number link. */ $result = GB_Hooks::apply_filters('get_pagenum_link', $result); } if ($escape) return esc_url($result); else return esc_url_raw($result); } |