Пример #1
0
/**
 * Shortcode function for Lightbox2
 *
 * @see [lightbox name="gallery" post="1"]
 * @param $atts
 * @param null $content
 */
function lightbox_func($atts, $content = null)
{
    $a = shortcode_atts(array('name' => 'lightbox', 'class' => 'lightbox'), $atts);
    wp_register_script('lightbox', YONK_URL . 'assets/js/lightbox.min.js', false, '2.8.2');
    wp_enqueue_script('lightbox');
    wp_register_style('lightbox', YONK_URL . 'assets/css/lightbox.min.css', false, '2.8.2', 'all');
    wp_enqueue_style('lightbox');
    if (!isset($a['post'])) {
        global $post;
        $p = $post;
    } else {
        $p = get_post(intval($a['post']));
    }
    $image_urls = explode('~~~', Yonk_Frontend::get_meta('gallery_attachments', $p));
    ob_start();
    ?>
	<div style="position:relative;">
		<div id="<?php 
    echo $a['name'];
    ?>
" class="<?php 
    echo $a['class'];
    ?>
">
<?php 
    foreach ($image_urls as $url) {
        $attachment_id = get_attachment_id($url);
        $attachment = get_post($attachment_id);
        ?>

		<a href="<?php 
        echo $url;
        ?>
" data-lightbox="<?php 
        echo $a['name'];
        ?>
" data-title="<?php 
        echo $attachment->post_excerpt;
        ?>
">
			<img src="<?php 
        echo wp_get_attachment_thumb_url($attachment_id);
        ?>
" alt="<?php 
        echo $attachment->post_title;
        ?>
" />
		</a>

		<?php 
    }
    ?>
		</div>
	</div>
<?php 
    return ob_get_clean();
}
/**
 * redirect_url
 * 
 * this function translates a url into a usable request
 * (obviously this is for mod-rewrite friendly urls - if a conventional
 * url query string is provided it returns that and doesn't process further)
 * 
 * this is called by process_request() on the index page
 */
function process_url()
{
    // first check if we're using a standard query string
    if (!empty($_SERVER["QUERY_STRING"])) {
        return $_SERVER["QUERY_STRING"];
    }
    // if not start to derive the actual request
    $url_request = str_replace(WW_ROOT_SUFFIX, '', $_SERVER['REQUEST_URI']);
    $url_request = clean_start_slash($url_request);
    $url_request = clean_end_slash($url_request);
    // if nothing is requested this must be the front page
    if (empty($url_request)) {
        return false;
    }
    // break up urldata into an array
    $url_request = strtolower($url_request);
    $urldata = explode('/', $url_request);
    // theme option
    if ($urldata[0] == 'theme') {
        if (isset($urldata[1])) {
            $_SESSION['theme'] = start_slash($urldata[1]);
            header('Location: ' . WW_WEB_ROOT);
            exit;
        } elseif (isset($_SESSION['theme'])) {
            unset($_SESSION['theme']);
            header('Location: ' . WW_WEB_ROOT);
            exit;
        } else {
            header('Location: ' . WW_WEB_ROOT);
            exit;
        }
    }
    /*	
    	author, page, p, tag - can all appear at various places within the url string,
    	so we work out the parameter position and succeeding value first
    	n.b. 'page' refers to a listing page number; 'p' is an article page number
    */
    $var_pos = array('author', 'page', 'p', 'tag');
    foreach ($var_pos as $vp) {
        if (in_array($vp, $urldata)) {
            $var_key = array_search($vp, $urldata);
            $val_key = $var_key + 1;
            $var_value = $urldata[$val_key];
            // specific code for author
            if ($vp == 'author') {
                $_GET['author_url'] = $var_value;
                if (empty($urldata[2])) {
                    return $urldata;
                }
                // specific code for tag
            } elseif ($vp == 'tag') {
                $_GET['tag_url'] = $var_value;
                if (empty($urldata[2])) {
                    return $urldata;
                }
                // otherwise value must be page number
            } else {
                $var_value = (int) $var_value;
                if (!empty($var_value)) {
                    $_GET[$vp] = $var_value;
                } else {
                    show_404($urldata);
                    return $urldata;
                }
            }
        }
    }
    // does the number of GET vars already match the size of the urldata array?
    if (sizeof($urldata) == sizeof($_GET) * 2) {
        return $urldata;
    }
    /*	
    	allowed values for first position defined first_pos array - if any other value 
    	is sent then a string is assumed to be a category, while an integer is assumed to be a year
    */
    $first_pos = array('author', 'admin', 'download', 'id', 'feeds', 'feed', 'podcast', 'rss', 'rss-external', 'search', 'sitemap', 'tag');
    // now start checking for valid requests in the url string
    switch ($urldata) {
        //	redirect to admin pages (e.g. www.domain.com/admin/)
        case $urldata[0] == 'admin':
            $location = WW_REAL_WEB_ROOT . "/ww_edit/index.php";
            header('Location: ' . $location);
            exit;
            break;
            //	downloads (e.g. www.domain.com/download/mp3/sample/ OR www.domain.com/download/12/)
        //	downloads (e.g. www.domain.com/download/mp3/sample/ OR www.domain.com/download/12/)
        case $urldata[0] == 'download':
            if (!empty($urldata[2])) {
                $download_id = get_attachment_id($urldata[1], $urldata[2]);
                serve_attachment($download_id);
                // ext/filename
            } elseif (!empty($urldata[1])) {
                serve_attachment($urldata[1]);
                // id only
            }
            break;
            // feeds listing (e.g. www.domain.com/feeds/)
        // feeds listing (e.g. www.domain.com/feeds/)
        case $urldata[0] == 'feeds':
            $_GET['page_name'] = 'listing';
            $_GET['feed_listing'] = 1;
            break;
            //	article id - provides a quick way of accessing articles (e.g. www.domain.com/id/12/)
        //	article id - provides a quick way of accessing articles (e.g. www.domain.com/id/12/)
        case $urldata[0] == 'id':
            header('HTTP/1.1 302 Moved Temporarily');
            $_GET['article_id'] = (int) $urldata[1];
            break;
            //	podcast feed (e.g. www.domain.com/podcast/ OR www.domain.com/podcast/[category_url]/)
        //	podcast feed (e.g. www.domain.com/podcast/ OR www.domain.com/podcast/[category_url]/)
        case $urldata[0] == 'podcast':
            $_GET['feed'] = 'podcast';
            $_GET['page_name'] = 'feed';
            if (!empty($urldata[1])) {
                $_GET['category_url'] = $urldata[1];
            }
            break;
            //	redirect to rss feeds, check for additional parameters
            /*		e.g. www.domain.com/rss/
            					e.g. www.domain.com/feed/author/[author_url]
            					e.g. www.domain.com/rss/tag/[tag_url]
            					e.g. www.domain.com/rss/[category_url]
            					e.g. www.domain.com/rss/comments/[article_id - optional]
            					e.g. www.domain.com/rss-external/GET/param
            			*/
        //	redirect to rss feeds, check for additional parameters
        /*		e.g. www.domain.com/rss/
        					e.g. www.domain.com/feed/author/[author_url]
        					e.g. www.domain.com/rss/tag/[tag_url]
        					e.g. www.domain.com/rss/[category_url]
        					e.g. www.domain.com/rss/comments/[article_id - optional]
        					e.g. www.domain.com/rss-external/GET/param
        			*/
        case $urldata[0] == 'rss':
        case $urldata[0] == 'feed':
            if (!empty($feed_url)) {
                // redirect the main feed (i.e. no url parameters) if feed_url is specified
                header('HTTP/1.1 302 Moved Temporarily');
                header('Location: ' . $feed_url);
            }
            // but keep rss-external URLs on site permanently
        // but keep rss-external URLs on site permanently
        case $urldata[0] == 'rss-external':
            $_GET['page_name'] = 'feed';
            $_GET['feed'] = 'articles';
            // for comments
            if (!empty($urldata[1])) {
                if ($urldata[1] == 'comments') {
                    // defaults to all comments
                    $_GET['feed'] = 'comments';
                    // unless an article id is sent
                    if (!empty($urldata[2])) {
                        $_GET['article_id'] = (int) $urldata[2];
                        // article ID for comments
                    }
                    // for category (author or tag would have been picked up already
                } elseif (empty($urldata[2])) {
                    // other option is a category url
                    $_GET['category_url'] = $urldata[1];
                }
            }
            break;
            // redirect for searches (e.g. www.domain.com/search/[search term])
        // redirect for searches (e.g. www.domain.com/search/[search term])
        case $urldata[0] == 'search':
            $_GET['search'] = $urldata[1];
            break;
            // redirect to sitemap
            /* 
            	sitemap.xml is redirected in .htaccess but this line allows use to use
            	www.domain.com/sitemap/ as well
            */
        // redirect to sitemap
        /* 
        	sitemap.xml is redirected in .htaccess but this line allows use to use
        	www.domain.com/sitemap/ as well
        */
        case $urldata[0] == 'sitemap':
            include WW_ROOT . '/ww_view/sitemap-xml.php';
            exit;
            break;
            // translate months, years, days, permatitled posts
        // translate months, years, days, permatitled posts
        case $urldata[0] > '1900' && $urldata[0] < '2056':
            $_GET['year'] = $urldata[0];
            // if we find a year, let's also check for month
            if (!empty($urldata[1]) && ($urldata[1] >= '01' && $urldata[1] <= '12')) {
                $_GET['month'] = $urldata[1];
                // now check for day
                if (!empty($urldata[2]) && ($urldata[2] >= '01' && $urldata[2] <= '31')) {
                    $_GET['day'] = $urldata[2];
                    // check for a title
                    if (!empty($urldata[3])) {
                        $_GET['article_url'] = $urldata[3];
                    }
                }
            }
            break;
            // our final option is a category
        // our final option is a category
        case !in_array($urldata[0], $first_pos):
            $category_url = $urldata[0];
            $_GET['category_url'] = $category_url;
            $allowed_after = array('author', 'page', 'tag');
            if (!empty($urldata[1]) && !in_array($urldata[1], $allowed_after)) {
                $_GET['article_url'] = $urldata[1];
            }
            break;
            // if nothing matches then 404 it
        // if nothing matches then 404 it
        default:
            show_404($urldata);
            return false;
            break;
    }
    return $urldata;
}