public static function connectFeedback($all_count, $cronjob = false) { global $wpdb; self::$cronSendOperation = $cronjob; if ($cronjob === true) { smpush_helper::$returnValue = 'cronjob'; } $fail = $androidfail = 0; $feedbacks = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "push_feedback"); foreach ($feedbacks as $feedback) { if ($feedback->device_type == 'ios_invalid') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='0' WHERE {token_name}='" . $feedback->tokens . "'")); self::updateStats('iosfail', 1); } elseif ($feedback->device_type == 'ios') { if (!empty($_GET['feedback_open'])) { self::jsonPrint(4, '<p>Start connection and reading with Apple feedback server, Maybe takes some time</p>'); } $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', self::$apisetting['apple_cert_path']); stream_context_set_option($ctx, 'ssl', 'passphrase', self::$apisetting['apple_passphrase']); if (self::$apisetting['apple_sandbox'] == 1) { $appleserver = 'tls://feedback.sandbox.push.apple.com:2196'; } else { $appleserver = 'tls://feedback.push.apple.com:2196'; } @($fpssl = stream_socket_client($appleserver, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx)); if (!$fpssl) { if (empty($errstr)) { $errstr = 'Apple certification error or problem with Password phrase'; } if ($err == 111) { $errstr .= ' - Contact your host to enable outgoing ports'; } self::jsonPrint(0, '<p class="error">Could not establish connection with SSL server: ' . $errstr . '</p>'); } $nFeedbackTupleLen = self::TIME_BINARY_SIZE + self::TOKEN_LENGTH_BINARY_SIZE + self::DEVICE_BINARY_SIZE; $sBuffer = ''; while (!feof($fpssl)) { $sBuffer .= $sCurrBuffer = fread($fpssl, 8192); $nCurrBufferLen = strlen($sCurrBuffer); unset($sCurrBuffer, $nCurrBufferLen); $nBufferLen = strlen($sBuffer); if ($nBufferLen >= $nFeedbackTupleLen) { $nFeedbackTuples = floor($nBufferLen / $nFeedbackTupleLen); for ($i = 0; $i < $nFeedbackTuples; $i++) { $sFeedbackTuple = substr($sBuffer, 0, $nFeedbackTupleLen); $sBuffer = substr($sBuffer, $nFeedbackTupleLen); $aFeedback = self::_parseBinaryTuple($sFeedbackTuple); self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='0' WHERE {token_name}='{$aFeedback['deviceToken']}'")); $fail++; unset($aFeedback); } } $read = array($fpssl); $null = NULL; $nChangedStreams = stream_select($read, $null, $null, 0, 1000000); if ($nChangedStreams === false) { break; } } self::updateStats('iosfail', $fail); if ($fail > 0) { self::jsonPrint(2, array('message' => '<p>Reading from Apple feedback is finised, try to read again for more</p>', 'all_count' => $all_count)); } } else { if (!empty($_GET['feedback_google'])) { self::jsonPrint(5, '<p>Start processing Google feedback queries</p>'); } $tokens = unserialize($feedback->tokens); $result = json_decode($feedback->feedback); foreach ($result->results as $key => $status) { if (isset($status->error)) { if ($status->error == 'InvalidRegistration' || $status->error == 'NotRegistered' || $status->error == 'MismatchSenderId') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='0' WHERE {token_name}='{$tokens[$key]}'")); $androidfail++; } } } self::updateStats('androidfail', $androidfail); } $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_feedback WHERE id='" . $feedback->id . "'"); } }
<input type="checkbox" name="archive[]" value="<?php echo $archive->id; ?> "> <div class="locked-indicator"></div> </th> <td class="name column-name"><strong><?php echo $archive->id; ?> </strong></td> <td class="name column-name"><span><?php echo $archive->message; ?> </span></td> <td class="name column-name"><span><?php echo empty($archive->report) ? '' : smpush_sendpush::printReport(unserialize($archive->report)); ?> </span></td> <td class="name column-name smpush-center"><?php echo date(self::$wpdateformat, strtotime($archive->starttime)); ?> </td> <td class="name column-name smpush-center"><?php echo empty($archive->endtime) ? 'Not finished yet' : date(self::$wpdateformat, strtotime($archive->endtime)); ?> </td> <td class="description column-categories"> <input type="button" class="button action smpush-open-btn" value="Delete" onclick="smpush_delete_service(<?php echo $archive->id; ?> )" />
public function send_notification() { $this->CheckParams(array('message')); $_REQUEST = array_map('urldecode', $_REQUEST); $setting = array(); if (!empty($_REQUEST['expire'])) { $setting['expire'] = $_REQUEST['expire']; } if (!empty($_REQUEST['ios_slide'])) { $setting['ios_slide'] = $_REQUEST['ios_slide']; } if (!empty($_REQUEST['ios_badge'])) { $setting['ios_badge'] = $_REQUEST['ios_badge']; } if (!empty($_REQUEST['ios_sound'])) { $setting['ios_sound'] = $_REQUEST['ios_sound']; } if (!empty($_REQUEST['ios_cavailable'])) { $setting['ios_cavailable'] = $_REQUEST['ios_cavailable']; } if (!empty($_REQUEST['ios_launchimg'])) { $setting['ios_launchimg'] = $_REQUEST['ios_launchimg']; } if (!empty($_REQUEST['customparams'])) { $setting['extra_type'] = 'json'; $setting['extravalue'] = $_REQUEST['customparams']; } if (!empty($_REQUEST['android_customparams'])) { $setting['and_extra_type'] = 'json'; $setting['and_extravalue'] = $_REQUEST['android_customparams']; } if (!empty($_REQUEST['sendtime'])) { $sendtime = strtotime($_REQUEST['sendtime'], current_time('timestamp', 1)); } else { $sendtime = 0; } if (!empty($_REQUEST['device_token'])) { $this->CheckParams(array('device_token', 'device_type')); smpush_sendpush::SendPushMessage($_REQUEST['device_token'], $_REQUEST['device_type'], $_REQUEST['message'], $setting, $sendtime); $this->output(1, 'Message sent successfully'); } elseif (!empty($_REQUEST['user_id'])) { $tokeninfo = self::$pushdb->get_row(self::parse_query("SELECT {token_name} AS device_token,{type_name} AS device_type FROM {tbname} WHERE userid='{$_REQUEST['user_id']}' AND {active_name}='1'")); if ($tokeninfo) { smpush_sendpush::SendPushMessage($tokeninfo->device_token, $tokeninfo->device_type, $_REQUEST['message'], $setting, $sendtime); $this->output(1, 'Message sent successfully'); } else { $this->output(0, 'Did not find data about this user or the user is inactive'); } } elseif (!empty($_REQUEST['channel'])) { if ($_REQUEST['channel'] == 'all') { smpush_sendpush::SendCronPush('all', $_REQUEST['message'], '', '', $setting, $sendtime); } else { smpush_sendpush::SendCronPush($_REQUEST['channel'], $_REQUEST['message'], '', 'channel', $setting, $sendtime); } $this->output(1, 'Message sent successfully'); } }
public static function new_comment($commid, $nowcomment) { global $wpdb; if ($nowcomment->comment_approved == 1) { if (self::$apisetting['e_usercomuser'] == 1) { if ($nowcomment->comment_parent > 0) { $comment = $wpdb->get_row("SELECT comment_post_ID,user_id FROM " . $wpdb->prefix . "comments WHERE comment_ID='" . $nowcomment->comment_parent . "' AND user_id>0", 'ARRAY_A'); if (!$comment) { return false; } $commentcount = $wpdb->get_var("SELECT COUNT(comment_ID) AS commcount FROM " . $wpdb->prefix . "comments WHERE comment_parent='" . $nowcomment->comment_parent . "' AND comment_approved='1'"); if ($commentcount > 0 and ($commentcount == 1 or $commentcount % 5 == 0)) { $subject = self::ShortString($nowcomment->comment_content, 60); $message = self::processNotifBody('e_usercomuser', $subject); smpush_sendpush::SendCronPush(array(0 => $comment['user_id']), $message, $comment['comment_post_ID']); } } } if (self::$apisetting['e_newcomment'] == 1) { $postid = $nowcomment->comment_post_ID; $commentcount = $wpdb->get_var("SELECT COUNT(comment_ID) AS commcount FROM " . $wpdb->prefix . "comments WHERE comment_post_ID='{$postid}' AND comment_approved='1'"); if ($commentcount > 0 and ($commentcount == 1 or $commentcount % 10 == 0)) { $post = $wpdb->get_row("SELECT post_title,post_author FROM " . $wpdb->prefix . "posts WHERE ID='{$postid}'", 'ARRAY_A'); $subject = self::ShortString($post['post_title'], 60); $message = self::processNotifBody('e_newcomment', $subject); smpush_sendpush::SendCronPush(array(0 => $post['post_author']), $message, $postid); } } } }
public static function sendPushCron($type) { global $wpdb; self::$sendoptions = get_transient('smpush_cronsend_' . self::$tempunique); if (self::$sendoptions === false) { $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_cron_queue WHERE sendoptions='" . self::$tempunique . "'"); self::writeLog('System did not find the related data for some cron sending: operation cancelled'); die; } if ($type == 'ios') { $DelIDS = implode(',', self::$iosDelIDS); $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_cron_queue WHERE id IN({$DelIDS})"); smpush_sendpush::connectPush(self::$sendoptions['message'], self::$iosDevices, 'ios', self::$sendoptions, true, 0, true); self::resetIOS(); } else { $DelIDS = implode(',', self::$andDelIDS); $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_cron_queue WHERE id IN({$DelIDS})"); smpush_sendpush::connectPush(self::$sendoptions['message'], self::$andDevices, 'android', self::$sendoptions, true, 0, true); self::resetAND(); } }