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 _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 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; } }