/** * Creates directories and the database entry for a category * * @param object $cat Holds information about the new category * @param boolean $checkOwner Determines whether the owner ID shall be checked against the existing users * @return boolean True on success, false otherwise * @since 1.5.0 */ public function createCategory($cat, $checkOwner = null) { jimport('joomla.filesystem.file'); if (is_null($checkOwner)) { $checkOwner = $this->checkOwner; } // Some checks if (!isset($cat->cid)) { $this->setError('Invalid category ID'); return false; } if (!isset($cat->name)) { $cat->name = 'no cat name'; } if (!isset($cat->alias)) { // Will be created later on $cat->alias = ''; } if (!isset($cat->parent_id) || $cat->parent_id < 0) { $cat->parent_id = 1; } else { // If category with parent category ID 1 comes in we have // to set the parent ID to the newly created one because // category with ID 1 is the ROOT category in JoomGallery if ($cat->parent_id == 1) { $cat->parent_id = $this->newCatid; } // Main categories are children of the ROOT category if ($cat->parent_id == 0) { $cat->parent_id = 1; } } if (!isset($cat->description)) { $cat->description = ''; } if (!isset($cat->ordering)) { $cat->ordering = 0; } if (!isset($cat->lft)) { $cat->lft = $cat->ordering; } if (!isset($cat->access)) { $cat->access = $this->_mainframe->getCfg('access'); } if (!isset($cat->published)) { $cat->published = 0; } if (!isset($cat->hidden)) { $cat->hidden = 0; } if (!isset($cat->in_hidden)) { $cat->in_hidden = 0; } if (!isset($cat->owner) || !is_numeric($cat->owner) || $cat->owner < 1 || $checkOwner && !JUser::getTable()->load($cat->owner)) { $cat->owner = 0; } if (!isset($cat->password)) { $cat->password = ''; } if (!isset($cat->thumbnail)) { $cat->thumbnail = 0; } if (!isset($cat->img_position)) { $cat->img_position = 0; } if (!isset($cat->params)) { $cat->params = ''; } if (!isset($cat->metakey)) { $cat->metakey = ''; } if (!isset($cat->metadesc)) { $cat->metadesc = ''; } if (!isset($cat->exclude_toplists)) { $cat->exclude_toplists = 0; } if (!isset($cat->exclude_search)) { $cat->exclude_search = 0; } $catid_changed = false; if ($cat->cid == 1) { // Special handling for categories with ID 1 because that's the ROOT category in JoomGallery $cat->cid = $this->getMaxCategoryId() + 1; // Store the new category ID because we have to use it for the images and categories in this category $this->newCatid = $cat->cid; $this->_mainframe->setUserState('joom.migration.internal.new_catid', $this->newCatid); $this->writeLogfile('New ID ' . $cat->cid . ' assigned to category ' . $cat->name); $catid_changed = true; } // Make the category name safe JFilterOutput::objectHTMLSafe($cat->name); // If the new category should be assigned as subcategory... if ($cat->parent_id > 1) { // Save the category path of parent category in a variable $parentpath = JoomHelper::getCatPath($cat->parent_id); } else { // Otherwise leave it empty $parentpath = ''; } // Creation of category path // Cleaning of category title with function JoomFile::fixFilename // so special chars are converted and underscore removed // affects only the category path $newcatname = JoomFile::fixFilename($cat->name); // Add an underscore and the category ID // affects only the category path $newcatname = $newcatname . '_' . $cat->cid; // Prepend - if exists - the parent category path $cat->catpath = $parentpath . $newcatname; // Create the paths of category for originals, pictures, thumbnails $cat_originalpath = JPath::clean($this->_ambit->get('orig_path') . $cat->catpath); $cat_detailpath = JPath::clean($this->_ambit->get('img_path') . $cat->catpath); $cat_thumbnailpath = JPath::clean($this->_ambit->get('thumb_path') . $cat->catpath); $result = array(); if (!JFolder::exists($cat_originalpath)) { $result[] = JFolder::create($cat_originalpath); $result[] = JoomFile::copyIndexHtml($cat_originalpath); } if (!JFolder::exists($cat_detailpath)) { $result[] = JFolder::create($cat_detailpath); $result[] = JoomFile::copyIndexHtml($cat_detailpath); } if (!JFolder::exists($cat_thumbnailpath)) { $result[] = JFolder::create($cat_thumbnailpath); $result[] = JoomFile::copyIndexHtml($cat_thumbnailpath); } // Create database entry $query = $this->_db->getQuery(true)->insert(_JOOM_TABLE_CATEGORIES)->columns('cid, name, alias, parent_id, lft, description, access, published, hidden, in_hidden, password, owner, thumbnail, img_position, catpath, params, metakey, metadesc, exclude_toplists, exclude_search')->values((int) $cat->cid . ',' . $this->_db->quote($cat->name) . ',' . $this->_db->quote($cat->alias) . ',' . (int) $cat->parent_id . ',' . (int) $cat->lft . ',' . $this->_db->quote($cat->description) . ',' . (int) $cat->access . ',' . (int) $cat->published . ',' . (int) $cat->hidden . ',' . (int) $cat->in_hidden . ',' . $this->_db->quote($cat->password) . ',' . (int) $cat->owner . ',' . (int) $cat->thumbnail . ',' . (int) $cat->img_position . ',' . $this->_db->quote($cat->catpath) . ',' . $this->_db->quote($cat->params) . ',' . $this->_db->quote($cat->metakey) . ',' . $this->_db->quote($cat->metadesc) . ',' . (int) $cat->exclude_toplists . ',' . (int) $cat->exclude_toplists); $this->_db->setQuery($query); $result[] = $this->runQuery(); // Create asset and alias $table = JTable::getInstance('joomgallerycategories', 'Table'); $table->load($cat->cid); if ($table->check()) { $result['db'] = $table->store(); if (!$result['db']) { $this->setError($table->getError(), true); } } if ($catid_changed) { // Set back category ID in the object because it may be used again later $cat->cid = 1; } if (!in_array(false, $result)) { $this->writeLogfile('Category ' . ($catid_changed ? $this->newCatid : $cat->cid) . ' created: ' . $cat->name); return true; } else { $this->writeLogfile(' -> Error creating category ' . ($catid_changed ? $this->newCatid : $cat->cid) . ': ' . $cat->name); return false; } }
/** * Deletes folders of an existing category * * @param string $catpath The catpath of the category * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _deleteFolders($catpath) { if (!$catpath) { return false; } $orig_path = JPath::clean($this->_ambit->get('orig_path') . $catpath); $img_path = JPath::clean($this->_ambit->get('img_path') . $catpath); $thumb_path = JPath::clean($this->_ambit->get('thumb_path') . $catpath); // Delete the folder of the category for the original images if (!JFolder::delete($orig_path)) { // If not successfull return false; } else { // Delete the folder of the category for the detail images if (!JFolder::delete($img_path)) { // If not successful if (JFolder::create($orig_path)) { JoomFile::copyIndexHtml($orig_path); } return false; } else { // Delete the folder of the category for the thumbnails if (!JFolder::delete($thumb_path)) { // If not successful if (JFolder::create($orig_path)) { JoomFile::copyIndexHtml($orig_path); } if (JFolder::create($img_path)) { JoomFile::copyIndexHtml($img_path); } return false; } } } return true; }
/** * Creates new folders for categories. * * @return int/boolean Number of created folders on success, false otherwise * @since 1.5.5 */ public function create() { $cids = JRequest::getVar('cid', array(), '', 'array'); $types = JRequest::getVar('type', array('thumb', 'img', 'orig'), '', 'array'); if (!count($cids)) { $this->setError(JText::_('COM_JOOMGALLERY_COMMON_MSG_NO_CATEGORIES_SELECTED')); return false; } // Get selected category IDs $query = $this->_db->getQuery(true)->select('refid')->from($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->where('id IN (' . implode(',', $cids) . ')')->where('type != 0'); $this->_db->setQuery($query); if (!($ids = $this->_db->loadColumn())) { $this->setError($this->_db->getErrorMsg()); return false; } $count = 0; foreach ($types as $type) { foreach ($ids as $cid) { // Create the folder $folder = $this->_ambit->get($type . '_path') . JoomHelper::getCatPath($cid); if (!JFolder::create($folder)) { continue; } JoomFile::copyIndexHtml($folder); // Update maintenance table $query = $this->_db->getQuery(true)->update($this->_db->qn(_JOOM_TABLE_MAINTENANCE))->set($type . ' = ' . $this->_db->q($this->_db->escape($folder)))->where('refid = ' . $cid)->where('type != 0'); $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $count++; } } return $count; }
/** * Creates a new category out of the information of the given object * * @param object $obj Should hold all the information about the new category * @param int The ID of the new category, false, if an error occured * @since 1.5.0 */ public function createCategory($obj) { jimport('joomla.filesystem.file'); JLoader::register('JoomFile', JPATH_ADMINISTRATOR . '/components/' . _JOOM_OPTION . '/helpers/file.php'); $row = JTable::getInstance('joomgallerycategories', 'Table'); $row->bind($obj); if (!$row->name) { $this->_mainframe->enqueueMessage(JText::_('No valid category name given'), 'error'); return false; } $row->parent_id = (int) $row->parent_id; if ($row->parent_id < 1) { $row->parent_id = 1; } // Determine location in category tree if (!isset($obj->ordering) || !$obj->ordering || $obj->ordering == 'first-child') { $row->setLocation($row->parent_id, 'first-child'); } else { if ($obj->ordering == 'last-child') { $row->setLocation($row->parent_id, 'last-child'); } else { $row->setLocation($obj->ordering, 'after'); } } // Ensure that the data is valid if (!$row->check()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Store the data in the database if (!$row->store()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Now we have the ID of the new category // and the catpath can be built $row->catpath = JoomFile::fixFilename($row->name) . '_' . $row->cid; if ($row->parent_id > 1) { $row->catpath = JoomHelper::getCatPath($row->parent_id) . $row->catpath; } // So store again, but afore let's create the alias $row->check(); if (!$row->store()) { $this->_mainframe->enqueueMessage($row->getError(), 'error'); return false; } // Create necessary folders and files $origpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathoriginalimages') . $row->catpath; $imgpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_pathimages') . $row->catpath; $thumbpath = JPATH_ROOT . '/' . $this->_jg_config->get('jg_paththumbs') . $row->catpath; $result = array(); $result[] = JFolder::create($origpath); $result[] = JoomFile::copyIndexHtml($origpath); $result[] = JFolder::create($imgpath); $result[] = JoomFile::copyIndexHtml($imgpath); $result[] = JFolder::create($thumbpath); $result[] = JoomFile::copyIndexHtml($thumbpath); if (in_array(false, $result)) { // Delete the just stored database entry $row->delete(); return false; } else { // New category successfully created return $row->cid; } }
/** * Install method * * @return boolean True on success, false otherwise * @since 2.0 */ public function install() { $app = JFactory::getApplication(); jimport('joomla.filesystem.file'); // Create image directories require_once JPATH_ADMINISTRATOR . '/components/com_joomgallery/helpers/file.php'; $thumbpath = JPATH_ROOT . '/images/joomgallery/thumbnails'; $imgpath = JPATH_ROOT . '/images/joomgallery/details'; $origpath = JPATH_ROOT . '/images/joomgallery/originals'; $result = array(); $result[] = JFolder::create($thumbpath); $result[] = JoomFile::copyIndexHtml($thumbpath); $result[] = JFolder::create($imgpath); $result[] = JoomFile::copyIndexHtml($imgpath); $result[] = JFolder::create($origpath); $result[] = JoomFile::copyIndexHtml($origpath); $result[] = JoomFile::copyIndexHtml(JPATH_ROOT . '/images/joomgallery'); if (in_array(false, $result)) { $app->enqueueMessage(JText::_('Unable to create image directories!'), 'error'); return false; } // Create news feed module $subdomain = ''; $language = JFactory::getLanguage(); if (strpos($language->getTag(), 'de-') === false) { $subdomain = 'en.'; } $row = JTable::getInstance('module'); $row->title = 'JoomGallery News'; $row->ordering = 1; $row->position = 'joom_cpanel'; $row->published = 1; $row->module = 'mod_feed'; $row->access = $app->getCfg('access'); $row->showtitle = 1; $row->params = 'cache=1 cache_time=15 moduleclass_sfx= rssurl=http://www.' . $subdomain . 'joomgallery.net/feed/rss.html rssrtl=0 rsstitle=1 rssdesc=0 rssimage=1 rssitems=3 rssitemdesc=1 word_count=200'; $row->client_id = 1; $row->language = '*'; if (!$row->store()) { $app->enqueueMessage(JText::_('Unable to insert feed module data!'), 'error'); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->insert('#__modules_menu'); $query->set('moduleid = ' . $row->id); $query->set('menuid = 0'); $db->setQuery($query); if (!$db->query()) { $app->enqueueMessage(JText::_('Unable to assign feed module!'), 'error'); } // joom_settings.css $temp = JPATH_ROOT . '/media/joomgallery/css/joom_settings.temp.css'; $dest = JPATH_ROOT . '/media/joomgallery/css/joom_settings.css'; if (!JFile::move($temp, $dest)) { $app->enqueueMessage(JText::_('Unable to copy joom_settings.css!'), 'error'); return false; } ?> <div class="hero-unit"> <img src="../media/joomgallery/images/joom_logo.png" alt="JoomGallery Logo" /> <div class="alert alert-success"> <h3>JoomGallery <?php echo $this->version; ?> was installed successfully.</h3> </div> <p>You may now start using JoomGallery or download specific language files afore:</p> <p> <a title="Start" class="btn" onclick="location.href='index.php?option=com_joomgallery'; return false;" href="#">Start now!</a> <a title="Languages" class="btn btn-primary" onclick="location.href='index.php?option=com_joomgallery&controller=help'; return false;" href="#">Languages</a> </p> </div> <?php }
/** * Creates the folders for a category * * @param string The category path for the category * @return boolean True on success, false otherwise * @since 1.5.5 */ protected function _createFolders($catpath) { $catpath = JPath::clean($catpath); // Create the folder of the category for the original images if (!JFolder::create($this->_ambit->get('orig_path') . $catpath)) { // If not successfull return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('orig_path') . $catpath); // Create the folder of the category for the detail images if (!JFolder::create($this->_ambit->get('img_path') . $catpath)) { // If not successful JFolder::delete($this->_ambit->get('orig_path') . $catpath); return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('img_path') . $catpath); // Create the folder of the category for the thumbnails if (!JFolder::create($this->_ambit->get('thumb_path') . $catpath)) { // If not successful JFolder::delete($this->_ambit->get('orig_path') . $catpath); JFolder::delete($this->_ambit->get('img_path') . $catpath); return false; } else { // Copy an index.html file into the new folder JoomFile::copyIndexHtml($this->_ambit->get('thumb_path') . $catpath); } } } return true; }
/** * Constructor * * @return void * @since 1.0.0 */ public function __construct() { $this->_mainframe = JFactory::getApplication(); $this->_config = JoomConfig::getInstance(); $this->_ambit = JoomAmbit::getInstance(); $this->_user = JFactory::getUser(); $this->_db = JFactory::getDBO(); $this->debug = $this->_mainframe->getUserStateFromRequest('joom.upload.debug', 'debug', false, 'post', 'bool'); $this->_debugoutput = $this->_mainframe->getUserStateFromRequest('joom.upload.debugoutput', 'debugoutput', '', 'post', 'string'); $this->catid = $this->_mainframe->getUserStateFromRequest('joom.upload.catid', 'catid', 0, 'int'); $this->imgtitle = $this->_mainframe->getUserStateFromRequest('joom.upload.title', 'imgtitle', '', 'string'); $this->counter = $this->getImageNumber(); $this->_site = $this->_mainframe->isSite(); // TODO Parameter in JoomGallery configuration neccessary ? // Create folder for image chunks $this->chunksFolder = $this->_mainframe->getCfg('tmp_path') . '/joomgallerychunks'; if (!JFolder::exists($this->chunksFolder)) { JFolder::create($this->chunksFolder); JoomFile::copyIndexHtml($this->chunksFolder); } }