function bindCacheIpbanned() { FDB::query("DELETE FROM " . FDB::table('ip_banned') . " WHERE expiration<'" . TIME_UTC . "'"); $data = array(); $query = FDB::query("SELECT ip1, ip2, ip3, ip4, expiration FROM " . FDB::table('ip_banned')); if (FDB::numRows($query)) { $data['expiration'] = 0; $data['regexp'] = $separator = ''; } while ($banned = FDB::fetch($query)) { $data['expiration'] = !$data['expiration'] || $banned['expiration'] < $data['expiration'] ? $banned['expiration'] : $data['expiration']; $data['regexp'] .= $separator . ($banned['ip1'] == '-1' ? '\\d+\\.' : $banned['ip1'] . '\\.') . ($banned['ip2'] == '-1' ? '\\d+\\.' : $banned['ip2'] . '\\.') . ($banned['ip3'] == '-1' ? '\\d+\\.' : $banned['ip3'] . '\\.') . ($banned['ip4'] == '-1' ? '\\d+' : $banned['ip4']); $separator = '|'; } FanweService::instance()->cache->saveCache('ipbanned', $data); }
/** * Queue Message for Delivery * * <code> * <?php * $db = new DbConnect('localhost','dbuser','dbpass','dbname'); * $db->show_errors(); * $apns = new APNS($db); * $apns->newMessage(1, '2010-01-01 00:00:00'); * $apns->addMessageAlert('You got your emails.'); * $apns->addMessageBadge(9); * $apns->addMessageSound('bingbong.aiff'); * $apns->queueMessage(); // ADD THE MESSAGE TO QUEUE * ?> * </code> * * @access public */ public function queueMessage() { // check to make sure a message was created if (!isset($this->message)) { $this->_triggerError('You cannot Queue a message that has not been created. Use newMessage() to create a new message.'); } // loop through possible users $to = $this->message['send']['to']; $when = $this->message['send']['when']; $clientId = is_null($this->message['aps']['clientid']) ? null : $this->prepare($this->message['aps']['clientid']); $list = is_array($to) ? $to : array($to); unset($this->message['send']); // Lets make sure that the recipients are integers. If not then just remove foreach ($list as $key => $val) { if (!is_numeric($val)) { $this->_triggerError("TO id was not an integer: {$val}."); unset($list[$key]); } } // No recipients left? if (empty($list)) { $this->_triggerError('No valid recipient was provided.'); } // Get the devices. // fetch the users id and check to make sure they have certain notifications enabled before trying to send anything to them. $sql = "\r\n\t\t\tSELECT `pid`, `pushbadge`, `pushalert`, `pushsound`, `clientid`\r\n\t\t\tFROM " . FDB::table('apns_devices') . " \r\n\t\t\tWHERE `pid` IN (" . implode(', ', $list) . ")\r\n\t\t\t\tAND `status`='active'" . (is_null($clientId) ? '' : "\r\n\t\t\t\tAND `clientid` = '{$clientId}'"); //echo $sql; exit; $res = FDB::query($sql); if (FDB::numRows($res) == 0) { $this->_triggerError('This user does not exist in the database. Message will not be delivered.'); } while ($row = FDB::fetch($res)) { $deliver = true; // Device id. $deviceid = $row['pid']; // Get the push settings. $pushbadge = $this->prepare($row['pushbadge']); $pushalert = $this->prepare($row['pushalert']); $pushsound = $this->prepare($row['pushsound']); $clientId = $this->prepare($row['clientid']); // has user disabled messages? if ($pushbadge == 'disabled' && $pushalert == 'disabled' && $pushsound == 'disabled') { $deliver = false; } if ($deliver === false && FDB::numRows($res) > 0) { $this->_triggerError('This user has disabled all push notifications. Message will not be delivered.'); } else { if ($deliver === true) { // make temp copy of message so we can cut out stuff this user may not get $usermessage = $this->message; // only send badge if user will get it if ($pushbadge == 'disabled') { $this->_triggerError('This user has disabled Push Badge Notifications, Badge will not be delivered.'); unset($usermessage['aps']['badge']); } // only send alert if user will get it if ($pushalert == 'disabled') { $this->_triggerError('This user has disabled Push Alert Notifications, Alert will not be delivered.'); unset($usermessage['aps']['alert']); } // only send sound if user will get it if ($pushsound == 'disabled') { $this->_triggerError('This user has disabled Push Sound Notifications, Sound will not be delivered.'); unset($usermessage['aps']['sound']); } //echo $usermessage; $fk_device = $this->prepare($deviceid); $message = $this->_jsonEncode($usermessage); $message = $this->prepare($message); $delivery = !empty($when) ? "'{$when}'" : 'NOW()'; //echo $message."<br>"; $sql = "INSERT INTO " . FDB::table('apns_messages') . " \r\n\t\t\t\t\t\tVALUES (\r\n\t\t\t\t\t\t\tNULL,\r\n\t\t\t\t\t\t\t'{$clientId}',\r\n\t\t\t\t\t\t\t'{$fk_device}',\r\n\t\t\t\t\t\t\t'{$message}',\r\n\t\t\t\t\t\t\t{$delivery},\r\n\t\t\t\t\t\t\t'queued',\r\n\t\t\t\t\t\t\tNOW(),\r\n\t\t\t\t\t\t\tNOW()\r\n\t\t\t\t\t\t);"; //echo $sql."<br>";exit; FDB::query($sql); unset($usermessage); } } } unset($this->message); }