Plugin Directory

Changeset 524346


Ignore:
Timestamp:
03/27/2012 04:55:57 PM (14 years ago)
Author:
markpdxt
Message:

1.0.2

Location:
sync-facebook-events/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sync-facebook-events/trunk/readme.txt

    r464504 r524346  
    55Requires at least: 3.0
    66Tested up to: 3.0
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88
    99Sync Facebook Events to The Events Calendar Plugin by Modern Tribe.
     
    21215. Ensure The Events Calendar plugin is installed and configured - http://wordpress.org/extend/plugins/the-events-calendar/
    22225. Press 'Update' to synchronize your current Facebook events for display within The Events Calendar.
     236. Synchronization will continue to occur once a day automatically. You can always update manually if/when needed.
    2324
    2425== Frequently Asked Questions ==
     
    5758== Changelog ==
    5859
     60= 1.0.2 =
     61* Aautomatic daily event sync
     62* Adjust event timezone to WordPress
     63
    5964= 1.0.1 =
    6065* Improved update display
  • sync-facebook-events/trunk/sync-facebook-events.php

    r506054 r524346  
    55Description: Sync Facebook Events to The Events Calendar Plugin
    66Author: Mark Nelson
    7 Version: 1.0.1
     7Version: 1.0.2
    88Author URI: http://pdxt.com
    99*/
    10  
    1110
    12 /*  Copyright 2011 PDX Technologies, LLC. (mark.nelson@pdxt.com)
     11/*  Copyright 2012 PDX Technologies, LLC. (mark.nelson@pdxt.com)
    1312
    1413    This program is free software; you can redistribute it and/or modify
     
    2726*/
    2827
    29 function fbes_init(){
     28register_activation_hook(__FILE__,'activate_fbes');
     29register_deactivation_hook(__FILE__,'deactivate_fbes');
     30function activate_fbes() { wp_schedule_event(time(), 'hourly', 'fbes_execute_sync'); }
     31function deactivate_fbes() { wp_clear_scheduled_hook('fbes_execute_sync'); }
     32add_action('fbes_execute_sync', 'fbes_process_events');
     33
     34function fbes_add_page() { add_options_page('Sync FB Events', 'Sync FB Events', 8, __FILE__, 'fbes_options_page'); }
     35add_action('admin_menu', 'fbes_add_page');
     36
     37function fbes_process_events() {
     38
     39    $to = "notify@pdxt.com";
     40    $subject = "fb sybc cron";
     41    $message = "the event has run";
     42   
     43    wp_mail($to, $subject, $message);
     44
     45    #Get option values
     46    $fbes_api_key = get_option('fbes_api_key');
     47    $fbes_api_secret = get_option('fbes_api_secret');
     48    $fbes_api_uid = get_option('fbes_api_uid');
     49
     50    $events = fbes_get_events($fbes_api_key, $fbes_api_secret, $fbes_api_uid);
     51    fbes_send_events($events);
    3052}
    3153
    32 add_action("plugins_loaded", "fbes_init");
    33 
    34 function fbes_add_page() {
    35     add_options_page('Sync FB Events', 'Sync FB Events', 8, __FILE__, 'fbes_options_page');
    36 }
    37 add_action('admin_menu', 'fbes_add_page');
    38 
    3954function fbes_get_events($fbes_api_key, $fbes_api_secret, $fbes_api_uid) {
    40    
     55       
    4156    require 'facebook.php';
    4257   
     
    5671        'callback'  => ''
    5772    );
    58 
     73   
    5974    $ret = $facebook->api($param);
    6075    return $ret;
     76}
     77
     78function fbes_send_events($events) {
     79
     80    $i=0;
     81    $query = new WP_Query( 'post_type=tribe_events&showposts=99999' );
     82    foreach($query->posts as $post) {
     83        foreach($post as $key=>$value) {
     84            if($key=="to_ping") {
     85                $eids[$value] = $post->ID;
     86            }
     87        }
     88    }
     89    wp_reset_query();
     90   
     91    $i=0;
     92    foreach($events as $event) {
     93       
     94        $args['post_title'] = $event['name'];
     95       
     96        $offset = get_option('gmt_offset')*3600;
     97       
     98        $offsetStart = $event['start_time']+$offset;
     99        $offsetEnd = $event['end_time']+$offset;
     100               
     101        $args['EventStartDate'] = date("m/d/Y", $offsetStart);
     102        $args['EventStartHour'] = date("H", $offsetStart);
     103        $args['EventStartMinute'] = date("i", $offsetStart);
     104       
     105        $args['EventEndDate'] = date("m/d/Y", $offsetEnd);
     106        $args['EventEndHour'] = date("H", $offsetEnd);
     107        $args['EventEndMinute'] = date("i", $offsetEnd);
     108
     109        $args['post_content'] = $event['description'];
     110        $args['Venue']['Venue'] = $event['location'];
     111       
     112        $args['post_status'] = "Publish";
     113        $args['to_ping'] = $event['eid'];
     114   
     115        if (array_key_exists($event['eid'], $eids)) {
     116            tribe_update_event($eids[$event['eid']],$args);
     117            $action = "Updating:".$eids[$event['eid']];
     118        } else {
     119            $post_id = tribe_create_event($args);
     120            $action = "Inserting:".$post_id;
     121        }
     122        reset($eids);
     123       
     124        print $action." ";
     125    }   
    61126}
    62127
     
    107172    <div style="margin-top:20px;font-size:14px;color:#444;border:1px solid #999;padding:15px;width:95%;font-face:couriernew;">
    108173    <span style="color:red;">Updaing all facebook events...</span><br />
    109     <?
    110         $i=0;
    111         $query = new WP_Query( 'post_type=tribe_events&showposts=99999' );
    112         foreach($query->posts as $post) {
    113             foreach($post as $key=>$value) {
    114                 if($key=="to_ping") {
    115                     $eids[$value] = $post->ID;
    116                 }
    117             }
    118         }
    119         wp_reset_query();
    120        
    121         $i=0;
    122         foreach($events as $event) {
    123            
    124             $args['post_title'] = $event['name'];
    125            
    126             //$args['EventStartDate'] = date("Y-m-d H:i", $event['start_time']);
    127            
    128             $args['EventStartDate'] = date("m/d/Y", $event['start_time']);
    129             $args['EventStartHour'] = date("H", $event['start_time']);
    130             $args['EventStartMinute'] = date("i", $event['start_time']);
    131            
    132             $args['EventEndDate'] = date("m/d/Y", $event['end_time']);
    133             $args['EventEndHour'] = date("H", $event['end_time']);
    134             $args['EventEndMinute'] = date("i", $event['end_time']);
    135 
    136             $args['post_content'] = $event['description'];
    137             $args['Venue']['Venue'] = $event['location'];
    138            
    139             $args['post_status'] = "Publish";
    140             $args['to_ping'] = $event['eid'];
    141        
    142             if (array_key_exists($event['eid'], $eids)) {
    143                 tribe_update_event($args);
    144                 $action = "Updating:".$eids[$event['eid']];
    145             } else {
    146                 $post_id = tribe_create_event($args);
    147                 $action = "Inserting:".$post_id;
    148             }
    149             reset($eids);
    150            
    151             print $action." ";
    152         }
    153         fclose($fp);
    154     ?><br />
     174    <?php fbes_send_events($events); ?><br />
    155175    <span style="color:red;">Events Calendar updated with current Facebook events.</span><br /><br />
    156176    </div>
Note: See TracChangeset for help on using the changeset viewer.