Example #1
0
 public function getCover()
 {
     $permissions = $this->getPemissions();
     /*@var $cover UHEADER_BOL_CoverBase */
     $cover = $permissions['view'] ? $this->cover : null;
     if ($cover === null) {
         return array('hasCover' => false, 'src' => null, 'data' => array(), 'css' => '', 'scale' => 0, 'tempateId' => $this->templateId, 'defaultTempateId' => $this->templateId, "class" => "uh-cover-no-cover");
     }
     $classList = array();
     $classList[] = "uh-cover-has-cover";
     if ($this->templateId !== null) {
         $classList[] = "uh-is-default-template";
     }
     if ($this->defaultTemplatesCount > 0) {
         $classList[] = "uh-has-default-templates";
     }
     return array('hasCover' => true, 'src' => $this->service->getCoverUrl($cover), 'data' => $cover->getSettings(), 'css' => $cover->getCssString(), 'scale' => $cover->getRatio(), 'templateId' => $this->templateId, "templateMode" => $this->templateId !== null, "class" => implode(" ", $classList));
 }
Example #2
0
 public function addFromPhotos($query)
 {
     $photoId = $query['photoId'];
     $userId = OW::getUser()->getId();
     $this->checkCredits();
     $sourcePath = UHEADER_CLASS_PhotoBridge::getInstance()->pullPhoto($photoId);
     if ($sourcePath === null) {
         throw new InvalidArgumentException("The requested photo wasn't find");
     }
     $coverDefaultHeight = OW::getConfig()->getValue('uheader', 'cover_height');
     $canvasWidth = $query['width'];
     $canvasHeight = $query['height'] < $coverDefaultHeight ? $coverDefaultHeight : $query['height'];
     $coverImage = new UTIL_Image($sourcePath);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $this->validateImage($coverImage, $canvasWidth, $canvasHeight);
     // Saving the cover
     $cover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_TMP);
     if ($cover === null) {
         $cover = new UHEADER_BOL_Cover();
     }
     $extension = UTIL_File::getExtension($sourcePath);
     $cover->file = uniqid('cover-' . $userId . '-') . '.' . $extension;
     $cover->userId = $userId;
     $cover->status = UHEADER_BOL_Cover::STATUS_TMP;
     $cover->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $cover->setSettings(array('photoId' => $photoId, 'dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveCover($cover);
     $coverPath = $this->service->getCoverPath($cover);
     OW::getStorage()->copyFile($sourcePath, $coverPath);
     @unlink($sourcePath);
     $coverUrl = $this->service->getCoverUrl($cover);
     return array('src' => $coverUrl, 'data' => $cover->getSettings(), 'ratio' => $cover->getRatio(), "mode" => "reposition");
 }