/** * */ public function link($label, $link, $icon = null, $class = 'link', $target = null, $suppressLabel = false, $translate = true) { $this->link = Digitalus_Toolbox_String::stripLeading('/', $link); $this->baseUrl = Digitalus_Toolbox_String::stripLeading('/', $this->view->getBaseUrl()); // clean the link if ($this->isRemoteLink($link) || $this->isAnchorLink($link)) { $cleanLink = $link; } else { $cleanLink = '/' . $this->addBaseUrl($this->link); } if ($target != null) { $target = 'target="' . $target . '"'; } $linkParts[] = '<a href="' . $cleanLink . '" class="' . $class . '" ' . $target . '>'; if (null !== $icon) { $linkParts[] = $this->getIcon($icon, $label); } if (!empty($label) && true != $suppressLabel) { if (true === (bool) $translate) { $linkParts[] = $this->view->getTranslation((string) $label); } else { $linkParts[] = (string) $label; } } $linkParts[] = '</a>'; return implode(null, $linkParts); }
/** * 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; }
public function removeCacheFormPath($path, $option = Zend_Cache::CLEANING_MODE_MATCHING_TAG) { $path = Digitalus_Toolbox_String::stripLeading('/', $path); $path = Digitalus_Toolbox_Regex::stripTrailingSlash($path); $path = Digitalus_Toolbox_String::addUnderscores($path); self::$_cache->clean($option, array($path)); }
/** * 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 static function getCurrentPageName($onlyLast = true) { $uri = new Digitalus_Uri(); $uriString = $uri->toString(); if (true === $onlyLast) { return Digitalus_Toolbox_String::getSelfFromPath($uriString); } return Digitalus_Toolbox_String::stripLeading('/', $uriString); }
public function hasAccess($tab) { if ($this->currentUser) { if ($this->currentUser->role == Model_User::SUPERUSER_ROLE) { return true; } else { $tab = Digitalus_Toolbox_String::stripLeading("/", $tab); $tab = str_replace("/", "_", $tab); if ($this->userModel->queryPermissions($tab)) { return true; } } } }
public static function upload($file, $path, $filename = null, $createPath = true, $base = '.') { $view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view; $e = new Digitalus_View_Error(); if ($file['error'] == 4 || empty($file['name'])) { return; } if (self::isAllowed($file['type'])) { $path = self::getMediaPath($path); //default to the name on the client machine if (is_null($filename)) { $filename = $file['name']; } $filename = str_replace('_', '-', $filename); $filename = str_replace(' ', '-', $filename); $path = str_replace(self::rootDirectory(), '', $path); $path = Digitalus_Toolbox_String::stripUnderscores($path); $path = Digitalus_Toolbox_String::stripLeading('/', $path); /* * This fixes an issue when the system is installed on a path other than * root. Path should contain a path that is relative to the (cms) root * index.php (not root to the public_html of the web server (as it was trying * to do before). */ $config = Zend_Registry::get('config'); $path = $config->filepath->media . '/' . $path; if ($createPath) { //attempt to create the new path Digitalus_Filesystem_Dir::makeRecursive($base, $path); } //clean the filename $filename = Digitalus_Filesystem_File::cleanFilename($filename); $filename = basename($filename); $path .= '/' . $filename; if (move_uploaded_file($file['tmp_name'], $path)) { //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($base . '/', $path); return $fullPath; } else { $e->add($view->getTranslation('An error occurred uploading the file' . ': ' . $file['name'])); } } else { $e->add($view->getTranslation('This filetype is not allowed' . ': ' . $file['type'])); } }
public function RenderListIcons($dir, $name) { $cache = Digitalus_Cache_Manager::getInstance(); $key = "{$dir}/{$name}"; if (($data = $cache->loadCache($key)) != false) { return $data; } $arr_files = Digitalus_Filesystem_File::getFilesByType($dir, array('png', 'jpg', 'gif')); $dir = Digitalus_Toolbox_String::stripLeading(BASE_PATH, $dir); $data = " <input type='radio' value='' name='{$name}'/> Empty "; foreach ($arr_files as $icon_file) { $data .= " <span><input type='radio' value='{$icon_file}' name='admin_menu_img'/> "; $data .= "<img src='{$dir}/{$icon_file}' alt='{$icon_file}'/></span> "; } $cache->saveCache($data, $key); return $data; }
/** * explode url * return : * Array ( [url_key] => admin_menu_index [module] => admin [controller] => menu [action] => index [params] => Array ( [key_1] => value_1 [key_2] => value_2 [key_3] => value_3 ) ) * */ public function ExplodeUrl($url) { $result = array(); $url = Digitalus_Toolbox_String::stripLeading($this->view->getBaseUrl() . '/', $url); $array_url = explode('/', $url); $result['url_key'] = ''; $result['base_url'] = $this->view->getBaseUrl(); $result['module'] = array_shift($array_url); $result['controller'] = array_shift($array_url); $result['action'] = array_shift($array_url); $result['url_key'] = $result['module'] . '_' . $result['controller'] . '_' . $result['action']; $params = array(); while ($key = array_shift($array_url)) { $params[$key] = array_shift($array_url); } $result['params'] = $params; return $result; }
public static function upload($file, $path, $filename, $createPath = true, $base = '.') { if (self::isAllowed($file['type'])) { $path = self::getMediaPath($path); //default to the name on the client machine if ($filename == null) { $filename = $file['name']; } $filename = str_replace('_', '-', $filename); $filename = str_replace(' ', '-', $filename); $path = str_replace(self::rootDirectory(), '', $path); $path = Digitalus_Toolbox_String::stripUnderscores($path); $path = Digitalus_Toolbox_String::stripLeading('/', $path); /* * Update by Brad Seefeld on May 12, 2009 * * This fixes an issue when the system is installed on a path other than * root. Path should contain a path that is relative to the (cms) root * index.php (not root to the public_html of the web server (as it was trying * to do before). */ $config = Zend_Registry::get('config'); $path = $config->filepath->media . '/' . $path; if ($createPath) { //attempt to create the new path Digitalus_Filesystem_Dir::makeRecursive($base, $path); } //clean the filename $filename = Digitalus_Filesystem_File::cleanFilename($filename); $filename = basename($filename); $path .= '/' . $filename; if (move_uploaded_file($file['tmp_name'], $path)) { //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($base . '/', $path); return $fullPath; } } }
/** * */ public function link($label, $link, $icon = null, $class = 'link', $target = null) { $this->link = Digitalus_Toolbox_String::stripLeading('/', $link); $this->baseUrl = Digitalus_Toolbox_String::stripLeading('/', $this->view->getBaseUrl()); // clean the link if ($this->isRemoteLink($link) || $this->isAnchorLink($link)) { $cleanLink = $link; } else { $cleanLink = '/' . $this->addBaseUrl($this->link); } if ($target != null) { $target = "target='{$target}'"; } $linkParts[] = "<a href='{$cleanLink}' class='{$class}' {$target}>"; if (null !== $icon) { $linkParts[] = $this->getIcon($icon, $label); } if (!empty($label)) { $linkParts[] = $this->view->getTranslation((string) $label); } $linkParts[] = '</a>'; return implode(null, $linkParts); }
/** * replaces underscores with slashes * if relative is true then return the path as relative * * @param string $string * @param bool $relative * @return string */ public static function stripUnderscores($string, $relative = false) { $string = str_replace('_', '/', trim($string)); if ($relative) { $string = Digitalus_Toolbox_String::stripLeading('/', $string); } $string = str_replace(self::UNDERSCORE, '_', $string); return $string; }
public static function hasAccess($path) { $userModel = new self(); $user = $userModel->getCurrentUser(); if ($user->role == Model_User::SUPERUSER_ROLE) { return true; } else { $path = Digitalus_Toolbox_String::stripLeading("/", $path); $path = str_replace("/", "_", $path); if ($userModel->queryPermissions($path)) { return true; } else { return false; } } }
/** * uploads the selected file (the key is the name of the files control) * if successfull then it resizes the images, creating a thumbnail and a full size image * if then removes the source file * * @param string $key */ public function uploadImage($key, $filename = false, $subdir = null, $resize = true, $makeThumb = true, $thumbWidth = null, $fullWidth = null) { //try to upload the file if ($subdir !== null) { $path = Digitalus_Toolbox_String::stripLeading('/', $subdir); } else { $path = self::IMAGE_PATH; } $upload = parent::upload($key, $path, $filename); if ($upload) { if ($resize == true) { //make the full sized image if ($fullWidth == null) { $fullWidth = self::FULL_WIDTH; } $this->fullPath = $this->resize($upload, $fullWidth, 'full_'); } else { $this->fullPath = $upload; } if ($makeThumb) { //make the thumbnail if ($thumbWidth == null) { $thumbWidth = self::THUMB_WIDTH; } $this->thumbPath = $this->resize($upload, $thumbWidth, 'thumb_'); } if ($resize == true) { //remove the source file unlink($upload); } } }
/** * 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; }