private function _handleGetResults()
 {
     $pathS = __DIR__ . '/../../listener/status.db';
     $statusArr = FileUtil::loadArray($pathS);
     $this->results[SMSController::RESULT_STATUS_ARR] = $statusArr;
     $pathM = __DIR__ . '/../../listener/msgs.db';
     $msgsArr = FileUtil::loadArray($pathM);
     $this->results[SMSController::RESULT_MSGS_ARR] = $msgsArr;
 }
 public function handleRequest()
 {
     $this->handleSendMMS();
     $this->handleGetStatus();
     // notifications
     $pathS = __DIR__ . '/../../listener/status.db';
     $this->results[MMSController::RESULT_STATUS_DB] = FileUtil::loadArray($pathS);
     // attachments
     $fnames = FileUtil::getFiles($this->_attachmentsFolder);
     array_unshift($fnames, "");
     // no attachment
     $this->results[MMSController::RESULT_FNAMES] = $fnames;
     // images
     $path = __DIR__ . '/../../MMSImages/mmslistener.db';
     $this->results[MMSController::RESULT_MSGS_DB] = FileUtil::loadArray($path);
     if (isset($_SESSION['id'])) {
         $this->results[MMSController::RESULT_MSG_ID] = $_SESSION['id'];
     }
 }
 private function loadFile()
 {
     $fileArr = FileUtil::loadArray($this->_fpath);
     if ($fileArr == NULL || !is_array($fileArr)) {
         $fileArr = array();
     }
     $indices = array(PaymentFileHandler::INDEX_TRANS_ID, PaymentFileHandler::INDEX_MERCHANT_TRANS_ID, PaymentFileHandler::INDEX_AUTH_CODE, PaymentFileHandler::INDEX_SUB_ID, PaymentFileHandler::INDEX_S_AUTH_CODE, PaymentFileHandler::INDEX_S_MERCHANT_TRANS_ID, PaymentFileHandler::INDEX_S_CONSUMER_ID, PaymentFileHandler::INDEX_S_MERCHANT_SUB_ID);
     foreach ($indices as $index) {
         if (!isset($fileArr[$index])) {
             $fileArr[$index] = array('Select...');
         }
         // save the Select... string
         $select = array_shift($fileArr[$index]);
         // limit on the number of entires
         while (count($fileArr[$index]) > $this->_limit) {
             array_shift($fileArr[$index]);
         }
         // now put the Select.. string back
         array_unshift($fileArr[$index], $select);
     }
     return $fileArr;
 }
 * limitations under the License.
 */
require __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$statusNotifications = array();
$fileArr = FileUtil::loadArray($statusFile);
foreach ($fileArr as $statusNotification) {
    $dInfoNotification = $statusNotification['deliveryInfoNotification'];
    $dInfo = $dInfoNotification['deliveryInfo'];
    $msgId = $dInfoNotification['messageId'];
    $addr = preg_replace('/\\d\\d\\d($)/', '***${1}', $dInfo['address']);
    $deliveryStatus = $dInfo['deliveryStatus'];
    $statusNotifications[] = array($msgId, $addr, $deliveryStatus);
}
$mmsNotificationsArr = FileUtil::loadArray($imagesDbPath);
$mmsNotifications = array();
$nsize = count($mmsNotificationsArr);
for ($i = $nsize - $mmsLimit; $i < $nsize; ++$i) {
    if ($i < 0) {
        continue;
    }
    $mmsNotification = $mmsNotificationsArr[$i];
    if (isset($mmsNotification['text'])) {
        $fpath = __DIR__ . '/../' . $mmsNotification['text'];
        $mmsNotification['text'] = file_get_contents($fpath);
    } else {
        $mmsNotification['text'] = '-';
    }
    $mmsNotifications[] = $mmsNotification;
}
 * Copyright 2015 AT&T
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$msgs = array();
$msgsArr = FileUtil::loadArray(MSGS_FILE);
foreach ($msgsArr as $msgsArrEntry) {
    $msgs[] = array($msgsArrEntry['MessageId'], $msgsArrEntry['DateTime'], $msgsArrEntry['SenderAddress'], $msgsArrEntry['DestinationAddress'], $msgsArrEntry['DestinationAddress']);
}
$statuses = array();
$statusesArr = FileUtil::loadArray(STATUS_FILE);
foreach ($statusesArr as $statusesArrEntry) {
    $info = $statusesArrEntry['deliveryInfoNotification'];
    $dinfo = $info['deliveryInfo'];
    $statuses[] = array($info['messageId'], $dinfo['address'], $dinfo['deliveryStatus']);
}
echo json_encode(array('messages' => $msgs, 'deliveryStatus' => $statuses));
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
use Att\Api\Util\FileUtil;
use Att\Api\Util\Util;
if (isset($_SESSION['subscriptionExpiry'])) {
    $tnow = time();
    $expiry = $_SESSION['subscriptionExpiry'];
    if ($tnow >= $expiry) {
        unset($_SESSION['subscriptionId']);
    }
}
if (!isset($_SESSION['subscriptionId'])) {
    $arr = array('stopPolling' => true);
    echo json_encode($arr);
    return;
}
$subscriptionId = $_SESSION['subscriptionId'];
$arr = FileUtil::loadArray(NOTIFICATION_FILE);
$vals = array();
foreach ($arr as $msgNotifications) {
    foreach ($msgNotifications as $subscriptionNotifications) {
        $subId = $subscriptionNotifications['subscriptionId'];
        if ($subId != $subscriptionId) {
            continue;
        }
        $callbackData = $subscriptionNotifications['callbackData'];
        $notificationEvents = $subscriptionNotifications['notificationEvents'];
        foreach ($notificationEvents as $evt) {
            $vals[] = Util::convertNulls(array($subId, $callbackData, $evt['messageId'], $evt['conversationThreadId'], $evt['eventType'], $evt['event'], $evt['text'], $evt['isTextTruncated'], $evt['isFavorite'], $evt['isUnread']));
        }
    }
}
echo json_encode($vals);
 public function handleRequest()
 {
     // handle transactions
     $this->handleNewTransaction();
     $this->handleTransactionAuthCode();
     $this->handleGetTransactionStatus();
     $this->handleTransRefund();
     // handle subscriptions
     $this->handleNewSubscription();
     $this->handleSubscriptionAuthCode();
     $this->handleGetSubscriptionStatus();
     $this->handleGetSubscriptionDetails();
     $this->handleSubCancel();
     $this->handleSubRefund();
     // handle part notary
     $this->handleNotary();
     // load file contents
     $this->setFileResults();
     // notification information
     $this->results['notifications'] = FileUtil::loadArray('notifications.db');
     // notary
     if (isset($_SESSION['notary'])) {
         $this->results['notary'] = unserialize($_SESSION['notary']);
     }
 }
<?php

require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$postBody = file_get_contents('php://input');
$asArray = true;
$messageInfo = json_decode($postBody, $asArray);
$statusarr = FileUtil::loadArray(STATUS_FILE);
$statusarr[] = $messageInfo;
// TODO: Put value into config
while (count($statusarr) > 5) {
    array_shift($statusarr);
}
FileUtil::saveArray($statusarr, STATUS_FILE);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$path = __DIR__;
$fname = $path . '/status.db';
$postBody = file_get_contents('php://input');
$asArray = true;
$messageInfo = json_decode($postBody, $asArray);
$statusarr = FileUtil::loadArray($fname);
$statusarr[] = $messageInfo;
// TODO: Put value into config
while (count($statusarr) > 5) {
    array_shift($statusarr);
}
FileUtil::saveArray($statusarr, $fname);
<?php

require_once __DIR__ . '/lib/Payment/NotificationDetails.php';
require_once __DIR__ . '/lib/Util/FileUtil.php';
use Att\Api\Payment\NotificationDetails;
use Att\Api\Util\FileUtil;
$rawXml = file_get_contents('php://input');
$details = NotificationDetails::fromXml($rawXml);
$arr = array('type' => $details->getNotificationType(), 'timestamp' => $details->getTimestamp(), 'effective' => $details->getEffective(), 'networkOperatorId' => $details->getNetworkOperatorId(), 'ownerIdentifier' => $details->getOwnerIdentifier(), 'purchaseDate' => $details->getPurchaseDate(), 'productIdentifier' => $details->getProductIdentifier(), 'purchaseActivityIdentifier' => $details->getPurchaseActivityIdentifier(), 'instanceIdentifier' => $details->getInstanceIdentifier(), 'minIdentifier' => $details->getMinIdentifier(), 'oldMinIdentifier' => $details->getOldMinIdentifier(), 'sequenceNumber' => $details->getSequenceNumber(), 'reasonCode' => $details->getReasonCode(), 'reasonMessage' => $details->getReasonMessage(), 'vendorPurchaseIdentifier' => $details->getVendorPurchaseIdentifier());
$notifications = FileUtil::loadArray('notifications.db');
$notifications[] = $arr;
// limit on the number of entires
// TODO: Get limit from config
while (count($notifications) > 5) {
    array_shift($notifications);
}
FileUtil::saveArray($notifications, 'notifications.db');
 /**
  * Loads an array from the given file path.
  * 
  * This method uses file locks and is therefore synchornization-safe. 
  * This method will block until a file lock is acquired. 
  * 
  * @param string $fpath file path
  *
  * @return array array loaded from file path, or an empty array if fpath 
  * does not exist
  */
 public static function loadArray($fpath)
 {
     if (!file_exists($fpath)) {
         return array();
     }
     $handle = fopen($fpath, 'r');
     if (!$handle) {
         throw Exception('Unable to open file: ' . $fpath);
     }
     if (!flock($handle, LOCK_SH)) {
         throw Exception('Unable to get lock on ' . $fpath);
     }
     $content = fread($handle, FileUtil::_fsize($fpath));
     $arr = unserialize($content);
     if (!is_array($arr)) {
         return array();
     }
     flock($handle, LOCK_UN);
     fclose($handle);
     return $arr;
 }
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$postBody = file_get_contents('php://input');
$messageInfo = json_decode($postBody, true);
$msgsarr = FileUtil::loadArray(MSGS_FILE);
// TODO: Put value into config
while (count($msgsarr) > 5) {
    array_shift($msgsarr);
}
$msgsarr[] = $messageInfo;
FileUtil::saveArray($msgsarr, MSGS_FILE);
    $mmPart = explode("BASE64", $mimePart);
    $filename = null;
    $contentType = null;
    if (preg_match("@Name=([^;^\n]+)@i", $mmPart[0], $matches)) {
        $filename = trim($matches[1]);
    }
    if (preg_match("@Content-Type:([^;^\n]+)@i", $mmPart[0], $matches)) {
        $contentType = trim($matches[1]);
    }
    if ($contentType == null || $filename == null) {
        continue;
    }
    $base64Data = base64_decode($mmPart[1]);
    $filePath = $imagesPath . '/' . $message['id'] . '/' . $filename;
    $relativePath = $imagesPathName . '/' . $message['id'] . '/' . $filename;
    if (preg_match("@image@", $contentType)) {
        $message["image"] = $relativePath;
    }
    if (preg_match("@text@", $contentType)) {
        $message["text"] = $relativePath;
    }
    if (!($fileHandle = fopen($filePath, 'w'))) {
        die("Unable to open {$filePath}");
    }
    fwrite($fileHandle, $base64Data);
    fclose($fileHandle);
}
// TODO: set a limit on the number of messages saved
$messages[] = $message;
FileUtil::saveArray($messages, $imagesDbPath);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
$path = __DIR__;
$fname = $path . '/msgs.db';
$postBody = file_get_contents('php://input');
$asArray = true;
$messageInfo = json_decode($postBody, $asArray);
$msgsarr = FileUtil::loadArray($fname);
// TODO: Put value into config
while (count($msgsarr) > 5) {
    array_shift($msgsarr);
}
$msgsarr[] = $messageInfo;
FileUtil::saveArray($msgsarr, $fname);
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/Util/FileUtil.php';
use Att\Api\Util\FileUtil;
// TODO: set a limit on the number of notifications saved
// currently the number will keep growing without bound
$rawNotification = file_get_contents('php://input');
$notifications = json_decode($rawNotification, true);
if ($notifications == null) {
    return;
}
$arr = FileUtil::loadArray(NOTIFICATION_FILE);
$msgNotifications = null;
if (isset($notifications['notifications'])) {
    $msgNotifications = $notifications['notification'];
} else {
    $msgNotifications = $notifications['messageNotifications'];
}
if (isset($msgNotifications['subscriptions'])) {
    $arr[] = $msgNotifications['subscriptions'];
} else {
    $arr[] = $msgNotifications['subscriptionNotifications'];
}
FileUtil::saveArray($arr, NOTIFICATION_FILE);
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */