accountId; } public function getFairShareAccountStatus(){ return $this->accountStatus; } public function isValidUserKey($userKey){ $userValidatorUrl = $this->fairShareUserValidationUrl; if (!empty($userKey)) { $userValidatorUrl .= $userKey; } $response = $this->fetchContent($userValidatorUrl); if($response == true){ $decodedResponse = json_decode($response, true); $this->accountId = $decodedResponse['rsp']['companyId']; $this->accountStatus = $decodedResponse['rsp']['companyStatus']; return true; } return false; } public function getRevenueInformation($userKey){ $userRevenueUrl = ''; if (!empty($userKey)) { $userRevenueUrl = $this->fairShareBaseUrl . "/" . $userKey . "/revenue"; } $response = $this->fetchContent($userRevenueUrl); if($response == true){ $decodedResponse = json_decode($response, true); return $decodedResponse['rsp']['earnings']; } return -1; } public function ingestSource($companyId, $postUrl, $title, $content, $widgetType){ $_err = 'lib sockets::'.__FUNCTION__.'(): '; $str = ''; $path = $this->SOURCE_UPLOAD_PATH; $str .= urlencode('companyId') . '=' . urlencode($companyId) . '&'; $str .= urlencode('articleId') . '=' . urlencode($postUrl) . '&'; $str .= urlencode('url') . '=' . urlencode($postUrl) . '&'; $str .= urlencode('title') . '=' . urlencode($title) . '&'; $str .= urlencode('content') . '=' . urlencode($content) . '&'; $str .= urlencode('srcWidgetType') . '=' . urlencode($widgetType); $fp = fsockopen($this->fairShareSrcIngestionUrl,$this->SRC_INGESTION_PORT,$errno,$errstr,$timeout=$this->SRC_INGESTION_TIMEOUT); if(!$fp){ // Log the upload error $fairShareAnalytics = new FairShareAnalytics(); $fairShareAnalytics->logFairShareError($companyId, 0, 2); } else{ stream_set_timeout($fp, $this->TIMEOUT_SECONDS); fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $this->fairShareSrcIngestionUrl\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ".strlen($str)."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $str."\r\n\r\n"); while(!feof($fp)) $response .= fgets($fp,4096); fclose($fp); // If it timed out, return false. if ($timeout['timed_out']) { return false; } } return $response; } private function fetchContent($url){ if (ini_get('allow_url_fopen') == '1'){ // Open the url $fp = @fopen($url, 'r'); if ($fp) { //Set the timeout stream_set_timeout($fp, $this->TIMEOUT_SECONDS); $response = ''; // Read till EOF while ($line = fread($fp, 1024)) { $response .= $line; } $timeout = stream_get_meta_data($fp); fclose($fp); // If it timed out, return false. if ($timeout['timed_out']) { return false; } return $response; } return false; } else{ //Check if curl is installed if (function_exists('curl_init')) { $curlHandler = curl_init(); // Set the url curl_setopt($curlHandler, CURLOPT_URL, $url); // Don't return headers curl_setopt($curlHandler, CURLOPT_HEADER, 0); // Return the content as a string curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); // Set user agent curl_setopt($curlHandler, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8'); $response = curl_exec($curlHandler); curl_close($curlHandler); return $response; } return false; } } } ?>