Ejemplo n.º 1
0
 public function process($url, $parent, $isAutomated)
 {
     $existing = $this->links->getBySlug(sluggifyUrl($url));
     if (!$existing) {
         $readability_data = $this->links->getReadability($url);
         $user = $isAutomated ? 2 : Auth::user()->id;
         $link_object = Links::make($url, $readability_data['title'], null, null, null, $readability_data['content'], $user, sluggifyUrl($url), getDomainFromUrl($url), md5(sluggifyUrl($url)), round(str_word_count($readability_data['content'], 0) / 130));
         $link = $this->links->save($link_object);
         if ($isAutomated) {
             $this->replaceReferenceOnParent($link, $parent);
         }
         // if($parent) $this->replaceReferenceOnParent($link, $parent);
         // dd('create handler ' . $url);
         Event::fire(new LinkWasCreated($link, $readability_data, $isAutomated));
         return $link;
     }
 }
//Get the raw post data from the request. This is the best-practice method as it does not rely on special php.ini directives
//like $HTTP_RAW_POST_DATA. Amazon SNS sends a JSON object as part of the raw post body.
$json = json_decode(file_get_contents("php://input"));
//Check for Restrict By Topic
if ($restrictByTopic) {
    if ($allowedTopic != $json->TopicArn) {
        $safeToProcess = false;
        if ($logToFile) {
            fwrite($fh, "ERROR: Allowed Topic ARN: " . $allowedTopic . " DOES NOT MATCH Calling Topic ARN: " . $json->TopicArn . "\n");
        }
    }
}
//Check for Verify Certificate
if ($verifyCertificate) {
    //Check For Certificate Source
    $domain = getDomainFromUrl($json->SigningCertURL);
    if ($domain != $sourceDomain) {
        $safeToProcess = false;
        if ($logToFile) {
            fwrite($fh, "Key domain: " . $domain . " is not equal to allowed source domain:" . $sourceDomain . "\n");
        }
    }
    //Build Up The String That Was Originally Encoded With The AWS Key So You Can Validate It Against Its Signature.
    if ($json->Type == "SubscriptionConfirmation") {
        $validationString = "";
        $validationString .= "Message\n";
        $validationString .= $json->Message . "\n";
        $validationString .= "MessageId\n";
        $validationString .= $json->MessageId . "\n";
        $validationString .= "SubscribeURL\n";
        $validationString .= $json->SubscribeURL . "\n";