public function renderBookmarks($bookmarks = null) { $xhtml = ''; if (!is_array($bookmarks)) { $mdlBookmark = new Model_Bookmark(); $bookmarks = $mdlBookmark->getUsersBookmarks(); } if (!empty($bookmarks)) { $xhtml = '<ul class="bookmarks">'; foreach ($bookmarks as $bookmark) { $xhtml .= ' <li>' . PHP_EOL; $xhtml .= ' ' . $this->view->link(null, '/admin/index/delete-bookmark/id/' . $bookmark->id, 'link_delete.png', 'clear') . PHP_EOL; $url = $bookmark->url; if (strpos($url, 'mod_') === 0) { $url = str_replace('mod_', '', $url); $url = Digitalus_Toolbox_String::stripUnderscores($url); $url = 'mod_' . $url; } else { $url = Digitalus_Toolbox_String::stripUnderscores($url); } $xhtml .= ' ' . $this->view->link($bookmark->label, '/' . $url); $xhtml .= ' </li>'; } $xhtml .= '</ul>'; } else { $xhtml = $this->view->getTranslation('You do not have any bookmarks.'); } return $xhtml; }
/** * removes any params from the uri */ public function CleanUri($uri = null, $absolute = false, $stripUnderscores = false) { if ($uri == null) { $uri = $this->view->pageObj->getCleanUri(); } if ($absolute && !empty($uri)) { $uri = '/' . $uri; } if ($stripUnderscores) { $uri = Digitalus_Toolbox_String::stripUnderscores($uri, true); } return Digitalus_Toolbox_String::addHyphens($uri); }
/** * Render partial action * * @throws Zend_Exception * @return void */ public function renderPartialAction() { $partial = $this->_request->getParam('partial'); if ($partial != null) { $this->view->partialKey = Digitalus_Toolbox_String::stripUnderscores($partial); $data = new stdClass(); $data->get = $this->_request->getParams(); $data->post = $_POST; $this->view->data = $data; } else { throw new Zend_Exception('Invalid placeholder passed'); } }
public static function getMediaPath($path, $relative = true) { $path = Digitalus_Toolbox_String::stripUnderscores($path); //make it impossible to get out of the media library $path = str_replace('./', '', $path); $path = str_replace('../', '', $path); //remove root path from path if it exists in path already. $path = str_replace(self::rootDirectory(false), '', $path); //remove the reference to media if it exists $pathParts = explode('/', $path); if (is_array($pathParts)) { if ($pathParts[0] == 'media') { unset($pathParts[0]); } //remove any leading slash that may exist. $partial = implode('/', $pathParts); if (substr($partial, 0, 1) == '/') { $partial = substr($partial, 1); } //add the media root $path = self::rootDirectory($relative) . '/' . $partial; return $path; } return false; }
/** * Delete File Action * * @return void */ public function deleteFileAction() { $file = $this->_request->getParam('file'); Digitalus_Media::deleteFile($file); $filePath = Digitalus_Toolbox_String::stripUnderscores($file); $parent = Digitalus_Toolbox_String::getParentFromPath($filePath); $cleanParent = Digitalus_Toolbox_String::addUnderscores($parent); $this->_request->setParam('folder', $cleanParent); $this->_forward('open-folder'); }
/** * Initialize the form * * @return void */ public function init() { parent::init(); $view = $this->getView(); $pathToMedia = $this->_getData('pathToMedia'); $mediaFolder = $this->_getData('mediaFolder'); $path = $this->_getData('path'); $filepath = $this->_getData('filepath'); $mediapath = $this->_getData('mediapath'); $files = $this->_getData('files'); $folders = $this->_getData('folders'); $folderPathParts = $this->_getData('folderPathParts'); $label = $this->_getData('label'); /* ********************************************************************* * CURRENT DIRECTORY * ****************************************************************** */ $pathParts[] = $pathToMedia; if (is_array($folderPathParts)) { foreach ($folderPathParts as $path2 => $label2) { $pathParts[] = '<a href="' . $view->getBaseUrl() . '/admin/media/open-folder/folder/' . $path2 . '">' . Digitalus_Toolbox_String::stripUnderscores($label2) . '</a>'; } } $xhtml = '<p>' . $view->getTranslation('Media Root') . implode('/', $pathParts) . '</p>'; $currentDirectory = $this->createElement('AnyMarkup', 'current_directory', array('value' => $xhtml, 'decorators' => $this->getStandardDecorator('none'))); /* ********************************************************************* * BROWSE * ****************************************************************** */ $siteRoot = $view->getBaseUrl() . '/'; $basePath = $siteRoot . $mediaFolder; if (!empty($filepath)) { $basePath .= '/' . $filepath; } $xhtml = ''; // DIRECTORIES if (is_array($folders) && count($folders) > 0) { $xhtml = '<h3>' . $view->getTranslation('Subfolders') . '</h3>'; foreach ($folders as $folder) { $folder = Digitalus_Toolbox_String::addUnderscores($folder); $cleanPath = Digitalus_Toolbox_String::stripHyphens($folder); $cleanPath = Digitalus_Toolbox_String::stripUnderscores($folder); $deleteLink = '/admin/media/delete-folder/folder/' . $mediapath . '_' . $folder; $path2 = '/admin/media/open-folder/folder/' . $mediapath . '_' . $folder; $xhtml .= '<div class="folderWrapper">' . ' ' . $view->link('Delete', $deleteLink, 'delete.png', 'rightLink delete') . ' <h4>' . $view->link($cleanPath, $path2, 'folder.png') . '</h4>' . ' <p>' . $view->getTranslation('Full path') . ': <code>' . $basePath . '/' . $cleanPath . '</code></p>' . '</div>'; } } // FILES if (is_array($files) && count($files) > 0) { $xhtml .= '<h3>' . $view->getTranslation('Files') . '</h3>'; foreach ($files as $file) { if (substr($file, 0, 1) != '.') { $filepath2 = Digitalus_Toolbox_String::stripUnderscores($basePath) . '/' . $file; $fileLink = $mediapath . '_' . $file; $deleteLink = '/admin/media/delete-file/file/' . $fileLink . '/'; $path2 = $mediaFolder . '/' . $filepath . $filepath2; $xhtml .= '<div class="fileWrapper">' . ' ' . $view->link('Delete', $deleteLink, 'delete.png', 'rightLink delete') . ' <h4>' . $view->link($file, $path2, $view->getIconByFiletype($filepath2, false)) . '</h4>' . ' <p>' . $view->getTranslation('Full path') . ': <code>' . $basePath . $filepath2 . '</code></p>' . '</div>'; } } } $subDirectories = $this->createElement('AnyMarkup', 'sub_directories', array('value' => $xhtml, 'decorators' => $this->getStandardDecorator('none'))); /* ********************************************************************* * UPLOAD * ****************************************************************** */ $filePath = $this->createElement('hidden', 'filepath', array('value' => $filepath, 'decorators' => $this->getStandardDecorator('none'))); $mediapath = $this->createElement('hidden', 'mediapath', array('value' => $mediapath, 'decorators' => $this->getStandardDecorator('none'))); $uploads = $this->createElement('file', 'uploads[]', array('label' => $view->getTranslation('Select the files to upload'), 'belongsTo' => 'uploads', 'attribs' => array('id' => 'multi_upload'), 'filters' => array('StringTrim', 'StripTags'), 'validators' => array(array('File_NotExists', true, array())))); $uploadSubmit = $this->createElement('submit', 'uploadSubmit', array('label' => $view->getTranslation('Upload Files'), 'attribs' => array('class' => 'submit'))); /* ********************************************************************* * CREATE SUBFOLDER * ****************************************************************** */ $path = $this->createElement('hidden', 'path', array('value' => $path, 'decorators' => $this->getStandardDecorator('none'))); $folderName = $this->createElement('text', 'folder_name', array('required' => true, 'label' => $view->getTranslation('Folder Name'), 'filters' => array('StringTrim', 'StripTags'), 'validators' => array(array('NotEmpty', true), array('Regex', true, array('pattern' => Digitalus_Media::MEDIALABEL_REGEX, 'messages' => array('regexNotMatch' => Digitalus_Media::MEDIALABEL_REGEX_NOTMATCH)))))); $createFolderSubmit = $this->createElement('submit', 'createFolderSubmit', array('label' => $view->getTranslation('Create Folder'), 'attribs' => array('class' => 'submit'))); /* ********************************************************************* * RENAME FOLDER * ****************************************************************** */ $newName = $this->createElement('text', 'new_folder_name', array('required' => true, 'label' => $view->getTranslation('New Name'), 'value' => $label, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array(array('NotEmpty', true), array('Regex', true, array('pattern' => Digitalus_Media::MEDIALABEL_REGEX, 'messages' => array('regexNotMatch' => Digitalus_Media::MEDIALABEL_REGEX_NOTMATCH)))))); $renameFolderSubmit = $this->createElement('submit', 'renameFolderSubmit', array('label' => $view->getTranslation('Rename Folder'), 'attribs' => array('class' => 'submit'))); /* ********************************************************************* * PUT IT ALL TOGETHER * ****************************************************************** */ $this->addElement($currentDirectory); $this->addElement($subDirectories); $this->addElement($filePath); $this->addElement($mediapath); $this->addElement($uploads); $this->addElement($path); $this->addElement($folderName); $this->addElement($newName); $this->addElement($uploadSubmit); $this->addElement($createFolderSubmit); $this->addElement($renameFolderSubmit); $this->addDisplayGroup(array('form_instance', 'filepath', 'mediapath', 'current_directory'), 'mediaCurrentGroup', array('legend' => $view->getTranslation('Current Folder'))); $this->addDisplayGroup(array('sub_directories'), 'mediaSubDirectoriesGroup', array('legend' => $view->getTranslation('Current folder contents'))); $this->addDisplayGroup(array('uploads', 'uploadSubmit'), 'mediaUploadGroup', array('legend' => $view->getTranslation('Upload Files'))); $this->addDisplayGroup(array('path', 'folder_name', 'createFolderSubmit'), 'mediaCreateFolderGroup', array('legend' => $view->getTranslation('Create Subfolder'))); $this->addDisplayGroup(array('new_folder_name', 'renameFolderSubmit'), 'mediaRenameFolderGroup', array('legend' => $view->getTranslation('Rename Folder'))); }