function published_time_links()
 {
     $archive_year = get_the_time('Y');
     $archive_month = get_the_time('m');
     $archive_day = get_the_time('d');
     echo get_day_link($archive_year, $archive_month, $archive_day);
 }
Esempio n. 2
0
 function widget($args, $instance)
 {
     global $post;
     /* PRINT THE WIDGET */
     extract($args, EXTR_SKIP);
     $title = !empty($instance['title']) ? $instance['title'] : '';
     if (!is_single()) {
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title;
         echo $title;
         echo $after_title;
     }
     $name = get_the_author_meta('display_name', $post->post_author);
     echo '<div class="large-icons">';
     echo '<ul>';
     edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'myThemes'), '<li>', '</li>');
     echo '<li><a href="' . get_day_link(get_post_time('Y', false, $post->ID), get_post_time('m', false, $post->ID), get_post_time('d', false, $post->ID)) . '">';
     echo '<time datetime="' . get_post_time('Y-m-d', false, $post->ID) . '"><i class="icon-calendar"></i>' . get_post_time(get_option('date_format'), false, $post->ID) . '</time></a></li>';
     echo '<li><a href="' . get_author_posts_url($post->post_author) . '" title="' . __('Writed by ', 'myThemes') . ' ' . $name . '"><i class="icon-user-5"></i>' . $name . '</a></li>';
     if ($post->comment_status == 'open') {
         $nr = get_comments_number($post->ID);
         if ($nr == 1) {
             $comments = $nr . ' ' . __('Comment', 'myThemes');
         } else {
             $comments = $nr . ' ' . __('Comments', 'myThemes');
         }
         echo '<li><a href="' . get_comments_link($post->ID) . '"><i class="icon-comment"></i>' . $comments . '</a></li>';
     }
     echo '</ul>';
     echo '</div>';
     echo $after_widget;
 }
Esempio n. 3
0
 /**
  * Prints HTML with meta information for the current post-date/time and author.
  */
 function zerif_posted_on_child()
 {
     $time_string = '<time class="entry-date published" itemprop="datePublished" datetime="%1$s">%2$s</time>';
     if (get_the_time('U') !== get_the_modified_time('U')) {
         $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
     }
     $time_string = sprintf($time_string, esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_attr(get_the_modified_date('c')), esc_html(get_the_modified_date()));
     printf(__('<span class="posted-on">Originally appeared in <a href="%2$s">%3$s</a> on  %1$s</span>', 'zerif'), sprintf('<a href="%1$s" rel="bookmark">%2$s</a>', esc_url(get_day_link(get_the_date('Y'), get_the_date('m'), get_the_date('d'))), $time_string), esc_attr(get_field('original_source_url')), esc_attr(get_field('original_source_media_outlet')));
 }
Esempio n. 4
0
 /**
  * Prints HTML with meta information for the current post-date/time and author.
  */
 function simple_life_posted_on()
 {
     $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
     if (get_the_time('U') !== get_the_modified_time('U')) {
         $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
     }
     $time_string = sprintf($time_string, esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_attr(get_the_modified_date('c')), esc_html(get_the_modified_date()));
     $posted_on = sprintf('%s', '<i class="fa fa-calendar" aria-hidden="true"></i> <a href="' . esc_url(get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'))) . '" rel="bookmark">' . $time_string . '</a>');
     $byline = sprintf('<i class="fa fa-user" aria-hidden="true"></i> %s', '<span class="author vcard"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></span>');
     echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>';
     // WPCS: XSS OK.
 }
Esempio n. 5
0
 public function test_page_type_date()
 {
     $this->go_to(get_year_link('2015'));
     $this->assertTrue(is_year());
     $this->assertSame('date', Ad_Layers::instance()->get_current_page_type());
     $this->go_to(get_month_link('2015', '03'));
     $this->assertTrue(is_month());
     $this->assertSame('date', Ad_Layers::instance()->get_current_page_type());
     $this->go_to(get_day_link('2015', '03', '14'));
     $this->assertTrue(is_day());
     $this->assertSame('date', Ad_Layers::instance()->get_current_page_type());
 }
        /**
         * The template part for displaying entry metas
         *
         * @package Customizr
         * @since Customizr 1.0
         */
        function tc_post_metas()
        {
            global $post;
            //when do we display the metas ?
            //1) we don't show metas on home page, 404, search page by default
            //2) +filter conditions
            $post_metas_bool = tc__f('__is_home') || is_404() || 'page' == $post->post_type ? false : true;
            $post_metas_bool = apply_filters('tc_show_post_metas', $post_metas_bool);
            if (!$post_metas_bool) {
                return;
            }
            ob_start();
            ?>

            <div class="entry-meta">
                <?php 
            if ('attachment' == $post->post_type) {
                $metadata = wp_get_attachment_metadata();
                printf('%1$s <span class="entry-date"><time class="entry-date updated" datetime="%2$s">%3$s</time></span> %4$s %5$s', '<span class="meta-prep meta-prep-entry-date">' . __('Published', 'customizr') . '</span>', apply_filters('tc_use_the_post_modified_date', false) ? esc_attr(get_the_date('c')) : esc_attr(get_the_modified_date('c')), esc_html(get_the_date()), isset($metadata['width']) && isset($metadata['height']) ? __('at dimensions', 'customizr') . '<a href="' . esc_url(wp_get_attachment_url()) . '" title="' . __('Link to full-size image', 'customizr') . '"> ' . $metadata['width'] . ' &times; ' . $metadata['height'] . '</a>' : '', __('in', 'customizr') . '<a href="' . esc_url(get_permalink($post->post_parent)) . '" title="' . __('Return to ', 'customizr') . esc_attr(strip_tags(get_the_title($post->post_parent))) . '" rel="gallery"> ' . get_the_title($post->post_parent) . '</a>.');
            } else {
                $categories_list = $this->tc_category_list();
                $tag_list = $this->tc_tag_list();
                $date = apply_filters('tc_date_meta', sprintf('<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s">%4$s</time></a>', esc_url(get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'))), esc_attr(get_the_time()), apply_filters('tc_use_the_post_modified_date', false) ? esc_attr(get_the_date('c')) : esc_attr(get_the_modified_date('c')), esc_html(get_the_date())));
                //end filter
                $author = apply_filters('tc_author_meta', sprintf('<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by %s', 'customizr'), get_the_author())), get_the_author()));
                //end filter
                // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
                $utility_text = '';
                if ($tag_list) {
                    $utility_text = __('This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'customizr');
                } elseif ($categories_list) {
                    $utility_text = __('This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'customizr');
                } else {
                    $utility_text = __('This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'customizr');
                }
                $utility_text = apply_filters('tc_meta_utility_text', $utility_text);
                //echoes every metas components
                printf($utility_text, $categories_list, $tag_list, $date, $author);
            }
            //endif attachment
            ?>

            </div><!-- .entry-meta -->

            <?php 
            $html = ob_get_contents();
            if ($html) {
                ob_end_clean();
            }
            echo apply_filters('tc_post_metas', $html);
        }
Esempio n. 7
0
function gardenia_entry_meta()
{
    $gardenia_categories_list = get_the_category_list(',', '');
    $gardenia_tag_list = get_the_tag_list('', ',');
    $gardenia_author = get_the_author();
    $gardenia_author_url = esc_url(get_author_posts_url(get_the_author_meta('ID')));
    $gardenia_comments = wp_count_comments(get_the_ID());
    $gardenia_date = sprintf('<time datetime="%1$s">%2$s</time>', sanitize_text_field(get_the_date('c')), esc_html(get_the_date()));
    ?>
	
		<div class="fancy_categories">
                <div class="glyphicon glyphicon-user color"><a href="<?php 
    echo $gardenia_author_url;
    ?>
" rel="tag"><?php 
    echo $gardenia_author;
    ?>
</a></div>
                <div class="glyphicon glyphicon-calendar color"><a href="<?php 
    echo esc_url(get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j')));
    ?>
" rel="tag"><?php 
    echo $gardenia_date;
    ?>
</a></div>
               <?php 
    if (!empty($gardenia_tag_list)) {
        ?>
<div class="glyphicon glyphicon-tag color"><?php 
        echo $gardenia_tag_list;
        ?>
</div><?php 
    }
    ?>
               <?php 
    if (!empty($gardenia_categories_list)) {
        ?>
<div class="glyphicon glyphicon-folder-open color"><?php 
        echo $gardenia_categories_list;
        ?>
</div><?php 
    }
    ?>
                <div class="glyphicon glyphicon-comment color"><span class="comment"><?php 
    comments_number(__('No Comments', 'gardenia'), __('1 Comment', 'gardenia'), __('% Comments', 'gardenia'));
    ?>
</span></div>
		</div>
<?php 
}
    function wpbppost_meta()
    {
        ?>

<ul class="post-meta inline-list">
  <li>
    Posted:
    <a href="<?php 
        echo get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'));
        ?>
">
      <?php 
        printf('<time datetime="%1$s">%2$s</time>', esc_attr(get_the_date('c')), esc_html(get_the_date()));
        ?>
    </a>
  </li>
  <li>
    <?php 
        the_tags('Tags: ', ', ', '');
        ?>
  </li>
  <li>
    <?php 
        $categories = get_the_category();
        $separator = ', ';
        $output = '';
        if (!empty($categories)) {
            foreach ($categories as $category) {
                $output .= '<a href="' . esc_url(get_category_link($category->term_id)) . '" alt="' . esc_attr(sprintf(__('View all posts in %s', 'textdomain'), $category->name)) . '">' . esc_html($category->name) . '</a>' . $separator;
            }
            echo 'Categories: ';
            echo trim($output, $separator);
        }
        ?>
  </li>
  <li>
    Author:
    <a href="<?php 
        echo esc_url(get_author_posts_url(get_the_author_meta('ID')));
        ?>
"><?php 
        echo get_the_author_meta('display_name');
        ?>
</a>
  </li>
</ul>

<?php 
    }
Esempio n. 9
0
/**
 * Get all dates archives urls associated to a specific post
 *
 * @since 1.0
 *
 * @param int $post_ID The post ID
 * @return array $urls List of dates URLs
 */
function get_rocket_post_dates_urls($post_ID)
{
    // Get the day and month of the post
    $date = explode('-', get_the_time('Y-m-d', $post_ID));
    $urls = array(get_year_link($date[0]) . 'index.html', get_year_link($date[0]) . $GLOBALS['wp_rewrite']->pagination_base, get_month_link($date[0], $date[1]) . 'index.html', get_month_link($date[0], $date[1]) . $GLOBALS['wp_rewrite']->pagination_base, get_day_link($date[0], $date[1], $date[2]));
    /**
     * Filter the list of dates URLs
     *
     * @since 1.1.0
     *
     * @param array $urls List of dates URLs
     */
    $urls = apply_filters('rocket_post_dates_urls', $urls);
    return $urls;
}
function avocation_entry_meta()
{
    $avocation_category_list = get_the_category_list(', ', ' <i class="fa fa-list-all"></i> ');
    $avocation_tag_list = get_the_tag_list('<i class="fa fa-tags"></i> ', ' , ');
    $avocation_date = sprintf('<time datetime="%1$s">%2$s</time>', esc_attr(get_the_date('c')), esc_html(get_the_date()));
    $avocation_author = sprintf('<a href="%1$s" title="%2$s" >%3$s</a>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by %s', 'avocation'), get_the_author())), get_the_author());
    if ($avocation_category_list) {
        $avocation_utility_text = '<div class="blog-meta"><ul><li><a href=' . esc_url(get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'))) . ' > <i class="fa fa-calendar"></i> %3$s </a></li> <li> <i class="fa fa-user"></i> %4$s </li> <li>  %2$s </li> <li> <i class="fa fa-list-alt"></i> %1$s </li> <li> <i class="fa fa-comment"></i> ' . avocation_comment_number_custom() . '</li></ul></div>';
    } elseif ($avocation_tag_list) {
        $avocation_utility_text = '<div class="blog-meta"><ul><li><a href=' . esc_url(get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'))) . ' > <i class="fa fa-calendar"></i> %3$s </a></li> <li> <i class="fa fa-user"></i> %4$s </li> </li> <li>  %2$s </li>  <li>  %1$s </li> <li> <i class="fa fa-comment"></i> ' . avocation_comment_number_custom() . '</li></ul></div>';
    } else {
        $avocation_utility_text = '<div class="blog-meta"><ul><li><a href=' . esc_url(get_day_link(get_post_time('Y'), get_post_time('m'), get_post_time('j'))) . ' > <i class="fa fa-calendar"></i> %3$s </a></li> <li> <i class="fa fa-user"></i> %4$s </li>  <li> <i class="fa fa-comment"></i> ' . avocation_comment_number_custom() . '</li></ul></div>';
    }
    printf($avocation_utility_text, $avocation_category_list, $avocation_tag_list, $avocation_date, $avocation_author);
}
 function widget($args, $instance)
 {
     global $post;
     /* PRINT THE WIDGET */
     extract($args, EXTR_SKIP);
     $instance = wp_parse_args((array) $instance, array('title' => ''));
     $title = esc_attr($instance['title']);
     if (!is_single()) {
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title;
         echo apply_filters('widget_title', $title, $instance, $this->id_base);
         echo $after_title;
     }
     $name = get_the_author_meta('display_name', $post->post_author);
     echo '<div class="large-icons">';
     echo '<ul>';
     edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'myThemes'), '<li>', '</li>');
     echo '<li><a href="' . get_day_link(get_post_time('Y', false, $post->ID), get_post_time('m', false, $post->ID), get_post_time('d', false, $post->ID)) . '">';
     echo '<time datetime="' . get_post_time('Y-m-d', false, $post->ID) . '"><i class="icon-calendar"></i>' . get_post_time(get_option('date_format'), false, $post->ID) . '</time></a></li>';
     echo '<li><a href="' . get_author_posts_url($post->post_author) . '" title="' . __('Writed by ', 'myThemes') . ' ' . $name . '"><i class="icon-user-5"></i>' . $name . '</a></li>';
     if ($post->comment_status == 'open') {
         $nr = get_comments_number($post->ID);
         if ($nr == 1) {
             $comments = $nr . ' ' . __('Comment', 'myThemes');
         } else {
             $comments = $nr . ' ' . __('Comments', 'myThemes');
         }
         echo '<li><a href="' . get_comments_link($post->ID) . '"><i class="icon-comment"></i>' . $comments . '</a></li>';
     }
     if (function_exists('stats_get_csv')) {
         $args = array('days' => -1, 'post_id' => $post->ID);
         $result = stats_get_csv('postviews', $args);
         $views = $result[0]['views'];
         $nr_views = number_format_i18n($views);
         $label_views = __('views', 'myThemes');
         if ($nr_views == 1) {
             $label_views = __('view', 'myThemes');
         }
         echo '<li><i class="icon-eye-2"></i> ' . $nr_views . ' ' . $label_views . '</li>';
     }
     echo '</ul>';
     echo '</div>';
     echo $after_widget;
 }
 function widget($args, $instance)
 {
     global $post;
     /* PRINT THE WIDGET */
     extract($args, EXTR_SKIP);
     $instance = wp_parse_args((array) $instance, array('title' => ''));
     $title = $instance['title'];
     if (!is_single()) {
         return;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title;
         echo apply_filters('widget_title', esc_attr($title), $instance, $this->id_base);
         echo $after_title;
     }
     $y = esc_attr(get_post_time('Y', false, $post->ID));
     $m = esc_attr(get_post_time('m', false, $post->ID));
     $d = esc_attr(get_post_time('d', false, $post->ID));
     $name = get_the_author_meta('display_name', $post->post_author);
     $dtime = get_post_time('Y-m-d', false, $post->ID);
     $ptime = get_post_time(esc_attr(get_option('date_format')), false, $post->ID, true);
     echo '<div class="large-icons">';
     echo '<ul>';
     edit_post_link('<i class="icon-pencil"></i>' . __('Edit', 'treeson'), '<li>', '</li>');
     echo '<li><a href="' . esc_url(get_day_link($y, $m, $d)) . '">';
     echo '<time datetime="' . esc_attr($dtime) . '"><i class="icon-calendar"></i>' . esc_html($ptime) . '</time></a></li>';
     echo '<li><a href="' . esc_url(get_author_posts_url($post->post_author)) . '" title="' . sprintf(__('Writed by %s', 'treeson'), esc_attr($name)) . '"><i class="icon-user-5"></i>' . esc_html($name) . '</a></li>';
     if ($post->comment_status == 'open') {
         $nr = get_comments_number($post->ID);
         echo '<li>';
         echo '<a href="' . esc_url(get_comments_link($post->ID)) . '">';
         echo '<i class="icon-comment"></i>';
         echo sprintf(_nx('%s Comment', '%s Comments', absint($nr), 'Number of comment(s) from widget "myThemes: Meta Details"', 'treeson'), number_format_i18n(absint($nr)));
         echo '</a></li>';
     }
     if (function_exists('stats_get_csv')) {
         $args = array('days' => -1, 'post_id' => $post->ID);
         $result = stats_get_csv('postviews', $args);
         $views = $result[0]['views'];
         echo '<li><i class="icon-eye-2"></i> ' . sprintf(_n('%s view', '%s views', absint($views), 'treeson'), number_format_i18n(absint($views))) . '</li>';
     }
     echo '</ul>';
     echo '</div>';
     echo $after_widget;
 }
 function gdlr_get_cause_info($array = array(), $post_option = array(), $wrapper = true)
 {
     global $theme_option;
     $ret = '';
     foreach ($array as $post_info) {
         switch ($post_info) {
             case 'date':
                 $ret .= '<div class="cause-info cause-date"><i class="icon-time"></i>';
                 $ret .= '<a href="' . get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')) . '">';
                 //$ret .= '<time date-time="' . get_the_time('Y-m-d') . '" pubdate>';
                 $ret .= get_the_time($theme_option['date-format']);
                 //$ret .= '</time>';
                 $ret .= '</a>';
                 $ret .= '</div>';
                 break;
             case 'category':
                 $cat = get_the_term_list(get_the_ID(), 'cause_category', '', '<span class="sep">,</span> ', '');
                 if (empty($cat)) {
                     break;
                 }
                 $ret .= '<div class="cause-info cause-category"><i class="icon-folder-close-alt"></i>';
                 $ret .= $cat;
                 $ret .= '</div>';
                 break;
             case 'pdf':
                 if (!empty($post_option['pdf'])) {
                     $ret .= '<div class="cause-info cause-pdf"><i class="icon-file-text"></i>';
                     $ret .= '<a href="' . wp_get_attachment_url($post_option['pdf']) . '" >';
                     $ret .= __('Download PDF', 'gdlr-cause');
                     $ret .= '</a>';
                     $ret .= '</div>';
                 }
                 break;
         }
     }
     if ($wrapper && !empty($ret)) {
         return '<div class="gdlr-cause-info">' . $ret . '<div class="clear"></div></div>';
     } else {
         if (!empty($ret)) {
             return $ret . '<div class="clear"></div>';
         }
     }
     return '';
 }
Esempio n. 14
0
function get_post_footer()
{
    $p_y = get_the_time('Y');
    $p_m = get_the_time('m');
    $p_d = get_the_time('d');
    $p_date = $p_y . '/' . $p_m . '/' . $p_d;
    $p_link = get_permalink();
    $result = '<div class="post-footer"><a href="' . $p_link . '" title="' . $p_link . '">#</a> | ';
    $result .= '<a href="' . get_day_link($p_y, $p_m, $p_d) . '" title="' . $p_date . ' ' . get_the_time("h:i:s a") . '">' . $p_date . '</a> | ' . get_the_category_list(' &bull; ');
    if (!is_page() && comments_open()) {
        $c_num = get_comments_number();
        if ($c_num == 0) {
            $c = __('No Comments', 'nutcrackr');
        } elseif ($c_num > 1) {
            $c = sprintf(__('%d Comments', 'nutcrackr'), $c_num);
        } else {
            $c = __('1 Comment', 'nutcrackr');
        }
        $result .= ' | <span class="number-of-comments"><a href="' . $p_link . '#comments" title="' . __('comment', 'nutcrackr') . '">' . $c . '</a></span>';
    }
    $result .= '</div>';
    echo $result;
}
function get_calendar($daylength = 1)
{
    global $wpdb, $wp_id, $m, $monthnum, $year, $timedifference, $month, $weekday, $posts, $wp_month_format;
    // Quick check. If we have no posts at all, abort!
    if (!$posts) {
        $gotsome = $wpdb->get_var("SELECT ID from {$wpdb->posts[$wp_id]} WHERE post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
        if (!$gotsome) {
            return;
        }
    }
    if (isset($_GET['w'])) {
        $w = '' . intval($_GET['w']);
    }
    $time_difference = get_settings('time_difference');
    // Let's figure out when we are
    if (!empty($monthnum) && !empty($year)) {
        $thismonth = '' . intval($monthnum);
        $thisyear = '' . intval($year);
    } elseif (!empty($w)) {
        // We need to get the month from MySQL
        $thisyear = '' . intval(substr($m, 0, 4));
        $d = ($w - 1) * 7 + 6;
        //it seems MySQL's weeks disagree with PHP's
        $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL {$d} DAY) ), '%m')");
    } elseif (!empty($m)) {
        $calendar = substr($m, 0, 6);
        $thisyear = '' . intval(substr($m, 0, 4));
        if (strlen($m) < 6) {
            $thismonth = '01';
        } else {
            $thismonth = '' . intval(substr($m, 4, 2));
        }
    } else {
        $thisyear = intval(date('Y', time() + $time_difference * 3600));
        $thismonth = intval(date('m', time() + $time_difference * 3600));
    }
    $unixmonth = mktime(0, 0, 0, $thismonth, 1, $thisyear);
    // Get the next and previous month and year with at least one post
    $previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year\n\t\t\tFROM {$wpdb->posts[$wp_id]}\n\t\t\tWHERE post_date < '{$thisyear}-{$thismonth}-01'\n\t\t\tAND post_status = 'publish'\n\t\t\t\t\t\t\t  ORDER BY post_date DESC\n\t\t\t\t\t\t\t  LIMIT 1");
    $next = $wpdb->get_row("SELECT  DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year\n\t\t\tFROM {$wpdb->posts[$wp_id]}\n\t\t\tWHERE post_date >  '{$thisyear}-{$thismonth}-01'\n\t\t\tAND MONTH( post_date ) != MONTH( '{$thisyear}-{$thismonth}-01' )\n\t\t\tAND post_status = 'publish'\n\t\t\t\t\t\t\t  ORDER  BY post_date ASC\n\t\t\t\t\t\t\t  LIMIT 1");
    $month_str = ereg_replace('%MONTH', $month[zeroise($thismonth, 2)], $wp_month_format);
    $month_str = ereg_replace('%YEAR', date('Y', $unixmonth), $month_str);
    echo '<table id="wp-calendar">
	<caption>' . $month_str . '</caption>
	<thead>
	<tr>';
    foreach ($weekday as $wd) {
        if (function_exists('mb_substr')) {
            echo "\n\t\t<th abbr='{$wd}' scope='col' title='{$wd}'>" . mb_substr($wd, 0, $daylength) . '</th>';
        } else {
            echo "\n\t\t<th abbr='{$wd}' scope='col' title='{$wd}'>" . substr($wd, 0, $daylength) . '</th>';
        }
    }
    echo '
	</tr>
	</thead>

	<tfoot>
	<tr>';
    if ($previous) {
        if (function_exists('mb_substr')) {
            $smonth_name = mb_substr($month[zeroise($previous->month, 2)], 0, 3);
        } else {
            $smonth_name = substr($month[zeroise($previous->month, 2)], 0, 3);
        }
        $month_str = ereg_replace('%MONTH', $month[zeroise($previous->month, 2)], $wp_month_format);
        $month_str = ereg_replace('%YEAR', date('Y', mktime(0, 0, 0, $previous->month, 1, $previous->year)), $month_str);
        echo "\n\t\t" . '<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="View posts for ' . $month_str . '">&laquo; ' . $smonth_name . '</a></td>';
    } else {
        echo "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    }
    echo "\n\t\t" . '<td class="pad">&nbsp;</td>';
    if ($next) {
        if (function_exists('mb_substr')) {
            $smonth_name = mb_substr($month[zeroise($next->month, 2)], 0, 3);
        } else {
            $smonth_name = substr($month[zeroise($next->month, 2)], 0, 3);
        }
        $month_str = ereg_replace('%MONTH', $month[zeroise($next->month, 2)], $wp_month_format);
        $month_str = ereg_replace('%YEAR', date('Y', mktime(0, 0, 0, $next->month, 1, $next->year)), $month_str);
        echo "\n\t\t" . '<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="View posts for ' . $month_str . '">' . $smonth_name . ' &raquo;</a></td>';
    } else {
        echo "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
    }
    echo '
	</tr>
	</tfoot>

	<tbody>
	<tr>';
    // Get days with posts
    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)\n\t\t\tFROM {$wpdb->posts[$wp_id]} WHERE MONTH(post_date) = {$thismonth}\n\t\t\tAND YEAR(post_date) = {$thisyear}\n\t\t\tAND post_status = 'publish'\n\t\t\tAND post_date < '" . date("Y-m-d H:i:s", time() + $time_difference * 3600) . "'", ARRAY_N);
    if ($dayswithposts) {
        foreach ($dayswithposts as $daywith) {
            $daywithpost[] = $daywith[0];
        }
    } else {
        $daywithpost = array();
    }
    if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") || strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "camino") || strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "safari")) {
        $ak_title_separator = "\n";
    } else {
        $ak_title_separator = ", ";
    }
    $ak_titles_for_day = array();
    $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " . "FROM {$wpdb->posts[$wp_id]} " . "WHERE YEAR(post_date) = '{$thisyear}' " . "AND MONTH(post_date) = '{$thismonth}' " . "AND post_date < '" . date("Y-m-d H:i:s", time() + $time_difference * 3600) . "' " . "AND post_status = 'publish'");
    if ($ak_post_titles) {
        foreach ($ak_post_titles as $ak_post_title) {
            if (empty($ak_titles_for_day["day_" . $ak_post_title->dom])) {
                $ak_titles_for_day["day_" . $ak_post_title->dom] = '';
            }
            if (empty($ak_titles_for_day["{$ak_post_title->dom}"])) {
                // first one
                $ak_titles_for_day["{$ak_post_title->dom}"] = htmlspecialchars(stripslashes($ak_post_title->post_title));
            } else {
                $ak_titles_for_day["{$ak_post_title->dom}"] .= $ak_title_separator . htmlspecialchars(stripslashes($ak_post_title->post_title));
            }
        }
    }
    // See how much we should pad in the beginning
    $pad = intval(date('w', $unixmonth));
    if (0 != $pad) {
        echo "\n\t\t<td colspan='{$pad}' class='pad'>&nbsp;</td>";
    }
    $daysinmonth = intval(date('t', $unixmonth));
    for ($day = 1; $day <= $daysinmonth; ++$day) {
        if (isset($newrow) && $newrow) {
            echo "\n\t</tr>\n\t<tr>\n\t\t";
        }
        $newrow = false;
        if ($day == date('j', time() + $time_difference * 3600) && $thismonth == date('m', time() + $time_difference * 3600)) {
            echo '<td id="today">';
        } else {
            echo "<td>";
        }
        if (in_array($day, $daywithpost)) {
            // any posts today?
            echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"{$ak_titles_for_day[$day]}\">{$day}</a>";
        } else {
            echo $day;
        }
        echo '</td>';
        if (6 == date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear))) {
            $newrow = true;
        }
    }
    $pad = 7 - date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear));
    if ($pad != 0 && $pad != 7) {
        echo "\n\t\t<td class='pad' colspan='{$pad}'>&nbsp;</td>";
    }
    echo "\n\t</tr>\n\t</tbody>\n\t</table>";
}
Esempio n. 16
0
/**
 * Display calendar with days that have posts as links.
 *
 * The calendar is cached, which will be retrieved, if it exists. If there are
 * no posts for the month, then it will not be displayed.
 *
 * @since 1.0.0
 *
 * @global wpdb      $wpdb
 * @global int       $m
 * @global int       $monthnum
 * @global int       $year
 * @global WP_Locale $wp_locale
 * @global array     $posts
 *
 * @param bool $initial Optional, default is true. Use initial calendar names.
 * @param bool $echo    Optional, default is true. Set to false for return.
 * @return string|void String when retrieving.
 */
function get_calendar($initial = true, $echo = true)
{
    global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    $key = md5($m . $monthnum . $year);
    if ($cache = wp_cache_get('get_calendar', 'calendar')) {
        if (is_array($cache) && isset($cache[$key])) {
            if ($echo) {
                /** This filter is documented in wp-includes/general-template.php */
                echo apply_filters('get_calendar', $cache[$key]);
                return;
            } else {
                /** This filter is documented in wp-includes/general-template.php */
                return apply_filters('get_calendar', $cache[$key]);
            }
        }
    }
    if (!is_array($cache)) {
        $cache = array();
    }
    // Quick check. If we have no posts at all, abort!
    if (!$posts) {
        $gotsome = $wpdb->get_var("SELECT 1 as test FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
        if (!$gotsome) {
            $cache[$key] = '';
            wp_cache_set('get_calendar', $cache, 'calendar');
            return;
        }
    }
    if (isset($_GET['w'])) {
        $w = '' . intval($_GET['w']);
    }
    // week_begins = 0 stands for Sunday
    $week_begins = intval(get_option('start_of_week'));
    // Let's figure out when we are
    if (!empty($monthnum) && !empty($year)) {
        $thismonth = '' . zeroise(intval($monthnum), 2);
        $thisyear = '' . intval($year);
    } elseif (!empty($w)) {
        // We need to get the month from MySQL
        $thisyear = '' . intval(substr($m, 0, 4));
        $d = ($w - 1) * 7 + 6;
        //it seems MySQL's weeks disagree with PHP's
        $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL {$d} DAY) ), '%m')");
    } elseif (!empty($m)) {
        $thisyear = '' . intval(substr($m, 0, 4));
        if (strlen($m) < 6) {
            $thismonth = '01';
        } else {
            $thismonth = '' . zeroise(intval(substr($m, 4, 2)), 2);
        }
    } else {
        $thisyear = gmdate('Y', current_time('timestamp'));
        $thismonth = gmdate('m', current_time('timestamp'));
    }
    $unixmonth = mktime(0, 0, 0, $thismonth, 1, $thisyear);
    $last_day = date('t', $unixmonth);
    // Get the next and previous month and year with at least one post
    $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_date < '{$thisyear}-{$thismonth}-01'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1");
    $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year\n\t\tFROM {$wpdb->posts}\n\t\tWHERE post_date > '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1");
    /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    $calendar_caption = _x('%1$s %2$s', 'calendar caption');
    $calendar_output = '<table id="wp-calendar">
	<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
	<thead>
	<tr>';
    $myweek = array();
    for ($wdcount = 0; $wdcount <= 6; $wdcount++) {
        $myweek[] = $wp_locale->get_weekday(($wdcount + $week_begins) % 7);
    }
    foreach ($myweek as $wd) {
        $day_name = $initial ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
        $wd = esc_attr($wd);
        $calendar_output .= "\n\t\t<th scope=\"col\" title=\"{$wd}\">{$day_name}</th>";
    }
    $calendar_output .= '
	</tr>
	</thead>

	<tfoot>
	<tr>';
    if ($previous) {
        $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    } else {
        $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    }
    $calendar_output .= "\n\t\t" . '<td class="pad">&nbsp;</td>';
    if ($next) {
        $calendar_output .= "\n\t\t" . '<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    } else {
        $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
    }
    $calendar_output .= '
	</tr>
	</tfoot>

	<tbody>
	<tr>';
    $daywithpost = array();
    // Get days with posts
    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)\n\t\tFROM {$wpdb->posts} WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'\n\t\tAND post_type = 'post' AND post_status = 'publish'\n\t\tAND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
    if ($dayswithposts) {
        foreach ((array) $dayswithposts as $daywith) {
            $daywithpost[] = $daywith[0];
        }
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) {
        $ak_title_separator = "\n";
    } else {
        $ak_title_separator = ', ';
    }
    $ak_titles_for_day = array();
    $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom " . "FROM {$wpdb->posts} " . "WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " . "AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " . "AND post_type = 'post' AND post_status = 'publish'");
    if ($ak_post_titles) {
        foreach ((array) $ak_post_titles as $ak_post_title) {
            /** This filter is documented in wp-includes/post-template.php */
            $post_title = esc_attr(apply_filters('the_title', $ak_post_title->post_title, $ak_post_title->ID));
            if (empty($ak_titles_for_day['day_' . $ak_post_title->dom])) {
                $ak_titles_for_day['day_' . $ak_post_title->dom] = '';
            }
            if (empty($ak_titles_for_day["{$ak_post_title->dom}"])) {
                // first one
                $ak_titles_for_day["{$ak_post_title->dom}"] = $post_title;
            } else {
                $ak_titles_for_day["{$ak_post_title->dom}"] .= $ak_title_separator . $post_title;
            }
        }
    }
    // See how much we should pad in the beginning
    $pad = calendar_week_mod(date('w', $unixmonth) - $week_begins);
    if (0 != $pad) {
        $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr($pad) . '" class="pad">&nbsp;</td>';
    }
    $daysinmonth = intval(date('t', $unixmonth));
    for ($day = 1; $day <= $daysinmonth; ++$day) {
        if (isset($newrow) && $newrow) {
            $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
        }
        $newrow = false;
        if ($day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp'))) {
            $calendar_output .= '<td id="today">';
        } else {
            $calendar_output .= '<td>';
        }
        if (in_array($day, $daywithpost)) {
            // any posts today?
            $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . '" title="' . esc_attr($ak_titles_for_day[$day]) . "\">{$day}</a>";
        } else {
            $calendar_output .= $day;
        }
        $calendar_output .= '</td>';
        if (6 == calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins)) {
            $newrow = true;
        }
    }
    $pad = 7 - calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins);
    if ($pad != 0 && $pad != 7) {
        $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr($pad) . '">&nbsp;</td>';
    }
    $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    $cache[$key] = $calendar_output;
    wp_cache_set('get_calendar', $cache, 'calendar');
    if ($echo) {
        /**
         * Filter the HTML calendar output.
         *
         * @since 3.0.0
         *
         * @param string $calendar_output HTML output of the calendar.
         */
        echo apply_filters('get_calendar', $calendar_output);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('get_calendar', $calendar_output);
    }
}
Esempio n. 17
0
 function get_ls_languages($template_args = array())
 {
     //Returns false if is admin and settings are corrupted
     if (is_admin() && !SitePress::check_settings_integrity()) {
         return false;
     }
     /** @var $wp_query WP_Query */
     global $sitepress, $wpdb, $wp_query, $w_this_lang;
     $current_language = $this->get_current_language();
     $default_language = $this->get_default_language();
     $cache_key_args = $template_args ? array_filter($template_args) : array('default');
     $cache_key_args[] = $current_language;
     $cache_key_args[] = $default_language;
     $cache_key_args = array_filter($cache_key_args);
     $cache_key = md5(json_encode($cache_key_args));
     $cache_group = 'ls_languages';
     $found = false;
     $ls_languages = wp_cache_get($cache_key, $cache_group, $found);
     if ($found) {
         return $ls_languages;
     }
     if (is_null($this->wp_query)) {
         $this->set_wp_query();
     }
     // use original wp_query for this
     // backup current $wp_query
     if (!isset($wp_query)) {
         return $this->get_active_languages();
     }
     $_wp_query_back = clone $wp_query;
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $this->wp_query;
     $w_active_languages = $this->get_active_languages();
     $this_lang = $this->this_lang;
     if ($this_lang == 'all') {
         $w_this_lang = array('code' => 'all', 'english_name' => 'All languages', 'display_name' => __('All languages', 'sitepress'));
     } else {
         $w_this_lang = $this->get_language_details($this_lang);
     }
     if (isset($template_args['skip_missing'])) {
         //override default setting
         $icl_lso_link_empty = !$template_args['skip_missing'];
     } else {
         $icl_lso_link_empty = $this->settings['icl_lso_link_empty'];
     }
     // 1. Determine translations
     if (is_category()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('cat'), 'category'));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_category');
         $translations = $this->get_element_translations($trid, 'tax_category', $skip_empty);
     } elseif (is_tag()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array(get_query_var('tag_id'), 'post_tag'));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         $trid = $sitepress->get_element_trid($term_taxonomy_id, 'tax_post_tag');
         $translations = $this->get_element_translations($trid, 'tax_post_tag', $skip_empty);
     } elseif (is_tax()) {
         $skip_empty = false;
         $term_taxonomy_id_prepared = $wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy=%s", array($wp_query->get_queried_object_id(), get_query_var('taxonomy')));
         $term_taxonomy_id = $wpdb->get_var($term_taxonomy_id_prepared);
         if ($this->is_translated_taxonomy(get_query_var('taxonomy'))) {
             $trid = $this->get_element_trid($term_taxonomy_id, 'tax_' . get_query_var('taxonomy'));
             $translations = $this->get_element_translations($trid, 'tax_' . get_query_var('taxonomy'), $skip_empty);
         } else {
             $translations[$this->get_current_language()] = (object) array('translation_id' => 0, 'language_code' => $this->get_default_language(), 'original' => 1, 'name' => get_query_var('taxonomy'), 'term_id' => $wp_query->get_queried_object_id());
         }
     } elseif (is_archive()) {
         $translations = array();
     } elseif (is_attachment()) {
         // Exception for attachments. Not translated.
         $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_attachment');
         $translations = $this->get_element_translations($trid, 'post_attachment');
     } elseif (is_page() || 'page' == get_option('show_on_front') && (isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_on_front') || isset($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts'))) {
         $trid = $sitepress->get_element_trid($wp_query->get_queried_object_id(), 'post_page');
         $translations = $this->get_element_translations($trid, 'post_page');
     } elseif (is_singular() && !empty($wp_query->posts)) {
         $trid = $sitepress->get_element_trid($this->wp_query->post->ID, 'post_' . $wp_query->posts[0]->post_type);
         $translations = $this->get_element_translations($trid, 'post_' . $wp_query->posts[0]->post_type);
     } else {
         $wp_query->is_singular = false;
         $wp_query->is_archive = false;
         $wp_query->is_category = false;
         $wp_query->is_404 = true;
     }
     // 2. determine url
     foreach ($w_active_languages as $k => $lang) {
         $skip_lang = false;
         if (is_singular() || !empty($this->wp_query->queried_object_id) && $this->wp_query->queried_object_id == get_option('page_for_posts')) {
             $this_lang_tmp = $this->this_lang;
             $this->this_lang = $lang['code'];
             $lang_page_on_front = get_option('page_on_front');
             $lang_page_for_posts = get_option('page_for_posts');
             if ($lang_page_on_front && $lang['code'] != $default_language) {
                 $lang_page_on_front = icl_object_id($lang_page_on_front, 'page', false, $lang['code']);
             }
             if ($lang_page_for_posts && $lang['code'] != $default_language) {
                 $lang_page_for_posts = icl_object_id($lang_page_for_posts, 'page', false, $lang['code']);
             }
             if ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id == $lang_page_on_front) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
             } elseif ('page' == get_option('show_on_front') && !empty($translations[$lang['code']]) && $translations[$lang['code']]->element_id && $translations[$lang['code']]->element_id == $lang_page_for_posts) {
                 if ($lang_page_for_posts) {
                     $lang['translated_url'] = get_permalink($lang_page_for_posts);
                 } else {
                     $lang['translated_url'] = $this->language_url($lang['code']);
                 }
             } else {
                 if (!empty($translations[$lang['code']]) && isset($translations[$lang['code']]->post_title)) {
                     $lang['translated_url'] = get_permalink($translations[$lang['code']]->element_id);
                     $lang['missing'] = 0;
                 } else {
                     if ($icl_lso_link_empty) {
                         if (!empty($template_args['link_empty_to'])) {
                             $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                         } else {
                             $lang['translated_url'] = $this->language_url($lang['code']);
                         }
                     } else {
                         $skip_lang = true;
                     }
                     $lang['missing'] = 1;
                 }
             }
             $this->this_lang = $this_lang_tmp;
         } elseif (is_category()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_category_link($translations[$lang['code']]->term_id);
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_tax()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_term_link((int) $translations[$lang['code']]->term_id, get_query_var('taxonomy'));
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_tag()) {
             if (isset($translations[$lang['code']])) {
                 global $icl_adjust_id_url_filter_off;
                 // force  the category_link_adjust_id to not modify this
                 $icl_adjust_id_url_filter_off = true;
                 $lang['translated_url'] = get_tag_link($translations[$lang['code']]->term_id);
                 $icl_adjust_id_url_filter_off = false;
                 // restore default bahavior
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_author()) {
             global $authordata, $wp_query;
             if (empty($authordata)) {
                 $authordata = get_userdata(get_query_var('author'));
             }
             $post_type = get_query_var('post_type') ? get_query_var('post_type') : 'post';
             if ($wpdb->get_var("SELECT COUNT(p.ID) FROM {$wpdb->posts} p\r\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_translations t ON p.ID=t.element_id AND t.element_type = 'post_{$post_type}'\r\n\t\t\t\t\t\tWHERE p.post_author='{$authordata->ID}' AND post_type='{$post_type}' AND post_status='publish' AND language_code='{$lang['code']}'")) {
                 remove_filter('home_url', array($this, 'home_url'), 1, 4);
                 remove_filter('author_link', array($this, 'author_link'));
                 $author_url = get_author_posts_url($authordata->ID);
                 add_filter('home_url', array($this, 'home_url'), 1, 4);
                 add_filter('author_link', array($this, 'author_link'));
                 $lang['translated_url'] = $this->convert_url($author_url, $lang['code']);
                 $lang['missing'] = 0;
             } else {
                 if ($icl_lso_link_empty) {
                     if (!empty($template_args['link_empty_to'])) {
                         $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                     } else {
                         $lang['translated_url'] = $this->language_url($lang['code']);
                     }
                 } else {
                     // dont skip the currrent language
                     if ($current_language != $lang['code']) {
                         $skip_lang = true;
                     }
                 }
                 $lang['missing'] = 1;
             }
         } elseif (is_archive() && !is_tag()) {
             global $icl_archive_url_filter_off;
             $icl_archive_url_filter_off = true;
             if ($this->wp_query->is_year) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                 }
                 $lang['translated_url'] = $this->archive_url(get_year_link($this->wp_query->query_vars['year']), $lang['code']);
             } elseif ($this->wp_query->is_month) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                     $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2);
                 } else {
                     if ($icl_lso_link_empty) {
                         if (!empty($template_args['link_empty_to'])) {
                             $lang['translated_url'] = str_replace('{%lang}', $lang['code'], $template_args['link_empty_to']);
                         } else {
                             $lang['translated_url'] = $this->language_url($lang['code']);
                         }
                     }
                     $lang['missing'] = 1;
                 }
                 $lang['translated_url'] = $this->archive_url(get_month_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum']), $lang['code']);
             } elseif ($this->wp_query->is_day) {
                 if (isset($this->wp_query->query_vars['m']) && !$this->wp_query->query_vars['year']) {
                     $this->wp_query->query_vars['year'] = substr($this->wp_query->query_vars['m'], 0, 4);
                     $this->wp_query->query_vars['monthnum'] = substr($this->wp_query->query_vars['m'], 4, 2);
                     $this->wp_query->query_vars['day'] = substr($this->wp_query->query_vars['m'], 6, 2);
                     gmdate('Y', current_time('timestamp'));
                     //force wp_timezone_override_offset to be called
                 }
                 $lang['translated_url'] = $this->archive_url(get_day_link($this->wp_query->query_vars['year'], $this->wp_query->query_vars['monthnum'], $this->wp_query->query_vars['day']), $lang['code']);
             } else {
                 if (isset($this->wp_query->query_vars['post_type'])) {
                     do_action('_icl_before_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']);
                     if ($this->is_translated_post_type($this->wp_query->query_vars['post_type']) && function_exists('get_post_type_archive_link')) {
                         remove_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10);
                         $lang['translated_url'] = $this->convert_url(get_post_type_archive_link($this->wp_query->query_vars['post_type']), $lang['code']);
                     } else {
                         if ($k != $this->get_default_language()) {
                             $skip_lang = true;
                             unset($w_active_languages[$k]);
                         }
                     }
                     do_action('_icl_after_archive_url', $this->wp_query->query_vars['post_type'], $lang['code']);
                 }
             }
             add_filter('post_type_archive_link', array($this, 'post_type_archive_link_filter'), 10, 2);
             $icl_archive_url_filter_off = false;
         } elseif (is_search()) {
             $url_glue = strpos($this->language_url($lang['code']), '?') === false ? '?' : '&';
             $lang['translated_url'] = $this->language_url($lang['code']) . $url_glue . 's=' . urlencode($wp_query->query['s']);
         } else {
             global $icl_language_switcher_preview;
             if ($icl_lso_link_empty || is_home() || is_404() || 'page' == get_option('show_on_front') && ($this->wp_query->queried_object_id == get_option('page_on_front') || $this->wp_query->queried_object_id == get_option('page_for_posts')) || $icl_language_switcher_preview || WPML_Root_Page::is_current_request_root()) {
                 $lang['translated_url'] = $this->language_url($lang['code']);
                 $skip_lang = false;
             } else {
                 $skip_lang = true;
                 unset($w_active_languages[$k]);
             }
         }
         if (!$skip_lang) {
             $w_active_languages[$k] = $lang;
         } else {
             unset($w_active_languages[$k]);
         }
     }
     // 3.
     foreach ($w_active_languages as $k => $v) {
         $lang_code = $w_active_languages[$k]['language_code'] = $w_active_languages[$k]['code'];
         unset($w_active_languages[$k]['code']);
         $native_name = $this->get_display_language_name($lang_code, $lang_code);
         if (!$native_name) {
             $native_name = $w_active_languages[$k]['english_name'];
         }
         $w_active_languages[$k]['native_name'] = $native_name;
         $translated_name = $this->get_display_language_name($lang_code, $current_language);
         if (!$translated_name) {
             $translated_name = $w_active_languages[$k]['english_name'];
         }
         $w_active_languages[$k]['translated_name'] = $translated_name;
         unset($w_active_languages[$k]['display_name']);
         unset($w_active_languages[$k]['english_name']);
         if (isset($w_active_languages[$k]['translated_url'])) {
             $w_active_languages[$k]['url'] = $w_active_languages[$k]['translated_url'];
             unset($w_active_languages[$k]['translated_url']);
         } else {
             $w_active_languages[$k]['url'] = $this->language_url($k);
         }
         $flag = $this->get_flag($lang_code);
         if ($flag->from_template) {
             $wp_upload_dir = wp_upload_dir();
             $flag_url = $wp_upload_dir['baseurl'] . '/flags/' . $flag->flag;
         } else {
             $flag_url = ICL_PLUGIN_URL . '/res/flags/' . $flag->flag;
         }
         $w_active_languages[$k]['country_flag_url'] = $flag_url;
         $w_active_languages[$k]['active'] = $current_language == $lang_code ? '1' : 0;
     }
     // 4. pass GET parameters
     $parameters_copied = apply_filters('icl_lang_sel_copy_parameters', array_map('trim', explode(',', $this->settings['icl_lang_sel_copy_parameters'])));
     if ($parameters_copied) {
         foreach ($_GET as $k => $v) {
             if (in_array($k, $parameters_copied)) {
                 $gets_passed[$k] = $v;
             }
         }
     }
     if (!empty($gets_passed)) {
         $gets_passed = http_build_query($gets_passed);
         foreach ($w_active_languages as $code => $al) {
             if (empty($al['missing'])) {
                 $glue = false !== strpos($w_active_languages[$code]['url'], '?') ? '&' : '?';
                 $w_active_languages[$code]['url'] .= $glue . $gets_passed;
             }
         }
     }
     // restore current $wp_query
     unset($wp_query);
     global $wp_query;
     // make it global again after unset
     $wp_query = clone $_wp_query_back;
     unset($_wp_query_back);
     $w_active_languages = apply_filters('icl_ls_languages', $w_active_languages);
     $w_active_languages = $this->sort_ls_languages($w_active_languages, $template_args);
     // Change the url, in case languages in subdomains are set.
     if ($this->settings['language_negotiation_type'] == 2) {
         foreach ($w_active_languages as $lang => $element) {
             $w_active_languages[$lang]['url'] = $this->convert_url($element['url'], $lang);
         }
     }
     wp_reset_query();
     wp_cache_set($cache_key, $w_active_languages, $cache_group);
     return $w_active_languages;
 }
Esempio n. 18
0
/**
 * Redirects incoming links to the proper URL based on the site url.
 *
 * Search engines consider www.somedomain.com and somedomain.com to be two
 * different URLs when they both go to the same location. This SEO enhancement
 * prevents penality for duplicate content by redirecting all incoming links to
 * one or the other.
 *
 * Prevents redirection for feeds, trackbacks, searches, comment popup, and
 * admin URLs. Does not redirect on IIS, page/post previews, and on form data.
 *
 * Will also attempt to find the correct link when a user enters a URL that does
 * not exist based on exact WordPress query. Will instead try to parse the URL
 * or query in an attempt to figure the correct page to go to.
 *
 * @since 2.3.0
 * @uses $wp_rewrite
 * @uses $is_IIS
 *
 * @param string $requested_url Optional. The URL that was requested, used to
 *		figure if redirect is needed.
 * @param bool $do_redirect Optional. Redirect to the new URL.
 * @return null|false|string Null, if redirect not needed. False, if redirect
 *		not needed or the string of the URL
 */
function redirect_canonical($requested_url = null, $do_redirect = true)
{
    global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
    if (is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST) || is_preview() || is_robots()) {
        return;
    }
    if (!$requested_url) {
        // build the URL in the address bar
        $requested_url = is_ssl() ? 'https://' : 'http://';
        $requested_url .= $_SERVER['HTTP_HOST'];
        $requested_url .= $_SERVER['REQUEST_URI'];
    }
    $original = @parse_url($requested_url);
    if (false === $original) {
        return;
    }
    // Some PHP setups turn requests for / into /index.php in REQUEST_URI
    // See: http://trac.wordpress.org/ticket/5017
    // See: http://trac.wordpress.org/ticket/7173
    // Disabled, for now:
    // $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);
    $redirect = $original;
    $redirect_url = false;
    // Notice fixing
    if (!isset($redirect['path'])) {
        $redirect['path'] = '';
    }
    if (!isset($redirect['query'])) {
        $redirect['query'] = '';
    }
    if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) {
        $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id));
        if (isset($vars[0]) && ($vars = $vars[0])) {
            if ('revision' == $vars->post_type && $vars->post_parent > 0) {
                $id = $vars->post_parent;
            }
            if ($redirect_url = get_permalink($id)) {
                $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
            }
        }
    }
    // These tests give us a WP-generated permalink
    if (is_404()) {
        // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
        $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id'));
        if ($id && ($redirect_post = get_post($id))) {
            $post_type_obj = get_post_type_object($redirect_post->post_type);
            if ($post_type_obj->public) {
                $redirect_url = get_permalink($redirect_post);
                $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
            }
        }
        if (!$redirect_url) {
            $redirect_url = redirect_guess_404_permalink();
        }
    } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {
        // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
        if (is_attachment() && !empty($_GET['attachment_id']) && !$redirect_url) {
            if ($redirect_url = get_attachment_link(get_query_var('attachment_id'))) {
                $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']);
            }
        } elseif (is_single() && !empty($_GET['p']) && !$redirect_url) {
            if ($redirect_url = get_permalink(get_query_var('p'))) {
                $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']);
            }
            if (get_query_var('page')) {
                $redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged');
                $redirect['query'] = remove_query_arg('page', $redirect['query']);
            }
        } elseif (is_single() && !empty($_GET['name']) && !$redirect_url) {
            if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) {
                $redirect['query'] = remove_query_arg('name', $redirect['query']);
            }
        } elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) {
            if ($redirect_url = get_permalink(get_query_var('page_id'))) {
                $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
            }
        } elseif (is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) {
            $redirect_url = home_url('/');
        } elseif (is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && !$redirect_url) {
            if ($redirect_url = get_permalink(get_option('page_for_posts'))) {
                $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
            }
        } elseif (!empty($_GET['m']) && (is_year() || is_month() || is_day())) {
            $m = get_query_var('m');
            switch (strlen($m)) {
                case 4:
                    // Yearly
                    $redirect_url = get_year_link($m);
                    break;
                case 6:
                    // Monthly
                    $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2));
                    break;
                case 8:
                    // Daily
                    $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
                    break;
            }
            if ($redirect_url) {
                $redirect['query'] = remove_query_arg('m', $redirect['query']);
            }
            // now moving on to non ?m=X year/month/day links
        } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day'])) {
            if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) {
                $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']);
            }
        } elseif (is_month() && get_query_var('year') && !empty($_GET['monthnum'])) {
            if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) {
                $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']);
            }
        } elseif (is_year() && !empty($_GET['year'])) {
            if ($redirect_url = get_year_link(get_query_var('year'))) {
                $redirect['query'] = remove_query_arg('year', $redirect['query']);
            }
        } elseif (is_author() && !empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) {
            $author = get_userdata(get_query_var('author'));
            if (false !== $author && ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename))) {
                $redirect['query'] = remove_query_arg('author', $redirect['query']);
            }
        } elseif (is_category() || is_tag() || is_tax()) {
            // Terms (Tags/categories)
            $term_count = 0;
            foreach (array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key) {
                $term_count += count($wp_query->query_vars[$key]);
            }
            $obj = $wp_query->get_queried_object();
            if ($term_count <= 1 && !empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && !is_wp_error($tax_url)) {
                if (is_category()) {
                    $redirect['query'] = remove_query_arg(array('category_name', 'category', 'cat'), $redirect['query']);
                } elseif (is_tag()) {
                    $redirect['query'] = remove_query_arg(array('tag', 'tag_id'), $redirect['query']);
                } elseif (is_tax()) {
                    // Custom taxonomies will have a custom query var, remove those too:
                    $tax = get_taxonomy($obj->taxonomy);
                    if (false !== $tax->query_var) {
                        $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']);
                    } else {
                        $redirect['query'] = remove_query_arg(array('term', 'taxonomy'), $redirect['query']);
                    }
                }
                $tax_url = parse_url($tax_url);
                if (!empty($tax_url['query'])) {
                    // Custom taxonomies may only be accessable via ?taxonomy=..&term=..
                    parse_str($tax_url['query'], $query_vars);
                    $redirect['query'] = add_query_arg($query_vars, $redirect['query']);
                } else {
                    // Taxonomy is accessable via a "pretty-URL"
                    $redirect['path'] = $tax_url['path'];
                }
            }
        } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false) {
            $category = get_term_by('slug', get_query_var('category_name'), 'category');
            $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
            if (!$category || is_wp_error($category) || !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms)) {
                $redirect_url = get_permalink($wp_query->get_queried_object_id());
            }
        }
        // paging and feeds
        if (get_query_var('paged') || is_feed() || get_query_var('cpage')) {
            if (!$redirect_url) {
                $redirect_url = $requested_url;
            }
            $paged_redirect = @parse_url($redirect_url);
            while (preg_match('#/page/?[0-9]+?(/+)?$#', $paged_redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path']) || preg_match('#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'])) {
                // Strip off paging and feed
                $paged_redirect['path'] = preg_replace('#/page/?[0-9]+?(/+)?$#', '/', $paged_redirect['path']);
                // strip off any existing paging
                $paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $paged_redirect['path']);
                // strip off feed endings
                $paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']);
                // strip off any existing comment paging
            }
            $addl_path = '';
            if (is_feed()) {
                $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : '';
                if (get_query_var('withcomments')) {
                    $addl_path .= 'comments/';
                }
                $addl_path .= user_trailingslashit('feed/' . (get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ? '' : get_query_var('feed')), 'feed');
                $redirect['query'] = remove_query_arg('feed', $redirect['query']);
            }
            if (get_query_var('paged') > 0) {
                $paged = get_query_var('paged');
                $redirect['query'] = remove_query_arg('paged', $redirect['query']);
                if (!is_feed()) {
                    if ($paged > 1 && !is_single()) {
                        $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit("page/{$paged}", 'paged');
                    } elseif (!is_single()) {
                        $addl_path = !empty($addl_path) ? trailingslashit($addl_path) : '';
                    }
                } elseif ($paged > 1) {
                    $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']);
                }
            }
            if (get_option('page_comments') && ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 || 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1)) {
                $addl_path = (!empty($addl_path) ? trailingslashit($addl_path) : '') . user_trailingslashit('comment-page-' . get_query_var('cpage'), 'commentpaged');
                $redirect['query'] = remove_query_arg('cpage', $redirect['query']);
            }
            $paged_redirect['path'] = user_trailingslashit(preg_replace('|/index.php/?$|', '/', $paged_redirect['path']));
            // strip off trailing /index.php/
            if (!empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false) {
                $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/';
            }
            if (!empty($addl_path)) {
                $paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path;
            }
            $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path'];
            $redirect['path'] = $paged_redirect['path'];
        }
    }
    // tack on any additional query vars
    $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']);
    if ($redirect_url && !empty($redirect['query'])) {
        if (strpos($redirect_url, '?') !== false) {
            $redirect_url .= '&';
        } else {
            $redirect_url .= '?';
        }
        $redirect_url .= $redirect['query'];
    }
    if ($redirect_url) {
        $redirect = @parse_url($redirect_url);
    }
    // www.example.com vs example.com
    $user_home = @parse_url(home_url());
    if (!empty($user_home['host'])) {
        $redirect['host'] = $user_home['host'];
    }
    if (empty($user_home['path'])) {
        $user_home['path'] = '/';
    }
    // Handle ports
    if (!empty($user_home['port'])) {
        $redirect['port'] = $user_home['port'];
    } else {
        unset($redirect['port']);
    }
    // trailing /index.php
    $redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']);
    // Remove trailing spaces from the path
    $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']);
    if (!empty($redirect['query'])) {
        // Remove trailing spaces from certain terminating query string args
        $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']);
        // Clean up empty query strings
        $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&');
        // Remove redundant leading ampersands
        $redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']);
    }
    // strip /index.php/ when we're not using PATHINFO permalinks
    if (!$wp_rewrite->using_index_permalinks()) {
        $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']);
    }
    // trailing slashes
    if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || is_front_page() && get_query_var('paged') > 1)) {
        $user_ts_type = '';
        if (get_query_var('paged') > 0) {
            $user_ts_type = 'paged';
        } else {
            foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) {
                $func = 'is_' . $type;
                if (call_user_func($func)) {
                    $user_ts_type = $type;
                    break;
                }
            }
        }
        $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type);
    } elseif (is_front_page()) {
        $redirect['path'] = trailingslashit($redirect['path']);
    }
    // Strip multiple slashes out of the URL
    if (strpos($redirect['path'], '//') > -1) {
        $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']);
    }
    // Always trailing slash the Front Page URL
    if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) {
        $redirect['path'] = trailingslashit($redirect['path']);
    }
    // Ignore differences in host capitalization, as this can lead to infinite redirects
    // Only redirect no-www <=> yes-www
    if (strtolower($original['host']) == strtolower($redirect['host']) || strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host'])) {
        $redirect['host'] = $original['host'];
    }
    $compare_original = array($original['host'], $original['path']);
    if (!empty($original['port'])) {
        $compare_original[] = $original['port'];
    }
    if (!empty($original['query'])) {
        $compare_original[] = $original['query'];
    }
    $compare_redirect = array($redirect['host'], $redirect['path']);
    if (!empty($redirect['port'])) {
        $compare_redirect[] = $redirect['port'];
    }
    if (!empty($redirect['query'])) {
        $compare_redirect[] = $redirect['query'];
    }
    if ($compare_original !== $compare_redirect) {
        $redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
        if (!empty($redirect['port'])) {
            $redirect_url .= ':' . $redirect['port'];
        }
        $redirect_url .= $redirect['path'];
        if (!empty($redirect['query'])) {
            $redirect_url .= '?' . $redirect['query'];
        }
    }
    if (!$redirect_url || $redirect_url == $requested_url) {
        return false;
    }
    // Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE
    $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);
    if (!$redirect_url || $redirect_url == $requested_url) {
        // yes, again -- in case the filter aborted the request
        return false;
    }
    if ($do_redirect) {
        // protect against chained redirects
        if (!redirect_canonical($redirect_url, false)) {
            wp_redirect($redirect_url, 301);
            exit;
        } else {
            // Debug
            // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
            return false;
        }
    } else {
        return $redirect_url;
    }
}
Esempio n. 19
0
function print_blog_medium($item_class, $item_size, $num_excerpt, $full_content)
{
    global $gdl_admin_translator, $more, $gdl_date_format;
    if ($full_content == 'Yes') {
        $more = 0;
    }
    if ($gdl_admin_translator == 'enable') {
        $translator_continue_reading = get_option(THEME_SHORT_NAME . '_translator_continue_reading', 'Continue Reading');
    } else {
        $translator_continue_reading = __('Continue Reading ', 'gdl_front_end');
    }
    while (have_posts()) {
        the_post();
        echo '<div class="' . $item_class . '">';
        echo '<div class="blog-content-wrapper">';
        // blog thumbnail
        echo '<div class="blog-medium-media-wrapper">';
        print_blog_thumbnail(get_the_ID(), $item_size);
        echo '</div>';
        // blog-medium-media-wrapper
        echo '<div class="blog-context-wrapper">';
        // blog title
        echo '<h2 class="blog-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
        // blog information
        echo '<div class="blog-info-wrapper">';
        echo '<div class="blog-date"><i class="icon-calendar"></i>';
        echo '<a href="' . get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')) . '" >';
        echo get_the_time($gdl_date_format);
        echo '</a>';
        echo '</div>';
        echo '<div class="blog-author"><i class="icon-user"></i>';
        echo the_author_posts_link();
        echo '</div>';
        echo '<div class="blog-comment"><i class="icon-comments"></i>';
        comments_popup_link(__('0 Comment', 'gdl_front_end'), __('1 Comment', 'gdl_front_end'), __('% Comments', 'gdl_front_end'), '', __('Comment are off', 'gdl_front_end'));
        echo '</div>';
        $tags_opening = '<div class="blog-tag"><i class="icon-tags"></i>';
        $tags_ending = '</div>';
        the_tags($tags_opening, ', ', $tags_ending);
        echo '<div class="clear"></div>';
        echo '</div>';
        // blog information
        // blog content
        echo '<div class="blog-content">';
        if ($full_content == "No") {
            if (get_post_type() == 'package') {
                echo do_shortcode(get_the_excerpt());
            } else {
                echo gdl_get_excerpt($num_excerpt, '... ');
            }
            echo '<div class="clear"></div>';
            echo '<a class="blog-continue-reading" href="' . get_permalink() . '"> ' . $translator_continue_reading . '</a>';
        } else {
            the_content($translator_continue_reading);
        }
        echo '</div>';
        echo '</div>';
        // blog-context-wrapper
        echo '</div>';
        // blog-content-wrapper
        echo '</div>';
        // blog-item
    }
}
Esempio n. 20
0
 /**
  * Flushes post cache
  *
  * @param integer $post_id
  * @return boolean
  */
 function flush_post($post_id = null)
 {
     if (!$post_id) {
         $post_id = $this->_detect_post_id();
     }
     if ($post_id) {
         $uris = array();
         $domain_url = w3_get_domain_url();
         $feeds = $this->_config->get_array('pgcache.purge.feed.types');
         if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('pgcache.purge.feed.terms')) {
             $taxonomies = get_post_taxonomies($post_id);
             $terms = nxt_get_post_terms($post_id, $taxonomies);
         }
         switch (true) {
             case $this->_config->get_boolean('pgcache.purge.author'):
             case $this->_config->get_boolean('pgcache.purge.archive.daily'):
             case $this->_config->get_boolean('pgcache.purge.archive.monthly'):
             case $this->_config->get_boolean('pgcache.purge.archive.yearly'):
             case $this->_config->get_boolean('pgcache.purge.feed.author'):
                 $post = get_post($post_id);
         }
         /**
          * Home URL
          */
         if ($this->_config->get_boolean('pgcache.purge.home')) {
             $home_path = w3_get_home_path();
             $site_path = w3_get_site_path();
             $uris[] = $home_path;
             if ($site_path != $home_path) {
                 $uris[] = $site_path;
             }
         }
         /**
          * Post URL
          */
         if ($this->_config->get_boolean('pgcache.purge.post')) {
             $post_link = post_permalink($post_id);
             $post_uri = str_replace($domain_url, '', $post_link);
             $uris[] = $post_uri;
         }
         /**
          * Post comments URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) {
             $comments_number = get_comments_number($post_id);
             $comments_per_page = get_option('comments_per_page');
             $comments_pages_number = @ceil($comments_number / $comments_per_page);
             for ($pagenum = 1; $pagenum <= $comments_pages_number; $pagenum++) {
                 $comments_pagenum_link = $this->_get_comments_pagenum_link($post_id, $pagenum);
                 $comments_pagenum_uri = str_replace($domain_url, '', $comments_pagenum_link);
                 $uris[] = $comments_pagenum_uri;
             }
         }
         /**
          * Post author URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.author') && $post) {
             $posts_number = count_user_posts($post->post_author);
             $posts_per_page = get_option('posts_per_page');
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $author_link = get_author_link(false, $post->post_author);
             $author_uri = str_replace($domain_url, '', $author_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $author_pagenum_link = $this->_get_pagenum_link($author_uri, $pagenum);
                 $author_pagenum_uri = str_replace($domain_url, '', $author_pagenum_link);
                 $uris[] = $author_pagenum_uri;
             }
         }
         /**
          * Post terms URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.terms')) {
             $posts_per_page = get_option('posts_per_page');
             foreach ($terms as $term) {
                 $term_link = get_term_link($term, $term->taxonomy);
                 $term_uri = str_replace($domain_url, '', $term_link);
                 $posts_pages_number = @ceil($term->count / $posts_per_page);
                 for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                     $term_pagenum_link = $this->_get_pagenum_link($term_uri, $pagenum);
                     $term_pagenum_uri = str_replace($domain_url, '', $term_pagenum_link);
                     $uris[] = $term_pagenum_uri;
                 }
             }
         }
         /**
          * Daily archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $post_month = gmdate('m', $post_date);
             $post_day = gmdate('d', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year, $post_month, $post_day);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $day_link = get_day_link($post_year, $post_month, $post_day);
             $day_uri = str_replace($domain_url, '', $day_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $day_pagenum_link = $this->_get_pagenum_link($day_uri, $pagenum);
                 $day_pagenum_uri = str_replace($domain_url, '', $day_pagenum_link);
                 $uris[] = $day_pagenum_uri;
             }
         }
         /**
          * Monthly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $post_month = gmdate('m', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year, $post_month);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $month_link = get_month_link($post_year, $post_month);
             $month_uri = str_replace($domain_url, '', $month_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $month_pagenum_link = $this->_get_pagenum_link($month_uri, $pagenum);
                 $month_pagenum_uri = str_replace($domain_url, '', $month_pagenum_link);
                 $uris[] = $month_pagenum_uri;
             }
         }
         /**
          * Yearly archive URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) {
             $post_date = strtotime($post->post_date);
             $post_year = gmdate('Y', $post_date);
             $posts_per_page = get_option('posts_per_page');
             $posts_number = $this->_get_archive_posts_count($post_year);
             $posts_pages_number = @ceil($posts_number / $posts_per_page);
             $year_link = get_year_link($post_year);
             $year_uri = str_replace($domain_url, '', $year_link);
             for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) {
                 $year_pagenum_link = $this->_get_pagenum_link($year_uri, $pagenum);
                 $year_pagenum_uri = str_replace($domain_url, '', $year_pagenum_link);
                 $uris[] = $year_pagenum_uri;
             }
         }
         /**
          * Feed URLs
          */
         if ($this->_config->get_boolean('pgcache.purge.feed.blog')) {
             foreach ($feeds as $feed) {
                 $feed_link = get_feed_link($feed);
                 $feed_uri = str_replace($domain_url, '', $feed_link);
                 $uris[] = $feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.comments')) {
             foreach ($feeds as $feed) {
                 $post_comments_feed_link = get_post_comments_feed_link($post_id, $feed);
                 $post_comments_feed_uri = str_replace($domain_url, '', $post_comments_feed_link);
                 $uris[] = $post_comments_feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) {
             foreach ($feeds as $feed) {
                 $author_feed_link = get_author_feed_link($post->post_author, $feed);
                 $author_feed_uri = str_replace($domain_url, '', $author_feed_link);
                 $uris[] = $author_feed_uri;
             }
         }
         if ($this->_config->get_boolean('pgcache.purge.feed.terms')) {
             foreach ($terms as $term) {
                 foreach ($feeds as $feed) {
                     $term_feed_link = get_term_feed_link($term->term_id, $term->taxonomy, $feed);
                     $term_feed_uri = str_replace($domain_url, '', $term_feed_link);
                     $uris[] = $term_feed_uri;
                 }
             }
         }
         /**
          * Flush cache
          */
         if (count($uris)) {
             $cache =& $this->_get_cache();
             $mobile_groups = $this->_get_mobile_groups();
             $referrer_groups = $this->_get_referrer_groups();
             $encryptions = $this->_get_encryptions();
             $compressions = $this->_get_compressions();
             foreach ($uris as $uri) {
                 foreach ($mobile_groups as $mobile_group) {
                     foreach ($referrer_groups as $referrer_group) {
                         foreach ($encryptions as $encryption) {
                             foreach ($compressions as $compression) {
                                 $page_key = $this->_get_page_key($uri, $mobile_group, $referrer_group, $encryption, $compression);
                                 $cache->delete($page_key);
                             }
                         }
                     }
                 }
             }
             /**
              * Purge varnish servers
              */
             if ($this->_config->get_boolean('varnish.enabled')) {
                 $varnish =& w3_instance('W3_Varnish');
                 foreach ($uris as $uri) {
                     $varnish->purge($uri);
                 }
             }
         }
         return true;
     }
     return false;
 }
 /**
  * A Breadcrumb Trail Filling Function
  * 
  * This functions fills a breadcrumb for a date archive.
  *
  */
 protected function do_archive_by_date()
 {
     global $wp_query;
     //First deal with the day breadcrumb
     if (is_day() || is_single()) {
         //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
         $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('d'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-day')));
         //If this is a day archive, add current-item type
         if (is_day()) {
             $breadcrumb->add_type('current-item');
         }
         //If we're paged, let's link to the first page
         if ($this->opt['bcurrent_item_linked'] || is_paged() && $this->opt['bpaged_display'] || is_single()) {
             //We're linking, so set the linked template
             $breadcrumb->set_template($this->opt['Hdate_template']);
             //Deal with the anchor
             $breadcrumb->set_url(get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')));
         }
     }
     //Now deal with the month breadcrumb
     if (is_month() || is_day() || is_single()) {
         //Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
         $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('F'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-month')));
         //If this is a month archive, add current-item type
         if (is_month()) {
             $breadcrumb->add_type('current-item');
         }
         //If we're paged, or not in the archive by month let's link to the first archive by month page
         if ($this->opt['bcurrent_item_linked'] || is_day() || is_single() || is_month() && is_paged() && $this->opt['bpaged_display']) {
             //We're linking, so set the linked template
             $breadcrumb->set_template($this->opt['Hdate_template']);
             //Deal with the anchor
             $breadcrumb->set_url(get_month_link(get_the_time('Y'), get_the_time('m')));
         }
     }
     //Place the year breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
     $breadcrumb = $this->add(new bcn_breadcrumb(get_the_time('Y'), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-year')));
     //If this is a year archive, add current-item type
     if (is_year()) {
         $breadcrumb->add_type('current-item');
     }
     //If we're paged, or not in the archive by year let's link to the first archive by year page
     if ($this->opt['bcurrent_item_linked'] || is_day() || is_month() || is_single() || is_paged() && $this->opt['bpaged_display']) {
         //We're linking, so set the linked template
         $breadcrumb->set_template($this->opt['Hdate_template']);
         //Deal with the anchor
         $breadcrumb->set_url(get_year_link(get_the_time('Y')));
     }
 }
Esempio n. 22
0
 /**
  * Gets the crumbs for a date-based archive.
  *
  * @access private
  * @static
  * @param array $options
  * @return array
  */
 private static function get_date_archive_crumbs(array $options)
 {
     $crumbs = array();
     $date = new DateTime(get_the_date('c'));
     $last_show = $options['last_show'];
     if (is_year() && !$last_show) {
         return $crumbs;
     }
     $crumbs[] = new HAG_Crumb($options, $date->format('Y'), get_year_link($date->format('Y')), false, is_year());
     if (is_year() || is_month() && !$last_show) {
         return $crumbs;
     }
     $crumbs[] = new HAG_Crumb($options, $date->format('F'), get_month_link($date->format('Y'), $date->format('n')), false, is_month());
     if (is_month() || is_day() && !$last_show) {
         return $crumbs;
     }
     $crumbs[] = new HAG_Crumb($options, $date->format('jS'), get_day_link($date->format('Y'), $date->format('n'), $date->format('j')), false, is_day());
     return $crumbs;
 }
 /**
  * Returns a list of special pages that can be configured by this rule.
  *
  * @since  1.0.0
  *
  * @return array List of special pages.
  */
 protected function get_special_pages()
 {
     if (!is_array($this->_content)) {
         $this->_content = array();
         $front_type = get_option('show_on_front');
         $front_url = MS_Helper_Utility::home_url('/');
         if ('page' === $front_type) {
             $home_url = get_permalink(get_option('page_for_posts'));
         } else {
             $home_url = $front_url;
         }
         $arch_year = get_year_link('');
         $arch_month = get_month_link('', '');
         $arch_day = get_day_link('', '', '');
         $arch_hour = esc_url_raw(add_query_arg('hour', '15', $arch_day));
         // Archive pages
         $this->_content['archive'] = (object) array('label' => __('Any Archive page', 'membership2'), 'url' => '');
         $this->_content['author'] = (object) array('label' => __('Author Archives', 'membership2'), 'url' => '');
         $this->_content['date'] = (object) array('label' => __('Any Date or Time Archive', 'membership2'), 'url' => '');
         $this->_content['year'] = (object) array('label' => __('Archive: Year', 'membership2'), 'url' => $arch_year);
         $this->_content['month'] = (object) array('label' => __('Archive: Month', 'membership2'), 'url' => $arch_month);
         $this->_content['day'] = (object) array('label' => __('Archive: Day', 'membership2'), 'url' => $arch_day);
         $this->_content['time'] = (object) array('label' => __('Archive: Time', 'membership2'), 'url' => $arch_hour);
         // Singular pages
         $this->_content['front'] = (object) array('label' => __('Front Page', 'membership2'), 'url' => $front_url);
         $this->_content['home'] = (object) array('label' => __('Blog Index', 'membership2'), 'url' => $home_url);
         $this->_content['notfound'] = (object) array('label' => __('404 Not Found', 'membership2'), 'url' => '');
         $this->_content['search'] = (object) array('label' => __('Search Results', 'membership2'), 'url' => '');
         $this->_content['single'] = (object) array('label' => __('Any single page or post', 'membership2'), 'url' => '');
         $this->_content['attachment'] = (object) array('label' => __('Any attachment page', 'membership2'), 'url' => '');
     }
     return $this->_content;
 }
/**
 * Redirects incoming links to the proper URL based on the site url.
 *
 * Search engines consider www.somedomain.com and somedomain.com to be two
 * different URLs when they both go to the same location. This SEO enhancement
 * prevents penality for duplicate content by redirecting all incoming links to
 * one or the other.
 *
 * Prevents redirection for feeds, trackbacks, searches, comment popup, and
 * admin URLs. Does not redirect on IIS, page/post previews, and on form data.
 *
 * Will also attempt to find the correct link when a user enters a URL that does
 * not exist based on exact WordPress query. Will instead try to parse the URL
 * or query in an attempt to figure the correct page to go to.
 *
 * @since 2.3.0
 * @uses $wp_rewrite
 * @uses $is_IIS
 *
 * @param string $requested_url Optional. The URL that was requested, used to
 *		figure if redirect is needed.
 * @param bool $do_redirect Optional. Redirect to the new URL.
 * @return null|false|string Null, if redirect not needed. False, if redirect
 *		not needed or the string of the URL
 */
function redirect_canonical($requested_url=null, $do_redirect=true) {
	global $wp_rewrite, $is_IIS, $wp_query, $wpdb;

	if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() )
		return;

	if ( !$requested_url ) {
		// build the URL in the address bar
		$requested_url  = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
		$requested_url .= $_SERVER['HTTP_HOST'];
		$requested_url .= $_SERVER['REQUEST_URI'];
	}

	$original = @parse_url($requested_url);
	if ( false === $original )
		return;

	// Some PHP setups turn requests for / into /index.php in REQUEST_URI
	// See: http://trac.wordpress.org/ticket/5017
	// See: http://trac.wordpress.org/ticket/7173
	// Disabled, for now:
	// $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);

	$redirect = $original;
	$redirect_url = false;

	// Notice fixing
	if ( !isset($redirect['path']) )  $redirect['path'] = '';
	if ( !isset($redirect['query']) ) $redirect['query'] = '';

	if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) {

		$vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) );

		if ( isset($vars[0]) && $vars = $vars[0] ) {
			if ( 'revision' == $vars->post_type && $vars->post_parent > 0 )
				$id = $vars->post_parent;

			if ( $redirect_url = get_permalink($id) )
				$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']);
		}
	}

	// These tests give us a WP-generated permalink
	if ( is_404() ) {
		$redirect_url = redirect_guess_404_permalink();
	} elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
		// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
		if ( is_single() && !empty($_GET['p']) && ! $redirect_url ) {
			if ( $redirect_url = get_permalink(get_query_var('p')) )
				$redirect['query'] = remove_query_arg('p', $redirect['query']);
			if ( get_query_var( 'page' ) ) {
				$redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
				$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
			}
		} elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) {
			if ( $redirect_url = get_permalink(get_query_var('page_id')) )
				$redirect['query'] = remove_query_arg('page_id', $redirect['query']);
		} elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) {
			$m = get_query_var('m');
			switch ( strlen($m) ) {
				case 4: // Yearly
					$redirect_url = get_year_link($m);
					break;
				case 6: // Monthly
					$redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) );
					break;
				case 8: // Daily
					$redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
					break;
			}
			if ( $redirect_url )
				$redirect['query'] = remove_query_arg('m', $redirect['query']);
		// now moving on to non ?m=X year/month/day links
		} elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) {
			if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) )
				$redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']);
		} elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) {
			if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) )
				$redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']);
		} elseif ( is_year() && !empty($_GET['year']) ) {
			if ( $redirect_url = get_year_link(get_query_var('year')) )
				$redirect['query'] = remove_query_arg('year', $redirect['query']);
		} elseif ( is_category() && !empty($_GET['cat']) ) {
			if ( $redirect_url = get_category_link(get_query_var('cat')) )
				$redirect['query'] = remove_query_arg('cat', $redirect['query']);
		} elseif ( is_author() && !empty($_GET['author']) ) {
			$author = get_userdata(get_query_var('author'));
			if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) )
				$redirect['query'] = remove_query_arg('author', $redirect['author']);
		}

	// paging and feeds
		if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) {
			if ( !$redirect_url )
				$redirect_url = $requested_url;
			$paged_redirect = @parse_url($redirect_url);
			while ( preg_match( '#/page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $paged_redirect['path'] ) ) {
				// Strip off paging and feed
				$paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging
				$paged_redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+)?$#', '/', $paged_redirect['path']); // strip off feed endings
				$paged_redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging
			}

			$addl_path = '';
			if ( is_feed() ) {
				$addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : '';
				if ( get_query_var( 'withcomments' ) )
					$addl_path .= 'comments/';
				$addl_path .= user_trailingslashit( 'feed/' . ( ( 'rss2' ==  get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' );
				$redirect['query'] = remove_query_arg( 'feed', $redirect['query'] );
			}

			if ( get_query_var('paged') > 0 ) {
				$paged = get_query_var('paged');
				$redirect['query'] = remove_query_arg( 'paged', $redirect['query'] );
				if ( !is_feed() ) {
					if ( $paged > 1 && !is_single() ) {
						$addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("page/$paged", 'paged');
					} elseif ( !is_single() ) {
						$addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit($paged_redirect['path'], 'paged');
					}
				} elseif ( $paged > 1 ) {
					$redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] );
				}
			}

			if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) {
				$addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' );
				$redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
			}

			$paged_redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $paged_redirect['path']) ); // strip off trailing /index.php/
			if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false )
				$paged_redirect['path'] = trailingslashit($paged_redirect['path']) . 'index.php/';
			if ( !empty( $addl_path ) )
				$paged_redirect['path'] = trailingslashit($paged_redirect['path']) . $addl_path;
			$redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path'];
			$redirect['path'] = $paged_redirect['path'];
		}
	}

	// tack on any additional query vars
	$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
	if ( $redirect_url && !empty($redirect['query']) ) {
		if ( strpos($redirect_url, '?') !== false )
			$redirect_url .= '&';
		else
			$redirect_url .= '?';
		$redirect_url .= $redirect['query'];
	}

	if ( $redirect_url )
		$redirect = @parse_url($redirect_url);

	// www.example.com vs example.com
	$user_home = @parse_url(get_option('home'));
	if ( !empty($user_home['host']) )
		$redirect['host'] = $user_home['host'];
	if ( empty($user_home['path']) )
		$user_home['path'] = '/';

	// Handle ports
	if ( !empty($user_home['port']) )
		$redirect['port'] = $user_home['port'];
	else
		unset($redirect['port']);

	// trailing /index.php
	$redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']);

	// Remove trailing spaces from the path
	$redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] );

	if ( !empty( $redirect['query'] ) ) {
		// Remove trailing spaces from certain terminating query string args
		$redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] );

		// Clean up empty query strings
		$redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&');

		// Remove redundant leading ampersands
		$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
	}

	// strip /index.php/ when we're not using PATHINFO permalinks
	if ( !$wp_rewrite->using_index_permalinks() )
		$redirect['path'] = str_replace('/index.php/', '/', $redirect['path']);

	// trailing slashes
	if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) {
		$user_ts_type = '';
		if ( get_query_var('paged') > 0 ) {
			$user_ts_type = 'paged';
		} else {
			foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) {
				$func = 'is_' . $type;
				if ( call_user_func($func) ) {
					$user_ts_type = $type;
					break;
				}
			}
		}
		$redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type);
	} elseif ( is_front_page() ) {
		$redirect['path'] = trailingslashit($redirect['path']);
	}

	// Always trailing slash the Front Page URL
	if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) )
		$redirect['path'] = trailingslashit($redirect['path']);

	// Ignore differences in host capitalization, as this can lead to infinite redirects
	// Only redirect no-www <=> yes-www
	if ( strtolower($original['host']) == strtolower($redirect['host']) ||
		( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) )
		$redirect['host'] = $original['host'];

	$compare_original = array($original['host'], $original['path']);

	if ( !empty( $original['port'] ) )
		$compare_original[] = $original['port'];

	if ( !empty( $original['query'] ) )
		$compare_original[] = $original['query'];

	$compare_redirect = array($redirect['host'], $redirect['path']);

	if ( !empty( $redirect['port'] ) )
		$compare_redirect[] = $redirect['port'];

	if ( !empty( $redirect['query'] ) )
		$compare_redirect[] = $redirect['query'];

	if ( $compare_original !== $compare_redirect ) {
		$redirect_url = $redirect['scheme'] . '://' . $redirect['host'];
		if ( !empty($redirect['port']) )
			$redirect_url .= ':' . $redirect['port'];
		$redirect_url .= $redirect['path'];
		if ( !empty($redirect['query']) )
			$redirect_url .= '?' . $redirect['query'];
	}

	if ( !$redirect_url || $redirect_url == $requested_url )
		return false;

	// Note that you can use the "redirect_canonical" filter to cancel a canonical redirect for whatever reason by returning FALSE
	$redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url);

	if ( !$redirect_url || $redirect_url == $requested_url ) // yes, again -- in case the filter aborted the request
		return false;

	if ( $do_redirect ) {
		// protect against chained redirects
		if ( !redirect_canonical($redirect_url, false) ) {
			wp_redirect($redirect_url, 301);
			exit();
		} else {
			// Debug
			// die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
			return false;
		}
	} else {
		return $redirect_url;
	}
}
Esempio n. 25
0
 /**
  * This function normally outputs the canonical but is also used in other places to retrieve
  * the canonical URL for the current page.
  *
  * @param bool $echo        Whether or not to output the canonical element.
  * @param bool $un_paged    Whether or not to return the canonical with or without pagination added to the URL.
  * @param bool $no_override Whether or not to return a manually overridden canonical
  *
  * @return string $canonical
  */
 public function canonical($echo = true, $un_paged = false, $no_override = false)
 {
     $canonical = false;
     $skip_pagination = false;
     // Set decent canonicals for homepage, singulars and taxonomy pages
     if (is_singular()) {
         $meta_canon = WPSEO_Meta::get_value('canonical');
         if ($no_override === false && $meta_canon !== '') {
             $canonical = $meta_canon;
             $skip_pagination = true;
         } else {
             $obj = get_queried_object();
             $canonical = get_permalink($obj->ID);
             // Fix paginated pages canonical, but only if the page is truly paginated.
             if (get_query_var('page') > 1) {
                 global $wp_rewrite;
                 $numpages = substr_count($obj->post_content, '<!--nextpage-->') + 1;
                 if ($numpages && get_query_var('page') <= $numpages) {
                     if (!$wp_rewrite->using_permalinks()) {
                         $canonical = add_query_arg('page', get_query_var('page'), $canonical);
                     } else {
                         $canonical = user_trailingslashit(trailingslashit($canonical) . get_query_var('page'));
                     }
                 }
             }
         }
         unset($meta_canon);
     } else {
         if (is_search()) {
             $canonical = get_search_link();
         } elseif (is_front_page()) {
             $canonical = home_url('/');
         } elseif ($this->is_posts_page()) {
             $canonical = get_permalink(get_option('page_for_posts'));
         } elseif (is_tax() || is_tag() || is_category()) {
             $term = get_queried_object();
             if ($no_override === false) {
                 $canonical = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical');
                 if (is_string($canonical) && $canonical !== '') {
                     $skip_pagination = true;
                 }
             }
             if (!is_string($canonical) || $canonical === '') {
                 $canonical = get_term_link($term, $term->taxonomy);
             }
         } elseif (is_post_type_archive()) {
             $post_type = get_query_var('post_type');
             if (is_array($post_type)) {
                 $post_type = reset($post_type);
             }
             $canonical = get_post_type_archive_link($post_type);
         } elseif (is_author()) {
             $canonical = get_author_posts_url(get_query_var('author'), get_query_var('author_name'));
         } elseif (is_archive()) {
             if (is_date()) {
                 if (is_day()) {
                     $canonical = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'));
                 } elseif (is_month()) {
                     $canonical = get_month_link(get_query_var('year'), get_query_var('monthnum'));
                 } elseif (is_year()) {
                     $canonical = get_year_link(get_query_var('year'));
                 }
             }
         }
     }
     if ($canonical && $un_paged) {
         return $canonical;
     }
     if ($canonical && !$skip_pagination && get_query_var('paged') > 1) {
         global $wp_rewrite;
         if (!$wp_rewrite->using_permalinks()) {
             $canonical = add_query_arg('paged', get_query_var('paged'), $canonical);
         } else {
             if (is_front_page()) {
                 $base = $wp_rewrite->using_index_permalinks() ? 'index.php/' : '/';
                 $canonical = home_url($base);
             }
             $canonical = user_trailingslashit(trailingslashit($canonical) . trailingslashit($wp_rewrite->pagination_base) . get_query_var('paged'));
         }
     }
     if ($canonical && 'default' !== $this->options['force_transport']) {
         $canonical = preg_replace('`^http[s]?`', $this->options['force_transport'], $canonical);
     }
     /**
      * Filter: 'wpseo_canonical' - Allow filtering of the canonical URL put out by WP SEO
      *
      * @api string $canonical The canonical URL
      */
     $canonical = apply_filters('wpseo_canonical', $canonical);
     if (is_string($canonical) && $canonical !== '') {
         if ($echo !== false) {
             echo '<link rel="canonical" href="' . esc_url($canonical, null, 'other') . '" />' . "\n";
         } else {
             return $canonical;
         }
     } else {
         return false;
     }
 }
Esempio n. 26
0
 /**
  * Turns %tag% from permalink structures into usable links for the breadcrumb trail.  This feels kind of
  * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post' 
  * post type.  In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
  * types.
  *
  * @since  0.6.0
  * @access public
  * @param  int    $post_id ID of the post whose parents we want.
  * @param  string $path    Path of a potential parent page.
  * @param  array  $args    Mixed arguments for the menu.
  * @return array
  */
 public function map_rewrite_tags($post_id, $path)
 {
     /* Get the post based on the post ID. */
     $post = get_post($post_id);
     /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */
     if (empty($post) || is_wp_error($post) || 'post' !== $post->post_type) {
         return $trail;
     }
     /* Trim '/' from both sides of the $path. */
     $path = trim($path, '/');
     /* Split the $path into an array of strings. */
     $matches = explode('/', $path);
     /* If matches are found for the path. */
     if (is_array($matches)) {
         /* Loop through each of the matches, adding each to the $trail array. */
         foreach ($matches as $match) {
             /* Trim any '/' from the $match. */
             $tag = trim($match, '/');
             /* If using the %year% tag, add a link to the yearly archive. */
             if ('%year%' == $tag) {
                 $this->items[] = '<a href="' . esc_url(get_year_link(get_the_time('Y', $post_id))) . '">' . sprintf($this->args['labels']['archive_year'], get_the_time(_x('Y', 'yearly archives date format', 'toivo-lite'))) . '</a>';
             } elseif ('%monthnum%' == $tag) {
                 $this->items[] = '<a href="' . esc_url(get_month_link(get_the_time('Y', $post_id), get_the_time('m', $post_id))) . '">' . sprintf($this->args['labels']['archive_month'], get_the_time(_x('F', 'monthly archives date format', 'toivo-lite'))) . '</a>';
             } elseif ('%day%' == $tag) {
                 $this->items[] = '<a href="' . esc_url(get_day_link(get_the_time('Y', $post_id), get_the_time('m', $post_id), get_the_time('d', $post_id))) . '">' . sprintf($this->args['labels']['archive_day'], get_the_time(_x('j', 'daily archives date format', 'toivo-lite'))) . '</a>';
             } elseif ('%author%' == $tag) {
                 $this->items[] = '<a href="' . esc_url(get_author_posts_url($post->post_author)) . '">' . get_the_author_meta('display_name', $post->post_author) . '</a>';
             } elseif ('%category%' == $tag) {
                 /* Force override terms in this post type. */
                 $this->args['post_taxonomy'][$post->post_type] = false;
                 /* Get the post categories. */
                 $terms = get_the_category($post_id);
                 /* Check that categories were returned. */
                 if ($terms) {
                     /* Sort the terms by ID and get the first category. */
                     usort($terms, '_usort_terms_by_ID');
                     $term = get_term($terms[0], 'category');
                     /* If the category has a parent, add the hierarchy to the trail. */
                     if (0 < $term->parent) {
                         $this->do_term_parents($term->parent, 'category');
                     }
                     /* Add the category archive link to the trail. */
                     $this->items[] = '<a href="' . esc_url(get_term_link($term, 'category')) . '">' . $term->name . '</a>';
                 }
             }
         }
     }
 }
Esempio n. 27
0
			<!--<div class="more-cate"><?php 
    echo $single_cate;
    ?>
</div>-->
			<div class="more-content">
				<h2><a href="<?php 
    the_permalink();
    ?>
"><?php 
    the_title();
    ?>
</a></h2>
				<span class="line">&nbsp;</span>
				<div class="meta">
					<a href="<?php 
    echo get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
    ?>
"><?php 
    the_time(get_option('date_format'));
    ?>
</a>
					<?php 
    echo get_mtc_rating_sys('span', ' &nbsp;&nbsp; ', '');
    ?>
					
				</div>
			</div>
			<?php 
    echo $carousel;
    ?>
		</li>
Esempio n. 28
0
 /**
  * Turns %tag% from permalink structures into usable links for the breadcrumb trail.  This feels kind of
  * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
  * post type.  In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
  * types.
  *
  * @since  0.6.0
  * @access protected
  * @param  int    $post_id ID of the post whose parents we want.
  * @param  string $path    Path of a potential parent page.
  * @param  array  $args    Mixed arguments for the menu.
  * @return array
  */
 protected function map_rewrite_tags($post_id, $path)
 {
     $post = get_post($post_id);
     // If the post doesn't have the `post` post type, bail.
     if ('post' !== $post->post_type) {
         return;
     }
     // Trim '/' from both sides of the $path.
     $path = trim($path, '/');
     // Split the $path into an array of strings.
     $matches = explode('/', $path);
     // If matches are found for the path.
     if (is_array($matches)) {
         // Loop through each of the matches, adding each to the $trail array.
         foreach ($matches as $match) {
             // Trim any '/' from the $match.
             $tag = trim($match, '/');
             // If using the %year% tag, add a link to the yearly archive.
             if ('%year%' == $tag) {
                 $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_year_link(get_the_time('Y', $post_id))), sprintf($this->labels['archive_year'], get_the_time(esc_html_x('Y', 'yearly archives date format', 'simple-life'))));
             } elseif ('%monthnum%' == $tag) {
                 $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_month_link(get_the_time('Y', $post_id), get_the_time('m', $post_id))), sprintf($this->labels['archive_month'], get_the_time(esc_html_x('F', 'monthly archives date format', 'simple-life'))));
             } elseif ('%day%' == $tag) {
                 $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_day_link(get_the_time('Y', $post_id), get_the_time('m', $post_id), get_the_time('d', $post_id))), sprintf($this->labels['archive_day'], get_the_time(esc_html_x('j', 'daily archives date format', 'simple-life'))));
             } elseif ('%author%' == $tag) {
                 $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_author_posts_url($post->post_author)), get_the_author_meta('display_name', $post->post_author));
             } elseif ('%category%' == $tag) {
                 // Force override terms in this post type.
                 $this->post_taxonomy[$post->post_type] = false;
                 // Add the post categories.
                 $this->add_post_terms($post_id, 'category');
             }
         }
     }
 }
Esempio n. 29
0
 echo '<div class="row gdl-page-row-wrapper">';
 echo '<div class="gdl-page-left mb0 ' . $sidebar_array['page_left_class'] . '">';
 echo '<div class="row">';
 echo '<div class="gdl-page-item mb0 pb20 gdl-blog-full ' . $sidebar_array['page_item_class'] . '">';
 if (have_posts()) {
     while (have_posts()) {
         the_post();
         // blog thumbnail
         print_single_blog_thumbnail(get_the_ID(), $item_size);
         echo '<div class="blog-content-wrapper">';
         // blog title
         echo '<h1 class="blog-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h1>';
         // blog information
         echo '<div class="blog-info-wrapper">';
         echo '<div class="blog-date"><i class="icon-calendar"></i>';
         echo '<a href="' . get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')) . '" >';
         echo get_the_time($gdl_date_format);
         echo '</a>';
         echo '</div>';
         echo '<div class="blog-comment"><i class="icon-comments"></i>';
         comments_popup_link(__('0 Comment', 'gdl_front_end'), __('1 Comment', 'gdl_front_end'), __('% Comments', 'gdl_front_end'), '', __('Comment are off', 'gdl_front_end'));
         echo '</div>';
         echo '<div class="blog-author"><i class="icon-user"></i>';
         echo the_author_posts_link();
         echo '</div>';
         $tags_opening = '<div class="blog-tag"><i class="icon-tags"></i>';
         $tags_ending = '</div>';
         the_tags($tags_opening, ', ', $tags_ending);
         echo '<div class="clear"></div>';
         echo '</div>';
         // blog information
Esempio n. 30
0
        ?>
" rel="bookmark" title="<?php 
        the_title_attribute();
        ?>
"><?php 
        the_title();
        ?>
</a></h1>
                                    <ul class="meta">
                                        <li><i class="fa fa-clock-o blogin-color"></i> <?php 
        $archive_year = get_the_time('Y');
        $archive_month = get_the_time('m');
        $archive_day = get_the_time('d');
        ?>
                                            <a href="<?php 
        echo get_day_link($archive_year, $archive_month, $archive_day);
        ?>
"><?php 
        echo get_the_time('m, d, Y');
        ?>
</a> </li>
                                        <li><i class="fa fa-user blogin-color"></i>&nbsp;<?php 
        the_author_posts_link();
        ?>
&nbsp;</li>
                                        <li><i class="fa fa-folder-open blogin-color"></i>&nbsp;<?php 
        the_category(', ');
        ?>
&nbsp;</li>
                                        <li class="comments"><i class="fa fa-comment blogin-color"></i> <?php 
        comments_popup_link(__('No Comments.', 'ariwoo'), __('Comment: 1', 'ariwoo'), __('Comments: %', 'ariwoo'));