public function connector() { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $path = SigProHelper::getPath('site'); $url = SigProHelper::getHTTPPath($path); JPath::check($path); include_once JPATH_COMPONENT_ADMINISTRATOR . '/js/elfinder/php/elFinderConnector.class.php'; include_once JPATH_COMPONENT_ADMINISTRATOR . '/js/elfinder/php/elFinder.class.php'; include_once JPATH_COMPONENT_ADMINISTRATOR . '/js/elfinder/php/elFinderVolumeDriver.class.php'; include_once JPATH_COMPONENT_ADMINISTRATOR . '/js/elfinder/php/elFinderVolumeLocalFileSystem.class.php'; function access($attr, $path, $data, $volume) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); // Hide files and folders starting with . if (strpos(basename($path), '.') === 0 && $attr == 'hidden') { return true; } // Read only access for front-end. Full access for administration section. switch ($attr) { case 'read': return true; break; case 'write': if ($mainframe->isSite()) { return false; } else { return version_compare(JVERSION, '1.6.0', 'ge') ? $user->authorise('core.create', 'com_sigpro') && $user->authorise('core.edit', 'com_sigpro') && $user->authorise('core.delete', 'com_sigpro') : true; } break; case 'locked': if ($mainframe->isSite()) { return true; } else { return version_compare(JVERSION, '1.6.0', 'ge') ? !($user->authorise('core.create', 'com_sigpro') && $user->authorise('core.edit', 'com_sigpro') && $user->authorise('core.delete', 'com_sigpro')) : false; } break; case 'hidden': return false; break; } } if ($mainframe->isAdmin()) { if (version_compare(JVERSION, '1.6.0', 'ge')) { $write = $user->authorise('core.create', 'com_sigpro') && $user->authorise('core.edit', 'com_sigpro') && $user->authorise('core.delete', 'com_sigpro'); } else { $write = true; } $permissions = array('read' => true, 'write' => $write); } else { $permissions = array('read' => true, 'write' => false); } $options = array('roots' => array(array('driver' => 'LocalFileSystem', 'path' => $path, 'URL' => $url, 'accessControl' => 'access', 'defaults' => $permissions))); $connector = new elFinderConnector(new elFinder($options)); $connector->run(); }
public function upload() { jimport('joomla.filesystem.file'); $file = $this->getState('file'); $filename = $this->getState('filename'); $response = array('status' => 0, 'error' => ''); //Check if file is uploaded if (is_null($file) || !is_uploaded_file($file['tmp_name'])) { $response['error'] = JText::_('COM_SIGPRO_FILE_WAS_NOT_UPLOADED'); } elseif (!($info = @getimagesize($file['tmp_name']))) { $response['error'] = JText::_('COM_SIGPRO_FILE_IS_NOT_AN_IMAGE'); } elseif (!in_array($info[2], array(1, 2, 3, 7, 8))) { $response['error'] = JText::_('COM_SIGPRO_THIS_IMAGE_IS_NOT_SUPPORTED'); } else { $type = $this->getState('type'); $folder = $this->getState('folder'); $path = SigProHelper::getPath($type); if ($folder && JFolder::exists($path . '/' . $folder)) { $result = JFile::upload($file['tmp_name'], $path . '/' . $folder . '/' . JFile::makeSafe($filename)); if ($result) { $response['status'] = 1; $response['name'] = JFile::makeSafe($filename); $response['width'] = $info[0]; $response['height'] = $info[1]; $response['mime'] = $info['mime']; $response['size'] = round(filesize($path . '/' . $folder . '/' . JFile::makeSafe($filename)) / 1024, 2); $httpPath = SigProHelper::getHTTPPath($path . '/' . $folder); $response['path'] = $httpPath . '/' . $response['name']; $response['url'] = SigProHelper::getImageURL($response['path']); } else { $response['error'] = JText::_('COM_SIGPRO_COULD_NOT_UPLOAD_FILE'); } } else { $response['error'] = JText::_('COM_SIGPRO_TARGET_FOLDER_DOES_NOT_EXIST'); } } return $response; }
public function getData() { $path = SigProHelper::getPath($this->getState('type')); $galleries = array(); if (!JFolder::exists($path)) { $this->setState('total', 0); return $galleries; } $folders = JFolder::folders($path, '.', true, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX')); foreach ($folders as $folder) { $basename = basename($folder); if (JString::strpos($basename, '.') === 0) { continue; } $images = JFolder::files($folder, '.jpg|.jpeg|.png|.gif|.JPG|.JPEG|.PNG|.GIF'); $files = JFolder::files($folder, '.txt'); $labels = false; foreach ($files as $file) { if (JString::strpos($file, 'labels.txt') !== false) { $labels = true; } } if (count($images) || $labels) { $relativeFolder = JString::str_ireplace(array($path . DIRECTORY_SEPARATOR, $path . '/'), '', $folder); // Replace forward slashes when we are under Windows Servers $relativeFolder = JString::str_ireplace(DIRECTORY_SEPARATOR, '/', $relativeFolder); $gallery = new JObject(); $gallery->set('folder', $relativeFolder); $gallery->set('insertPath', $relativeFolder); $application = JFactory::getApplication(); if ($application->isSite() && $this->getState('type') == 'site') { $user = JFactory::getUser(); if (version_compare(JVERSION, '2.5', 'ge')) { $isAdmin = $user->authorise('core.admin', 'com_sigpro'); } else { $isAdmin = $user->gid == 25; } if (!$isAdmin) { $gallery->set('insertPath', '/media/jw_sigpro/users/' . SigProHelper::getUserFolder() . '/' . $relativeFolder); } } $gallery->set('path', SigProHelper::getHTTPPath($folder)); $gallery->set('title', basename($folder)); $gallery->set('titleLower', JString::strtolower($gallery->get('title'))); $gallery->set('images', $images); $gallery->set('created', filemtime($folder)); if (count($images)) { $preview = SigProHelper::getHTTPPath($folder . '/' . $images[0]); $url = SigProHelper::getImageURL($preview); } else { $url = JURI::root(true) . '/administrator/components/com_sigpro/images/unavailable.png'; } $gallery->set('preview', $url); $gallery->set('url', $url); $link = 'index.php?option=com_sigpro&view=gallery&type=' . $this->getState('type', 'site') . '&folder=' . $gallery->folder . '&tmpl=' . JRequest::getCmd('tmpl', 'index') . '&editorName=' . JRequest::getCmd('editorName'); $template = JRequest::getCmd('template'); if ($template) { $link .= '&template=' . $template; } $gallery->set('link', JRoute::_($link)); $gallery->set('numOfImages', count($gallery->images)); $gallery->set('checked_out', ''); $galleries[JString::strtolower($folder)] = $gallery; } } $this->setState('total', count($galleries)); $galleries = $this->sortGalleries($galleries); if ($this->getState('limit')) { $galleries = array_slice($galleries, $this->getState('limitstart'), $this->getState('limit'), true); } if ($this->getState('type') == 'k2') { $db = JFactory::getDBO(); $ItemIds = array(); foreach ($galleries as $gallery) { $ItemIds[] = $gallery->title; } JArrayHelper::toInteger($ItemIds); $ItemIds = array_filter($ItemIds); if (count($ItemIds)) { $db->setQuery("SELECT id, title FROM #__k2_items WHERE id IN (" . implode(',', $ItemIds) . ")"); $items = $db->loadObjectList(); foreach ($items as $item) { foreach ($galleries as $gallery) { if ($gallery->title == $item->id) { $gallery->title = $item->title; } } } } } return $galleries; }