/** * 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'); }
/** * 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); } } }
/** * Get the thumbnail folders * * @param string $path The path * @param bool[optional] $includeSource Should the source-folder be included in the return-array. * @return array */ public static function getThumbnailFolders($path, $includeSource = false) { $folders = SpoonDirectory::getList((string) $path, false, null, '/^([0-9]*)x([0-9]*)$/'); if ($includeSource && SpoonDirectory::exists($path . '/source')) { $folders[] = 'source'; } $return = array(); foreach ($folders as $folder) { $item = array(); $chunks = explode('x', $folder, 2); // skip invalid items if (count($chunks) != 2 && !$includeSource) { continue; } $item['dirname'] = $folder; $item['path'] = $path . '/' . $folder; if (substr($path, 0, strlen(PATH_WWW)) == PATH_WWW) { $item['url'] = substr($item['path'], strlen(PATH_WWW)); } if ($folder == 'source') { $item['width'] = null; $item['height'] = null; } else { $item['width'] = $chunks[0] != '' ? (int) $chunks[0] : null; $item['height'] = $chunks[1] != '' ? (int) $chunks[1] : null; } $return[] = $item; } return $return; }
/** * Get an unique URL for a page * * @param string $URL The URL to base on. * @param int[optional] $id The id to ignore. * @param int[optional] $parentId The parent for the page to create an url for. * @param bool[optional] $isAction Is this page an action. * @return string */ public static function getURL($URL, $id = null, $parentId = 0, $isAction = false) { $URL = (string) $URL; $parentIds = array((int) $parentId); // 0, 1, 2, 3, 4 are all toplevels, so we should place them on the same level if ($parentId == 0 || $parentId == 1 || $parentId == 2 || $parentId == 3 || $parentId == 4) { $parentIds = array(0, 1, 2, 3, 4); } // get db $db = BackendModel::getDB(); // no specific id if ($id === null) { // no items? if ((bool) $db->getVar('SELECT 1 FROM pages AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ? AND i.language = ? LIMIT 1', array('active', $URL, BL::getWorkingLanguage()))) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new URL return self::getURL($URL, null, $parentId, $isAction); } } else { // there are items so, call this method again. if ((bool) $db->getVar('SELECT 1 FROM pages AS i INNER JOIN meta AS m ON i.meta_id = m.id WHERE i.parent_id IN(' . implode(',', $parentIds) . ') AND i.status = ? AND m.url = ? AND i.id != ? AND i.language = ? LIMIT 1', array('active', $URL, $id, BL::getWorkingLanguage()))) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new URL return self::getURL($URL, $id, $parentId, $isAction); } } // get full URL $fullURL = self::getFullUrl($parentId) . '/' . $URL; // get info about parent page $parentPageInfo = self::get($parentId, null, BL::getWorkingLanguage()); // does the parent have extra's? if ($parentPageInfo['has_extra'] == 'Y' && !$isAction) { // set locale FrontendLanguage::setLocale(BackendLanguage::getWorkingLanguage(), true); // get all onsite action $actions = FrontendLanguage::getActions(); // if the new URL conflicts with an action we should rebuild the URL if (in_array($URL, $actions)) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new URL return self::getURL($URL, $id, $parentId, $isAction); } } // check if folder exists if (SpoonDirectory::exists(PATH_WWW . '/' . $fullURL)) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new URL return self::getURL($URL, $id, $parentId, $isAction); } // check if it is an appliation if (in_array(trim($fullURL, '/'), array_keys(ApplicationRouting::getRoutes()))) { // add a number $URL = BackendModel::addNumber($URL); // recall this method, but with a new URL return self::getURL($URL, $id, $parentId, $isAction); } // return the unique URL! return $URL; }
/** * Load the data */ private function loadData() { // get all modules $modules = BackendModel::getModules(); // get user sequence $userSequence = BackendAuthentication::getUser()->getSetting('dashboard_sequence'); // user sequence does not exist? if (!isset($userSequence)) { // get group ID of user $groupId = BackendAuthentication::getUser()->getGroupId(); // get group preset $userSequence = BackendGroupsModel::getSetting($groupId, 'dashboard_sequence'); } // loop all modules foreach ($modules as $module) { // you have sufficient rights? if (BackendAuthentication::isAllowedModule($module)) { // build pathName $pathName = BACKEND_MODULES_PATH . '/' . $module; // check if the folder exists if (SpoonDirectory::exists($pathName . '/widgets')) { // get widgets $widgets = (array) SpoonFile::getList($pathName . '/widgets', '/(.*)\\.php/i'); // loop widgets foreach ($widgets as $widget) { // require the class require_once $pathName . '/widgets/' . $widget; // init var $widgetName = str_replace('.php', '', $widget); // build classname $className = 'Backend' . SpoonFilter::toCamelCase($module) . 'Widget' . SpoonFilter::toCamelCase($widgetName); // validate if the class exists if (!class_exists($className)) { throw new BackendException('The widgetfile is present, but the classname should be: ' . $className . '.'); } // check if model file exists if (SpoonFile::exists($pathName . '/engine/model.php')) { // require model require_once $pathName . '/engine/model.php'; } // present? $present = isset($userSequence[$module][$widgetName]['present']) ? $userSequence[$module][$widgetName]['present'] : false; // if not present, continue if (!$present) { continue; } // create instance $instance = new $className(); // has rights if (!$instance->isAllowed()) { continue; } // hidden? $hidden = isset($userSequence[$module][$widgetName]['hidden']) ? $userSequence[$module][$widgetName]['hidden'] : false; // execute instance if it is not hidden if (!$hidden) { $instance->execute(); } // user sequence provided? $column = isset($userSequence[$module][$widgetName]['column']) ? $userSequence[$module][$widgetName]['column'] : $instance->getColumn(); $position = isset($userSequence[$module][$widgetName]['position']) ? $userSequence[$module][$widgetName]['position'] : $instance->getPosition(); $title = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(SpoonFilter::toCamelCase($widgetName)); $templatePath = $instance->getTemplatePath(); // reset template path if ($templatePath == null) { $templatePath = BACKEND_PATH . '/modules/' . $module . '/layout/widgets/' . $widgetName . '.tpl'; } // build item $item = array('template' => $templatePath, 'module' => $module, 'widget' => $widgetName, 'title' => $title, 'hidden' => $hidden); // add on new position if no position is set or if the position is already used if ($position === null || isset($this->widgets[$column][$position])) { $this->widgets[$column][] = $item; } else { $this->widgets[$column][$position] = $item; } } } } } // sort the widgets foreach ($this->widgets as &$column) { ksort($column); } }
/** * 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'); } } } }
/** * 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; }
/** * Does this template exist. * This does not check for existence in the database but on the filesystem. * * @param string $theme Theme to check for existence. * @return bool */ public static function existsTheme($theme) { $theme = (string) $theme; // check if modules directory exists return SpoonDirectory::exists(FRONTEND_PATH . '/themes/' . $theme) || $theme == 'core'; }
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); }
/** * 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']); } } }
/** * Loads the wizard * * @return void */ private function loadWizardSteps() { // check if this template path exists $templatePath = SpoonDirectory::exists(BACKEND_MODULE_PATH . '/templates/' . $this->record['language'] . '/' . $this->record['template']); // set wizard values $wizard = array(); $wizard[1] = array('id' => 1, 'label' => BL::lbl('WizardInformation')); $wizard[2] = array('id' => 2, 'label' => BL::lbl('WizardTemplate')); $wizard[3] = array('id' => 3, 'label' => BL::lbl('WizardContent')); $wizard[4] = array('id' => 4, 'label' => BL::lbl('WizardSend')); // load the appropriate selected classes $wizard[$this->stepId]['selected'] = true; // loop the wizard steps foreach ($wizard as &$step) { // if the current active step equals this loop's ID + 1, this list item will need the beforeSelected class if ($step['id'] + 1 == $this->stepId) { $step['beforeSelected'] = true; } // make the step link visible if we already passed this step if ($step['id'] <= $this->stepId) { $step['stepLink'] = true; } // make the step link visible if this is step 2 if ($step['id'] == 2) { $step['stepLink'] = true; } // make the step link visible if this is step 3 and the template is already set if ($step['id'] == 3 && !empty($this->record['template']) && $templatePath) { $step['stepLink'] = true; } // make the step link visible if this is step 4 and the subject/content_html is already set if ($step['id'] == 4 && !empty($this->record['content_html'])) { $step['stepLink'] = true; } } // assign iteration to the template $this->tpl->assign('wizard', $wizard); }
/** * 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']); } } }
/** * 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); } } }
/** * 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); }
/** * 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']); } } }
/** * 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']); } } } }
/** * Retrieves a list of files within a directory. * * @return array An array containing a list of files in the given directory. * @param string $path The path to the directory. * @param string[optional] $includeRegexp A regular expresion that filters the files that should be included in the list. */ public static function getList($path, $includeRegexp = null) { // redefine arguments $path = (string) $path; // validate regex if ($includeRegexp !== null) { // redefine $includeRegexp = (string) $includeRegexp; // validate if (!SpoonFilter::isValidRegexp($includeRegexp)) { throw new SpoonFileSystemException('Invalid regular expression (' . $includeRegexp . ')'); } } // define list $files = array(); // directory exists if (SpoonDirectory::exists($path)) { // attempt to open directory if ($directory = @opendir($path)) { // start reading while (($file = readdir($directory)) !== false) { // no '.' and '..' and it's a file if ($file != '.' && $file != '..' && is_file($path . '/' . $file)) { // is there a include-pattern? if ($includeRegexp !== null) { // init var $matches = array(); // is this a match? if (preg_match($includeRegexp, $file, $matches) != 0) { $files[] = $file; } } else { $files[] = $file; } } } } // close directory @closedir($directory); } // directory doesn't exist or a problem occured return $files; }
/** * 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'); } } }
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); }
/** * 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')); } } } }
/** * Get the widgets * * @return void */ private function getWidgets() { // get all active modules $modules = BackendModel::getModules(true); // loop all modules foreach ($modules as $module) { // you have sufficient rights? if (BackendAuthentication::isAllowedModule($module)) { // build pathName $pathName = BACKEND_MODULES_PATH . '/' . $module; // check if the folder exists if (SpoonDirectory::exists($pathName . '/widgets')) { // get widgets $widgets = (array) SpoonFile::getList($pathName . '/widgets', '/(.*)\\.php/i'); // loop through widgets foreach ($widgets as $widget) { // require the classes require_once $pathName . '/widgets/' . $widget; // init var $widgetName = str_replace('.php', '', $widget); // build classname $className = 'Backend' . SpoonFilter::toCamelCase($module) . 'Widget' . SpoonFilter::toCamelCase($widgetName); // validate if the class exists if (!class_exists($className)) { // throw exception throw new BackendException('The widgetfile is present, but the classname should be: ' . $className . '.'); } else { // add to array $this->widgetInstances[] = array('module' => $module, 'widget' => $widgetName, 'className' => $className); // create reflection class $reflection = new ReflectionClass('Backend' . SpoonFilter::toCamelCase($module) . 'Widget' . SpoonFilter::toCamelCase($widgetName)); // get the offset $offset = strpos($reflection->getDocComment(), '*', 7); // get the first sentence $description = substr($reflection->getDocComment(), 0, $offset); // replacements $description = str_replace('*', '', $description); $description = trim(str_replace('/', '', $description)); } // check if model file exists if (SpoonFile::exists($pathName . '/engine/model.php')) { // require model require_once $pathName . '/engine/model.php'; } // add to array $this->widgets[] = array('label' => SpoonFilter::toCamelCase($widgetName), 'value' => $widgetName, 'description' => $description); } } } } }
/** * 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; }