コード例 #1
0
/**
 * Display or retrieve the current event start date.
 *
 * @since 1.3.0
 *
 * @param string $before Optional. Content to prepend to the title.
 * @param string $after Optional. Content to append to the title.
 * @param string $format Optional. See PHP date() for formatting options.
 * @param bool $echo Optional, default to true. Whether to display or return.
 * @return null|string Null on no title. String if $echo parameter is false.
 */
function am_the_startdate($format = 'Y-m-d H:i:s', $before = '', $after = '', $echo = true)
{
    $date = am_get_the_startdate($format);
    if (strlen($date) == 0) {
        return;
    }
    $date = $before . $date . $after;
    if ($echo) {
        echo $date;
    } else {
        return $date;
    }
}
コード例 #2
0
 /**
  * Parses a shortcode, returning the appropriate event information
  * Much of this code is 'borrowed' from WordPress' own shortcode handling stuff!
  */
 protected function process_shortcode($m)
 {
     if ('[' == $m[1] && ']' == $m[6]) {
         return substr($m[0], 1, -1);
     }
     //Extract any attributes contained in the shortcode
     extract(shortcode_atts(array('format' => '', 'limit' => '0', 'size' => 'post-thumbnail', 'link' => 'false', 'cond' => ''), shortcode_parse_atts($m[3])));
     //Sanitize the attributes
     $format = esc_attr($format);
     $cond = esc_attr($cond);
     $size = esc_attr($size);
     $limit = absint($limit);
     $link = 'true' === $link;
     // Do the appropriate stuff depending on which shortcode we're looking at.
     // See valid shortcode list (above) for explanation of each shortcode
     switch ($m[2]) {
         case 'event-title':
             $title = esc_html(trim(get_the_title()));
             //If a word limit has been set, trim the title to the required length
             if (0 != $limit) {
                 preg_match('/([\\S]+\\s*){0,' . $limit . '}/', $title, $title);
                 $title = trim($title[0]);
             }
             if ($link) {
                 return $m[1] . '<a href="' . get_permalink() . '">' . $title . '</a>' . $m[6];
             } else {
                 return $m[1] . $title . $m[6];
             }
         case 'thumbnail':
             $thumbnail = get_the_post_thumbnail(get_the_ID(), $size);
             return $m[1] . $thumbnail . $m[6];
         case 'content':
             $content = get_the_content();
             //If a word limit has been set, trim the title to the required length
             if (0 != $limit) {
                 preg_match('/([\\S]+\\s*){0,' . $limit . '}/', $content, $content);
                 $content = trim($content[0]);
             }
             return $m[1] . $content . $m[6];
         case 'permalink':
             return $m[1] . get_permalink() . $m[6];
         case 'excerpt':
             $excerpt = get_the_excerpt();
             if (0 != $limit) {
                 preg_match('/([\\S]+\\s*){0,' . $limit . '}/', $excerpt, $excerpt);
                 $excerpt = trim($excerpt[0]);
             }
             return $m[1] . get_the_excerpt() . $m[6];
         case 'event-category':
             $categoryArray = am_get_the_event_category();
             if (count($categoryArray) > 0) {
                 if ($link) {
                     return $m[1] . '<a href="' . get_term_link($categoryArray[0]) . '">' . $categoryArray[0]->name . '</a>' . $m[6];
                 } else {
                     return $m[1] . $categoryArray[0]->name . $m[6];
                 }
             } else {
                 return '-';
             }
         case 'event-venue':
             $venueArray = am_get_the_venue();
             if (count($venueArray) > 0) {
                 if ($link) {
                     return $m[1] . '<a href="' . get_term_link($venueArray[0]) . '">' . $venueArray[0]->name . '</a>' . $m[6];
                 } else {
                     return $m[1] . $venueArray[0]->name . $m[6];
                 }
             } else {
                 return '-';
             }
         case 'start-date':
             $startdate = am_get_the_startdate();
             $format = $format === '' ? "m/d/Y H:i" : $format;
             return $m[1] . date_i18n($format, strtotime($startdate)) . $m[6];
         case 'end-date':
             $enddate = am_get_the_enddate();
             $format = $format === '' ? "m/d/Y H:i" : $format;
             return $m[1] . date_i18n($format, strtotime($enddate)) . $m[6];
         case 'if':
             switch ($cond) {
                 case 'startdate-not-enddate':
                     $result = am_get_the_startdate() !== am_get_the_enddate() ? $m[1] . $m[5] . $m[6] : '';
                     return $this->parse_event($result);
                 case 'startday-not-endday':
                     $start_day = date('mdY', strtotime(am_get_the_startdate()));
                     $end_day = date('mdY', strtotime(am_get_the_enddate()));
                     $result = $start_day !== $end_day ? $m[1] . $m[5] . $m[6] : '';
                     return $this->parse_event($result);
                 case 'startdate-is-enddate':
                     $result = am_get_the_startdate() === am_get_the_enddate() ? $m[1] . $m[5] . $m[6] : '';
                     return $this->parse_event($result);
                 case 'startday-is-endday':
                     $start_day = date('mdY', strtotime(am_get_the_startdate()));
                     $end_day = date('mdY', strtotime(am_get_the_enddate()));
                     $result = $start_day === $end_day ? $m[1] . $m[5] . $m[6] : '';
                     return $this->parse_event($result);
                 default:
                     return $this->parse_event($m[1] . $m[5] . $m[6]);
             }
     }
 }