<?php defined('_JEXEC') or die('Restricted access'); global $jlistConfig; JHtml::_('behavior.tooltip'); JHTML::_('behavior.formvalidation'); // JHtml::_('behavior.formvalidator'); Joomla >= 3.4 jimport('joomla.form.form'); $canDo = jdownloadsHelper::getActions(); // get DB prefix string and table list to check whether it exists backup tables $db = JFactory::getDBO(); $prefix = JDownloadsHelper::getCorrectDBPrefix(); $tablelist = $db->getTableList(); $old_version_found = false; if (in_array($prefix . 'jdownloads_config_backup', $tablelist)) { $old_version_found = true; } ?> <script type="text/javascript"> function confirmAction(task) { if (task == 'resetDownloadCounter' ){ var x = confirm("<?php echo JText::_('COM_JDOWNLOADS_BACKEND_SETTINGS_RESET_COUNTER_CONFIRM'); ?> ") if (x == true){ window.location="index.php?option=com_jdownloads&task=tools.resetDownloadCounter" } }
/** * logic for create the backup file * */ public function runbackup() { global $jlistConfig; $jinput = JFactory::getApplication()->input; $jd_version = JDownloadsHelper::getjDownloadsVersion(); $jd_version = str_replace(' ', '_', $jd_version); $add_also_logs = $jinput->get('logs', 0, 'int'); // check user access right if (JFactory::getUser()->authorise('com_jdownloads.edit.config', 'com_jdownloads')) { $db = JFactory::getDBO(); $prefix = JDownloadsHelper::getCorrectDBPrefix(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jdownloads' . DS . 'tables'); if ($add_also_logs) { $dbtables = array($prefix . 'jdownloads_config', $prefix . 'jdownloads_categories', $prefix . 'jdownloads_files', $prefix . 'jdownloads_licenses', $prefix . 'jdownloads_ratings', $prefix . 'jdownloads_logs', $prefix . 'jdownloads_templates', $prefix . 'jdownloads_usergroups_limits', $prefix . 'assets'); } else { // logs are not stored $dbtables = array($prefix . 'jdownloads_config', $prefix . 'jdownloads_categories', $prefix . 'jdownloads_files', $prefix . 'jdownloads_licenses', $prefix . 'jdownloads_ratings', $prefix . 'jdownloads_templates', $prefix . 'jdownloads_usergroups_limits', $prefix . 'assets'); } $file = '<?php' . "\r\n"; for ($i = 0; $i < count($dbtables); $i++) { // the target db can has an other prefix, so we can not use it here $table_name = str_replace($prefix, '#__', $dbtables[$i]); // make not the Joomla asset table empty!!! if ($dbtables[$i] != $prefix . 'assets') { $file .= '$db->setQuery("TRUNCATE TABLE `' . $table_name . '`") ;$db->execute();' . "\r\n"; } else { // only remove all olders jdownloads categories and downloads from asset table // but not the component root item (level=1) $file .= '$db->setQuery("DELETE FROM `' . $table_name . '` WHERE `name` LIKE ' . $db->quote('com_jdownloads%') . ' AND `level` > ' . $db->quote('1') . '"); $db->execute();' . "\r\n"; } } // we will backup not the assets in this version array_pop($dbtables); foreach ($dbtables as $dbtable) { if ($dbtable == $prefix . 'jdownloads_ratings' || $dbtable == $prefix . 'jdownloads_files') { $db->setQuery("SELECT file_id FROM {$dbtable}"); } else { $db->setQuery("SELECT id FROM {$dbtable}"); } // alternate when we will get also the assets data (not useful in this version): /*} elseif ($dbtable == $prefix.'assets' ){ $db->setQuery("SELECT id FROM $dbtable WHERE `name` LIKE 'com_jdownloads%' AND `level` > '1'"); } else { $db->setQuery("SELECT id FROM $dbtable"); } */ $xids = $db->loadObjectList(); foreach ($xids as $xid) { switch ($dbtable) { case $prefix . 'jdownloads_config': $object = JTable::getInstance('config', 'jdownloadsTable'); break; case $prefix . 'jdownloads_categories': $object = JTable::getInstance('category', 'jdownloadsTable'); break; case $prefix . 'jdownloads_files': $object = JTable::getInstance('download', 'jdownloadsTable'); break; case $prefix . 'jdownloads_licenses': $object = JTable::getInstance('license', 'jdownloadsTable'); break; case $prefix . 'jdownloads_templates': $object = JTable::getInstance('template', 'jdownloadsTable'); break; case $prefix . 'jdownloads_logs': $object = JTable::getInstance('log', 'jdownloadsTable'); break; case $prefix . 'jdownloads_ratings': $object = JTable::getInstance('rating', 'jdownloadsTable'); break; case $prefix . 'jdownloads_usergroups_limits': $object = JTable::getInstance('group', 'jdownloadsTable'); break; case $prefix . 'assets': $object = JTable::getInstance('assets', 'jdownloadsTable'); break; } // get the data row if ($dbtable == $prefix . 'jdownloads_files') { $object->load($xid->file_id); } elseif ($dbtable == $prefix . 'jdownloads_ratings') { $db->setQuery("SELECT * FROM " . $prefix . 'jdownloads_ratings' . " WHERE `file_id` = '{$xid->file_id}'"); $row = $db->loadObject(); } else { $object->load($xid->id); } // the target db can has an other prefix, so we can not use it here $table_name = str_replace($prefix, '#__', $dbtable); if ($table_name != '#__jdownloads_ratings') { $sql = '$db->setQuery("INSERT INTO ' . $table_name . ' ( %s ) VALUES ( %s );"); $db->execute();$i++; ' . "\r\n"; $fields = array(); $values = array(); foreach (get_object_vars($object) as $k => $v) { if (is_array($v) or is_object($v) or $v === NULL) { continue; } if ($k[0] == '_') { continue; } // set field name $fields[] = $db->quoteName($k); // set field value (but not for ID field from assets table!!!) if ($table_name == '#__assets' && $k == 'id') { $values[] = "''"; } else { // write 0 to asset id if ($k == 'asset_id') { $values[] = "'0'"; } else { $values[] = $db->Quote($v); } } } $file .= sprintf($sql, implode(",", $fields), implode(",", $values)); } else { // special handling for ratings table required, then we have here not a primary key $file .= '$db->setQuery("INSERT INTO ' . $table_name . ' ( `file_id`,`rating_sum`,`rating_count`,`lastip` ) VALUES ( ' . $db->quote($row->file_id) . ',' . $db->quote($row->rating_sum) . ',' . $db->quote($row->rating_count) . ',' . $db->quote($row->last_ip) . ' );"); $db->execute();$i++; ' . "\r\n"; } } } $date_current = JHtml::_('date', '', 'Y-m-d_H:i:s'); $file .= "\r\n?>"; header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header('Cache-Control: post-check=0, pre-check=0', false); header("Pragma: no-cache"); header("Content-type: text/plain"); header('Content-Disposition: attachment; filename="' . 'backup_jdownloads_v' . $jd_version . '_date_' . $date_current . '_.txt' . '"'); print $file; } exit; }
/** * logic to export a selected layout * */ public function export() { global $jlistConfig; $app = JFactory::getApplication(); $jinput = JFactory::getApplication()->input; $id = $this->input->get('cid', array(), 'array'); if (count($id) != 1) { // to much layouts selected $app->redirect(JRoute::_('index.php?option=com_jdownloads&view=templates&type=' . (int) $jinput->get('type'), false), JText::_('COM_JDOWNLOADS_LAYOUTS_EXPORT_MSG_COUNT_ERROR'), 'error'); } $id = $id[0]; $jd_version = JDownloadsHelper::getjDownloadsVersion(); $db = JFactory::getDBO(); $prefix = JDownloadsHelper::getCorrectDBPrefix(); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jdownloads' . DS . 'tables'); // load layout data $object = JTable::getInstance('template', 'jdownloadsTable'); $result = $object->load($id); if (!$result) { // abort $app->redirect(JRoute::_('index.php?option=com_jdownloads&view=templates&type=' . (int) $jinput->get('type'), false), JText::_('COM_JDOWNLOADS_LAYOUTS_EXPORT_MSG_ERROR'), 'error'); } else { switch ($object->template_typ) { case '1': $object->template_typ = 'categories'; break; case '4': $object->template_typ = 'category'; break; case '2': $object->template_typ = 'files'; break; case '5': $object->template_typ = 'details'; break; case '3': $object->template_typ = 'summary'; break; case '7': $object->template_typ = 'search'; break; } $file = '<?xml version="1.0" encoding="utf-8"?>' . "\r\n"; $file .= '<layout>' . "\r\n"; $file .= '<!-- This file is a jDownloads layout file -->' . "\r\n\r\n"; $file .= '<!-- Optional: -->' . "\r\n"; $file .= '<creation_date></creation_date>' . "\r\n\r\n"; $file .= '<!-- Optional: -->' . "\r\n"; $file .= '<author></author>' . "\r\n\r\n"; $file .= '<!-- The installed version of jDownloads should be at or later than the version shown below, as otherwise this layout may not work properly. The value is set automatically when a layout is exported (optional) -->' . "\r\n"; $file .= '<targetjdownloads>' . $jd_version . '</targetjdownloads>' . "\r\n\r\n"; $file .= '<!-- This is the name of the layout (required) -->' . "\r\n"; $file .= '<template_name>' . $object->template_name . '</template_name>' . "\r\n\r\n"; $file .= '<!-- Must be one of: categories, category, files, details, summary, search (required) -->' . "\r\n"; $file .= '<template_typ>' . $object->template_typ . '</template_typ>' . "\r\n\r\n"; $file .= '<!-- Start here with header, subheader and footer area -->' . "\r\n"; $file .= '<!-- Header Area Layout -->' . "\r\n"; $file .= '<template_header_text>' . "\r\n" . htmlentities($object->template_header_text) . "\r\n" . '</template_header_text>' . "\r\n\r\n"; $file .= '<!-- Sub Header Area Layout -->' . "\r\n"; $file .= '<template_subheader_text>' . "\r\n" . htmlentities($object->template_subheader_text) . "\r\n" . '</template_subheader_text>' . "\r\n\r\n"; $file .= '<!-- Footer Area Layout -->' . "\r\n"; $file .= '<template_footer_text>' . "\r\n" . htmlentities($object->template_footer_text) . "\r\n" . '</template_footer_text>' . "\r\n\r\n"; $file .= '<!-- Start here with main layout part -->' . "\r\n"; $file .= '<!-- Use Before Layout -->' . "\r\n"; $file .= '<template_before_text>' . "\r\n" . htmlentities($object->template_before_text) . "\r\n" . '</template_before_text>' . "\r\n\r\n"; $file .= '<!-- The Main Layout Field -->' . "\r\n"; $file .= '<template_text>' . "\r\n" . htmlentities($object->template_text) . "\r\n" . '</template_text>' . "\r\n\r\n"; $file .= '<!-- Use After Layout -->' . "\r\n"; $file .= '<template_after_text>' . "\r\n" . htmlentities($object->template_after_text) . "\r\n" . '</template_after_text>' . "\r\n\r\n"; $file .= '<!-- Should be allways 0 -->' . "\r\n"; $file .= '<template_active>0</template_active>' . "\r\n\r\n"; $file .= '<!-- Use 1 for default layout, normal value is 0. Default layouts cannot be deleted by the user. (required) -->' . "\r\n"; $file .= '<template_locked>0</template_locked>' . "\r\n\r\n"; $file .= '<!-- Layout description (optional) -->' . "\r\n"; $file .= '<note>' . "\r\n" . htmlentities($object->note) . "\r\n" . '</note>' . "\r\n\r\n"; $file .= '<!-- Number of columns - only required for categories layouts - default 1 -->' . "\r\n"; $file .= '<cols>' . (int) $object->cols . '</cols>' . "\r\n\r\n"; $file .= '<!-- Default = 1 - only usable in files layouts - use 0 when the layout has checkboxes for mass downloads -->' . "\r\n"; $file .= '<checkbox_off>' . (int) $object->checkbox_off . '</checkbox_off>' . "\r\n\r\n"; $file .= '<!-- Default = 0 - should only be 1 for categories layouts when the layout shall be used to list sub categories -->' . "\r\n"; $file .= '<use_to_view_subcats>' . (int) $object->use_to_view_subcats . '</use_to_view_subcats>' . "\r\n\r\n"; $file .= '<!-- Default = 1 - only usable in files and details layouts - use 0 when the layout is to use mini symbols for some main data -->' . "\r\n"; $file .= '<symbol_off>' . (int) $object->symbol_off . '</symbol_off>' . "\r\n\r\n"; $file .= '<!-- Use * for all languages (default) - Note: this language field is not used currently, it is a possible future use in layouts. -->' . "\r\n"; $file .= '<language>' . $object->language . '</language>' . "\r\n"; $file .= '</layout>'; $filename = 'exported_layout_jd_' . $jd_version . '_' . str_replace(' ', '_', $object->template_name . '.xml'); // SET HEADER TO OUTPUT DATA header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header('Content-type: text/xml'); header('Content-Disposition: attachment; filename="' . $filename . '"'); print $file; } exit; }