Example #1
0
 public function updateImage($widgetId, $postData, $currentData)
 {
     // var_dump($postData);
     $var = $postData['varName'];
     $newImg = $postData['fileName'];
     $newCrop = $postData['crop'];
     // do we have old data?
     if (isset($currentData[$var])) {
         $oldImg = $currentData[$var]['fileName'];
         $oldCrop = $currentData[$var]['crop'];
     } else {
         $oldImg = false;
         $oldCrop = false;
     }
     // unbind/bind file
     if ($newImg != $oldImg) {
         if ($oldImg) {
             \Ip\Internal\Repository\Model::unbindFile($oldImg, 'CustomSection', $widgetId);
         }
         \Ip\Internal\Repository\Model::bindFile($newImg, 'CustomSection', $widgetId);
     }
     // handle cropping
     if ($newCrop != $oldCrop) {
         // ????
     }
     $currentData[$var] = array('fileName' => $newImg, 'crop' => $newCrop);
     return $currentData;
 }
Example #2
0
 public function afterUpdate($recordId, $oldData, $newData)
 {
     if (!isset($oldData[$this->field])) {
         $oldData[$this->field] = '';
     }
     if (!isset($newData[$this->field])) {
         $newData[$this->field] = '';
     }
     if (!empty($oldData[$this->field]) && $oldData[$this->field] != $newData[$this->field]) {
         \Ip\Internal\Repository\Model::unbindFile($oldData[$this->field], $this->repositoryBindKey, $recordId);
     }
     if (!empty($newData[$this->field]) && $oldData[$this->field] != $newData[$this->field]) {
         \Ip\Internal\Repository\Model::bindFile($newData[$this->field][0], $this->repositoryBindKey, $recordId);
     }
 }
Example #3
0
 /**
  *
  * Duplicate widget action. This function is executed after the widget is being duplicated.
  * All widget data is duplicated automatically. This method is used only in case a widget
  * needs to do some maintenance tasks on duplication.
  * @param int $oldId old widget id
  * @param int $newId duplicated widget id
  * @param array $data data that has been duplicated from old widget to the new one
  * @return array
  */
 public function duplicate($oldId, $newId, $data)
 {
     if (!isset($data['images']) || !is_array($data['images'])) {
         return null;
     }
     foreach ($data['images'] as $image) {
         if (!is_array($image)) {
             return null;
         }
         if (isset($image['imageOriginal']) && $image['imageOriginal']) {
             \Ip\Internal\Repository\Model::bindFile($image['imageOriginal'], 'Content', $newId);
         }
     }
     return $data;
 }
Example #4
0
 /**
  *
  * Duplicate widget action. This function is executed after the widget is being duplicated.
  * All widget data is duplicated automatically. This method is used only in case a widget
  * needs to do some maintenance tasks on duplication.
  * @param int $oldId old widget id
  * @param int $newId duplicated widget id
  * @param array $data data that has been duplicated from old widget to the new one
  * @return array
  */
 public function duplicate($oldId, $newId, $data)
 {
     if (!is_array($data)) {
         return $data;
     }
     if (isset($data['imageOriginal']) && $data['imageOriginal']) {
         \Ip\Internal\Repository\Model::bindFile($data['imageOriginal'], 'Content', $newId);
     }
     return $data;
 }
Example #5
0
/**
 * Mark repository file as being used by a plugin. The point of this is to
 * instruct ImpressPages to prevent original file in repository from accidental deletion.
 * See ipUnbindFile on how to undo this action and mark asset as not being used by the plugin.
 * @param string $file file name relative to file/repository/. Eg. 'im-naked-in-the-shower.jpg'
 * @param string $plugin plugin name that uses the asset.
 * @param int $id single plugin might bind to the same file several times. In that case plugin might differentiate those binds by $id. If you sure this can't be the case for your plugin, use 1. You have to use the same id in ipUnbindFile
 * @param string $baseDir by default repository locate files in 'file/repository/'. If you work with 'file/secure' dir, pass this value here.
 */
function ipBindFile($file, $plugin, $id, $baseDir = 'file/repository/')
{
    \Ip\Internal\Repository\Model::bindFile($file, $plugin, $id, $baseDir);
}
Example #6
0
 public function saveImage()
 {
     if (!isset($_POST['key'])) {
         throw new \Exception("Required parameter not set");
     }
     $key = $_POST['key'];
     if (!isset($_POST['type'])) {
         throw new \Exception("Required parameter not set");
     }
     $type = $_POST['type'];
     if (!isset($_POST['cssClass'])) {
         throw new \Exception("Required parameter not set");
     }
     $cssClass = $_POST['cssClass'];
     if (!isset($_POST['defaultValue'])) {
         throw new \Exception("Required parameter not set");
     }
     $defaultValue = $_POST['defaultValue'];
     if (!isset($_POST['options'])) {
         $options = array();
     } else {
         $options = $_POST['options'];
     }
     if (!isset($_POST['languageId'])) {
         throw new \Exception("Required parameter not set");
     }
     $languageId = $_POST['languageId'];
     if (!isset($_POST['pageId'])) {
         throw new \Exception("Required parameter not set");
     }
     $pageId = $_POST['pageId'];
     $imageStr = $this->dao->getValue(Dao::PREFIX_IMAGE, $key, $languageId, $pageId);
     $image = new Entity\Image($imageStr);
     $scope = $this->dao->getLastOperationScope();
     $sameScope = $scope && $scope->getType() == $type;
     //STORE IMAGE
     if (isset($_POST['newImage']) && is_file(ipFile('file/repository/' . $_POST['newImage']))) {
         //remove old image
         if ($image->getImageOrig() && is_file(ipFile($image->getImageOrig()))) {
             if ($sameScope) {
                 //otherwise we need to leave image for original scope
                 \Ip\Internal\Repository\Model::unbindFile($image->getImageOrig(), 'developer/inline_management', $image->getId());
             }
         }
         \Ip\Internal\Repository\Model::bindFile($_POST['newImage'], 'developer/inline_management', $image->getId());
         //1 means logo
         $image->setImageOrig($_POST['newImage']);
     } else {
         if (!$sameScope) {
             //duplicate original image if we are resaving it in different scope
             if ($image->getImageOrig() && is_file(ipFile($image->getImageOrig()))) {
                 \Ip\Internal\Repository\Model::bindFile($image->getImageOrig(), 'developer/inline_management', $image->getId());
                 $image->setImageOrig($image->getImageOrig());
             }
         }
     }
     if (isset($_POST['cropX1']) && isset($_POST['cropY1']) && isset($_POST['cropX2']) && isset($_POST['cropY2']) && isset($_POST['windowWidth']) && isset($_POST['windowHeight'])) {
         //new small image
         $image->setX1($_POST['cropX1']);
         $image->setY1($_POST['cropY1']);
         $image->setX2($_POST['cropX2']);
         $image->setY2($_POST['cropY2']);
         $image->setRequiredWidth($_POST['windowWidth']);
         $image->setRequiredHeight($_POST['windowHeight']);
     } else {
         if (!$sameScope) {
             //in this place cropped image should be duplicated. But after implementation of reflection service it is not used
         }
     }
     if (!$sameScope) {
         //we are trying to save into different scope. We need to delete any images that could exist there
         switch ($type) {
             case Scope::SCOPE_PAGE:
                 //this always should return false. But just in case JS part would change, we implement it.
                 $oldImageStr = $this->dao->getPageValue(Dao::PREFIX_IMAGE, $key, $languageId, $pageId);
                 break;
             case Scope::SCOPE_PARENT_PAGE:
                 trigger_error("developer/inline_management", "Unexpected situation");
                 //there is no option to save to parent if $sameScope is true.
                 break;
             case Scope::SCOPE_LANGUAGE:
                 $oldImageStr = $this->dao->getLanguageValue(Dao::PREFIX_IMAGE, $key, $languageId);
                 break;
             case Scope::SCOPE_GLOBAL:
                 $oldImageStr = $this->dao->getGlobalValue(Dao::PREFIX_IMAGE, $key);
                 break;
         }
         if ($oldImageStr) {
             $oldScope = $this->dao->getLastOperationScope();
             if ($oldScope->getType() == $type) {
                 //if really have old image in this scope. If $oldScope != $type, we got global image - not from the scope we are saving in
                 $oldImage = new Entity\Image($oldImageStr);
                 $this->removeImageRecord($oldImage, $key, $oldScope);
             }
         }
     }
     switch ($type) {
         case Scope::SCOPE_PAGE:
             $this->dao->setPageValue(Dao::PREFIX_IMAGE, $key, $languageId, $pageId, $image->getValueStr());
             break;
         case Scope::SCOPE_PARENT_PAGE:
             $this->dao->setPageValue(Dao::PREFIX_IMAGE, $key, $scope->getLanguageId(), $scope->getPageId(), $image->getValueStr());
             break;
         case Scope::SCOPE_LANGUAGE:
             $this->dao->setLanguageValue(Dao::PREFIX_IMAGE, $key, $languageId, $image->getValueStr());
             break;
         case Scope::SCOPE_GLOBAL:
         default:
             $this->dao->setGlobalValue(Dao::PREFIX_IMAGE, $key, $image->getValueStr());
             break;
     }
     $inlineManagementService = new Service();
     $options['languageId'] = $languageId;
     $options['pageId'] = $pageId;
     $newHtml = $inlineManagementService->generateManagedImage($key, $defaultValue, $options, $cssClass);
     $data = array("status" => "success", "newHtml" => $newHtml);
     return new \Ip\Response\Json($data);
 }