Esempio n. 1
0
 function createsubcategory()
 {
     JRequest::checkToken() or jexit('Invalid Token');
     $task = $this->input->get('task', '', 'string');
     $post['title'] = $this->input->get('subcategoryname', '', 'string');
     $post['description'] = $this->input->get('phocagallerycreatesubcatdescription', '', 'string');
     $post['parent_id'] = $this->input->get('parentcategoryid', 0, 'int');
     $task = $this->input->get('task', '', 'string');
     $post['title'] = $this->input->get('subcategoryname', '', 'string');
     $post['description'] = $this->input->get('phocagallerycreatesubcatdescription', '', 'string');
     $post['parent_id'] = $this->input->get('parentcategoryid', 0, 'int');
     $catid = $this->input->get('catid', '', 'string');
     $tab = $this->input->get('tab', 0, 'int');
     $Itemid = $this->input->get('Itemid', 0, 'int');
     $limitStart = $this->input->get('limitstart', 0, 'int');
     $catid = (int) $catid;
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000);
     $enableUserSubCatApprove = $paramsC->get('enable_usersubcat_approve', 0);
     $enableDirectSubCat = $paramsC->get('enable_direct_subcat', 0);
     $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar);
     $post['alias'] = $post['title'];
     //PhocaGalleryText::getAliasName($post['title']);
     $post['aliasfolder'] = PhocaGalleryText::getAliasName($post['title']);
     $model = $this->getModel('user');
     $userSubCatCount = $paramsC->get('user_subcat_count', 5);
     $user = JFactory::getUser();
     $post['approved'] = 0;
     $id = $catid;
     if ($enableUserSubCatApprove == 0) {
         $post['approved'] = 1;
     }
     if ($limitStart > 0) {
         $limitStartUrl = '&limitstart=' . $limitStart;
     } else {
         $limitStartUrl = '';
     }
     // Lang
     $userLang = PhocaGalleryUser::getUserLang();
     $post['language'] = $userLang['lang'];
     $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels();
     $access = PhocaGalleryAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels);
     $app = JFactory::getApplication();
     // USER IS NOT LOGGED
     if (!$access) {
         $app->enqueueMessage($this->_loginstr);
         $app->redirect($this->_loginurl);
         exit;
     }
     if ($enableDirectSubCat != 1) {
         $msg = JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION');
         $app->enqueueMessage($msg);
         $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false));
         return;
     }
     if ((int) $post['parent_id'] < 1) {
         $msg = JText::_('COM_PHOCAGALLERY_PARENT_CATEGORY_NOT_SELECTED');
         $app->enqueueMessage($msg);
         $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false));
         return;
     }
     // $isOwnerCategory 			= $model->isOwnerCategory($this->_user->id, (int)$post['parent_id']);
     // $limitStartUrl 				= $this->getLimitStartUrl(0, 'subcat', (int)$isOwnerCategory );
     // if(!$isOwnerCategory) {
     // $msg = JText::_( 'COM_PHOCAGALLERY_PARENT_CATEGORY_NOT_ASSIGNED_TO_USER' );
     // $app->redirect(JRoute::_($this->_url. $limitStartUrl->subcat . $limitStartUrl->image, false), $msg);
     // exit;
     // }
     $subCatCount = $model->getCountUserSubCat($user->id);
     $subCatCount = (int) $subCatCount + 1;
     if ((int) $subCatCount > (int) $userSubCatCount) {
         $msg = JText::_('COM_PHOCAGALLERY_MAX_SUBCAT_COUNT_REACHED');
         $app->enqueueMessage($msg);
         $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false));
         return;
     }
     $ownerMainCategory = $model->getOwnerMainCategory($user->id);
     if (!$ownerMainCategory) {
         // - - - - -
         // NEW
         // - - - - -
         $msg = '';
         // Create an user folder on the server
         $userFolder = PhocaGalleryText::getAliasName($user->username) . '-' . substr($post['aliasfolder'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4);
         $errorMsg = '';
         $createdFolder = PhocaGalleryFileFolder::createFolder($userFolder, $errorMsg);
         if ($errorMsg != '') {
             $msg = JText::_('COM_PHOCAGALLERY_ERROR_FOLDER_CREATING') . ': ' . JText::_($errorMsg);
             $app->enqueueMessage($msg);
             $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&tab=' . $tab . '&Itemid=' . $Itemid . $limitStartUrl, false));
             return false;
         }
     } else {
         $userFolder = $ownerMainCategory->userfolder;
     }
     if ($post['title'] != '') {
         $post['access'] = 0;
         $post['image_position'] = 'left';
         $post['published'] = 1;
         $post['accessuserid'] = '-1';
         $post['uploaduserid'] = $user->id;
         $post['deleteuserid'] = $user->id;
         $post['userfolder'] = $userFolder;
         $post['owner_id'] = $user->id;
         $id = $model->store($post);
         if ($id && $id > 0) {
             $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_CREATING_CATEGORY');
         } else {
             $msg = JText::_('COM_PHOCAGALLERY_ERROR_CREATING_CATEGORY');
         }
     } else {
         $msg = JText::_('COM_PHOCAGALLERY_ERROR_TITLE');
     }
     $app->enqueueMessage($msg);
     $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $id . '&Itemid=' . $Itemid . $limitStartUrl, false));
 }
Esempio n. 2
0
 function createcategory()
 {
     $app = JFactory::getApplication();
     JRequest::checkToken() or jexit('Invalid Token');
     $task = JRequest::getVar('task', '', 'post', 'string', 0);
     $post['title'] = JRequest::getVar('categoryname', '', 'post', 'string', 0);
     $post['description'] = JRequest::getVar('phocagallerycreatecatdescription', '', 'post', 'string', 0);
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000);
     $enableUserCatApprove = (int) $paramsC->get('enable_usercat_approve', 0);
     $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar);
     $post['alias'] = $post['title'];
     //PhocaGalleryText::getAliasName($post['title']);
     $post['aliasfolder'] = PhocaGalleryText::getAliasName($post['title']);
     $post['approved'] = 0;
     if ($enableUserCatApprove == 0) {
         $post['approved'] = 1;
     }
     // Lang
     $userLang = PhocaGalleryUser::getUserLang();
     $post['language'] = $userLang['lang'];
     /*
     		switch ($this->tmpl['userucplang']){
     			
     			case 2:
     				$registry = new JRegistry;
     				$registry->loadJSON($user->params);
     				$lang = $registry->get('language','*');
     				$this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="'.$lang.'" />';
     			break;
     			
     			case 3:
     				$lang = JFactory::getLanguage()->getTag();
     				$this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="*" />';
     			break;
     			
     			default:
     			case 1:
     				$this->tmpl['userucplangvalue'] = '<input type="hidden" name="language" value="*" />';
     			break;
     		}*/
     $limitStartUrl = new JObject();
     $limitStartUrl->subcat = '&limitstartsubcat=' . $this->_limitstartsubcat;
     $limitStartUrl->image = '&limitstartsubcat=' . $this->_limitstartimage;
     $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels();
     $access = PhocaGalleryAccess::isAccess($this->_user->authorisedLevels(), $neededAccessLevels);
     // user is logged in
     if ($access) {
         if ($post['title'] != '') {
             $model = $this->getModel('user');
             // Owner can have only one main category - check it
             $ownerMainCategory = $model->getOwnerMainCategory($this->_user->id);
             // User has no category, he (she) can create one
             if (!$ownerMainCategory) {
                 // - - - - -
                 // NEW
                 // - - - - -
                 $msg = '';
                 // Create an user folder on the server
                 $this->_userFolder = PhocaGalleryText::getAliasName($this->_user->username) . '-' . substr($post['aliasfolder'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4);
                 $errorMsg = '';
                 $createdFolder = PhocaGalleryFileFolder::createFolder($this->_userFolder, $errorMsg);
                 if ($errorMsg != '') {
                     $msg = JText::_('COM_PHOCAGALLERY_ERROR_FOLDER_CREATING') . ': ' . JText::_($errorMsg);
                 }
                 // -----------------------------------
                 // Folder Created, all right
                 if ($msg == '') {
                     // Set default values
                     $post['access'] = 0;
                     //$post['access'] 		= 1;
                     $post['parent_id'] = 0;
                     $post['image_position'] = 'left';
                     $post['published'] = 1;
                     $post['accessuserid'] = '-1';
                     $post['uploaduserid'] = $this->_user->id;
                     $post['deleteuserid'] = $this->_user->id;
                     $post['userfolder'] = $this->_userFolder;
                     $post['owner_id'] = $this->_user->id;
                     // Create new category
                     $id = $model->store($post);
                     if ($id && $id > 0) {
                         $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_SAVING_CATEGORY');
                         $errUploadMsg = '';
                         $succeeded = '';
                         PhocaGalleryControllerUser::saveUser('', $succeeded, $errUploadMsg);
                         //$msg .= '<br />' . $errUploadMsg;
                     } else {
                         $msg = JText::_('COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY');
                     }
                 }
             } else {
                 if ($post['title'] != '') {
                     // - - - - -
                     // EDIT
                     // - - - - -
                     $post['id'] = $ownerMainCategory->id;
                     $id = $model->store($post);
                     if ($id && $id > 0) {
                         $msg = JText::_('COM_PHOCAGALLERY_SUCCESS_SAVING_CATEGORY');
                     } else {
                         $msg = JText::_('COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY');
                     }
                 }
             }
         } else {
             $msg = JText::_('COM_PHOCAGALLERY_ERROR_TITLE');
         }
         $this->setRedirect(JRoute::_($this->_url . $limitStartUrl->subcat . $limitStartUrl->image, false), $msg);
     } else {
         $app = JFactory::getApplication();
         $app->redirect($this->_loginurl, $this->_loginstr);
         exit;
     }
 }
Esempio n. 3
0
 protected function processImages()
 {
     if (!empty($this->items)) {
         $params = JComponentHelper::getParams('com_phocagallery');
         $pagination_thumbnail_creation = $params->get('pagination_thumbnail_creation', 0);
         $clean_thumbnails = $params->get('clean_thumbnails', 0);
         //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->items_thumbnail)) {
             if ($pagination_thumbnail_creation == 1) {
                 $this->items_thumbnail = $this->items;
             } else {
                 $this->items_thumbnail = $this->get('ItemsThumbnail');
             }
         }
         // - - - - - - - - - - - - - - - - - - - -
         // 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 = PhocaGalleryPath::getPath();
         $origPath = $path->image_abs;
         $origPathServer = str_replace(DS, '/', $path->image_abs);
         //-----------------------------------------
         //Do all thumbnails no limit no pagination
         if (!empty($this->items_thumbnail)) {
             foreach ($this->items_thumbnail as $key => $value) {
                 $fileOriginalThumb = PhocaGalleryFile::getFileOriginal($value->filename);
                 //Let the user know that the file doesn't exists and delete all thumbnails
                 if (JFile::exists($fileOriginalThumb)) {
                     $refreshUrlThumb = 'index.php?option=com_phocagallery&view=phocagalleryimgs';
                     $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refreshUrlThumb, 1, 1, 1);
                 }
             }
         }
         $this->items_thumbnail = null;
         // delete data to reduce memory
         //Only the the site with limitation or pagination...
         if (!empty($this->items)) {
             foreach ($this->items as $key => $value) {
                 $fileOriginal = PhocaGalleryFile::getFileOriginal($value->filename);
                 //Let the user know that the file doesn't exists and delete all thumbnails
                 if (!JFile::exists($fileOriginal)) {
                     $this->items[$key]->filename = JText::_('COM_PHOCAGALLERY_IMG_FILE_NOT_EXISTS');
                     $this->items[$key]->fileoriginalexist = 0;
                 } else {
                     //Create thumbnails small, medium, large
                     $refresh_url = 'index.php?option=com_phocagallery&view=phocagalleryimgs';
                     $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refresh_url, 1, 1, 1);
                     $this->items[$key]->linkthumbnailpath = $fileThumb['thumb_name_s_no_rel'];
                     $this->items[$key]->fileoriginalexist = 1;
                 }
             }
         }
         //Clean Thumbs Folder if there are thumbnail files but not original file
         if ($clean_thumbnails == 1) {
             PhocaGalleryFileFolder::cleanThumbsFolder();
         }
     }
 }
Esempio n. 4
0
 public static function getList($small = 0, $medium = 0, $large = 0, $refreshUrl)
 {
     static $list;
     $params = JComponentHelper::getParams('com_phocagallery');
     $clean_thumbnails = $params->get('clean_thumbnails', 0);
     // Only process the list once per request
     if (is_array($list)) {
         return $list;
     }
     // Get current path from request
     $current = JRequest::getVar('folder');
     // If undefined, set to empty
     if ($current == 'undefined') {
         $current = '';
     }
     //Get folder variables from Helper
     $path = PhocaGalleryPath::getPath();
     // Initialize variables
     if (strlen($current) > 0) {
         $origPath = JPath::clean($path->image_abs . $current);
     } else {
         $origPath = $path->image_abs;
     }
     $origPathServer = str_replace(DS, '/', $path->image_abs);
     $images = array();
     $folders = array();
     // Get the list of files and folders from the given folder
     $fileList = JFolder::files($origPath);
     $folderList = JFolder::folders($origPath, '', false, false, array(0 => 'thumbs'));
     if (is_array($fileList) && !empty($fileList)) {
         natcasesort($fileList);
     }
     $field = JRequest::getVar('field');
     $refreshUrl = $refreshUrl . '&folder=' . $current . '&field=' . $field;
     // Iterate over the files if they exist
     //file - abc.img, file_no - folder/abc.img
     if ($fileList !== false) {
         foreach ($fileList as $file) {
             $ext = strtolower(JFile::getExt($file));
             // Don't display thumbnails from defined files (don't save them into a database)...
             $dontCreateThumb = PhocaGalleryFileThumbnail::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 (JFile::exists($origPath . DS . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                     //Create thumbnails small, medium, large
                     $fileNo = $current . "/" . $file;
                     $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($fileNo, $refreshUrl, $small, $medium, $large);
                     $tmp = new JObject();
                     $tmp->name = $fileThumb['name'];
                     $tmp->nameno = $fileThumb['name_no'];
                     $tmp->linkthumbnailpath = $fileThumb['thumb_name_m_no_rel'];
                     $tmp->linkthumbnailpathabs = $fileThumb['thumb_name_m_no_abs'];
                     $images[] = $tmp;
                 }
             }
         }
     }
     //Clean Thumbs Folder if there are thumbnail files but not original file
     if ($clean_thumbnails == 1) {
         PhocaGalleryFileFolder::cleanThumbsFolder();
     }
     // - - - - - - - - - - - -
     // Iterate over the folders if they exist
     if ($folderList !== false) {
         foreach ($folderList as $folder) {
             $tmp = new JObject();
             $tmp->name = basename($folder);
             $tmp->path_with_name = str_replace(DS, '/', JPath::clean($origPath . DS . $folder));
             $tmp->path_without_name_relative = $path->image_abs . str_replace($origPathServer, '', $tmp->path_with_name);
             $tmp->path_with_name_relative_no = str_replace($origPathServer, '', $tmp->path_with_name);
             $folders[] = $tmp;
         }
     }
     $list = array('folders' => $folders, 'Images' => $images);
     return $list;
 }
Esempio n. 5
0
 function delete($cid = array())
 {
     $params =& JComponentHelper::getParams('com_phocagallery');
     $clean_thumbnails = $params->get('clean_thumbnails', 0);
     $result = false;
     if (count($cid)) {
         JArrayHelper::toInteger($cid);
         $cids = implode(',', $cid);
         // - - - - - - - - - - - - -
         // Get all filenames we want to delete from database, we delete all thumbnails from server of this file
         $queryd = 'SELECT filename as filename FROM #__phocagallery WHERE id IN ( ' . $cids . ' )';
         $this->_db->setQuery($queryd);
         $fileObject = $this->_db->loadObjectList();
         // - - - - - - - - - - - - -
         //Delete it from DB
         $query = 'DELETE FROM #__phocagallery' . ' WHERE id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         // - - - - - - - - - - - - - -
         // Delete thumbnails - medium and large, small from server
         // All id we want to delete - gel all filenames
         foreach ($fileObject as $key => $value) {
             //The file can be stored in other category - don't delete it from server because other category use it
             $querys = "SELECT id as id FROM #__phocagallery WHERE filename='" . $value->filename . "' ";
             $this->_db->setQuery($queryd);
             $sameFileObject = $this->_db->loadObject();
             // same file in other category doesn't exist - we can delete it
             if (!$sameFileObject) {
                 PhocaGalleryFileThumbnail::deleteFileThumbnail($value->filename, 1, 1, 1);
             }
         }
         // Clean Thumbs Folder if there are thumbnail files but not original file
         if ($clean_thumbnails == 1) {
             phocagalleryimport('phocagallery.file.filefolder');
             PhocaGalleryFileFolder::cleanThumbsFolder();
         }
         // - - - - - - - - - - - - - -
     }
     return true;
 }