예제 #1
0
 public function ensureImageDirIsAvailable($row_id)
 {
     $image_dir = $this->getImageDir($row_id);
     if ($image_dir !== false) {
         if (!file_exists($image_dir)) {
             FileUtils::createFolderRecursive($image_dir);
         }
     }
 }
예제 #2
0
 public function setData($id, $data)
 {
     if ($data === null) {
         return false;
     }
     $properties = $this->getProperties($id);
     if ($properties === false) {
         return false;
     }
     $folder = $this->getPageEditFolder($id, $properties);
     $url = $this->getPageFilesEditUrl($id, $properties);
     if (!is_dir($folder)) {
         $published_folder = $this->getPagePublishedFolder($id, $properties);
         if (is_dir($published_folder)) {
             if (!FileUtils::copyFolder($published_folder, $folder)) {
                 return false;
             }
         } else {
             if (!FileUtils::createFolderRecursive($folder)) {
                 return false;
             }
         }
     }
     $page_files_folder = $folder . self::PAGE_FILES_FOLDER_NAME;
     $page_files_url = $url;
     if (!file_exists($page_files_folder)) {
         FileUtils::createFolderRecursive($page_files_folder);
     }
     $decoded_data = json_decode($data, true);
     $parameters = array('pageId' => $id, 'pageFiles' => $page_files_folder . '/', 'pageFilesUrl' => $page_files_url . '/');
     Plugins::call(Plugins::BEFORE_SAVE_PAGE_DATA_FIELDS, $parameters, $decoded_data);
     $this->applyPluginsToDataFields(Plugins::SAVE_PAGE_DATA_FIELD, $parameters, $decoded_data, $properties);
     Plugins::call(Plugins::AFTER_SAVE_PAGE_DATA_FIELDS, $parameters, $decoded_data);
     $encoded_data = json_encode($decoded_data);
     $file = $folder . self::DATA_FILE_NAME;
     if (!FileUtils::createFile($file)) {
         return false;
     }
     if (@file_put_contents($file, $encoded_data) === false) {
         return false;
     }
     if ($properties['status'] == self::STATUS_PUBLISHED) {
         $new_properties = array('status' => self::STATUS_EDIT);
         $this->setProperties($id, $new_properties);
     }
     return true;
 }