public function sanitize_callback($input)
 {
     //return $input;
     // Define all of the variables that we'll be using
     $ccb_api_user = "";
     $ccb_api_pass = "";
     $ccb_api_prefix = "";
     $output = array();
     // Loop through each of the incoming options
     foreach ($input as $key => $value) {
         // Check to see if the current option has a value. If so, process it.
         if (isset($input[$key])) {
             switch ($key) {
                 case 'api_user':
                     $ccb_api_user = $input[$key];
                     break;
                 case 'api_pass':
                     $ccb_api_pass = $input[$key];
                     break;
                 case 'api_prefix':
                     $ccb_api_prefix = $input[$key];
                     break;
             }
             // Strip all HTML and PHP tags and properly handle quoted strings
             $output[$key] = strip_tags(stripslashes($input[$key]));
         }
     }
     // Let's test the connection with our newly saved settings
     $output['connection_test'] = (string) CCBPress()->ccb->test_connection($output['api_prefix'], $output['api_user'], $output['api_pass']);
     // Return the array
     return $output;
 }
    public function api_status_display()
    {
        $api_status = CCBPress()->ccb->api_status(array('cache_lifespan' => 0));
        if (!is_object($api_status)) {
            return;
        }
        ?>
		<table class="ccbpress-dash-widget-api-status">
			<tr>
				<td>
					<div><?php 
        echo (string) number_format(floatval($api_status->response->counter));
        ?>
</div>
					<?php 
        _e('requests today', 'ccbpress-core');
        ?>
				</td>
				<td>
					<div><?php 
        echo (string) number_format(floatval($api_status->response->daily_limit));
        ?>
</div>
					<?php 
        _e('your daily limit', 'ccbpress-core');
        ?>
				</td>
			</tr>
		</table>
		<?php 
    }
        /**
         * Front-end display of the widget
         *
         * @since 1.0.0
         *
         * @param  array $args     Widget arguments.
         * @param  array $instance Saved values from database.
         *
         * @return void
         */
        public function widget($args, $instance)
        {
            $ccb_api_url = CCBPress()->ccb->api_url;
            $ccb_login_url = str_replace('api.php', 'login.php', $ccb_api_url);
            $ccb_password_url = str_replace('api.php', 'w_password.php', $ccb_api_url);
            echo $args['before_widget'];
            if (!empty($instance['title'])) {
                echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
            }
            ob_start();
            ?>
		<form action="<?php 
            esc_attr_e($ccb_login_url);
            ?>
" method="post" target="_blank">
			<input type="hidden" name="ax" value="login" />
			<input type="hidden" name="rurl" value="" />
			<label for="username_<?php 
            esc_attr_e($args['widget_id']);
            ?>
"><?php 
            _e('Username:'******'ccbpress-core');
            ?>
</label>
			<input id="username_<?php 
            esc_attr_e($args['widget_id']);
            ?>
" type="text" name="form[login]" value="" />
			<label for="password_<?php 
            esc_attr_e($args['widget_id']);
            ?>
"><?php 
            _e('Password:'******'ccbpress-core');
            ?>
</label>
			<input id="password_<?php 
            esc_attr_e($args['widget_id']);
            ?>
" type="password" name="form[password]" value="" />
			<p>
				<input type="submit" value="<?php 
            esc_attr_e(__('Login', 'ccbpress-core'));
            ?>
" />
			</p>
		</form>
		<p>
			<a href="<?php 
            esc_attr_e($ccb_password_url);
            ?>
" target="_blank"><?php 
            _e('Forgot username or password?', 'ccbpress-core');
            ?>
</a>
		</p>
		<?php 
            echo ob_get_clean();
            echo $args['after_widget'];
        }
 public function settings_page_tabs($tabs)
 {
     $tabs[] = array('tab_id' => 'ccb', 'settings_id' => 'ccbpress_settings_ccb', 'title' => __('Church Community Builder', 'ccbpress-core'), 'submit' => TRUE);
     $tabs[] = array('tab_id' => 'ccbpress', 'settings_id' => 'ccbpress_settings', 'title' => __('CCBPress', 'ccbpress-core'), 'submit' => TRUE);
     if (CCBPress()->ccb->is_connected()) {
         $tabs[] = array('tab_id' => 'sync', 'settings_id' => 'ccbpress_settings_sync', 'title' => __('Data Import', 'ccbpress-core'), 'submit' => TRUE);
     }
     return $tabs;
 }
 /**
  * Event Profiles
  */
 protected function ccb_event_profiles($item)
 {
     update_option('ccbpress_event_sync_in_progress', 'Processing batch ' . $item['args']['page']);
     $results = CCBPress()->ccb->event_profiles($item['args']);
     if (!$results) {
         delete_option('ccbpress_event_sync_in_progress');
         update_option('ccbpress_last_event_sync', date('Y-m-d H:i:s', current_time('timestamp')));
         return false;
     }
     $events_count = 0;
     if (isset($results->response->events['count'])) {
         $events_count = $results->response->events['count'];
     }
     $event_profiles_db = new CCBPress_Event_Profiles_DB();
     foreach ($results->response->events->event as $event) {
         // Skip the event if it is not listed
         if ('false' == $event->public_calendar_listed) {
             continue;
         }
         $db_data = array('event_id' => $event['id'], 'name' => $event->name, 'description' => $event->description, 'leader_notes' => $event->leader_notes, 'start_datetime' => date('Y-m-d H:i:s', strtotime($event->start_datetime, current_time('timestamp'))), 'start_date' => $event->start_date, 'start_time' => $event->start_time, 'end_datetime' => date('Y-m-d H:i:s', strtotime($event->end_datetime, current_time('timestamp'))), 'end_date' => $event->end_date, 'end_time' => $event->end_time, 'timezone' => $event->timezone, 'recurrence_description' => $event->recurrence_description, 'approval_status_id' => $event->approval_status['id'], 'approval_status' => $event->approval_status, 'exceptions' => json_encode($event->exceptions), 'group_id' => $event->group['id'], 'group_name' => $event->group, 'organizer_id' => $event->organizer['id'], 'organizer' => $event->organizer, 'phone_type' => $event->phone['type'], 'phone' => $event->phone, 'location_name' => $event->location->name, 'location_street_address' => $event->location->street_address, 'location_city' => $event->location->city, 'location_state' => $event->location->state, 'location_zip' => $event->location->zip, 'location_line_1' => $event->location->line_1, 'location_line_2' => $event->location->line_2, 'registration_limit' => $event->registration->limit, 'registration_event_type_id' => $event->registration->event_type['id'], 'registration_event_type' => $event->registration->event_type, 'registration_forms' => json_encode($event->registration->forms), 'resources' => json_encode($event->resources), 'setup_start' => date('Y-m-d H:i:s', strtotime($event->setup->start, current_time('timestamp'))), 'setup_end' => date('Y-m-d H:i:s', strtotime($event->setup->end, current_time('timestamp'))), 'setup_notes' => $event->setup->notes, 'event_grouping_id' => $event->event_grouping['id'], 'event_grouping' => $event->event_grouping, 'creator_id' => $event->creator['id'], 'creator' => $event->creator, 'modifier_id' => $event->modifier['id'], 'modifier' => $event->modifier, 'listed' => 'true' == $event->listed ? 1 : 0, 'public_calendar_listed' => 'true' == $event->public_calendar_listed ? 1 : 0, 'created' => date('Y-m-d H:i:s', strtotime($event->created, current_time('timestamp'))), 'modified' => date('Y-m-d H:i:s', strtotime($event->modified, current_time('timestamp'))));
         $exists = $event_profiles_db->get($event['id']);
         if ($exists) {
             $event_profiles_db->update($event['id'], $db_data);
         } else {
             $event_profiles_db->insert($db_data);
         }
         unset($exists);
     }
     unset($event_profiles_db);
     unset($results);
     if ($events_count > 0 && $item['args']['per_page'] > 0 && $events_count == $item['args']['per_page']) {
         $item['args']['page'] = $item['args']['page'] + 1;
         return $item;
     }
     delete_option('ccbpress_event_sync_in_progress');
     update_option('ccbpress_last_event_sync', date('Y-m-d H:i:s', current_time('timestamp')));
     return false;
 }
        /**
         * Front-end display of the widget
         *
         * @since 1.0.0
         *
         * @param  array $args     Widget arguments.
         * @param  array $instance Saved values from database.
         *
         * @return void
         */
        public function widget($args, $instance)
        {
            $ccb_api_url = CCBPress()->ccb->api_url;
            $ccb_online_giving_url = str_replace('api.php', 'w_give_online.php', $ccb_api_url);
            echo $args['before_widget'];
            if (!empty($instance['title'])) {
                echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
            }
            ob_start();
            ?>
		<form action="<?php 
            esc_attr_e($ccb_online_giving_url);
            ?>
" target="_blank">
		    <input type="submit" value="<?php 
            esc_attr_e(__('Give Now', 'ccbpress-core'));
            ?>
">
		</form>
		<?php 
            echo ob_get_clean();
            echo $args['after_widget'];
        }
 /**
  * Create a new instance
  */
 function __construct()
 {
     $ccbpress_ccb = get_option('ccbpress_ccb');
     $api_user = '';
     if (isset($ccbpress_ccb['api_user'])) {
         $api_user = $ccbpress_ccb['api_user'];
     }
     $api_pass = '';
     if (isset($ccbpress_ccb['api_pass'])) {
         $api_pass = $ccbpress_ccb['api_pass'];
     }
     $api_prefix = '';
     if (isset($ccbpress_ccb['api_prefix'])) {
         $api_prefix = $ccbpress_ccb['api_prefix'];
     }
     $this->api_url = $this->api_protocol . $api_prefix . $this->api_endpoint;
     $this->api_user = $api_user;
     $this->api_pass = $api_pass;
     $this->transient_prefix = 'ccbp_';
     $this->test_srv = 'api_status';
     $this->image_cache_dir = 'ccbpress';
     $this->transient_fallback = CCBPress()->transients;
 }
 public function sync_events()
 {
     if (!isset($_POST['ccbpress_nonce']) || !wp_verify_nonce($_POST['ccbpress_nonce'], 'ccbpress-nonce')) {
         die('Insufficient Permissions');
     }
     $ccbpress_sync_options = get_option('ccbpress_settings_sync', array());
     if ('Never' === ($last_sync = get_option('ccbpress_last_event_sync', 'Never'))) {
         $modified_since = NULL;
     } else {
         $modified_since = (string) date('Y-m-d', strtotime($last_sync));
     }
     CCBPress()->sync->push_to_queue(array('srv' => 'event_profiles', 'args' => array('include_guest_list' => '0', 'page' => 1, 'per_page' => 100, 'modified_since' => $modified_since, 'cache_lifespan' => 0)));
     CCBPress()->sync->save()->dispatch();
     echo 'started';
     wp_die();
 }
function ccbpress_schedule_get($get_url, $cache_lifespan, $api_user, $api_pass, $transient_prefix)
{
    CCBPress()->ccb->get($get_url, $cache_lifespan);
}
 /**
  * Build the CCB Easy Email URL
  *
  * @param	string	$individual_id			The individual id.
  * @param	string	$group_id				The group id.
  * @param	string	$individual_full_name	The individual's full name.
  *
  * @return	string	The URL.
  */
 public function email_url($individual_id, $group_id, $individual_full_name)
 {
     $url = str_replace('api.php', 'easy_email.php', CCBPress()->ccb->api_url);
     $url = add_query_arg('ax', 'create_new', $url);
     $url = add_query_arg('individual_id', $individual_id, $url);
     $url = add_query_arg('group_id', $group_id, $url);
     $url = add_query_arg('individual_full_name', $individual_full_name, $url);
     return $url;
 }
 private function localize()
 {
     wp_localize_script('ccbpress-core-admin', 'ccbpress_vars', array('ccbpress_nonce' => wp_create_nonce('ccbpress-nonce')));
     $current_user = wp_get_current_user();
     wp_localize_script('ccbpress-core-beacon', 'ccbpress_core_beacon_vars', array('customer_name' => $current_user->display_name, 'customer_email' => $current_user->user_email, 'ccbpress_ver' => CCBPress()->version, 'wp_ver' => get_bloginfo('version'), 'php_ver' => phpversion(), 'topics' => apply_filters('ccbpress_support_topics', array(array('val' => 'general', 'label' => __('General question', 'ccbpress-core')), array('val' => 'ccb-credentials', 'label' => __('Help connecting to Church Community Builder', 'ccbpress-core')), array('val' => 'bug', 'label' => __('I think I found a bug', 'ccbpress-core'))))));
 }
                $timestamp = strtotime('midnight ' . get_option('timezone_string'));
                if ($timestamp < current_time('timestamp')) {
                    $timestamp = strtotime('+1 day', $timestamp);
                }
                wp_schedule_event($timestamp, 'daily', 'ccbpress_daily_maintenance');
            }
        }
        /**
         * Unschedule daily mantenance tasks
         *
         * @since 1.0.0
         *
         * @return void
         */
        public static function unschedule_cron()
        {
            wp_clear_scheduled_hook('ccbpress_daily_maintenance');
            wp_clear_scheduled_hook('ccbpress_transient_cache_cleanup');
        }
    }
}
// End if class_exists check
/**
 * Initialize the CCBPress_Core class
 */
function CCBPress()
{
    return CCBPress_Core::instance();
}
CCBPress();
 public function initialize()
 {
     if (!CCBPress()->ccb->is_connected()) {
         return;
     }
     // If the option does not exist, then add it
     if (false == get_option('ccbpress_settings_sync')) {
         add_option('ccbpress_settings_sync');
     }
     // Get the array of registered services
     $services = apply_filters('ccbpress_ccb_services', array());
     // First, we register a section. This is necessary since all future options must belong to one.
     add_settings_section('ccbpress_settings_group_sync_section', __('Group Data', 'ccbpress-core'), array($this, 'group_sync_section_callback'), 'ccbpress_settings_sync');
     // Set some default values
     $group_auto_sync = FALSE;
     $group_auto_sync_schedule = __('No add-ons are currently registered to use groups.', 'ccbpress-core');
     // Check for group related services
     if (in_array('group_profiles', $services) || in_array('group_profile_from_id', $services)) {
         $group_auto_sync_schedule = __('Scheduled to run in approximately ', 'ccbpress-core') . human_time_diff(strtotime('now'), wp_next_scheduled('ccbpress_daily_maintenance'));
         $group_auto_sync = TRUE;
     }
     /**
      * Automatic Sync
      */
     add_settings_field('group_auto_sync', '<strong>' . __('Automatic Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_group_sync_section', array('header' => NULL, 'title' => NULL, 'content' => $group_auto_sync_schedule));
     if (TRUE === $group_auto_sync) {
         /**
          * Last Group Sync
          */
         $last_group_sync = get_option('ccbpress_last_group_sync', 'Never');
         if ('Never' != $last_group_sync) {
             $last_group_sync = human_time_diff(strtotime('now', current_time('timestamp')), strtotime($last_group_sync, current_time('timestamp'))) . ' ago';
         }
         add_settings_field('group_last_sync', '<strong>' . __('Last Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_group_sync_section', array('header' => NULL, 'title' => NULL, 'content' => '<span class="ccbpress-last-group-sync">' . $last_group_sync . '</span>'));
         // Include Images
         add_settings_field('group_include_images', '<strong>' . __('Include images?', 'ccbpress-core') . '</strong>', array($this, 'checkbox_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_group_sync_section', array('field_id' => 'group_include_images', 'page_id' => 'ccbpress_settings_sync', 'label' => __('Download group images during import. <i>(Turning this on will dramatically slow down the process.)</i>', 'ccbpress-core')));
         /**
          * Manual Sync
          */
         $group_sync_status = get_option('ccbpress_group_sync_in_progress', false);
         if ($group_sync_status) {
             $group_sync_status = 'running';
         }
         add_settings_field('group_manual_sync', '<strong>' . __('Manual Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_group_sync_section', array('header' => NULL, 'title' => NULL, 'content' => '<button class="button button-secondary" id="ccbpress-manual-group-sync-button" data-ccbpress-status="' . $group_sync_status . '">Run Import Now</button><div id="ccbpress-group-sync-status"></div>'));
     }
     // First, we register a section. This is necessary since all future options must belong to one.
     add_settings_section('ccbpress_settings_event_sync_section', __('Event Data', 'ccbpress-core'), array($this, 'event_sync_section_callback'), 'ccbpress_settings_sync');
     // Set some default values
     $event_auto_sync = FALSE;
     $event_auto_sync_schedule = __('No add-ons are currently registered to use events.', 'ccbpress-core');
     // Check for group related services
     if (in_array('event_profiles', $services) || in_array('event_profile_from_id', $services)) {
         $event_auto_sync_schedule = __('Scheduled to run in approximately ', 'ccbpress-core') . human_time_diff(strtotime('now'), wp_next_scheduled('ccbpress_daily_maintenance'));
         $event_auto_sync = TRUE;
     }
     /**
      * Automatic Sync
      */
     add_settings_field('event_auto_sync', '<strong>' . __('Automatic Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_event_sync_section', array('header' => NULL, 'title' => NULL, 'content' => $event_auto_sync_schedule));
     if (TRUE === $event_auto_sync) {
         /**
          * Last Event Sync
          */
         $last_event_sync = get_option('ccbpress_last_event_sync', 'Never');
         if ('Never' != $last_event_sync) {
             $last_event_sync = human_time_diff(strtotime('now', current_time('timestamp')), strtotime($last_event_sync, current_time('timestamp'))) . ' ago';
         }
         add_settings_field('event_last_sync', '<strong>' . __('Last Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_event_sync_section', array('header' => NULL, 'title' => NULL, 'content' => '<span class="ccbpress-last-event-sync">' . $last_event_sync . '</span>'));
         /**
          * Manual Sync
          */
         $event_sync_status = get_option('ccbpress_event_sync_in_progress', false);
         if ($event_sync_status) {
             $event_sync_status = 'running';
         }
         add_settings_field('event_manual_sync', '<strong>' . __('Manual Import', 'ccbpress-core') . '</strong>', array($this, 'text_callback'), 'ccbpress_settings_sync', 'ccbpress_settings_event_sync_section', array('header' => NULL, 'title' => NULL, 'content' => '<button class="button button-secondary" id="ccbpress-manual-event-sync-button" data-ccbpress-status="' . $event_sync_status . '">Run Import Now</button><div id="ccbpress-event-sync-status"></div>'));
     }
     // Finally, we register the fields with WordPress
     register_setting('ccbpress_settings_sync', 'ccbpress_sync', array($this, 'sanitize_callback'));
 }
 private function run_sync($what, $sync_all = FALSE)
 {
     $ccbpress_sync_options = get_option('ccbpress_settings_sync', array());
     switch ($what) {
         case 'groups':
             $include_image_link = '0';
             if (isset($ccbpress_sync_options['group_include_images'])) {
                 $include_image_link = '1';
             }
             if ('Never' === ($last_sync = get_option('ccbpress_last_group_sync', 'Never')) || $sync_all) {
                 $modified_since = (string) date('Y-m-d', strtotime('-6 months', current_time('timestamp')));
             } else {
                 $modified_since = (string) date('Y-m-d', strtotime($last_sync));
             }
             CCBPress()->sync->push_to_queue(array('srv' => 'group_profiles', 'args' => array('include_participants' => '0', 'include_image_link' => $include_image_link, 'page' => 1, 'per_page' => 100, 'modified_since' => $modified_since, 'cache_lifespan' => 0)));
             CCBPress()->sync->save()->dispatch();
             break;
         case 'events':
             if ('Never' === ($last_sync = get_option('ccbpress_last_event_sync', 'Never')) || $sync_all) {
                 $modified_since = null;
             } else {
                 $modified_since = (string) date('Y-m-d', strtotime($last_sync));
             }
             CCBPress()->sync->push_to_queue(array('srv' => 'event_profiles', 'args' => array('include_guest_list' => '0', 'page' => 1, 'per_page' => 100, 'modified_since' => $modified_since, 'cache_lifespan' => 0)));
             CCBPress()->sync->save()->dispatch();
             break;
     }
 }