Beispiel #1
0
 public static function send($device_token, $message, $additional_data = array(), $badge = null, $sound = 'default')
 {
     if (!self::$apn) {
         $settings = WPAPN_AdminController::getSettings();
         try {
             self::$apn = new WPAPN_APN($settings);
         } catch (Exception $e) {
             WPAPN_AdminController::showMessage($e->getMessage(), true);
             self::$apn = false;
             return false;
         }
     }
     $post_id = wp_insert_post(array('post_type' => WPAPN_NotificationController::$type, 'post_status' => 'publish', 'post_title' => $message));
     if (is_wp_error($post_id)) {
         return false;
     }
     self::$apn->payloadMethod = 'enhance';
     // you can turn on this method for debuggin purpose
     $connected = true;
     try {
         $connected = self::$apn->connectToPush();
     } catch (Exception $e) {
         $connected = false;
     }
     if (!$connected) {
         WPAPN_Plugin::log('APN error', 'Could not connect to the push service');
         return false;
     }
     // adding custom variables to the notification
     if (!empty($additional_data)) {
         self::$apn->setData($additional_data);
     }
     // send
     $send_result = self::$apn->sendMessage($device_token, $message, $badge, $sound);
     wp_update_post(array('ID' => $post_id, 'post_content' => self::$apn->recent_payload));
     update_post_meta($post_id, WP_APN_PLUGIN . '-device-token', $device_token);
     update_post_meta($post_id, WP_APN_PLUGIN . '-badge', $badge);
     update_post_meta($post_id, WP_APN_PLUGIN . '-sound', $sound);
     if ($send_result) {
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-status', 'sent');
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-error', '');
         WPAPN_Plugin::log('APN debug', 'Sending successful');
     } else {
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-status', 'error');
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-error', self::$apn->error);
         WPAPN_Plugin::log('APN error', self::$apn->error);
     }
     self::$apn->disconnectPush();
     return $post_id;
 }
    public static function custom_columns_views($column_name, $post_id)
    {
        global $post;
        switch ($column_name) {
            case 'message':
                ?>
					<strong><?php 
                echo $post->post_title;
                ?>
</strong>
				<?php 
                break;
            case 'payload':
                ?>
					<pre><?php 
                echo WPAPN_Plugin::json_format($post->post_content);
                ?>
</pre>
				<?php 
                break;
            case 'user':
                $user_id = WPAPN_Model::get_post_meta($post_id, WP_APN_PLUGIN . '-user', true);
                $author = get_user_by('id', $user_id);
                if ($author) {
                    $permalink = admin_url('/user-edit.php?user_id=' . $post->post_author);
                    ?>
						<div style="float: left;"><?php 
                    echo get_avatar($post->post_author, 32);
                    ?>
</div>
						<div style="float: left;line-height: 30px; margin-left: 10px;">
							<a href="<?php 
                    echo $permalink;
                    ?>
"><?php 
                    echo get_the_author_meta('display_name', $post->post_author);
                    ?>
</a>
						</div>
						<div style="clear:both;"></div>
						<div class="row-actions">
							<a href="<?php 
                    echo $permalink;
                    ?>
"><?php 
                    echo __('Edit');
                    ?>
</a>
						</div>
					<?php 
                }
                break;
            case 'device_token':
                $device_token = WPAPN_Model::get_post_meta($post_id, WP_APN_PLUGIN . '-device-token', true);
                ?>
					<?php 
                echo $device_token;
                ?>
				<?php 
                break;
            case 'status':
                $status = WPAPN_Model::get_post_meta($post_id, WP_APN_PLUGIN . '-sent-status', true);
                $error = WPAPN_Model::get_post_meta($post_id, WP_APN_PLUGIN . '-sent-error', true);
                ?>
					<div><?php 
                _e('Status', WP_APN_PLUGIN);
                ?>
: <?php 
                echo $status;
                ?>
</div>
					
					<?php 
                if ($error) {
                    ?>
						<div><?php 
                    _e('Send Error', WP_APN_PLUGIN);
                    ?>
: <?php 
                    echo $error;
                    ?>
</div>
					<?php 
                }
                ?>
				<?php 
                break;
        }
    }
Beispiel #3
0
}
define('WP_APN_PLUGIN', 'wp-apn');
define('WP_APN_APPPATH', dirname(__FILE__));
define('WP_APN_FILE', __FILE__);
if (!class_exists('WPAPN_Plugin')) {
    include_once WP_APN_APPPATH . '/controllers/Plugin.php';
}
if (!class_exists('APN')) {
    include_once WP_APN_APPPATH . '/libraries/apn.class.php';
}
// initialization
register_activation_hook(__FILE__, array('WPAPN_Plugin', 'activation'));
// plugin actions
add_filter('plugin_action_links', array('WPAPN_Plugin', 'registerPluginActions'), 10, 2);
// early actions
WPAPN_Plugin::initEarlyActions();
function wp_wp_apn_init()
{
    if (!class_exists('WPAPN_Model')) {
        include_once WP_APN_APPPATH . '/models/Model.php';
    }
    if (!class_exists('WPAPN_AssetsController')) {
        include_once WP_APN_APPPATH . '/controllers/AssetsController.php';
    }
    if (!class_exists('WPAPN_AdminController')) {
        include_once WP_APN_APPPATH . '/controllers/AdminController.php';
    }
    if (!class_exists('WPAPN_ApiController')) {
        include_once WP_APN_APPPATH . '/controllers/ApiController.php';
    }
    if (!class_exists('WPAPN_MyApiController')) {
Beispiel #4
0
					<code><pre><?php 
if (file_exists(WPAPN_Plugin::getLogsPath() . date('Y-m-d') . '.php')) {
    include_once WPAPN_Plugin::getLogsPath() . date('Y-m-d') . '.php';
} else {
    _e("Today's log file doesn't exist", WP_APN_PLUGIN);
}
?>
</pre></code>
				</div>
				
			</div>
		</div>
		
	<div class="pure-u-1">
		<?php 
$documentation_url = WPAPN_Plugin::getDocsUrl();
?>
		<div class="wp-apn-bl">
			<div class="row hdr">
				<h3>
					<span class="fa fa-file-code-o"></span>
					<?php 
_e('Documentation', WP_APN_PLUGIN);
?>
					<a class="right" target="_blank" href="<?php 
echo $documentation_url;
?>
" title="<?php 
_e('open in the separate tab', WP_APN_PLUGIN);
?>
"><span class="fa fa-external-link"></span></a>
Beispiel #5
0
 public static function showSettings()
 {
     $requirements = WPAPN_Plugin::requirements();
     include_once WP_APN_APPPATH . '/views/settings.php';
 }
Beispiel #6
0
 public function log($type, $message)
 {
     if ($type == 'error' || $this->debug) {
         WPAPN_Plugin::log($type, $message);
     }
 }