/** * Simulate a user visiting the URL from a browser as closely as we can * * @param string $url * @param array|null $cookies * @param string|null $referrer * @param bool $skipBody * * @return array */ static function legitimateRequest($url, $cookies = null, $referrer = null, bool $skipBody = false) { $r = curl_init(); $curl_opt = array(CURLOPT_HTTPHEADER => array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Encoding: gzip, deflate, sdch", "Accept-Language: hu,en-GB;q=0.8,en;q=0.6", "Connection: keep-alive"), CURLOPT_HEADER => true, CURLOPT_URL => $url, CURLOPT_BINARYTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.5678.91 Safari/537.36"); if (isset($referrer)) { $curl_opt[CURLOPT_REFERER] = $referrer; } if (is_array($cookies)) { $curl_opt[CURLOPT_COOKIE] = implode('; ', $cookies); } if ($skipBody === true) { $curl_opt[CURLOPT_NOBODY] = $skipBody; } curl_setopt_array($r, $curl_opt); $response = curl_exec($r); $responseCode = curl_getinfo($r, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($r, CURLINFO_HEADER_SIZE); $responseHeaders = rtrim(CoreUtils::substring($response, 0, $headerSize)); $response = CoreUtils::substring($response, $headerSize); $curlError = curl_error($r); curl_close($r); if ($responseCode < 200 || $responseCode >= 300) { throw new CURLRequestException(rtrim("cURL fail for URL \"{$url}\" (HTTP {$responseCode}); {$curlError}", ' ;'), $responseCode); } global $http_response_header; $http_response_header = array_map("rtrim", explode("\n", $responseHeaders)); if (preg_match(new RegExp('Content-Encoding:\\s?gzip'), $responseHeaders)) { $response = gzdecode($response); } return array('responseHeaders' => $responseHeaders, 'response' => $response); }
/** * Makes authenticated requests to the DeviantArt API * * @param string $endpoint * @param null|array $postdata * @param null|string $token * * @return array */ static function request($endpoint, $token = null, $postdata = null) { global $signedIn, $currentUser, $http_response_header; $requestHeaders = array("Accept-Encoding: gzip", "User-Agent: MLPVC-RR @ " . GITHUB_URL); if (!isset($token) && $signedIn) { $token = $currentUser->Session['access']; } if (!empty($token)) { $requestHeaders[] = "Authorization: Bearer {$token}"; } else { if ($token !== false) { return null; } } $requestURI = preg_match(new RegExp('^https?://'), $endpoint) ? $endpoint : "https://www.deviantart.com/api/v1/oauth2/{$endpoint}"; $r = curl_init($requestURI); $curl_opt = array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_HTTPHEADER => $requestHeaders, CURLOPT_HEADER => 1, CURLOPT_BINARYTRANSFER => 1); if (!empty($postdata)) { $query = array(); foreach ($postdata as $k => $v) { $query[] = urlencode($k) . '=' . urlencode($v); } $curl_opt[CURLOPT_POST] = count($postdata); $curl_opt[CURLOPT_POSTFIELDS] = implode('&', $query); } curl_setopt_array($r, $curl_opt); $response = curl_exec($r); $responseCode = curl_getinfo($r, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($r, CURLINFO_HEADER_SIZE); $responseHeaders = rtrim(CoreUtils::substring($response, 0, $headerSize)); $response = CoreUtils::substring($response, $headerSize); $http_response_header = array_map("rtrim", explode("\n", $responseHeaders)); $curlError = curl_error($r); curl_close($r); self::$requestCount++; if ($responseCode < 200 || $responseCode >= 300) { throw new CURLRequestException(rtrim("cURL fail for URL \"{$requestURI}\" (HTTP {$responseCode}); {$curlError}", ' ;'), $responseCode); } if (preg_match(new RegExp('Content-Encoding:\\s?gzip'), $responseHeaders)) { $response = gzdecode($response); } return JSON::decode($response); }
/** * Checks if a deviation is in the club * * @param int|string $DeviationID * * @return bool|int */ static function isDeviationInClub($DeviationID) { if (!is_int($DeviationID)) { $DeviationID = intval(CoreUtils::substring($DeviationID, 1), 36); } try { $DiFiRequest = HTTP::legitimateRequest("http://deviantart.com/global/difi/?c[]=\"DeviationView\",\"getAllGroups\",[\"{$DeviationID}\"]&t=json"); } catch (CURLRequestException $e) { return $e->getCode(); } if (empty($DiFiRequest['response'])) { return 1; } $DiFiRequest = @JSON::decode($DiFiRequest['response'], JSON::AS_OBJECT); if (empty($DiFiRequest->DiFi->status)) { return 2; } if ($DiFiRequest->DiFi->status !== 'SUCCESS') { return 3; } if (empty($DiFiRequest->DiFi->response->calls)) { return 4; } if (empty($DiFiRequest->DiFi->response->calls[0])) { return 5; } if (empty($DiFiRequest->DiFi->response->calls[0]->response)) { return 6; } if (empty($DiFiRequest->DiFi->response->calls[0]->response->status)) { return 7; } if ($DiFiRequest->DiFi->response->calls[0]->response->status !== 'SUCCESS') { return 8; } if (empty($DiFiRequest->DiFi->response->calls[0]->response->content->html)) { return 9; } $html = $DiFiRequest->DiFi->response->calls[0]->response->content->html; return strpos($html, 'gmi-groupname="MLP-VectorClub">') !== false; }
private static function _arrangeNewOld($data) { $newOld = array(); unset($data['entryid'], $data['target']); foreach ($data as $k => $v) { if (is_null($v)) { continue; } $thing = CoreUtils::substring($k, 3); $type = CoreUtils::substring($k, 0, 3); if (!isset($newOld[$thing])) { $newOld[$thing] = array(); } $newOld[$thing][$type] = $thing === 'twoparter' ? !!$v : $v; } return $newOld; }
<?php switch ($errcause) { case "db": ?> <h1>Database connection error</h1> <p>Could not connect to database on <?php echo DB_HOST; ?> </p> <?php echo CoreUtils::notice('info', '<span class="typcn typcn-info-large"></span> The database of our website cannot be reached. Hopefully this is just a temporary issue and everything will be back to normal soon. Sorry for the inconvenience. <a class="send-feedback">Notify the developer</a>', true); echo CoreUtils::notice('warn', '<strong>Probable cause / debug information:</strong><pre><code>' . $e->getMessage() . '</code></pre>', true); break; case "libmiss": ?> <h1>Configuration problem</h1> <p>A required extension/setting is missng</p> <?php echo CoreUtils::notice('info', '<span class="typcn typcn-info-large"></span> One of the site\'s core modules have not been installed yet. This usually happens after a software upgrade/reinstall and is just a temporary issue, no data has been lost and everything will be back to normal very soon. Sorry for the inconvenience. <a class="send-feedback">Notify the developer</a>', true); echo CoreUtils::notice('warn', '<strong>Probable cause / debug information:</strong><pre><code>' . $e->getMessage() . '</code></pre>', true); break; } ?> </div> <?php echo CoreUtils::exportVars(array('ServiceUnavailableError' => true)); $customJS = array("/js/min/global.js", "/js/min/moment.js", "/js/min/dialog.js"); foreach ($customJS as $k => $el) { $customJS[$k] .= '?' . filemtime(APPATH . CoreUtils::substring($el, 1)); } require "footer.php";
/** * Get Request / Reservation Submission Form HTML * * @param string $type * * @return string */ private static function _getForm($type) { global $currentUser; $Type = strtoupper($type[0]) . CoreUtils::substring($type, 1); $optional = $type === 'reservation' ? 'optional, ' : ''; $optreq = $type === 'reservation' ? '' : 'required'; $HTML = <<<HTML \t<form class="hidden post-form" data-type="{$type}"> \t\t<h2>Make a {$type}</h2> \t\t<div> \t\t\t<label> \t\t\t\t<span>{$Type} description ({$optional}3-255 chars)</span> \t\t\t\t<input type="text" name="label" pattern="^.{3,255}\$" maxlength="255" {$optreq}> \t\t\t</label> \t\t\t<label> \t\t\t\t<span>Image URL</span> \t\t\t\t<input type="text" name="image_url" pattern="^.{2,255}\$" required> \t\t\t\t<button type="button" class="check-img red typcn typcn-arrow-repeat">Check image</button><br> \t\t\t</label> \t\t\t<div class="img-preview"> \t\t\t\t<div class="notice info"> \t\t\t\t\t<p>Please click the <strong>Check image</strong> button after providing an URL to get a preview & verify if the link is correct.</p> \t\t\t\t\t<hr> \t\t\t\t\t<p class="keep">You can use a link from any of the following providers: <a href="http://sta.sh/" target="_blank">Sta.sh</a>, <a href="http://deviantart.com/" target="_blank">DeviantArt</a>, <a href="http://imgur.com/" target="_blank">Imgur</a>, <a href="http://derpibooru.org/" target="_blank">Derpibooru</a>, <a href="http://puush.me/" target="_blank">Puush</a>, <a href="http://app.prntscr.com/" target="_blank">LightShot</a></p> \t\t\t\t</div> \t\t\t</div> HTML; if ($type === 'request') { $HTML .= <<<HTML \t\t\t<label> \t\t\t\t<span>{$Type} type</span> \t\t\t\t<select name="type" required> \t\t\t\t\t<option value="" style="display:none" selected>Choose one</option> \t\t\t\t\t<optgroup label="{$Type} types"> \t\t\t\t\t\t<option value="chr">Character</option> \t\t\t\t\t\t<option value="bg">Background</option> \t\t\t\t\t\t<option value="obj">Object</option> \t\t\t\t\t</optgroup> \t\t\t\t</select> \t\t\t</label> HTML; } if (Permission::sufficient('developer')) { $UNP = USERNAME_PATTERN; $HTML .= <<<HTML \t\t\t<label> \t\t\t\t<span>{$Type} as user</span> \t\t\t\t<input type="text" name="post_as" pattern="^{$UNP}\$" maxlength="20" placeholder="Username" spellcheck="false"> \t\t\t</label> HTML; } $HTML .= <<<HTML \t\t</div> \t\t<button class="green">Submit {$type}</button> <button type="reset">Cancel</button> \t</form> HTML; return $HTML; }