Plugin Directory

Changeset 1031812


Ignore:
Timestamp:
11/24/2014 02:11:42 PM (11 years ago)
Author:
O-Zone
Message:

Remove Facebook support, some bugs fixed and minor code improvements

Location:
wp-meetup-activity/trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • wp-meetup-activity/trunk/default.css

    r668363 r1031812  
    1 .wpmeetupactivity-icon {
    2     vertical-align: middle;
    3     border: 0px;
    4     padding: 2px;
    5 }
    6 
    71.wpmeetupactivity-setup-fieldset {
    82    border:1px solid #aaa;
     
    1812    background: #aaa;
    1913    color: #fff;
     14}
     15
     16.wpmeetupactivity-widget-list {
     17    list-style-type: none;
     18    padding: 0px;
     19    margin: 0px;
     20}
     21
     22.wpmeetupactivity-widget-list li { 
     23    border-bottom: 1px solid #ccc;
     24}
     25
     26.wpmeetupactivity-widget-list li p { 
     27    padding-left: 5px;
     28}
     29
     30.wpmeetupactivity-widget-list li img { 
     31    float: left; 
     32    margin: 0 5px 0 0;
     33    padding: 2px;
    2034}
    2135
  • wp-meetup-activity/trunk/meetup_api/Meetup.php

    r583907 r1031812  
    3636define('MEETUP_ENDPOINT_VENUES', '/2/venues');
    3737
    38 // Setup includes - this should be an autoloader soon
    39 require_once('MeetupConnection.class.php');
    40 require_once('MeetupApiResponse.class.php');
    41 require_once('MeetupApiRequest.class.php');
    42 require_once('MeetupExceptions.class.php');
    43 
    44 require_once('MeetupCheckins.class.php');
    45 require_once('MeetupEvents.class.php');
    46 require_once('MeetupFeeds.class.php');
    47 require_once('MeetupGroups.class.php');
    48 require_once('MeetupMembers.class.php');
    49 require_once('MeetupPhotos.class.php');
    50 require_once('MeetupRsvps.class.php');
    51 require_once('MeetupTopics.class.php');
    52 require_once('MeetupVenues.class.php');
    53 require_once("MeetupOAuth2Helper.class.php");
     38include_once('MeetupApiRequest.class.php');
     39include_once('MeetupApiResponse.class.php');
     40include_once('MeetupExceptions.class.php');
     41include_once('MeetupCheckins.class.php');
     42include_once('MeetupConnection.class.php');
     43include_once('MeetupEvents.class.php');
     44include_once('MeetupFeeds.class.php');
     45include_once('MeetupGroups.class.php');
     46include_once('MeetupExceptions.class.php');
     47include_once('MeetupExceptions.class.php');
     48include_once('MeetupConnection.class.php');
     49include_once('MeetupMembers.class.php');
     50include_once('MeetupConnection.class.php');
     51include_once('MeetupOAuth2Helper.class.php');
     52include_once('MeetupPhotos.class.php');
     53include_once('MeetupRsvps.class.php');
     54include_once('MeetupTopics.class.php');
     55include_once('MeetupExceptions.class.php');
     56include_once('MeetupVenues.class.php');
  • wp-meetup-activity/trunk/meetup_api/MeetupConnection.class.php

    r583907 r1031812  
    2020        // Clear error status
    2121        $ret = false;
    22        
     22
    2323        $options = array(
    2424            CURLOPT_RETURNTRANSFER => true,     // return web page
     
    2929            CURLOPT_HEADER => 0
    3030        );
    31         //echo $Url;
     31
    3232        $ch = curl_init( $Url );
    3333        curl_setopt_array( $ch, $options );
     
    4040        $response->setHttpCode($header['http_code']);
    4141        $response->setResponse($header['content']);
    42        
     42
    4343
    4444
     
    8585     * NOTE: The Meetup API contains a list of parameters that are required for
    8686     * each endpoint with a default condition of "any of"
    87      * 
     87     *
    8888     * @param Array $RequiredList - Names of required parameters
    8989     * @param Array $Parameters - List of provided paramters
     
    112112    /*
    113113    * Initializes a connection to the Meetup API using API keys
    114     * 
     114    *
    115115    * @param String $key - A users's Meetup api key
    116116    */
     
    121121    /**
    122122     * Adds additional query parameters for key authentication
    123      * 
     123     *
    124124     * @param Array $params - request parameters
    125125     * @return Array modified request parameters
     
    137137    /*
    138138    * Initializes a connection to the Meetup API using oAuth 2
    139     * 
     139    *
    140140    * @param String $access_token - A valid access token received from a Meetup access token request
    141141    */
    142142    public function __construct($access_token) {
    143143    $this->_access_token = $access_token;
    144     }   
     144    }
    145145
    146146    /**
    147147     * Adds additional query parameters for key authentication
    148      * 
     148     *
    149149     * @param Array $params - request parameters
    150150     * @return Array modified request parameters
  • wp-meetup-activity/trunk/meetup_api/MeetupFeeds.class.php

    r583907 r1031812  
    1818    public function getActivity( $Parameters = array() ) {
    1919        $url = $this->buildUrl( MEETUP_ENDPOINT_FEED_ACTIVITY, $Parameters );
    20         // echo $url;
    2120        $response =  $this->get( $url )->getResponse();
    2221        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupGroups.class.php

    r583907 r1031812  
    2222        $required_params = array( 'campaign_id', 'domain', 'group_id', 'group_urlname', 'member_id', 'organizer_id', 'sponsor_id');
    2323        $url = $this->buildUrl( MEETUP_ENDPOINT_GROUPS, $Parameters, $required_params );
    24         echo $url;
    2524        $response =  $this->get( $url )->getResponse();
    2625        return $response['results'];
     
    4039        $required_params = array( 'group_id', 'group_urlname', 'topic,groupnum');
    4140        $url = $this->buildUrl( MEETUP_ENDPOINT_GROUP_COMMENTS, $Parameters, $required_params );
    42         echo $url;
    4341        $response =  $this->get( $url )->getResponse();
    4442        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupMembers.class.php

    r583907 r1031812  
    2121        $required_params = array( 'group_id', 'group_urlname', 'member_id', 'service', 'topic,groupnum');
    2222        $url = $this->buildUrl( MEETUP_ENDPOINT_MEMBERS, $Parameters, $required_params );
    23        // echo $url;
    2423        $response =  $this->get( $url )->getResponse();
    2524        return $response['results'];
     
    3635    public function getMember( $MemberId, $Parameters = array() ) {
    3736        $url = $this->buildUrl( MEETUP_ENDPOINT_MEMBER . "/$MemberId", $Parameters );
    38       //  echo $url;
    3937        $response =  $this->get( $url )->getResponse();
    4038        return $response;
     
    5553        $required_params = array( 'group_id', 'group_urlname', 'topic,groupnum');
    5654        $url = $this->buildUrl( MEETUP_ENDPOINT_PROFILES, $Parameters, $required_params );
    57        // echo $url;
    5855        $response =  $this->get( $url )->getResponse();
    5956        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupPhotos.class.php

    r583907 r1031812  
    2121        $required_params = array( 'photo_id');
    2222        $url = $this->buildUrl( MEETUP_ENDPOINT_PHOTO_COMMENTS, $Parameters, $required_params );
    23         echo $url;
    2423        $response =  $this->get( $url )->getResponse();
    2524        return $response;
     
    3938        $required_params = array( 'event_id', 'group_id', 'photo_album_id');
    4039        $url = $this->buildUrl( MEETUP_ENDPOINT_PHOTO_ALBUMS, $Parameters, $required_params );
    41         echo $url;
    4240        $response =  $this->get( $url )->getResponse();
    4341        return $response['results'];
     
    5755        $required_params = array( 'event_id', 'group_id', 'photo_album_id', 'member_id', 'photo_id', 'tagged');
    5856        $url = $this->buildUrl( MEETUP_ENDPOINT_PHOTOS, $Parameters, $required_params );
    59         echo $url;
    6057        $response =  $this->get( $url )->getResponse();
    6158        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupRsvps.class.php

    r583907 r1031812  
    2222        $required_params = array( 'event_id');
    2323        $url = $this->buildUrl( MEETUP_ENDPOINT_RSVPS, $Parameters, $required_params );
    24         echo $url;
    2524        $response =  $this->get( $url )->getResponse();
    2625        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupTopics.class.php

    r583907 r1031812  
    1818    public function getTopics( $Parameters ) {
    1919        $url = $this->buildUrl( MEETUP_ENDPOINT_TOPICS, $Parameters );
    20         echo $url;
    2120        $response =  $this->get( $url )->getResponse();
    2221        return $response['results'];
  • wp-meetup-activity/trunk/meetup_api/MeetupVenues.class.php

    r583907 r1031812  
    2424        $required_params = array ( 'city', 'country', 'lat', 'lon', 'state', 'text', 'zip' );
    2525        $url = $this->buildUrl( MEETUP_ENDPOINT_OPEN_VENUES, $Parameters, $required_params );
    26         echo $url;
    2726        $response =  $this->get( $url )->getResponse();
    2827        return $response['results'];
     
    3231     * Search for Meetup venues by one of your groups, events, or venue
    3332     * identifiers. For a full text search on public venues use getOpenVenues
    34      * 
     33     *
    3534     * @link http://www.meetup.com/meetup_api/docs/2/venues/
    3635     * @param <type> $Parameters
     
    4039        $required_params = array ( 'event_id', 'group_id', 'group_urlname', 'venue_id' );
    4140        $url = $this->buildUrl( MEETUP_ENDPOINT_VENUES, $Parameters, $required_params );
    42         echo $url;
    4341        $response =  $this->get( $url )->getResponse();
    4442        return $response['results'];
  • wp-meetup-activity/trunk/readme.txt

    r676447 r1031812  
    4040== Changelog ==
    4141
     42= 0.1.7 =
     43*
     44
     45= 0.1.6 =
     46* Fixed PHP warnings on wpdb->prepare
     47
    4248= 0.1.5 =
    4349* Fixed a bug with scheduled events (wp-cron)
  • wp-meetup-activity/trunk/wp-meetup-activity.php

    r676447 r1031812  
    44Plugin URI: http://www.zerozone.it/wordpress-meetup-plugin/
    55Description: Display group activity and events from Meetup.com in a widget for your wordpress
    6 Version: 0.1.5
     6Version: 0.1.7
    77Author: Michele "O-Zone" Pinassi
    88Author URI: http://www.zerozone.it/
    99
    10 Copyright 2012-2013  Michele "O-Zone" Pinassi
     10Copyright 2012-2014  Michele "O-Zone" Pinassi
    1111
    1212    This program is free software; you can redistribute it and/or modify
     
    2525
    2626/* Meetup API */
    27 include(dirname(__FILE__).DIRECTORY_SEPARATOR."meetup_api/Meetup.php");
    28 
    29 /* Facebook PHP SDK */
    30 if(!class_exists( 'Facebook_WP' )) {
    31     require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'facebook-sdk/class-facebook-wp.php');
    32 }
     27include(dirname(__FILE__).DIRECTORY_SEPARATOR.'meetup_api/Meetup.php');
     28
     29include('wp-meetup-activity-widgets.php');
    3330
    3431add_option('wpmeetupactivity_apikey', '', '', 'yes');
    3532add_option('wpmeetupactivity_events_desc', 'at %ADDRESS%. There are already %RSVP_YES% booked friends !', '', 'yes');
    3633add_action('admin_menu', 'wpmeetupactivity_plugin_menu');
    37 add_action('plugins_loaded', 'wpmeetupactivity_widget_init');
    3834add_action('init', 'wpmeetupactivity_register_styles');
    39 add_action('init', 'wpmeetupactivity_fb_init');
     35
     36add_action( 'widgets_init', create_function( '', "register_widget('Meetup_Activity_Widget');" ) );
     37add_action( 'widgets_init', create_function( '', "register_widget('Meetup_Events_Widget');" ) );
    4038
    4139register_activation_hook(__FILE__,'wpmeetupactivity_activate');
     
    4442
    4543global $wpdb;
    46 
    47 define(WP_MEETUP_ACTIVITY,'0.1.5');
     44global $current_site;
     45
     46define(WP_MEETUP_ACTIVITY,'0.1.7');
    4847define(WP_MEETUP_ACTIVITY_TABLE, $wpdb->prefix."meetup_activity");
     48define(WP_MEETUP_ACTIVITY_CRON_HOOK, "wpmeetupactivity_".$current_site->id);
     49define(WP_MEETUP_ACTIVITY_OLDERDAYS,7); /* Days for argument degree */
    4950
    5051/*
     
    5455*/
    5556
    56 add_action('wpmeetupactivity_hourly', 'wpmeetupactivity_plugin_cron_hourly');
     57add_action("wpmeetupactivity_".$current_site->id."_hourly", "wpmeetupactivity_plugin_cron_hourly");
    5758
    5859function wpmeetupactivity_plugin_cron_hourly() {
     
    6162}
    6263
     64function wpmeetupactivity_install_cron() {
     65    global $current_site;
     66    if(!wp_next_scheduled(WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly')) {
     67    wp_schedule_event( current_time( 'timestamp' ), 'hourly', WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     68    echo "<div class=\"updated\"><p><strong>";
     69    echo __('CRON Hourly updates scheduled !', $wpmeetupactivity_textdomain);
     70    echo "</strong></p></div>";
     71    }
     72}
     73
     74function wpmeetupactivity_uninstall_cron() {
     75
     76    wp_clear_scheduled_hook(WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     77
     78/*    $timestamp = wp_next_scheduled(WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     79    while($timestamp) {
     80    wp_unschedule_event($timestamp, 'hourly', WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     81    $timestamp = wp_next_scheduled(WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     82    }
     83
     84    wp_clear_scheduled_hook( WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly' );
     85*/
     86    echo "<div class=\"updated\"><p><strong>";
     87    echo __('CRON Hourly updates cleared !', $wpmeetupactivity_textdomain);
     88    echo "</strong></p></div>";
     89}
     90
    6391/*
    6492
     
    6795*/
    6896function wpmeetupactivity_activate() {
    69     if(!wp_next_scheduled('wpmeetupactivity_hourly')) {
    70     wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'wpmeetupactivity_hourly');
    71     }
     97    wpmeetupactivity_install_cron();
     98    wpmeetupactivity_update_db_check();
    7299}
    73100
     
    113140    group_name text NOT NULL,
    114141    add_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     142    last_update datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    115143    UNIQUE KEY group_id (group_id)
    116144    ) DEFAULT CHARSET = utf8;";
     
    123151    echo __('Updated DB to '.WP_MEETUP_ACTIVITY, $wpmeetupactivity_textdomain);
    124152    echo "</strong></p></div>";
    125 
    126     wpmeetupactivity_activate();
    127153    }
    128154}
    129155
    130156function wpmeetupactivity_deactivate() {
    131     global $wpdb;
    132     $timestamp = wp_next_scheduled('wpmeetupactivity_hourly');
    133     wp_unschedule_event($timestamp, 'hourly', 'wpmeetupactivity_hourly');
     157    wpmeetupactivity_uninstall_cron();
    134158}
    135159
     
    139163    $wpdb->query($wpdb->prepare("DROP ".WP_MEETUP_ACTIVITY_TABLE."_groups; DROP ".WP_MEETUP_ACTIVITY_TABLE."_act;"));
    140164    /* Disable CRON */
    141     $timestamp = wp_next_scheduled('wpmeetupactivity_hourly');
    142    
    143     while($timestamp) {
    144     wp_unschedule_event($timestamp, 'hourly', 'wpmeetupactivity_hourly');
    145     $timestamp = wp_next_scheduled('wpmeetupactivity_hourly');
    146     }
    147 
    148    
    149     wp_clear_scheduled_hook( 'wpmeetupactivity_hourly' );
    150    
     165    wpmeetupactivity_uninstall_cron();
    151166}
    152167
     
    197212    $apikey = get_option('wpmeetupactivity_apikey');
    198213
    199     $fb_options = get_option('wpmeetupactivity_fb_options');
    200     $fb_pages = $fb_options['pages'];
    201 
    202214    $groupsArray = get_option('wpmeetupactivity_groups');
    203215
     
    212224
    213225        foreach($activities as $act) {
    214             /*
    215             [group_name] => Siena 5 Stelle
    216             [discussion_body] => Tommaso bisogna stare attenti, siamo la citt del Palio, potrebbero esser mosse critiche in tal senso, no vivisezione si morte cavalli c' un conflitto in ci. Di cui persino io mi rendo conto pur essendo Palio convinta. S.
    217             [photo_url] => http://photos4.meetupstatic.com/photos/member/a/a/9/8/thumb_58003672.jpeg
    218             [link] => http://www.meetup.com/Gruppo-di-Siena/messages/boards/thread/25811602/post/80398742#80398742
    219             [group_id] => 209457
    220             [message_id] => 80398742
    221             [discussion_title] => La Novartis, negli stabilimenti di Siena, pratica la vivisezione ?
    222             [member_id] => 46604112 [id] => ch209457-ts9223370692436524023-disc-25811602
    223             [title] => Siena 5 Stelle: Risposta ad una Discussione
    224             [updated] => Wed Aug 08 05:30:51 EDT 2012
    225             [member_name] => Silvia
    226             [published] => Wed Aug 08 05:30:51 EDT 2012
    227             [thread_id] => 25811602
    228             [item_type] => new_reply
    229             [is_reply] => True
    230             */
    231226            if(in_array($act["group_id"],$groupsArray)) {
    232227            /* get activities only from subscribed groups */
     
    252247                   
    253248                    $wpdb->query($wpdb->prepare("UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_act SET message_id=%d,author=%s,ranking=%f,item_type=%s,chg_date=NOW() WHERE group_id=$groupId AND thread_id=$threadId;",$messageId,$act['member_name'],$ranking,$act['item_type']));
    254                
    255                     if($fb_options['post_on_reply']) {
    256                     /* Post replies to FB pages, if configured */
    257                     wpmeetupactivity_fb_posttopage($act['link'],$act['discussion_body']);
    258                     }
    259                    
     249                                   
    260250                    if(is_admin()) {
    261251                    echo "<div class=\"updated\"><p><strong>".__('Updated thread '.$act['discussion_title'], $wpmeetupactivity_textdomain)."</strong></p></div>";
     
    266256                $wpdb->query($wpdb->prepare("INSERT INTO ".WP_MEETUP_ACTIVITY_TABLE."_act (group_id, thread_id, message_id, author, item_type, item_title, item_url, ranking, chg_date, add_date) VALUES ( %d, %d, %d, %s, %s, %s, %s, 1, NOW(), NOW())", $groupId, $threadId, $messageId, $act['member_name'], $act['item_type'], $act['discussion_title'], $act['link']));
    267257
    268                 if($fb_options['post_on_new']) {
    269                     /* Post new threads to FB pages, if configured */
    270                     wpmeetupactivity_fb_posttopage($act['link'],$act['discussion_body']);
    271                 }
    272 
    273258                if(is_admin()) {
    274259                    echo "<div class=\"updated\"><p><strong>".__('Added new thread '.$act['discussion_title'], $wpmeetupactivity_textdomain)."</strong></p></div>";
     
    276261                }
    277262            }
     263            // Update LAST_UPDATE
    278264            }
     265                $wpdb->query($wpdb->prepare("UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_groups SET last_update=NOW() WHERE group_id='%d';",$act["group_id"]));
    279266        }
    280267        // Degrade ranking for older items
    281         $wpdb->query($wpdb->prepare("UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_act SET ranking=ranking-0.1 WHERE DATEDIFF(NOW(),chg_date) > 7;"));
     268        $wpdb->query($wpdb->prepare("UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_act SET ranking=ranking-0.1 WHERE DATEDIFF(NOW(),chg_date) > %d;",WP_MEETUP_ACTIVITY_OLDERDAYS));
    282269        }  catch (Exception $e) {
    283270        echo "Meetup API error: $e";
     
    291278
    292279    $apikey = get_option('wpmeetupactivity_apikey');
    293 
    294     $fb_options = get_option('wpmeetupactivity_fb_options');
    295     $fb_pages = $fb_options['pages'];
    296280
    297281    $groupsArray = get_option('wpmeetupactivity_groups');
     
    306290
    307291            foreach($events as $event) {
    308             /* Array ( [visibility] => public
    309                 [status] => upcoming
    310                 [maybe_rsvp_count] => 0
    311                 [venue] => Array (
    312                 [id] => 11656882
    313                 [lon] => 11.35083
    314                 [repinned] =>
    315                 [name] => Circolo CRAL
    316                 [address_1] => via Algero Rosi 6
    317                 [lat] => 43.31786
    318                 [country] => it
    319                 [city] => Siena
    320                 )
    321                 [id] => 103939182
    322                 [utc_offset] => 3600000
    323                 [time] => 1360958400000
    324                 [waitlist_count] => 0
    325                 [created] => 1360515889000
    326                 [yes_rsvp_count] => 10
    327                 [updated] => 1360617331000
    328                 [event_url] => http://www.meetup.com/Gruppo-di-Siena/events/[id]/
    329                 [description] => descrizione evento....
    330                 [headcount] => 0
    331                 [name] => Incontro con l'economista Filippo Abbate
    332                 [group] => Array (
    333                 [id] => 209457
    334                 [group_lat] => 43.319999694824
    335                 [name] => Forum di Siena
    336                 [group_lon] => 11.329999923706
    337                 [join_mode] => open
    338                 [urlname] => Gruppo-di-Siena
    339                 [who] => Amici di Siena
    340                 )
    341             )  */
    342 
    343292            $eventId = $event['id'];
    344293           
    345             $eventUpdated = gmdate("Y-m-d H:i:s",intval($event['updated'])/1000);
     294            $eventUpdated = gmdate("Y-m-d H:i:s",($event['updated']/1000));
     295           
     296            $eventDate = gmdate("Y-m-d H:i:s",($event['time']/1000));
    346297           
    347298            $eventVenue = $event['venue']['name'].','.$event['venue']['city'];
     
    353304                // L'evento esiste gia
    354305                if($result['tDelta'] > 0) {
    355                 $result = $wpdb->query( $wpdb->prepare( "UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_events SET event_title='%s', event_address='%s', event_description='%s', event_datetime='%s',  event_updated='%s', event_status='%s', yes_rsvp=%d WHERE event_id=$eventId;", $event['name'],  $eventVenue,  $event['description'], gmdate("Y-m-d H:i:s",intval($event['time'])/1000), $eventUpdated, $event['status'], intval($event['yes_rsvp_count'])));
     306                $result = $wpdb->query( $wpdb->prepare( "UPDATE ".WP_MEETUP_ACTIVITY_TABLE."_events SET event_title='%s', event_address='%s', event_description='%s', event_datetime='%s',  event_updated='%s', event_status='%s', yes_rsvp=%d WHERE event_id=$eventId;", $event['name'],  $eventVenue,  $event['description'], $eventDate, $eventUpdated, $event['status'], intval($event['yes_rsvp_count'])));
    356307                if($verbose) {
    357308                    echo "<div class=\"updated\"><p><strong>";
     
    366317            } else {
    367318                // L'evento non esiste: aggiungilo al DB !
    368                 $result = $wpdb->query( $wpdb->prepare("INSERT INTO ".WP_MEETUP_ACTIVITY_TABLE."_events (group_id, event_id, event_title, event_address, event_description, event_datetime, event_updated, is_public, event_status, event_url, yes_rsvp, add_date) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', 1, '%s', '%s', %d, NOW())", $groupId, $eventId, $event['name'], $eventVenue, $event['description'], gmdate("Y-m-d H:i:s",intval($event['time'])/1000), $eventUpdated, $event['status'], $event['event_url'], intval($event['yes_rsvp_count'])));
     319                $result = $wpdb->query( $wpdb->prepare("INSERT INTO ".WP_MEETUP_ACTIVITY_TABLE."_events (group_id, event_id, event_title, event_address, event_description, event_datetime, event_updated, is_public, event_status, event_url, yes_rsvp, add_date) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', 1, '%s', '%s', %d, NOW())", $groupId, $eventId, $event['name'], $eventVenue, $event['description'], $eventDate, $eventUpdated, $event['status'], $event['event_url'], intval($event['yes_rsvp_count'])));
    369320                if($verbose) {
    370321                echo "<div class=\"updated\"><p><strong>";
     
    389340function wpmeetupactivity_plugin_menu() {
    390341    add_options_page('WP-Meetup-Activity Plugin Options', 'WP-Meetup-Activity', 8, __FILE__, 'wpmeetupactivity_plugin_options');
    391 }
    392 
    393 function wpmeetupactivity_widget_init() {
    394     if ( function_exists( 'wp_register_sidebar_widget' ) ) {
    395     wp_register_sidebar_widget('wpmeetupactivity','WP-Meetup-Activity', 'wpmeetupactivity_widget_activity',array('description' => 'Display latest activity on your Meetups'));
    396     wp_register_sidebar_widget('wpmeetupevents','WP-Meetup-Events', 'wpmeetupactivity_widget_events',array('description' => 'Display upcoming Meetups'));
    397     } else {
    398     // Deprecated function for older WP...
    399     register_sidebar_widget('WP-Meetup-Activity', 'wpmeetupactivity_widget_activity');
    400     register_sidebar_widget('WP-Meetup-Events', 'wpmeetupactivity_widget_events');
    401     }
    402342}
    403343
     
    466406        }
    467407    } else {
    468         echo "<b>No events planned yet !</b>";
     408        echo "<ul><li>No events planned in your groups</li></ul>";
    469409    }
    470410    } else {
     
    490430    $groupsArray = get_option('wpmeetupactivity_groups');
    491431    $my_prefs = get_option('wpmeetupactivity_prefs');
    492 
    493     $fb_options = get_option('wpmeetupactivity_fb_options');
    494     $fb_pages = $fb_options['pages'];
    495432   
    496433    $orderBy = $my_prefs['orderBy'];
     
    548485        echo "</ul>";
    549486    } else {
    550         echo "<b>No activities in selected groups</b>";
     487        echo "<ul><li>No activities in selected groups</li></ul>";
    551488    }
    552489    } else {
     
    568505}
    569506
    570 
    571 /*
    572 
    573 Facebook functions for auto-post of new threads on FB page
    574 
    575 */
    576 
    577 function wpmeetupactivity_fb_get_locale() {
    578     $fb_valid_fb_locales = array(
    579         'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_DE', 'eu_ES', 'en_PI', 'en_UD', 'ck_US', 'en_US', 'es_LA', 'es_CL', 'es_CO', 'es_ES', 'es_MX',
    580         'es_VE', 'fb_FI', 'fi_FI', 'fr_FR', 'gl_ES', 'hu_HU', 'it_IT', 'ja_JP', 'ko_KR', 'nb_NO', 'nn_NO', 'nl_NL', 'pl_PL', 'pt_BR', 'pt_PT',
    581         'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sv_SE', 'th_TH', 'tr_TR', 'ku_TR', 'zh_CN', 'zh_HK', 'zh_TW', 'fb_LT', 'af_ZA', 'sq_AL', 'hy_AM',
    582         'az_AZ', 'be_BY', 'bn_IN', 'bs_BA', 'bg_BG', 'hr_HR', 'nl_BE', 'en_GB', 'eo_EO', 'et_EE', 'fo_FO', 'fr_CA', 'ka_GE', 'el_GR', 'gu_IN',
    583         'hi_IN', 'is_IS', 'id_ID', 'ga_IE', 'jv_ID', 'kn_IN', 'kk_KZ', 'la_VA', 'lv_LV', 'li_NL', 'lt_LT', 'mk_MK', 'mg_MG', 'ms_MY', 'mt_MT',
    584         'mr_IN', 'mn_MN', 'ne_NP', 'pa_IN', 'rm_CH', 'sa_IN', 'sr_RS', 'so_SO', 'sw_KE', 'tl_PH', 'ta_IN', 'tt_RU', 'te_IN', 'ml_IN', 'uk_UA',
    585         'uz_UZ', 'vi_VN', 'xh_ZA', 'zu_ZA', 'km_KH', 'tg_TJ', 'ar_AR', 'he_IL', 'ur_PK', 'fa_IR', 'sy_SY', 'yi_DE', 'gn_PY', 'qu_PE', 'ay_BO',
    586         'se_NO', 'ps_AF', 'tl_ST'
    587     );
    588 
    589     $locale = get_locale();
    590 
    591     // convert locales like "es" to "es_ES", in case that works for the given locale (sometimes it does)
    592     if (strlen($locale) == 2) {
    593         $locale = strtolower($locale).'_'.strtoupper($locale);
    594     }
    595 
    596     // convert things like de-DE to de_DE
    597     $locale = str_replace('-', '_', $locale);
    598 
    599     // check to see if the locale is a valid FB one, if not, use en_US as a fallback
    600     if ( !in_array($locale, $fb_valid_fb_locales) ) {
    601         $locale = 'en_US';
    602     }
    603 
    604     return apply_filters('fb_locale', $locale); // filter the locale in case somebody has a weird case and needs to change it
    605 }
    606 
    607 function wpmeetupactivity_fb_get_user_meta( $user_id, $meta_key, $single = false ) {
    608     $override = apply_filters( 'wpmeetupactivity_fb_get_user_meta', false, $user_id, $meta_key, $single );
    609     if ( false !== $override )
    610         return $override;
    611 
    612     return get_user_meta( $user_id, $meta_key, $single );
    613 }
    614 
    615 function wpmeetupactivity_fb_update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
    616     $override = apply_filters( 'wpmeetupactivity_fb_update_user_meta', false, $user_id, $meta_key, $meta_value, $prev_value );
    617     if ( false !== $override )
    618         return $override;
    619 
    620     return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
    621 }
    622 
    623 function wpmeetupactivity_fb_delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
    624     $override = apply_filters( 'wpmeetupactivity_fb_delete_user_meta', false, $user_id, $meta_key, $meta_value );
    625     if ( false !== $override )
    626         return $override;
    627 
    628     return delete_user_meta( $user_id, $meta_key, $meta_value );
    629 }
    630 
    631 function wpmeetupactivity_fb_js_sdk_setup() {
    632     $options = get_option( 'fb_options' );
    633 
    634     if ( empty( $options['app_id'] ) )
    635         return;
    636 
    637     $args = apply_filters( 'fb_init', array(
    638         'appId' => $options['app_id'],
    639         'channelUrl' => add_query_arg( 'fb-channel-file', 1, site_url( '/' ) ),
    640         'status' => true,
    641         'cookie' => true,
    642         'xfbml' => true,
    643         'oauth' => true
    644     ) );
    645 
    646     echo '<script type="text/javascript">window.fbAsyncInit=function(){FB.init(' . json_encode( $args ) . ');';
    647     do_action( 'fb_async_init', $args );
    648     echo '}</script>';
    649 
    650     $locale = wpmeetupactivity_fb_get_locale();
    651     if ( ! $locale )
    652         return;
    653     wp_enqueue_script( 'fb-connect', ( is_ssl() ? 'https' : 'http' ) . '://connect.facebook.net/' . $locale . '/all.js', array(), null, true );
    654 
    655     add_action( 'wp_footer', 'wpmeetupactivity_fb_root' );
    656 }
    657 
    658 function wpmeetupactivity_fb_root() {
    659     echo '<div id="fb-root"></div>';
    660 }
    661 
    662 
    663 function wpmeetupactivity_fb_posttopage($link,$message) {
    664     global $facebook;
    665 
    666     $fb_options = get_option('wpmeetupactivity_fb_options');
    667    
    668     if(count($fb_options['pages']) > 0) {
    669     foreach($fb_options['pages'] as $fb_page_id) {
    670             $args = array(
    671             // 'access_token' => $facebook->getAccessToken(),
    672                 'from' => $fb_page_id,
    673             'link' => $link,
    674             'message' => $message,
    675         );
    676    
    677         try {
    678             $publish_result = $facebook->api("/$fb_page_id/feed", 'POST', $args);
    679         } catch (WP_FacebookApiException $e) {
    680             $error_result = $e->getResult();
    681         if(is_admin()) {
    682             echo "<div class=\"error\"><p><strong>".__('FB Post-to-Page error: '.$error_result, $wpmeetupactivity_textdomain)."</strong></p></div>";
    683         }
    684         }
    685        
    686         print_r($publish_result);
    687     }
    688     }
    689 }
    690 
    691 function wpmeetupactivity_fb_getuserpages() {
    692     global $facebook;
    693 
    694     $options = get_option('wpmeetupactivity_fb_options');
    695 
    696     $accounts = array();
    697 
    698     if ( ! isset( $facebook ) )
    699         return $accounts;
    700 
    701     try {
    702         $accounts = $facebook->api('/me/accounts', 'GET', array('ref' => 'fbwpp'));
    703     } catch (FacebookApiException $e) {
    704         return $accounts;
    705     }
    706 
    707     return $accounts['data'];
    708 }
    709 
    710 
    711 function wpmeetupactivity_fb_init() {
    712     global $facebook;
    713 
    714     $my_prefs = get_option('wpmeetupactivity_prefs');
    715 
    716     if($my_prefs["enableFb"]) {
    717    
    718     $fb_options = get_option('wpmeetupactivity_fb_options');
    719 
    720     // appId and secret are required by BaseFacebook
    721     if((!empty( $fb_options['app_id']) && !empty($fb_options['app_secret']))) {
    722         $facebook = new Facebook_WP_Extend(array(
    723         'appId'  => $fb_options['app_id'],
    724         'secret' => $fb_options['app_secret'],
    725             ));
    726     }
    727 
    728     add_action( 'wp_head', 'wpmeetupactivity_fb_js_sdk_setup' );
    729     add_action( 'admin_head', 'wpmeetupactivity_fb_js_sdk_setup' );
    730     }
    731 }
    732 
    733507/*
    734508
     
    738512function wpmeetupactivity_plugin_options() {
    739513    global $wpdb;
    740     global $facebook;
    741 
    742514
    743515    load_plugin_textdomain($wpmeetupactivity_textdomain, PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
     
    752524    if($_SERVER['REQUEST_METHOD'] == 'POST') {
    753525
    754         foreach($_POST["wpmeetupactivity_groups"] as $groupId => $val) {
    755             if($val == 'on') {
    756             $myGroups[] = $groupId;
     526    if(is_array($_POST["wpmeetupactivity_groups"])) {
     527        foreach($_POST["wpmeetupactivity_groups"] as $groupId => $val) {
     528                if($val == 'on') {
     529                $myGroups[] = $groupId;
     530            }
    757531            }
    758532        }
     
    764538        }
    765539
    766        
    767540        if($_POST["wpmeetupactivity_prefs_displayauthor"] == 'on') {
    768541            $my_prefs["displayAuthor"] = true;
     
    777550        }
    778551
    779         if($_POST["wpmeetupactivity_prefs_fb_enable"] == 'on') {
    780             $my_prefs["enableFb"] = true;
    781         } else {
    782             $my_prefs["enableFb"] = false;
    783         }
    784 
    785552    $my_prefs["displayAct"] = intval($_POST["wpmeetupactivity_prefs_displayact"]);
    786553    $my_prefs["displayEvents"] = intval($_POST["wpmeetupactivity_prefs_displayevents"]);
     
    795562    update_option('wpmeetupactivity_prefs',$my_prefs);
    796563
    797     // FB options
    798    
    799         if($my_prefs["enableFb"]) {
    800         $fb_options['app_id'] = $_POST['wpmeetupactivity_fb_appid'];
    801         $fb_options['app_secret'] = $_POST['wpmeetupactivity_fb_appsecret'];
    802 
    803         if($_POST["wpmeetupactivity_fb_post_on_new"] == 'on') {
    804             $fb_options['post_on_new'] = true;
    805         } else {
    806         $fb_options['post_on_new'] = false;
    807             }
    808 
    809         if($_POST["wpmeetupactivity_fb_post_on_reply"] == 'on') {
    810         $fb_options['post_on_reply'] = true;
    811         } else {
    812         $fb_options['post_on_reply'] = false;
    813         }
    814 
    815         $fb_pages = array();
    816    
    817         if(isset($_POST["wpmeetupactivity_fb_pages"])) {
    818         foreach($_POST["wpmeetupactivity_fb_pages"] as $pageId => $val) {
    819             $fb_pages[] = $pageId;
    820         }
    821         }   
    822         $fb_options['pages'] = $fb_pages;
    823        
    824         update_option('wpmeetupactivity_fb_options',$fb_options);
    825     }
    826    
    827564    // Saved !
    828565
     
    830567    echo __('Options saved.', $wpmeetupactivity_textdomain);
    831568    echo "</strong></p></div>";
     569
     570    if($_POST["wpmeetupactivity_is_scheduled"] == 'on') {
     571        wpmeetupactivity_install_cron();
     572    } else {
     573        wpmeetupactivity_uninstall_cron();
     574    }
    832575
    833576    if($_POST["wpmeetupactivity_purge_act_db"] == 'on') {
     
    871614    <b>v".WP_MEETUP_ACTIVITY." &copy; <a href=\"http://www.zerozone.it\">Michele \"O-Zone\" Pinassi</a></b>
    872615    </p>
    873     <form method='post'>
     616    <!-- Table prefix on DBMS ".WP_MEETUP_ACTIVITY_TABLE." -->";
     617   
     618    /* Check for CRON schedule */
     619    $is_scheduled = wp_get_schedule(WP_MEETUP_ACTIVITY_CRON_HOOK.'_hourly');
     620    if(!$is_scheduled) {
     621    echo "<div class=\"error\"><p><strong>";
     622    echo __('Cron schedule not set ! Your database will not be updated: please activate hourly updates below', $wpmeetupactivity_textdomain);
     623    echo "</strong></p></div>";
     624    }
     625   
     626    echo "<form method='post'>
    874627    <fieldset class='wpmeetupactivity-setup-fieldset'><legend> Meetup Api Key </legend>
    875628        <p>
     
    895648            echo " checked";
    896649        }
    897         echo "> ".$group['group_name']."</li>";
     650        echo "> ".$group['group_name']." (".$group['last_update'].")</li>";
    898651    }
    899652        echo "</ul>
    900653        </p></fieldset>
    901654        <fieldset class='wpmeetupactivity-setup-fieldset'><legend> Administrator functions </legend>
     655        <p>
     656        <input type='checkbox' name='wpmeetupactivity_is_scheduled' ".wpmeetupactivity_is_checked($is_scheduled)."> Set hourly updates using wp_cron
     657    </p>
    902658        <p>
    903659        <input type='checkbox' name='wpmeetupactivity_force_act_fetch'> Force activity fetch on save changes
     
    951707    </select>
    952708    </p>
    953    
    954     </fieldset><fieldset class='wpmeetupactivity-setup-fieldset'><legend> Facebook settings </legend>
    955     <p>
    956         <input type='checkbox' name='wpmeetupactivity_prefs_fb_enable' ".wpmeetupactivity_is_checked($my_prefs["enableFb"])."> Enable Facebook support
    957     </p>";
    958 
    959     if($my_prefs["enableFb"]) {
    960     $fb_options = get_option('wpmeetupactivity_fb_options');
    961    
    962     if ((empty($fb_options['app_id']) || empty($fb_options['app_secret'])) && current_user_can( 'manage_options' ) ) {
    963         echo "<div class=\"error\"><p><strong>";
    964         echo __('Need to configure Facebook Setting to use the post to page function !', $wpmeetupactivity_textdomain);
    965         echo "</strong></p></div>";
    966     } else {
    967             $fb_user = $facebook->getUser();
    968            
    969         $params = array( 'scope' => 'read_stream, manage_pages, publish_stream, offline_access' );
    970         if ($fb_user) {
    971         // Proceed knowing you have a logged in user who's authenticated.
    972         echo "<b>Currently connected as: $fb_user</b> (<a href='".$facebook->getLogoutUrl()."'>Disconnect from Facebook</a>)<br/>";
    973         } else {
    974         echo "Not connected (<a href='".$facebook->getLoginUrl($params)."'>Connect with Facebook App</a>)";
    975         }
    976     }
    977     echo "<p>
    978         App Id: <input type='text' size='64' name='wpmeetupactivity_fb_appid' value='".$fb_options['app_id']."' />
    979     </p><p>
    980         App Secret: <input type='text' size='128' name='wpmeetupactivity_fb_appsecret' value='".$fb_options['app_secret']."' />
    981     </p>";
    982     if ($fb_user) {
    983         echo "<fieldset class='wpmeetupactivity-setup-fieldset'><legend> Facebook Post-on-Page </legend>
    984         <p>
    985         <input type='checkbox' name='wpmeetupactivity_fb_post_on_new' ".wpmeetupactivity_is_checked($fb_options["post_on_new"])."> Post new threads on FB pages
    986         </p><p>
    987         <input type='checkbox' name='wpmeetupactivity_fb_post_on_reply' ".wpmeetupactivity_is_checked($my_prefs["post_on_reply"])."> Post every reply on FB pages (not suggested)
    988         </p><p>";
    989         if(is_array($fb_options['pages'])) {
    990         $fb_pages = $fb_options['pages'];
    991         } else {
    992         $fb_pages = array();
    993         }
    994    
    995         $c=0;
    996    
    997         foreach(wpmeetupactivity_fb_getuserpages() as $fb_page) {
    998         $fb_page_id = $fb_page['id'];
    999         if(is_array($fb_page['perms'])) {
    1000             if(in_array('CREATE_CONTENT',$fb_page['perms'])) {
    1001             echo "<input type='checkbox' name='wpmeetupactivity_fb_pages[".$fb_page_id."]' ".wpmeetupactivity_is_checked(in_array($fb_page_id,$fb_pages))."> ".$fb_page['name']." (<a href='http://www.facebook.com/$fb_page_id'>link</a>)<br/>";
    1002             $c++;
    1003             }
    1004         }
    1005         }
    1006         if($c == 0) {
    1007         echo "Sorry: you can't write to any page with this Facebook account !";
    1008         }
    1009         echo "</p></fieldset>";
    1010     }
    1011     }
    1012     echo "</fieldset><p class='submit'><input type='submit' name='Submit' value='Save changes' /></p>
     709    <p class='submit'><input type='submit' name='Submit' value='Save changes' /></p>
    1013710    </form></div><!-- /WRAP -->";
    1014711}
Note: See TracChangeset for help on using the changeset viewer.