Beispiel #1
0
 function _createCategoriesRecursive(&$orig_path_server, $path, &$existing_categories, &$existing_images, $parent_id = 0)
 {
     $totalresult->image_count = 0;
     $totalresult->category_count = 0;
     $category_name = basename($path);
     $id = $this->_getCategoryId($existing_categories, $category_name, $parent_id);
     $category = null;
     if ($id == -1) {
         $row =& $this->getTable('phocagalleryc');
         $row->published = 1;
         $row->parent_id = $parent_id;
         $row->title = $category_name;
         $row->alias = PhocaGalleryHelper::getAliasName($category_name);
         $row->ordering = $row->getNextOrder("parent_id = " . $this->_db->Quote($row->parent_id));
         if (!$row->check()) {
             JError::raiseError(500, $row->getError('Check Problem'));
         }
         if (!$row->store()) {
             JError::raiseError(500, $row->getError('Store Problem'));
         }
         $category = new JObject();
         $category->title = $category_name;
         $category->parent_id = $parent_id;
         $category->id = $row->id;
         $totalresult->category_count++;
         $id = $category->id;
         $existing_categories[] =& $category;
         $this->setCategoryCount(1);
         //This subcategory was added
     }
     // Full path: eg. "/home/www/joomla/images/categ/subcat/"
     $full_path = str_replace(DS, '/', JPath::clean(DS . $path));
     // Relative path eg "categ/subcat"
     $relative_path = str_replace($orig_path_server, '', $full_path);
     //
     // Add all images from this folder
     //
     $totalresult->image_count += $this->_addAllImagesFromFolder($existing_images, $id, $path, $relative_path);
     $this->setImageCount($totalresult->image_count);
     //
     // Do sub folders
     //
     $parent_id = $id;
     $folder_list = JFolder::folders($path, $filter = '.', $recurse = false, $fullpath = true, $exclude = array('thumbs'));
     // Iterate over the folders if they exist
     if ($folder_list !== false) {
         foreach ($folder_list as $folder) {
             //$this->setCategoryCount(1);//This subcategory was added
             $result = $this->_createCategoriesRecursive($orig_path_server, $folder, $existing_categories, $existing_images, $id);
             $totalresult->image_count += $result->image_count;
             $totalresult->category_count += $result->category_count;
             //	$this->setCategoryCount($totalresult->category_count);
         }
     }
     return $totalresult;
 }
Beispiel #2
0
 function createCategory()
 {
     global $mainframe;
     JRequest::checkToken() or jexit('Invalid Token');
     $user =& JFactory::getUser();
     $view = JRequest::getVar('view', '', 'post', '', 0);
     $post['title'] = JRequest::getVar('categoryname', '', 'post', 'string', 0);
     $post['description'] = JRequest::getVar('phocagallerycreatecatdescription', '', 'post', 'string', 0);
     $Itemid = JRequest::getVar('Itemid', 0, '', 'int');
     $tab = JRequest::getVar('tab', 0, '', 'int');
     // Params
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     // 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;
     }
     $maxCreateCatChar = $paramsC->get('max_create_cat_char', 1000);
     $post['description'] = substr($post['description'], 0, (int) $maxCreateCatChar);
     $post['alias'] = PhocaGalleryHelper::getAliasName($post['title']);
     // user is logged in
     if ($user->aid > 0 && $user->id > 0) {
         if ($post['title'] != '') {
             $model = $this->getModel('user');
             $userCatId = $model->getUserCategory($user->id);
             // User has no category, he (she) can create one
             if (empty($userCatId->id)) {
                 // NEW
                 $msg = '';
                 // Create an user folder on the server
                 $userFolder = PhocaGalleryHelper::getAliasName($user->username) . '-' . substr($post['alias'], 0, 10) . '-' . substr(md5(uniqid(time())), 0, 4);
                 $createdFolderError = '';
                 $createdFolder = PhocaGalleryHelper::createFolder($userFolder);
                 $createdFolderError = preg_match("/.\\[PhocaError\\]/i", $createdFolder);
                 if ($createdFolderError) {
                     $msg = JText::_('Error Folder Creating') . ': ' . str_replace('[PhocaError]', '', $createdFolder);
                 }
                 // -----------------------------------
                 // 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['params'] = 'accessuserid=-1;' . 'uploaduserid=' . $user->id . ';' . 'deleteuserid=' . $user->id . ';' . 'userfolder=' . $userFolder . ';';
                     // Create new category
                     $id = $model->store($post);
                     if ($id && $id > 0) {
                         $data['userid'] = $user->id;
                         $data['catid'] = $id;
                         $userCategoryId = $model->storeUserCategory($data);
                         if ($userCategoryId && $userCategoryId > 0) {
                             $msg = JText::_('Phoca Gallery User Control Category Saved');
                         } else {
                             $msg = JText::_('Error Saving Phoca Gallery User Control Category');
                         }
                     } else {
                         $msg = JText::_('Error Saving Phoca Gallery User Control Category');
                     }
                 }
             } else {
                 if ($post['title'] != '') {
                     // EDIT
                     $post['id'] = $userCatId->categoryid;
                     $id = $model->store($post);
                     if ($id && $id > 0) {
                         $msg = JText::_('Phoca Gallery User Control Category Edited');
                     } else {
                         $msg = JText::_('Error Editing Phoca Gallery User Control Category');
                     }
                 }
             }
         } else {
             $msg = JText::_('ERROR CREATE CATEGORY PHOCA GALLERY - TITLE');
         }
         $this->setRedirect(JRoute::_('index.php?option=com_phocagallery&view=user&tab=' . $tab . '&Itemid=' . $Itemid, false), $msg);
     } else {
         $this->setRedirect(JRoute::_('index.php?option=com_user&view=login', false), JText::_("NOT AUTHORISED TO DO ACTION"));
         exit;
     }
 }
Beispiel #3
0
 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;
     }
 }
Beispiel #4
0
 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;
 }