From 8a49b1e80ecff023b43ecd3441e64f884648302b Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 28 May 2019 20:28:05 +0100 Subject: [PATCH] remove unmaintained chatbox / amazon_s3 exts --- ext/amazon_s3/lib/S3.php | 2389 ------------------------- ext/amazon_s3/main.php | 79 - ext/chatbox/cp/ajax.php | 486 ----- ext/chatbox/cp/css/style.css | 386 ---- ext/chatbox/cp/index.php | 45 - ext/chatbox/cp/js/admincp.js | 388 ---- ext/chatbox/css/dark.yshout.css | 389 ---- ext/chatbox/css/overlay.css | 93 - ext/chatbox/css/style.css | 113 -- ext/chatbox/history/css/style.css | 85 - ext/chatbox/history/index.php | 142 -- ext/chatbox/history/js/history.js | 276 --- ext/chatbox/include.php | 7 - ext/chatbox/js/yshout.js | 810 --------- ext/chatbox/logs/.htaccess | 4 - ext/chatbox/logs/log.1.txt | 1 - ext/chatbox/logs/yshout.bans.txt | 1 - ext/chatbox/logs/yshout.prefs.txt | 1 - ext/chatbox/main.php | 38 - ext/chatbox/php/ajaxcall.class.php | 314 ---- ext/chatbox/php/filestorage.class.php | 106 -- ext/chatbox/php/functions.php | 174 -- ext/chatbox/php/yshout.class.php | 292 --- ext/chatbox/preferences.php | 75 - ext/chatbox/smileys/biggrin.gif | Bin 172 -> 0 bytes ext/chatbox/smileys/confused.gif | Bin 171 -> 0 bytes ext/chatbox/smileys/cool.gif | Bin 172 -> 0 bytes ext/chatbox/smileys/cry.gif | Bin 498 -> 0 bytes ext/chatbox/smileys/eek.gif | Bin 170 -> 0 bytes ext/chatbox/smileys/evil.gif | Bin 236 -> 0 bytes ext/chatbox/smileys/lol.gif | Bin 336 -> 0 bytes ext/chatbox/smileys/mad.gif | Bin 174 -> 0 bytes ext/chatbox/smileys/mrgreen.gif | Bin 349 -> 0 bytes ext/chatbox/smileys/neutral.gif | Bin 171 -> 0 bytes ext/chatbox/smileys/razz.gif | Bin 176 -> 0 bytes ext/chatbox/smileys/redface.gif | Bin 650 -> 0 bytes ext/chatbox/smileys/rolleyes.gif | Bin 485 -> 0 bytes ext/chatbox/smileys/sad.gif | Bin 171 -> 0 bytes ext/chatbox/smileys/smile.gif | Bin 174 -> 0 bytes ext/chatbox/smileys/surprised.gif | Bin 174 -> 0 bytes ext/chatbox/smileys/twisted.gif | Bin 238 -> 0 bytes ext/chatbox/smileys/wink.gif | Bin 170 -> 0 bytes ext/chatbox/yshout.php | 39 - 43 files changed, 6733 deletions(-) delete mode 100644 ext/amazon_s3/lib/S3.php delete mode 100644 ext/amazon_s3/main.php delete mode 100644 ext/chatbox/cp/ajax.php delete mode 100644 ext/chatbox/cp/css/style.css delete mode 100644 ext/chatbox/cp/index.php delete mode 100644 ext/chatbox/cp/js/admincp.js delete mode 100644 ext/chatbox/css/dark.yshout.css delete mode 100644 ext/chatbox/css/overlay.css delete mode 100644 ext/chatbox/css/style.css delete mode 100644 ext/chatbox/history/css/style.css delete mode 100644 ext/chatbox/history/index.php delete mode 100644 ext/chatbox/history/js/history.js delete mode 100644 ext/chatbox/include.php delete mode 100644 ext/chatbox/js/yshout.js delete mode 100644 ext/chatbox/logs/.htaccess delete mode 100644 ext/chatbox/logs/log.1.txt delete mode 100644 ext/chatbox/logs/yshout.bans.txt delete mode 100644 ext/chatbox/logs/yshout.prefs.txt delete mode 100644 ext/chatbox/main.php delete mode 100644 ext/chatbox/php/ajaxcall.class.php delete mode 100644 ext/chatbox/php/filestorage.class.php delete mode 100644 ext/chatbox/php/functions.php delete mode 100644 ext/chatbox/php/yshout.class.php delete mode 100644 ext/chatbox/preferences.php delete mode 100644 ext/chatbox/smileys/biggrin.gif delete mode 100644 ext/chatbox/smileys/confused.gif delete mode 100644 ext/chatbox/smileys/cool.gif delete mode 100644 ext/chatbox/smileys/cry.gif delete mode 100644 ext/chatbox/smileys/eek.gif delete mode 100644 ext/chatbox/smileys/evil.gif delete mode 100644 ext/chatbox/smileys/lol.gif delete mode 100644 ext/chatbox/smileys/mad.gif delete mode 100644 ext/chatbox/smileys/mrgreen.gif delete mode 100644 ext/chatbox/smileys/neutral.gif delete mode 100644 ext/chatbox/smileys/razz.gif delete mode 100644 ext/chatbox/smileys/redface.gif delete mode 100644 ext/chatbox/smileys/rolleyes.gif delete mode 100644 ext/chatbox/smileys/sad.gif delete mode 100644 ext/chatbox/smileys/smile.gif delete mode 100644 ext/chatbox/smileys/surprised.gif delete mode 100644 ext/chatbox/smileys/twisted.gif delete mode 100644 ext/chatbox/smileys/wink.gif delete mode 100644 ext/chatbox/yshout.php diff --git a/ext/amazon_s3/lib/S3.php b/ext/amazon_s3/lib/S3.php deleted file mode 100644 index 660844c4..00000000 --- a/ext/amazon_s3/lib/S3.php +++ /dev/null @@ -1,2389 +0,0 @@ - $host, 'type' => $type, 'user' => $user, 'pass' => $pass); - } - - - /** - * Set the error mode to exceptions - * - * @param boolean $enabled Enable exceptions - * @return void - */ - public static function setExceptions($enabled = true) - { - self::$useExceptions = $enabled; - } - - - /** - * Set AWS time correction offset (use carefully) - * - * This can be used when an inaccurate system time is generating - * invalid request signatures. It should only be used as a last - * resort when the system time cannot be changed. - * - * @param string $offset Time offset (set to zero to use AWS server time) - * @return void - */ - public static function setTimeCorrectionOffset($offset = 0) - { - if ($offset == 0) - { - $rest = new S3Request('HEAD'); - $rest = $rest->getResponse(); - $awstime = $rest->headers['date']; - $systime = time(); - $offset = $systime > $awstime ? -($systime - $awstime) : ($awstime - $systime); - } - self::$__timeOffset = $offset; - } - - - /** - * Set signing key - * - * @param string $keyPairId AWS Key Pair ID - * @param string $signingKey Private Key - * @param boolean $isFile Load private key from file, set to false to load string - * @return boolean - */ - public static function setSigningKey($keyPairId, $signingKey, $isFile = true) - { - self::$__signingKeyPairId = $keyPairId; - if ((self::$__signingKeyResource = openssl_pkey_get_private($isFile ? - file_get_contents($signingKey) : $signingKey)) !== false) return true; - self::__triggerError('S3::setSigningKey(): Unable to open load private key: '.$signingKey, __FILE__, __LINE__); - return false; - } - - - /** - * Free signing key from memory, MUST be called if you are using setSigningKey() - * - * @return void - */ - public static function freeSigningKey() - { - if (self::$__signingKeyResource !== false) - openssl_free_key(self::$__signingKeyResource); - } - - - /** - * Internal error handler - * - * @internal Internal error handler - * @param string $message Error message - * @param string $file Filename - * @param integer $line Line number - * @param integer $code Error code - * @return void - */ - private static function __triggerError($message, $file, $line, $code = 0) - { - if (self::$useExceptions) - throw new S3Exception($message, $file, $line, $code); - else - trigger_error($message, E_USER_WARNING); - } - - - /** - * Get a list of buckets - * - * @param boolean $detailed Returns detailed bucket list when true - * @return array | false - */ - public static function listBuckets($detailed = false) - { - $rest = new S3Request('GET', '', '', self::$endpoint); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::listBuckets(): [%s] %s", $rest->error['code'], - $rest->error['message']), __FILE__, __LINE__); - return false; - } - $results = array(); - if (!isset($rest->body->Buckets)) return $results; - - if ($detailed) - { - if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) - $results['owner'] = array( - 'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName - ); - $results['buckets'] = array(); - foreach ($rest->body->Buckets->Bucket as $b) - $results['buckets'][] = array( - 'name' => (string)$b->Name, 'time' => strtotime((string)$b->CreationDate) - ); - } else - foreach ($rest->body->Buckets->Bucket as $b) $results[] = (string)$b->Name; - - return $results; - } - - - /** - * Get contents for a bucket - * - * If maxKeys is null this method will loop through truncated result sets - * - * @param string $bucket Bucket name - * @param string $prefix Prefix - * @param string $marker Marker (last file listed) - * @param string $maxKeys Max keys (maximum number of keys to return) - * @param string $delimiter Delimiter - * @param boolean $returnCommonPrefixes Set to true to return CommonPrefixes - * @return array | false - */ - public static function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null, $returnCommonPrefixes = false) - { - $rest = new S3Request('GET', $bucket, '', self::$endpoint); - if ($maxKeys == 0) $maxKeys = null; - if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix); - if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker); - if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys); - if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter); - else if (!empty(self::$defDelimiter)) $rest->setParameter('delimiter', self::$defDelimiter); - $response = $rest->getResponse(); - if ($response->error === false && $response->code !== 200) - $response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status'); - if ($response->error !== false) - { - self::__triggerError(sprintf("S3::getBucket(): [%s] %s", - $response->error['code'], $response->error['message']), __FILE__, __LINE__); - return false; - } - - $results = array(); - - $nextMarker = null; - if (isset($response->body, $response->body->Contents)) - foreach ($response->body->Contents as $c) - { - $results[(string)$c->Key] = array( - 'name' => (string)$c->Key, - 'time' => strtotime((string)$c->LastModified), - 'size' => (int)$c->Size, - 'hash' => substr((string)$c->ETag, 1, -1) - ); - $nextMarker = (string)$c->Key; - } - - if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes)) - foreach ($response->body->CommonPrefixes as $c) - $results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix); - - if (isset($response->body, $response->body->IsTruncated) && - (string)$response->body->IsTruncated == 'false') return $results; - - if (isset($response->body, $response->body->NextMarker)) - $nextMarker = (string)$response->body->NextMarker; - - // Loop through truncated results if maxKeys isn't specified - if ($maxKeys == null && $nextMarker !== null && (string)$response->body->IsTruncated == 'true') - do - { - $rest = new S3Request('GET', $bucket, '', self::$endpoint); - if ($prefix !== null && $prefix !== '') $rest->setParameter('prefix', $prefix); - $rest->setParameter('marker', $nextMarker); - if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter); - - if (($response = $rest->getResponse()) == false || $response->code !== 200) break; - - if (isset($response->body, $response->body->Contents)) - foreach ($response->body->Contents as $c) - { - $results[(string)$c->Key] = array( - 'name' => (string)$c->Key, - 'time' => strtotime((string)$c->LastModified), - 'size' => (int)$c->Size, - 'hash' => substr((string)$c->ETag, 1, -1) - ); - $nextMarker = (string)$c->Key; - } - - if ($returnCommonPrefixes && isset($response->body, $response->body->CommonPrefixes)) - foreach ($response->body->CommonPrefixes as $c) - $results[(string)$c->Prefix] = array('prefix' => (string)$c->Prefix); - - if (isset($response->body, $response->body->NextMarker)) - $nextMarker = (string)$response->body->NextMarker; - - } while ($response !== false && (string)$response->body->IsTruncated == 'true'); - - return $results; - } - - - /** - * Put a bucket - * - * @param string $bucket Bucket name - * @param constant $acl ACL flag - * @param string $location Set as "EU" to create buckets hosted in Europe - * @return boolean - */ - public static function putBucket($bucket, $acl = self::ACL_PRIVATE, $location = false) - { - $rest = new S3Request('PUT', $bucket, '', self::$endpoint); - $rest->setAmzHeader('x-amz-acl', $acl); - - if ($location !== false) - { - $dom = new DOMDocument; - $createBucketConfiguration = $dom->createElement('CreateBucketConfiguration'); - $locationConstraint = $dom->createElement('LocationConstraint', $location); - $createBucketConfiguration->appendChild($locationConstraint); - $dom->appendChild($createBucketConfiguration); - $rest->data = $dom->saveXML(); - $rest->size = strlen($rest->data); - $rest->setHeader('Content-Type', 'application/xml'); - } - $rest = $rest->getResponse(); - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::putBucket({$bucket}, {$acl}, {$location}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Delete an empty bucket - * - * @param string $bucket Bucket name - * @return boolean - */ - public static function deleteBucket($bucket) - { - $rest = new S3Request('DELETE', $bucket, '', self::$endpoint); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 204) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::deleteBucket({$bucket}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Create input info array for putObject() - * - * @param string $file Input file - * @param mixed $md5sum Use MD5 hash (supply a string if you want to use your own) - * @return array | false - */ - public static function inputFile($file, $md5sum = true) - { - if (!file_exists($file) || !is_file($file) || !is_readable($file)) - { - self::__triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__); - return false; - } - clearstatcache(false, $file); - return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ? - (is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : ''); - } - - - /** - * Create input array info for putObject() with a resource - * - * @param string $resource Input resource to read from - * @param integer $bufferSize Input byte size - * @param string $md5sum MD5 hash to send (optional) - * @return array | false - */ - public static function inputResource(&$resource, $bufferSize = false, $md5sum = '') - { - if (!is_resource($resource) || (int)$bufferSize < 0) - { - self::__triggerError('S3::inputResource(): Invalid resource or buffer size', __FILE__, __LINE__); - return false; - } - - // Try to figure out the bytesize - if ($bufferSize === false) - { - if (fseek($resource, 0, SEEK_END) < 0 || ($bufferSize = ftell($resource)) === false) - { - self::__triggerError('S3::inputResource(): Unable to obtain resource size', __FILE__, __LINE__); - return false; - } - fseek($resource, 0); - } - - $input = array('size' => $bufferSize, 'md5sum' => $md5sum); - $input['fp'] =& $resource; - return $input; - } - - - /** - * Put an object - * - * @param mixed $input Input data - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param constant $acl ACL constant - * @param array $metaHeaders Array of x-amz-meta-* headers - * @param array $requestHeaders Array of request headers or content type as a string - * @param constant $storageClass Storage class constant - * @param constant $serverSideEncryption Server-side encryption - * @return boolean - */ - public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD, $serverSideEncryption = self::SSE_NONE) - { - if ($input === false) return false; - $rest = new S3Request('PUT', $bucket, $uri, self::$endpoint); - - if (!is_array($input)) $input = array( - 'data' => $input, 'size' => strlen($input), - 'md5sum' => base64_encode(md5($input, true)) - ); - - // Data - if (isset($input['fp'])) - $rest->fp =& $input['fp']; - elseif (isset($input['file'])) - $rest->fp = @fopen($input['file'], 'rb'); - elseif (isset($input['data'])) - $rest->data = $input['data']; - - // Content-Length (required) - if (isset($input['size']) && $input['size'] >= 0) - $rest->size = $input['size']; - else { - if (isset($input['file'])) { - clearstatcache(false, $input['file']); - $rest->size = filesize($input['file']); - } - elseif (isset($input['data'])) - $rest->size = strlen($input['data']); - } - - // Custom request headers (Content-Type, Content-Disposition, Content-Encoding) - if (is_array($requestHeaders)) - foreach ($requestHeaders as $h => $v) - strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v); - elseif (is_string($requestHeaders)) // Support for legacy contentType parameter - $input['type'] = $requestHeaders; - - // Content-Type - if (!isset($input['type'])) - { - if (isset($requestHeaders['Content-Type'])) - $input['type'] =& $requestHeaders['Content-Type']; - elseif (isset($input['file'])) - $input['type'] = self::__getMIMEType($input['file']); - else - $input['type'] = 'application/octet-stream'; - } - - if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class - $rest->setAmzHeader('x-amz-storage-class', $storageClass); - - if ($serverSideEncryption !== self::SSE_NONE) // Server-side encryption - $rest->setAmzHeader('x-amz-server-side-encryption', $serverSideEncryption); - - // We need to post with Content-Length and Content-Type, MD5 is optional - if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false)) - { - $rest->setHeader('Content-Type', $input['type']); - if (isset($input['md5sum'])) $rest->setHeader('Content-MD5', $input['md5sum']); - - $rest->setAmzHeader('x-amz-acl', $acl); - foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v); - $rest->getResponse(); - } else - $rest->response->error = array('code' => 0, 'message' => 'Missing input parameters'); - - if ($rest->response->error === false && $rest->response->code !== 200) - $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); - if ($rest->response->error !== false) - { - self::__triggerError(sprintf("S3::putObject(): [%s] %s", - $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Put an object from a file (legacy function) - * - * @param string $file Input file path - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param constant $acl ACL constant - * @param array $metaHeaders Array of x-amz-meta-* headers - * @param string $contentType Content type - * @return boolean - */ - public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null) - { - return self::putObject(self::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType); - } - - - /** - * Put an object from a string (legacy function) - * - * @param string $string Input data - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param constant $acl ACL constant - * @param array $metaHeaders Array of x-amz-meta-* headers - * @param string $contentType Content type - * @return boolean - */ - public static function putObjectString($string, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = 'text/plain') - { - return self::putObject($string, $bucket, $uri, $acl, $metaHeaders, $contentType); - } - - - /** - * Get an object - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param mixed $saveTo Filename or resource to write to - * @return mixed - */ - public static function getObject($bucket, $uri, $saveTo = false) - { - $rest = new S3Request('GET', $bucket, $uri, self::$endpoint); - if ($saveTo !== false) - { - if (is_resource($saveTo)) - $rest->fp =& $saveTo; - else - if (($rest->fp = @fopen($saveTo, 'wb')) !== false) - $rest->file = realpath($saveTo); - else - $rest->response->error = array('code' => 0, 'message' => 'Unable to open save file for writing: '.$saveTo); - } - if ($rest->response->error === false) $rest->getResponse(); - - if ($rest->response->error === false && $rest->response->code !== 200) - $rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status'); - if ($rest->response->error !== false) - { - self::__triggerError(sprintf("S3::getObject({$bucket}, {$uri}): [%s] %s", - $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__); - return false; - } - return $rest->response; - } - - - /** - * Get object information - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param boolean $returnInfo Return response information - * @return mixed | false - */ - public static function getObjectInfo($bucket, $uri, $returnInfo = true) - { - $rest = new S3Request('HEAD', $bucket, $uri, self::$endpoint); - $rest = $rest->getResponse(); - if ($rest->error === false && ($rest->code !== 200 && $rest->code !== 404)) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::getObjectInfo({$bucket}, {$uri}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return $rest->code == 200 ? $returnInfo ? $rest->headers : true : false; - } - - - /** - * Copy an object - * - * @param string $srcBucket Source bucket name - * @param string $srcUri Source object URI - * @param string $bucket Destination bucket name - * @param string $uri Destination object URI - * @param constant $acl ACL constant - * @param array $metaHeaders Optional array of x-amz-meta-* headers - * @param array $requestHeaders Optional array of request headers (content type, disposition, etc.) - * @param constant $storageClass Storage class constant - * @return mixed | false - */ - public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD) - { - $rest = new S3Request('PUT', $bucket, $uri, self::$endpoint); - $rest->setHeader('Content-Length', 0); - foreach ($requestHeaders as $h => $v) - strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v); - foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v); - if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class - $rest->setAmzHeader('x-amz-storage-class', $storageClass); - $rest->setAmzHeader('x-amz-acl', $acl); - $rest->setAmzHeader('x-amz-copy-source', sprintf('/%s/%s', $srcBucket, rawurlencode($srcUri))); - if (sizeof($requestHeaders) > 0 || sizeof($metaHeaders) > 0) - $rest->setAmzHeader('x-amz-metadata-directive', 'REPLACE'); - - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::copyObject({$srcBucket}, {$srcUri}, {$bucket}, {$uri}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return isset($rest->body->LastModified, $rest->body->ETag) ? array( - 'time' => strtotime((string)$rest->body->LastModified), - 'hash' => substr((string)$rest->body->ETag, 1, -1) - ) : false; - } - - - /** - * Set up a bucket redirection - * - * @param string $bucket Bucket name - * @param string $location Target host name - * @return boolean - */ - public static function setBucketRedirect($bucket = NULL, $location = NULL) - { - $rest = new S3Request('PUT', $bucket, '', self::$endpoint); - - if( empty($bucket) || empty($location) ) { - self::__triggerError("S3::setBucketRedirect({$bucket}, {$location}): Empty parameter.", __FILE__, __LINE__); - return false; - } - - $dom = new DOMDocument; - $websiteConfiguration = $dom->createElement('WebsiteConfiguration'); - $redirectAllRequestsTo = $dom->createElement('RedirectAllRequestsTo'); - $hostName = $dom->createElement('HostName', $location); - $redirectAllRequestsTo->appendChild($hostName); - $websiteConfiguration->appendChild($redirectAllRequestsTo); - $dom->appendChild($websiteConfiguration); - $rest->setParameter('website', null); - $rest->data = $dom->saveXML(); - $rest->size = strlen($rest->data); - $rest->setHeader('Content-Type', 'application/xml'); - $rest = $rest->getResponse(); - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::setBucketRedirect({$bucket}, {$location}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Set logging for a bucket - * - * @param string $bucket Bucket name - * @param string $targetBucket Target bucket (where logs are stored) - * @param string $targetPrefix Log prefix (e,g; domain.com-) - * @return boolean - */ - public static function setBucketLogging($bucket, $targetBucket, $targetPrefix = null) - { - // The S3 log delivery group has to be added to the target bucket's ACP - if ($targetBucket !== null && ($acp = self::getAccessControlPolicy($targetBucket, '')) !== false) - { - // Only add permissions to the target bucket when they do not exist - $aclWriteSet = false; - $aclReadSet = false; - foreach ($acp['acl'] as $acl) - if ($acl['type'] == 'Group' && $acl['uri'] == 'http://acs.amazonaws.com/groups/s3/LogDelivery') - { - if ($acl['permission'] == 'WRITE') $aclWriteSet = true; - elseif ($acl['permission'] == 'READ_ACP') $aclReadSet = true; - } - if (!$aclWriteSet) $acp['acl'][] = array( - 'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'WRITE' - ); - if (!$aclReadSet) $acp['acl'][] = array( - 'type' => 'Group', 'uri' => 'http://acs.amazonaws.com/groups/s3/LogDelivery', 'permission' => 'READ_ACP' - ); - if (!$aclReadSet || !$aclWriteSet) self::setAccessControlPolicy($targetBucket, '', $acp); - } - - $dom = new DOMDocument; - $bucketLoggingStatus = $dom->createElement('BucketLoggingStatus'); - $bucketLoggingStatus->setAttribute('xmlns', 'http://s3.amazonaws.com/doc/2006-03-01/'); - if ($targetBucket !== null) - { - if ($targetPrefix == null) $targetPrefix = $bucket . '-'; - $loggingEnabled = $dom->createElement('LoggingEnabled'); - $loggingEnabled->appendChild($dom->createElement('TargetBucket', $targetBucket)); - $loggingEnabled->appendChild($dom->createElement('TargetPrefix', $targetPrefix)); - // TODO: Add TargetGrants? - $bucketLoggingStatus->appendChild($loggingEnabled); - } - $dom->appendChild($bucketLoggingStatus); - - $rest = new S3Request('PUT', $bucket, '', self::$endpoint); - $rest->setParameter('logging', null); - $rest->data = $dom->saveXML(); - $rest->size = strlen($rest->data); - $rest->setHeader('Content-Type', 'application/xml'); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Get logging status for a bucket - * - * This will return false if logging is not enabled. - * Note: To enable logging, you also need to grant write access to the log group - * - * @param string $bucket Bucket name - * @return array | false - */ - public static function getBucketLogging($bucket) - { - $rest = new S3Request('GET', $bucket, '', self::$endpoint); - $rest->setParameter('logging', null); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::getBucketLogging({$bucket}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - if (!isset($rest->body->LoggingEnabled)) return false; // No logging - return array( - 'targetBucket' => (string)$rest->body->LoggingEnabled->TargetBucket, - 'targetPrefix' => (string)$rest->body->LoggingEnabled->TargetPrefix, - ); - } - - - /** - * Disable bucket logging - * - * @param string $bucket Bucket name - * @return boolean - */ - public static function disableBucketLogging($bucket) - { - return self::setBucketLogging($bucket, null); - } - - - /** - * Get a bucket's location - * - * @param string $bucket Bucket name - * @return string | false - */ - public static function getBucketLocation($bucket) - { - $rest = new S3Request('GET', $bucket, '', self::$endpoint); - $rest->setParameter('location', null); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::getBucketLocation({$bucket}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'US'; - } - - - /** - * Set object or bucket Access Control Policy - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param array $acp Access Control Policy Data (same as the data returned from getAccessControlPolicy) - * @return boolean - */ - public static function setAccessControlPolicy($bucket, $uri = '', $acp = array()) - { - $dom = new DOMDocument; - $dom->formatOutput = true; - $accessControlPolicy = $dom->createElement('AccessControlPolicy'); - $accessControlList = $dom->createElement('AccessControlList'); - - // It seems the owner has to be passed along too - $owner = $dom->createElement('Owner'); - $owner->appendChild($dom->createElement('ID', $acp['owner']['id'])); - $owner->appendChild($dom->createElement('DisplayName', $acp['owner']['name'])); - $accessControlPolicy->appendChild($owner); - - foreach ($acp['acl'] as $g) - { - $grant = $dom->createElement('Grant'); - $grantee = $dom->createElement('Grantee'); - $grantee->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); - if (isset($g['id'])) - { // CanonicalUser (DisplayName is omitted) - $grantee->setAttribute('xsi:type', 'CanonicalUser'); - $grantee->appendChild($dom->createElement('ID', $g['id'])); - } - elseif (isset($g['email'])) - { // AmazonCustomerByEmail - $grantee->setAttribute('xsi:type', 'AmazonCustomerByEmail'); - $grantee->appendChild($dom->createElement('EmailAddress', $g['email'])); - } - elseif ($g['type'] == 'Group') - { // Group - $grantee->setAttribute('xsi:type', 'Group'); - $grantee->appendChild($dom->createElement('URI', $g['uri'])); - } - $grant->appendChild($grantee); - $grant->appendChild($dom->createElement('Permission', $g['permission'])); - $accessControlList->appendChild($grant); - } - - $accessControlPolicy->appendChild($accessControlList); - $dom->appendChild($accessControlPolicy); - - $rest = new S3Request('PUT', $bucket, $uri, self::$endpoint); - $rest->setParameter('acl', null); - $rest->data = $dom->saveXML(); - $rest->size = strlen($rest->data); - $rest->setHeader('Content-Type', 'application/xml'); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::setAccessControlPolicy({$bucket}, {$uri}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Get object or bucket Access Control Policy - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @return mixed | false - */ - public static function getAccessControlPolicy($bucket, $uri = '') - { - $rest = new S3Request('GET', $bucket, $uri, self::$endpoint); - $rest->setParameter('acl', null); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - - $acp = array(); - if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) - $acp['owner'] = array( - 'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName - ); - - if (isset($rest->body->AccessControlList)) - { - $acp['acl'] = array(); - foreach ($rest->body->AccessControlList->Grant as $grant) - { - foreach ($grant->Grantee as $grantee) - { - if (isset($grantee->ID, $grantee->DisplayName)) // CanonicalUser - $acp['acl'][] = array( - 'type' => 'CanonicalUser', - 'id' => (string)$grantee->ID, - 'name' => (string)$grantee->DisplayName, - 'permission' => (string)$grant->Permission - ); - elseif (isset($grantee->EmailAddress)) // AmazonCustomerByEmail - $acp['acl'][] = array( - 'type' => 'AmazonCustomerByEmail', - 'email' => (string)$grantee->EmailAddress, - 'permission' => (string)$grant->Permission - ); - elseif (isset($grantee->URI)) // Group - $acp['acl'][] = array( - 'type' => 'Group', - 'uri' => (string)$grantee->URI, - 'permission' => (string)$grant->Permission - ); - else continue; - } - } - } - return $acp; - } - - - /** - * Delete an object - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @return boolean - */ - public static function deleteObject($bucket, $uri) - { - $rest = new S3Request('DELETE', $bucket, $uri, self::$endpoint); - $rest = $rest->getResponse(); - if ($rest->error === false && $rest->code !== 204) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::deleteObject(): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Get a query string authenticated URL - * - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param integer $lifetime Lifetime in seconds - * @param boolean $hostBucket Use the bucket name as the hostname - * @param boolean $https Use HTTPS ($hostBucket should be false for SSL verification) - * @return string - */ - public static function getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false) - { - $expires = self::__getTime() + $lifetime; - $uri = str_replace(array('%2F', '%2B'), array('/', '+'), rawurlencode($uri)); - return sprintf(($https ? 'https' : 'http').'://%s/%s?AWSAccessKeyId=%s&Expires=%u&Signature=%s', - // $hostBucket ? $bucket : $bucket.'.s3.amazonaws.com', $uri, self::$__accessKey, $expires, - $hostBucket ? $bucket : self::$endpoint.'/'.$bucket, $uri, self::$__accessKey, $expires, - urlencode(self::__getHash("GET\n\n\n{$expires}\n/{$bucket}/{$uri}"))); - } - - - /** - * Get a CloudFront signed policy URL - * - * @param array $policy Policy - * @return string - */ - public static function getSignedPolicyURL($policy) - { - $data = json_encode($policy); - $signature = ''; - if (!openssl_sign($data, $signature, self::$__signingKeyResource)) return false; - - $encoded = str_replace(array('+', '='), array('-', '_', '~'), base64_encode($data)); - $signature = str_replace(array('+', '='), array('-', '_', '~'), base64_encode($signature)); - - $url = $policy['Statement'][0]['Resource'] . '?'; - foreach (array('Policy' => $encoded, 'Signature' => $signature, 'Key-Pair-Id' => self::$__signingKeyPairId) as $k => $v) - $url .= $k.'='.str_replace('%2F', '/', rawurlencode($v)).'&'; - return substr($url, 0, -1); - } - - - /** - * Get a CloudFront canned policy URL - * - * @param string $url URL to sign - * @param integer $lifetime URL lifetime - * @return string - */ - public static function getSignedCannedURL($url, $lifetime) - { - return self::getSignedPolicyURL(array( - 'Statement' => array( - array('Resource' => $url, 'Condition' => array( - 'DateLessThan' => array('AWS:EpochTime' => self::__getTime() + $lifetime) - )) - ) - )); - } - - - /** - * Get upload POST parameters for form uploads - * - * @param string $bucket Bucket name - * @param string $uriPrefix Object URI prefix - * @param constant $acl ACL constant - * @param integer $lifetime Lifetime in seconds - * @param integer $maxFileSize Maximum filesize in bytes (default 5MB) - * @param string $successRedirect Redirect URL or 200 / 201 status code - * @param array $amzHeaders Array of x-amz-meta-* headers - * @param array $headers Array of request headers or content type as a string - * @param boolean $flashVars Includes additional "Filename" variable posted by Flash - * @return object - */ - public static function getHttpUploadPostParams($bucket, $uriPrefix = '', $acl = self::ACL_PRIVATE, $lifetime = 3600, - $maxFileSize = 5242880, $successRedirect = "201", $amzHeaders = array(), $headers = array(), $flashVars = false) - { - // Create policy object - $policy = new stdClass; - $policy->expiration = gmdate('Y-m-d\TH:i:s\Z', (self::__getTime() + $lifetime)); - $policy->conditions = array(); - $obj = new stdClass; $obj->bucket = $bucket; array_push($policy->conditions, $obj); - $obj = new stdClass; $obj->acl = $acl; array_push($policy->conditions, $obj); - - $obj = new stdClass; // 200 for non-redirect uploads - if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201))) - $obj->success_action_status = (string)$successRedirect; - else // URL - $obj->success_action_redirect = $successRedirect; - array_push($policy->conditions, $obj); - - if ($acl !== self::ACL_PUBLIC_READ) - array_push($policy->conditions, array('eq', '$acl', $acl)); - - array_push($policy->conditions, array('starts-with', '$key', $uriPrefix)); - if ($flashVars) array_push($policy->conditions, array('starts-with', '$Filename', '')); - foreach (array_keys($headers) as $headerKey) - array_push($policy->conditions, array('starts-with', '$'.$headerKey, '')); - foreach ($amzHeaders as $headerKey => $headerVal) - { - $obj = new stdClass; - $obj->{$headerKey} = (string)$headerVal; - array_push($policy->conditions, $obj); - } - array_push($policy->conditions, array('content-length-range', 0, $maxFileSize)); - $policy = base64_encode(str_replace('\/', '/', json_encode($policy))); - - // Create parameters - $params = new stdClass; - $params->AWSAccessKeyId = self::$__accessKey; - $params->key = $uriPrefix.'${filename}'; - $params->acl = $acl; - $params->policy = $policy; unset($policy); - $params->signature = self::__getHash($params->policy); - if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201))) - $params->success_action_status = (string)$successRedirect; - else - $params->success_action_redirect = $successRedirect; - foreach ($headers as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal; - foreach ($amzHeaders as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal; - return $params; - } - - - /** - * Create a CloudFront distribution - * - * @param string $bucket Bucket name - * @param boolean $enabled Enabled (true/false) - * @param array $cnames Array containing CNAME aliases - * @param string $comment Use the bucket name as the hostname - * @param string $defaultRootObject Default root object - * @param string $originAccessIdentity Origin access identity - * @param array $trustedSigners Array of trusted signers - * @return array | false - */ - public static function createDistribution($bucket, $enabled = true, $cnames = array(), $comment = null, $defaultRootObject = null, $originAccessIdentity = null, $trustedSigners = array()) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::createDistribution({$bucket}, ".(int)$enabled.", [], '$comment'): %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - $useSSL = self::$useSSL; - - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('POST', '', '2010-11-01/distribution', 'cloudfront.amazonaws.com'); - $rest->data = self::__getCloudFrontDistributionConfigXML( - $bucket.'.s3.amazonaws.com', - $enabled, - (string)$comment, - (string)microtime(true), - $cnames, - $defaultRootObject, - $originAccessIdentity, - $trustedSigners - ); - - $rest->size = strlen($rest->data); - $rest->setHeader('Content-Type', 'application/xml'); - $rest = self::__getCloudFrontResponse($rest); - - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 201) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::createDistribution({$bucket}, ".(int)$enabled.", [], '$comment'): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } elseif ($rest->body instanceof SimpleXMLElement) - return self::__parseCloudFrontDistributionConfig($rest->body); - return false; - } - - - /** - * Get CloudFront distribution info - * - * @param string $distributionId Distribution ID from listDistributions() - * @return array | false - */ - public static function getDistribution($distributionId) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::getDistribution($distributionId): %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - $useSSL = self::$useSSL; - - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('GET', '', '2010-11-01/distribution/'.$distributionId, 'cloudfront.amazonaws.com'); - $rest = self::__getCloudFrontResponse($rest); - - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::getDistribution($distributionId): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - elseif ($rest->body instanceof SimpleXMLElement) - { - $dist = self::__parseCloudFrontDistributionConfig($rest->body); - $dist['hash'] = $rest->headers['hash']; - $dist['id'] = $distributionId; - return $dist; - } - return false; - } - - - /** - * Update a CloudFront distribution - * - * @param array $dist Distribution array info identical to output of getDistribution() - * @return array | false - */ - public static function updateDistribution($dist) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::updateDistribution({$dist['id']}): %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - $useSSL = self::$useSSL; - - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('PUT', '', '2010-11-01/distribution/'.$dist['id'].'/config', 'cloudfront.amazonaws.com'); - $rest->data = self::__getCloudFrontDistributionConfigXML( - $dist['origin'], - $dist['enabled'], - $dist['comment'], - $dist['callerReference'], - $dist['cnames'], - $dist['defaultRootObject'], - $dist['originAccessIdentity'], - $dist['trustedSigners'] - ); - - $rest->size = strlen($rest->data); - $rest->setHeader('If-Match', $dist['hash']); - $rest = self::__getCloudFrontResponse($rest); - - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::updateDistribution({$dist['id']}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } else { - $dist = self::__parseCloudFrontDistributionConfig($rest->body); - $dist['hash'] = $rest->headers['hash']; - return $dist; - } - return false; - } - - - /** - * Delete a CloudFront distribution - * - * @param array $dist Distribution array info identical to output of getDistribution() - * @return boolean - */ - public static function deleteDistribution($dist) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::deleteDistribution({$dist['id']}): %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - $useSSL = self::$useSSL; - - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('DELETE', '', '2008-06-30/distribution/'.$dist['id'], 'cloudfront.amazonaws.com'); - $rest->setHeader('If-Match', $dist['hash']); - $rest = self::__getCloudFrontResponse($rest); - - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 204) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::deleteDistribution({$dist['id']}): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - return true; - } - - - /** - * Get a list of CloudFront distributions - * - * @return array - */ - public static function listDistributions() - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::listDistributions(): [%s] %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - $useSSL = self::$useSSL; - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('GET', '', '2010-11-01/distribution', 'cloudfront.amazonaws.com'); - $rest = self::__getCloudFrontResponse($rest); - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - self::__triggerError(sprintf("S3::listDistributions(): [%s] %s", - $rest->error['code'], $rest->error['message']), __FILE__, __LINE__); - return false; - } - elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->DistributionSummary)) - { - $list = array(); - if (isset($rest->body->Marker, $rest->body->MaxItems, $rest->body->IsTruncated)) - { - //$info['marker'] = (string)$rest->body->Marker; - //$info['maxItems'] = (int)$rest->body->MaxItems; - //$info['isTruncated'] = (string)$rest->body->IsTruncated == 'true' ? true : false; - } - foreach ($rest->body->DistributionSummary as $summary) - $list[(string)$summary->Id] = self::__parseCloudFrontDistributionConfig($summary); - - return $list; - } - return array(); - } - - /** - * List CloudFront Origin Access Identities - * - * @return array - */ - public static function listOriginAccessIdentities() - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::listOriginAccessIdentities(): [%s] %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('GET', '', '2010-11-01/origin-access-identity/cloudfront', 'cloudfront.amazonaws.com'); - $rest = self::__getCloudFrontResponse($rest); - $useSSL = self::$useSSL; - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - trigger_error(sprintf("S3::listOriginAccessIdentities(): [%s] %s", - $rest->error['code'], $rest->error['message']), E_USER_WARNING); - return false; - } - - if (isset($rest->body->CloudFrontOriginAccessIdentitySummary)) - { - $identities = array(); - foreach ($rest->body->CloudFrontOriginAccessIdentitySummary as $identity) - if (isset($identity->S3CanonicalUserId)) - $identities[(string)$identity->Id] = array('id' => (string)$identity->Id, 's3CanonicalUserId' => (string)$identity->S3CanonicalUserId); - return $identities; - } - return false; - } - - - /** - * Invalidate objects in a CloudFront distribution - * - * Thanks to Martin Lindkvist for S3::invalidateDistribution() - * - * @param string $distributionId Distribution ID from listDistributions() - * @param array $paths Array of object paths to invalidate - * @return boolean - */ - public static function invalidateDistribution($distributionId, $paths) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::invalidateDistribution(): [%s] %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - $useSSL = self::$useSSL; - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('POST', '', '2010-08-01/distribution/'.$distributionId.'/invalidation', 'cloudfront.amazonaws.com'); - $rest->data = self::__getCloudFrontInvalidationBatchXML($paths, (string)microtime(true)); - $rest->size = strlen($rest->data); - $rest = self::__getCloudFrontResponse($rest); - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 201) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - trigger_error(sprintf("S3::invalidate('{$distributionId}',{$paths}): [%s] %s", - $rest->error['code'], $rest->error['message']), E_USER_WARNING); - return false; - } - return true; - } - - - /** - * Get a InvalidationBatch DOMDocument - * - * @internal Used to create XML in invalidateDistribution() - * @param array $paths Paths to objects to invalidateDistribution - * @param int $callerReference - * @return string - */ - private static function __getCloudFrontInvalidationBatchXML($paths, $callerReference = '0') - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $invalidationBatch = $dom->createElement('InvalidationBatch'); - foreach ($paths as $path) - $invalidationBatch->appendChild($dom->createElement('Path', $path)); - - $invalidationBatch->appendChild($dom->createElement('CallerReference', $callerReference)); - $dom->appendChild($invalidationBatch); - return $dom->saveXML(); - } - - - /** - * List your invalidation batches for invalidateDistribution() in a CloudFront distribution - * - * http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListInvalidation.html - * returned array looks like this: - * Array - * ( - * [I31TWB0CN9V6XD] => InProgress - * [IT3TFE31M0IHZ] => Completed - * [I12HK7MPO1UQDA] => Completed - * [I1IA7R6JKTC3L2] => Completed - * ) - * - * @param string $distributionId Distribution ID from listDistributions() - * @return array - */ - public static function getDistributionInvalidationList($distributionId) - { - if (!extension_loaded('openssl')) - { - self::__triggerError(sprintf("S3::getDistributionInvalidationList(): [%s] %s", - "CloudFront functionality requires SSL"), __FILE__, __LINE__); - return false; - } - - $useSSL = self::$useSSL; - self::$useSSL = true; // CloudFront requires SSL - $rest = new S3Request('GET', '', '2010-11-01/distribution/'.$distributionId.'/invalidation', 'cloudfront.amazonaws.com'); - $rest = self::__getCloudFrontResponse($rest); - self::$useSSL = $useSSL; - - if ($rest->error === false && $rest->code !== 200) - $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status'); - if ($rest->error !== false) - { - trigger_error(sprintf("S3::getDistributionInvalidationList('{$distributionId}'): [%s]", - $rest->error['code'], $rest->error['message']), E_USER_WARNING); - return false; - } - elseif ($rest->body instanceof SimpleXMLElement && isset($rest->body->InvalidationSummary)) - { - $list = array(); - foreach ($rest->body->InvalidationSummary as $summary) - $list[(string)$summary->Id] = (string)$summary->Status; - - return $list; - } - return array(); - } - - - /** - * Get a DistributionConfig DOMDocument - * - * http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?PutConfig.html - * - * @internal Used to create XML in createDistribution() and updateDistribution() - * @param string $bucket S3 Origin bucket - * @param boolean $enabled Enabled (true/false) - * @param string $comment Comment to append - * @param string $callerReference Caller reference - * @param array $cnames Array of CNAME aliases - * @param string $defaultRootObject Default root object - * @param string $originAccessIdentity Origin access identity - * @param array $trustedSigners Array of trusted signers - * @return string - */ - private static function __getCloudFrontDistributionConfigXML($bucket, $enabled, $comment, $callerReference = '0', $cnames = array(), $defaultRootObject = null, $originAccessIdentity = null, $trustedSigners = array()) - { - $dom = new DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - $distributionConfig = $dom->createElement('DistributionConfig'); - $distributionConfig->setAttribute('xmlns', 'http://cloudfront.amazonaws.com/doc/2010-11-01/'); - - $origin = $dom->createElement('S3Origin'); - $origin->appendChild($dom->createElement('DNSName', $bucket)); - if ($originAccessIdentity !== null) $origin->appendChild($dom->createElement('OriginAccessIdentity', $originAccessIdentity)); - $distributionConfig->appendChild($origin); - - if ($defaultRootObject !== null) $distributionConfig->appendChild($dom->createElement('DefaultRootObject', $defaultRootObject)); - - $distributionConfig->appendChild($dom->createElement('CallerReference', $callerReference)); - foreach ($cnames as $cname) - $distributionConfig->appendChild($dom->createElement('CNAME', $cname)); - if ($comment !== '') $distributionConfig->appendChild($dom->createElement('Comment', $comment)); - $distributionConfig->appendChild($dom->createElement('Enabled', $enabled ? 'true' : 'false')); - - $trusted = $dom->createElement('TrustedSigners'); - foreach ($trustedSigners as $id => $type) - $trusted->appendChild($id !== '' ? $dom->createElement($type, $id) : $dom->createElement($type)); - $distributionConfig->appendChild($trusted); - - $dom->appendChild($distributionConfig); - //var_dump($dom->saveXML()); - return $dom->saveXML(); - } - - - /** - * Parse a CloudFront distribution config - * - * See http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?GetDistribution.html - * - * @internal Used to parse the CloudFront DistributionConfig node to an array - * @param object &$node DOMNode - * @return array - */ - private static function __parseCloudFrontDistributionConfig(&$node) - { - if (isset($node->DistributionConfig)) - return self::__parseCloudFrontDistributionConfig($node->DistributionConfig); - - $dist = array(); - if (isset($node->Id, $node->Status, $node->LastModifiedTime, $node->DomainName)) - { - $dist['id'] = (string)$node->Id; - $dist['status'] = (string)$node->Status; - $dist['time'] = strtotime((string)$node->LastModifiedTime); - $dist['domain'] = (string)$node->DomainName; - } - - if (isset($node->CallerReference)) - $dist['callerReference'] = (string)$node->CallerReference; - - if (isset($node->Enabled)) - $dist['enabled'] = (string)$node->Enabled == 'true' ? true : false; - - if (isset($node->S3Origin)) - { - if (isset($node->S3Origin->DNSName)) - $dist['origin'] = (string)$node->S3Origin->DNSName; - - $dist['originAccessIdentity'] = isset($node->S3Origin->OriginAccessIdentity) ? - (string)$node->S3Origin->OriginAccessIdentity : null; - } - - $dist['defaultRootObject'] = isset($node->DefaultRootObject) ? (string)$node->DefaultRootObject : null; - - $dist['cnames'] = array(); - if (isset($node->CNAME)) - foreach ($node->CNAME as $cname) - $dist['cnames'][(string)$cname] = (string)$cname; - - $dist['trustedSigners'] = array(); - if (isset($node->TrustedSigners)) - foreach ($node->TrustedSigners as $signer) - { - if (isset($signer->Self)) - $dist['trustedSigners'][''] = 'Self'; - elseif (isset($signer->KeyPairId)) - $dist['trustedSigners'][(string)$signer->KeyPairId] = 'KeyPairId'; - elseif (isset($signer->AwsAccountNumber)) - $dist['trustedSigners'][(string)$signer->AwsAccountNumber] = 'AwsAccountNumber'; - } - - $dist['comment'] = isset($node->Comment) ? (string)$node->Comment : null; - return $dist; - } - - - /** - * Grab CloudFront response - * - * @internal Used to parse the CloudFront S3Request::getResponse() output - * @param object &$rest S3Request instance - * @return object - */ - private static function __getCloudFrontResponse(&$rest) - { - $rest->getResponse(); - if ($rest->response->error === false && isset($rest->response->body) && - is_string($rest->response->body) && substr($rest->response->body, 0, 5) == 'response->body = simplexml_load_string($rest->response->body); - // Grab CloudFront errors - if (isset($rest->response->body->Error, $rest->response->body->Error->Code, - $rest->response->body->Error->Message)) - { - $rest->response->error = array( - 'code' => (string)$rest->response->body->Error->Code, - 'message' => (string)$rest->response->body->Error->Message - ); - unset($rest->response->body); - } - } - return $rest->response; - } - - - /** - * Get MIME type for file - * - * To override the putObject() Content-Type, add it to $requestHeaders - * - * To use fileinfo, ensure the MAGIC environment variable is set - * - * @internal Used to get mime types - * @param string &$file File path - * @return string - */ - private static function __getMIMEType(&$file) - { - static $exts = array( - 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', - 'png' => 'image/png', 'ico' => 'image/x-icon', 'pdf' => 'application/pdf', - 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'svg' => 'image/svg+xml', - 'svgz' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', - 'zip' => 'application/zip', 'gz' => 'application/x-gzip', - 'tar' => 'application/x-tar', 'bz' => 'application/x-bzip', - 'bz2' => 'application/x-bzip2', 'rar' => 'application/x-rar-compressed', - 'exe' => 'application/x-msdownload', 'msi' => 'application/x-msdownload', - 'cab' => 'application/vnd.ms-cab-compressed', 'txt' => 'text/plain', - 'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', - 'css' => 'text/css', 'js' => 'text/javascript', - 'xml' => 'text/xml', 'xsl' => 'application/xsl+xml', - 'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', - 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', - 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php' - ); - - $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); - if (isset($exts[$ext])) return $exts[$ext]; - - // Use fileinfo if available - if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) && - ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC'])) !== false) - { - if (($type = finfo_file($finfo, $file)) !== false) - { - // Remove the charset and grab the last content-type - $type = explode(' ', str_replace('; charset=', ';charset=', $type)); - $type = array_pop($type); - $type = explode(';', $type); - $type = trim(array_shift($type)); - } - finfo_close($finfo); - if ($type !== false && strlen($type) > 0) return $type; - } - - return 'application/octet-stream'; - } - - - /** - * Get the current time - * - * @internal Used to apply offsets to sytem time - * @return integer - */ - public static function __getTime() - { - return time() + self::$__timeOffset; - } - - - /** - * Generate the auth string: "AWS AccessKey:Signature" - * - * @internal Used by S3Request::getResponse() - * @param string $string String to sign - * @return string - */ - public static function __getSignature($string) - { - return 'AWS '.self::$__accessKey.':'.self::__getHash($string); - } - - - /** - * Creates a HMAC-SHA1 hash - * - * This uses the hash extension if loaded - * - * @internal Used by __getSignature() - * @param string $string String to sign - * @return string - */ - private static function __getHash($string) - { - return base64_encode(extension_loaded('hash') ? - hash_hmac('sha1', $string, self::$__secretKey, true) : pack('H*', sha1( - (str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . - pack('H*', sha1((str_pad(self::$__secretKey, 64, chr(0x00)) ^ - (str_repeat(chr(0x36), 64))) . $string))))); - } - -} - -/** - * S3 Request class - * - * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class - * @version 0.5.0-dev - */ -final class S3Request -{ - /** - * AWS URI - * - * @var string - * @access pricate - */ - private $endpoint; - - /** - * Verb - * - * @var string - * @access private - */ - private $verb; - - /** - * S3 bucket name - * - * @var string - * @access private - */ - private $bucket; - - /** - * Object URI - * - * @var string - * @access private - */ - private $uri; - - /** - * Final object URI - * - * @var string - * @access private - */ - private $resource = ''; - - /** - * Additional request parameters - * - * @var array - * @access private - */ - private $parameters = array(); - - /** - * Amazon specific request headers - * - * @var array - * @access private - */ - private $amzHeaders = array(); - - /** - * HTTP request headers - * - * @var array - * @access private - */ - private $headers = array( - 'Host' => '', 'Date' => '', 'Content-MD5' => '', 'Content-Type' => '' - ); - - /** - * Use HTTP PUT? - * - * @var bool - * @access public - */ - public $fp = false; - - /** - * PUT file size - * - * @var int - * @access public - */ - public $size = 0; - - /** - * PUT post fields - * - * @var array - * @access public - */ - public $data = false; - - /** - * S3 request respone - * - * @var object - * @access public - */ - public $response; - - - /** - * Constructor - * - * @param string $verb Verb - * @param string $bucket Bucket name - * @param string $uri Object URI - * @param string $endpoint AWS endpoint URI - * @return mixed - */ - function __construct($verb, $bucket = '', $uri = '', $endpoint = 's3.amazonaws.com') - { - - $this->endpoint = $endpoint; - $this->verb = $verb; - $this->bucket = $bucket; - $this->uri = $uri !== '' ? '/'.str_replace('%2F', '/', rawurlencode($uri)) : '/'; - - //if ($this->bucket !== '') - // $this->resource = '/'.$this->bucket.$this->uri; - //else - // $this->resource = $this->uri; - - if ($this->bucket !== '') - { - if ($this->__dnsBucketName($this->bucket)) - { - $this->headers['Host'] = $this->bucket.'.'.$this->endpoint; - $this->resource = '/'.$this->bucket.$this->uri; - } - else - { - $this->headers['Host'] = $this->endpoint; - $this->uri = $this->uri; - if ($this->bucket !== '') $this->uri = '/'.$this->bucket.$this->uri; - $this->bucket = ''; - $this->resource = $this->uri; - } - } - else - { - $this->headers['Host'] = $this->endpoint; - $this->resource = $this->uri; - } - - - $this->headers['Date'] = gmdate('D, d M Y H:i:s T'); - $this->response = new STDClass; - $this->response->error = false; - $this->response->body = null; - $this->response->headers = array(); - } - - - /** - * Set request parameter - * - * @param string $key Key - * @param string $value Value - * @return void - */ - public function setParameter($key, $value) - { - $this->parameters[$key] = $value; - } - - - /** - * Set request header - * - * @param string $key Key - * @param string $value Value - * @return void - */ - public function setHeader($key, $value) - { - $this->headers[$key] = $value; - } - - - /** - * Set x-amz-meta-* header - * - * @param string $key Key - * @param string $value Value - * @return void - */ - public function setAmzHeader($key, $value) - { - $this->amzHeaders[$key] = $value; - } - - - /** - * Get the S3 response - * - * @return object | false - */ - public function getResponse() - { - $query = ''; - if (sizeof($this->parameters) > 0) - { - $query = substr($this->uri, -1) !== '?' ? '?' : '&'; - foreach ($this->parameters as $var => $value) - if ($value == null || $value == '') $query .= $var.'&'; - else $query .= $var.'='.rawurlencode($value).'&'; - $query = substr($query, 0, -1); - $this->uri .= $query; - - if (array_key_exists('acl', $this->parameters) || - array_key_exists('location', $this->parameters) || - array_key_exists('torrent', $this->parameters) || - array_key_exists('website', $this->parameters) || - array_key_exists('logging', $this->parameters)) - $this->resource .= $query; - } - $url = (S3::$useSSL ? 'https://' : 'http://') . ($this->headers['Host'] !== '' ? $this->headers['Host'] : $this->endpoint) . $this->uri; - - //var_dump('bucket: ' . $this->bucket, 'uri: ' . $this->uri, 'resource: ' . $this->resource, 'url: ' . $url); - - // Basic setup - $curl = curl_init(); - curl_setopt($curl, CURLOPT_USERAGENT, 'S3/php'); - - if (S3::$useSSL) - { - // Set protocol version - curl_setopt($curl, CURLOPT_SSLVERSION, S3::$useSSLVersion); - - // SSL Validation can now be optional for those with broken OpenSSL installations - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, S3::$useSSLValidation ? 2 : 0); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, S3::$useSSLValidation ? 1 : 0); - - if (S3::$sslKey !== null) curl_setopt($curl, CURLOPT_SSLKEY, S3::$sslKey); - if (S3::$sslCert !== null) curl_setopt($curl, CURLOPT_SSLCERT, S3::$sslCert); - if (S3::$sslCACert !== null) curl_setopt($curl, CURLOPT_CAINFO, S3::$sslCACert); - } - - curl_setopt($curl, CURLOPT_URL, $url); - - if (S3::$proxy != null && isset(S3::$proxy['host'])) - { - curl_setopt($curl, CURLOPT_PROXY, S3::$proxy['host']); - curl_setopt($curl, CURLOPT_PROXYTYPE, S3::$proxy['type']); - if (isset(S3::$proxy['user'], S3::$proxy['pass']) && S3::$proxy['user'] != null && S3::$proxy['pass'] != null) - curl_setopt($curl, CURLOPT_PROXYUSERPWD, sprintf('%s:%s', S3::$proxy['user'], S3::$proxy['pass'])); - } - - // Headers - $headers = array(); $amz = array(); - foreach ($this->amzHeaders as $header => $value) - if (strlen($value) > 0) $headers[] = $header.': '.$value; - foreach ($this->headers as $header => $value) - if (strlen($value) > 0) $headers[] = $header.': '.$value; - - // Collect AMZ headers for signature - foreach ($this->amzHeaders as $header => $value) - if (strlen($value) > 0) $amz[] = strtolower($header).':'.$value; - - // AMZ headers must be sorted - if (sizeof($amz) > 0) - { - //sort($amz); - usort($amz, array(&$this, '__sortMetaHeadersCmp')); - $amz = "\n".implode("\n", $amz); - } else $amz = ''; - - if (S3::hasAuth()) - { - // Authorization string (CloudFront stringToSign should only contain a date) - if ($this->headers['Host'] == 'cloudfront.amazonaws.com') - $headers[] = 'Authorization: ' . S3::__getSignature($this->headers['Date']); - else - { - $headers[] = 'Authorization: ' . S3::__getSignature( - $this->verb."\n". - $this->headers['Content-MD5']."\n". - $this->headers['Content-Type']."\n". - $this->headers['Date'].$amz."\n". - $this->resource - ); - } - } - - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - curl_setopt($curl, CURLOPT_HEADER, false); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); - curl_setopt($curl, CURLOPT_WRITEFUNCTION, array(&$this, '__responseWriteCallback')); - curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this, '__responseHeaderCallback')); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - - // Request types - switch ($this->verb) - { - case 'GET': break; - case 'PUT': case 'POST': // POST only used for CloudFront - if ($this->fp !== false) - { - curl_setopt($curl, CURLOPT_PUT, true); - curl_setopt($curl, CURLOPT_INFILE, $this->fp); - if ($this->size >= 0) - curl_setopt($curl, CURLOPT_INFILESIZE, $this->size); - } - elseif ($this->data !== false) - { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb); - curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data); - } - else - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->verb); - break; - case 'HEAD': - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'HEAD'); - curl_setopt($curl, CURLOPT_NOBODY, true); - break; - case 'DELETE': - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); - break; - default: break; - } - - // Execute, grab errors - if (curl_exec($curl)) - $this->response->code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - else - $this->response->error = array( - 'code' => curl_errno($curl), - 'message' => curl_error($curl), - 'resource' => $this->resource - ); - - @curl_close($curl); - - // Parse body into XML - if ($this->response->error === false && isset($this->response->headers['type']) && - $this->response->headers['type'] == 'application/xml' && isset($this->response->body)) - { - $this->response->body = simplexml_load_string($this->response->body); - - // Grab S3 errors - if (!in_array($this->response->code, array(200, 204, 206)) && - isset($this->response->body->Code, $this->response->body->Message)) - { - $this->response->error = array( - 'code' => (string)$this->response->body->Code, - 'message' => (string)$this->response->body->Message - ); - if (isset($this->response->body->Resource)) - $this->response->error['resource'] = (string)$this->response->body->Resource; - unset($this->response->body); - } - } - - // Clean up file resources - if ($this->fp !== false && is_resource($this->fp)) fclose($this->fp); - - return $this->response; - } - - /** - * Sort compare for meta headers - * - * @internal Used to sort x-amz meta headers - * @param string $a String A - * @param string $b String B - * @return integer - */ - private function __sortMetaHeadersCmp($a, $b) - { - $lenA = strpos($a, ':'); - $lenB = strpos($b, ':'); - $minLen = min($lenA, $lenB); - $ncmp = strncmp($a, $b, $minLen); - if ($lenA == $lenB) return $ncmp; - if (0 == $ncmp) return $lenA < $lenB ? -1 : 1; - return $ncmp; - } - - /** - * CURL write callback - * - * @param resource &$curl CURL resource - * @param string &$data Data - * @return integer - */ - private function __responseWriteCallback(&$curl, &$data) - { - if (in_array($this->response->code, array(200, 206)) && $this->fp !== false) - return fwrite($this->fp, $data); - else - $this->response->body .= $data; - return strlen($data); - } - - - /** - * Check DNS conformity - * - * @param string $bucket Bucket name - * @return boolean - */ - private function __dnsBucketName($bucket) - { - if (strlen($bucket) > 63 || preg_match("/[^a-z0-9\.-]/", $bucket) > 0) return false; - if (S3::$useSSL && strstr($bucket, '.') !== false) return false; - if (strstr($bucket, '-.') !== false) return false; - if (strstr($bucket, '..') !== false) return false; - if (!preg_match("/^[0-9a-z]/", $bucket)) return false; - if (!preg_match("/[0-9a-z]$/", $bucket)) return false; - return true; - } - - - /** - * CURL header callback - * - * @param resource $curl CURL resource - * @param string $data Data - * @return integer - */ - private function __responseHeaderCallback($curl, $data) - { - if (($strlen = strlen($data)) <= 2) return $strlen; - if (substr($data, 0, 4) == 'HTTP') - $this->response->code = (int)substr($data, 9, 3); - else - { - $data = trim($data); - if (strpos($data, ': ') === false) return $strlen; - list($header, $value) = explode(': ', $data, 2); - if ($header == 'Last-Modified') - $this->response->headers['time'] = strtotime($value); - elseif ($header == 'Date') - $this->response->headers['date'] = strtotime($value); - elseif ($header == 'Content-Length') - $this->response->headers['size'] = (int)$value; - elseif ($header == 'Content-Type') - $this->response->headers['type'] = $value; - elseif ($header == 'ETag') - $this->response->headers['hash'] = $value{0} == '"' ? substr($value, 1, -1) : $value; - elseif (preg_match('/^x-amz-meta-.*$/', $header)) - $this->response->headers[$header] = $value; - } - return $strlen; - } - -} - -/** - * S3 exception class - * - * @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class - * @version 0.5.0-dev - */ - -class S3Exception extends Exception { - /** - * Class constructor - * - * @param string $message Exception message - * @param string $file File in which exception was created - * @param string $line Line number on which exception was created - * @param int $code Exception code - */ - function __construct($message, $file, $line, $code = 0) - { - parent::__construct($message, $code); - $this->file = $file; - $this->line = $line; - } -} diff --git a/ext/amazon_s3/main.php b/ext/amazon_s3/main.php deleted file mode 100644 index c2f4514f..00000000 --- a/ext/amazon_s3/main.php +++ /dev/null @@ -1,79 +0,0 @@ - - * License: GPLv2 - * Description: Copy uploaded files to S3 - * Documentation: - */ - -require_once "ext/amazon_s3/lib/S3.php"; - -class UploadS3 extends Extension -{ - public function onInitExt(InitExtEvent $event) - { - global $config; - $config->set_default_string("amazon_s3_access", ""); - $config->set_default_string("amazon_s3_secret", ""); - $config->set_default_string("amazon_s3_bucket", ""); - } - - public function onSetupBuilding(SetupBuildingEvent $event) - { - $sb = new SetupBlock("Amazon S3"); - $sb->add_text_option("amazon_s3_access", "Access key: "); - $sb->add_text_option("amazon_s3_secret", "
Secret key: "); - $sb->add_text_option("amazon_s3_bucket", "
Bucket: "); - $event->panel->add_block($sb); - } - - public function onImageAddition(ImageAdditionEvent $event) - { - global $config; - $access = $config->get_string("amazon_s3_access"); - $secret = $config->get_string("amazon_s3_secret"); - $bucket = $config->get_string("amazon_s3_bucket"); - if (!empty($bucket)) { - log_debug("amazon_s3", "Mirroring Image #".$event->image->id." to S3 #$bucket"); - $s3 = new S3($access, $secret); - $s3->putBucket($bucket, S3::ACL_PUBLIC_READ); - $s3->putObjectFile( - warehouse_path("thumbs", $event->image->hash), - $bucket, - 'thumbs/'.$event->image->hash, - S3::ACL_PUBLIC_READ, - [], - [ - "Content-Type" => "image/jpeg", - "Content-Disposition" => "inline; filename=image-" . $event->image->id . ".jpg", - ] - ); - $s3->putObjectFile( - warehouse_path("images", $event->image->hash), - $bucket, - 'images/'.$event->image->hash, - S3::ACL_PUBLIC_READ, - [], - [ - "Content-Type" => $event->image->get_mime_type(), - "Content-Disposition" => "inline; filename=image-" . $event->image->id . "." . $event->image->ext, - ] - ); - } - } - - public function onImageDeletion(ImageDeletionEvent $event) - { - global $config; - $access = $config->get_string("amazon_s3_access"); - $secret = $config->get_string("amazon_s3_secret"); - $bucket = $config->get_string("amazon_s3_bucket"); - if (!empty($bucket)) { - log_debug("amazon_s3", "Deleting Image #".$event->image->id." from S3"); - $s3 = new S3($access, $secret); - $s3->deleteObject($bucket, "images/" . $event->image->hash); - $s3->deleteObject($bucket, "thumbs/" . $event->image->hash); - } - } -} diff --git a/ext/chatbox/cp/ajax.php b/ext/chatbox/cp/ajax.php deleted file mode 100644 index 7c74d120..00000000 --- a/ext/chatbox/cp/ajax.php +++ /dev/null @@ -1,486 +0,0 @@ - false, - 'html' => cp() - ]; - - echo json_encode($result); - return; - } - - login(md5($_POST['password'])); - $result = []; - if (loggedIn()) { - $result['error'] = false; - $result['html'] = cp(); - } else { - $result['error'] = 'invalid'; - } - - echo json_encode($result); -} - -function doLogout() -{ - logout(); - - $result = [ - 'error' => false - ]; - - echo json_encode($result); -} - -function doUnban() -{ - global $kioskMode; - - if ($kioskMode) { - $result = [ - 'error' => false - ]; - - echo json_encode($result); - return; - } - - if (!loggedIn()) { - return; - } - - $ys = ys(); - $result = []; - - $ip = $_POST['ip']; - - if ($ys->banned($ip)) { - $ys->unban($ip); - $result['error'] = false; - } else { - $result['error'] = 'notbanned'; - } - - - echo json_encode($result); -} - -function doUnbanAll() -{ - global $kioskMode; - - if ($kioskMode) { - $result = [ - 'error' => false - ]; - - echo json_encode($result); - return; - } - - if (!loggedIn()) { - return; - } - - $ys = ys(); - $ys->unbanAll(); - - $result = [ - 'error' => false - ]; - - echo json_encode($result); -} - - -function doSetPreference() -{ - global $prefs, $kioskMode; - - if ($kioskMode) { - $result = [ - 'error' => false - ]; - - echo json_encode($result); - return; - } - - if (!loggedIn()) { - return; - } - - $pref = $_POST['preference']; - $value = magic($_POST['value']); - - if ($value === 'true') { - $value = true; - } - if ($value === 'false') { - $value = false; - } - - $prefs[$pref] = $value; - - savePrefs($prefs); - - if ($pref == 'password') { - login(md5($value)); - } - - $result = [ - 'error' => false - ]; - - echo json_encode($result); -} - - -function doResetPreferences() -{ - global $prefs, $kioskMode; - - if ($kioskMode) { - $result = [ - 'error' => false - ]; - - echo json_encode($result); - return; - } - - if (!loggedIn()) { - return; - } - - resetPrefs(); - login(md5($prefs['password'])); - - // $prefs['password'] = 'lol no'; - $result = [ - 'error' => false, - 'prefs' => $prefs - ]; - - echo json_encode($result); -} - -/* CP Display */ - -function cp() -{ - global $kioskMode; - - if (!loggedIn() && !$kioskMode) { - return 'You\'re not logged in!'; - } - - return ' - -
- -
-

YShout.Preferences

- Logout -
- - - - ' . preferencesForm() . ' -
- -
-
-

YShout.About

- Logout -
- - - - ' . about() . ' -
- -
-
-

YShout.Bans

- Logout -
- - - - ' . bansList() . ' - -
'; -} - -function bansList() -{ - global $kioskMode; - - $ys = ys(); - $bans = $ys->bans(); - - $html = ''; - } - - return $html; -} - -function preferencesForm() -{ - global $prefs, $kioskMode; - - return ' -
-
-
-
Control Panel
-
    -
  1. - - -
  2. -
-
- -
-
Flood Control
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
  5. - - -
  6. -
  7. - - -
  8. -
  9. - - -
  10. -
-
- -
-
History
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
-
- -
-
Miscellaneous
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
-
-
- -
-
-
Form
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
  5. - - -
  6. -
  7. - - -
  8. -
  9. - - -
  10. -
  11. - - -
  12. -
  13. - - -
  14. -
  15. - - -
  16. -
-
- -
-
Shouts
-
    -
  1. - - -
  2. -
  3. - - -
  4. -
  5. - - -
  6. -
  7. - - -
  8. -
  9. - - -
  10. -
-
-
-
- '; -} - -function about() -{ - global $prefs; - - $html = ' -
-

About YShout

-

YShout was created and developed by Yuri Vishnevsky. Version 5 is the first one with an about page, so you\'ll have to excuse the lack of appropriate information — I\'m not quite sure what it is that goes on "About" pages anyway.

-

Other than that obviously important tidbit of information, there\'s really nothing else that I can think of putting here... If anyone knows what a good and proper about page should contain, please contact me! -

- -
-

Contact Yuri

-

If you have any questions or comments, you can contact me by email at yurivish@gmail.com, or on AIM at yurivish42.

-

I hope you\'ve enjoyed using YShout!

-
- '; - - - return $html; -} diff --git a/ext/chatbox/cp/css/style.css b/ext/chatbox/cp/css/style.css deleted file mode 100644 index b37a885e..00000000 --- a/ext/chatbox/cp/css/style.css +++ /dev/null @@ -1,386 +0,0 @@ -* { - margin: 0; - padding: 0; -} - -html, body {height: 100%;} - -body { - background: #1a1a1a url(../images/bg.gif) center center no-repeat; - color: #a7a7a7; - font: 11px/1 Tahoma, Arial, sans-serif; - text-shadow: 0 0 0 #273541; - overflow: hidden; -} - -a { - outline: none; - color: #fff; - text-decoration: none; -} - -a:hover{ - color: #fff; -} - -input { - font-size: 11px; - background: #e5e5e5; - border: 1px solid #f5f5f5; - padding: 2px; -} - -select { - font-size: 11px; -} - -#cp { - height: 440px; - width: 620px; - position: absolute; - top: 50%; - left: 50%; - margin-top: -220px; - margin-left: -310px; -} - -#nav { - height: 65px; - width: 100%; - background: url(../images/bg-nav.gif) repeat-x; - position: absolute; - bottom: 0; -} - - #nav ul { - display: none; - width: 240px; - height: 65px; - margin: 0 auto; - list-style: none; - } - - #nav li { - width: 80px; - float: left; - text-align: center; - } - - #nav a { - display: block; - height: 65px; - text-indent: -4200px; - outline: none; - } - - #nav a:active { - background-position: 0 -65px; - } - - #n-prefs a { background: 0 0 url("../images/n-prefs.gif") no-repeat; } - #n-bans a { background: 0 0 url("../images/n-bans.gif") no-repeat; } - #n-about a { background: 0 0 url("../images/n-about.gif") no-repeat; } - -.subnav { - height: 25px; - background: url(../images/bg-subnav.gif) repeat-x; - list-style: none; -} - - .subnav input { - float: left; - margin-top: 2px; - margin-right: 10px; - } - - .subnav li { - width: 85px; - float: left; - text-indent: -4200px; - } - - .subnav a { - display: block; - height: 25px; - } - - .subnav a:hover { - background-position: bottom left !important; - } - - #sn-administration a { background: url(../images/sn-administration.gif) no-repeat; } - #sn-display a { background: url(../images/sn-display.gif) no-repeat; } - #sn-form a { background: url(../images/sn-form.gif) no-repeat; } - #sn-resetall a { background: url(../images/sn-resetall.gif) no-repeat; } - #sn-ban a { background: url(../images/sn-ban.gif) no-repeat; } - #sn-unbanall a { background: url(../images/sn-unbanall.gif) no-repeat; } - #sn-deleteall a { background: url(../images/sn-deleteall.gif) no-repeat; } - #sn-about a { background: url(../images/sn-about.gif) no-repeat; } - #sn-contact a { background: url(../images/sn-contact.gif) no-repeat; } - - - - .sn-loading { - display: block; - height: 25px; - width: 25px; - float: right; - text-indent: -4200px; - background: url(../images/sn-spinny.gif) no-repeat; - _position: absolute; - _right: 20px; - _top: 50px; - } - - @media { .sn-loading { - position: absolute; - right: 15px; - top: 41px; - }} - -#content { - position: relative; - height: 375px; - overflow: hidden; -} - - .header { - height: 33px; - padding-bottom: 2px; - border-bottom: 1px solid #444; - } - - #login .header { border-bottom: 1px solid #4c657b; } - - h1 { - float: left; - height: 32px; - width: 185px; - text-indent: -4200px; - } - - #login h1 { background: url(../images/h-login.gif) no-repeat; } - #preferences h1 { background: url(../images/h-preferences.gif) no-repeat; } - #bans h1 { background: url(../images/h-bans.gif) no-repeat; } - #about h1 { background: url(../images/h-about.gif) no-repeat; } - - .logout { - display: block; - height: 32px; - width: 45px; - float: right; - text-indent: -4200px; - background: url(../images/a-logout.gif) no-repeat; - } - - .logout:hover { - background-position: bottom left; - } - - .section { - clear: both; - width: 590px; - height: 355px; - padding: 15px; - padding-top: 5px; - position: absolute; - } - -#login { - left: 0; - background: url(../images/bg-login.gif) repeat-x; - z-index: 5; -} - - #login-form { - height: 45px; - width: 300px; - position: absolute; - top: 50%; - left: 50%; - margin-top: -45px; - margin-left: -150px; - background: url(../images/bg-login-form.gif) no-repeat; - } - - #login-form label { - display: none; - } - - #login-form input { - position: absolute; - left: 127px; - top: 13px; - width: 153px; - z-index: 2; - border: 1px solid #d4e7fa; - background: #e7eef6; - } - - #login-loading { - display: block; - position: absolute; - top: 12px; - right: 8px; - height: 25px; - width: 25px; - text-indent: -4200px; - background: url(../images/login-spinny.gif) no-repeat; - z-index: 1; - } - -#preferences { - left: 0; - background: url(../images/bg-prefs.gif) repeat-x; -} - - #preferences-form { } - - #preferences-form fieldset { - margin-top: 10px; - width: 295px; - border: none; - } - - #preferences-form fieldset.odd { - float: right; - } - - #preferences-form fieldset.even { - float: left; - } - - #preferences-form .legend { - display: block; - width: 265px; - color: #fff; - padding-bottom: 3px; - border-bottom: 1px solid #80a147; - } - - /* IE7 */ - @media {#preferences-form legend { - margin-left: -7px; - }} - - #preferences-form ol { - list-style: none; - margin-top: 15px; - } - - #preferences-form li { - width: 295px; - padding-bottom: 10px; - } - - #preferences-form label { - display: block; - width: 130px; - float: left; - } - - #preferences-form input { - width: 129px; - } - - #preferences-form select { - width: 135px; - } - - .cp-pane { - position: absolute; - width: 590px; - display: none; - } - - #cp-pane-administration { - display: block; - } - -#bans { - left: 0; - background: url(../images/bg-bans.gif) repeat-x; - line-height: 1.3; -} - - #cp #bans-list a { - color: #d9d9d9; - border-bottom: 1px solid transparent; - _border-bottom: none; - } - - #cp #bans-list a:hover { - color: #fff; - border-bottom: 1px solid #de4147; - } - - #bans-list { - padding-top: 10px; - list-style: none; - height: 280px; - overflow: auto; - } - - #bans-list li { - clear: both; - padding: 3px 5px; - - } - - #bans-list .nickname { - color: #fff; - font-size: 12px; - } - - #bans-list .unban-link { - position: absolute; - right: 20px; - - } - - #no-bans { - margin-top: 100px; - text-align: center; - font-size: 22px; - color: #383838; - } - -#about { - left: 0; - background: url(../images/bg-about.gif) repeat-x; - line-height: 1.6; -} - - #about h2 { - color: #fff; - font: Arial, sans-serif; - font-size: 14px; - font-weight: normal; - margin-bottom: 5px; - } - - #about p { - margin-bottom: 5px; - } - - - #cp-pane-about { - margin-top: 10px; - display: block; - } - - #cp-pane-contact { - margin-top: 10px; - } - - #cp-pane-about a, - #cp-pane-contact a { - color: #d9d9d9; - padding-bottom: 2px; - } - - #cp-pane-about a:hover, - #cp-pane-contact a:hover { - color: #fff; - border-bottom: 1px solid #f3982d; - } diff --git a/ext/chatbox/cp/index.php b/ext/chatbox/cp/index.php deleted file mode 100644 index 5ed6f34b..00000000 --- a/ext/chatbox/cp/index.php +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - YShout: Admin CP - - - - - - -
- - -
-
-
-

YShout.Preferences

-
- -
- - - Loading... -
-
- -
-
- - \ No newline at end of file diff --git a/ext/chatbox/cp/js/admincp.js b/ext/chatbox/cp/js/admincp.js deleted file mode 100644 index 3fe93b27..00000000 --- a/ext/chatbox/cp/js/admincp.js +++ /dev/null @@ -1,388 +0,0 @@ -/*jshint bitwise:true, curly:true, devel:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */ - -Array.prototype.inArray = function (value) { - for (var i = 0; i < this.length; i++) { - if (this[i] === value) { - return true; - } - } - - return false; -}; - -var AdminCP = function() { - var self = this; - var args = arguments; - $(function(){ - self.init.apply(self, args); - }); -}; - -AdminCP.prototype = { - z: 5, - animSpeed: 'normal', - curSection: 'login', - curPrefPane: 'administration', - curAboutPane: 'about', - - init: function(options) { - this.initializing = true; - this.loginForm(); - this.initEvents(); - if (this.loaded()) { - this.afterLogin(); - } else { - $('#login-password')[0].focus(); - } - - this.initializing = false; - }, - - loginForm: function() { - $('#login-loading').fadeTo(1, 0); - }, - - initEvents: function() { - var self = this; - - $('#login-form').submit(function() { self.login(); return false; }); - $('#n-prefs').click(function() { self.show('preferences'); return false; }); - $('#n-bans').click(function() { self.show('bans'); return false; }); - $('#n-about').click(function() { self.show('about'); return false; }); - }, - - afterLogin: function() { - var self = this; - - // Login and logout - $('#login-password')[0].blur(); - $('.logout').click(function() { self.logout(); return false; }); - - // Show the nav - if (this.initializing) { - $('#nav ul').css('display', 'block'); - } else { - $('#nav ul').slideDown(); - } - - // Some css for betterlookingness - $('#preferences-form fieldset:odd').addClass('odd'); - $('#preferences-form fieldset:even').addClass('even'); - - $('#bans-list li:odd').addClass('odd'); - $('#bans-list li:even').addClass('even'); - - // Hide the loading thingie - $('.sn-loading').fadeTo(1, 0); - - // Events after load - this.initEventsAfter(); - - // If they want to go directly to a section - var anchor = this.getAnchor(); - - if (anchor.length > 0 && ['preferences', 'bans', 'about'].inArray(anchor)) { - self.show(anchor); - } else { - self.show('preferences'); - } - }, - - initEventsAfter: function() { - var self = this; - - // Navigation - $('#sn-administration').click(function() { self.showPrefPane('administration'); return false; }); - $('#sn-display').click(function() { self.showPrefPane('display'); return false; }); - $('#sn-about').click(function() { self.showAboutPane('about'); return false; }); - $('#sn-contact').click(function() { self.showAboutPane('contact'); return false; }); - $('#sn-resetall').click(function() { self.resetPrefs(); return false; }); - $('#sn-unbanall').click(function() { self.unbanAll(); return false; }); - - // Bans - $('.unban-link').click(function() { - self.unban($(this).parent().find('.ip').html(), $(this).parent()); - return false; - }); - - // Preferences - $('#preferences-form input').keypress(function(e) { - var key = window.event ? e.keyCode : e.which; - if (key === 13 || key === 3) { - self.changePref.apply(self, [$(this).attr('rel'), this.value]); - return false; - } - }).focus(function() { - this.name = this.value; - }).blur(function() { - if (this.name !== this.value) { - self.changePref.apply(self, [$(this).attr('rel'), this.value]); - } - }); - - $('#preferences-form select').change(function() { - self.changePref.apply(self, [$(this).attr('rel'), $(this).find('option:selected').attr('rel')]); - }); - }, - - changePref: function(pref, value) { - this.loading(); - var pars = { - mode: 'setpreference', - preference: pref, - 'value': value - }; - this.ajax(function(json) { - if (!json.error) { - this.done(); - } else { - alert(json.error); - } - }, pars); - }, - - resetPrefs: function() { - this.loading(); - - var pars = { - mode: 'resetpreferences' - }; - - this.ajax(function(json) { - this.done(); - if (json.prefs) { - for (pref in json.prefs) { - var value = json.prefs[pref]; - var el = $('#preferences-form input[@rel=' + pref + '], select[@rel=' + pref + ']')[0]; - - if (el.type === 'text') { - el.value = value; - } else { - if (value === true) { value = 'true'; } - if (value === false) { value = 'false'; } - - $('#preferences-form select[@rel=' + pref + ']') - .find('option') - .removeAttr('selected') - .end() - .find('option[@rel=' + value + ']') - .attr('selected', 'yeah'); - } - } - } - }, pars); - }, - - invalidPassword: function() { - // Shake the login form - $('#login-form') - .animate({ marginLeft: -145 }, 100) - .animate({ marginLeft: -155 }, 100) - .animate({ marginLeft: -145 }, 100) - .animate({ marginLeft: -155 }, 100) - .animate({ marginLeft: -150 }, 50); - - $('#login-password').val('').focus(); - }, - - login: function() { - if (this.loaded()) { - alert('Something _really_ weird has happened. Refresh and pretend nothing ever happened.'); - return; - } - - var self = this; - var pars = { - mode: 'login', - password: $('#login-password').val() - }; - - this.loginLoading(); - - this.ajax(function() { - this.ajax(function(json) { - self.loginDone(); - if (json.error) { - self.invalidPassword(); - return; - } - - $('#content').append(json.html); - self.afterLogin.apply(self); - }, pars); - }, pars); - - }, - - logout: function() { - var self = this; - var pars = { - mode: 'logout' - }; - - this.loading(); - - this.ajax(function() { - $('#login-password').val(''); - $('#nav ul').slideUp(); - self.show('login', function() { - $('#login-password')[0].focus(); - $('.section').not('#login').remove(); - self.done(); - }); - }, pars); - }, - - show: function(section, callback) { -// var sections = ['login', 'preferences', 'bans', 'about']; -// if (!sections.inArray(section)) section = 'preferences'; - - if ($.browser.msie) { - if (section === 'preferences') { - $('#preferences select').css('display', 'block'); - } else { - $('#preferences select').css('display', 'none'); - } - } - - if (section === this.curSection) { return; } - - this.curSection = section; - - $('#' + section)[0].style.zIndex = ++this.z; - - if (this.initializing) { - $('#' + section).css('display', 'block'); - } else { - $('#' + section).fadeIn(this.animSpeed, callback); - } - }, - - showPrefPane: function(pane) { - var self = this; - - if (pane === this.curPrefPane) { return; } - this.curPrefPane = pane; - $('#preferences .cp-pane').css('display', 'none'); - $('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() { - if (self.curPrefPane === pane) { - $('#preferences .cp-pane').not('#cp-pane-' + pane).css('display', 'none'); - } else { - $('#cp-pane-' + pane).css('display', 'none'); - } - }); - }, - - showAboutPane: function(pane) { - var self = this; - - if (pane === this.curAboutPane) { return; } - this.curAboutPane = pane; - $('#about .cp-pane').css('display', 'none'); - $('#cp-pane-' + pane).css('display', 'block').fadeIn(this.animSpeed, function() { - if (self.curAboutPane === pane) { - $('#about .cp-pane').not('#cp-pane-' + pane).css('display', 'none'); - } else { - $('#cp-pane-' + pane).css('display', 'none'); - } - }); - }, - - ajax: function(callback, pars, html) { - var self = this; - - $.post('ajax.php', pars, function(parse) { - // alert(parse); - if (parse) { - if (html) { - callback.apply(self, [parse]); - } else { - callback.apply(self, [self.json(parse)]); - } - } else { - callback.apply(self); - } - }); - }, - - json: function(parse) { - var json = eval('(' + parse + ')'); - return json; - }, - - loaded: function() { - return ($('#cp-loaded').length === 1); - }, - - loading: function() { - $('#' + this.curSection + ' .sn-loading').fadeTo(this.animSpeed, 1); - }, - - done: function() { - $('#' + this.curSection + ' .sn-loading').fadeTo(this.animSpeed, 0); - }, - - loginLoading: function() { - $('#login-password').animate({ - width: 134 - }); - - $('#login-loading').fadeTo(this.animSpeed, 1); - - }, - - loginDone: function() { - $('#login-password').animate({ - width: 157 - }); - $('#login-loading').fadeTo(this.animSpeed, 0); - }, - - getAnchor: function() { - var href = window.location.href; - if (href.indexOf('#') > -1 ) { - return href.substr(href.indexOf('#') + 1).toLowerCase(); - } - return ''; - }, - - unban: function(ip, el) { - var self = this; - - this.loading(); - var pars = { - mode: 'unban', - 'ip': ip - }; - - this.ajax(function(json) { - if (!json.error) { - $(el).fadeOut(function() { - $(this).remove(); - $('#bans-list li:odd').removeClass('even').addClass('odd'); - $('#bans-list li:even').removeClass('odd').addClass('even'); - }, this.animSpeed); - } - self.done(); - }, pars); - }, - - unbanAll: function() { - this.loading(); - - var pars = { - mode: 'unbanall' - }; - - this.ajax(function(json) { - this.done(); - $('#bans-list').fadeOut(this.animSpeed, function() { - $('#bans-list').children().remove(); - $('#bans-list').fadeIn(); - }); - }, pars); - } - -}; - -var cp = new AdminCP(); \ No newline at end of file diff --git a/ext/chatbox/css/dark.yshout.css b/ext/chatbox/css/dark.yshout.css deleted file mode 100644 index 41e7899c..00000000 --- a/ext/chatbox/css/dark.yshout.css +++ /dev/null @@ -1,389 +0,0 @@ -/* - -YShout HTML Structure: - -
-
-
- - Yurivish: - Hey! - - - Info | - Delete | - Ban - -
- -
- - Hello. - - - Info | - Delete | - Ban - -
- -
- - Yup... - - - Info | - Delete | - Ban - -
-
-
- -
-
-
- - - [View History|Admin CP] - -
-
-
- - - -*/ - - -#yshout * { - margin: 0; - padding: 0; -} - -#yshout a { - text-decoration: none; - color: #989898; -} - -#yshout a:hover { - color: #fff; -} - -#yshout a:active { - color: #e5e5e5; -} - -/* Adjust the width here --------------------------- */ - -#yshout { - position: relative; - overflow: hidden; - font: 11px/1.4 Arial, Helvetica, sans-serif; -} - -/* Posts -------------------------------------- */ - -#yshout #ys-posts { - position: relative; - background: #1a1a1a; -} - -#yshout .ys-post { - border-bottom: 1px solid #212121; - margin: 0 5px; - padding: 5px; - position: relative; - overflow: hidden; - text-align: left; -} - - -#yshout .ys-admin-post .ys-post-nickname { - padding-left: 11px; - background: url(../images/star-dark.gif) 0 2px no-repeat; -} - - -#yshout .ys-post-timestamp { - color: #333; -} - -#yshout .ys-post-nickname { - color: #e5e5e5; -} - -#yshout .ys-post-message { - color: #595959; -} - - -/* Banned -------------------------------------- */ - -#yshout .ys-banned-post .ys-post-nickname, -#yshout .ys-banned-post .ys-post-message, -#yshout .ys-banned-post { - color: #b3b3b3 !important; -} - -#yshout #ys-banned { - position: absolute; - z-index: 75; - height: 100%; - _height: 430px; - top: 0; - left: 0; - margin: 0 5px; - background: #1a1a1a; -} - -#yshout #ys-banned span { - position: absolute; - display: block; - height: 20px; - margin-top: -10px; - top: 50%; - padding: 0 20px; - color: #666; - text-align: center; - font-size: 13px; - z-index: 80; -} - -#yshout #ys-banned a { - color: #999; -} - -#yshout #ys-banned a:hover { - color: #666; -} - -/* Hover Controls -------------------------------------- */ - -#yshout .ys-post-actions { - display: none; - position: absolute; - top: 0; - right: 0; - padding: 5px; - font-size: 11px; - z-index: 50; - background: #1a1a1a; - color: #666; -} - -#yshout .ys-post-actions a { - color: #989898; -} - -#yshout .ys-post-actions a:hover { - color: #fff; -} - -#yshout .ys-post:hover .ys-post-actions { - display: block; -} - -#yshout .ys-post-info { - color: #595959; -} - -#yshout .ys-post-info em { - font-style: normal; - color: #1a1a1a; -} - -#yshout .ys-info-overlay { - display: none; - position: absolute; - z-index: 45; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: #1a1a1a; - padding: 5px; -} - -#yshout .ys-info-inline { - display: none; - margin-top: 2px; - padding-top: 3px; - border-top: 1px solid #f2f2f2; -} - -/* Post Form -------------------------------------- */ - -#yshout #ys-post-form { - height: 40px; - line-height: 40px; - background: #262626; - text-align: left; -} - - #yshout #ys-input-nickname, - #yshout #ys-input-message { - font-size: 11px; - padding: 2px; - background: #333; - border: 1px solid #404040; - } - - #yshout #ys-post-form fieldset { - _position: absolute; - border: none; - padding: 0 10px; - _margin-top: 10px; - } - - #yshout #ys-input-nickname { - width: 105px; - margin-left: 5px; - } - - #yshout #ys-input-message { - margin-left: 5px; - width: 400px; - } - - #yshout #ys-input-submit { - font-size: 11px; - width: 64px; - margin-left: 5px; - } - - #yshout #ys-input-submit:hover { - cursor: pointer; - } - - #yshout .ys-before-focus { - color: #4d4d4d; - } - - #yshout .ys-after-focus { - color: #e5e5e5; - } - - #yshout .ys-input-invalid { - - } - - #yshout .ys-post-form-link { - margin-left: 5px; - - } - - -/* Overlays - This should go in all YShout styles -------------------------------------- */ - -#ys-overlay { - position: fixed; - _position: absolute; - z-index: 100; - width: 100%; - height: 100%; - top: 0; - left: 0; - background-color: #000; - filter: alpha(opacity=60); - -moz-opacity: 0.6; - opacity: 0.6; -} - -* html body { - height: 100%; - width: 100%; -} - -#ys-closeoverlay-link, -#ys-switchoverlay-link { - display: block; - font-weight: bold; - height: 13px; - font: 11px/1 Arial, Helvetica, sans-serif; - color: #fff; - text-decoration: none; - margin-bottom: 1px; - outline: none; - float: left; -} - -#ys-switchoverlay-link { - float: right; -} - -.ys-window { - z-index: 102; - position: fixed; - _position: absolute; - top: 50%; - left: 50%; -} - - #ys-cp { - margin-top: -220px; - margin-left: -310px; - width: 620px; - } - - #ys-yshout { - margin-top: -250px; - margin-left: -255px; - width: 500px; - } - - #ys-history { - margin-top: -220px; - margin-left: -270px; - width: 540px; - } - -#yshout .ys-browser { - border: none !important; - outline: none !important; - z-index: 102; - overflow: auto; - background: transparent !important; -} - - #yshout-browser { - height: 580px; - width: 510px; - } - - #cp-browser { - height: 440px; - width: 620px; - _height: 450px; - _width: 440px; - } - - #history-browser { - height: 440px; - width: 540px; - border-top: 1px solid #545454; - border-left: 1px solid #545454; - border-bottom: 1px solid #444; - border-right: 1px solid #444; - } \ No newline at end of file diff --git a/ext/chatbox/css/overlay.css b/ext/chatbox/css/overlay.css deleted file mode 100644 index a2c00179..00000000 --- a/ext/chatbox/css/overlay.css +++ /dev/null @@ -1,93 +0,0 @@ -/* Overlays - Use this stylesheet if you want to only use yLink. -------------------------------------- */ - -#ys-overlay { - position: fixed; - _position: absolute; - z-index: 100; - width: 100%; - height: 100%; - top: 0; - left: 0; - background-color: #000; - filter: alpha(opacity=60); - -moz-opacity: 0.6; - opacity: 0.6; -} - -* html body { - height: 100%; - width: 100%; -} - -#ys-closeoverlay-link, -#ys-switchoverlay-link { - display: block; - font-weight: bold; - height: 13px; - font: 11px/1 Arial, Helvetica, sans-serif; - color: #fff; - text-decoration: none; - margin-bottom: 1px; - outline: none; - float: left; -} - -#ys-switchoverlay-link { - float: right; -} - -.ys-window { - z-index: 102; - position: fixed; - _position: absolute; - top: 50%; - left: 50%; -} - - #ys-cp { - margin-top: -220px; - margin-left: -310px; - width: 620px; - } - - #ys-yshout { - margin-top: -250px; - margin-left: -255px; - width: 500px; - } - - #ys-history { - margin-top: -220px; - margin-left: -270px; - width: 540px; - } - -#yshout .ys-browser { - border: none !important; - outline: none !important; - z-index: 102; - overflow: auto; - background: transparent !important; -} - - #yshout-browser { - height: 580px; - width: 510px; - } - - #cp-browser { - height: 440px; - width: 620px; - _height: 450px; - _width: 440px; - } - - #history-browser { - height: 440px; - width: 540px; - border-top: 1px solid #545454; - border-left: 1px solid #545454; - border-bottom: 1px solid #444; - border-right: 1px solid #444; - } \ No newline at end of file diff --git a/ext/chatbox/css/style.css b/ext/chatbox/css/style.css deleted file mode 100644 index 3ad07b80..00000000 --- a/ext/chatbox/css/style.css +++ /dev/null @@ -1,113 +0,0 @@ -* { - margin: 0; - padding: 0; -} - -body { - background: #182635 url(../images/bg.gif) fixed repeat-x; - font: 11px/1.6 Arial, Helvetica, sans-serif; - color: #92b5ce; -} - -a { - color: #d5edff; - text-decoration: none; -} - -a:hover { - color: #fff !important; - text-decoration: underline; -} - -h2 { - font-weight: normal; - color: #fff; - font-size: 14px; - margin-bottom: 5px; - margin-top:10px; -} - -p { - margin-bottom: 5px; -} - -pre { - padding: 3px; - margin-top: 5px; - margin-bottom: 10px; - background: url(../images/bg-code.png); - _background: none; - color: #b4d4eb; -} - -code { - color: #fff; -} - -pre code { - padding: 0; - color: #b4d4eb; -} - -ul { - list-style: none; -} - -li { - margin-bottom: 5px; -} - -em { - font-weight: normal; - font-style: normal; - color: #fff; -} - -#container { - width: 510px; - margin: 0 auto; -} - - #top { - width: 510px; - margin-top: 25px; - height: 20px; - border-bottom: 1px solid #567083; - font-size: 11px; - overflow: hidden; - - } - - h1 { - text-indent: -4200px; - height: 13px; - width: 120px; - background: url(../images/h-welcome.gif) no-repeat; - float: left; - } - - #nav { - color: #93b3ca; - float: right; - line-height: 1.6; - } - -#footer { - width: 510px; - margin: 20px auto 10px auto; - padding-top: 5px; - border-top: 1px solid #273e56; - color: #384858; -} - -#footer:hover { - color: #92b5ce; -} - -#footer:hover a { - color: #fff; -} - -#footer a { - color: #425d7a; -} \ No newline at end of file diff --git a/ext/chatbox/history/css/style.css b/ext/chatbox/history/css/style.css deleted file mode 100644 index dc76f214..00000000 --- a/ext/chatbox/history/css/style.css +++ /dev/null @@ -1,85 +0,0 @@ -* { - margin: 0; - padding: 0; -} - -body { - background: #202020 url(../images/bg.gif) fixed repeat-x; - color: #5c5c5c; - font: 11px/1.6 Arial, Helvetica, sans-serif; -} - -#top { - height: 25px; - width: 510px; - margin: 0 auto; - margin-top: 20px; - border-bottom: 1px solid #444; - overflow: none; - line-height: 1.0; -} - - h1 { - text-indent: -4200px; - background: url(../images/h-history.gif) no-repeat; - width: 105px; - height: 17px; - margin-top: 5px; - float: left; - overflow: none; - _position: absolute; - } - - #top a, #bottom a { - color: #7d7d7d; - text-decoration: none; - } - - #top a { - line-height: 25px; - } - - #top a:hover, #bottom a:hover { - color: #fff; - border-bottom-color: #5e5e5e; - } - - - #log { - font-size: 11px; - margin-left: 10px; - border: 1px solid #767676; - border-right: none; - width: 60px; - - } - - #controls { - float: right; - } - - -#yshout { - margin: 0 auto; - margin-top: 10px; -} - -#bottom { - width:510px; - margin: 10px auto; -} - - #bottom #to-top { - margin-left: 5px; - } - -/* Inane IE Compatibility PNG fixes -------------------------------------- */ - -#yshout #ys-before-posts { _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='../example/images/ys-bg-posts-top.png',sizingMethod='crop'); } -#yshout #ys-posts { _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='../example/images/bg-posts.png',sizingMethod='scale'); } -#yshout #ys-after-posts { _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='../example/images/ys-bg-posts-bottom.png',sizingMethod='crop'); } -#yshout #ys-banned { _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='../example/images/bg-banned.png',sizingMethod='scale'); } -#yshout #ys-post-form { _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='../example/images/bg-form.png',sizingMethod='crop'); } -#yshout .ys-post { _height: 1%; } - diff --git a/ext/chatbox/history/index.php b/ext/chatbox/history/index.php deleted file mode 100644 index 94272f06..00000000 --- a/ext/chatbox/history/index.php +++ /dev/null @@ -1,142 +0,0 @@ -'; - - $admin = loggedIn(); - - $log = 1; - - if (isset($_GET['log'])) { - $log = $_GET['log']; - } - - if (isset($_POST['log'])) { - $log = $_POST['log']; - } - - if (filter_var($log, FILTER_VALIDATE_INT) === false) { - $log = 1; - } - - $ys = ys($log); - $posts = $ys->posts(); - - if (sizeof($posts) === 0) { - $html .= ' -
- - Yurivish: - Hey, there aren\'t any posts in this log. -
- '; - } - - $id = 0; - - foreach ($posts as $post) { - $id++; - - $banned = $ys->banned($post['adminInfo']['ip']); - $html .= '
' . "\n"; - - $ts = ''; - - switch ($prefs['timestamp']) { - case 12: - $ts = date('h:i', $post['timestamp']); - break; - case 24: - $ts = date('H:i', $post['timestamp']); - break; - case 0: - $ts = ''; - break; - } - - $html .= ' ' . "\n"; - $html .= ' ' . $post['nickname'] . '' . $prefs['nicknameSeparator'] . ' ' . "\n"; - $html .= ' ' . $post['message'] . '' . "\n"; - $html .= ' ' . "\n"; - - $html .= ' ' . "\n"; - $html .= ' Info' . ($admin ? ' | Delete | ' . ($banned ? 'Unban' : 'Ban') : '') . "\n"; - $html .= ' ' . "\n"; - - if ($admin) { - $html .= ''; - } - - $html .= '
' . "\n"; - } - - $html .= '' . "\n"; - - -if (isset($_POST['p'])) { - echo $html; - exit; -} - -?> - - - - - YShout: History - - - - - - - - - - -
-

YShout.History

-
- - Clear this log, or - Clear all logs. - - - -
-
-
-
-
- -
-
-
- -
- Back to top -
- - diff --git a/ext/chatbox/history/js/history.js b/ext/chatbox/history/js/history.js deleted file mode 100644 index 438c5c90..00000000 --- a/ext/chatbox/history/js/history.js +++ /dev/null @@ -1,276 +0,0 @@ -/*jshint bitwise:true, curly:true, devel:true, eqeqeq:true, evil:true, forin:false, noarg:true, noempty:true, nonew:true, undef:true, strict:false, browser:true, jquery:true */ - -var History = function() { - var self = this; - var args = arguments; - $(function(){ - self.init.apply(self, args); - }); -}; - -History.prototype = { - animSpeed: 'normal', - noPosts: '
\n\nYurivish:\nHey, there aren\'t any posts in this log.\n
', - - init: function(options) { - this.prefsInfo = options.prefsInfo; - this.log = options.log; - this.initEvents(); - $('body').ScrollToAnchors({ duration: 800 }); - }, - - initEvents: function() { - var self = this; - - this.initLogEvents(); - - // Select log - $('#log').change(function() { - var logIndex = $(this).find('option[@selected]').attr('rel'); - - var pars = { - p: 'yes', - log: logIndex - }; - - self.ajax(function(html) { - $('#ys-posts').html(html); - $('#yshout').fadeIn(); - self.initLogEvents(); - }, pars, true, 'index.php'); - }); - - // Clear the log - $('#clear-log').click(function() { - var el = this; - var pars = { - reqType: 'clearlog' - }; - - self.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the admin CP to clear the log.'); - el.innerHTML = 'Clear this log'; - return; - } - } - - $('#ys-posts').html(self.noPosts); - self.initLogEvents(); - el.innerHTML = 'Clear this log'; - }, pars); - - this.innerHTML = 'Clearing...'; - return false; - }); - - // Clear all logs - $('#clear-logs').click(function() { - var el = this; - var pars = { - reqType: 'clearlogs' - }; - - self.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - el.innerHTML = 'Clear all logs'; - self.error('You\'re not an admin. Log in through the admin CP to clear logs.'); - return; - } - } - - $('#ys-posts').html(self.noPosts); - self.initLogEvents(); - el.innerHTML = 'Clear all logs'; - }, pars); - - this.innerHTML = 'Clearing...'; - return false; - }); - }, - - initLogEvents: function() { - var self = this; - - $('#yshout .ys-post') - .find('.ys-info-link').toggle( - function() { self.showInfo.apply(self, [$(this).parent().parent()[0].id, this]); return false; }, - function() { self.hideInfo.apply(self, [$(this).parent().parent()[0].id, this]); return false; }) - .end() - .find('.ys-ban-link').click( - function() { self.ban.apply(self, [$(this).parent().parent()[0]]); return false; }) - .end() - .find('.ys-delete-link').click( - function() { self.del.apply(self, [$(this).parent().parent()[0]]); return false; }); - }, - - showInfo: function(id, el) { - var jEl = $('#' + id + ' .ys-post-info'); - - if (jEl.length === 0) { return false; } - - if (this.prefsInfo === 'overlay') { - jEl.css('display', 'block').fadeIn(this.animSpeed); - } else { - jEl.slideDown(this.animSpeed); - } - - el.innerHTML ='Close Info'; - return false; - }, - - hideInfo: function(id, el) { - var jEl = $('#' + id + ' .ys-post-info'); - - if (jEl.length === 0) { return false; } - - if (this.prefsInfo === 'overlay') { - jEl.fadeOut(this.animSpeed); - } else { - jEl.slideUp(this.animSpeed); - } - - el.innerHTML = 'Info'; - return false; - }, - - ban: function(post) { - var self = this; - var link = $('#' + post.id).find('.ys-ban-link')[0]; - - switch(link.innerHTML) - { - case 'Ban': - var pIP = $(post).find('.ys-h-ip').html(); - var pNickname = $(post).find('.ys-h-nickname').html(); - - var pars = { - log: self.log, - reqType: 'ban', - ip: pIP, - nickname: pNickname - }; - - this.ajax(function(json) { - if (json.error) { - switch (json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the admin CP to ban people.'); - break; - } - return; - } - - $('#yshout .ys-post[@rel="' + pars.ip + '"]') - .addClass('ys-banned-post') - .find('.ys-ban-link') - .html('Unban'); - - }, pars); - - link.innerHTML = 'Banning...'; - return false; - - case 'Banning...': - return false; - - case 'Unban': - var pIP = $(post).find('.ys-h-ip').html(); - var pars = { - reqType: 'unban', - ip: pIP - }; - - this.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the admin CP to unban people.'); - return; - } - } - - $('#yshout .ys-post[@rel="' + pars.ip + '"]') - .removeClass('ys-banned-post') - .find('.ys-ban-link') - .html('Ban'); - - }, pars); - - link.innerHTML = 'Unbanning...'; - return false; - - case 'Unbanning...': - return false; - } - }, - - del: function(post) { - var self = this; - - var link = $('#' + post.id).find('.ys-delete-link')[0]; - if (link.innerHTML === 'Deleting...') { return; } - - var pUID = $(post).find('.ys-h-uid').html(); - - var pars = { - reqType: 'delete', - uid: pUID - }; - - self.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the admin CP to ban people.'); - return; - } - } - - $(post).slideUp(self.animSpeed); - - }, pars); - - link.innerHTML = 'Deleting...'; - return false; - - }, - - json: function(parse) { - var json = eval('(' + parse + ')'); - return json; - }, - - ajax: function(callback, pars, html, page) { - pars = jQuery.extend({ - reqFor: 'history', - log: this.log - }, pars); - - var self = this; - - if (page === null) { page = '../yshout.php'; } - - $.post(page, pars, function(parse) { - if (parse) { - if (html) { - callback.apply(self, [parse]); - } else { - callback.apply(self, [self.json(parse)]); - } - } else { - callback.apply(self); - } - }); - }, - - error: function(err) { - alert(err); - } - -}; - diff --git a/ext/chatbox/include.php b/ext/chatbox/include.php deleted file mode 100644 index 55e32ad2..00000000 --- a/ext/chatbox/include.php +++ /dev/null @@ -1,7 +0,0 @@ - 0) && (this.options.yPath.charAt(this.options.yPath.length - 1) !== '/')) { - this.options.yPath += '/'; - } - - if (this.options.yLink) { - if (this.options.yLink.charAt(0) !== '#') { - this.options.yLink = '#' + this.options.yLink; - } - - $(this.options.yLink).click(function() { - self.openYShout.apply(self); - return false; - }); - } - - // Load YShout from a link, in-page - if (this.options.h_loadlink) { - $(this.options.h_loadlink).click(function() { - $('#yshout').css('display', 'block'); - $(this).unbind('click').click(function() { return false; }); - return false; - }); - this.load(true); - } else { - this.load(); - } - }, - - load: function(hidden) { - if ($('#yshout').length === 0) { return; } - - if (hidden) { $('#yshout').css('display', 'none'); } - - this.ajax(this.initialLoad, { - reqType: 'init', - yPath: this.options.yPath, - log: this.options.log - }); - }, - - initialLoad: function(updates) { - - if (updates.yError) { - alert('There appears to be a problem: \n' + updates.yError + '\n\nIf you haven\'t already, try chmodding everything inside the YShout directory to 777.'); - } - - var self = this; - - this.prefs = jQuery.extend(updates.prefs, this.options.prefs); - this.initForm(); - this.initRefresh(); - this.initLinks(); - if (this.prefs.flood) { this.initFlood(); } - - if (updates.nickname) { - $('#ys-input-nickname') - .removeClass('ys-before-focus') - .addClass( 'ys-after-focus') - .val(updates.nickname); - } - - if (updates) { - this.updates(updates); - } - - if (!this.prefs.doTruncate) { - $('#ys-posts').css('height', $('#ys-posts').height + 'px'); - } - - if (!this.prefs.inverse) { - var postsDiv = $('#ys-posts')[0]; - postsDiv.scrollTop = postsDiv.scrollHeight; - } - - this.markEnds(); - - this.initializing = false; - }, - - initForm: function() { - this.d('In initForm'); - - var postForm = - '
' + - '' + - '' + - (this.prefs.showSubmit ? '' : '') + - (this.prefs.postFormLink === 'cp' ? 'Admin CP' : '') + - (this.prefs.postFormLink === 'history' ? 'View History' : '') + - '
'; - - var postsDiv = '
'; - - if (this.prefs.inverse) { $('#yshout').html(postForm + postsDiv); } - else { $('#yshout').html(postsDiv + postForm); } - - $('#ys-posts') - .before('
') - .after('
'); - - $('#ys-post-form') - .before('
') - .after('
'); - - var self = this; - - var defaults = { - 'ys-input-nickname': self.prefs.defaultNickname, - 'ys-input-message': self.prefs.defaultMessage - }; - - var keypress = function(e) { - var key = window.event ? e.keyCode : e.which; - if (key === 13 || key === 3) { - self.send.apply(self); - return false; - } - }; - - var focus = function() { - if (this.value === defaults[this.id]) { - $(this).removeClass('ys-before-focus').addClass( 'ys-after-focus').val(''); - } - }; - - var blur = function() { - if (this.value === '') { - $(this).removeClass('ys-after-focus').addClass('ys-before-focus').val(defaults[this.id]); - } - }; - - $('#ys-input-message').keypress(keypress).focus(focus).blur(blur); - $('#ys-input-nickname').keypress(keypress).focus(focus).blur(blur); - - $('#ys-input-submit').click(function(){ self.send.apply(self); }); - $('#ys-post-form').submit(function(){ return false; }); - }, - - initRefresh: function() { - var self = this; - if (this.refreshTimer) { clearInterval(this.refreshTimer); } - - this.refreshTimer = setInterval(function() { - self.ajax(self.updates, { reqType: 'refresh' }); - }, this.prefs.refresh); // ! 3000..? - }, - - initFlood: function() { - this.d('in initFlood'); - var self = this; - this.floodCount = 0; - this.floodControl = false; - - this.floodTimer = setInterval(function() { - self.floodCount = 0; - }, this.prefs.floodTimeout); - }, - - initLinks: function() { - if ($.browser.msie) { return; } - - var self = this; - - $('#ys-cp-link').click(function() { - self.openCP.apply(self); - return false; - }); - - $('#ys-history-link').click(function() { - self.openHistory.apply(self); - return false; - }); - - }, - - openCP: function() { - var self = this; - if (this.cpOpen) { return; } - this.cpOpen = true; - - var url = this.options.yPath + 'cp/index.php'; - - $('body').append('
CloseView HistorySomething went horribly wrong.
'); - - $('#ys-overlay, #ys-closeoverlay-link').click(function() { - self.reload.apply(self, [true]); - self.closeCP.apply(self); - return false; - }); - - $('#ys-switchoverlay-link').click(function() { - self.closeCP.apply(self); - self.openHistory.apply(self); - return false; - }); - - }, - - closeCP: function() { - this.cpOpen = false; - $('#ys-overlay, #ys-cp').remove(); - }, - - openHistory: function() { - var self = this; - if (this.hOpen) { return; } - this.hOpen = true; - var url = this.options.yPath + 'history/index.php?log='+ this.options.log; - $('body').append('
CloseView Admin CPSomething went horribly wrong.
'); - - $('#ys-overlay, #ys-closeoverlay-link').click(function() { - self.reload.apply(self, [true]); - self.closeHistory.apply(self); - return false; - }); - - $('#ys-switchoverlay-link').click(function() { - self.closeHistory.apply(self); - self.openCP.apply(self); - return false; - }); - - }, - - closeHistory: function() { - this.hOpen = false; - $('#ys-overlay, #ys-history').remove(); - }, - - openYShout: function() { - var self = this; - if (this.ysOpen) { return; } - this.ysOpen = true; - var url = this.options.yPath + 'example/yshout.html'; - - $('body').append('
CloseSomething went horribly wrong.
'); - - $('#ys-overlay, #ys-closeoverlay-link').click(function() { - self.reload.apply(self, [true]); - self.closeYShout.apply(self); - return false; - }); - }, - - closeYShout: function() { - this.ysOpen = false; - $('#ys-overlay, #ys-yshout').remove(); - }, - - send: function() { - if (!this.validate()) { return; } - if (this.prefs.flood && this.floodControl) { return; } - - var postNickname = $('#ys-input-nickname').val(), postMessage = $('#ys-input-message').val(); - - if (postMessage === '/cp') { - this.openCP(); - } else if (postMessage === '/history') { - this.openHistory(); - } else { - this.ajax(this.updates, { - reqType: 'post', - nickname: postNickname, - message: postMessage - }); - } - - $('#ys-input-message').val(''); - - if (this.prefs.flood) { this.flood(); } - }, - - validate: function() { - var nickname = $('#ys-input-nickname').val(), - message = $('#ys-input-message').val(), - error = false; - - var showInvalid = function(input) { - $(input).removeClass('ys-input-valid').addClass('ys-input-invalid')[0].focus(); - error = true; - }; - - var showValid = function(input) { - $(input).removeClass('ys-input-invalid').addClass('ys-input-valid'); - }; - - if (nickname === '' || nickname === this.prefs.defaultNickname) { - showInvalid('#ys-input-nickname'); - } else { - showValid('#ys-input-nickname'); - } - - if (message === '' || message === this.prefs.defaultMessage) { - showInvalid('#ys-input-message'); - } else { - showValid('#ys-input-message'); - } - - return !error; - }, - - flood: function() { - var self = this; - this.d('in flood'); - if (this.floodCount < this.prefs.floodMessages) { - this.floodCount++; - return; - } - - this.floodAttempt++; - this.disable(); - - if (this.floodAttempt === this.prefs.autobanFlood) { - this.banSelf('You have been banned for flooding the shoutbox!'); - } - - setTimeout(function() { - self.floodCount = 0; - self.enable.apply(self); - }, this.prefs.floodDisable); - }, - - disable: function () { - $('#ys-input-submit')[0].disabled = true; - this.floodControl = true; - }, - - enable: function () { - $('#ys-input-submit')[0].disabled = false; - this.floodControl = false; - }, - - findBySame: function(ip) { - if (!$.browser.safari) {return;} - - var same = []; - - for (var i = 0; i < this.p.length; i++) { - if (this.p[i].adminInfo.ip === ip) { - same.push(this.p[i]); - } - } - - for (var j = 0; j < same.length; j++) { - $('#' + same[j].id).fadeTo(this.animSpeed, 0.8).fadeTo(this.animSpeed, 1); - } - }, - - updates: function(updates) { - if (!updates) {return;} - if (updates.prefs) {this.prefs = updates.prefs;} - if (updates.posts) {this.posts(updates.posts);} - if (updates.banned) {this.banned();} - }, - - banned: function() { - var self = this; - clearInterval(this.refreshTimer); - clearInterval(this.floodTimer); - if (this.initializing) { - $('#ys-post-form').css('display', 'none'); - } else { - $('#ys-post-form').fadeOut(this.animSpeed); - } - - if ($('#ys-banned').length === 0) { - $('#ys-input-message')[0].blur(); - $('#ys-posts').append('
You\'re banned. Click here to unban yourself if you\'re an admin. If you\'re not, go log in!
'); - - $('#ys-banned-cp-link').click(function() { - self.openCP.apply(self); - return false; - }); - - $('#ys-unban-self').click(function() { - self.ajax(function(json) { - if (!json.error) { - self.unbanned(); - } else if (json.error === 'admin') { - alert('You can only unban yourself if you\'re an admin.'); - } - }, { reqType: 'unbanself' }); - return false; - }); - } - }, - - unbanned: function() { - var self = this; - $('#ys-banned').fadeOut(function() { $(this).remove(); }); - this.initRefresh(); - $('#ys-post-form').css('display', 'block').fadeIn(this.animSpeed, function(){ - self.reload(); - }); - }, - - posts: function(p) { - for (var i = 0; i < p.length; i++) { - this.post(p[i]); - } - - this.truncate(); - - if (!this.prefs.inverse) { - var postsDiv = $('#ys-posts')[0]; - postsDiv.scrollTop = postsDiv.scrollHeight; - } - }, - - post: function(post) { - var self = this; - - var pad = function(n) { return n > 9 ? n : '0' + n; }; - var date = function(ts) { return new Date(ts * 1000); }; - var time = function(ts) { - var d = date(ts); - var h = d.getHours(), m = d.getMinutes(); - - if (self.prefs.timestamp === 12) { - h = (h > 12 ? h - 12 : h); - if (h === 0) { h = 12; } - } - - return pad(h) + ':' + pad(m); - }; - - var dateStr = function(ts) { - var t = date(ts); - - var Y = t.getFullYear(); - var M = t.getMonth(); - var D = t.getDay(); - var d = t.getDate(); - var day = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][D]; - var mon = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][M]; - - return day + ' ' + mon + '. ' + d + ', ' + Y; - }; - - var self = this; - - this.postNum++; - var id = 'ys-post-' + this.postNum; - post.id = id; - - post.message = this.links(post.message); - post.message = this.smileys(post.message); - post.message = this.bbcode(post.message); - var html = - '
' + - (this.prefs.timestamp> 0 ? ' ' : '') + - '' + post.nickname + this.prefs.nicknameSeparator + ' ' + - '' + post.message + ' ' + - '' + - 'Info' + (post.adminInfo ? ' | Delete | ' + (post.banned ? 'Unban' : 'Ban') : '') + '' + - '
'; - if (this.prefs.inverse) { $('#ys-posts').prepend(html); } - else { $('#ys-posts').append(html); } - - this.p.push(post); - - $('#' + id) - .find('.ys-post-nickname').click(function() { - if (post.adminInfo) { - self.findBySame(post.adminInfo.ip); - } - }).end() - .find('.ys-info-link').toggle( - function() { self.showInfo.apply(self, [id, this]); return false; }, - function() { self.hideInfo.apply(self, [id, this]); return false; }) - .end() - .find('.ys-ban-link').click( - function() { self.ban.apply(self, [post, id]); return false; }) - .end() - .find('.ys-delete-link').click( - function() { self.del.apply(self, [post, id]); return false; }); - - }, - - showInfo: function(id, el) { - var jEl = $('#' + id + ' .ys-post-info'); - if (this.prefs.info === 'overlay') { - jEl.css('display', 'block').fadeIn(this.animSpeed); - } else { - jEl.slideDown(this.animSpeed); - } - - el.innerHTML = 'Close Info'; - return false; - }, - - hideInfo: function(id, el) { - var jEl = $('#' + id + ' .ys-post-info'); - if (this.prefs.info === 'overlay') { - jEl.fadeOut(this.animSpeed); - } else { - jEl.slideUp(this.animSpeed); - } - - el.innerHTML = 'Info'; - return false; - }, - - ban: function(post, id) { - var self = this; - - var link = $('#' + id).find('.ys-ban-link')[0]; - - switch(link.innerHTML) { - case 'Ban': - var pars = { - reqType: 'ban', - ip: post.adminInfo.ip, - nickname: post.nickname - }; - - this.ajax(function(json) { - if (json.error) { - switch (json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the Admin CP to ban people.'); - break; - } - return; - } - //alert('p: ' + this.p + ' / ' + this.p.length); - if (json.bannedSelf) { - self.banned(); // ? - } else { - $.each(self.p, function(i) { - if (this.adminInfo && this.adminInfo.ip === post.adminInfo.ip) { - $('#' + this.id) - .addClass('ys-banned-post') - .find('.ys-ban-link').html('Unban'); - } - }); - } - }, pars); - - link.innerHTML = 'Banning...'; - return false; - - case 'Banning...': - return false; - - case 'Unban': - var pars = { - reqType: 'unban', - ip: post.adminInfo.ip - }; - - this.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the Admin CP to unban people.'); - return; - } - } - - $.each(self.p, function(i) { - if (this.adminInfo && this.adminInfo.ip === post.adminInfo.ip) { - $('#' + this.id) - .removeClass('ys-banned-post') - .find('.ys-ban-link').html('Ban'); - } - }); - - }, pars); - - link.innerHTML = 'Unbanning...'; - return false; - - case 'Unbanning...': - return false; - } - }, - - del: function(post, id) { - var self = this; - var link = $('#' + id).find('.ys-delete-link')[0]; - - if (link.innerHTML === 'Deleting...') { return; } - - var pars = { - reqType: 'delete', - uid: post.uid - }; - - self.ajax(function(json) { - if (json.error) { - switch(json.error) { - case 'admin': - self.error('You\'re not an admin. Log in through the Admin CP to ban people.'); - return; - } - } - self.reload(); - }, pars); - - link.innerHTML = 'Deleting...'; - return false; - }, - - banSelf: function(reason) { - var self = this; - - this.ajax(function(json) { - if (json.error === false) { - self.banned(); - } - }, { - reqType: 'banself', - nickname: $('#ys-input-nickname').val() - }); - }, - - bbcode: function(s) { - s = s.sReplace('[i]', ''); - s = s.sReplace('[/i]', ''); - s = s.sReplace('[I]', ''); - s = s.sReplace('[/I]', ''); - - s = s.sReplace('[b]', ''); - s = s.sReplace('[/b]', ''); - s = s.sReplace('[B]', ''); - s = s.sReplace('[/B]', ''); - - s = s.sReplace('[u]', ''); - s = s.sReplace('[/u]', ''); - s = s.sReplace('[U]', ''); - s = s.sReplace('[/U]', ''); - - return s; - }, - - smileys: function(s) { - var yp = this.options.yPath; - - var smile = function(str, smiley, image) { - return str.sReplace(smiley, ''); - }; - - s = smile(s, ':twisted:', 'twisted.gif'); - s = smile(s, ':cry:', 'cry.gif'); - s = smile(s, ':\'(', 'cry.gif'); - s = smile(s, ':shock:', 'eek.gif'); - s = smile(s, ':evil:', 'evil.gif'); - s = smile(s, ':lol:', 'lol.gif'); - s = smile(s, ':mrgreen:', 'mrgreen.gif'); - s = smile(s, ':oops:', 'redface.gif'); - s = smile(s, ':roll:', 'rolleyes.gif'); - - s = smile(s, ':?', 'confused.gif'); - s = smile(s, ':D', 'biggrin.gif'); - s = smile(s, '8)', 'cool.gif'); - s = smile(s, ':x', 'mad.gif'); - s = smile(s, ':|', 'neutral.gif'); - s = smile(s, ':P', 'razz.gif'); - s = smile(s, ':(', 'sad.gif'); - s = smile(s, ':)', 'smile.gif'); - s = smile(s, ':o', 'surprised.gif'); - s = smile(s, ';)', 'wink.gif'); - - return s; - }, - - links: function(s) { - return s.replace(/((https|http|ftp|ed2k):\/\/[\S]+)/gi, '$1'); - }, - - truncate: function(clearAll) { - var truncateTo = clearAll ? 0 : this.prefs.truncate; - var posts = $('#ys-posts .ys-post').length; - if (posts <= truncateTo) { return; } - //alert(this.initializing); - if (this.prefs.doTruncate || this.initializing) { - var diff = posts - truncateTo; - for (var i = 0; i < diff; i++) { - this.p.shift(); - } - - // $('#ys-posts .ys-post:gt(' + truncateTo + ')').remove(); - - if (this.prefs.inverse) { - $('#ys-posts .ys-post:gt(' + (truncateTo - 1) + ')').remove(); - } else { - $('#ys-posts .ys-post:lt(' + (posts - truncateTo) + ')').remove(); - } - } - - this.markEnds(); - }, - - markEnds: function() { - $('#ys-posts') - .find('.ys-first').removeClass('ys-first').end() - .find('.ys-last').removeClass('ys-last'); - - $('#ys-posts .ys-post:first-child').addClass('ys-first'); - $('#ys-posts .ys-post:last-child').addClass('ys-last'); - }, - - reload: function(everything) { - var self = this; - this.initializing = true; - - if (everything) { - this.ajax(function(json) { - $('#yshout').html(''); - clearInterval(this.refreshTimer); - clearInterval(this.floodTimer); - this.initialLoad(json); - }, { - reqType: 'init', - yPath: this.options.yPath, - log: this.options.log - }); - } else { - this.ajax(function(json) { this.truncate(true); this.updates(json); this.initializing = false; }, { - reqType: 'reload' - }); - } - }, - - error: function(str) { - alert(str); - }, - - json: function(parse) { - this.d('In json: ' + parse); - var json = eval('(' + parse + ')'); - if (!this.checkError(json)) { return json; } - }, - - checkError: function(json) { - if (!json.yError) { return false; } - - this.d('Error: ' + json.yError); - return true; - }, - - ajax: function(callback, pars, html) { - pars = jQuery.extend({ - reqFor: 'shout' - }, pars); - - var self = this; - - $.ajax({ - type: 'POST', - url: this.options.yPath + 'yshout.php', - dataType: html ? 'text' : 'json', - data: pars, - success: function(parse) { - var arr = [parse]; - callback.apply(self, arr); - } - }); - }, - - d: function(message) { - // console.log(message); - $('#debug').css('display', 'block').prepend('

' + message + '

'); - return message; - } -}; diff --git a/ext/chatbox/logs/.htaccess b/ext/chatbox/logs/.htaccess deleted file mode 100644 index fdb803ca..00000000 --- a/ext/chatbox/logs/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ - -order allow,deny -deny from all - \ No newline at end of file diff --git a/ext/chatbox/logs/log.1.txt b/ext/chatbox/logs/log.1.txt deleted file mode 100644 index 7b63d5b6..00000000 --- a/ext/chatbox/logs/log.1.txt +++ /dev/null @@ -1 +0,0 @@ -a:2:{s:4:"info";a:1:{s:15:"latestTimestamp";d:1365655195.8733589649200439453125;}s:5:"posts";a:1:{i:0;a:6:{s:8:"nickname";s:7:"YaoiFox";s:7:"message";s:42:"I hope enjoy this chatbox based on YShout!";s:9:"timestamp";d:1365655195.8733589649200439453125;s:5:"admin";b:0;s:3:"uid";s:32:"ee9e9a7a01909be8065571655dad044d";s:9:"adminInfo";a:1:{s:2:"ip";s:11:"84.193.78.8";}}}} \ No newline at end of file diff --git a/ext/chatbox/logs/yshout.bans.txt b/ext/chatbox/logs/yshout.bans.txt deleted file mode 100644 index c856afcf..00000000 --- a/ext/chatbox/logs/yshout.bans.txt +++ /dev/null @@ -1 +0,0 @@ -a:0:{} \ No newline at end of file diff --git a/ext/chatbox/logs/yshout.prefs.txt b/ext/chatbox/logs/yshout.prefs.txt deleted file mode 100644 index d76446b3..00000000 --- a/ext/chatbox/logs/yshout.prefs.txt +++ /dev/null @@ -1 +0,0 @@ -a:23:{s:8:"password";s:8:"fortytwo";s:7:"refresh";i:6000;s:4:"logs";i:5;s:7:"history";i:200;s:7:"inverse";b:0;s:8:"truncate";i:15;s:10:"doTruncate";b:1;s:9:"timestamp";i:12;s:15:"defaultNickname";s:8:"Nickname";s:14:"defaultMessage";s:12:"Message Text";s:13:"defaultSubmit";s:6:"Shout!";s:10:"showSubmit";b:1;s:14:"nicknameLength";i:25;s:13:"messageLength";i:175;s:17:"nicknameSeparator";s:1:":";s:5:"flood";b:1;s:12:"floodTimeout";i:5000;s:13:"floodMessages";i:4;s:12:"floodDisable";i:8000;s:12:"autobanFlood";i:0;s:11:"censorWords";s:19:"fuck shit bitch ass";s:12:"postFormLink";s:7:"history";s:4:"info";s:6:"inline";} \ No newline at end of file diff --git a/ext/chatbox/main.php b/ext/chatbox/main.php deleted file mode 100644 index 463340fa..00000000 --- a/ext/chatbox/main.php +++ /dev/null @@ -1,38 +0,0 @@ - - * Link: http://www.drudexsoftware.com - * License: GPLv2 - * Description: Places an ajax chatbox at the bottom of each page - * Documentation: - * This chatbox uses YShout 5 as core. - */ -class Chatbox extends Extension -{ - public function onPageRequest(PageRequestEvent $event) - { - global $page, $user; - - // Adds header to enable chatbox - $root = get_base_href(); - $yPath = make_http($root . "/ext/chatbox/"); - $page->add_html_header(" - - - - - - - ", 500); - - // loads the chatbox at the set location - $html = "
"; - $chatblock = new Block("Chatbox", $html, "main", 97); - $chatblock->is_content = false; - $page->add_block($chatblock); - } -} diff --git a/ext/chatbox/php/ajaxcall.class.php b/ext/chatbox/php/ajaxcall.class.php deleted file mode 100644 index f5b1677a..00000000 --- a/ext/chatbox/php/ajaxcall.class.php +++ /dev/null @@ -1,314 +0,0 @@ -reqType = $_POST['reqType']; - } - - public function process() - { - switch ($this->reqType) { - case 'init': - - $this->initSession(); - $this->sendFirstUpdates(); - break; - - case 'post': - $nickname = $_POST['nickname']; - $message = $_POST['message']; - cookie('yNickname', $nickname); - $ys = ys($_SESSION['yLog']); - - if ($ys->banned(ip())) { - $this->sendBanned(); - break; - } - if ($post = $ys->post($nickname, $message)) { - // To use $post somewheres later - $this->sendUpdates(); - } - break; - - case 'refresh': - $ys = ys($_SESSION['yLog']); - if ($ys->banned(ip())) { - $this->sendBanned(); - break; - } - - $this->sendUpdates(); - break; - - case 'reload': - $this->reload(); - break; - - case 'ban': - $this->doBan(); - break; - - case 'unban': - $this->doUnban(); - break; - - case 'delete': - $this->doDelete(); - break; - - case 'banself': - $this->banSelf(); - break; - - case 'unbanself': - $this->unbanSelf(); - break; - - case 'clearlog': - $this->clearLog(); - break; - - case 'clearlogs': - $this->clearLogs(); - break; - } - } - - public function doBan() - { - $ip = $_POST['ip']; - $nickname = $_POST['nickname']; - $send = []; - $ys = ys($_SESSION['yLog']); - - switch (true) { - case !loggedIn(): - $send['error'] = 'admin'; - break; - case $ys->banned($ip): - $send['error'] = 'already'; - break; - default: - $ys->ban($ip, $nickname); - if ($ip == ip()) { - $send['bannedSelf'] = true; - } - $send['error'] = false; - } - - echo json_encode($send); - } - - public function doUnban() - { - $ip = $_POST['ip']; - $send = []; - $ys = ys($_SESSION['yLog']); - - switch (true) { - case !loggedIn(): - $send['error'] = 'admin'; - break; - case !$ys->banned($ip): - $send['error'] = 'already'; - break; - default: - $ys->unban($ip); - $send['error'] = false; - } - - echo json_encode($send); - } - - public function doDelete() - { - $uid = $_POST['uid']; - $send = []; - $ys = ys($_SESSION['yLog']); - - switch (true) { - case !loggedIn(): - $send['error'] = 'admin'; - break; - default: - $ys->delete($uid); - $send['error'] = false; - } - - echo json_encode($send); - } - - public function banSelf() - { - $ys = ys($_SESSION['yLog']); - $nickname = $_POST['nickname']; - $ys->ban(ip(), $nickname); - - $send = []; - $send['error'] = false; - - echo json_encode($send); - } - - public function unbanSelf() - { - if (loggedIn()) { - $ys = ys($_SESSION['yLog']); - $ys->unban(ip()); - - $send = []; - $send['error'] = false; - } else { - $send = []; - $send['error'] = 'admin'; - } - - echo json_encode($send); - } - - public function reload() - { - global $prefs; - $ys = ys($_SESSION['yLog']); - - $posts = $ys->latestPosts($prefs['truncate']); - $this->setSessTimestamp($posts); - $this->updates['posts'] = $posts; - echo json_encode($this->updates); - } - - public function initSession() - { - $_SESSION['yLatestTimestamp'] = 0; - $_SESSION['yYPath'] = $_POST['yPath']; - $_SESSION['yLog'] = $_POST['log']; - $loginHash = cookieGet('yLoginHash') ; - if (isset($loginHash) && $loginHash != '') { - login($loginHash); - } - } - - public function sendBanned() - { - $this->updates = [ - 'banned' => true - ]; - - echo json_encode($this->updates); - } - - public function sendUpdates() - { - global $prefs; - $ys = ys($_SESSION['yLog']); - if (!$ys->hasPostsAfter($_SESSION['yLatestTimestamp'])) { - return; - } - - $posts = $ys->postsAfter($_SESSION['yLatestTimestamp']); - $this->setSessTimestamp($posts); - - $this->updates['posts'] = $posts; - - echo json_encode($this->updates); - } - - public function setSessTimestamp(&$posts) - { - if (!$posts) { - return; - } - - $latest = array_slice($posts, -1, 1); - $_SESSION['yLatestTimestamp'] = $latest[0]['timestamp']; - } - - public function sendFirstUpdates() - { - global $prefs, $overrideNickname; - - $this->updates = []; - - $ys = ys($_SESSION['yLog']); - - $posts = $ys->latestPosts($prefs['truncate']); - $this->setSessTimestamp($posts); - - $this->updates['posts'] = $posts; - $this->updates['prefs'] = $this->cleanPrefs($prefs); - - if ($nickname = cookieGet('yNickname')) { - $this->updates['nickname'] = $nickname; - } - - if ($overrideNickname) { - $this->updates['nickname'] = $overrideNickname; - } - - if ($ys->banned(ip())) { - $this->updates['banned'] = true; - } - - echo json_encode($this->updates); - } - - public function cleanPrefs($prefs) - { - unset($prefs['password']); - return $prefs; - } - - public function clearLog() - { - //$log = $_POST['log']; - $send = []; - $ys = ys($_SESSION['yLog']); - - switch (true) { - case !loggedIn(): - $send['error'] = 'admin'; - break; - default: - $ys->clear(); - $send['error'] = false; - } - - echo json_encode($send); - } - - public function clearLogs() - { - global $prefs; - - //$log = $_POST['log']; - $send = []; - - //$ys = ys($_SESSION['yLog']); - - switch (true) { - case !loggedIn(): - $send['error'] = 'admin'; - break; - default: - for ($i = 1; $i <= $prefs['logs']; $i++) { - $ys = ys($i); - $ys->clear(); - } - - $send['error'] = false; - } - - echo json_encode($send); - } - } diff --git a/ext/chatbox/php/filestorage.class.php b/ext/chatbox/php/filestorage.class.php deleted file mode 100644 index b75e4d82..00000000 --- a/ext/chatbox/php/filestorage.class.php +++ /dev/null @@ -1,106 +0,0 @@ -shoutLog = $shoutLog; - $folder = 'logs'; - if (!is_dir($folder)) { - $folder = '../' . $folder; - } - if (!is_dir($folder)) { - $folder = '../' . $folder; - } - - $this->path = $folder . '/' . $path . '.txt'; - } - - public function open($lock = false) - { - $this->handle = fopen($this->path, 'a+'); - - if ($lock) { - $this->lock(); - return $this->load(); - } - } - - public function close(&$array) - { - if (isset($array)) { - $this->save($array); - } - - $this->unlock(); - fclose($this->handle); - unset($this->handle); - } - - public function load() - { - if (($contents = $this->read($this->path)) == null) { - return $this->resetArray(); - } - - return unserialize($contents); - } - - public function save(&$array, $unlock = true) - { - $contents = serialize($array); - $this->write($contents); - if ($unlock) { - $this->unlock(); - } - } - - public function unlock() - { - if (isset($this->handle)) { - flock($this->handle, LOCK_UN); - } - } - - public function lock() - { - if (isset($this->handle)) { - flock($this->handle, LOCK_EX); - } - } - - public function read() - { - fseek($this->handle, 0); - //return stream_get_contents($this->handle); - return file_get_contents($this->path); - } - - public function write($contents) - { - ftruncate($this->handle, 0); - fwrite($this->handle, $contents); - } - - public function resetArray() - { - if ($this->shoutLog) { - $default = [ - 'info' => [ - 'latestTimestamp' => -1 - ], - - 'posts' => [] - ]; - } else { - $default = []; - } - - $this->save($default, false); - return $default; - } -} diff --git a/ext/chatbox/php/functions.php b/ext/chatbox/php/functions.php deleted file mode 100644 index 9ab9430f..00000000 --- a/ext/chatbox/php/functions.php +++ /dev/null @@ -1,174 +0,0 @@ -= $len) { - break; - } - if ($chr & 0x80) { - $chr <<= 1; - while ($chr & 0x80) { - $i++; - $chr <<= 1; - } - } - } - - return $count; - } - - function error($err) - { - echo 'Error: ' . $err; - exit; - } - - function ys($log = 1) - { - global $yShout, $prefs; - if ($yShout) { - return $yShout; - } - - if (filter_var($log, FILTER_VALIDATE_INT, ["options" => ["min_range" => 0, "max_range" => $prefs['logs']]]) === false) { - $log = 1; - } - - $log = 'log.' . $log; - return new YShout($log, loggedIn()); - } - - function dstart() - { - global $ts; - - $ts = ts(); - } - - function dstop() - { - global $ts; - echo 'Time elapsed: ' . ((ts() - $ts) * 100000); - exit; - } - - function login($hash) - { - // echo 'login: ' . $hash . "\n"; - - $_SESSION['yLoginHash'] = $hash; - cookie('yLoginHash', $hash); - // return loggedIn(); - } - - function logout() - { - $_SESSION['yLoginHash'] = ''; - cookie('yLoginHash', ''); - // cookieClear('yLoginHash'); - } - - function loggedIn() - { - global $prefs; - - $loginHash = cookieGet('yLoginHash', false); - // echo 'loggedin: ' . $loginHash . "\n"; - // echo 'pw: ' . $prefs['password'] . "\n"; - - if (isset($loginHash)) { - return $loginHash == md5($prefs['password']); - } - - if (isset($_SESSION['yLoginHash'])) { - return $_SESSION['yLoginHash'] == md5($prefs['password']); - } - - return false; - } diff --git a/ext/chatbox/php/yshout.class.php b/ext/chatbox/php/yshout.class.php deleted file mode 100644 index 205eda37..00000000 --- a/ext/chatbox/php/yshout.class.php +++ /dev/null @@ -1,292 +0,0 @@ -storage = new $storage($path, true); - $this->admin = $admin; - } - - public function posts() - { - global $null; - $this->storage->open(); - $s = $this->storage->load(); - $this->storage->close($null); - - if ($s) { - return $s['posts']; - } - } - - public function info() - { - global $null; - $s = $this->storage->open(true); - - $this->storage->close($null); - - if ($s) { - return $s['info']; - } - } - - public function postsAfter($ts) - { - $allPosts = $this->posts(); - - $posts = []; - - /* for ($i = sizeof($allPosts) - 1; $i > -1; $i--) { - $post = $allPosts[$i]; - - if ($post['timestamp'] > $ts) - $posts[] = $post; - } */ - - foreach ($allPosts as $post) { - if ($post['timestamp'] > $ts) { - $posts[] = $post; - } - } - - $this->postProcess($posts); - return $posts; - } - - public function latestPosts($num) - { - $allPosts = $this->posts(); - $posts = array_slice($allPosts, -$num, $num); - - $this->postProcess($posts); - return array_values($posts); - } - - public function hasPostsAfter($ts) - { - $info = $this->info(); - $timestamp = $info['latestTimestamp']; - return $timestamp > $ts; - } - - public function post($nickname, $message) - { - global $prefs; - - if ($this->banned(ip()) /* && !$this->admin*/) { - return false; - } - - if (!$this->validate($message, $prefs['messageLength'])) { - return false; - } - if (!$this->validate($nickname, $prefs['nicknameLength'])) { - return false; - } - - $message = trim(clean($message)); - $nickname = trim(clean($nickname)); - - if ($message == '') { - return false; - } - if ($nickname == '') { - return false; - } - - $timestamp = ts(); - - $message = $this->censor($message); - $nickname = $this->censor($nickname); - - $post = [ - 'nickname' => $nickname, - 'message' => $message, - 'timestamp' => $timestamp, - 'admin' => $this->admin, - 'uid' => md5($timestamp . ' ' . $nickname), - 'adminInfo' => [ - 'ip' => ip() - ] - ]; - - $s = $this->storage->open(true); - - $s['posts'][] = $post; - - if (sizeof($s['posts']) > $prefs['history']) { - $this->truncate($s['posts']); - } - - $s['info']['latestTimestamp'] = $post['timestamp']; - - $this->storage->close($s); - $this->postProcess($post); - return $post; - } - - public function truncate(&$array) - { - global $prefs; - - $array = array_slice($array, -$prefs['history']); - $array = array_values($array); - } - - public function clear() - { - global $null; - - $this->storage->open(true); - $this->storage->resetArray(); - // ? Scared to touch it... Misspelled though. Update: Touched! Used to be $nulls... - $this->storage->close($null); - } - - public function bans() - { - global $storage, $null; - - $s = new $storage('yshout.bans'); - $s->open(); - $bans = $s->load(); - $s->close($null); - - return $bans; - } - - public function ban($ip, $nickname = '', $info = '') - { - global $storage; - - $s = new $storage('yshout.bans'); - $bans = $s->open(true); - - $bans[] = [ - 'ip' => $ip, - 'nickname' => $nickname, - 'info' => $info, - 'timestamp' => ts() - ]; - - $s->close($bans); - } - - public function banned($ip) - { - global $storage, $null; - - $s = new $storage('yshout.bans'); - $bans = $s->open(true); - $s->close($null); - - foreach ($bans as $ban) { - if ($ban['ip'] == $ip) { - return true; - } - } - - return false; - } - - public function unban($ip) - { - global $storage; - - $s = new $storage('yshout.bans'); - $bans = $s->open(true); - - foreach ($bans as $key=>$value) { - if ($value['ip'] == $ip) { - unset($bans[$key]); - } - } - - $bans = array_values($bans); - $s->close($bans); - } - - public function unbanAll() - { - global $storage, $null; - - $s = new $storage('yshout.bans'); - $s->open(true); - $s->resetArray(); - $s->close($null); - } - - public function delete($uid) - { - global $prefs, $storage; - - - $s = $this->storage->open(true); - - $posts = $s['posts']; - - foreach ($posts as $key=>$value) { - if (!isset($value['uid'])) { - unset($posts['key']); - } elseif ($value['uid'] == $uid) { - unset($posts[$key]); - } - } - - $s['posts'] = array_values($posts); - $this->storage->close($s); - - return true; - } - - public function validate($str, $maxLen) - { - return len($str) <= $maxLen; - } - - public function censor($str) - { - global $prefs; - - $cWords = explode(' ', $prefs['censorWords']); - $words = explode(' ', $str); - $endings = '|ed|es|ing|s|er|ers'; - $arrEndings = explode('|', $endings); - - foreach ($cWords as $cWord) { - foreach ($words as $i=>$word) { - $pattern = '/^(' . $cWord . ')+(' . $endings . ')\W*$/i'; - $words[$i] = preg_replace($pattern, str_repeat('*', strlen($word)), $word); - } - } - - return implode(' ', $words); - } - - public function postProcess(&$post) - { - if (isset($post['message'])) { - if ($this->banned($post['adminInfo']['ip'])) { - $post['banned'] = true; - } - if (!$this->admin) { - unset($post['adminInfo']); - } - } else { - foreach ($post as $key=>$value) { - if ($this->banned($value['adminInfo']['ip'])) { - $post[$key]['banned'] = true; - } - if (!$this->admin) { - unset($post[$key]['adminInfo']); - } - } - } - } -} diff --git a/ext/chatbox/preferences.php b/ext/chatbox/preferences.php deleted file mode 100644 index 4a337ac9..00000000 --- a/ext/chatbox/preferences.php +++ /dev/null @@ -1,75 +0,0 @@ -open(); - $prefs = $s->load(); - $s->close($null); - } - - function savePrefs($newPrefs) - { - global $prefs, $storage; - - $s = new $storage('yshout.prefs'); - $s->open(true); - $s->close($newPrefs); - $prefs = $newPrefs; - } - - function resetPrefs() - { - $defaultPrefs = [ - 'password' => 'fortytwo', // The password for the CP - - 'refresh' => 6000, // Refresh rate - - 'logs' => 5, // Amount of different log files to allow - 'history' => 200, // Shouts to keep in history - - 'inverse' => false, // Inverse shoutbox / form on top - - 'truncate' => 15, // Truncate messages client-side - 'doTruncate' => true, // Truncate messages? - - 'timestamp' => 12, // Timestamp format 12- or 24-hour - - 'defaultNickname' => 'Nickname', - 'defaultMessage' => 'Message Text', - 'defaultSubmit' => 'Shout!', - 'showSubmit' => true, - - 'nicknameLength' => 25, - 'messageLength' => 175, - - 'nicknameSeparator' => ':', - - 'flood' => true, - 'floodTimeout' => 5000, - 'floodMessages' => 4, - 'floodDisable' => 8000, - 'floodDelete' => false, - - 'autobanFlood' => 0, // Autoban people for flooding after X messages - - 'censorWords' => 'fuck shit bitch ass', - - 'postFormLink' => 'history', - - 'info' => 'inline' - ]; - - savePrefs($defaultPrefs); - } - - resetPrefs(); - //loadPrefs(); diff --git a/ext/chatbox/smileys/biggrin.gif b/ext/chatbox/smileys/biggrin.gif deleted file mode 100644 index d3527723c6d8a0ddfa7ca0bfe1ab8fce0055918c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 172 zcmZ?wbhEHbgxLc6$23b2ZD19|4%af-@@>3F2nzSlmGt}{{R2@|NpQ5 zKLsg(0L7myj0_CC3_2h#$P5OS$PJ#HS#x(>T`Hg?&Q{P6{IT@*|fe Qt&nb$oR(_V$-rO@0AZ~_>i_@% diff --git a/ext/chatbox/smileys/confused.gif b/ext/chatbox/smileys/confused.gif deleted file mode 100644 index 0c49e06983f1fff4bc0834b4d86ce39b8a36a914..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 171 zcmZ?wbhEHbZXiyV-#U P9L#x)b-Z(h7#XYqI2k)k diff --git a/ext/chatbox/smileys/cool.gif b/ext/chatbox/smileys/cool.gif deleted file mode 100644 index cead0306c0e38e57bdb0cc85a407b995dcbdc656..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 172 zcmZ?wbhEHb+|z`)C(1LA_rU|@;d;3=6kcSq>7bCTj>1sqIsoCSRx)8`fJ$~w+{ zJX`yX^?~=R4m2(o_)+HS{ItMiUIk0)fwE>-?dDgxjscmQ{AM&TEaGA7z8`VSO88#> SHjRW8(oK@nQq4LU7_0%kd_$xF diff --git a/ext/chatbox/smileys/cry.gif b/ext/chatbox/smileys/cry.gif deleted file mode 100644 index 7d54b1f994bb20c2a17c6e9e53edb39e0444b380..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 498 zcmZ?wbhEHbivPL&TtkAL9RpmA^bD98ftnS6varfA2r%e?3<5cWfi*@! zrOPq0Pa{O{R3VSL)CLZwJI;bVj@ow|9P^f2{b_KV;g#sD#JTIhK{X4eRSZoFOA4&E zE?xGWjgRM;Ia^8kzR>%TOS23r6eRl<`~6;g|7yg@*31^DX`|+%tO&MH1Y{u#11keN z5Hhd|DyTR-@tBu#X^wBxK7*WjP8?uWTo6?pKs7*@va%&Sa#%9C1z8HDof#;_rJ&H~ zFsWx*ry9h3B%L5>ZUqL1B|!6=oIFuX25Dyj%JU{%Vn~@hA!8Mj(`_aU6Ueh0) diff --git a/ext/chatbox/smileys/eek.gif b/ext/chatbox/smileys/eek.gif deleted file mode 100644 index 5d3978106a2da37441ed17c9d05383b367570d46..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 170 zcmZ?wbhEHbd`4m;$l6XN^_D8SRJJ2FugV_ z;@-1W`~Ak%x7W!T7_8VEVD?C1V$(vmHm-x7t|ENQXTMbHG-$9e9m-TqP;V|s+-sI@ SDB66dp*Gz_Y_|#%gEasOPe3vN diff --git a/ext/chatbox/smileys/evil.gif b/ext/chatbox/smileys/evil.gif deleted file mode 100644 index ab1aa8e123fe263608d06126ce08c560ad419f97..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 236 zcmZ?wbhEHbgxLc6$23bKgaO@B*VYC4FCTM|KGy!A1Lx~^8f$G|7kJ& z%VnN6ZQB2*4FCVX1}P;4DE?$&WMB|r&;e-z*~!3~slec{BxBNqoiq9;sWfXDwJwx! zTfpypu*1~B&zgxLc6$23b2ZD19|4%af-@@>3F2n!7!vFtG{{R2@|NpQ5 zKLsg(0LA~@ey$E)D;vwK1$ZJE z)->GK{b0hvv^Z;7;HB1zIS=v}c`BF7qB`mkh55UYFL448CX~YJS?+%vC0^DXyTAT=mC2Y$ux)_YXI57TebiI diff --git a/ext/chatbox/smileys/mad.gif b/ext/chatbox/smileys/mad.gif deleted file mode 100644 index 1f6c3c2fb401596ec44f4a1189bde2cbc45364aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 174 zcmZ?wbhEHb3F2nzSlmGt}{tp7j|Nnpe z|0z%&3KV~`FfuUkGU$N#ATtF%wyNW~cLKD&UCI$nR5;ND%aoaG8jR+sH5 z;LGade6U~GQPko`gGJNAq7#;kr@G#2#;~znnVhs^*T0km#>C~4JR&=FdsEeR+|3R= Q;9xFbtmB<4#K>R`0GZ1@LjV8( diff --git a/ext/chatbox/smileys/razz.gif b/ext/chatbox/smileys/razz.gif deleted file mode 100644 index 29da2a2fccc79981bc54db7513ca6d2374592f9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 176 zcmZ?wbhEHb^3h|5y0`zsdjqAOHXV zwXw1B|EEADAfWh@g^_`Qk3k2-0hz(T5_`c@GHdRQt4o8V#Kj6YnC2W7^l?<@Q2(%O z^|TpzE=L6K%vq%4Qv0AgI88 ZPHWn(3w4)`M4Rs!oY|mbDlEug4FCb$KH>lX diff --git a/ext/chatbox/smileys/redface.gif b/ext/chatbox/smileys/redface.gif deleted file mode 100644 index ad7628320c3d15756c84794c8c0523f1072da640..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 650 zcmZ?wbhEHb&Qw$Gs7{2#K|NnmWcSgp)ZKdDmF#NyN{%1+%|LxoV z&6x4L*vr+`_5YJ6|9^e`f9A~pR}4QI8vg%z`Rh8vzsC$emo5AMNBH0A=KudDKaP*T z>0!pe!0`X+%wGqqfegj}+zPv3R$%UgcxPlMx(u7qxxxfZd?$&YQ;PGndxWo3ZY ziH`8-T?`B&DNk$k=JGRs=w-6FQO@h2ko&aap$ji#VOF!1O><{wyHRCMkfx2Ai?Slv zYA%q~j0}tnyg^Qv|J?fJ`y}Jo`B}5IcZU0i%+^)m>vp{!Bqu6#)+xQyYu&8=mRY(7 z)}5aCNL5gG*%{+AHF>K87ridk_T^KXg3qiu^$yZP~SpxtUz5smy diff --git a/ext/chatbox/smileys/rolleyes.gif b/ext/chatbox/smileys/rolleyes.gif deleted file mode 100644 index d7f5f2f4b18f8a141c7a5dd1e09ff106a2f9fa1e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 485 zcmZ?wbhEHbgxLc6$23bKgaO@B*Xvz|NqTp_`ikW|G&xq{~!PVSNQ)^ zpx|qe3NTRo&+X?L671|4;A*62z|05~RQ$=p%EiFTpaW6>GM0fQZi6Rh*4!PT(*&f% z*$TRZ<}@?I^CYG*?eW$Pd$isBan+(fO1gn0b6dW=x%w~q}~tKE&`I~ zWZ+_80zw8BmJOU2m9Ux1yJ3o3D&v+$ZG#t4ZLVMy3?Qu_ZQMY+8CYaDcq&S-H42Fh z{c)CE%Sn@EnS+n-#i)qLlhWcv5Vs)dU<2w9+u*4hy}}}Vq4ah~j;>ScENX^v3nduQ d4TmZP8gAjeGaoDCD!-THXQ zaD}Q`!Ef~@t%4VS^H`jpHe@qRnmW&T1rN_M_11z^Th4v=m-`t@{9)jl*%hj`3F2nzSlmGt}{tp7jjg5`} z|9}1eDNqRrDE?$&WMJT9&;fBkW-zcsU+|R7ntLO3**QsZu>uaJIn9DTj_MrhAC|2y zn^DM@#l<(@zDcWq`B+oyDaGR~0+SdoFXD`_(PqAxy<2o0Q>0^(jhH~$tb+>(~Mkip?iSJVUgxLc6$23bKgaNIF2n!7!vD80{0DM@;NRr`CxMLP|FjsU zO`B$HZ2T{m`TzgdAk{j*8D$QDUE*nK$ z7w|KG>@aokb7%R&!0WI`LE+V`jZbtHGVEq^HDzd8gshBhJhWk{9N&@6Gj#R{?N7d_ u@Ss3Q_U6Qmr`{j;vSH$AZf0`Va5JoNi_%bKV4KJmrQFw{HdRBB!5RP#AxjVd diff --git a/ext/chatbox/smileys/wink.gif b/ext/chatbox/smileys/wink.gif deleted file mode 100644 index d1482880421dde677d3302940aa875ff22a11b06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 170 zcmZ?wbhEHba9D@n#Zhbsv zutHU>;J1F0R>6zE2`tV}8xE^#?@bGklrZsUYAp!;dbG*vY{CM88Jk-qvwbqQUtQFY Pm?x1IA$CiJiNP8Goi0B( diff --git a/ext/chatbox/yshout.php b/ext/chatbox/yshout.php deleted file mode 100644 index dfa356b9..00000000 --- a/ext/chatbox/yshout.php +++ /dev/null @@ -1,39 +0,0 @@ -process(); - break; - - case 'history': - - // echo $_POST['log']; - $ajax = new AjaxCall($_POST['log']); - $ajax->process(); - break; - - default: - exit; - } -} else { - include 'example.html'; -} - -function errorOccurred($num, $str, $file, $line) -{ - $err = [ - 'yError' => "$str. \n File: $file \n Line: $line" - ]; - - echo json_encode($err); - - exit; -}