8 define(
'ACCESS_KEY',
getParam(
'ch_sites_key_id'));
9 define(
'SECRET_KEY',
getParam(
'ch_sites_secret_key'));
10 define(
'ACCOUNT_TYPE',
getParam(
'ch_sites_account_type'));
11 define(
'THUMBNAIL_URI',
$GLOBALS[
'oChSitesModule']->sThumbUrl);
12 define(
'THUMBNAIL_DIR',
$GLOBALS[
'oChSitesModule']->sThumbPath);
13 define(
'INSIDE_PAGES',
getParam(
'ch_sites_inside_pages') ==
'on' ?
true :
false);
14 define(
'CUSTOM_MSG_URL',
getParam(
'ch_sites_custom_msg_url'));
15 define(
'CACHE_DAYS',
getParam(
'ch_sites_cache_days'));
18 define(
'VER',
'2.0.3_dol7');
19 define(
'DEBUG',
getParam(
'ch_sites_debug') ==
'on' ?
true :
false);
20 define(
'QUOTA_IMAGE',
'quota.jpg');
21 define(
'BANDWIDTH_IMAGE',
'bandwidth.jpg');
22 define(
'NO_RESPONSE_IMAGE',
'no_response.jpg');
54 $sRequestUrl =
'http://images.shrinktheweb.com/account.php';
58 if ($aResponse[
'stw_response_status'] ==
'Success') {
72 $aArgs[
'stwurl'] =
$sUrl;
87 if ($sImageUrl ==
'no_response') {
103 return $sImageUrl ?
'<img src="' .
ch_html_attribute($sImageUrl) .
'"'.$sTags.
'/>' :
false;
120 if ($iCacheDays >= 0 && $aOptions[
'Embedded'] != 1) {
121 $aArgs[
'stwurl'] =
$sUrl;
125 unset($aArgs[
'stwu']);
126 $aArgs[
'stwembed'] = 1;
127 $aArgs[
'stwurl'] =
$sUrl;
128 $sImageUrl = urldecode(
"http://images.shrinktheweb.com/xino.php?".http_build_query($aArgs,
'',
'&'));
139 $aOptions[
'Size'] = $aOptions[
'Size'] ? $aOptions[
'Size'] :
getParam(
'ch_sites_thumb_size');
140 $aOptions[
'SizeCustom'] = $aOptions[
'SizeCustom'] ? $aOptions[
'SizeCustom'] :
getParam(
'ch_sites_thumb_size_custom');
141 $aOptions[
'FullSizeCapture'] = $aOptions[
'FullSizeCapture'] ? $aOptions[
'FullSizeCapture'] :
getParam(
'ch_sites_full_size') ==
'on' ?
true :
false;
142 $aOptions[
'MaxHeight'] = $aOptions[
'MaxHeight'] ? $aOptions[
'MaxHeight'] :
getParam(
'ch_sites_max_height');
143 $aOptions[
'NativeResolution'] = $aOptions[
'NativeResolution'] ? $aOptions[
'NativeResolution'] :
getParam(
'ch_sites_native_res');
144 $aOptions[
'WidescreenY'] = $aOptions[
'WidescreenY'] ? $aOptions[
'WidescreenY'] :
getParam(
'ch_sites_widescreen_y');
145 $aOptions[
'RefreshOnDemand'] = $aOptions[
'RefreshOnDemand'] ? $aOptions[
'RefreshOnDemand'] :
false;
146 $aOptions[
'Delay'] = $aOptions[
'Delay'] ? $aOptions[
'Delay'] :
getParam(
'ch_sites_delay');
147 $aOptions[
'Quality'] = $aOptions[
'Quality'] ? $aOptions[
'Quality'] :
getParam(
'ch_sites_quality');
160 $aArgs[
'stwver'] =
VER;
164 $aArgs[
'stwinside'] = 1;
169 if (!$aOptions[
'FullSizeCapture'] && !$aOptions[
'WidescreenY']) {
171 if ($aOptions[
'SizeCustom']) {
172 $aArgs[
'stwxmax'] = $aOptions[
'SizeCustom'];
174 $aArgs[
'stwsize'] = $aOptions[
'Size'];
179 if ($aOptions[
'FullSizeCapture']) {
180 $aArgs[
'stwfull'] = 1;
181 if ($aOptions[
'SizeCustom']) {
182 $aArgs[
'stwxmax'] = $aOptions[
'SizeCustom'];
184 $aArgs[
'stwxmax'] = 120;
186 if ($aOptions[
'MaxHeight']) {
187 $aArgs[
'stwymax'] = $aOptions[
'MaxHeight'];
192 if ($aOptions[
'NativeResolution']) {
193 $aArgs[
'stwnrx'] = $aOptions[
'NativeResolution'];
194 if ($aOptions[
'WidescreenY']) {
195 $aArgs[
'stwnry'] = $aOptions[
'WidescreenY'];
196 if ($aOptions[
'SizeCustom']) {
197 $aArgs[
'stwxmax'] = $aOptions[
'SizeCustom'];
199 $aArgs[
'stwxmax'] = 120;
205 if ($aOptions[
'Delay']) {
206 $aArgs[
'stwdelay'] = intval($aOptions[
'Delay']) <= 45 ? intval($aOptions[
'Delay']) : 45;
210 if ($aOptions[
'RefreshOnDemand']) {
211 $aArgs[
'stwredo'] = 1;
215 if ($aOptions[
'Quality']) {
216 $aArgs[
'stwq'] = intval($aOptions[
'Quality']);
232 $aArgs = is_array($aArgs) ? $aArgs : array();
238 $sReturnName =
false;
240 $iForceUpdate = $aArgs[
'stwredo'] ?
true :
false;
254 switch ($aImage[
'status']) {
260 return $aImage[
'url'];
269 case 'bandwidth_exceed':
276 return $aImage[
'status'];
283 if (file_exists(
$sFile)) {
295 $sRequestUrl =
'http://images.shrinktheweb.com/xino.php';
298 if ($sRemoteData !=
"") {
301 if ($aResponse[
'exists'] && $aResponse[
'thumbnail'] !=
'') {
302 $aImage = array(
'status' =>
'save',
'url' => $aResponse[
'thumbnail']);
305 }
else if ($aResponse[
'stw_bandwidth_remaining'] == 0 && !$aResponse[
'locked'] && !$aResponse[
'invalid'] && !$aResponse[
'exists']) {
306 $aImage = array(
'status' =>
'bandwidth_exceed',
'url' => $aResponse[
'thumbnail']);
308 }
else if ($aResponse[
'stw_quota_remaining'] == 0 && !$aResponse[
'locked'] && !$aResponse[
'invalid'] && !$aResponse[
'exists']) {
309 $aImage = array(
'status' =>
'quota_exceed',
'url' => $aResponse[
'thumbnail']);
311 }
else if (!$aResponse[
'exists'] && $aResponse[
'thumbnail'] !=
'') {
312 $aImage = array(
'status' =>
'nosave',
'url' => $aResponse[
'thumbnail']);
315 $aImage = array(
'status' =>
'error');
322 $aImage = array(
'status' =>
'no_response');
337 if ($oFile = fopen(
$sFile,
"w+")) {
338 fputs($oFile, $sRemoteData);
343 if (file_exists(
$sFile)) {
363 $aArgs[
'stwaccesskeyid'] =
'accountproblem';
365 if ($aOptions[
'SizeCustom']) {
366 $aArgs[
'stwxmax'] = $aOptions[
'SizeCustom'];
368 $aArgs[
'stwsize'] = $aOptions[
'Size'];
371 $sRequestUrl =
'http://images.shrinktheweb.com/xino.php';
374 if ($sRemoteData !=
'') {
377 if (!$aResponse[
'exists'] && $aResponse[
'thumbnail'] !=
'') {
378 $sImageUrl = $aResponse[
'thumbnail'];
384 if ($isDownloaded ==
true) {
401 if (!file_exists(
$sFile)) {
406 $iCutoff =
time() - (3600 * 6);
407 if (filemtime(
$sFile) <= $iCutoff) {
442 $aReplace = array(
'http',
'https',
'ftp',
'://');
443 $sUrl = str_replace($aReplace,
'', $aArgs[
'stwurl']);
454 if (extension_loaded(
'simplexml')) {
455 $oDOM =
new DOMDocument;
456 $oDOM->loadXML($sResponse);
457 $sXML = simplexml_import_dom($oDOM);
458 $sXMLLayout =
'http://www.shrinktheweb.com/doc/stwresponse.xsd';
461 $aResponse[
'stw_response_status'] = $sXML->children($sXMLLayout)->Response->ResponseStatus->StatusCode;
462 $aResponse[
'stw_action'] = $sXML->children($sXMLLayout)->Response->ThumbnailResult->Thumbnail[1];
463 $aResponse[
'stw_response_code'] = $sXML->children($sXMLLayout)->Response->ResponseCode->StatusCode;
464 $aResponse[
'stw_last_captured'] = $sXML->children($sXMLLayout)->Response->ResponseTimestamp->StatusCode;
465 $aResponse[
'stw_quota_remaining'] = $sXML->children($sXMLLayout)->Response->Quota_Remaining->StatusCode;
466 $aResponse[
'stw_bandwidth_remaining'] = $sXML->children($sXMLLayout)->Response->Bandwidth_Remaining->StatusCode;
467 $aResponse[
'stw_category_code'] = $sXML->children($sXMLLayout)->Response->CategoryCode->StatusCode;
468 $aResponse[
'thumbnail'] = $sXML->children($sXMLLayout)->Response->ThumbnailResult->Thumbnail[0];
471 $aResponse[
'stw_response_status'] =
_getLegacyResponse(
'ResponseStatus', $sRemoteData);
475 $aResponse[
'stw_quota_remaining'] =
_getLegacyResponse(
'Quota_Remaining', $sRemoteData);
477 $aResponse[
'stw_bandwidth_remaining'] =
_getLegacyResponse(
'Bandwidth_Remaining', $sRemoteData);
481 $aResponse = array_merge($aResponse, $aThumbnail);
484 if ($aResponse[
'stw_action'] ==
'delivered') {
485 $aResponse[
'exists'] =
true;
487 $aResponse[
'exists'] =
false;
490 if ($aResponse[
'stw_action'] ==
'fix_and_retry') {
491 $aResponse[
'problem'] =
true;
493 $aResponse[
'problem'] =
false;
496 if ($aResponse[
'stw_action'] ==
'noretry' && !$aResponse[
'exists']) {
497 $aResponse[
'error'] =
true;
499 $aResponse[
'error'] =
false;
503 if ($aResponse[
'stw_response_code'] ==
'INVALID_REQUEST') {
504 $aResponse[
'invalid'] =
true;
506 $aResponse[
'invalid'] =
false;
510 if ($aResponse[
'stw_response_code'] ==
'LOCK_TO_ACCOUNT') {
511 $aResponse[
'locked'] =
true;
513 $aResponse[
'locked'] =
false;
521 $sRegex =
'/<[^:]*:' . $sSearch .
'[^>]*>[^<]*<[^:]*:StatusCode[^>]*>([^<]*)<\//';
522 if (preg_match($sRegex,
$s, $sMatches)) {
530 $sRegex =
'/<[^:]*:ThumbnailResult?[^>]*>[^<]*<[^:]*:Thumbnail\s*(?:Exists=\"((?:true)|(?:false))\")+[^>]*>([^<]*)<\//';
531 if (preg_match($sRegex,
$s, $sMatches)) {
532 return array(
'stw_action' => $sMatches[1],
533 'thumbnail' => $sMatches[2]);
547 if ($iCacheDays == 0 && file_exists(
$sFile)) {
551 $iCutoff =
time() - (3600 * 24 * $iCacheDays);
552 return (!file_exists(
$sFile) || filemtime(
$sFile) <= $iCutoff);
561 if ($aArray && isset($aArray[$sKey])) {
562 return $aArray[$sKey];
566 if ($isReturnSpace) {
578 if (extension_loaded(
'simplexml')) {
579 $oDOM =
new DOMDocument;
580 $oDOM->loadXML($sResponse);
581 $sXML = simplexml_import_dom($oDOM);
582 $sXMLLayout =
'http://www.shrinktheweb.com/doc/stwacctresponse.xsd';
585 $aResponse[
'stw_response_status'] = $sXML->children($sXMLLayout)->Response->Status->StatusCode;
586 $aResponse[
'stw_account_level'] = $sXML->children($sXMLLayout)->Response->Account_Level->StatusCode;
588 $aResponse[
'stw_inside_pages'] = $sXML->children($sXMLLayout)->Response->Inside_Pages->StatusCode;
589 $aResponse[
'stw_custom_size'] = $sXML->children($sXMLLayout)->Response->Custom_Size->StatusCode;
590 $aResponse[
'stw_full_length'] = $sXML->children($sXMLLayout)->Response->Full_Length->StatusCode;
591 $aResponse[
'stw_refresh_ondemand'] = $sXML->children($sXMLLayout)->Response->Refresh_OnDemand->StatusCode;
592 $aResponse[
'stw_custom_delay'] = $sXML->children($sXMLLayout)->Response->Custom_Delay->StatusCode;
593 $aResponse[
'stw_custom_quality'] = $sXML->children($sXMLLayout)->Response->Custom_Quality->StatusCode;
594 $aResponse[
'stw_custom_resolution'] = $sXML->children($sXMLLayout)->Response->Custom_Resolution->StatusCode;
595 $aResponse[
'stw_custom_messages'] = $sXML->children($sXMLLayout)->Response->Custom_Messages->StatusCode;
604 $aResponse[
'stw_refresh_ondemand'] =
_getLegacyResponse(
'Refresh_OnDemand', $sRemoteData);
606 $aResponse[
'stw_custom_quality'] =
_getLegacyResponse(
'Custom_Quality', $sRemoteData);
607 $aResponse[
'stw_custom_resolution'] =
_getLegacyResponse(
'Custom_Resolution', $sRemoteData);
608 $aResponse[
'stw_custom_messages'] =
_getLegacyResponse(
'Custom_Messages', $sRemoteData);