/** * */ public function checkSkinStyles($name, $values) { $config = Zend_Registry::get('config'); $basePath = $config->design->pathToSkins; $xhtml = array(); $this->view->name = $name; $this->view->selectedStyles = $values; //load the skin folders if (is_dir('./' . $basePath)) { $folders = Digitalus_Filesystem_Dir::getDirectories('./' . $basePath); if (count($folders) > 0) { foreach ($folders as $folder) { $this->view->skin = $folder; $styles = Digitalus_Filesystem_File::getFilesByType('./' . $basePath . '/' . $folder . '/styles', 'css'); if (is_array($styles)) { foreach ($styles as $style) { //add each style sheet to the hash // key = path / value = filename $hashStyles[$style] = $style; } $this->view->styles = $hashStyles; $xhtml[] = $this->view->render($this->partialFile); unset($hashStyles); } } } } else { throw new Zend_Acl_Exception('Unable to locate skin folder'); } return implode(null, $xhtml); }
/** * you pass this function the key for the $_FILES[key] array * and the new filepath to move the file to * then add the new filename * if $createPath is true then this will attempt to create the directories required for the path * * @param string $key * @param string $path * @param string $filename * @param bool $createPath */ public function upload($key, $path, $filename = false, $createPath = true, $permissions = '777') { if (self::isUploaded($key)) { //default to the name on the client machine if (!$filename) { $filename = $_FILES[$key]['name']; } $path = Digitalus_Toolbox_String::stripLeading('/', $path); if ($createPath) { //attempt to create the new path Digitalus_Filesystem_Dir::makeRecursive(self::PATH_TO_FILES, $path); } //clean the filename $filename = Digitalus_Filesystem_File::cleanFilename($filename); $filename = Digitalus_Toolbox_String::getSelfFromPath($filename); $fullPath = self::PATH_TO_FILES . "/" . $path . "/" . $filename; if (move_uploaded_file($_FILES[$key]['tmp_name'], $fullPath)) { // Set permissions for this file @chmod($fullPath, $permissions); //return the filepath if things worked out //this is relative to the site root as this is the format that will be required for links and what not $fullPath = Digitalus_Toolbox_String::stripLeading('./', $fullPath); return $fullPath; } } }
public function renderMediaBrowser($path, $folderLink, $fileLink) { $folders = Digitalus_Filesystem_Dir::getDirectories($path); $files = Digitalus_Filesystem_File::getFilesByType($path, false, false, true); $links = null; if (is_array($folders) && count($folders) > 0) { foreach ($folders as $folder) { $folderPath = $path . '/' . $folder; $link = Digitalus_Toolbox_String::addUnderscores($folderPath); //remove reference to media $link = str_replace('media_', '', $link); $submenu = $this->view->RenderMediaBrowser($folderPath, $folderLink, $fileLink); $links[] = '<li class="menuItem">' . $this->view->link($folder, '/' . $folderLink . '/' . $link, 'folder.png') . $submenu . '</li>'; } } if (is_array($files) && count($files) > 0) { foreach ($files as $file) { if (substr($file, 0, 1) != '.') { $filePath = $path . '/' . $file; $links[] = '<li class="menuItem">' . $this->view->link($file, $fileLink . '/' . $filePath, $this->view->getIconByFiletype($file, false)) . '</li>'; } } } if (is_array($links)) { $filetree = '<ul id="fileTree" class="treeview">' . implode(null, $links) . '</ul>'; return $filetree; } return null; }
/** * Return an array with the existing extension modules * * @return array|false */ public static function getModules() { $modules = Digitalus_Filesystem_Dir::getDirectories(APPLICATION_PATH . '/modules'); if (is_array($modules)) { return $modules; } return false; }
/** * indexes the helper library and adds the script paths to the subdirs */ public static function register($view) { $helperDirs = Digitalus_Filesystem_Dir::getDirectories('./application/helpers'); if (is_array($helperDirs)) { foreach ($helperDirs as $dir) { $view->addHelperPath('./application/helpers/' . $dir, 'Digitalus_View_Helper_' . ucfirst($dir)); } } }
/** * Initialize the form * * @return void */ public function init() { parent::init(); $view = $this->getView(); // create new element $id = $this->createElement('hidden', 'id', array('decorators' => array('ViewHelper'))); $this->addElement($id); // create new element $name = $this->createElement('text', 'page_name', array('label' => $view->getTranslation('Page Name'), 'required' => true, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array(array('NotEmpty', true), array('StringLength', true, array(4, Model_Page::PAGE_NAME_LENGTH)), array('Regex', true, array('pattern' => Model_Page::PAGE_NAME_REGEX, 'messages' => array('regexNotMatch' => Model_Page::PAGE_NAME_REGEX_NOTMATCH)))), 'attribs' => array('size' => 50), 'order' => 0)); $this->addElement($name); // add options for parent page $multiOptions = array(0 => $view->getTranslation('Site Root')); $mdlIndex = new Model_Page(); $index = $mdlIndex->getIndex(0, 'name'); if (is_array($index)) { foreach ($index as $id => $page) { $multiOptions[$id] = $page; } } // create new element $parentId = $this->createElement('select', 'parent_id', array('label' => $view->getTranslation('Parent page') . ':', 'required' => true, 'multiOptions' => $multiOptions, 'order' => 1)); $this->addElement($parentId); // add options for template $multiOptions = array(); $templateConfig = Zend_Registry::get('config')->template; $templates = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public'); foreach ($templates as $template) { $designs = Digitalus_Filesystem_File::getFilesByType(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public/' . $template . '/pages', 'xml'); if (is_array($designs)) { foreach ($designs as $design) { $design = Digitalus_Toolbox_Regex::stripFileExtension($design); $multiOptions[$template . '_' . $design] = $view->getTranslation($template) . ' / ' . $view->getTranslation($design); } } } // create new element $contentTemplate = $this->createElement('select', 'content_template', array('label' => $view->getTranslation('Template') . ':', 'required' => true, 'multiOptions' => $multiOptions, 'order' => 2)); $this->addElement($contentTemplate); // create new element $continue = $this->createElement('checkbox', 'continue_adding_pages', array('label' => $view->getTranslation('Continue adding pages') . '?', 'order' => 3)); $this->addElement($continue); // create new element $showOnMenu = $this->createElement('checkbox', 'show_on_menu', array('label' => $view->getTranslation('Show Page on menu') . '?', 'order' => 4)); $this->addElement($showOnMenu); // create new element $publish = $this->createElement('checkbox', 'publish_pages', array('label' => $view->getTranslation('Publish page instantly') . '?', 'order' => 5)); $this->addElement($publish); // create new element $submit = $this->createElement('submit', 'submitPageForm', array('label' => $view->getTranslation('Submit'), 'attribs' => array('class' => 'submit'), 'order' => 1000)); $this->addElement($submit); $this->addDisplayGroup(array('form_instance', 'id', 'page_name', 'parent_id', 'content_template', 'continue_adding_pages', 'show_on_menu', 'publish_pages', 'submitPageForm'), 'createPageGroup'); }
/** * render a module page like news_showNewPosts */ public function loadModule($module, $action, $params = array()) { //validate the module $modules = Digitalus_Filesystem_Dir::getDirectories(APPLICATION_PATH . '/modules'); // @todo: validate the action as well if (in_array($module, $modules)) { if (is_array($params)) { foreach ($params as $k => $v) { $paramsArray[(string) $k] = (string) $v; } } return $this->view->action($action, 'public', 'mod_' . $module, $paramsArray); } }
/** * */ public function selectDesign($name, $value = null, $attr = null) { $templateConfig = Zend_Registry::get('config')->template; $templates = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public'); foreach ($templates as $template) { $designs = Digitalus_Filesystem_File::getFilesByType(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public/' . $template . '/pages', 'xml'); if (is_array($designs)) { foreach ($designs as $design) { $design = Digitalus_Toolbox_Regex::stripFileExtension($design); $options[$template . '_' . $design] = $template . ' / ' . $design; } } } return $this->view->formSelect($name, $value, $attr, $options); }
public function init() { $id = $this->createElement('hidden', 'id'); $id->setDecorators(array('ViewHelper')); $this->addElement($id); $name = $this->createElement('text', 'page_name'); $name->addFilter('StripTags'); $name->setRequired(true); $name->setLabel('Page Name: '); $name->setAttrib('size', 50); $name->setOrder(0); $this->addElement($name); $parentId = $this->createElement('select', 'parent_id'); $parentId->setLabel($this->getView()->getTranslation('Parent page') . ':'); $mdlIndex = new Model_Page(); $index = $mdlIndex->getIndex(0, 'name'); $parentId->addMultiOption(0, $this->getView()->getTranslation('Site Root')); if (is_array($index)) { foreach ($index as $id => $page) { $parentId->addMultiOption($id, $page); } } $parentId->setOrder(1); $this->addElement($parentId); $contentTemplate = $this->createElement('select', 'content_template'); $contentTemplate->setLabel($this->getView()->getTranslation('Template') . ':'); $templateConfig = Zend_Registry::get('config')->template; $templates = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public'); foreach ($templates as $template) { $designs = Digitalus_Filesystem_File::getFilesByType(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public/' . $template . '/pages', 'xml'); if (is_array($designs)) { foreach ($designs as $design) { $design = Digitalus_Toolbox_Regex::stripFileExtension($design); $contentTemplate->addMultiOption($template . '_' . $design, $template . ' / ' . $design); } } } $contentTemplate->setOrder(2); $this->addElement($contentTemplate); $continue = $this->createElement('checkbox', 'continue_adding_pages'); $continue->setLabel($this->getView()->getTranslation('Continue adding pages') . '?'); $continue->setOrder(3); $this->addElement($continue); $submit = $this->createElement('submit', $this->getView()->getTranslation('Submit')); $submit->setOrder(1000); $this->addElement($submit); }
/** * */ public function selectSkin($name, $value = null, $attr = null, $defaut = null) { $config = Zend_Registry::get('config'); $pathToPublicSkins = $config->design->pathToSkins; $skins = Digitalus_Filesystem_Dir::getDirectories($pathToPublicSkins); if ($defaut == NULL) { $defaut = $this->view->getTranslation('Select One'); } $options[0] = $defaut; if (is_array($skins)) { foreach ($skins as $skin) { $options[$skin] = $skin; } return $this->view->formSelect($name, $value, $attr, $options); } else { return null; } }
/** * */ public function selectDesign($name, $value = null, $attribs = null, $options = null) { $templateConfig = Zend_Registry::get('config')->template; $templates = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public'); foreach ($templates as $template) { $designs = Digitalus_Filesystem_File::getFilesByType(BASE_PATH . '/' . $templateConfig->pathToTemplates . '/public/' . $template . '/pages', 'xml'); if (is_array($designs)) { foreach ($designs as $design) { $design = Digitalus_Toolbox_Regex::stripFileExtension($design); $options[$template . '_' . $design] = $template . ' / ' . $design; } } } $form = new Digitalus_Form(); $select = $form->createElement('select', $name, array('multiOptions' => $options, 'value' => $value)); if (is_array($attribs)) { $select->setAttribs($attribs); } return $select; }
protected function _getModuleForms() { $moduleForms = array(); $modules = Digitalus_Filesystem_Dir::getDirectories(APPLICATION_PATH . '/modules'); if (is_array($modules)) { foreach ($modules as $module) { $pages = Digitalus_Filesystem_File::getFilesByType(APPLICATION_PATH . '/modules/' . $module . '/views/scripts/public', 'phtml'); if (is_array($pages)) { foreach ($pages as $page) { if (strpos($page, '.form.')) { $page = Digitalus_Toolbox_Regex::stripFileExtension($page); $page = str_replace('.form', '', $page); $moduleForms[$module . '_' . $page] = $this->view->getTranslation($module) . ' -> ' . $page; } } } } return $moduleForms; } return false; }
public function SelectModule($name, $value, $attribs = null) { $modules = Digitalus_Filesystem_Dir::getDirectories('./application/modules'); if (is_array($modules)) { $data[] = $this->view->getTranslation('Select a module'); foreach ($modules as $module) { $pages = Digitalus_Filesystem_File::getFilesByType('./application/modules/' . $module . '/views/scripts/public', 'phtml'); if (is_array($pages)) { foreach ($pages as $page) { if (!strpos($page, '.form.')) { $page = Digitalus_Toolbox_Regex::stripFileExtension($page); $data[$module . '_' . $page] = $module . ' -> ' . $page; } } } } $attribs['multiple'] = false; return $this->view->formSelect($name, $value, $attribs, $data); } else { return $this->view->getTranslation('There are no modules currently installed'); } }
/** * Return an array with the existing extension modules * * @return array|false */ protected function _getModules() { $modules = Digitalus_Filesystem_Dir::getDirectories(APPLICATION_PATH . '/modules'); if (is_array($modules)) { return $modules; } else { return false; } }
public static function deleteFolder($folder) { $config = Zend_Registry::get('config'); if (self::testFilepath($folder)) { $folder = Digitalus_Toolbox_String::stripUnderscores($folder); $fullPath = self::rootDirectory() . '/' . $folder; //move the folder to the trash Digitalus_Filesystem_Dir::copyRecursive($fullPath, $config->filepath->trash); Digitalus_Filesystem_Dir::deleteRecursive($fullPath); } }
/** * Open Folder Action * * @return void */ public function openFolderAction() { $folder = $this->_request->getParam('folder'); $folder = str_replace('media_', '', $folder); $folder = Digitalus_Toolbox_String::stripLeading('_', $folder); $data = array(); $data['path'] = $folder; $folderArray = explode('_', $folder); if (is_array($folderArray)) { foreach ($folderArray as $pathPart) { if (!empty($pathPart)) { $fullPathParts[] = $pathPart; $fullPath = implode('_', $fullPathParts); $folderPathParts[$fullPath] = $pathPart; } } } if (isset($folderPathParts) && !empty($folderPathParts)) { $data['folderPathParts'] = $folderPathParts; $data['label'] = array_pop($folderPathParts); } $pathToFolder = Digitalus_Toolbox_String::stripUnderscores($folder); $data['filepath'] = $pathToFolder; $data['mediapath'] = $folder; $data['folders'] = Digitalus_Filesystem_Dir::getDirectories($this->_pathToMedia . '/' . $pathToFolder); $data['files'] = Digitalus_Filesystem_File::getFilesByType($this->_pathToMedia . '/' . $pathToFolder, false, false, true); $data['mediaFolder'] = $this->view->mediaFolder; $form = new Admin_Form_Media(null, $data); $form->setDecorators(array('FormElements', 'Form', array('FormErrors', array('placement' => 'prepend')))); if ($this->_request->isPost() && Digitalus_Filter_Post::has('form_instance')) { $path = Digitalus_Filter_Post::get('path'); $filePath = Digitalus_Filter_Post::get('filepath'); $mediaPath = Digitalus_Filter_Post::get('mediapath'); $folderName = Digitalus_Filter_Post::get('folder_name'); $newFolderName = Digitalus_Filter_Post::get('new_folder_name'); // indicator if it is a return of one of the other actions if (false == $this->_request->getParam('return')) { // createFolderAction if ($form->isValidPartial(array('path' => $path, 'folder_name' => $folderName)) && isset($_POST['createFolderSubmit']) && !empty($_POST['createFolderSubmit'])) { $this->_request->setParam('path', $path); $this->_request->setParam('folder_name', $folderName); $this->_forward('create-folder'); // renameFolderAction } else { if ($form->isValidPartial(array('filepath' => $filePath, 'new_folder_name' => $newFolderName)) && isset($_POST['renameFolderSubmit']) && !empty($_POST['renameFolderSubmit'])) { $this->_request->setParam('filepath', $filePath); $this->_request->setParam('new_folder_name', $newFolderName); $this->_forward('rename-folder'); // uploadAction } else { if ($form->isValidPartial(array('filepath' => $filePath, 'mediapath' => $mediaPath)) && isset($_POST['uploadSubmit']) && !empty($_POST['uploadSubmit'])) { $this->_request->setParam('filepath', $filePath); $this->_request->setParam('mediapath', $mediaPath); $this->_forward('upload'); } } } } } $this->view->form = $form; $tmpPath = Digitalus_Toolbox_String::addUnderscores($folder); $this->view->toolbarLinks['Add to my bookmarks'] = $this->baseUrl . '/admin/index/bookmark' . '/url/admin_media_open-folder_folder_' . $tmpPath . '/label/' . $this->view->getTranslation('Media') . ':' . $pathToFolder; $this->view->toolbarLinks['Delete'] = $this->baseUrl . '/admin/media/delete-folder/folder/' . $folder; $this->view->breadcrumbs[$this->view->getTranslation('Open Folder') . ': ' . Digitalus_Toolbox_String::stripUnderscores($folder)] = $this->baseUrl . '/admin/media/open-folder/folder/' . $folder; }
/** * deletes a directory recursively * * @param string $target * @param bool $verbose * @return bool */ public static function deleteRecursive($target, $verbose = false) { $exceptions = array('.', '..'); if (!($sourcedir = @opendir($target))) { if ($verbose) { echo "<strong>Could't open {$target} </strong><br />\n"; } return false; } while (false !== ($sibling = readdir($sourcedir))) { if (!in_array($sibling, $exceptions)) { $object = str_replace('//', '/', $target . '/' . $sibling); if ($verbose) { echo 'Processing: <strong>' . $object . "</strong><br />\n"; } if (is_dir($object)) { Digitalus_Filesystem_Dir::deleteRecursive($object); } if (is_file($object)) { $result = @unlink($object); if ($verbose && $result) { echo "File has been removed<br />\n"; } if ($verbose && !$result) { echo "<strong>Couldn't remove file</strong>"; } } } } closedir($sourcedir); if ($result = @rmdir($target)) { if ($verbose) { echo "Target directory has been removed<br />\n"; return true; } } else { if ($verbose) { echo "<strong>Couldn't remove target directory</strong>"; return false; } } }
/** * * Removes unneeded directories * * @return void */ private function _removeDirectories() { $directories = array('data', 'configs', 'models'); foreach ($directories as $directory) { Digitalus_Filesystem_Dir::deleteRecursive(APPLICATION_PATH . '/' . $directory); } }
/** * Open Folder Action * * @return void */ public function openFolderAction() { $folder = $this->_request->getParam('folder'); $folder = str_replace('media_', '', $folder); $this->view->path = $folder; $folder = Digitalus_Toolbox_String::stripHyphens($folder); $folder = Digitalus_Toolbox_String::stripLeading('_', $folder); $folderArray = explode('_', $folder); if (is_array($folderArray)) { foreach ($folderArray as $pathPart) { if (!empty($pathPart)) { $fullPathParts[] = $pathPart; $fullPath = implode('_', $fullPathParts); $folderPathParts[$fullPath] = $pathPart; } } } if (isset($folderPathParts) && !empty($folderPathParts)) { $this->view->folderPathParts = $folderPathParts; } $pathToFolder = Digitalus_Toolbox_String::stripUnderscores($folder); $this->view->filesystemPath = $pathToFolder; $this->view->mediaPath = $folder; $this->view->folders = Digitalus_Filesystem_Dir::getDirectories($this->_pathToMedia . '/' . $pathToFolder); $this->view->files = Digitalus_Filesystem_File::getFilesByType($this->_pathToMedia . '/' . $pathToFolder, false, false, true); $this->view->breadcrumbs[$this->view->getTranslation('Open Folder') . ': ' . Digitalus_Toolbox_String::stripUnderscores($folder)] = $this->getFrontController()->getBaseUrl() . '/admin/media/open-folder/folder/' . $folder; $this->view->toolbarLinks = array(); $tmpPath = Digitalus_Toolbox_String::addUnderscores($folder); $this->view->toolbarLinks['Add to my bookmarks'] = $this->getFrontController()->getBaseUrl() . '/admin/index/bookmark' . '/url/admin_media_open-folder_folder_' . $tmpPath . '/label/' . $this->view->getTranslation('Media') . ':' . $pathToFolder; $this->view->toolbarLinks['Delete'] = $this->getFrontController()->getBaseUrl() . '/admin/media/delete-folder/folder/' . $folder; }
/** * Initialize the view * * @return Zend_View */ protected function _initView() { // Initialize view $view = new Zend_View(); // $this->bootstrap('siteSettings'); // // Get settings resource // $settings = $this->getResource('siteSettings'); // // // Set doctype and charset // $view->doctype($settings->get('doc_type')); // $view->placeholder('charset')->set($settings->get('default_charset')); // Add the view to the ViewRenderer $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer'); $viewRenderer->setView($view); // Load digitalus helpers // base helpers // $view->addHelperPath('Digitalus/View/Helper', 'Digitalus_View_Helper'); // $view->addHelperPath('Digitalus/Content/Control', 'Digitalus_Content_Control'); // Get $helperDirs from cache object $cache = $this->getResource('cache'); if (($helperDirs = $cache->load('helper_dirs')) == false) { $helperDirs = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/library/Digitalus/View/Helper'); $cache->save($helperDirs, 'helper_dirs'); } // $helperDirs = Digitalus_Filesystem_Dir::getDirectories(BASE_PATH . '/library/Digitalus/View/Helper'); if (is_array($helperDirs)) { foreach ($helperDirs as $dir) { $view->addHelperPath(BASE_PATH . '/library/Digitalus/View/Helper/' . $dir, 'Digitalus_View_Helper_' . ucfirst($dir)); } } $view->baseUrl = $this->_front->getBaseUrl(); // Return it, so that it can be stored by the bootstrap return $view; }
$updater->run(); $view->placeholder('form')->set($view->render('update1.phtml')); } catch (Digitalus_Updater_Exception $e) { $updater->addError('A fatal error while updating the databases occurred!'); $updater->addError($e->getMessage()); } break; } } else { $updater->addError('You can only update from version ' . Digitalus_Updater_Abstract::getOldVersion() . '!<br />Older versions are not supported!'); } } else { // The cms is already installed // Remove the install directory # Digitalus_Filesystem_Dir::deleteRecursive('./install'); Digitalus_Filesystem_Dir::rename('./install', './install_hidden'); // Return to the index file header('location: ./'); } /* ***************************************************************************** * F R E S H I N S T A L L * ************************************************************************** */ } else { // Fetch the current step $step = $_GET['step']; $step = intval($step); if ($step < 1) { $step = 1; } switch ($step) { case 1: