From c80bc0ae2f08262c1c62a23e319f54481c00278e Mon Sep 17 00:00:00 2001 From: Craig D'Amelio Date: Thu, 18 Dec 2014 10:29:44 -0500 Subject: [PATCH 1/2] Update snapchat_agent.php separate isMedia into isImage and isVideo functions which can be used independently to identify if the media is an image or a video. The isMedia function relies on the individual functions and allows a consumer of this class to use these headers which are much more accurate than the media_type attribute which I have (anecdotally) found to be unreliable. --- src/snapchat_agent.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/snapchat_agent.php b/src/snapchat_agent.php index 1dc22a9..1ddfe8c 100644 --- a/src/snapchat_agent.php +++ b/src/snapchat_agent.php @@ -176,17 +176,35 @@ public function hash($first, $second) { * TRUE if the blob looks like a media file, FALSE otherwise. */ function isMedia($data) { + return isImage($data) || isVideo($data); + } + + /** + * Checks to see if a blob looks like an image file. + * + * @param data $data + * The blob data (or just the header). + * + * @return bool + * TRUE if the blob looks like an image (jpeg), FALSE otherwise. + */ + function isImage($data) { // Check for a JPG header. - if ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)) { - return TRUE; - } - + return ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)) + } + + /** + * Checks to see if a blob looks like a video file. + * + * @param data $data + * The blob data (or just the header). + * + * @return bool + * TRUE if the blob looks like an video (mp4), FALSE otherwise. + */ + function isVideo($data) { // Check for a MP4 header. - if ($data[0] == chr(0x00) && $data[1] == chr(0x00)) { - return TRUE; - } - - return FALSE; + return ($data[0] == chr(0x00) && $data[1] == chr(0x00)); } /** From 00fc2562dcf6c475336ee580eccf86a850a5ec03 Mon Sep 17 00:00:00 2001 From: Craig D'Amelio Date: Thu, 18 Dec 2014 12:11:29 -0500 Subject: [PATCH 2/2] Update snapchat_agent.php terrible syntax error, dropped a semicolon --- src/snapchat_agent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snapchat_agent.php b/src/snapchat_agent.php index 1ddfe8c..a9e66c9 100644 --- a/src/snapchat_agent.php +++ b/src/snapchat_agent.php @@ -190,7 +190,7 @@ function isMedia($data) { */ function isImage($data) { // Check for a JPG header. - return ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)) + return ($data[0] == chr(0xFF) && $data[1] == chr(0xD8)); } /**