function _loadData() { global $mainframe; // Lets load the content if it doesn't already exist if (empty($this->_data)) { // Lets load the content if it doesn't already exist if (empty($this->_data)) { $query = 'SELECT p.filename as filename' . ' FROM #__phocagallery AS p' . ' WHERE p.id = ' . (int) $this->_id; $this->_db->setQuery($query); $filename_object = $this->_db->loadObject(); //Get Folder settings and File resize settings $path = PhocaGalleryHelper::getPathSet(); $file = new JObject(); //Create thumbnail if it doesn't exists but originalfile must exist $orig_path = $path['orig_abs_ds']; $refresh_url = 'index.php?option=com_phocagallery&view=phocagalleryd&tmpl=component&cid[]=' . $this->_id; //Creata thumbnails if not exist PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $filename_object->filename, $refresh_url, 1, 1, 1); jimport('joomla.filesystem.file'); if (!isset($filename_object->filename)) { $file->set('linkthumbnailpath', ''); } else { $thumbnail_file = PhocaGalleryHelper::getThumbnailName($filename_object->filename, 'large'); $file->set('linkthumbnailpath', $thumbnail_file['rel']); } } if (isset($file)) { $this->_data = $file; } else { $this->_data = ''; } return (bool) $this->_data; } return true; }
function display($tpl = null) { global $mainframe; $params =& JComponentHelper::getParams('com_phocagallery'); // Do not allow cache JResponse::allowCache(false); $document =& JFactory::getDocument(); $document->addStyleSheet('../administrator/components/com_phocagallery/assets/phocagallery.css'); $document->addStyleSheet('../administrator/templates/system/css/system.css'); $document->addCustomTag("<!--[if IE]>\n<link rel=\"stylesheet\" href=\"../administrator/components/com_phocagallery/assets/phocagalleryieall.css\" type=\"text/css\" />\n<![endif]-->"); $path = PhocaGalleryHelper::getPathSet(); $path_orig_rel = $path['orig_rel_ds']; $this->assign('path_orig_rel', $path_orig_rel); $this->assignRef('folders', $this->get('folders')); $this->assignRef('state', $this->get('state')); parent::display($tpl); }
function display($tpl = null) { global $mainframe; $params =& JComponentHelper::getParams('com_phocagallery'); // Do not allow cache JResponse::allowCache(false); $document =& JFactory::getDocument(); $document->addStyleSheet('../administrator/components/com_phocagallery/assets/phocagallery.css'); $document->addStyleSheet('../administrator/templates/system/css/system.css'); $document->addCustomTag("<!--[if IE]>\n<link rel=\"stylesheet\" href=\"../administrator/components/com_phocagallery/assets/phocagalleryieall.css\" type=\"text/css\" />\n<![endif]-->"); $path = PhocaGalleryHelper::getPathSet(); $path_orig_rel = $path['orig_rel_ds']; $this->assign('path_orig_rel', $path_orig_rel); $this->assignRef('images', $this->get('images')); $this->assignRef('folders', $this->get('folders')); $this->assignRef('state', $this->get('state')); // Upload Form ------------------------------------ JHTML::_('behavior.mootools'); //$document->addScript('components/com_phocagallery/assets/upload/mediamanager.js'); $document->addStyleSheet('components/com_phocagallery/assets/upload/mediamanager.css'); // Set FTP form $ftp = !JClientHelper::hasCredentials('ftp'); // Set flash uploader if ftp password and login exists (will be not problems) $state = $this->get('state'); $refreshSite = 'index.php?option=com_phocagallery&view=phocagalleryi&tmpl=component&folder=' . $state->folder; if (!$ftp) { if ($params->get('enable_flash', 1)) { PhocaGalleryHelperUpload::uploader('file-upload', array('onAllComplete' => 'function(){ window.location.href="' . $refreshSite . '"; }')); } } // PARAMS - Upload size $upload_maxsize = 3000000; if ($params->get('upload_maxsize') != '') { $upload_maxsize = $params->get('upload_maxsize'); } // END Upload Form ------------------------------------ $this->assignRef('session', JFactory::getSession()); $this->assignRef('uploadmaxsize', $upload_maxsize); $this->assign('require_ftp', $ftp); parent::display($tpl); echo JHTML::_('behavior.keepalive'); }
function getList() { static $list; // Only process the list once per request if (is_array($list)) { return $list; } // Get current path from request $current = $this->getState('folder'); // If undefined, set to empty if ($current == 'undefined') { $current = ''; } //Get folder variables from Helper $path = PhocaGalleryHelper::getPathSet(); // Initialize variables if (strlen($current) > 0) { $orig_path = $path['orig_abs_ds'] . $current; } else { $orig_path = $path['orig_abs_ds']; } $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/'); $folders = array(); // Get the list of files and folders from the given folder $folder_list = JFolder::folders($orig_path, '', false, false, array(0 => 'thumbs')); // Iterate over the folders if they exist if ($folder_list !== false) { foreach ($folder_list as $folder) { $tmp = new JObject(); $tmp->name = basename($folder); $tmp->path_with_name = str_replace(DS, '/', JPath::clean($orig_path . DS . $folder)); $tmp->path_without_name_relative = $path['orig_rel_ds'] . str_replace($orig_path_server, '', $tmp->path_with_name); $tmp->path_with_name_relative_no = str_replace($orig_path_server, '', $tmp->path_with_name); $folders[] = $tmp; } } $list = array('folders' => $folders); return $list; }
function getList() { static $list; //Params $params =& JComponentHelper::getParams('com_phocagallery'); //Clean Thumbnails or not if ($params->get('clean_thumbnails') != '') { $clean_thumbnails = $params->get('clean_thumbnails'); } else { $clean_thumbnails = 0; } // Only process the list once per request if (is_array($list)) { return $list; } // Get current path from request $current = $this->getState('folder'); // If undefined, set to empty if ($current == 'undefined') { $current = ''; } //Get folder variables from Helper $path = PhocaGalleryHelper::getPathSet(); // Initialize variables if (strlen($current) > 0) { $orig_path = $path['orig_abs_ds'] . $current; } else { $orig_path = $path['orig_abs_ds']; } $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/'); $images = array(); $folders = array(); // Get the list of files and folders from the given folder $file_list = JFolder::files($orig_path); $folder_list = JFolder::folders($orig_path, '', false, false, array(0 => 'thumbs')); natcasesort($file_list); // Iterate over the files if they exist //file - abc.img, file_no - folder/abc.img if ($file_list !== false) { foreach ($file_list as $file) { $ext = strtolower(JFile::getExt($file)); // Don't display thumbnails from defined files (don't save them into a database)... $dontCreateThumb = PhocaGalleryHelper::dontCreateThumb($file); if ($dontCreateThumb == 1) { $ext = ''; // WE USE $ext FOR NOT CREATE A THUMBNAIL CLAUSE } if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg') { if (is_file($orig_path . DS . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') { //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&view=phocagallerym&layout=form&hidemainmenu=1&folder=' . $current; $file_no = $current . "/" . $file; $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($path['orig_abs_ds'], $file_no, $refresh_url, 0, 0, 0); $tmp = new JObject(); $tmp->name = $file_thumb['name']; $tmp->path_with_name_relative_no = $file_thumb['path_with_name_relative_no']; $tmp->linkthumbnailpath = $file_thumb['thumb_name_m_no_rel']; $images[] = $tmp; } } } } //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { PhocaGalleryHelper::cleanThumbsFolder(); } //--------------------------------------------------------------------------------------------------------------- // Iterate over the folders if they exist if ($folder_list !== false) { foreach ($folder_list as $folder) { $tmp = new JObject(); $tmp->name = basename($folder); $tmp->path_with_name = str_replace(DS, '/', JPath::clean($orig_path . DS . $folder)); $tmp->path_without_name_relative = $path['orig_rel_ds'] . str_replace($orig_path_server, '', $tmp->path_with_name); $tmp->path_with_name_relative_no = str_replace($orig_path_server, '', $tmp->path_with_name); $folders[] = $tmp; } } $list = array('folders' => $folders, 'images' => $images); return $list; }
function getFileOriginal($filename) { $path = PhocaGalleryHelper::getPathSet(); $file_original = $path['orig_abs_ds'] . $filename; //original file return $file_original; }
function store($data, $return) { //If this file doesn't exists don't save it if (!PhocaGalleryHelper::existsFileOriginal($data['filename'])) { $this->setError('File not exists'); return false; } //If there is no title and no alias, use filename as title and alias if (!isset($data['title']) || isset($data['title']) && $data['title'] == '') { $data['title'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']); } if (!isset($data['alias']) || isset($data['alias']) && $data['alias'] == '') { $data['alias'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']); } //clean alias name (no bad characters) $data['alias'] = PhocaGalleryHelper::getAliasName($data['alias']); $row =& $this->getTable('phocagallery'); // Bind the form fields to the Phoca gallery table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } // Create the timestamp for the date $row->date = gmdate('Y-m-d H:i:s'); // if new item, order last in appropriate group if (!$row->id) { $where = 'catid = ' . (int) $row->catid; $row->ordering = $row->getNextOrder($where); } // Make sure the Phoca gallery table is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the Phoca gallery table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } //Create thumbnail small, medium, large $path = PhocaGalleryHelper::getPathSet(); $returnFrontMessage = PhocaGalleryHelper::getOrCreateThumbnail($path['orig_abs_ds'], $row->filename, $return, 1, 1, 1, 1); if ($returnFrontMessage == 'Success') { return true; } else { return false; } }
function getData() { //Params $params =& JComponentHelper::getParams('com_phocagallery'); //Standard Thumbs creation or Pagination Thumbs Creation if ($params->get('pagination_thumbnail_creation') != '') { $pagination_thumbnail_creation = $params->get('pagination_thumbnail_creation'); } else { $pagination_thumbnail_creation = 0; } //Clean Thumbnails or not if ($params->get('clean_thumbnails') != '') { $clean_thumbnails = $params->get('clean_thumbnails'); } else { $clean_thumbnails = 0; } // Lets load the content if it doesn't already exist if (empty($this->_data)) { $query = $this->_buildQuery(); $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit')); } //Server doesn't have CPU power //we do thumbnail for all images - there is no pagination... //or we do thumbanil for only listed images if (empty($this->_data_thumbnail)) { if ($pagination_thumbnail_creation == 1) { $this->_data_thumbnail = $this->_data; } else { $query = $this->_buildQueryThumbnail(); $this->_data_thumbnail = $this->_getList($query); } } //------------------------------------------------------------------------------------------------------ // Check if the file stored in database is on the server. If not please refer to user // Get filename from every object there is stored in database //------------------------------------------------------------------------------------------------------ //file - abc.img, file_no - folder/abc.img //Get folder variables from Helper $path = PhocaGalleryHelper::getPathSet(); $orig_path = $path['orig_abs_ds']; $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/'); //----------------------------------------- //Do all thumbnails no limit no pagination if (!empty($this->_data_thumbnail)) { foreach ($this->_data_thumbnail as $key => $value) { $file_original_thumb = PhocaGalleryHelper::getFileOriginal($value->filename); //Let the user know that the file doesn't exists and delete all thumbnails if (!JFile::exists($file_original_thumb)) { //$this->_data[$key]->filename = JText::_( 'File does not exist' ); //$this->_data[$key]->fileoriginalexist = 0; //We must not delete the thumbnails if the file doesn't exist - we use cleanThumbsFolder() function } else { //Create thumbnails small, medium, large $refresh_url_thumb = 'index.php?option=com_phocagallery&view=phocagallerys'; //$refresh_url_thumb = 'index.php?option=com_phocagallery&controller=phocagallerys'; $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $value->filename, $refresh_url_thumb, 1, 1, 1); //$this->_data[$key]->linkthumbnailpath = $file_thumb['thumb_name_s_no_rel']; //$this->_data[$key]->path_without_name_relative = $file_thumb['path_without_name_relative']; //$this->_data[$key]->fileoriginalexist = 1; } } //Clean Thumbs Folder if there are thumbnail files but not original file //PhocaGalleryHelper::cleanThumbsFolder(); //------------------------------------------------------------------------------------------------------ } $this->_data_thumbnail = null; // delete data to reduce memory //Only the the site with limitation or pagination... if (!empty($this->_data)) { foreach ($this->_data as $key => $value) { $file_original = PhocaGalleryHelper::getFileOriginal($value->filename); //Let the user know that the file doesn't exists and delete all thumbnails if (!JFile::exists($file_original)) { $this->_data[$key]->filename = JText::_('Image Filename does not exist'); $this->_data[$key]->fileoriginalexist = 0; //We must not delete the thumbnails if the file doesn't exist - we use cleanThumbsFolder() function } else { //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&view=phocagallerys'; //$refresh_url = 'index.php?option=com_phocagallery&controller=phocagallerys'; $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $value->filename, $refresh_url, 1, 1, 1); $this->_data[$key]->linkthumbnailpath = $file_thumb['thumb_name_s_no_rel']; //$this->_data[$key]->path_without_name_relative = $file_thumb['path_without_name_relative']; $this->_data[$key]->fileoriginalexist = 1; } } //Clean Thumbs Folder if there are thumbnail files but not original file //PhocaGalleryHelper::cleanThumbsFolder(); //------------------------------------------------------------------------------------------------------ } //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { PhocaGalleryHelper::cleanThumbsFolder(); } return $this->_data; }
function _displayForm($tpl) { global $mainframe, $option; $uri =& JFactory::getURI(); $phocagallery =& $this->get('Data'); //Data from model $lists = array(); $db =& JFactory::getDBO(); $document =& JFactory::getDocument(); $params =& JComponentHelper::getParams('com_phocagallery'); JToolBarHelper::title(JText::_('Phoca gallery') . ': <small><small>[ ' . JText::_('Multiple Add') . ' ]</small></small>'); JToolBarHelper::save(); JToolBarHelper::cancel(); JToolBarHelper::help('screen.phocagallery', true); $phocagallery->published = 1; $phocagallery->order = 0; $phocagallery->catid = JRequest::getVar('catid', 0, 'post', 'int'); $phocagallery->id = 0; // build the html select list for ordering $query = 'SELECT ordering AS value, title AS text' . ' FROM #__phocagallery' . ' WHERE catid = ' . (int) $phocagallery->catid . ' ORDER BY ordering'; $lists['ordering'] = JHTML::_('list.specificordering', $phocagallery, $phocagallery->id, $query, false); //------------------------------------------------------------------------ //build the list of categories $query = 'SELECT a.title AS text, a.id AS value, a.parent_id as parentid' . ' FROM #__phocagallery_categories AS a' . ' ORDER BY a.ordering'; $db->setQuery($query); $phocagallerys = $db->loadObjectList(); $tree = array(); $text = ''; $tree = PhocaGalleryHelper::CategoryTree($phocagallerys, $tree, 0, $text); $phocagallerys_tree_array = PhocaGalleryHelper::CategoryTreeCreating($phocagallerys, $tree, 0); array_unshift($phocagallerys_tree_array, JHTML::_('select.option', '0', '- ' . JText::_('Select Category') . ' -', 'value', 'text')); //list categories $lists['catid'] = JHTML::_('select.genericlist', $phocagallerys_tree_array, 'catid', '', 'value', 'text', $phocagallery->catid); //----------------------------------------------------------------------- // build the html select list $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $phocagallery->published); //clean gallery data jimport('joomla.filter.output'); JFilterOutput::objectHTMLSafe($phocagallery, ENT_QUOTES, 'description'); $this->assignRef('lists', $lists); $this->assignRef('phocagallery', $phocagallery); $this->assignRef('button', $button); $this->assignRef('request_url', $uri->toString()); //-------------------------------------------------------------------------------------------------------- /*image manager*/ JResponse::allowCache(false); // Do not allow cache $path = PhocaGalleryHelper::getPathSet(); // Upload Form ------------------------------------ JHTML::_('behavior.mootools'); //$document->addScript('components/com_phocagallery/assets/upload/mediamanager.js'); $document->addStyleSheet('components/com_phocagallery/assets/upload/mediamanager.css'); // Set FTP form $ftp = !JClientHelper::hasCredentials('ftp'); // Set flash uploader if ftp password and login exists (will be not problems) $state = $this->get('state'); $refreshSite = 'index.php?option=com_phocagallery&view=phocagallerym&layout=form&hidemainmenu=1&folder=' . $state->folder; if (!$ftp) { if ($params->get('enable_flash', 1)) { PhocaGalleryHelperUpload::uploader('file-upload', array('onAllComplete' => 'function(){ window.location.href="' . $refreshSite . '"; }')); } } // PARAMS - Upload size $upload_maxsize = 3000000; if ($params->get('upload_maxsize') != '') { $upload_maxsize = $params->get('upload_maxsize'); } // END Upload Form ------------------------------------ $this->assignRef('session', JFactory::getSession()); $this->assignRef('uploadmaxsize', $upload_maxsize); $this->assign('require_ftp', $ftp); $this->assignRef('path_orig_rel', $path['orig_rel_ds']); $this->assignRef('images', $this->get('images')); $this->assignRef('folders', $this->get('folders')); $this->assignRef('state', $this->get('state')); parent::display($tpl); echo JHTML::_('behavior.keepalive'); }
function upload() { global $mainframe; // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); // Set FTP credentials, if given $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); $path = PhocaGalleryHelper::getPathSet(); $file = JRequest::getVar('Filedata', '', 'files', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $format = JRequest::getVar('format', 'html', '', 'cmd'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $viewBack = JRequest::getVar('viewback', '', '', ''); $err = null; // Make the filename safe if (isset($file['name'])) { $file['name'] = JFile::makeSafe($file['name']); } // All HTTP header will be overwritten with js message if (isset($file['name'])) { $filepath = JPath::clean($path['orig_abs_ds'] . $folder . DS . strtolower($file['name'])); if (!PhocaGalleryHelperUpload::canUpload($file, $err)) { if ($format == 'json') { switch ($err) { case 'WARNFILETOOLARGE': header('HTTP/1.0 413 Request Entity Too Large'); jexit('Error. The File Is Too Large!'); break; default: header('HTTP/1.0 415 Unsupported Media Type'); jexit('Error. Unsupported Media Type!'); break; } } else { JError::raiseNotice(100, JText::_($err)); // REDIRECT if ($return) { $mainframe->redirect(base64_decode($return) . '&folder=' . $folder); } return; } } if (JFile::exists($filepath)) { if ($format == 'json') { header('HTTP/1.0 409 Conflict'); jexit('Error. File already exists'); } else { JError::raiseNotice(100, JText::_('Error. File already exists')); // REDIRECT if ($return) { $mainframe->redirect(base64_decode($return) . '&folder=' . $folder); } return; } } if (!JFile::upload($file['tmp_name'], $filepath)) { if ($format == 'json') { header('HTTP/1.0 406 Not Acceptable'); jexit('Error. Unable to upload file'); } else { JError::raiseWarning(100, JText::_('Error. Unable to upload file')); // REDIRECT if ($return) { $mainframe->redirect(base64_decode($return) . '&folder=' . $folder); } return; } } else { if ($format == 'json') { header('HTTP/1.0 400'); // With 400 error will be not displayed (?? - ok) jexit('Upload complete'); } else { $mainframe->enqueueMessage(JText::_('Phoca Gallery, Upload complete')); // REDIRECT if ($return) { $mainframe->redirect(base64_decode($return) . '&folder=' . $folder); } return; } } } else { $msg = JTEXT::_('WARNFILETYPE'); if ($format == 'json') { header('HTTP/1.0 415 Unsupported Media Type'); jexit('Error. Unable to upload file'); } else { if ($return) { $mainframe->redirect(base64_decode($return) . '&folder=' . $folder, $msg); } else { switch ($viewBack) { case 'phocagalleryi': $mainframe->redirect('index.php?option=com_phocagallery&view=phocagalleryi&tmpl=component&folder=' . $folder, $msg); break; case 'phocagallerym': $mainframe->redirect('index.php?option=com_phocagallery&view=phocagallerym&layout=form&hidemainmenu=1&folder=' . $folder, $msg); break; default: $mainframe->redirect('index.php?option=com_phocagallery', $msg); break; } } } } }
function piclens($cids) { $db =& JFactory::getDBO(); $path = PhocaGalleryHelper::getPathSet(); $paramsC = JComponentHelper::getParams('com_phocagallery'); // PARAMS $piclens_image = $paramsC->get('piclens_image', 1); if (JFolder::exists($path['orig_abs_ds'])) { foreach ($cids as $kcid => $vcid) { $this->setXMLFile(); if (!$this->_XMLFile) { $this->setError('Could not create XML builder'); return false; } if (!($node = $this->_XMLFile->createElement('rss'))) { $this->setError('Could not create node!'); return false; } $node->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss'); $node->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); $node->setAttribute('version', '2.0'); $this->_XMLFile->setDocumentElement($node); if (!($root =& $this->_XMLFile->documentElement)) { $this->setError('Could not obtain root element!'); return false; } $channel =& $this->_XMLFile->createElement('channel'); $atomIcon =& $this->_XMLFile->createElement('atom:icon'); $atomIcon->setText('http://www.phoca.cz/images/phoca-piclens.png'); $channel->appendChild($atomIcon); $query = 'SELECT a.id AS id, a.title AS title, a.filename AS filename FROM #__phocagallery AS a' . ' WHERE a.catid = ' . (int) $vcid . ' AND a.published = 1' . ' ORDER BY a.catid, a.ordering'; $db->setQuery($query); $rows = $db->loadObjectList(); foreach ($rows as $krow => $vrow) { $file = PhocaGalleryHelper::getOrCreateThumbnail('', $vrow->filename, ''); $orig_file = str_replace("../", "", $file['path_with_name_relative']); $orig_file = str_replace("//", "/", $orig_file); $thumb_name_l_no_rel = str_replace("../", "", $file['thumb_name_l_no_rel']); $thumb_name_l_no_rel = str_replace("//", "/", $thumb_name_l_no_rel); $juri_base = str_replace("administrator", "", JURI::base(true)); $thumb_image_path = $juri_base . $thumb_name_l_no_rel; $orig_file_path = $juri_base . $orig_file; $item =& $this->_XMLFile->createElement('item'); $item->appendChild($this->_buildXMLElement('title', $vrow->title)); $item->appendChild($this->_buildXMLElement('link', $thumb_image_path)); $thumbnail =& $this->_XMLFile->createElement('media:thumbnail'); $thumbnail->setAttribute('url', $thumb_image_path); $content =& $this->_XMLFile->createElement('media:content'); if ($piclens_image == 1) { $content->setAttribute('url', $thumb_image_path); } else { $content->setAttribute('url', $orig_file_path); } $item->appendChild($thumbnail); $item->appendChild($content); $guid =& $this->_XMLFile->createElement('guid'); $guid->setText($vcid . '-phocagallerypiclenscode-' . $vrow->filename); $guid->setAttribute('isPermaLink', "false"); $item->appendChild($guid); $channel->appendChild($item); } $root->appendChild($channel); $this->_XMLFile->setXMLDeclaration('<?xml version="1.0" encoding="utf-8" standalone="yes"?>'); //echo $this->_XMLFile->toNormalizedString( true );exit; // saveXML_utf8 doesn't save setXMLDeclaration if (!$this->_XMLFile->saveXML($path['orig_abs_ds'] . DS . $vcid . '.rss', true)) { $this->setError('Could not save XML file!'); return false; } } return true; } else { $this->setError('Phoca Gallery image folder not exists'); } }
function upload() { global $mainframe; // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); // Set FTP credentials, if given jimport('joomla.client.helper'); $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); $user =& JFactory::getUser(); $path = PhocaGalleryHelper::getPathSet(); $file = JRequest::getVar('Filedata', '', 'files', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $tab = JRequest::getVar('tab', 0, '', 'int'); $format = JRequest::getVar('format', 'html', '', 'cmd'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $viewBack = JRequest::getVar('viewback', '', '', ''); $err = null; $view = JRequest::getVar('view', '', 'get', '', JREQUEST_NOTRIM); $catid = JRequest::getVar('id', '', 'get', 'string', JREQUEST_NOTRIM); //$catid = JRequest::getVar( 'catid', '', 'post', 'string', JREQUEST_NOTRIM ); $Itemid = JRequest::getVar('Itemid', 0, '', 'int'); $limitStart = JRequest::getVar('limitstart', 0, '', 'int'); $paramsC = JComponentHelper::getParams('com_phocagallery'); $catidAlias = $catid; // for return // Set the limistart (TODO) if ($limitStart > 0) { $limitStartUrl = '&limitstart=' . $limitStart; } else { $limitStartUrl = ''; } // From which view the image is uploaded switch ($view) { case 'user': // UCP is disabled (security reasons) $enable_user_cp = $paramsC->get('enable_user_cp', 0); if ($enable_user_cp == 0) { $mainframe->redirect(JURI::base(true), JText::_("User Control Panel is disabled")); exit; } $return = JRoute::_('index.php?option=com_phocagallery&view=user&tab=' . $tab . '&Itemid=' . $Itemid, false); // Get user catid, we are not in the category, so we must find the catid $modelUser = $this->getModel('user'); $userCatId = $modelUser->getUserCategory($user->id); // User has no category, he (she) can create one if (!empty($userCatId->categoryid)) { $catid = $userCatId->categoryid; } else { $mainframe->redirect($return, JText::_('Error Uploading Phoca Gallery User Control Image')); exit; } break; case 'category': default: $return = JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $catidAlias . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false); break; } $model = $this->getModel('category'); // USER RIGHT - UPLOAD ======================================== // 2, 2 means that user access will be ignored in function getUserRight for display Delete button $rightDisplayUpload = 0; $catParams = $model->getCategoryParams((int) $catid); if (isset($catParams->params)) { $rightDisplayUpload = PhocaGalleryHelper::getUserRight($catParams->params, 'uploaduserid', 2, 2, $user->get('id', 0), 0); } // ============================================================ // USER RIGHT - FOLDER ======================================== $rightFolder[0] = ''; if (isset($catParams->params)) { $rightFolder = PhocaGalleryHelper::getParamsArray($catParams->params, 'userfolder'); } // ============================================================ if ($rightDisplayUpload == 1) { if ($rightFolder[0] == '') { $mainframe->redirect($return, JText::_('User Folder Not Defined')); } if (!JFolder::exists($path['orig_abs_ds'] . $rightFolder[0] . DS)) { $mainframe->redirect($return, JText::_('Defined User Folder Does Not Exist')); } // Check if the size will be not over the category folder size jimport('joomla.filesystem.folder'); $path = PhocaGalleryHelper::getPathset(); $catPath = $path['orig_abs_ds'] . $rightFolder[0] . DS; $files = JFolder::files($catPath); // Get size of all images in the folder $allFileSize = 0; foreach ($files as $fileInFolder) { $fileSize = PhocaGalleryHelperFront::getFileSizePhoca($rightFolder[0] . DS . $fileInFolder, 0); $allFileSize = $allFileSize + (int) $fileSize; } // Get the size of all images include new uploaded image in Bytes if (isset($file['size'])) { $allFileSize = $allFileSize + (int) $file['size']; } $maxFolderSize = (int) $paramsC->get('cat_folder_maxsize', 20000000); if ($maxFolderSize > 0 && (int) $allFileSize > $maxFolderSize) { $mainframe->redirect($return, JText::_('WARNFILETOOLARGEFOLDER')); } // Make the filename safe if (isset($file['name'])) { $file['name'] = JFile::makeSafe($file['name']); } if (isset($file['name'])) { $filepath = JPath::clean($path['orig_abs_ds'] . $rightFolder[0] . DS . $file['name']); if (!PhocaGalleryHelperUpload::canUpload($file, $err)) { $mainframe->redirect($return, JText::_($err)); exit; } if (JFile::exists($filepath)) { $mainframe->redirect($return, JText::_('File already exists')); exit; } if (!JFile::upload($file['tmp_name'], $filepath)) { $mainframe->redirect($return, JText::_('Unable to upload file')); exit; } else { // Saving file name into database with relative path $file['name'] = $rightFolder[0] . '/' . $file['name']; PhocaGalleryController::save((int) $catid, $file['name'], $return); //$mainframe->redirect($return,JText::_('Upload complete')); //exit; } } else { $mainframe->redirect($return, JText::_('WARNFILETYPE')); exit; } } else { $mainframe->redirect(JRoute::_('index.php?option=com_user&view=login', false), JText::_("NOT AUTHORISED TO DO ACTION")); exit; } }
function store($data) { //Params $params =& JComponentHelper::getParams('com_phocagallery'); //Clean Thumbnails or not if ($params->get('clean_thumbnails') != '') { $clean_thumbnails = $params->get('clean_thumbnails'); } else { $clean_thumbnails = 0; } //If this file doesn't exists don't save it if (!PhocaGalleryHelper::existsFileOriginal($data['filename'])) { $this->setError(); return false; } //If there is no title and no alias, use filename as title and alias if ($data['title'] == '') { $data['title'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']); } if ($data['alias'] == '') { $data['alias'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']); } //clean alias name (no bad characters) $data['alias'] = PhocaGalleryHelper::getAliasName($data['alias']); $row =& $this->getTable(); // Bind the form fields to the Phoca gallery table if (!$row->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } // Create the timestamp for the date $row->date = gmdate('Y-m-d H:i:s'); // if new item, order last in appropriate group if (!$row->id) { $where = 'catid = ' . (int) $row->catid; $row->ordering = $row->getNextOrder($where); } // Make sure the Phoca gallery table is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the Phoca gallery table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } //------------------------------------------------------------------------------------------------------ //Create thumbnail small, medium, large //------------------------------------------------------------------------------------------------------ //file - abc.img, file_no - folder/abc.img //Get folder variables from Helper $path = PhocaGalleryHelper::getPathSet(); $orig_path = $path['orig_abs_ds']; //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&controller=phocagallery&task=thumbs'; $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $row->filename, $refresh_url, 1, 1, 1); //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { PhocaGalleryHelper::cleanThumbsFolder(); } //--------------------------------------------------------------------------------------------------------------- return true; }