/** * Create a new Payload object with the given status. * * @param mixed $status * * @return Payload */ public function createPayload($status = null) { $payload = new Payload(); if ($status) { $payload->setStatus($status); } return $payload; }
/** * @param $locKey * @param $locArgs * @param $message * @param $actionLocKey * @param $launchImage * @param $badge * @param $sound * @param $payload * @param $contentAvailable * @return string * @throws \UnexpectedValueException * @throws \InvalidArgumentException */ public static function processPayload($locKey, $locArgs, $message, $actionLocKey, $launchImage, $badge, $sound, $payload, $contentAvailable) { $isValid = false; $pb = new Payload(); if ($locKey !== null && strlen($locKey) > 0) { // loc-key $pb->setAlertLocKey($locKey); // loc-args if ($locArgs !== null && strlen($locArgs) > 0) { $pb->setAlertLocArgs(explode(',', $locArgs)); } $isValid = true; } // body if ($message !== null && strlen($message) > 0) { $pb->setAlertBody($message); $isValid = true; } // action-loc-key if ($actionLocKey !== null && strlen($actionLocKey) > 0) { $pb->setAlertActionLocKey($actionLocKey); } // launch-image if ($launchImage !== null && strlen($launchImage) > 0) { $pb->setAlertLaunchImage($launchImage); } // badge $badgeNum = -1; if (is_numeric($badge)) { $badgeNum = (int) $badge; } if ($badgeNum >= 0) { $pb->setBadge($badgeNum); $isValid = true; } // sound if ($sound !== null && strlen($sound) > 0) { $pb->setSound($sound); } else { $pb->setSound('default'); } //contentAvailable if ($contentAvailable === 1) { $pb->setContentAvailable(1); $isValid = true; } // payload if ($payload !== null && strlen($payload) > 0) { $pb->addParam('payload', $payload); } if ($isValid === false) { throw new \UnexpectedValueException('one of the params(locKey,message,badge) must not be null or contentAvailable must be 1'); } $json = $pb->toString(); if ($json === null) { throw new \UnexpectedValueException('payload json is null'); } return $json; }
private function prepareEmptyYoRequest(Payload $payload = null) { $request = new HTTP\Request(); $request->https = true; $request->host = 'api.justyo.co'; $request->parameters = ['api_token' => $this->apiToken]; if (!empty($payload)) { $request->parameters += $payload->toHTTPParameters(); } return $request; }
/** * Returns true, if the error response is a Perun exception. * * @return boolean */ public function isPerunException() { $isPerunException = $this->payload->getParam(self::PARAM_ERROR_IS_PERUN_EXCEPTION); if ($isPerunException && $isPerunException == 'true') { return true; } return false; }
public function test() { $payload = new Payload(); $payload->setStatus($payload::SUCCESS)->setInput('input')->setOutput('output')->setMessages('messages')->setExtras('extras'); $this->assertSame($payload::SUCCESS, $payload->getStatus()); $this->assertSame('input', $payload->getInput()); $this->assertSame('output', $payload->getOutput()); $this->assertSame('messages', $payload->getMessages()); $this->assertSame('extras', $payload->getExtras()); }
private function process_notification() { // Create notification item // $payload = Payload::PayloadJSON(array('alert' => 'process_notification() notification.', 'sound' => 'default'), array('metadata' => 'extra stuff')); $notificationItem = new APNsNotificationItem('38592f807b0e8d0dc284b6e9711c61504d04a988af9b626d83c56f6704904c4a', $payload, 'notificationidentifier', null, null); // Create notification // $notification = new APNsNotification(APNS_NOTIFICATION_COMMAND_PUSH, APNS_NOTIFICATION_FRAME_LENGTH, array($notificationItem)); // Send notification // $this->APNsManager->sendNotification($notification); }
public function testGetSet() { $obj = new Payload('application/json'); $obj = new Payload('application/json', '{"name":"aaron"}'); $this->assertSame('application/json', $obj->getContentType()); $this->assertSame('{"name":"aaron"}', $obj->getContent()); $subject = <<<EOD { "collection" : { "version" : "1.0", "href" : "http://example.org/friends/" } } EOD; $obj->setContentType('application/vnd.collection+json'); $obj->setContent($subject); $this->assertSame('application/vnd.collection+json', $obj->getContentType()); $this->assertSame($subject, $obj->getContent()); }
public function testJsonSerialize() { $commit = new Payload(); $commit->setAfter('After'); $this->assertInternalType('array', $commit->jsonSerialize()); }
/** * Compare two labels for equality. * @param object $that object to compare * @return bool */ public function equals($that) { return parent::equals($that) && $this->userId == $that->userId; }
public function getIterator() { return new \ArrayIterator($this->payload->toArray()); }
<?php /** * RemoteCS - Convenient Remote Coding Standards Validation * This file should be called via HTTP from GitHub as a Webhook * Make sure the script has rights to run Git * * @author Tamas Kalman <*****@*****.**> */ require_once 'vendor/autoload.php'; require_once 'Payload.class.php'; require_once 'config.php'; $payload = new Payload(); $payload->log(); $result = $payload->downloadRepository(); if (!$result) { $payload->debugLog('Cannot run Git'); exit; } $problems = $payload->validateCommits(); $payload->removeSourceDir(); if ($problems !== true) { $payload->sendEmail($problems); $payload->debugLog($problems, 'problems-'); }
public function createResponse(Payload $payload) { return new Hal\Response($this->resourceFactory->createContactResource($this->contactStorage->read($payload->read('id')))); }
<?php error_reporting(E_ALL); ini_set('display_errors', 'on'); include 'db.php'; include 'payload.php'; $search = $_GET['search']; $db = new DB(); $sql = "SELECT * FROM Companies WHERE Name LIKE '%{$search}%'"; $results = $db->execute($sql); Payload::$values = []; while ($row = $results->fetch_assoc()) { $a = []; $a['Name'] = $row['Name']; $a['Industry'] = $row['Industry']; $a['Website'] = $row['Website']; array_push(Payload::$values, $a); } $payload = json_encode(Payload::$values); print_r(Payload::$values); ?> <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form> <input type="text" name="search" placeholder="Find a company rating" size="75"><br>
<?php require_once 'includes/config.php'; require_once 'class/payload.class.php'; if (isset($_POST['create'])) { $name = $_POST['name']; $code_url = $_POST['code_url']; $code_inject = $_POST['code_inject']; $payload = new Payload(); $payload->setName($name); $payload->setUrl($code_url); $payload->setCode($code_inject); $payload->insertpayload(); echo $payload->status; } ?> <div class="panel"> <div class="ui pointing menu"> <a href="index.php?action=panel" class="item">Logs</a> <a href="index.php?action=payload" class="active item">Custom payload</a> <a href="logout.php" class="item">Logout</a> <div class="right menu"> <div class="item"> <div class="ui transparent icon input"> <input type="text" placeholder="Search..."> <i class="fa fa-search"></i> </div> </div> <a class="item">Welcome <?php echo $_SESSION['username']; ?>
/** * Send message to the websocket * @param int $type * @param string $message * @param int $id * @param int $endpoint * @return Client * @throws \InvalidArgumentException * @throws \RuntimeException */ public function send($type, $message = NULL, $id = NULL, $endpoint = NULL) { if (!is_int($type) || $type > 8) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } $raw_message = $type . ':' . $id . ':' . $endpoint . ':' . $message; $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(TRUE)->setPayload($raw_message); $encoded = $payload->encodePayload(); $res = @fwrite($this->fd, $encoded); if ($res === 0) { $error = error_get_last(); throw new \RuntimeException($error['message'], $error['code']); } return $this; }
/** * Method to produce and return a consistent Payload object. * * Use this when a translation fails. * * @param \AKlump\Http\Transfer\Payload $payload [description] * * @return \AKlump\Http\Transfer\Payload A new payload containing a failure message. */ public static function failedTranslation($payload) { $obj = new Payload('text/error'); $obj->setContent('Unable to recognize/translate mime type: ' . $payload->getContentType()); return $obj; }
public static function attend(Inputter $inputter, JSONOutputter $outputter) { // List Created // // Constants // // Verify input // $required_keys = array('attending_user_identification' => '', 'event_identification' => '', 'attending_status' => ''); $inputter->validate_input($required_keys, null); // Validate input // $validate_error = null; UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array['attending_user_identification'], $validate_error); UniversallyUniqueIdentifier::propertyIsValid('rawIdentifier', $inputter->variables_array['event_identification'], $validate_error); if (isset($validate_error)) { $outputter->print_error($validate_error); } // Attending status // $inputter->variables_array['attending_status'] = intval($inputter->variables_array['attending_status']); if ($inputter->variables_array['attending_status'] < 0 || $inputter->variables_array['attending_status'] > 2) { // Throw error, status is out of bounds // $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, $attending_status . ' is out of bounds.'); $outputter->print_error($error); } // Identification should exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:AttendingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['attending_user_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, $attending_user_identification . ' should be an existing user identification.')); } // Identification should exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:Event) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['event_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, $event_identification . ' should be an existing event identification.')); } // Attending user's cannot attend their own events // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (creator:CreatingUser)-[relationship:' . CREATINGUSER_RELATIONSHIP_NAME_EVENT . ']->(event:Event) ' . 'WHERE creator.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['attending_user_identification'] . "' AND event." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['event_identification'] . "' " . 'RETURN relationship'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (isset($result_check_object[0]) && isset($result_check_object[0]['relationship'])) { // Throw error, cannot attend own event // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'Cannot attend own event.')); } // Events // $query_string = 'MATCH (attendingUser:AttendingUser), (event:Event)-[:' . EVENT_RELATIONSHIP_NAME_CREATOR . ']->(creatingUser:CreatingUser) ' . 'WHERE attendingUser.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['attending_user_identification'] . "' AND event." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['event_identification'] . "' " . 'RETURN attendingUser, event, creatingUser'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); if ($result->count() <= 0) { $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'No results returned.')); } $attendingUser = $result[0]['attendingUser']; $event = $result[0]['event']; $creatingUser = $result[0]['creatingUser']; // Get relationship // $query_string = 'OPTIONAL MATCH (attendingUser:AttendingUser)-[relationship:' . ATTENDINGUSER_RELATIONSHIP_NAME_RSVP . ']->(event:Event) ' . 'WHERE attendingUser.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['attending_user_identification'] . "' AND event." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['event_identification'] . "' " . 'RETURN relationship'; $query = new Everyman\Neo4j\Cypher\Query($client, $query_string); $result = $query->getResultSet(); if ($result->count() <= 0) { $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'No results returned.')); } $relationship = $result[0]['relationship']; if (!isset($relationship)) { // Create relationship as it's not created yet // $relationship = $client->makeRelationship()->setStartNode($attendingUser)->setEndNode($event)->setType(ATTENDINGUSER_RELATIONSHIP_NAME_RSVP)->setProperty(ATTENDINGUSER_RELATIONSHIP_NAME_RSVP_PROPERTY_NAME_ATTENDING_STATUS, $inputter->variables_array['attending_status'])->save(); } if (!isset($relationship)) { $error = Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'Problem attending event'); $outputter->print_error($error); } else { $relationship->setProperty(ATTENDINGUSER_RELATIONSHIP_NAME_RSVP_PROPERTY_NAME_ATTENDING_STATUS, $inputter->variables_array['attending_status'])->save(); } // 4) Send notifications // if ($inputter->variables_array['attending_status'] == ATTENDINGUSER_RELATIONSHIP_NAME_RSVP_PROPERTY_VALUE_ATTENDING_STATUS_ATTENDING) { $name = $attendingUser->getProperty(CREATINGUSER_KEY_FIRST_NAME); if (!isset($name)) { $name = $attendingUser->getProperty(CREATINGUSER_KEY_NAME); } $identifiers = $creatingUser->getProperty(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS); if (isset($identifiers) && is_array($identifiers) && count($identifiers) > 0) { foreach ($identifiers as $identifier) { // Create notification item // $payload = Payload::PayloadJSON(array('alert' => $name . " is attending you're event.", 'sound' => 'default'), array()); $notificationItem = new APNsNotificationItem($identifier, $payload, 'notificationIdentifier', null, null); // Create notification // $notification = new APNsNotification(APNS_NOTIFICATION_COMMAND_PUSH, APNS_NOTIFICATION_FRAME_LENGTH, array($notificationItem)); // Send notification // $inputter->notificationController->APNsManager->sendNotification($notification); } } } // 5) Print data // $outputter->print_data(array(array('attending_status' => $inputter->variables_array['attending_status']))); }
/** * Send message to the websocket * * @access public * @param int $type * @param int $id * @param int $endpoint * @param string $message * @return ElephantIO\Client */ public function send($type, $ns = null, $event = null, $data = null) { if (!is_int($type)) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } /*$raw_message = $type.':'.$id.':'.$endpoint.':'.$message;*/ $raw_message = $type; if ($ns && $ns != '/') { $raw_message .= $ns; } if ($event) { $raw_message .= ',["' . $event . '"'; if (!empty($data)) { $raw_message .= ',' . json_encode($data); } $raw_message .= ']'; } $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(true)->setPayload($raw_message); $encoded = $payload->encodePayload(); if (is_resource($this->fd)) { fwrite($this->fd, $encoded); // wait 100ms before closing connection usleep(100 * 1000); $this->log('debug', 'Sent ' . $raw_message); } return $this; }
<?php /** * This code is generating JWT of a product. * * @copyright 2013 Google Inc. All rights reserved. * @author Rohit Panwar <*****@*****.**> */ /** * JWT class to encode/decode payload into JWT format. */ include_once "JWT.php"; /** * Get payload of the product. */ include_once "payload.php"; $user_id = get_current_user_id(); $sellerIdentifier = $merchantid; $sellerSecretKey = $merchantkey; $payload = new Payload(); $payload->SetIssuedAt(time()); $payload->SetExpiration(time() + 3600); $payload->AddProperty("name", "{$post_title}"); $payload->AddProperty("description", "{$post_title}"); $payload->AddProperty("price", "{$payable_amount}"); $payload->AddProperty("currencyCode", "{$currency_code}"); $payload->AddProperty("sellerData", "user_id:{$user_id},post_id:{$last_postid}"); // Creating payload of the product. $Token = $payload->CreatePayload($sellerIdentifier); // Encoding payload into JWT format. $jwtToken = JWT::encode($Token, $sellerSecretKey);
* * @author Rohit Panwar <*****@*****.**> * * This code is generating JWT of a product. */ /** * JWT class to encode/decode payload into JWT format. */ include_once 'lib/JWT.php'; /** * Get merchant account information. */ include_once 'seller_info.php'; /** * Get payload of the product. */ include_once 'payload.php'; $sellerIdentifier = SellerInfo::$issuerId; $sellerSecretKey = SellerInfo::$secretKey; $payload = new Payload(); $payload->SetIssuedAt(time()); $payload->SetExpiration(time() + 3600); $payload->AddProperty('name', 'Piece of Cake'); $payload->AddProperty('description', 'Virtual chocolate cake to fill your virtual tummy'); $payload->AddProperty('price', '10.50'); $payload->AddProperty('currencyCode', 'USD'); $payload->AddProperty('sellerData', 'user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j'); // Creating payload of the product. $Token = $payload->CreatePayload($sellerIdentifier); // Encoding payload into JWT format. $jwtToken = JWT::encode($Token, $sellerSecretKey);
/** * @param $message * @param int $opCode * @param bool $mask * * @return string */ private function encode($message, $opCode = Payload::OPCODE_TEXT, $mask = true) { $payload = new Payload(); return $payload->setOpcode($opCode)->setMask($mask)->setPayload($message)->encodePayload(); }
public function testSubject() { $subjectA = $this->getMock('\\stdClass'); $subjectB = $this->getMock('\\stdClass'); $payload = new Payload('id', $subjectA); $this->assertSame($subjectA, $payload->getSubject()); $payload->setSubject($subjectB); $this->assertSame($subjectB, $payload->getSubject()); }
* This code is generating JWT of a product. * * @copyright 2013 Google Inc. All rights reserved. * @author Rohit Panwar <*****@*****.**> */ /** * JWT class to encode/decode payload into JWT format. */ include_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/payment/google_jwt.php'; /** * Get merchant account information. */ include_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/payment/google_seler_info.php'; /** * Get payload of the product. */ include_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/payment/google_payload.php'; $sellerIdentifier = SellerInfo::$issuerId; $sellerSecretKey = SellerInfo::$secretKey; $payload = new Payload(); $payload->SetIssuedAt(time()); $payload->SetExpiration(time() + 3600); $payload->AddProperty("name", "Piece of Cake"); $payload->AddProperty("description", "Virtual chocolate cake to fill your virtual tummy"); $payload->AddProperty("price", "10.50"); $payload->AddProperty("currencyCode", "USD"); $payload->AddProperty("sellerData", "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j"); // Creating payload of the product. $Token = $payload->CreatePayload($sellerIdentifier); // Encoding payload into JWT format. $jwtToken = JWT::encode($Token, $sellerSecretKey);
#!/usr/bin/php <?php /** * GitHub Command Line Payload tester * Outputs a Payload log file in human readable format * * @author Tamas Kalman <*****@*****.**> */ require_once 'vendor/autoload.php'; require_once 'Payload.class.php'; require_once 'config.php'; $filename = isset($argv[1]) ? $argv[1] : null; if (!$filename) { printf("Usage: %s <logfile>\n", basename(__FILE__)); exit; } $payload = new Payload(); $result = $payload->loadPayloadFromLog($filename); if ($result === false) { printf("Can't load logfile: [%s]\n", $filename); exit; } $payload->downloadRepository(); $problems = $payload->validateCommits(); $payload->removeSourceDir(); if ($problems !== true) { $payload->sendEmail($problems); }
/** * Send message to the websocket * * @access public * @param int $type * @param int $id * @param int $endpoint * @param string $message * @return ElephantIO\Client */ public function send($type, $id = null, $endpoint = null, $message = null) { if (!is_int($type) || $type > 8) { throw new \InvalidArgumentException('ElephantIOClient::send() type parameter must be an integer strictly inferior to 9.'); } $raw_message = $type . ':' . $id . ':' . $endpoint . ':' . $message; $payload = new Payload(); $payload->setOpcode(Payload::OPCODE_TEXT)->setMask(true)->setPayload($raw_message); $encoded = $payload->encodePayload(); fwrite($this->fd, $encoded); // wait 100ms before closing connexion usleep(100 * 1000); $this->stdout('debug', 'Sent ' . $raw_message); return $this; }
public static function create(Inputter $inputter, JSONOutputter $outputter) { // Create // // 1) Test all data is available and valid // // Availability // $required_dictionary = array('user_identification' => '', 'user_to_follow_identification' => ''); $inputter->validate_input($required_dictionary, null); // Valid // // Identifiers // $validation_error = null; UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_identification'], $validation_error); UniversallyUniqueObject::propertyIsValid(UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION, $inputter->variables_array['user_to_follow_identification'], $validation_error); if (isset($validation_error)) { $outputter->print_error($validation_error); } // Different // if ($inputter->variables_array['user_identification'] === $inputter->variables_array['user_to_follow_identification']) { $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_INPUT_NOT_UNIQUE, 'Users cannot follow themselves.')); } // 2) Check request we want to process CAN go ahead // // Identification should exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:AttendingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_identification should be an existing user identification.')); } $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_object = 'MATCH (object:CreatingUser) ' . 'WHERE object.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_follow_identification'] . "' " . 'RETURN object'; $query_check_object = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_object); $result_check_object = $query_check_object->getResultSet(); if (!isset($result_check_object[0]['object'])) { // No user_to_follow_identification exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_ENTITY_DOES_NOT_EXIST, 'user_to_follow_identification should be an existing user identification.')); } // Connection might exist // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_check_connection = 'OPTIONAL MATCH (user:AttendingUser)-[following:' . ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW . ']->(user_to_follow:CreatingUser)-[follower: ' . CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER . ']->(user) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_follow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_follow_identification'] . "' " . 'RETURN following, follower'; $query_check_connection = new Everyman\Neo4j\Cypher\Query($client, $query_string_check_connection); $result_check_connection = $query_check_connection->getResultSet(); if (isset($result_check_connection[0]['following']) || isset($result_check_connection[0]['follower'])) { // At least one object exists // $outputter->print_error(Error::withDomain(PRIVATE_EVENTS_REST_CONTROLLER_ERROR_DOMAIN, PRIVATE_EVENTS_REST_CONTROLLER_ERROR_CODE_RELATIONSHIP_EXISTS, 'Connection already exists between users.')); } // 3) We've got the go ahead to process the request as it's intended - create a follow connection // // Get objects // $client = new Everyman\Neo4j\Client('events.sb04.stations.graphenedb.com', 24789); $client->getTransport()->setAuth('Events', '3TP9LHROhv8LIcGmbYzq'); $query_string_users = 'MATCH (user:AttendingUser), (user_to_follow:CreatingUser) ' . 'WHERE user.' . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_identification'] . "' AND user_to_follow." . UNIVERSALLY_UNIQUE_OBJECT_KEY_IDENTIFICATION . " = '" . $inputter->variables_array['user_to_follow_identification'] . "' " . 'RETURN user, user_to_follow'; $query_users = new Everyman\Neo4j\Cypher\Query($client, $query_string_users); $result_users = $query_users->getResultSet(); $user = $result_users[0]['user']; $user_to_follow = $result_users[0]['user_to_follow']; // Add relationship // $user->relateTo($user_to_follow, ATTENDINGUSER_RELATIONSHIP_NAME_FOLLOW)->save(); $user_to_follow->relateTo($user, CREATINGUSER_RELATIONSHIP_NAME_FOLLOWER)->save(); // 4) Send a notification to the new following user // // Send a notification to all of the devices of the following user telling them they have a new follower // $name = $user->getProperty(CREATINGUSER_KEY_FIRST_NAME); if (!isset($name)) { $name = $user->getProperty(CREATINGUSER_KEY_NAME); } $identifiers = $user_to_follow->getProperty(USER_KEY_NOTIFICATION_DEVICE_IDENTIFIERS); if (isset($identifiers) && is_array($identifiers) && count($identifiers) > 0) { foreach ($identifiers as $identifier) { // Create notification item // $payload = Payload::PayloadJSON(array('alert' => $name . ' has started following you.', 'sound' => 'default'), array('metadata' => 'extra stuff')); $notificationItem = new APNsNotificationItem($identifier, $payload, 'notificationIdentifier', null, null); // Create notification // $notification = new APNsNotification(APNS_NOTIFICATION_COMMAND_PUSH, APNS_NOTIFICATION_FRAME_LENGTH, array($notificationItem)); // Send notification // $inputter->notificationController->APNsManager->sendNotification($notification); } } // 5) Output results // // Print data // $outputter->print_data(array(array("user" => AttendingUser::printer_dictionary($user), "user_to_follow" => CreatingUser::printer_dictionary($user_to_follow)))); }
static function processPayload($locKey, $locArgs, $message, $actionLocKey, $launchImage, $badge, $sound, $payload) { $isValid = false; $pb = new Payload(); if ($locKey != null && strlen($locKey) > 0) { // loc-key $pb->setAlertLocKey($locKey); // loc-args if ($locArgs != null && strlen($locArgs) > 0) { $pb->setAlertLocArgs(explode(',', $locArgs)); } $isValid = true; } // body if ($message != null && strlen($message) > 0) { $pb->setAlertBody($message); $isValid = true; } // action-loc-key if ($actionLocKey != null && strlen($actionLocKey) > 0) { $pb->setAlertActionLocKey($actionLocKey); } // launch-image if ($launchImage != null && strlen($launchImage) > 0) { $pb->setAlertLaunchImage($launchImage); } // badge $badgeNum = -1; if (is_numeric($badge)) { $badgeNum = (int) $badge; } if ($badgeNum >= 0) { $pb->setBadge($badgeNum); $isValid = true; } // sound if ($sound != null && strlen($sound) > 0) { $pb->setSound($sound); } else { $pb->setSound("default"); } // payload if ($payload != null && strlen($payload) > 0) { $pb->addParam("payload", $payload); } if ($isValid == false) { throw new Exception("one of the params(locKey,message,badge) must not be null"); } $json = $pb->toString(); if ($json == null) { throw new Exception("payload json is null"); } return $json; }
/** * Get all Threads in the user's mailbox. * * @param Google_Service_Gmail $service Authorized Gmail API instance. * @param string $userId User's email address. The special value 'me' * can be used to indicate the authenticated user. * @return array Array of Threads. */ function listThreads($service, $maxResults) { $user = '******'; $pageToken = NULL; $opt_param = array(); $opt_param['includeSpamTrash'] = false; // $opt_param['maxResults'] = $maxResults; $opt_param['maxResults'] = 5; $opt_param['labelIds'] = 'INBOX'; $threads = array(); $threadsResponse = $service->users_threads->listUsersThreads($user, $opt_param); if ($threadsResponse->getThreads()) { $threads = array_merge($threads, $threadsResponse->getThreads()); } $threadsList = new ThreadList(); $mimeTypes = array("image/png", "image/bmp", "image/gif", "image/jpeg", "image/tiff"); foreach ($threads as $thread) { $threadItem = thread_get($service, $user, $thread->getId()); $threadObject = new Thread($threadItem->getId(), $threadItem->getHistoryId(), $threadItem->getSnippet()); $threadMessages = $threadItem->getMessages(); foreach ($threadMessages as $threadMessage) { $threadMessageObject = new Message($threadMessage->getId(), $threadMessage->getHistoryId(), $threadMessage->getSizeEstimate(), $threadMessage->getSnippet(), $threadMessage->getThreadId()); foreach ($threadMessage->getLabelIds() as $label) { $threadMessageObject->addLabels($label); } $payloads = $threadMessage->getPayload(); // gets parts $payloadObject = new Payload($payloads->getFilename(), $payloads->getMimeType(), $payloads->getPartId()); $payloadBody = $payloads->getBody(); $payloadBodyObject = new Body($payloadBody->getSize(), $payloadBody->getData(), $payloadBody->getAttachmentId()); $payloadObject->setBody($payloadBodyObject); $payloadHeaders = $payloads->getHeaders(); foreach ($payloadHeaders as $payloadHeader) { $payloadObject->addHeaders($payloadHeader->getName(), $payloadHeader->getValue()); } $payloadParts = $payloads->getParts(); foreach ($payloadParts as $payloadPart) { $payloadPartObject = new Part($payloadPart->getPartId(), $payloadPart->getMimeType(), $payloadPart->getFilename()); $partHeaders = $payloadPart->getHeaders(); foreach ($partHeaders as $partHeader) { $payloadPartObject->addHeaders($partHeader->getName(), $partHeader->getValue()); } $partBody = $payloadPart->getBody(); $mimeType = $payloadPart->getMimeType(); $fileName = $payloadPart->getFilename(); $partBodyData = $partBody->getData(); if ($mimeType == "text/html") { $partBodyData = stripStyle($partBodyData); } // get attachment if (in_array($mimeType, $mimeTypes)) { $payloadObject->setHasAttachments(true); $messageId = $threadMessage->getId(); $attachmentId = $partBody->getAttachmentId(); // $messageId = "1517ad66755a3a4e"; // $attachmentId = "ANGjdJ_NHguibEZ714ypsmh4AaLozb2ljIe9UnAwH9txKGemrt_5LedqDr3KZ6RLyw40lb5n584YB5ZKMOtiw5o9OT7ClArfD8PDezzdA7cOyf6HW0CNwK_L_vRDPiEoMBRfQljfntWQoC9oAr1C-PjC-wmMuEMDzhezghpQ5vqpKV4nBGhFZ8AHf4QAwvrtT0T8dgn3L6uKGce2WEAkUMKSdCDDAruntSb4cUA9joHouiJ9zFSzQz0Wwc4Ru2MSofkPMWi9F1f2pb1MdCgzUTMgfSEfoLbJGSYgNen5WES7t8OO8B1SPn2STcHOeNg"; $attachment = getAttachment($service, $user, $messageId, $attachmentId); $image = getAttachmentAndWrite($service, $user, $messageId, $attachmentId, $fileName, $mimeType); $payloadObject->addImage($image); $payloadPartObject->addBody(new Body($partBody->getSize(), $partBodyData, $partBody->getAttachmentId(), $attachment, $image)); } else { $payloadPartObject->addBody(new Body($partBody->getSize(), $partBodyData, $partBody->getAttachmentId())); } // ---------------------------------------------------------- $payloadPartsSub = $payloadPart->getParts(); foreach ($payloadPartsSub as $payloadPartSub) { $payloadPartSubObject = new Part($payloadPartSub->getPartId(), $payloadPartSub->getMimeType(), $payloadPartSub->getFilename()); $partHeaders = $payloadPartSub->getHeaders(); foreach ($partHeaders as $partHeader) { $payloadPartSubObject->addHeaders($partHeader->getName(), $partHeader->getValue()); } $partBody = $payloadPartSub->getBody(); $partBodyData = $partBody->getData(); if ($payloadPartSub->getMimeType() == "text/html") { $partBodyData = stripStyle($partBodyData); } $payloadPartSubObject->addBody(new Body($partBody->getSize(), $partBodyData, $partBody->getAttachmentId())); $payloadPartObject->addParts($payloadPartSubObject); } // ----------------------------------------------------------------------- $payloadObject->addParts($payloadPartObject); } if ($payloadObject->getHasAttachments()) { foreach ($payloadObject->getParts() as $key => $parts) { if ($parts->mimeType == "multipart/alternative") { foreach ($parts->getParts() as $key1 => $part) { if ($part->mimeType == "text/html") { $data = subImagesInHtml($part, $payloadObject->getImages()); $payloadObject->parts[$key]->parts[$key1]->body[0]->data = $data; } } } } } $threadMessageObject->setPayload($payloadObject); $threadObject->addMessage($threadMessageObject); } $threadsList->addThread($threadObject); } echo json_encode($threadsList); // echo json_last_error_msg(); }