Esempio n. 1
0
 public function setUp()
 {
     // create directory
     $directory = realpath(dirname(__FILE__) . '/..') . '/tmp/logging';
     SpoonDirectory::create($directory, 0777);
     // create instance
     $this->log = new SpoonLog('custom', $directory);
 }
Esempio n. 2
0
    /**
     * Install the module
     */
    public function install()
    {
        // load install.sql
        $this->importSQL(dirname(__FILE__) . '/data/install.sql');
        // add 'search' as a module
        $this->addModule('search');
        // import locale
        $this->importLocale(dirname(__FILE__) . '/data/locale.xml');
        // general settings
        $this->setSetting('search', 'overview_num_items', 10);
        $this->setSetting('search', 'validate_search', true);
        // module rights
        $this->setModuleRights(1, 'search');
        // action rights
        $this->setActionRights(1, 'search', 'add_synonym');
        $this->setActionRights(1, 'search', 'edit_synonym');
        $this->setActionRights(1, 'search', 'delete_synonym');
        $this->setActionRights(1, 'search', 'settings');
        $this->setActionRights(1, 'search', 'statistics');
        $this->setActionRights(1, 'search', 'synonyms');
        // set navigation
        $navigationModulesId = $this->setNavigation(null, 'Modules');
        $navigationSearchId = $this->setNavigation($navigationModulesId, 'Search');
        $this->setNavigation($navigationSearchId, 'Statistics', 'search/statistics');
        $this->setNavigation($navigationSearchId, 'Synonyms', 'search/synonyms', array('search/add_synonym', 'search/edit_synonym'));
        // settings navigation
        $navigationSettingsId = $this->setNavigation(null, 'Settings');
        $navigationModulesId = $this->setNavigation($navigationSettingsId, 'Modules');
        $this->setNavigation($navigationModulesId, 'Search', 'search/settings');
        // add extra's
        $searchId = $this->insertExtra('search', 'block', 'Search', null, 'a:1:{s:3:"url";s:40:"/private/nl/search/statistics?token=true";}', 'N', 2000);
        $this->insertExtra('search', 'widget', 'SearchForm', 'form', null, 'N', 2001);
        // loop languages
        foreach ($this->getLanguages() as $language) {
            // check if a page for search already exists in this language
            // @todo refactor this nasty if statement...
            if (!(bool) $this->getDB()->getVar('SELECT 1
				 FROM pages AS p
				 INNER JOIN pages_blocks AS b ON b.revision_id = p.revision_id
				 WHERE b.extra_id = ? AND p.language = ?
				 LIMIT 1', array($searchId, $language))) {
                // insert search
                $this->insertPage(array('title' => SpoonFilter::ucfirst($this->getLocale('Search', 'core', $language, 'lbl', 'frontend')), 'type' => 'root', 'language' => $language), null, array('extra_id' => $searchId, 'position' => 'main'));
            }
        }
        // activate search on 'pages'
        $this->searchPages();
        // create module cache path
        if (!SpoonDirectory::exists(PATH_WWW . '/frontend/cache/search')) {
            SpoonDirectory::create(PATH_WWW . '/frontend/cache/search');
        }
    }
 public function testMove()
 {
     // setup
     SpoonDirectory::create($this->path . '/move_org');
     // copy
     SpoonDirectory::move($this->path . '/move_org', $this->path . '/move_dest');
     // check if both folders exists
     $var = (bool) (!SpoonDirectory::exists($this->path . '/move_org') && SpoonDirectory::exists($this->path . '/move_dest'));
     // assert
     $this->assertTrue($var);
     // cleanup
     SpoonDirectory::delete($this->path . '/move_dest');
 }
Esempio n. 4
0
 /**
  * Generates the desired image formats based on the source image
  *
  * @param string $path The path we write the images to.
  * @param string $filename The name of the source file.
  * @param array[optional] $formats The formats of the images to generate based on the source.
  * @return bool	Returns true if every file succeeded
  */
 public static function generateImages($path, $filename, array $formats = null)
 {
     // check input
     if (empty($filename)) {
         return false;
     }
     // create the path up to the source dir
     if (!\SpoonDirectory::exists($path . '/source')) {
         \SpoonDirectory::create($path . '/source');
     }
     // source path
     $pathSource = $path . '/source';
     // formats found
     if (!empty($formats)) {
         // loop the formats
         foreach ($formats as $format) {
             // create the path for this product
             if (!\SpoonDirectory::exists($path . '/' . $format['size'])) {
                 \SpoonDirectory::create($path . '/' . $format['size']);
             }
             // exploded format
             $explodedFormat = explode('x', $format['size']);
             // set enlargement/aspect ratio
             $allowEnlargement = isset($format['allow_enlargement']) ? $format['allow_enlargement'] : true;
             $forceAspectRatio = isset($format['force_aspect_ratio']) ? $format['force_aspect_ratio'] : true;
             // get measurements of the source file
             $sourceDimensions = getimagesize($pathSource . '/' . $filename);
             // source width is bigger than what it should be
             $width = $sourceDimensions[0] > $explodedFormat[0] ? $explodedFormat[0] : $sourceDimensions[0];
             $height = isset($explodedFormat[1]) && $sourceDimensions[1] > $explodedFormat[1] ? $explodedFormat[1] : $sourceDimensions[1];
             // check if height is empty or not
             if (empty($height)) {
                 $height = null;
             }
             // make a thumbnail for the provided format
             $thumbnail = new \SpoonThumbnail($pathSource . '/' . $filename, $width, $forceAspectRatio ? null : $height);
             $thumbnail->setAllowEnlargement($allowEnlargement);
             $thumbnail->setForceOriginalAspectRatio($forceAspectRatio);
             $success[] = $thumbnail->parseToFile($path . '/' . $format['size'] . '/' . $filename);
             unset($thumbnail);
         }
     }
 }
Esempio n. 5
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // validate the image
         if ($this->frm->getField('image')->isFilled()) {
             // image extension and mime type
             $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
         }
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['text'] = $fields['text']->getValue();
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             $item['id'] = BackendAddressesModel::insert($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue();
                 BackendAddressesModel::insertLanguage($itemLanguage);
             }
             if (isset($fields["groups"])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 foreach ($groups as $value) {
                     $groupAddress = array();
                     $groupAddress["address_id"] = $item['id'];
                     $groupAddress["group_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($groupAddress);
                 }
             }
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name']));
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 6
0
 /**
  * Generate thumbnails based on the folders in the path
  * Use
  *  - 128x128 as foldername to generate an image that where the width will be 128px and the height will be 128px
  *  - 128x as foldername to generate an image that where the width will be 128px, the height will be calculated based on the aspect ratio.
  *  - x128 as foldername to generate an image that where the width will be 128px, the height will be calculated based on the aspect ratio.
  *
  * @param string $path
  * @param string $filename
  */
 public function generateThumbnails($path, $filename)
 {
     // create folder if needed
     if (!SpoonDirectory::exists($path . '/source')) {
         SpoonDirectory::create($path . '/source');
     }
     // move the source file
     $this->moveFile($path . '/source/' . $filename);
     // generate the thumbnails
     FrontendModel::generateThumbnails($path, $path . '/source/' . $filename);
 }
Esempio n. 7
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['revision_id'] = $this->record['revision_id'];
             // this is used to let our model know the status (active, archive, draft) of the edited item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['edited_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 $item['image'] = $this->record['image'];
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // create folders if needed
                 if (!SpoonDirectory::exists($imagePath . '/source')) {
                     SpoonDirectory::create($imagePath . '/source');
                 }
                 if (!SpoonDirectory::exists($imagePath . '/128x128')) {
                     SpoonDirectory::create($imagePath . '/128x128');
                 }
                 // if the image should be deleted
                 if ($this->frm->getField('delete_image')->isChecked()) {
                     // delete the image
                     SpoonFile::delete($imagePath . '/source/' . $item['image']);
                     // reset the name
                     $item['image'] = null;
                 }
                 // new image given?
                 if ($this->frm->getField('image')->isFilled()) {
                     // delete the old image
                     SpoonFile::delete($imagePath . '/source/' . $this->record['image']);
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image & generate thumbnails
                     $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
                 } elseif ($item['image'] != null) {
                     // get the old file extension
                     $imageExtension = SpoonFile::getExtension($imagePath . '/source/' . $item['image']);
                     // get the new image name
                     $newName = $this->meta->getURL() . '.' . $imageExtension;
                     // only change the name if there is a difference
                     if ($newName != $item['image']) {
                         // loop folders
                         foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
                             // move the old file to the new name
                             SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
                         }
                         // assign the new name to the database
                         $item['image'] = $newName;
                     }
                 }
             } else {
                 $item['image'] = null;
             }
             // update the item
             $item['revision_id'] = BackendBlogModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // recalculate comment count so the new revision has the correct count
             BackendBlogModel::reCalculateCommentCount(array($this->id));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // edit search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL());
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id'];
             }
             // append to redirect URL
             if ($this->categoryId != null) {
                 $redirectUrl .= '&category=' . $this->categoryId;
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
Esempio n. 8
0
 /**
  * Attemps to move the uploaded file to the new location.
  *
  * @return	bool
  * @param	string $path			The path whereto the file will be moved.
  * @param	int[optional] $chmod	The octal value to use for chmod.
  */
 public function moveFile($path, $chmod = 0755)
 {
     // create missing directories
     if (!file_exists(dirname($path))) {
         SpoonDirectory::create(dirname($path));
     }
     // move the file
     $return = @move_uploaded_file($_FILES[$this->attributes['name']]['tmp_name'], (string) $path);
     // chmod file
     @chmod($path, $chmod);
     // return move file status
     return $return;
 }
Esempio n. 9
0
 private function uploadFile()
 {
     //--Check if the file is an image or file
     if ($this->isImage()) {
         // the image path
         $path = FRONTEND_FILES_PATH . '/Media/Images';
         if (!\SpoonDirectory::exists($path . '/Source')) {
             \SpoonDirectory::create($path . '/Source');
         }
     } else {
         // the file path
         $path = FRONTEND_FILES_PATH . '/Media/Files';
     }
     // create folders if needed
     // build the filename
     $filename = $this->checkFilename();
     $item = array();
     $item["filename"] = $filename;
     $item["extension"] = $this->field->getExtension();
     $item["created_on"] = BackendModel::getUTCDate('Y-m-d H:i:s');
     $item["filesize"] = $this->field->getFileSize("b");
     $data = array();
     //--Check if file is an image to specify data
     if ($this->isImage()) {
         $item["filetype"] = $this->fieldTypeImage;
         //--Put file on disk
         $this->field->moveFile($path . "/Source/" . $filename);
         // create folders if needed
         if (!\SpoonDirectory::exists($path . '/128x128')) {
             \SpoonDirectory::create($path . '/128x128');
         }
         //--Create all tumbs/resizes of file
         $thumbnail = new \SpoonThumbnail($path . "/Source/" . $filename);
         $thumbnail->setAllowEnlargement(true);
         \Common\Core\Model::generateThumbnails($path, $path . '/Source/' . $filename);
     } else {
         $item["filetype"] = $this->fieldTypeFile;
         // move the source file
         $this->field->moveFile($path . "/" . $filename);
     }
     //--Serialize data
     $item["data"] = serialize($data);
     //--Store item so we can access it
     $this->item = $item;
     //--Insert into media
     return BackendModel::getContainer()->get('database')->insert("media", $item);
 }
Esempio n. 10
0
 /**
  * Saves the image to a file (quality is only used for jpg images).
  *
  * @return	bool						True if the image was saved, false if not.
  * @param	string $filename			The path where the image should be saved.
  * @param	int[optional] $quality		The quality to use (only applies on jpg-images).
  * @param	int[optional] $chmod		Mode that should be applied on the file.
  */
 public function parseToFile($filename, $quality = 100, $chmod = 0666)
 {
     // redefine vars
     $filename = (string) $filename;
     $quality = (int) $quality;
     //
     if (@is_writable(dirname($filename)) !== true) {
         // does the folder exist? if not, try to create
         if (!SpoonDirectory::create(dirname($filename))) {
             if ($this->strict) {
                 throw new SpoonThumbnailException('The destination-path should be writable.');
             }
             return false;
         }
     }
     // get extension
     $extension = SpoonFile::getExtension($filename);
     // invalid quality
     if (!SpoonFilter::isBetween(1, 100, $quality)) {
         // strict?
         if ($this->strict) {
             throw new SpoonThumbnailException('The quality should be between 1 - 100');
         }
         return false;
     }
     // invalid extension
     if (SpoonFilter::getValue($extension, array('gif', 'jpeg', 'jpg', 'png'), '') == '') {
         if ($this->strict) {
             throw new SpoonThumbnailException('Only gif, jpeg, jpg or png are allowed types.');
         }
         return false;
     }
     // get current dimensions
     $imageProperties = @getimagesize($this->filename);
     // validate imageProperties
     if ($imageProperties === false) {
         // strict?
         if ($this->strict) {
             throw new SpoonThumbnailException('The sourcefile "' . $this->filename . '" could not be found.');
         }
         return false;
     }
     // set current dimensions
     $currentWidth = (int) $imageProperties[0];
     $currentHeight = (int) $imageProperties[1];
     $currentType = (int) $imageProperties[2];
     $currentMime = (string) $imageProperties['mime'];
     // file is the same?
     if ($currentType == IMAGETYPE_GIF && $extension == 'gif' || $currentType == IMAGETYPE_JPEG && in_array($extension, array('jpg', 'jpeg')) || $currentType == IMAGETYPE_PNG && $extension == 'png') {
         if ($currentWidth == $this->width && $currentHeight == $this->height) {
             return SpoonDirectory::copy($this->filename, $filename, true, true, $chmod);
         }
     }
     // resize image
     $this->resizeImage($currentWidth, $currentHeight, $currentType, $currentMime);
     // output to file
     switch (strtolower($extension)) {
         case 'gif':
             $return = @imagegif($this->image, $filename);
             break;
         case 'jpeg':
         case 'jpg':
             $return = @imagejpeg($this->image, $filename, $quality);
             break;
         case 'png':
             $return = @imagepng($this->image, $filename);
             break;
     }
     // chmod
     @chmod($filename, $chmod);
     // cleanup memory
     @imagedestroy($this->image);
     // return success
     return (bool) $return;
 }
Esempio n. 11
0
 private static function uploadFile()
 {
     //--Check if the file is an image or file
     if (self::isImage()) {
         // the image path
         $path = FRONTEND_FILES_PATH . '/media/images';
     } else {
         // the file path
         $path = FRONTEND_FILES_PATH . '/media/files';
     }
     // create folders if needed
     if (!SpoonDirectory::exists($path . '/source')) {
         SpoonDirectory::create($path . '/source');
     }
     if (!SpoonDirectory::exists($path . '/128x128')) {
         SpoonDirectory::create($path . '/128x128');
     }
     // build the filename
     $filename = self::checkFilename();
     $item = array();
     $item["filename"] = $filename;
     $item["extension"] = self::$field->getExtension();
     $item["created_on"] = FrontendModel::getUTCDate('Y-m-d H:i:s');
     $item["filesize"] = self::$field->getFileSize("b");
     $data = array();
     //--Check if file is an image to specify data
     if (self::isImage()) {
         $item["filetype"] = self::$fieldTypeImage;
         $data["width"] = self::$field->getWidth();
         $data["height"] = self::$field->getHeight();
         // upload the image & generate thumbnails
         self::$field->generateThumbnails($path, $filename);
     } else {
         $item["filetype"] = self::$fieldTypeFile;
         // move the source file
         self::$field->moveFile($path . "/" . $filename);
     }
     //--Serialize data
     $item["data"] = serialize($data);
     // get db
     $db = FrontendModel::getDB(true);
     //--Insert into media
     return $db->insert("media", $item);
 }
Esempio n. 12
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(Language::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // validate redirect
         $redirectValue = $this->frm->getField('redirect')->getValue();
         if ($redirectValue == 'internal') {
             $this->frm->getField('internal_redirect')->isFilled(Language::err('FieldIsRequired'));
         }
         if ($redirectValue == 'external') {
             $this->frm->getField('external_redirect')->isURL(Language::err('InvalidURL'));
         }
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = Language::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             //$item['link'] = $fields['link']->getValue();
             $item['linktext'] = $fields['linktext']->getValue();
             if ($redirectValue == 'internal') {
                 $item['link'] = null;
                 $item['page_id'] = $this->frm->getField('internal_redirect')->getValue();
             }
             if ($redirectValue == 'external') {
                 $item['link'] = $this->frm->getField('external_redirect')->getValue();
                 $item['page_id'] = null;
             }
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/image';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             if (!\SpoonDirectory::exists($imagePath . '/x800')) {
                 \SpoonDirectory::create($imagePath . '/x800');
             }
             if (!\SpoonDirectory::exists($imagePath . '/450x250')) {
                 \SpoonDirectory::create($imagePath . '/450x250');
             }
             if (!\SpoonDirectory::exists($imagePath . '/600x300')) {
                 \SpoonDirectory::create($imagePath . '/600x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/source')) {
                 \SpoonDirectory::create($imagePath . '/source');
             }
             // image provided?
             if ($fields['image']->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getUrl() . '.' . $fields['image']->getExtension();
                 // upload the image & generate thumbnails
                 $fields['image']->generateThumbnails($imagePath, $item['image']);
             }
             $item['hidden'] = $fields['hidden']->getValue();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['extra_id'] = $this->record['extra_id'];
             $item['meta_id'] = $this->meta->save();
             BackendBlocksModel::update($item);
             $item['id'] = $this->id;
             Model::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(Model::createURLForAction('Index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 13
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //			$fields['name']->isFilled(BL::err('FieldIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             $item['meta_id'] = $this->meta->save();
             $item['company'] = $fields['company']->getValue();
             $item['name'] = $fields['name']->getValue();
             $item['firstname'] = $fields['firstname']->getValue();
             $item['email'] = $fields['email']->getValue();
             $item['address'] = $fields['address']->getValue();
             $item['zipcode'] = $fields['zipcode']->getValue();
             $item['city'] = $fields['city']->getValue();
             $item['country'] = $fields['country']->getValue();
             $item['phone'] = $fields['phone']->getValue();
             $item['fax'] = $fields['fax']->getValue();
             $item['website'] = str_replace("http://", "", $fields['website']->getValue());
             $item['zipcodes'] = $fields['zipcodes']->getValue();
             $item['remark'] = $fields['remark']->getValue();
             //$item['text'] = $fields['text']->getValue();
             //$item['assort'] = $fields['assort']->getValue();
             //$item['open'] = $fields['open']->getValue();
             //$item['closed'] = $fields['closed']->getValue();
             //$item['visit'] = $fields['visit']->getValue();
             //$item['size'] = $fields['size']->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['hidden'] = $fields['hidden']->getValue();
             if ($item['country'] == '') {
                 $item['country'] = 'BE';
             }
             //--Create url
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
             //--Get lat
             $geocode = json_decode(\SpoonHTTP::getContent($url));
             //--Sleep between the requests
             sleep(0.05);
             //--Check result
             $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
             $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
             $item['image'] = $this->record['image'];
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/Addresses/Images';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                 \SpoonDirectory::create($imagePath . '/Source');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                 \SpoonDirectory::create($imagePath . '/400x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             // if the image should be deleted
             if ($this->frm->getField('delete_image')->isChecked()) {
                 // delete the image
                 \SpoonFile::delete($imagePath . '/Source/' . $item['image']);
                 // reset the name
                 $item['image'] = null;
             }
             // new image given?
             if ($this->frm->getField('image')->isFilled()) {
                 // delete the old image
                 \SpoonFile::delete($imagePath . '/Source/' . $this->record['image']);
                 // build the image name
                 $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             } elseif ($item['image'] != null) {
                 // get the old file extension
                 $imageExtension = \SpoonFile::getExtension($imagePath . '/Source/' . $item['image']);
                 // get the new image name
                 $newName = $this->meta->getURL() . '.' . $imageExtension;
                 // only change the name if there is a difference
                 if ($newName != $item['image']) {
                     // loop folders
                     foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) {
                         // move the old file to the new name
                         \SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName);
                     }
                     // assign the new name to the database
                     $item['image'] = $newName;
                 }
             }
             BackendAddressesModel::update($this->id, $item);
             $item['id'] = $this->id;
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue();
                 BackendAddressesModel::updateLanguage($itemLanguage);
             }
             if (isset($fields["groups"])) {
                 //--Get all the groups
                 $groups = $fields["groups"]->getValue();
                 BackendAddressesModel::deleteGroupsFromAddress($item['id']);
                 foreach ($groups as $value) {
                     $groupAddress = array();
                     $groupAddress["address_id"] = $item['id'];
                     $groupAddress["group_id"] = $value;
                     //--Add user to the group
                     BackendAddressesModel::insertAddressToGroup($groupAddress);
                 }
             }
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name']));
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }
Esempio n. 14
0
 /**
  * Writes a string to a file.
  *
  * @return	bool						True if the content was written, false if not.
  * @param	string $filename			The path of the file.
  * @param	string $content				The content that should be written.
  * @param	bool[optional] $createFile	Should the file be created if it doesn't exists?
  * @param	bool[optional] $append		Should the content be appended if the file already exists?
  * @param	int[optional] $chmod		Mode that should be applied on the file.
  */
 public static function setContent($filename, $content, $createFile = true, $append = false, $chmod = 0666)
 {
     // redefine vars
     $filename = (string) $filename;
     $content = (string) $content;
     $createFile = (bool) $createFile;
     $append = (bool) $append;
     // file may not be created, but it doesn't exist either
     if (!$createFile && self::exists($filename)) {
         throw new SpoonFileException('The file "' . $filename . '" doesn\'t exist');
     }
     // create directory recursively if needed
     SpoonDirectory::create(dirname($filename));
     // create file & open for writing
     $handler = $append ? @fopen($filename, 'a') : @fopen($filename, 'w');
     // something went wrong
     if ($handler === false) {
         throw new SpoonFileException('The file "' . $filename . '" could not be created. Check if PHP has enough permissions.');
     }
     // store error reporting level
     $level = error_reporting();
     // disable errors
     error_reporting(0);
     // write to file
     $write = fwrite($handler, $content);
     // validate write
     if ($write === false) {
         throw new SpoonFileException('The file "' . $filename . '" could not be written to. Check if PHP has enough permissions.');
     }
     // close the file
     fclose($handler);
     // chmod file
     chmod($filename, $chmod);
     // restore error reporting level
     error_reporting($level);
     // status
     return true;
 }
Esempio n. 15
0
 /**
  * Writes a string to a file.
  *
  * @return	bool						True if the content was written, false if not.
  * @param	string $filename			The path of the file.
  * @param	string $content				The content that should be written.
  * @param	bool[optional] $createFile	Should the file be created if it doesn't exists?
  * @param	bool[optional] $append		Should the content be appended if the file already exists?
  * @param	int[optional] $chmod		Mode that should be applied on the file.
  */
 public static function setContent($filename, $content, $createFile = true, $append = false, $chmod = 0777)
 {
     // redefine vars
     $filename = (string) $filename;
     $content = (string) $content;
     $createFile = (bool) $createFile;
     $append = (bool) $append;
     // file may not be created, but it doesn't exist either
     if (!$createFile && self::exists($filename)) {
         throw new SpoonFileSystemException('The file "' . $filename . '" doesn\'t exist');
     }
     // create directory recursively if needed
     SpoonDirectory::create(dirname($filename), $chmod, true);
     // create file & open for writing
     $handler = $append ? @fopen($filename, 'a') : @fopen($filename, 'w');
     // something went wrong
     if ($handler === false) {
         throw new SpoonFileSystemException('The file "' . $filename . '" could not be created. Check if PHP has enough permissions.');
     }
     // write to file & close it
     @fwrite($handler, $content);
     @fclose($handler);
     // chmod file
     @chmod($filename, $chmod);
     // status
     return true;
 }
Esempio n. 16
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('category_id')->getValue() == 'new_category') {
             $this->frm->getField('category_id')->addError(BL::err('FieldIsRequired'));
         }
         if ($this->imageIsAllowed) {
             // validate the image
             if ($this->frm->getField('image')->isFilled()) {
                 // image extension and mime type
                 $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
                 $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             }
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = (int) BackendBlogModel::getMaximumId() + 1;
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = $item['created_on'];
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // create folders if needed
                 if (!SpoonDirectory::exists($imagePath . '/source')) {
                     SpoonDirectory::create($imagePath . '/source');
                 }
                 if (!SpoonDirectory::exists($imagePath . '/128x128')) {
                     SpoonDirectory::create($imagePath . '/128x128');
                 }
                 // image provided?
                 if ($this->frm->getField('image')->isFilled()) {
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image & generate thumbnails
                     $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
                 }
             }
             // insert the item
             $item['revision_id'] = BackendBlogModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // add search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock('blog', 'detail') . '/' . $this->meta->getURL());
                 }
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['revision_id']);
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $this->redirect(BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']);
             }
         }
     }
 }
Esempio n. 17
0
 /**
  * Process the XML and treat it as a blogpost
  *
  * @param SimpleXMLElement $xml The XML to process.
  * @return bool
  */
 private function processXMLAsPost(SimpleXMLElement $xml)
 {
     // init var
     $postID = substr((string) $xml->id, mb_strpos((string) $xml->id, 'post-') + 5);
     // validate
     if ($postID == '') {
         return false;
     }
     if ((string) $xml->title == '') {
         return false;
     }
     // build item
     $item['id'] = (int) BackendBlogModel::getMaximumId() + 1;
     $item['user_id'] = BackendAuthentication::getUser()->getUserId();
     $item['hidden'] = 'N';
     $item['allow_comments'] = 'Y';
     $item['num_comments'] = 0;
     $item['status'] = 'active';
     $item['language'] = BL::getWorkingLanguage();
     $item['publish_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->published));
     $item['created_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->published));
     $item['edited_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->updated));
     $item['category_id'] = 1;
     $item['title'] = (string) $xml->title;
     $item['text'] = (string) $xml->content;
     // set drafts hidden
     if (strtotime((string) $xml->published) > time()) {
         $item['hidden'] = 'Y';
         $item['status'] = 'draft';
     }
     // build meta
     $meta = array();
     $meta['keywords'] = $item['title'];
     $meta['keywords_overwrite'] = 'N';
     $meta['description'] = $item['title'];
     $meta['description_overwrite'] = 'N';
     $meta['title'] = $item['title'];
     $meta['title_overwrite'] = 'N';
     $meta['url'] = BackendBlogModel::getURL($item['title']);
     $meta['url_overwrite'] = 'N';
     // replace f****d up links
     $item['text'] = preg_replace('|<a(.*)onblur="(.*)"(.*)>|Ui', '<a$1$3>', $item['text']);
     // fix images
     $item['text'] = preg_replace('|<img(.*)border="(.*)"(.*)>|Ui', '<img$1$3>', $item['text']);
     // remove inline styles
     $item['text'] = preg_replace('|<(.*)style="(.*)"(.*)>|Ui', '<$1$3>', $item['text']);
     // whitespace
     $item['text'] = preg_replace('|\\s{2,}|', ' ', $item['text']);
     // cleanup
     $search = array('<br /><br />', '<div><br /></div>', '<div>', '</div>', '<i>', '</i>', '<b>', '</b>', '<p><object', '</object></p>', '<p><p>', '</p></p>', '...');
     $replace = array('</p><p>', '</p><p>', '', '', '<em>', '</em>', '<strong>', '</strong>', '<object', '</object>', '<p>', '</p>', '…');
     // cleanup
     $item['text'] = '<p>' . str_replace($search, $replace, SpoonFilter::htmlentitiesDecode($item['text'])) . '</p>';
     // get images
     $matches = array();
     preg_match_all('/<img.*src="(.*)".*\\/>/Ui', $item['text'], $matches);
     // any images?
     if (isset($matches[1]) && !empty($matches[1])) {
         // init var
         $imagesPath = FRONTEND_FILES_PATH . '/userfiles/images/blog';
         $imagesURL = FRONTEND_FILES_URL . '/userfiles/images/blog';
         // create dir if needed
         if (!SpoonDirectory::exists($imagesPath)) {
             SpoonDirectory::create($imagesPath);
         }
         // loop matches
         foreach ($matches[1] as $key => $file) {
             // get file info
             $fileInfo = SpoonFile::getInfo($file);
             // init var
             $destinationFile = $item['id'] . '_' . $fileInfo['basename'];
             try {
                 // download
                 SpoonFile::download($file, $imagesPath . '/' . $destinationFile);
                 // replace the old URL with the new one
                 $item['text'] = str_replace($file, $imagesURL . '/' . $destinationFile, $item['text']);
             } catch (Exception $e) {
                 // ignore
             }
         }
     }
     // get links
     $matches = array();
     preg_match_all('/<a.*href="(.*)".*\\/>/Ui', $item['text'], $matches);
     // any images?
     if (isset($matches[1]) && !empty($matches[1])) {
         // loop matches
         foreach ($matches[1] as $key => $file) {
             // get new link
             $replaceWith = self::download($file, $item['id']);
             // should we replace?
             if ($replaceWith !== false) {
                 // replace the old URL with the new one
                 $item['text'] = str_replace($file, $replaceWith, $item['text']);
             }
         }
     }
     // insert meta
     $item['meta_id'] = BackendModel::getDB(true)->insert('meta', $meta);
     // insert
     BackendBlogModel::insert($item);
     // store the post
     $this->newIds[$postID] = $item['id'];
     // get tags
     $tags = array();
     // loop categories
     foreach ($xml->category as $category) {
         // is this a tag? if so add it
         if ((string) $category['scheme'] == 'http://www.blogger.com/atom/ns#') {
             $tags[] = (string) $category['term'];
         }
     }
     // any tags?
     if (!empty($tags)) {
         BackendTagsModel::saveTags($item['id'], implode(',', $tags), $this->getModule());
     }
     // return
     return true;
 }
Esempio n. 18
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $file = $this->frm->getField('file');
         $this->frm->getField('title')->isFilled(BL::err('NameIsRequired'));
         $file->isFilled(BL::err('FieldIsRequired'));
         // validate the file
         if ($this->frm->getField('file')->isFilled()) {
             // file extension
             $this->frm->getField('file')->isAllowedExtension($this->allowedExtensions, BL::err('FileExtensionNotAllowed'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build file record to insert
             $item['agenda_id'] = $this->item['id'];
             $item['title'] = $this->frm->getField('title')->getValue();
             // the file path
             $filePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/' . $item['agenda_id'] . '/source';
             // create folders if needed
             if (!\SpoonDirectory::exists($filePath)) {
                 \SpoonDirectory::create($filePath);
             }
             // file provided?
             if ($file->isFilled()) {
                 // build the file name
                 $item['filename'] = time() . '.' . $file->getExtension();
                 // upload the file
                 $file->moveFile($filePath . '/' . $item['filename']);
             }
             $item['sequence'] = BackendAgendaModel::getMaximumFilesSequence($item['agenda_id']) + 1;
             // insert it
             $item['id'] = BackendAgendaModel::saveFile($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_file', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('media') . '&agenda_id=' . $item['agenda_id'] . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id'] . '#tabFiles');
         }
     }
 }
Esempio n. 19
0
 /**
  * Validate the form add image
  *
  * @return void
  */
 private function validateFormAddImage()
 {
     //--Check if the add-image form is submitted
     if ($this->frmAddImage->isSubmitted()) {
         //--Clean up fields in the form
         $this->frmAddImage->cleanupFields();
         //--Get image field
         $filImage = $this->frmAddImage->getField('images');
         //--Check if the field is filled in
         if ($filImage->isFilled()) {
             //--Image extension and mime type
             $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             //--Check if there are no errors.
             $strError = $filImage->getErrors();
             if ($strError === null) {
                 //--Get the filename
                 $strFilename = BackendGalleriaModel::checkFilename(substr($filImage->getFilename(), 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension());
                 //--Fill in the item
                 $item = array();
                 $item["album_id"] = (int) $this->id;
                 $item["user_id"] = BackendAuthentication::getUser()->getUserId();
                 $item["language"] = BL::getWorkingLanguage();
                 $item["filename"] = $strFilename;
                 $item["description"] = "";
                 $item["publish_on"] = BackendModel::getUTCDate();
                 $item["hidden"] = "N";
                 $item["sequence"] = BackendGalleriaModel::getMaximumImageSequence($this->id) + 1;
                 //--the image path
                 $imagePath = FRONTEND_FILES_PATH . '/Galleria/Images';
                 //--create folders if needed
                 if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                     \SpoonDirectory::create($imagePath . '/Source');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                     \SpoonDirectory::create($imagePath . '/128x128');
                 }
                 //--image provided?
                 if ($filImage->isFilled()) {
                     //--upload the image & generate thumbnails
                     $filImage->generateThumbnails($imagePath, $item["filename"]);
                 }
                 //--Add item to the database
                 BackendGalleriaModel::insert($item);
                 //--Redirect
                 $this->redirect(BackendModel::createURLForAction('edit_album') . '&id=' . $item["album_id"] . '&report=added-image&var=' . urlencode($item["filename"]) . '#tabImages');
             }
         }
     }
 }
Esempio n. 20
0
 /**
  * Validate the form add image
  *
  * @return void
  */
 private function validateForm()
 {
     //--Check if the add-image form is submitted
     if ($this->frm->isSubmitted()) {
         //--Clean up fields in the form (NOT ALLOWED: fields from plupload like name are deleted)
         //$this->frm->cleanupFields();
         //--Get image field
         $filImage = $this->frm->getField('images');
         //--Check if the field is filled in
         if ($filImage->isFilled()) {
             //--Image extension and mime type
             $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             //--Check if there are no errors.
             $strError = $filImage->getErrors();
             if ($strError === null) {
                 //--Get the filename
                 $strFilename = BackendGalleryModel::checkFilename(substr($_REQUEST["name"], 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension());
                 //--Fill in the item
                 $item = array();
                 $item["album_id"] = (int) $this->id;
                 $item["user_id"] = BackendAuthentication::getUser()->getUserId();
                 $item["language"] = BL::getWorkingLanguage();
                 $item["filename"] = $strFilename;
                 $item["description"] = "";
                 $item["publish_on"] = BackendModel::getUTCDate();
                 $item["hidden"] = "N";
                 $item["sequence"] = BackendGalleryModel::getMaximumImageSequence($this->id) + 1;
                 //--the image path
                 $imagePath = FRONTEND_FILES_PATH . '/Gallery/Images';
                 //--create folders if needed
                 $resolutions = $this->get('fork.settings')->get("Gallery", 'resolutions', false);
                 foreach ($resolutions as $res) {
                     if (!\SpoonDirectory::exists($imagePath . '/' . $res)) {
                         \SpoonDirectory::create($imagePath . '/' . $res);
                         // Create filesystem object
                         $filesystem = new Filesystem();
                         // Create var dir for ease of use
                         $dir = $imagePath;
                         // Check if dir exists
                         if ($filesystem->exists($dir . '/Source/')) {
                             // Create Finder object for the files
                             $finderFiles = new Finder();
                             // Get all the files in the source-dir
                             $files = $finderFiles->files()->in($dir . '/Source/');
                             // Check if $files is not empty
                             if (!empty($files)) {
                                 // Explode the dir-name
                                 $chunks = explode("x", $res, 2);
                                 // Create folder array
                                 $folder = array();
                                 $folder['width'] = $chunks[0] != '' ? (int) $chunks[0] : null;
                                 $folder['height'] = $chunks[1] != '' ? (int) $chunks[1] : null;
                                 // Loop all the files
                                 foreach ($files as $file) {
                                     set_time_limit(150);
                                     // Check if the file exists
                                     if (!$filesystem->exists($imagePath . '/' . $res . '/' . $file->getBasename())) {
                                         // generate the thumbnail
                                         $thumbnail = new \SpoonThumbnail($dir . '/Source/' . $file->getBasename(), $folder['width'], $folder['height']);
                                         $thumbnail->setAllowEnlargement(true);
                                         // if the width & height are specified we should ignore the aspect ratio
                                         if ($folder['width'] !== null && $folder['height'] !== null) {
                                             $thumbnail->setForceOriginalAspectRatio(false);
                                         }
                                         $thumbnail->parseToFile($imagePath . '/' . $res . '/' . $file->getBasename());
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/Source')) {
                     \SpoonDirectory::create($imagePath . '/Source');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                     \SpoonDirectory::create($imagePath . '/128x128');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                     \SpoonDirectory::create($imagePath . '/800x');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/200x')) {
                     \SpoonDirectory::create($imagePath . '/200x');
                 }
                 if (!\SpoonDirectory::exists($imagePath . '/400x300')) {
                     \SpoonDirectory::create($imagePath . '/400x300');
                 }
                 //--image provided?
                 if ($filImage->isFilled()) {
                     //--upload the image & generate thumbnails
                     $filImage->generateThumbnails($imagePath, $item["filename"]);
                 }
                 //--Add item to the database
                 $idInsert = BackendGalleryModel::insert($item);
                 $item['id'] = $idInsert;
                 //--Create html for ajax
                 $tpl = new Template();
                 $txtDescription = $this->frm->addTextarea("description_" . $idInsert, $item['description']);
                 $item['field_description'] = $txtDescription->setAttribute('style', 'resize: none;')->parse();
                 //--Parse filename to get name
                 $path_parts = pathinfo(FRONTEND_FILES_PATH . '/Gallery/Images/Source/' . $item['filename']);
                 $item['name'] = $path_parts['filename'];
                 $folders = BackendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Gallery/Images', true);
                 foreach ($folders as $folder) {
                     $item['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $item['filename'];
                 }
                 $tpl->assign('images', array($item));
                 $html = $tpl->getContent(BACKEND_MODULES_PATH . '/Gallery/Layout/Templates/Ajax/Image.tpl');
                 //Send html (ajax response)
                 $this->output(self::OK, $html, BL::msg('Success'));
             }
         }
     }
 }
Esempio n. 21
0
 /**
  * Install the module.
  */
 public function install()
 {
     // load install.sql
     $this->importSQL(dirname(__FILE__) . '/Data/install.sql');
     // add 'profiles' as a module
     $this->addModule('Profiles');
     // import locale
     $this->importLocale(dirname(__FILE__) . '/Data/locale.xml');
     // general settings
     $this->setSetting('Profiles', 'allow_gravatar', true);
     // add folders
     \SpoonDirectory::create(PATH_WWW . '/src/Frontend/Files/Profiles/avatars/source/');
     \SpoonDirectory::create(PATH_WWW . '/src/Frontend/Files/Profiles/avatars/240x240/');
     \SpoonDirectory::create(PATH_WWW . '/src/Frontend/Files/Profiles/avatars/64x64/');
     \SpoonDirectory::create(PATH_WWW . '/src/Frontend/Files/Profiles/avatars/32x32/');
     // module rights
     $this->setModuleRights(1, 'Profiles');
     // action rights
     $this->setActionRights(1, 'Profiles', 'Add');
     $this->setActionRights(1, 'Profiles', 'AddGroup');
     $this->setActionRights(1, 'Profiles', 'AddProfileGroup');
     $this->setActionRights(1, 'Profiles', 'Block');
     $this->setActionRights(1, 'Profiles', 'DeleteGroup');
     $this->setActionRights(1, 'Profiles', 'DeleteProfileGroup');
     $this->setActionRights(1, 'Profiles', 'Delete');
     $this->setActionRights(1, 'Profiles', 'EditGroup');
     $this->setActionRights(1, 'Profiles', 'EditProfileGroup');
     $this->setActionRights(1, 'Profiles', 'Edit');
     $this->setActionRights(1, 'Profiles', 'ExportTemplate');
     $this->setActionRights(1, 'Profiles', 'Groups');
     $this->setActionRights(1, 'Profiles', 'Import');
     $this->setActionRights(1, 'Profiles', 'Index');
     $this->setActionRights(1, 'Profiles', 'MassAction');
     // set navigation
     $navigationModulesId = $this->setNavigation(null, 'Modules');
     $navigationProfilesId = $this->setNavigation($navigationModulesId, 'Profiles');
     $this->setNavigation($navigationProfilesId, 'Overview', 'profiles/index', array('profiles/add', 'profiles/edit', 'profiles/add_profile_group', 'profiles/edit_profile_group', 'profiles/import'));
     $this->setNavigation($navigationProfilesId, 'Groups', 'profiles/groups', array('profiles/add_group', 'profiles/edit_group'));
     // add extra
     $activateId = $this->insertExtra('Profiles', 'block', 'Activate', 'Activate', null, 'N', 5000);
     $forgotPasswordId = $this->insertExtra('Profiles', 'block', 'ForgotPassword', 'ForgotPassword', null, 'N', 5001);
     $indexId = $this->insertExtra('Profiles', 'block', 'Dashboard', null, null, 'N', 5002);
     $loginId = $this->insertExtra('Profiles', 'block', 'Login', 'Login', null, 'N', 5003);
     $logoutId = $this->insertExtra('Profiles', 'block', 'Logout', 'Logout', null, 'N', 5004);
     $changeEmailId = $this->insertExtra('Profiles', 'block', 'ChangeEmail', 'ChangeEmail', null, 'N', 5005);
     $changePasswordId = $this->insertExtra('Profiles', 'block', 'ChangePassword', 'ChangePassword', null, 'N', 5006);
     $settingsId = $this->insertExtra('Profiles', 'block', 'Settings', 'Settings', null, 'N', 5007);
     $registerId = $this->insertExtra('Profiles', 'block', 'Register', 'Register', null, 'N', 5008);
     $resetPasswordId = $this->insertExtra('Profiles', 'block', 'ResetPassword', 'ResetPassword', null, 'N', 5008);
     $resendActivationId = $this->insertExtra('Profiles', 'block', 'ResendActivation', 'ResendActivation', null, 'N', 5009);
     $this->insertExtra('Profiles', 'widget', 'LoginBox', 'LoginBox', null, 'N', 5010);
     $this->insertExtra('Profiles', 'widget', 'LoginLink', 'LoginLink', null, 'N', 5011);
     // get search widget id
     $searchId = (int) $this->getDB()->getVar('SELECT id FROM modules_extras WHERE module = ? AND action = ?', array('search', 'form'));
     // loop languages
     foreach ($this->getLanguages() as $language) {
         // only add pages if profiles isn't linked anywhere
         // @todo refactor me, syntax sucks atm
         if (!(bool) $this->getDB()->getVar('SELECT 1
              FROM pages AS p
              INNER JOIN pages_blocks AS b ON b.revision_id = p.revision_id
              INNER JOIN modules_extras AS e ON e.id = b.extra_id
              WHERE e.module = ? AND p.language = ?
              LIMIT 1', array('Profiles', $language))) {
             // activate page
             $this->insertPage(array('title' => 'Activate', 'type' => 'root', 'language' => $language), null, array('extra_id' => $activateId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // forgot password page
             $this->insertPage(array('title' => 'Forgot password', 'type' => 'root', 'language' => $language), null, array('extra_id' => $forgotPasswordId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // reset password page
             $this->insertPage(array('title' => 'Reset password', 'type' => 'root', 'language' => $language), null, array('extra_id' => $resetPasswordId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // resend activation email page
             $this->insertPage(array('title' => 'Resend activation e-mail', 'type' => 'root', 'language' => $language), null, array('extra_id' => $resendActivationId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // login page
             $this->insertPage(array('title' => 'Login', 'type' => 'root', 'language' => $language), null, array('extra_id' => $loginId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // register page
             $this->insertPage(array('title' => 'Register', 'type' => 'root', 'language' => $language), null, array('extra_id' => $registerId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // logout page
             $this->insertPage(array('title' => 'Logout', 'type' => 'root', 'language' => $language), null, array('extra_id' => $logoutId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // index page
             $indexPageId = $this->insertPage(array('title' => 'Profile', 'type' => 'root', 'language' => $language), null, array('extra_id' => $indexId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // settings page
             $this->insertPage(array('title' => 'Profile settings', 'parent_id' => $indexPageId, 'language' => $language), null, array('extra_id' => $settingsId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // change email page
             $this->insertPage(array('title' => 'Change email', 'parent_id' => $indexPageId, 'language' => $language), null, array('extra_id' => $changeEmailId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
             // change password page
             $this->insertPage(array('title' => 'Change password', 'parent_id' => $indexPageId, 'language' => $language), null, array('extra_id' => $changePasswordId, 'position' => 'main'), array('extra_id' => $searchId, 'position' => 'top'));
         }
     }
 }
Esempio n. 22
0
 /**
  * Minify a javascript-file
  *
  * @param string $file The file to be minified.
  * @return string
  */
 private function minifyJS($file)
 {
     // create unique filename
     $fileName = md5($file) . '.js';
     $finalURL = FRONTEND_CACHE_URL . '/minified_js/' . $fileName;
     $finalPath = FRONTEND_CACHE_PATH . '/minified_js/' . $fileName;
     // check that file does not yet exist or has been updated already
     if (!SpoonFile::exists($finalPath) || filemtime(PATH_WWW . $file) > filemtime($finalPath)) {
         // create directory if it does not exist
         if (!SpoonDirectory::exists(dirname($finalPath))) {
             SpoonDirectory::create(dirname($finalPath));
         }
         // minify the file
         require_once PATH_LIBRARY . '/external/minify.php';
         $js = new MinifyJS(PATH_WWW . $file);
         $js->minify($finalPath);
     }
     return $finalURL;
 }