__construct(); } /** * Init all variables when WP is ready * * @action evenpost_init * @filter eventpost_default_list_shema * @filter eventpost_list_shema */ public function init(){ $this->META_START = 'event_begin'; $this->META_END = 'event_end'; $this->META_COLOR = 'event_color'; // http://codex.wordpress.org/Geodata $this->META_ADD = 'geo_address'; $this->META_LAT = 'geo_latitude'; $this->META_LONG = 'geo_longitude'; $this->list_id = 0; $this->NomDuMois = array('', __('Jan', 'event-post'), __('Feb', 'event-post'), __('Mar', 'event-post'), __('Apr', 'event-post'), __('May', 'event-post'), __('Jun', 'event-post'), __('Jul', 'event-post'), __('Aug', 'event-post'), __('Sept', 'event-post'), __('Oct', 'event-post'), __('Nov', 'event-post'), __('Dec', 'event-post')); $this->Week = array(__('Sunday', 'event-post'), __('Monday', 'event-post'), __('Tuesday', 'event-post'), __('Wednesday', 'event-post'), __('Thursday', 'event-post'), __('Friday', 'event-post'), __('Saturday', 'event-post')); $this->maps = $this->get_maps(); $this->settings = $this->get_settings(); do_action('evenpost_init', $this); $this->Shortcodes = new EventPost_Shortcodes(); // Edit add_action('add_meta_boxes', array(&$this, 'add_custom_box')); foreach($this->settings['posttypes'] as $posttype){ add_filter('manage_'.$posttype.'_posts_columns', array(&$this, 'columns_head'), 2); add_action('manage_'.$posttype.'_posts_custom_column', array(&$this, 'columns_content'), 10, 2); } if (!empty($this->settings['markpath']) && !empty($this->settings['markurl'])) { $this->markpath = ABSPATH.'/'.$this->settings['markpath']; $this->markurl = $this->settings['markurl']; } else { $this->markpath = plugin_dir_path(__FILE__) . 'markers/'; $this->markurl = plugins_url('/markers/', __FILE__); } $this->dateformat = str_replace(array('yy', 'mm', 'dd'), array('Y', 'm', 'd'), __('yy-mm-dd', 'event-post')); $this->default_list_shema = apply_filters('eventpost_default_list_shema', array( 'container' => ' <%type% class="event_loop %id% %class%" id="%listid%" style="%style%" %attributes%>%list% ', 'item' => ' <%child% class="event_item %class%" data-color="%color%"> %event_thumbnail%
%event_title%
%event_date% %event_cat% %event_location% %event_excerpt% ' )); $this->list_shema = apply_filters('eventpost_list_shema',$this->default_list_shema); $this->map_interactions=array( 'DragRotate'=>__('Drag Rotate', 'event-post'), 'DoubleClickZoom'=>__('Double Click Zoom', 'event-post'), 'DragPan'=>__('Drag Pan', 'event-post'), 'PinchRotate'=>__('Pinch Rotate', 'event-post'), 'PinchZoom'=>__('Pinch Zoom', 'event-post'), 'KeyboardPan'=>__('Keyboard Pan', 'event-post'), 'KeyboardZoom'=>__('Keyboard Zoom', 'event-post'), 'MouseWheelZoom'=>__('Mouse Wheel Zoom', 'event-post'), 'DragZoom'=>__('Drag Zoom', 'event-post'), ); } public function register_widgets(){ register_widget('EventPost_List'); register_widget('EventPost_Map'); register_widget('EventPost_Cal'); } /** * Usefull hexadecimal to decimal converter. Returns an array of RGB from a given hexadecimal color. * @param string $color * @return array $color($R, $G, $B) */ public function hex2dec($color = '000000') { $tbl_color = array(); if (!strstr('#', $color)){ $color = '#' . $color; } $tbl_color['R'] = hexdec(substr($color, 1, 2)); $tbl_color['G'] = hexdec(substr($color, 3, 2)); $tbl_color['B'] = hexdec(substr($color, 5, 2)); return $tbl_color; } /** * Fetch all registered image sizes * @global array $_wp_additional_image_sizes * @return array */ function get_thumbnail_sizes(){ global $_wp_additional_image_sizes; $sizes = array('thumbnail', 'medium', 'large', 'full'); foreach(array_keys($_wp_additional_image_sizes) as $size){ $sizes[]=$size; } return $sizes; } /** * Just for localization */ private function no_use() { __('Add calendar and/or geolocation metadata on posts', 'event-post'); __('Event Post', 'event-post'); } /** * Get blog settings, load and saves default settings if needed. Can be filterred using * * `` * * @action eventpost_getsettings_action * @filter eventpost_getsettings * @return array */ public function get_settings() { $ep_settings = get_option('ep_settings'); $reg_settings=false; if(!is_array($ep_settings)){ $ep_settings = array(); } if (!isset($ep_settings['dateformat']) || empty($ep_settings['dateformat'])) { $ep_settings['dateformat'] = get_option('date_format'); $reg_settings=true; } if (!isset($ep_settings['timeformat']) || empty($ep_settings['timeformat'])) { $ep_settings['timeformat'] = get_option('time_format'); $reg_settings=true; } if (!isset($ep_settings['tile']) || empty($ep_settings['tile']) || !isset($this->maps[$ep_settings['tile']])) { $maps = array_keys($this->maps); $ep_settings['tile'] = $this->maps[$maps[0]]['id']; $reg_settings=true; } if (!isset($ep_settings['cache']) || !is_numeric($ep_settings['cache'])) { $ep_settings['cache'] = 0; $reg_settings=true; } if (!isset($ep_settings['export']) || empty($ep_settings['export'])) { $ep_settings['export'] = 'both'; $reg_settings=true; } if (!isset($ep_settings['dateforhumans'])) { $ep_settings['dateforhumans'] = 1; $reg_settings=true; } if (!isset($ep_settings['emptylink'])) { $ep_settings['emptylink'] = 1; $reg_settings=true; } if (!isset($ep_settings['markpath'])) { $ep_settings['markpath'] = ''; $reg_settings=true; } if (!isset($ep_settings['singlepos']) || empty($ep_settings['singlepos'])) { $ep_settings['singlepos'] = 'after'; $reg_settings=true; } if (!isset($ep_settings['loopicons'])) { $ep_settings['loopicons'] = 1; $reg_settings=true; } if (!isset($ep_settings['adminpos']) || empty($ep_settings['adminpos'])) { $ep_settings['adminpos'] = 'side'; $reg_settings=true; } if (!isset($ep_settings['container_shema']) ) { $ep_settings['container_shema'] = ''; $reg_settings=true; } if (!isset($ep_settings['item_shema']) ) { $ep_settings['item_shema'] = ''; $reg_settings=true; } if(!isset($ep_settings['datepicker']) || !in_array($ep_settings['datepicker'], array('simple', 'native'))){ $ep_settings['datepicker']='simple'; $reg_settings=true; } if(!isset($ep_settings['posttypes']) || !is_array($ep_settings['posttypes'])){ $ep_settings['posttypes']=array('post'); $reg_settings=true; } do_action_ref_array('eventpost_getsettings_action', array(&$ep_settings, &$reg_settings)); //Save settings not changed if($reg_settings===true){ update_option('ep_settings', $ep_settings); } return apply_filters('eventpost_getsettings', $ep_settings); } /** * Checks if HTML schemas are not empty * @param array $shema * @return array */ public function custom_shema($shema){ if(!empty($this->settings['container_shema'])){ $shema['container']=$this->settings['container_shema']; } if(!empty($this->settings['item_shema'])){ $shema['item']=$this->settings['item_shema']; } return $shema; } /** * Parse the maps.json file. Custom maps can be added by using the `eventpost_getsettings` filter like the following example: * * ``` * 'Myt custom map', * 'id'=>'custom_map', * 'urls'=>array( * 'http://a.customurl.org/{z}/{x}/{y}.png', * 'http://b.customurl.org/{z}/{x}/{y}.png', * 'http://c.customurl.org/{z}/{x}/{y}.png', * ) * )); * return $maps; * } * ?> * ``` * * @filter eventpost_maps * @return array of map arrays ['name', 'id', 'urls'] */ public function get_maps() { $maps = array(); $filename = plugin_dir_path(__FILE__) . 'maps.json'; if (is_file($filename) && (false !== $json = json_decode(file_get_contents($filename)))) { // Convert objects to array to ensure retrocompatibility $arrays = array(); foreach($json as $map){ $arrays[$map->id] = (array) $map; } $maps = apply_filters('eventpost_maps', $arrays); } return $maps; } /** * * @return array */ public function get_colors() { $colors = array(); if (is_dir($this->markpath)) { $files = scandir($this->markpath); foreach ($files as $file) { if (substr($file, -4) == '.png') { $colors[substr($file, 0, -4)] = $this->markurl . $file; } } } return $colors; } /** * * @param string $color * @return sring */ public function get_marker($color) { if (is_file($this->markpath . $color . '.png')) { return $this->markurl . $color . '.png'; } return plugins_url('/markers/ffffff.png', __FILE__); } /** * Enqueue CSS files */ public function load_styles() { //CSS wp_register_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version); wp_enqueue_style('event-post', plugins_url('/css/eventpost.min.css', __FILE__), false, $this->version); wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version); wp_enqueue_style('dashicons', includes_url('/css/dashicons.min.css')); } /** * Enqueue Editor style */ public function editor_styles() { add_editor_style( plugins_url('/css/eventpost.min.css', __FILE__) ); } /** * Enqueue JS files */ public function load_scripts($deps = array('jquery')) { // JS wp_enqueue_script('jquery', false, false, false, true); wp_enqueue_script('event-post', plugins_url('/js/eventpost.min.js', __FILE__), $deps, $this->version, true); wp_localize_script('event-post', 'eventpost_params', array( 'imgpath' => plugins_url('/img/', __FILE__), 'maptiles' => $this->maps, 'defaulttile' => $this->settings['tile'], 'ajaxurl' => admin_url() . 'admin-ajax.php', 'map_interactions'=>$this->map_interactions, )); } /** * Enqueue JS files for maps */ public function load_map_scripts() { // JS wp_enqueue_script('openlayers', plugins_url('/js/OpenLayers.js', __FILE__), false, $this->version, true); $this->load_scripts(array('jquery', 'openlayers')); if(is_admin()){ $this->admin_scripts(array('jquery', 'openlayers')); } } /** * Enqueue CSS files in admin */ public function admin_head() { $page = basename($_SERVER['SCRIPT_NAME']); if( $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){ return; } wp_enqueue_style('openlayers', plugins_url('/css/openlayers.css', __FILE__), false, $this->version); wp_enqueue_style('jquery-ui', plugins_url('/css/jquery-ui.css', __FILE__), false, $this->version); wp_enqueue_style('event-post-admin', plugins_url('/css/eventpost-admin.css', __FILE__), false, $this->version); } /** * Enqueue JS files in admin */ public function admin_scripts($deps = array('jquery')) { $page = basename($_SERVER['SCRIPT_NAME']); if( $page!='post-new.php' && !($page=='post.php' && filter_input(INPUT_GET, 'action')=='edit') && !($page=='options-general.php' && filter_input(INPUT_GET, 'page')=='event-settings') ){ return; } wp_enqueue_script('jquery'); wp_enqueue_script('jquery-effects-core'); wp_enqueue_script('jquery-effects-shake'); if($this->settings['datepicker']=='simple' || (isset($_GET['page']) && $_GET['page']=='event-settings')){ wp_enqueue_script('jquery-ui-datepicker'); $deps[] = 'jquery-ui-datepicker'; } wp_enqueue_script('event-post-admin', plugins_url('/js/eventpost-admin.min.js', __FILE__), $deps, $this->version, true); $language = get_bloginfo('language'); if (strpos($language, '-') > -1) { $language = strtolower(substr($language, 0, 2)); } wp_localize_script('event-post-admin', 'eventpost', array( 'imgpath' => plugins_url('/img/', __FILE__), 'date_choose' => ''.__('Choose', 'event-post').'', 'date_format' => __('yy-mm-dd', 'event-post'), 'more_icons' => __('More icons', 'event-post'), 'pick_a_date'=>__('Pick a date','event-post'), 'use_current_location'=>__('Use my current location','event-post'), 'start_drag'=>__('Click to
drag the map
and change location','event-post'), 'empty_address'=>__('Be kind to fill a non empty address :)', 'event-post'), 'search'=>__('Type an address', 'event-post'), 'stop_drag'=>_x('Done','Stop allowing to drag the map', 'event-post'), 'datepickeri18n'=>array( 'order'=>__( '%1$s %2$s, %3$s @ %4$s:%5$s', 'event-post'), 'day'=>__('Day', 'event-post'), 'month'=>__('Month', 'event-post'), 'year'=>__('Day', 'event-post'), 'hour'=>__('Hour', 'event-post'), 'minute'=>__('Minute', 'event-post'), 'ok'=>__('OK', 'event-post'), 'cancel'=>__('Cancel', 'event-post'), 'edit'=>__('Edit', 'event-post'), 'months'=>$this->NomDuMois, ), 'META_START' => $this->META_START, 'META_END' => $this->META_END, 'META_ADD' => $this->META_ADD, 'META_LAT' => $this->META_LAT, 'META_LONG' => $this->META_LONG, 'lang'=>$language, 'maptiles' => $this->maps, 'defaulttile' => $this->settings['tile'] )); } /** * Add custom header meta for single events */ public function single_header() { if (is_single()) { $event = $this->retreive(); if ($event->address != '' || ($event->lat != '' && $event->long != '')) { ?> start != '' && $event->end != '') { ?> settings['dateforhumans']){ if (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y')) { return __('today', 'event-post'); } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('+1 day'))) { return __('tomorrow', 'event-post'); } elseif (is_numeric($date) && date('d/m/Y', $date) == date('d/m/Y', strtotime('-1 day'))) { return __('yesterday', 'event-post'); } } return date_i18n($format, $date); } /** * * @param timestamp $time_start * @param timestamp $time_end * @return string */ public function delta_date($time_start, $time_end){ if(!$time_start || !$time_end){ return; } //Display dates $dates="\t\t\t\t".'
'; if (date('d/m/Y', $time_start) == date('d/m/Y', $time_end)) { $dates.= "\n\t\t\t\t\t\t\t".''; } else { $dates.= ' ' . __('from', 'event-post') . ' ' . __('to', 'event-post') . ' '; } $dates.="\n\t\t\t\t\t\t".'
'; return $dates; } /** * * @param WP_Post object $post * @param mixed $links * @return string */ public function print_date($post = null, $links = 'deprecated', $context='') { $dates = ''; $event = $this->retreive($post); if ($event->start != '' && $event->end != '') { $dates.=$this->delta_date($event->time_start, $event->time_end); $timezone_string = get_option('timezone_string'); $gmt_offset = get_option('gmt_offset '); $codegmt = 0; if ($gmt_offset != 0 && substr($gmt_offset, 0, 1) != '-' && substr($gmt_offset, 0, 1) != '+') { $codegmt = $gmt_offset * -1; $gmt_offset = '+' . $gmt_offset; } if (!is_admin() && $event->time_end > current_time('timestamp') && ( $this->settings['export'] == 'both' || ($this->settings['export'] == 'single' && is_single() ) || ($this->settings['export'] == 'list' && !is_single() ) )) { // Export event $title = urlencode($post->post_title); $address = urlencode($post->address); $url = urlencode($post->guid); $mt = strtotime($codegmt . ' Hours', $event->time_start); $d_s = date("Ymd", $mt) . 'T' . date("His", $mt); $mte = strtotime($codegmt . ' Hours', $event->time_end); $d_e = date("Ymd", $mte) . 'T' . date("His", $mte); $uid = $post->ID . '-' . $post->blog_id; // format de date ICS $ics_url = plugins_url('export/ics.php', __FILE__) . '?t=' . $title . '&u=' . $uid . '&sd=' . $d_s . '&ed=' . $d_e . '&a=' . $address . '&d=' . $url . '&tz=%3BTZID%3D' . urlencode($timezone_string); // format de date Google cal $google_url = 'https://www.google.com/calendar/event?action=TEMPLATE&text=' . $title . '&dates=' . $d_s . 'Z/' . $d_e . 'Z&details=' . $url . '&ctz='.$timezone_string.'&location=' . $address . '&trp=false&sprop=&sprop=name'; // format de date VCS $vcs_url = plugins_url('export/vcs.php', __FILE__) . '?t=' . $title . '&u=' . $uid . '&sd=' . $d_s . '&ed=' . $d_e . '&a=' . $address . '&d=' . $url . '&tz=%3BTZID%3D' . urlencode($timezone_string); $dates.=' ical Google outlook '; } } return apply_filters('eventpost_printdate', $dates); } /** * * @param WP_Post object $post * @return string */ public function print_location($post=null, $context='') { $location = ''; if ($post == null) $post = get_post(); elseif (is_numeric($post)) { $post = get_post($post); } if (!isset($post->start)) { $post = $this->retreive($post); } $address = $post->address; $lat = $post->lat; $long = $post->long; $color = $post->color; if ($address != '' || ($lat != '' && $long != '')) { $location.="\t\t\t\t".'ID . '" data-latitude="' . $lat . '" data-longitude="' . $long . '" data-marker="' . $this->get_marker($color) . '" '; } $location.=' itemprop="adr">' . "\n\t\t\t\t\t\t\t".'' . "\n".$address . "\n\t\t\t\t\t\t\t". ''; if ($context=='single' && $lat != '' && $long != '') { $location.="\n\t\t\t\t\t\t\t".'' . __('Map', 'event-post') . ''; } $location.="\n\t\t\t\t\t\t".''; } return apply_filters('eventpost_printlocation', $location); } /** * * @param WP_Post object $post * @return string */ public function print_categories($post=null, $context='') { if ($post == null) $post = get_post(); elseif (is_numeric($post)) { $post = get_post($post); } if (!isset($post->start)) { $post = $this->retreive($post); } $cats = ''; $categories = $post->categories; if ($categories) { $cats.="\t\t\t\t".'color; if ($color != '') { $cats.=' style="color:#' . $color . '"'; } $cats.='>'; foreach ($categories as $category) { $cats .= $category->name . ' '; } $cats.=''; } return $cats; } /** * Generate, return or output date event datas * @param WP_Post object $post * @param string $class * @filter eventpost_get_single * @return string */ public function get_single($post = null, $class = '', $context='') { if ($post == null) { $post = $this->retreive(); } $datas_date = $this->print_date($post, null, $context); $datas_cat = $this->print_categories($post, $context); $datas_loc = $this->print_location($post, $context); if ($datas_date != '' || $datas_loc != '') { $rgb = $this->hex2dec($post->color); return '
' . apply_filters('eventpost_get_single', $datas_date . $datas_cat . $datas_loc, $post) . '
'; } return ''; } /** * Displays dates of a gieven post * @param WP_Post object $post * @param string $class * @return string */ public function get_singledate($post = null, $class = '', $context='') { return '
' . "\n\t\t".$this->print_date($post, null, $context) . "\n\t\t\t\t\t".'
'; } /** * Displays coloured terms of a given post * @param WP_Post object $post * @param string $class * @return string */ public function get_singlecat($post = null, $class = '', $context='') { return '
' . "\n\t\t".$this->print_categories($post, $context) . "\n\t\t\t\t\t".'
'; } /** * Displays location of a given post * @param WP_Post object $post * @param string $class * @return string */ public function get_singleloc($post = null, $class = '', $context='') { return '
' . "\n\t\t".$this->print_location($post, $context) . "\n\t\t\t\t\t".'
'; } /** * Uses `the_content` filter to add event details before or after the content of the current post * @param string $content * @return string */ public function display_single($content) { if (is_page() || !is_single() || is_home()) return $content; $post = get_queried_object(); //Prevent from filters applying "the_content" on another thing than the current post content remove_filter('the_content', array(&$this, 'display_single'), 9999); $current_content = apply_filters('the_content', $post->post_content); if ($current_content == $content) { $post = $this->retreive(); $eventbar = apply_filters('eventpost_contentbar', $this->get_single($post, 'event_single', 'single'), $post); if($this->settings['singlepos']=='before'){ $content=$eventbar.$content; } else{ $content.=$eventbar; } $this->load_map_scripts(); } add_filter('the_content', array(&$this, 'display_single'), 9999); return $content; } /** * Outputs events details (dates, geoloc, terms) of given post * @param WP_Post object $post * @echoes string * @return void */ public function print_single($post = null) { echo $this->get_single($post); } /** * Alter the post title in order to add icons if needed * @param string $title * @return string */ public function the_title($title){ if(!in_the_loop() || !$this->settings['loopicons']){ return $title; } $event = $this->retreive(); if(!empty($event->start)){ $title .= ' '; } if(!empty($event->lat) && !empty($event->long)){ $title .= ' '; } return $title; } /** * Return an HTML list of events * * @filter eventpost_params($defaults, 'list_events') * @filter eventpost_listevents * @filter eventpost_item_scheme_entities * @filter eventpost_item_scheme_values * * @param array $atts * @param string $id * @param string $context * @return string */ public function list_events($atts, $id = 'event_list', $context='') { $ep_settings = $this->settings; $defaults = array( 'nb' => 0, 'type' => 'div', 'future' => true, 'past' => false, 'geo' => 0, 'width' => '', 'height' => '', 'tile' => $ep_settings['tile'], 'title' => '', 'before_title' => '

', 'after_title' => '

', 'cat' => '', 'tag' => '', 'events' => '', 'style' => '', 'thumbnail' => '', 'thumbnail_size' => '', 'excerpt' => '', 'orderby' => 'meta_value', 'order' => 'ASC', 'class' => '', 'container_schema' => $this->list_shema['container'], 'item_schema' => $this->list_shema['item'], ); // Map UI options foreach($this->map_interactions as $int_key=>$int_name){ $defaults[$int_key]=true; } $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'list_events'), $atts); extract($atts); if (!is_array($events)) { $events = $this->get_events($atts); } $ret = ''; $this->list_id++; if (sizeof($events) > 0) { if (!empty($title)) { $ret.= html_entity_decode($before_title) . $title . html_entity_decode($after_title); } $child = ($type == 'ol' || $type == 'ul') ? 'li' : 'div'; $list = ''; if($id=='event_geolist'){ $this->load_map_scripts(); $list.=sprintf('<%1$s class="event_geolist_icon_loader">

'.__('An events map', 'event-post').'

', $type); } foreach ($events as $event) { $class_item = ($event->time_end >= current_time('timestamp')) ? 'event_future' : 'event_past'; if ($ep_settings['emptylink'] == 0 && empty($event->post_content)) { $event->permalink = '#' . $id . $this->list_id; } elseif(empty($ob->permalink)){ $event->permalink=$event->guid; } $list.=str_replace( apply_filters('eventpost_item_scheme_entities', array( '%child%', '%class%', '%color%', '%event_link%', '%event_thumbnail%', '%event_title%', '%event_date%', '%event_cat%', '%event_location%', '%event_excerpt%' )), apply_filters('eventpost_item_scheme_values', array( $child, $class_item, $event->color, $event->permalink, $thumbnail == true ? '' . get_the_post_thumbnail($event->root_ID, !empty($thumbnail_size) ? $thumbnail_size : 'thumbnail', array('class' => 'attachment-thumbnail wp-post-image event_thumbnail')) . '' : '', $event->post_title, $this->get_singledate($event, '', $context), $this->get_singlecat($event, '', $context), $this->get_singleloc($event, '', $context), $excerpt == true && $event->post_excerpt!='' ? ''.$event->post_excerpt.'' : '', ), $event), $item_schema ); } $attributes = ''; if($id == 'event_geolist'){ $attributes = 'data-tile="'.$tile.'" data-width="'.$width.'" data-height="'.$height.'" data-disabled-interactions="'; foreach($this->map_interactions as $int_key=>$int_name){ $attributes.=$atts[$int_key]==false ? $int_key.', ' : ''; } $attributes.='"'; } $ret.=str_replace( array( '%type%', '%id%', '%class%', '%listid%', '%style%', '%attributes%', '%list%' ), array( $type, $id, $class, $id . $this->list_id, (!empty($width) ? 'width:' . $width . ';' : '') . (!empty($height) ? 'height:' . $height . ';' : '') . $style, $attributes, $list ), $container_schema ); } return apply_filters('eventpost_listevents', $ret, $id.$this->list_id, $atts, $events, $context); } /** * get_events * @param array $atts * @filter eventpost_params * @filter eventpost_get_items * @return array of post_ids wich are events */ public function get_events($atts) { $requete = (shortcode_atts(apply_filters('eventpost_params', array( 'nb' => 5, 'future' => true, 'past' => false, 'geo' => 0, 'cat' => '', 'tag' => '', 'date' => '', 'orderby' => 'meta_value', 'orderbykey' => $this->META_START, 'order' => 'ASC', 'tax_name' => '', 'tax_term' => '', 'post_type'=> $this->settings['posttypes'] ), 'get_events'), $atts)); extract($requete); wp_reset_query(); $arg = array( 'post_type' => $post_type, 'posts_per_page' => $nb, 'meta_key' => $orderbykey, 'orderby' => $orderby, 'order' => $order ); if($tax_name=='category'){ $tax_name=''; $cat=$tax_term; } elseif($tax_name=='post-tag'){ $tax_name=''; $tag=$tax_term; } // CUSTOM TAXONOMY if ($tax_name != '' && $tax_term != '') { $arg[$tax_name] = $tax_term; } // CAT if ($cat != '') { if (preg_match('/[a-zA-Z]/i', $cat)) { $arg['category_name'] = $cat; } else { $arg['cat'] = $cat; } } // TAG if ($tag != '') { $arg['tag'] = $tag; } // DATES $meta_query = array( array( 'key' => $this->META_END, 'value' => '', 'compare' => '!=' ), array( 'key' => $this->META_END, 'value' => '0:0:00 0:', 'compare' => '!=' ), array( 'key' => $this->META_END, 'value' => ':00', 'compare' => '!=' ), array( 'key' => $this->META_START, 'value' => '', 'compare' => '!=' ), array( 'key' => $this->META_START, 'value' => '0:0:00 0:', 'compare' => '!=' ) ); if ($future == 0 && $past == 0) { $meta_query = array(); $arg['meta_key'] = null; $arg['orderby'] = null; $arg['order'] = null; } elseif ($future == 1 && $past == 0) { $meta_query[] = array( 'key' => $this->META_END, 'value' => current_time('mysql'), 'compare' => '>=', //'type'=>'DATETIME' ); } elseif ($future == 0 && $past == 1) { $meta_query[] = array( 'key' => $this->META_END, 'value' => current_time('mysql'), 'compare' => '<=', //'type'=>'DATETIME' ); } if ($date != '') { $date = date('Y-m-d', $date); $meta_query = array( array( 'key' => $this->META_END, 'value' => $date . ' 00:00:00', 'compare' => '>=', 'type' => 'DATETIME' ), array( 'key' => $this->META_START, 'value' => $date . ' 23:59:59', 'compare' => '<=', 'type' => 'DATETIME' ) ); } // GEO if ($geo == 1) { $meta_query[] = array( 'key' => $this->META_LAT, 'value' => '', 'compare' => '!=' ); $meta_query[] = array( 'key' => $this->META_LONG, 'value' => '', 'compare' => '!=' ); $arg['meta_key'] = $this->META_LAT; $arg['orderby'] = 'meta_value'; $arg['order'] = 'DESC'; } $arg['meta_query'] = $meta_query; $query_md5 = 'eventpost_' . md5(var_export($requete, true)); // Check if cache is activated if ($this->settings['cache'] == 1 && false !== ( $cached_events = get_transient($query_md5) )) { return apply_filters('eventpost_get_items', is_array($cached_events) ? $cached_events : array(), $requete, $arg); } $events = apply_filters('eventpost_get', '', $requete, $arg); if ('' === $events) { global $wpdb; $query = new WP_Query($arg); $events = $wpdb->get_col($query->request); foreach ($events as $k => $post) { $event = $this->retreive($post); $events[$k] = $event; } } if ($this->settings['cache'] == 1){ set_transient($query_md5, $events, 5 * MINUTE_IN_SECONDS); } return apply_filters('eventpost_get_items', $events, $requete, $arg); } /** * * @param object $event * @return object */ public function retreive($event = null) { global $EventPost_cache; $ob = get_post($event); if($ob->start){ return $ob; } if(isset($EventPost_cache[$ob->ID])){ return $EventPost_cache[$ob->ID]; } $ob->start = get_post_meta($ob->ID, $this->META_START, true); $ob->end = get_post_meta($ob->ID, $this->META_END, true); if (!$this->dateisvalid($ob->start)){ $ob->start = ''; } if (!$this->dateisvalid($ob->end)){ $ob->end = ''; } $ob->root_ID = $ob->ID; $ob->time_start = !empty($ob->start) ? strtotime($ob->start) : ''; $ob->time_end = !empty($ob->end) ? strtotime($ob->end) : ''; $ob->address = get_post_meta($ob->ID, $this->META_ADD, true); $ob->lat = get_post_meta($ob->ID, $this->META_LAT, true); $ob->long = get_post_meta($ob->ID, $this->META_LONG, true); $ob->color = get_post_meta($ob->ID, $this->META_COLOR, true); $ob->categories = get_the_category($ob->ID); $ob->permalink = get_permalink($ob->ID); $ob->blog_id = get_current_blog_id(); if ($ob->color == ''){ $ob->color = '000000'; } $EventPost_cache[$ob->ID] = apply_filters('eventpost_retreive', $ob); return $EventPost_cache[$ob->ID]; } /** * * @param mixte $_term * @param string $taxonomy * @param string $post_type */ public function retreive_term($_term=null, $taxonomy='category', $post_type='post') { $term = get_term($_term, $taxonomy); if(!$term){ return $term; } $term->start = $term->end = $term->time_start = $term->time_end = Null; $request = array( 'post_type'=>$post_type, 'tax_name'=>$term->taxonomy, 'tax_term'=>$term->slug, 'future'=>true, 'past'=>true, 'nb'=>-1, 'order'=>'ASC' ); $events = $this->get_events($request); $term->events_count = count($events); if($term->events_count){ $term->start = $events[0]->start; $term->time_start = $events[0]->time_start; $term->end = $events[$term->events_count-1]->end; $term->time_end = $events[$term->events_count-1]->time_end; } $request['order']='DESC'; $request['nb']=1; $request['orderbykey']=$this->META_END; $events = $this->get_events($request); if(count($events)){ $term->end = $events[0]->end; $term->time_end = $events[0]->time_end; } return $term; } /** ADMIN ISSUES * */ /** * add custom boxes in posts edit page */ public function add_custom_box() { foreach($this->settings['posttypes'] as $posttype){ add_meta_box('event_post_date', __('Event date', 'event-post'), array(&$this, 'inner_custom_box_date'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core'); add_meta_box('event_post_loc', __('Location', 'event-post'), array(&$this, 'inner_custom_box_loc'), $posttype, apply_filters('eventpost_add_custom_box_position', $this->settings['adminpos'], $posttype), 'core'); do_action('eventpost_add_custom_box', $posttype); } if(!function_exists('shortcode_ui_register_for_shortcode')){ add_meta_box('event_post_sc_edit', __('Events Shortcode editor', 'event-post'), array(&$this, 'inner_custom_box_edit'), 'page'); } } /** * display the date custom box */ public function inner_custom_box_date() { wp_nonce_field(plugin_basename(__FILE__), 'eventpost_nonce'); $post_id = get_the_ID(); $event = $this->retreive($post_id); $start_date = $event->start; $end_date = $event->end; $eventcolor = $event->color; $language = get_bloginfo('language'); if (strpos($language, '-') > -1) { $language = strtolower(substr($language, 0, 2)); } $colors = $this->get_colors(); ?>

0): ?>

$file): ?>

retreive($post); ?>
load_map_scripts(); } /** * display custombox containing shortcode wizard */ public function inner_custom_box_edit() { $ep_settings = $this->settings; ?>

[event_list]
META_COLOR, FILTER_SANITIZE_STRING)) { update_post_meta($post_id, $this->META_COLOR, $color); } // Clean date or no date if ((false !== $start = filter_input(INPUT_POST, $this->META_START, FILTER_SANITIZE_STRING)) && (false !== $end = filter_input(INPUT_POST, $this->META_END, FILTER_SANITIZE_STRING)) && '' != $start && '' != $end) { update_post_meta($post_id, $this->META_START, substr($start,0,16).':00'); update_post_meta($post_id, $this->META_END, substr($end,0,16).':00'); } else { delete_post_meta($post_id, $this->META_START); delete_post_meta($post_id, $this->META_END); } // Clean location or no location if ((false !== $lat = filter_input(INPUT_POST, $this->META_LAT, FILTER_SANITIZE_STRING)) && (false !== $long = filter_input(INPUT_POST, $this->META_LONG, FILTER_SANITIZE_STRING)) && '' != $lat && '' != $long) { update_post_meta($post_id, $this->META_ADD, filter_input(INPUT_POST, $this->META_ADD, FILTER_SANITIZE_STRING)); update_post_meta($post_id, $this->META_LAT, $lat); update_post_meta($post_id, $this->META_LONG, $long); } else { delete_post_meta($post_id, $this->META_ADD); delete_post_meta($post_id, $this->META_LAT); delete_post_meta($post_id, $this->META_LONG); } } /** * * @param string $date * @param string $cat * @param boolean $display * @return boolean */ public function display_caldate($date, $cat = '', $display = false, $colored=true, $thumbnail='') { $events = $this->get_events(array('nb' => -1, 'date' => $date, 'cat' => $cat, 'retreive' => true)); $nb = count($events); if ($display) { if ($nb > 0) { $ret.=''; return $ret; } return''; } else { return $nb > 0 ? '' : date('j', $date); } } /** * @param array $atts * @filter eventpost_params * @return string */ public function calendar($atts) { extract(shortcode_atts(apply_filters('eventpost_params', array( 'date' => date('Y-n'), 'cat' => '', 'mondayfirst' => 0, //1 : weeks starts on monday 'datepicker' => 1, 'colored' => 1, 'thumbnail'=>'', ), 'calendar'), $atts)); $annee = substr($date, 0, 4); $mois = substr($date, 5); $time = mktime(0, 0, 0, $mois, 1, $annee); $prev_year = strtotime('-1 Year', $time); $next_year = strtotime('+1 Year', $time); $prev_month = strtotime('-1 Month', $time); $next_month = strtotime('+1 Month', $time); $JourMax = date("t", $time); $NoJour = -date("w", $time); if ($mondayfirst == 0) { $NoJour +=1; } else { $NoJour +=2; $this->Week[] = array_shift($this->Week); } if ($NoJour > 0 && $mondayfirst == 1) { $NoJour -=7; } $ret = '' . ''; $ret.=''; for ($w = 0; $w < 7; $w++) { $ret.=''; } $ret.=''; $ret.=''; $ret.=''; $sqldate = date('Y-m', $time); $cejour = date('Y-m-d'); for ($semaine = 0; $semaine <= 5; $semaine++) { // 6 semaines par mois $ret.=''; for ($journee = 0; $journee <= 6; $journee++) { // 7 jours par semaine if ($NoJour > 0 && $NoJour <= $JourMax) { // si le jour est valide a afficher $td = ''; } else { $ret.=''; } $NoJour ++; } $ret.=''; } $ret.='
' . __('A calendar of events', 'event-post') . '
'; if ($datepicker == 1) { $ret.='
'; $ret.=' '; $ret.=$annee; $ret.=' '; $ret.=' '; $ret.=$this->NomDuMois[$mois]; $ret.=' '; $ret.=''; $ret.='
'; } $ret.='
' . strtoupper(substr($this->Week[$w], 0, 1)) . '
'; if ($sqldate . '-' . ($NoJour<10?'0':'').$NoJour == $cejour) { $td = ''; } $ret.=$td; $ret.= $this->display_caldate(mktime(0, 0, 0, $mois, $NoJour, $annee), $cat, false, $colored, $thumbnail); $ret.='
'; return $ret; } /** * echoes the content of the calendar in ajax context */ public function ajaxcal() { echo $this->calendar(array( 'date' => esc_attr(FILTER_INPUT(INPUT_GET, 'date')), 'cat' => esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), 'mondayfirst' => esc_attr(FILTER_INPUT(INPUT_GET, 'mf')), 'datepicker' => esc_attr(FILTER_INPUT(INPUT_GET, 'dp')), 'colored' => esc_attr(FILTER_INPUT(INPUT_GET, 'color')), 'thumbnail' => esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail')), )); exit(); } /** * echoes the date of the calendar in ajax context */ public function ajaxdate() { echo $this->display_caldate(strtotime(esc_attr(FILTER_INPUT(INPUT_GET, 'date'))), esc_attr(FILTER_INPUT(INPUT_GET, 'cat')), true, esc_attr(FILTER_INPUT(INPUT_GET, 'color')), esc_attr(FILTER_INPUT(INPUT_GET, 'thumbnail'))); exit(); } /** * echoes a date in ajax context */ public function HumanDate() { if (isset($_REQUEST['date']) && !empty($_REQUEST['date'])) { $date = strtotime($_REQUEST['date']); echo $this->human_date($date, $this->settings['dateformat']).(date('H:i', $date)=='00:00' ? '' : ' '. date($this->settings['timeformat'], $date)); exit(); } } /** * AJAX Get lat long from address */ public function GetLatLong() { if (isset($_REQUEST['q']) && !empty($_REQUEST['q'])) { // verifier le cache $q = $_REQUEST['q']; header('Content-Type: application/json'); $transient_name = 'eventpost_osquery_' . $q; $val = get_transient($transient_name); if (false === $val || empty($val)) { $language = get_bloginfo('language'); if (strpos($language, '-') > -1) { $language = strtolower(substr($language, 0, 2)); } $val = file_get_contents('http://nominatim.openstreetmap.org/search?q=' . urlencode($q) . '&format=json&accept-language=' . $language); set_transient($transient_name, $val, 30 * DAY_IN_SECONDS); } echo $val; exit(); } } /** * alters columns * @param array $defaults * @return array * @filter eventpost_columns_head */ public function columns_head($defaults) { $defaults['event'] = __('Event', 'event-post'); $defaults['location'] = __('Location', 'event-post'); return apply_filters('eventpost_columns_head', $defaults); } /** * echoes content of a row in a given column * @param string $column_name * @param int $post_id * @action eventpost_columns_content */ public function columns_content($column_name, $post_id) { if ($column_name == 'location') { $lat = get_post_meta($post_id, $this->META_LAT, true); $lon = get_post_meta($post_id, $this->META_LONG, true); if (!empty($lat) && !empty($lon)) { add_thickbox(); $color = get_post_meta($post_id, $this->META_COLOR, true); if ($color == ''){ $color = '777777'; } echo '' . '' . ''.__('View on a map', 'event-post').'' . get_post_meta($post_id, $this->META_ADD, true) . ' '; } } if ($column_name == 'event') { echo $this->print_date($post_id, false); } do_action('eventpost_columns_content', $column_name, $post_id); } /** ADMIN PAGES **/ /** * save settings end redirect * @return void */ public function save_settings(){ if (!current_user_can('manage_options')){ return; } if (!wp_verify_nonce(\filter_input(INPUT_POST,'ep_nonce_settings',FILTER_SANITIZE_STRING), 'ep_nonce_settings')) { wp_die(__('Security error', 'event-post')); } $valid_post = array( 'ep_settings'=>array( 'filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY ) ); foreach ($this->settings as $item_name=>$item_value){ $valid_post['ep_settings'][$item_name] = FILTER_SANITIZE_STRING; } $post_types=(array) $_POST['ep_settings']['posttypes']; $posttypes = get_post_types(); foreach($post_types as $posttype){ if(!in_array($posttype, $posttypes)){ unset($post_types[$posttype]); } } if (false !== $settings = \filter_input_array(INPUT_POST,$valid_post)) { $settings['ep_settings']['container_shema']=stripslashes($_POST['ep_settings']['container_shema']); $settings['ep_settings']['item_shema']= stripslashes($_POST['ep_settings']['item_shema']); $settings['ep_settings']['posttypes']= array_values($post_types); update_option('ep_settings', $settings['ep_settings']); } wp_redirect('options-general.php?page=event-settings&confirm=options_saved'); exit; } /** * adds menu items */ public function manage_options() { add_options_page(__('Events settings', 'event-post'), __('Events', 'event-post'), 'manage_options', 'event-settings', array(&$this, 'manage_settings')); } /** * adds items to the native "right now" dashboard widget * @param array $elements * @return array */ public function dashboard_right_now($elements){ $nb_date = count($this->get_events(array('future'=>1, 'past'=>1, 'nb'=>-1))); $nb_geo = count($this->get_events(array('future'=>1, 'past'=>1, 'geo'=>1, 'nb'=>-1))); if($nb_date){ array_push($elements, ' '.sprintf(__('%d Events','event-post'), $nb_date).""); } if($nb_geo){ array_push($elements, ' '.sprintf(__('%d Geolocalized events','event-post'), $nb_geo).""); } return $elements; } /** * output content of the setting page */ public function manage_settings() { if ('options_saved'===\filter_input(INPUT_GET,'confirm',FILTER_SANITIZE_STRING)) { ?>

settings; ?>

default_list_shema['container']) ?>

default_list_shema['item']) ?>


$posttype): ?>

human_date(current_time('timestamp')) .' '. date($this->settings['timeformat'], current_time('timestamp')); ?>

get_events(array('cat'=>$cat,'nb'=>-1)); foreach ($events as $event) { echo"BEGIN:VEVENT\r\n" . "CREATED:".$this->ics_date(strtotime($event->post_date))."\r\n" . "LAST-MODIFIED:".$this->ics_date(strtotime($event->post_modified))."\r\n" . "SUMMARY:".$event->post_title."\r\n" . "UID:".md5(site_url()."_eventpost_".$event->ID)."\r\n" . "LOCATION:".str_replace(',','\,',$event->address)."\r\n" . "DTSTART;TZID=$timezone_string:".$this->ics_date($event->time_start)."\r\n" . "DTEND;TZID=$timezone_string:".$this->ics_date($event->time_end)."\r\n" . "DESCRIPTION:".$event->guid."\r\n" . "END:VEVENT\r\n"; } echo"END:VCALENDAR\r\n"; exit; } } }