public function getName($title, $filename, $preferTitle = 0) { $name = $title; $fon = $this->params->get( 'filename_or_name', 'filename' ); if ($fon == 'title') { $name = $title; } else if ($fon == 'filename'){ $name = PhocaDownloadFile::getTitleFromFilenameWithExt( $filename ); } else if ($fon == 'filenametitle'){ if ($preferTitle == 1) { $name = $title; } else { // Must be solved before $name = PhocaDownloadFile::getTitleFromFilenameWithExt( $filename ); } } return $name; }
function display($tpl = null) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $userLevels = implode(',', $user->getAuthorisedViewLevels()); $db = JFactory::getDBO(); $menu = $app->getMenu(); $document = JFactory::getDocument(); $params = $app->getParams(); $moduleId = $app->input->get('id', 0, 'int'); $table =& JTable::getInstance('module'); if ((int) $moduleId > 0) { $db = JFactory::getDBO(); $query = 'SELECT a.params' . ' FROM #__modules AS a' . ' WHERE a.published = 1' . ' AND a.id =' . (int) $moduleId . ' ORDER BY a.ordering'; $db->setQuery($query); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } $module = $db->loadObject(); if (isset($module->params) && $module->params != '') { jimport('joomla.html.parameter'); $paramsM = new JRegistry(); $paramsM->loadString($module->params); //$paramsM->loadJSON($module->params); // Params $categories = $paramsM->get('category_ids', ''); $ordering = $paramsM->get('file_ordering', 6); $fileCount = $paramsM->get('file_count', 5); $feedTitle = $paramsM->get('feed_title', JText::_('COM_PHOCADOWNLOAD_DOWNLOAD')); $displayDateType = $paramsM->get('display_date_type', 1); $document->setTitle($this->escape(html_entity_decode($feedTitle))); $wheres = array(); if (is_array($categories) && count($categories) > 0) { JArrayHelper::toInteger($categories); $categoriesString = implode(',', $categories); $wheres[] = ' c.catid IN ( ' . $categoriesString . ' ) '; } else { if ((int) $categories > 0) { $wheres[] = ' c.catid IN ( ' . $categories . ' ) '; } } $wheres[] = ' c.catid= cc.id'; $wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND c.access IN (' . $userLevels . ') ) )'; $wheres[] = '( (unaccessible_file = 1 ) OR (unaccessible_file = 0 AND cc.access IN (' . $userLevels . ') ) )'; $wheres[] = ' c.published = 1'; $wheres[] = ' c.approved = 1'; $wheres[] = ' cc.published = 1'; $wheres[] = ' c.textonly = 0'; // Active $jnow = JFactory::getDate(); $now = $jnow->toSql(); $nullDate = $db->getNullDate(); $wheres[] = ' ( c.publish_up = ' . $db->Quote($nullDate) . ' OR c.publish_up <= ' . $db->Quote($now) . ' )'; $wheres[] = ' ( c.publish_down = ' . $db->Quote($nullDate) . ' OR c.publish_down >= ' . $db->Quote($now) . ' )'; $fileOrdering = PhocaDownloadOrdering::getOrderingText($ordering); $query = ' SELECT c.*, cc.id AS categoryid, cc.title AS categorytitle, cc.alias AS categoryalias, cc.access as cataccess, cc.accessuserid as cataccessuserid ' . ' FROM #__phocadownload AS c' . ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = c.catid' . ' WHERE ' . implode(' AND ', $wheres) . ' ORDER BY c.' . $fileOrdering; $db->setQuery($query, 0, $fileCount); $files = $db->loadObjectList(); foreach ($files as $keyDoc => $valueDoc) { // USER RIGHT - Access of categories (if file is included in some not accessed category) - - - - - // ACCESS is handled in SQL query, ACCESS USER ID is handled here (specific users) $rightDisplay = 0; if (!empty($valueDoc)) { $rightDisplay = PhocaDownloadAccess::getUserRight('accessuserid', $valueDoc->cataccessuserid, $valueDoc->cataccess, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0); } // - - - - - - - - - - - - - - - - - - - - - - if ($rightDisplay == 1) { $item = new JFeedItem(); $title = $this->escape($valueDoc->title . ' (' . PhocaDownloadFile::getTitleFromFilenameWithExt($valueDoc->filename) . ')'); $title = html_entity_decode($title); $item->title = $title; $link = PhocaDownloadRoute::getCategoryRoute($valueDoc->categoryid, $valueDoc->categoryalias); $item->link = JRoute::_($link); // FILEDATE $fileDate = ''; if ((int) $displayDateType > 0) { if ($valueDoc->filename != '') { $fileDate = PhocaDownloadFile::getFileTime($valueDoc->filename, $displayDateType, "Y-m-d H:M:S"); } } else { $fileDate = JHTML::Date($valueDoc->date, "Y-m-d H:i:s"); } if ($fileDate != '') { $item->date = $fileDate; } //$item->description = $valueDoc->description; // $item->description = '<div><img src="media/com_phocadownload/images/phoca-download.png" alt="" /></div><div>New file "' .$valueDoc->title . '" ('. $valueDoc->filename.') released on '. $dateDesc.' is available on <a href="http://www.phoca.cz/download">Phoca download site</a></div>'.$valueDoc->description; $item->description = '<div><img src="media/com_phocadownload/images/phoca-download.png" alt="" /></div>' . $valueDoc->description; $item->category = $valueDoc->categorytitle; // $item->section = $valueDoc->sectiontitle; if ($valueDoc->author != '') { $item->author = $valueDoc->author; } $document->addItem($item); } } } } }
function save($data) { $app = JFactory::getApplication(); $post = JRequest::get('post'); $data = JRequest::getVar('jform', array(0), 'post', 'array'); // ================================================= // Make a copy for play and preview $paramsC = JComponentHelper::getParams('com_phocadownload'); $papCopy = $paramsC->get('pap_copy', 0); $data['pap_copy_m'] = 0; if ($papCopy == 2 || $papCopy == 3) { $data['pap_copy_m'] = 1; } // ================================================= if (isset($post['foldercid'])) { $data['foldercid'] = $post['foldercid']; } if (isset($post['cid'])) { $data['cid'] = $post['cid']; } if (isset($data['catid']) && (int) $data['catid'] > 0) { $data['catid'] = (int) $data['catid']; } else { $data['catid'] = 0; } //Get folder variables from Helper $path = PhocaDownloadPath::getPathSet(); $origPath = $path['orig_abs_ds']; $origPathServer = str_replace(DS, '/', JPath::clean($path['orig_abs_ds'])); // Cache all existing categories $query = 'SELECT id, title, parent_id' . ' FROM #__phocadownload_categories'; $this->_db->setQuery($query); $existingCategories = $this->_db->loadObjectList(); // Cache all existing files $query = 'SELECT catid, filename' . ' FROM #__phocadownload'; $this->_db->setQuery($query); $existingFiles = $this->_db->loadObjectList(); $result = new StdClass(); $result->category_count = 0; $result->image_count = 0; // Category will be saved - Files will be saved in recursive function if (isset($data['foldercid'])) { foreach ($data['foldercid'] as $foldername) { if (strlen($foldername) > 0) { $fullPath = $path['orig_abs_ds'] . $foldername; $result = $this->_createCategoriesRecursive($origPathServer, $fullPath, $existingCategories, $existingFiles, $data['catid'], $data); } } } // Only Files will be saved if (isset($data['cid'])) { // Make a copy for play and preview (1) -------- if (isset($data['pap_copy_m']) && $data['pap_copy_m'] == 1) { //$paramsC = JComponentHelper::getParams('com_phocadownload') ; $overwriteExistingFiles = $paramsC->get('overwrite_existing_files', 0); } // ------------------------------------------------ foreach ($data['cid'] as $filename) { if ($filename) { //$ext = strtolower(JFile::getExt($filename)); $row = $this->getTable('phocadownload'); $datam = array(); $datam['published'] = $data['published']; $datam['catid'] = $data['catid']; $datam['approved'] = $data['approved']; $datam['language'] = $data['language']; $datam['filename'] = $filename; if ($data['title'] != '') { $datam['title'] = $data['title']; } else { $datam['title'] = PhocaDownloadFile::getTitleFromFilenameWithoutExt($filename); } if ($data['alias'] != '') { $datam['alias'] = $data['alias']; } else { $datam['alias'] = $data['alias']; // PhocaDownloadFile::getAliasName($datam['title']); } $datam['token'] = PhocaDownloadUtils::getToken($datam['title'] . $datam['filename']); // Make a copy for play and preview (2) if (isset($data['pap_copy_m']) && $data['pap_copy_m'] == 1) { $filenameExt = PhocaDownloadFile::getTitleFromFilenameWithExt($filename); $storedfilename = $filename; $storedfoldername = str_replace($filenameExt, '', $storedfilename); $o = $this->_copyPreviewAndPlay($filenameExt, $storedfilename, $storedfoldername, $path, $overwriteExistingFiles); $datam['filename_play'] = $o['filename_play']; $datam['filename_preview'] = $o['filename_preview']; } // Save // Bind the form fields to the Phoca download table if (!$row->bind($datam)) { $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 download table is valid if (!$row->check()) { $this->setError($this->_db->getErrorMsg()); return false; } // Store the Phoca download table to the database if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } $result->image_count++; } } $this->setfileCount($result->image_count); } $msg = $this->categoryCount . ' ' . JText::_('COM_PHOCADOWNLOAD_CATEGORIES_ADDED') . ', ' . $this->fileCount . ' ' . JText::_('COM_PHOCADOWNLOAD_FILES_ADDED'); $app->enqueueMessage($msg); $app->redirect(JRoute::_('index.php?option=com_phocadownload&view=phocadownloadfiles', false)); return true; }