public function recentHeatmap() { $member = Member::currentUser(); $heatmap = Heatmaps::get()->filter(array('MemberID' => $member->ID, 'Deleted' => 0))->sort('Created', 'DESC')->first(); if ($heatmap) { $created = strtotime($heatmap->Created); $diffHours = (time() - $created) / (60 * 60); if ($diffHours <= 1) { return $heatmap; } } return false; }
public function processCreateHeatmap() { $data = $this->request->postVars(); //Restrict users create heatmaps who do not have enough credits $member = Member::currentUser(); $memberId = $member->ID; if (!$this->getExpiringHeatmapsRemaining($memberId) && !$this->getNonExpiringHeatmapsRemaining($memberId)) { return "inlineMsg2"; } //Restrict images upload whose dimensions are out of required range $tmpImageUrl = $data['OriginalImage']['tmp_name']; list($imageWidth, $imageHeight) = getimagesize($tmpImageUrl); if ($imageWidth < 500 || $imageWidth > 1600 || $imageHeight < 500 || $imageHeight > 1200) { return "inlineMsg3"; } // Create a heatmap folder for the user if it does not exist $heatmapFolder = Folder::find_or_make("/Uploads/heatmaps/{$memberId}"); $heatmapFolderPath = $heatmapFolder->Filename; //chmod($heatmapFolderPath, 0777); //Rename the orginal uploaded image $originalImageName = $this->renameUploadedImage($data['OriginalImage']['name']); //Original image path $originalImagePath = Director::baseFolder() . "/{$heatmapFolderPath}{$originalImageName}"; //Original image URL $originalImageUrl = Director::absoluteBaseURL() . "assets/Uploads/heatmaps/{$memberId}/{$originalImageName}"; //Move the original image to heatmap folder move_uploaded_file($tmpImageUrl, $originalImagePath); //chmod($originalImagePath, 0777); // Create a file object for the original image $originalImage = new File(); $originalImage->ClassName = 'Image'; $originalImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$originalImageName}"; $originalImage->Title = pathinfo($originalImageName, PATHINFO_FILENAME); $originalImage->ParentID = $heatmapFolder->ID; $originalImage->OwnerID = $memberId; $originalImage->write(); //Create Heatmap $viewType = 2; $viewDistance = 1; $analysisOptions = 511; $outputOptions = 21; $response = $this->CreateHeatmap('sitetuners', 'tim.ash', $originalImageUrl, $viewType, $viewDistance, $analysisOptions, $outputOptions); if ($response['success']) { $originalHeatmapUrl = $response['image_url']; $heatmapName = $this->createHeatmapName($originalImageUrl, $memberId); $heatmapUrl = Director::absoluteBaseURL() . "assets/Uploads/heatmaps/{$memberId}/{$heatmapName}"; $heatmapPath = Director::baseFolder() . "/{$heatmapFolderPath}{$heatmapName}"; //Save/copy the heatmap $content = file_get_contents($originalHeatmapUrl); file_put_contents($heatmapPath, $content); // Create a file object for the heatmap image $heatmapImage = new File(); $heatmapImage->ClassName = 'Image'; $heatmapImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$heatmapName}"; $heatmapImage->Title = pathinfo($heatmapName, PATHINFO_FILENAME); $heatmapImage->ParentID = $heatmapFolder->ID; $heatmapImage->OwnerID = $memberId; $heatmapImage->write(); //Create the heatmap record $heatmap = new Heatmaps(); $heatmap->UploadImageName = $data['OriginalImage']['name']; $heatmap->HeatmapType = 0; $heatmap->MemberID = $memberId; $heatmap->OriginalImageID = $originalImage->ID; $heatmap->HeatmapID = $heatmapImage->ID; if ($data['IncludeWatermark'] == 1) { $watermarkHeatmapName = $this->createHeatmapName($originalImageUrl, $memberId, true); $watermarkHeatmapUrl = Director::absoluteBaseURL() . "assets/Uploads/heatmaps/{$memberId}/{$watermarkHeatmapName}"; $watermarkHeatmapPath = Director::baseFolder() . "/{$heatmapFolderPath}{$watermarkHeatmapName}"; //Save/copy the heatmap $this->createWatermarkHeatmap($heatmapUrl, $watermarkHeatmapPath); // Create a file object for the heatmap image $watermarkHeatmapImage = new File(); $watermarkHeatmapImage->ClassName = 'Image'; $watermarkHeatmapImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$watermarkHeatmapName}"; $watermarkHeatmapImage->Title = pathinfo($watermarkHeatmapName, PATHINFO_FILENAME); $watermarkHeatmapImage->ParentID = $heatmapFolder->ID; $watermarkHeatmapImage->OwnerID = $memberId; $watermarkHeatmapImage->write(); //Create the heatmap record $heatmap->HeatmapType = 1; $heatmap->WatermarkHeatmapID = $watermarkHeatmapImage->ID; } $heatmap->write(); //Update/Deduct heatmap credits $this->updateHeatmapCredits($memberId); //Send an email to the user $email = new Email(); $email->setSubject("AttentionWizard heatmap for {$data['OriginalImage']['name']}"); $email->setFrom('*****@*****.**'); $email->setTo($member->Email); $email->setTemplate('HeatmapCreatedEmail'); $email->populateTemplate(array('fullName' => $member->FirstName . ' ' . $member->Surname, 'imageName' => $data['OriginalImage']['name'], 'absoluteLink' => Director::absoluteBaseURL())); $email->send(); //Redirect to manage heatmaps page $this->setMessage('Success', 'Heatmap is created successfully'); return "url1"; } else { $email = new Email(); $email->setSubject('Heatmap Soap Request Not Working! Urgent'); $email->setFrom('*****@*****.**'); //$email->setTo('*****@*****.**'); $email->setTo('*****@*****.**'); $email->setTemplate('HeatmapFailedEmail'); $email->populateTemplate(array('lastResponse' => $response['soap_response'], 'lastResponseHeaders' => $response['response_headers'])); $email->send(); return "inlineMsg4"; } }
public function moveHeatmapsFromJoomlaToSS() { die('test2'); error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('max_execution_time', 0); ini_set('memory_limit', '-1'); $mysqli = $this->getDbConnection(); $result2 = $mysqli->query("SELECT * FROM jos_users u inner join jos_heatmaps h on u.id = h.userid where h.status_new = 1"); $totalHeatmaps = 0; while ($obj2 = $result2->fetch_object()) { //if($obj2->id != 14835 && $obj2->id != 16667 ) //continue; if ($this->getSSHeatmapFile(basename($obj2->heatmap_image_url))) { continue; } //Get member id $ssMember = $this->getSSMember($obj2->email); $memberId = $ssMember->ID; $heatmaps = new Heatmaps(); $heatmaps->Created = $obj2->heatmap_created; $heatmaps->LastEdited = $obj2->heatmap_created; if ($obj2->heatmap_type == 2) { $heatmaps->HeatmapType = 1; } $heatmaps->UploadImageName = basename($obj2->original_image); $heatmaps->Deleted = $obj2->hstatus; $heatmaps->MemberID = $memberId; // Create a heatmap folder for the user if it does not exist $heatmapFolder = Folder::find_or_make("/Uploads/heatmaps/{$memberId}"); $heatmapFolderPath = $heatmapFolder->Filename; if ($originalImageUrl = $obj2->original_image_url) { $originalImageName = basename($originalImageUrl); //Original image destination URL $originalImagePath = Director::baseFolder() . "/{$heatmapFolderPath}{$originalImageName}"; //Save/copy the original image if ($content = @file_get_contents($originalImageUrl)) { file_put_contents($originalImagePath, $content); // Create a file object for the original image $originalImage = new File(); $originalImage->ClassName = 'Image'; $originalImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$originalImageName}"; $originalImage->Title = pathinfo($originalImageName, PATHINFO_FILENAME); $originalImage->ParentID = $heatmapFolder->ID; $originalImage->OwnerID = $memberId; $originalImage->write(); $heatmaps->OriginalImageID = $originalImage->ID; } } //Get heatmap url if ($heatmapImageUrl = $obj2->heatmap_image_url) { $heatmapImageUrl = str_replace('/web/attentionwizard/', '', $heatmapImageUrl); $heatmapImageUrl = str_replace('/EBS/sites/wiz.dynacast.net/htdoc/', '', $heatmapImageUrl); $heatmapImageUrl = "https://www.attentionwizard.com/{$heatmapImageUrl}"; if ($content = @file_get_contents($heatmapImageUrl)) { //Save/copy the heatmap $heatmapName = basename($heatmapImageUrl); $heatmapPath = Director::baseFolder() . "/{$heatmapFolderPath}{$heatmapName}"; file_put_contents($heatmapPath, $content); // Create a file object for the heatmap image $heatmapImage = new File(); $heatmapImage->ClassName = 'Image'; $heatmapImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$heatmapName}"; $heatmapImage->Title = pathinfo($heatmapName, PATHINFO_FILENAME); $heatmapImage->ParentID = $heatmapFolder->ID; $heatmapImage->OwnerID = $memberId; $heatmapImage->write(); $heatmaps->HeatmapID = $heatmapImage->ID; } } //Get wm heatmap url if ($wmHeatmapImageUrl = $obj2->watermark_image_url) { $wmHeatmapImageUrl = str_replace('/web/attentionwizard/', '', $wmHeatmapImageUrl); $wmHeatmapImageUrl = str_replace('/EBS/sites/wiz.dynacast.net/htdoc/', '', $wmHeatmapImageUrl); $wmHeatmapImageUrl = "https://www.attentionwizard.com/{$wmHeatmapImageUrl}"; if ($content = @file_get_contents($wmHeatmapImageUrl)) { //Save/copy the heatmap $wmHeatmapName = basename($wmHeatmapImageUrl); $wmHeatmapPath = Director::baseFolder() . "/{$heatmapFolderPath}{$wmHeatmapName}"; file_put_contents($wmHeatmapPath, $content); // Create a file object for the heatmap image $watermarkHeatmapImage = new File(); $watermarkHeatmapImage->ClassName = 'Image'; $watermarkHeatmapImage->Filename = "assets/Uploads/heatmaps/{$memberId}/{$wmHeatmapName}"; $watermarkHeatmapImage->Title = pathinfo($wmHeatmapName, PATHINFO_FILENAME); $watermarkHeatmapImage->ParentID = $heatmapFolder->ID; $watermarkHeatmapImage->OwnerID = $memberId; $watermarkHeatmapImage->write(); $heatmaps->WatermarkHeatmapID = $watermarkHeatmapImage->ID; } } $heatmaps->write(); $totalHeatmaps++; } $mysqli->close(); echo "Total Heatmaps moved: {$totalHeatmaps}"; }