Plugin Directory

Changeset 3103735


Ignore:
Timestamp:
06/17/2024 07:51:01 PM (19 months ago)
Author:
christer_f
Message:

Bug fix (date for shwoing tickets)
Added dutch language
More debug around tickets

First version allowing custom page for showing the events (using parameters in the events_list shortcodes

Location:
hello-event/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • hello-event/trunk/hello_event.php

    r3103734 r3103735  
    3838 */
    3939
     40// STILL NEED TO FIX: Backlink to event if custom event page!!!
     41// IDEA: Set this in the settings rather that as a parameter to the short code for listing events.
     42
    4043namespace Tekomatik\HelloEvent;
    4144
     
    109112    add_shortcode('hello-id-of-event', array($this, 'id_of_event'));
    110113    add_shortcode('hello-link-to-event', array($this, 'link_to_event'));
     114    add_shortcode('hello-title', array($this, 'event_title'));
     115    add_shortcode('hello-thumbnail', array($this, 'event_thumbnail'));
    111116    add_shortcode('hello-start-date', array($this, 'event_start_date'));
    112117    add_shortcode('hello-start-time', array($this, 'event_start_time'));
     
    116121    add_shortcode('hello-end-date-and-time', array($this, 'event_end_date_and_time'));
    117122    add_shortcode('hello-location', array($this, 'event_location'));
     123    add_shortcode('hello-content', array($this, 'event_content'));
     124    add_shortcode('hello-excerpt', array($this, 'event_excerpt'));
     125 
    118126   
    119127    // Make sure we have the necessary product category for WooCommerce
     
    12921300  // ================== Shortcode handlers =========================================================
    12931301  //
    1294   public function link_to_ticket($args) {
     1302  public function link_to_ticket_OLD($args) {
    12951303    // If the current post is an event and there are slots for sale, then return a link
    12961304    // Process shortcode hello_event_link_to_ticket
     
    12981306    global $post;
    12991307    $html = '';
    1300     $html .= '<div style="border:1px solid red; color: orange; padding: 8px">DEBUG OUTPUT:<br/>';
    13011308    if ( $post->post_type == Hello_Event::EVENT_SLUG ) {
    1302       $html .= "Post type correct. ID: ".get_the_ID()."<br/>";
    13031309      $a = shortcode_atts( array(
    13041310             'text' => __("Tickets to participate are available in our shop", 'hello-event'),
    13051311         ), $args );
    1306       $html .= $this->test_get_link_to_product(get_the_ID(), true) . '</div>';
    13071312      list($link, $rc) = $this->get_link_to_product(get_the_ID(), true);
    13081313      if ($link) {
    13091314        $html .= '<a href="'. $link . '">' . $a['text'] . '</a>';
    13101315        $html = apply_filters('hello_event_display_link_to_ticket', $html, get_the_ID(), $link);
     1316        // Don't know why at some point we had a fourth parameter here
     1317        // $html = apply_filters('hello_event_display_link_to_ticket', $html, get_the_ID(), $link, 'shortcode');
     1318        return $html . '</div>';
     1319      }
     1320      else { return $html . $this->debug_msg(__("Tickets not fully configured", 'hello-event') . ". ".
     1321                     $this->ticket_config_error($rc)); }     
     1322    }
     1323    else { return $html . $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
     1324  }
     1325 
     1326  public function link_to_ticket($args) {
     1327    // If the current post is an event and there are slots for sale, then return a link
     1328    // Process shortcode hello_event_link_to_ticket
     1329    $args = shortcode_atts( array(
     1330           'id' => get_the_ID(),
     1331           'text' => __("Tickets to participate are available in our shop", 'hello-event'),    ), $args );
     1332    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
     1333    $id = $args['id'];
     1334    $html = '';
     1335    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     1336      list($link, $rc) = $this->get_link_to_product($args['id'], true);
     1337      if ($link) {
     1338        $html .= '<a href="'. $link . '">' . $args['text'] . '</a>';
     1339        $html = apply_filters('hello_event_display_link_to_ticket', $html, $args['id'], $link);
    13111340        // Don't know why at some point we had a fourth parameter here
    13121341        // $html = apply_filters('hello_event_display_link_to_ticket', $html, get_the_ID(), $link, 'shortcode');
     
    14011430    $args = shortcode_atts( array(
    14021431           'id' => get_the_ID(),
     1432           'format' => false,
    14031433    ), $args );
     1434    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14041435    $id = $args['id'];
    14051436    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
    1406       $html = $this->transform_iso_date(get_post_meta($id, 'start_date', true));
     1437      if ($args['format'] == 'iso')
     1438        $html = get_post_meta($id, 'start_date', true);
     1439      else
     1440        $html = $this->transform_iso_date(get_post_meta($id, 'start_date', true));
    14071441      return $html;
    14081442    }
    14091443    else { return $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
    14101444  }
     1445 
     1446  public function event_title($args) {
     1447    $args = shortcode_atts( array(
     1448           'id' => get_the_ID(),
     1449    ), $args );
     1450    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
     1451    $id = $args['id'];
     1452    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     1453      return get_the_title($id);
     1454    }
     1455    else { return $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
     1456  }
     1457 
     1458  public function event_thumbnail($args) {
     1459    $args = shortcode_atts( array(
     1460           'id' => get_the_ID(),
     1461    ), $args );
     1462    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
     1463    $id = $args['id'];
     1464    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     1465      return get_the_post_thumbnail($id);
     1466    }
     1467    else { return $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
     1468  }
     1469
     1470
     1471  public function event_content($args){
     1472    $args = shortcode_atts( array(
     1473           'id' => get_the_ID(),
     1474    ), $args );
     1475    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
     1476    $id = $args['id'];
     1477    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     1478      $html = get_post_field('post_content', $id);
     1479      return $html;
     1480    }
     1481    else { return $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
     1482  }
     1483 
     1484  public function event_excerpt($args){
     1485    $args = shortcode_atts( array(
     1486           'id' => get_the_ID(),
     1487    ), $args );
     1488    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
     1489    $id = $args['id'];
     1490    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     1491      $html = $this->real_or_computed_excerpt($id);
     1492      return $html;
     1493    }
     1494    else { return $this->debug_msg(__("Shortcode can only be used when displaying events", 'hello-event')); }
     1495  }
     1496   
    14111497 
    14121498  public function event_start_time($args){
     
    14141500           'id' => get_the_ID(),
    14151501    ), $args );
     1502    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14161503    $id = $args['id'];
    14171504    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     
    14341521           'id' => get_the_ID(),
    14351522    ), $args );
     1523    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14361524    $id = $args['id'];
    14371525    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     
    14521540           'id' => get_the_ID(),
    14531541    ), $args );
     1542    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14541543    $id = $args['id'];
    14551544    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     
    14701559    $args = shortcode_atts( array(
    14711560           'id' => get_the_ID(),
     1561           'format' => false,
    14721562    ), $args );
     1563    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14731564    $id = $args['id'];
    14741565    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
    1475       $html = $this->transform_iso_date(get_post_meta($id, 'end_date', true));
     1566      if ($args['format'] == 'iso')
     1567        $html = get_post_meta($id, 'end_date', true);
     1568      else
     1569        $html = $this->transform_iso_date(get_post_meta($id, 'end_date', true));
    14761570      return $html;
    14771571    }
     
    14831577           'id' => get_the_ID(),
    14841578    ), $args );
     1579    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14851580    $id = $args['id'];
    14861581    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     
    14951590           'id' => get_the_ID(),
    14961591    ), $args );
     1592    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    14971593    $id = $args['id'];
    14981594    if (get_post_type($id) == Hello_Event::EVENT_SLUG) {
     
    15071603           'id' => get_the_ID(),
    15081604    ), $args );
     1605    $args['id'] = isset($_GET['event_id']) ? $_GET['event_id'] : $args['id'];
    15091606    $id = $args['id'];
    15101607    $btn_txt = __('Add to Calendar', 'hello-event');
     
    16811778             get_option( 'hello_event')['hello_field_autolink_to_product']=="on" ) {
    16821779          list($link, $rc) = $this->get_link_to_product($post_id, true);
     1780          if ($rc > 0) {
     1781            $before .= $this->debug_msg(__("Tickets not fully configured", 'hello_event') . ". ".
     1782                                           $this->ticket_config_error($rc));
     1783          }
    16831784          if ($link) {
    16841785            if ( isset(get_option( 'hello_event')['hello_field_ticket_visibility']) &&
    16851786                  get_option( 'hello_event')['hello_field_ticket_visibility']=="on" &&
    1686                   $this->event_end_date([]) < date("Y-m-d")) {
     1787                  $this->event_end_date(['format' => 'iso']) < date("Y-m-d")) {
    16871788              // Don't show any link to the ticket for past event
    16881789            }
  • hello-event/trunk/includes/hello-event-list-events.php

    r2946985 r3103735  
    3131  }
    3232 
     33  // =========================== Helpers ================================
     34  function permalink_by_slug($slug) {
     35    $args = array(
     36        'post_type'       => 'page',
     37        'name'            => $slug,
     38        'posts_per_page'  => 1
     39    );
     40    $pages = get_posts($args);
     41    if ($pages)
     42      return get_permalink($pages[0]);
     43    else
     44      return false;
     45    // $query = new \WP_Query( $args );
     46    // if( $query->have_posts() ) {
     47    //       $query->the_post();
     48    //       $permalink = get_permalink( get_the_ID() );
     49    // }
     50    // wp_reset_postdata();
     51    // return $permalink;
     52  }
     53
     54 
     55  function link_to_event_page($permalink, $event_id, $custom_page_slug) {
     56    // If custom page is false the link returned = $permalink
     57    // Otherwise the link is to the link returned = custom page URL with event id as parameter
     58    if (!$custom_page_slug)
     59      return $permalink;
     60    $url = $this->permalink_by_slug($custom_page_slug);
     61    if ($url)
     62      return add_query_arg('event_id',$event_id, $url);
     63    else
     64      return $permalink;
     65  }
     66 
    3367  function handle_shortcode_event_list($args0) {
    3468    $args = shortcode_atts( array(
     
    3872           'width' => false, // Optionally Used in widget show
    3973           'link_to_book' => false, // Do we want to display a "Book Now" button?
    40            'language' => false, // Can be used in date presentations
     74           // 'language' => false, // Can be used in date presentations
    4175                     'thumbnail' => "", // can be 'square', 'round' or both (sepaated by space)
     76           'event_page' => false, // can be set to the slug of a custom page to show the events
    4277             
    4378       ), $args0 );
     
    187222          </div>
    188223        ";
    189        
     224
    190225        switch ($args['show']) {
    191226          case 'minimal' :
     
    193228            $html .= '  <div class="start-date">'.$start_date.'</div>';
    194229            $html .= '  <div class="event-title">';
    195             $html .= '     <a href="'.get_the_permalink().'" rel="bookmark" title="Permanent Link to '.get_the_title().'">';
     230            $html .= '     <a href="'.$this->link_to_event_page(get_the_permalink(), $id, $args['event_page']).'" rel="bookmark" title="Permanent Link to '.get_the_title().'">';
    196231            $html .=       get_the_title().'</a>';
    197232            $html .= '  </div>';
     
    210245          case 'gallery' : // xxx
    211246            $g_start_date = $start_date;
    212             if ($args['language'] == "french") {
    213               $g_start_date = new \DateTime($start_date);
    214               $g_start_date = $g_start_date->format("d/m Y");
    215             }
     247            // if (false && $args['language'] == "french") {
     248            //   $g_start_date = new \DateTime($start_date);
     249            //   $g_start_date = $g_start_date->format("d/m Y");
     250            // }
    216251            $g_dates = '<i class="far fa-calendar"></i> ' . $g_start_date .'<br/>';
    217252            $g_times = '<i class="far fa-clock"></i> ' . $start_time .'<br/>';
     
    232267            $g_title = "
    233268              <div class='title'>
    234                 <a href='".get_the_permalink()."'
     269                <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    235270                    rel='bookmark'
    236271                    title='Permalink to ".get_the_title()."'>".get_the_title()."
    237272                </a>
    238273              </div>";
     274             
     275             
     276             
    239277            $html .= "
    240278            <div class='hello-event style1 list gallery " . $event_type_class ."'>
     
    260298              <div class='description'>
    261299                <div class='title'>
    262                   <a href='".get_the_permalink()."'
     300                  <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    263301                      rel='bookmark'
    264302                      title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    286324                  </div>
    287325                  <div class='title'>
    288                     <a href='".get_the_permalink()."'
     326                    <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    289327                        rel='bookmark'
    290328                        title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    314352                <div class='intro'>
    315353                  <div class='title'>
    316                     <a href='".get_the_permalink()."'
     354                    <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    317355                        rel='bookmark'
    318356                        title='Permalink to ".get_the_title()."'>".get_the_title()."
    319357                    </a>
    320358                  </div>
     359                 
    321360                  <div class='thumbnail ".$args['thumbnail']."'>" . get_the_post_thumbnail($id, 'hello-event-widget-image') . "</div>
    322361                </div>
     
    342381                  </div>
    343382                  <div class='title'>
    344                     <a href='".get_the_permalink()."'
     383                    <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    345384                        rel='bookmark'
    346385                        title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    388427                  </div>
    389428                  <div class='title'>
    390                     <a href='".get_the_permalink()."'
     429                    <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    391430                        rel='bookmark'
    392431                        title='Permalink to ".get_the_title()."'>".get_the_title()."
  • hello-event/trunk/readme.txt

    r3103734 r3103735  
    7575= 1.3.14
    7676* More debug info when debug setting is switched on in the settings
     77* Added Dutch language - courtesy of Wim De Kelver
     78* Removed language parameter from shortcodes. This parameter only impacted how dates are shown, but this is already handled in the plugin settings
     79* Bug correction: when settings are positioned to use other date format than ISO (yyyy-mm-dd) the test to show the link to an event ticket only for future events failed. Has been corrected
    7780= 1.3.13
    7881* Better info about Demo site on Wordpress.org
Note: See TracChangeset for help on using the changeset viewer.