京都大学東南アジア地域研究研究所 情報処理室

Google Calendar List View

The plugin is to create a shortcode for displaying the list view of a public Google Calendar.  If you want to use a multi-Google Calendar later,  you can specify them in the shortcode options.

Google Calendar List View

Latest version

Shortcode

If you only use a public Google calendar, you can use the setting values of "Google Calendar API Key" and "Google Calendar ID".If you want to use multi Google Calendar later,  you can specify them in the shortcode options. Version 4.0 supports the multi Google Calendars. If you want to add 2 or more Google Calendars, set g_id_*** shortcode option. You can set an unique key as ***. If you want to set an Google Calendar API key on each Google Calendar ID, set g_api_key_*** with g_id_***.
In case of using the default values, please put the shortcode as Text mode because it needs to use <ul> tag. If you use "p" value on html_tag, you can use Visual mode.

Or if you want to customize the output values, please use the following hook.

Options on Shortcode (Version 6.8)

The shortcode is to display the list (default 10 items) of public Google Calendars from now (start_date)  to the future.  The default date format is YYYY.MM.DD. The sort is the ascending on start_date.

The following shortcode option is priority than setting values.

How to create Google Calendar API Key

I think I don’t need to explain it because above document is very nice! Please keep in mind that there is query limitation (Google Calendar API Usage Limits).

How to find Google Calendar ID

Please see above document, you can find it!

For example

In the following example, two sample google calendars  "Public Calendar 1" and "Public Calendar 2"

Public Calendar 1

Public Calendar 2

 

If you input the following code on Text mode to a Page or a Post (Tested on April 9, 2017).

「Public Calendar 1」
<ul>
[gc_list_view g_id="◯◯@group.calendar.google.com" start_date="ALL" orderbysort="descending"]
</ul>
「Public Calendar 2」
<dl>
<dt>List View of Google Calendar Events</dt>
[gc_list_view g_id="◯◯@group.calendar.google.com" orderbysort="descending" html_tag="dd"]
</dl>

The following content is displayed.

If you click each link, a detail page of the Google Calendar event is displayed as new window.

"Public Calendar 1" is all past data on April 9, 2017, so it needs to set start_date="ALL" or start_date="2017-04-01" option if you want to display the past events.

What’s kind of settings?

There are settings on "Google Calendar List View Settings" in the setting menu of the administration dashboard.

Google Calendar API Settings

Output Settings

Hooks & Notice

How to use Hooks

The following codes were tested on functions.php in the theme.
Please keep in mind that the output data can be changed from the following hooks.
Therefore, please pay attention the security countermeasure.

 

Array for a Hook

Since version 5.9, the reference of the original resources in Google Calendar event are available from the hook. If you want to refer the resources, you specify add_filter( 'lvgc_each_output_data', 'function name', 10, 3 ); and function function-name ($out, $out_atts, $gc_value) .

$out_atts use in each hook.
if you use "extract($out_atts);", you can use the following variables.

 

lvgc_each_output_data

The hook can change the output data in each item.

Default output is as below:

Let’s code the above output data on a hook.

Firstly, please set "hook_secret_key" on a shortcode.

Then, add the following code to the functions.php in a theme.

add_filter( 'lvgc_each_output_data' , 'lvgc_each_output_data_fix' , 10 , 2 );

function lvgc_each_output_data_fix($out, $out_atts){
  extract($out_atts);
  $hook_secret_key = 'hogehoge';

  $start_end_date_value = $start_date_value;
  if(!empty($view_end_date) && !empty($end_date_value)):
    $start_end_date_value .=  ' ' . $view_end_date . ' ' . $end_date_value;
  endif;

  $out = <<< ___EOF___
    
  • $start_end_date_value $output_category_temp $gc_title
  • ___EOF___; return array('hook_secret_key'=>$hook_secret_key, 'data'=>$out); }

     

    If you want to refer original resources in Google Calendar event, please see the sample code.

    add_filter( 'lvgc_each_output_data' , 'lvgc_each_output_data_fix' , 10 , 3 );
    
    function lvgc_each_output_data_fix($out, $out_atts, $gc_value){
      extract($out_atts);
      $hook_secret_key = 'hogehoge';
    
      $start_end_date_value = $start_date_value;
      if(!empty($view_end_date) && !empty($end_date_value)):
        $start_end_date_value .=  ' ' . $view_end_date . ' ' . $end_date_value;
      endif;
    
    // $gc_value['creator']['displayName'], $gc_value['iconLink'], etc.
    
      $out = <<< ___EOF___
        
  • $start_end_date_value $output_category_temp $gc_title
  • ___EOF___; return array('hook_secret_key'=>$hook_secret_key, 'data'=>$out); }

    If you want do a different change on each shortcode, you add "id" option in the shortcode and use the following code.

    [gc_list_view g_id="hogehoge" id="99" hook_secret_key="hogehoge"]

    [gc_list_view g_id="hoge" id="hoge" hook_secret_key="hogehoge"]

    add_filter( 'lvgc_each_output_data' , 'lvgc_each_output_data_fix' , 10 , 2 );
    
    function lvgc_each_output_data_fix($out, $out_atts){
      extract($out_atts);
      $hook_secret_key = 'hogehoge';
    
      $start_end_date_value = $start_date_value;
      if(!empty($view_end_date) && !empty($end_date_value)):
        $start_end_date_value .=  ' ' . $view_end_date . ' ' . $end_date_value;
      endif;
      
      if ($id === '99'):
          $out = <<< ___EOF___
        
  • $start_end_date_value $output_category_temp $gc_title
  • ___EOF___; elseif ($id === 'hoge'): $out = <<< ___EOF___ $start_date_value $output_category_temp $gc_title ___EOF___; endif; return array('hook_secret_key'=>$hook_secret_key, 'data'=>$out); }

    More Customizing

    If you want to customize, please utilize above the attribution for the hook.
    Ex. The following code is the "lip" template tag file.

    * Output HTML

    
    
  • 25/09/2017

    Symposium

    ** project

    Title
  • add_filter( 'lvgc_each_output_data' , 'lvgc_each_output_data_fix' , 10 , 2 );
    
    function lvgc_each_output_data_fix($out, $out_atts){
      extract($out_atts);
      $hook_secret_key = 'hogehoge';
    
      $start_end_date_value = $start_date_value;
      if(!empty($view_end_date) && !empty($end_date_value)):
        $start_end_date_value .=  ' ' . $view_end_date . ' ' . $end_date_value;
      endif;
    
      // Customizing category html.
    $output_category_temp = '';
    if(!empty($enable_view_category)):
        if(!empty($hash_tags_type_title)):
            $output_category_temp .= "

    $hash_tags_type_title

    "; endif; if(!empty($hash_tags_organizer_value)): $output_category_temp .= "

    $hash_tags_organizer_value

    "; endif; endif; if ( isset($no_event_link) && !empty($no_event_link) ): $out_temp .= <<< ___EOF___
  • $start_end_date_value $output_category_temp $pre_start_date_value_br
    - $gc_title ___EOF___; else: $out_temp .= <<< ___EOF___
  • $start_end_date_value $output_category_temp $pre_start_date_value_br
    - $gc_title ___EOF___; endif; if ( isset($view_location) && !empty($view_location) ): if( isset($view_location_name) && !empty($view_location_name) ): $location_header_name = $view_location_name; else: $location_header_name = __("Location:", $this->plugin_name); endif; $out .= <<< ___EOF___
    $location_header_name $gc_location ___EOF___; endif; $out .= <<< ___EOF___ ___EOF___; return array('hook_secret_key'=>$hook_secret_key, 'data'=>$out); }

    Notes on customizing li-month

    When customizing using hooks, refer to library/tags/li-month.php, and use the traditional <ul> tag, please put </ul> in the next line of the shortcode to close it. This is because the hooks process each event, and you cannot set a closing tag at the end of the hooks when you put together monthly events.

    The month name is limited to English because it uses the datetime function. If you want to make it in other languages, please write the code for that.
    The following is a sample code for Japanese and Dutch-based on library/tags/li-month.php.

    add_filter( 'lvgc_each_output_data' , 'lvgc_each_output_data_fix' , 10 , 2 );
    
    function lvgc_each_output_data_fix($out, $out_atts){
      extract($out_atts);
      $hook_secret_key = 'hogehoge';
    
      $start_end_date_value = $start_date_value;
      if(!empty($view_end_date) && !empty($end_date_value)):
        $start_end_date_value .=  ' ' . $view_end_date . ' ' . $end_date_value;
      endif;
    
    $out = '';
    if($pre_start_date_month_value === $start_date_month_value):
        $month_value = '';
    else:
        if( isset($month_value) && !empty($month_value) ) :
            $out .= <<< ___EOF___
    
    
    ___EOF___;
        endif;
    endif;
    
    if( isset($month_value) && !empty($month_value) ) :
        $out .= <<< ___EOF___
    $month_value
    
      ___EOF___; endif; if ( isset($no_event_link) && !empty($no_event_link) ): // The following foreach is used to support multilingual month names. If you comment out this section, the month name will be fixed in English. foreach($translate_month_values as $org_lang=>$con_lang): if($month_value === $org_lang): $month_value = $con_lang; break; endif; endforeach; $out .= <<< ___EOF___
    • $start_end_date_value $output_category_temp $gc_title ___EOF___; else: $out .= <<< ___EOF___
    • $start_end_date_value $output_category_temp $gc_title ___EOF___; endif; if ( isset($view_location) && !empty($view_location) ): if( isset($view_location_name) && !empty($view_location_name) ): $location_header_name = $view_location_name; else: $location_header_name = __("Location:", $plugin_name); endif; $out .= <<< ___EOF___
      $location_header_name $gc_location ___EOF___; endif; $out .= <<< ___EOF___
    • ___EOF___; return array('hook_secret_key'=>$hook_secret_key, 'data'=>$out); }

     

    Notice: coding timezone

    WordPress forcibly processes the date as UTC timezone. In other words, "date" and "i18_date" function don’t work on  WordPress if you want to code other timezone except UTC.  Therefore, you need to use WordPress date functions "current_time" and "get_date_from_gmt" instead of date and i18_date.

    Get current time & convert date format

    • $current_time = currentitme("d-m-Y");  (03-04-2017 means April 3, 2017)

    Convert date format: get_date_from_gmt

    • $start_date = get_date_from_gmt($item[‘start’][‘dateTime’], "d-m-Y");

    The following example is to convert $start_date to the setting timezone on WordPress.

    Change history (past version)

    • Nov 05, 2022: Update 7.0.0(Changed API acquisition method)
    • Mar 31, 2022: Update 6.9.2
    • Mar 30, 2022: Update 6.9, 6.9.1
    • Mar 27, 2022: Update 6.8
    • Feb 10, 2022: Update 6.7.2
    • Feb 7, 2022: Update 6.7.1
    • Feb 4, 2022: Update 6.7
    • Nov 21, 2021: Update 6.6
    • Apr 22, 2021: Update 6.5.2
    • Apr 21, 2021: Update 6.5.1
    • Apr 21, 2021: Update 6.5(Added “no_event_link” shortcode option.)
    • Apr 18, 2021: Update 6.4, 6.4.1(Add shortcode option view_location_name.)
    • Apr 16, 2021: Update 6.3(Added the ability to show excerpt of event description (max 1024 bytes) when you mouse over the event link)
    • Mar 20, 2021: Update 6.2
    • Mar 16, 2021: Update 6.1
    • Mar 15, 2021: Update 6.0
    • Mar 05, 2021: Update 5.9.1
    • May 14, 2020: Update 5.9
    • Mar 08, 2020: Update 5.8
    • Feb 26, 2020: Update 5.7
    • Feb 04, 2020: Update 5.6
    • Jan 24, 2020: Update 5.5
    • Dec 13, 2019: Update 5.4
    • Nov 26, 2019: Update 5.3
    • Nov 11, 2019: Update 5.2
    • Jul 19, 2019: Update 5.1
    • Feb 14, 2019: Update 5.0
    • Sep 27, 2018: Updated 4.6
    • Sep 26, 2018: Updated 4.5 and 4.5.1
    • Sep 18, 2018: Updated 4.4
    • Jul 11, 2018: Updated 4.3
    • Nov 11, 2017: Updated 4.2
    • Oct 19, 2017: Updated 4.1
    • Sep 17, 2017: Updated 4.0
    • Aug 31, 2017: Updated 3.1
    • Aug 25, 2017: Updated 3.0
    • Aug 24, 2017: Updated 2.2
    • Jul 21, 2017: Updated 2.1
    • Jun 26, 2017: Updated 2.0
    • Jun 25, 2017: Updated 1.5, 1.51
    • Apr 18, 2017: Updated 1.3, 1.4, 1.41, and 1.42.
    • Apr 11, 2017: Updated 1.2.
    • Apr 10, 2017: Updated 1.1.
    • Apr 09, 2017: Released 1.0.

    November 21, 2021 Fixed the documentation for version 6.6.
    April 21, 2021 Fixed the documentation for version 6.5.
    April 18, 2021 Fixed the documentation for version 6.4, 6.4.1.
    April 16, 2021 Fixed the documentation for version 6.3.
    March 16, 2021 Fixed the documentation for version 6.1.
    March 15, 2021 Fixed the documentation for version 6.0.
    August 25, 2017  Fixed the documentation for version 3.0.
    August 24, 2017  Fixed the documentation for version 2.2.
    July 21, 2017 Fixed the documentation for version 2.1.
    June 26, 2017  Fixed the documentation for version 2.0.
    June 25, 2017 @kimipooh

     

     

     

    京都大学東南アジア地域研究研究所 情報処理室

    Back to top