├── index.html
├── admin
├── index.html
├── js
│ ├── index.html
│ └── jquery.js
├── helpers
│ ├── index.html
│ └── upload.php
├── images
│ ├── index.html
│ ├── go.jpg
│ └── logo.png
├── include
│ ├── index.html
│ └── helper.php
├── models
│ ├── index.html
│ ├── global.php
│ ├── virtual.php
│ ├── extensions.php
│ └── sites.php
├── plugin
│ ├── index.html
│ ├── mtwFirstInstall.xml
│ └── mtwFirstInstall.php
├── sql
│ ├── index.html
│ ├── firstinstall.sql
│ └── install.sql
├── tables
│ ├── index.html
│ ├── extensions.php
│ └── sites.php
├── controllers
│ ├── index.html
│ ├── help.php
│ └── sites.php
├── extensions
│ └── index.html
├── languages
│ ├── index.html
│ ├── en-GB.com_mtwmultiple.ini
│ └── es-ES.com_mtwmultiple.ini
├── views
│ ├── global
│ │ ├── index.html
│ │ ├── tmpl
│ │ │ ├── index.html
│ │ │ └── default.php
│ │ └── view.html.php
│ ├── help
│ │ ├── index.html
│ │ ├── tmpl
│ │ │ ├── index.html
│ │ │ └── default.php
│ │ └── view.html.php
│ ├── sites
│ │ ├── index.html
│ │ ├── tmpl
│ │ │ ├── index.html
│ │ │ ├── default.php
│ │ │ └── form.php
│ │ └── view.html.php
│ ├── extensions
│ │ ├── index.html
│ │ ├── tmpl
│ │ │ ├── index.html
│ │ │ └── default.php
│ │ └── view.html.php
│ └── virtual
│ │ ├── index.html
│ │ ├── tmpl
│ │ ├── index.html
│ │ └── default.php
│ │ └── view.html.php
├── config.xml
├── controller.php
├── mtwmultiple.php
└── mtwmultiple.xml
├── site
└── index.html
├── TODO
├── sql
└── install_component.sql
└── mtwmultiple.xml
/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/js/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/site/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/helpers/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/images/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/include/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/models/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/plugin/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/sql/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/tables/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/controllers/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/extensions/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/languages/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/global/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/help/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/sites/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/extensions/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/global/tmpl/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/help/tmpl/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/sites/tmpl/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/virtual/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/extensions/tmpl/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/admin/views/virtual/tmpl/index.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | @ RELEASE 0.2.0
2 |
3 | = Fix Javascript email validation
4 | + Make sites editables
5 |
--------------------------------------------------------------------------------
/admin/images/go.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastslack/mtwMultiple/master/admin/images/go.jpg
--------------------------------------------------------------------------------
/admin/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fastslack/mtwMultiple/master/admin/images/logo.png
--------------------------------------------------------------------------------
/admin/languages/en-GB.com_mtwmultiple.ini:
--------------------------------------------------------------------------------
1 | COM_MTWMULTIPLE_CONFIGURATION="mtwMultiple Configuration"
2 | COM_CONFIG_GLOBAL_FIELDSET_LABEL="Global config"
3 |
4 |
--------------------------------------------------------------------------------
/admin/languages/es-ES.com_mtwmultiple.ini:
--------------------------------------------------------------------------------
1 | com_mtwmultiple_configuration="mtwMultiple Configuration"
2 | COM_CONFIG_GLOBAL_FIELDSET_LABEL="Global config"
3 |
4 |
--------------------------------------------------------------------------------
/sql/install_component.sql:
--------------------------------------------------------------------------------
1 | INSERT INTO `jos_components`
2 | (`name`, `link`, `menuid`, `parent`, `admin_menu_link`, `admin_menu_alt`, `option`, `ordering`, `admin_menu_img`, `iscore`, `params`, `enabled`)
3 | VALUES (mtwMultiple', 'option=com_mtwmultiple', 0, 0, 'option=com_mtwmultiple', 'mtwMultiple', 'com_mtwmultiple', 0, 'js/ThemeOffice/install.png', 0, '', 1);
4 |
5 |
--------------------------------------------------------------------------------
/admin/config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
--------------------------------------------------------------------------------
/admin/views/help/tmpl/default.php:
--------------------------------------------------------------------------------
1 |
13 |
20 |
--------------------------------------------------------------------------------
/admin/controller.php:
--------------------------------------------------------------------------------
1 |
36 |
--------------------------------------------------------------------------------
/admin/plugin/mtwFirstInstall.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | System - First Install
4 | Matias Aguirre
5 | 23/07/2009
6 | Copyright (C) 2008 Matware. All rights reserved.
7 | GNU General Public License
8 | maguirre@matware.com.ar
9 | http://www.matware.com.ar/
10 | 0.1.0
11 | This plugin install extensions from mtwMultiple at first time.
12 |
13 | mtwFirstInstall.php
14 |
15 |
24 |
25 |
--------------------------------------------------------------------------------
/admin/tables/extensions.php:
--------------------------------------------------------------------------------
1 | execute( JRequest::getVar('task'));
36 |
37 | // Redirect if set by the controller
38 | $controller->redirect();
39 |
--------------------------------------------------------------------------------
/admin/views/global/view.html.php:
--------------------------------------------------------------------------------
1 | assignRef('config', $mtwCFG);
37 |
38 | parent::display($tpl);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/admin/views/virtual/view.html.php:
--------------------------------------------------------------------------------
1 | assignRef('config', $mtwCFG);
47 | $this->assignRef('virtual', $virtual);
48 |
49 | parent::display($tpl);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/admin/models/global.php:
--------------------------------------------------------------------------------
1 | setId((int)$array[0]);
25 | }
26 |
27 | function saveConfig( $post ) {
28 |
29 | require_once('components/com_mtwmultiple/helpers/config.php' );
30 | jimport('joomla.filesystem.file');
31 |
32 | $configFile = JPATH_COMPONENT.'/mtwmultiple_config.php';
33 | if (JFile::exists( $configFile )) {
34 | require_once( $configFile );
35 | }else{
36 | JFile::copy( $configFile . '.orig', $configFile );
37 | }
38 |
39 | $path = ConfigHelper::removeSlash( $post['path'] );
40 |
41 | $configText = "\n";
45 |
46 | $return = JFile::write($configFile, $configText);
47 |
48 | return $return;
49 |
50 | }
51 |
52 | }
53 | ?>
54 |
--------------------------------------------------------------------------------
/admin/tables/sites.php:
--------------------------------------------------------------------------------
1 |
6 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | */
13 |
14 | // no direct access
15 | defined('_JEXEC') or die('Restricted access');
16 |
17 | /**
18 | * Working Copy Table class
19 | *
20 | */
21 | class TableSites extends JTable {
22 |
23 | var $id = null;
24 | var $name = '';
25 | var $title = '';
26 | var $email = '';
27 | var $create_by = '';
28 | var $created = '';
29 | var $passwd = '';
30 |
31 | function __construct(&$_db) {
32 | parent::__construct('#__mtwmultiple_sites', 'id', $_db);
33 | }
34 |
35 | /**
36 | * Overloaded check function
37 | *
38 | * @access public
39 | * @return boolean
40 | * @see JTable::check
41 | * @since 1.5
42 | */
43 | function getNewID() {
44 |
45 | $db =& $this->getDBO();
46 |
47 | $query = 'SELECT *'
48 | . ' FROM '.$this->_tbl
49 | . ' ORDER BY '.$this->_tbl_key.' DESC';
50 | $db->setQuery( $query );
51 |
52 | return $db->loadResult( )+1;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/admin/views/global/tmpl/default.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
57 |
--------------------------------------------------------------------------------
/admin/sql/install.sql:
--------------------------------------------------------------------------------
1 | --
2 | -- Table structure for table `#__mtwmultiple_sites`
3 | --
4 |
5 | CREATE TABLE IF NOT EXISTS `#__mtwmultiple_sites` (
6 | `id` int(11) NOT NULL AUTO_INCREMENT,
7 | `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
8 | `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
9 | `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
10 | `created_by` int(11) NOT NULL,
11 | `created` datetime NOT NULL,
12 | `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
13 | `checked_out` datetime NOT NULL,
14 | `checked_out_time` datetime NOT NULL,
15 | PRIMARY KEY (`id`)
16 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
17 |
18 | --
19 | -- Table structure for table `#__mtwmultiple_extensions`
20 | --
21 |
22 | CREATE TABLE IF NOT EXISTS `#__mtwmultiple_extensions` (
23 | `id` int(11) NOT NULL AUTO_INCREMENT,
24 | `filename` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
25 | `type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
26 | `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
27 | `author` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
28 | `creationDate` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
29 | `copyright` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
30 | `license` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
31 | `authorEmail` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
32 | `authorUrl` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
33 | `version` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
34 | `enable` int(11) NOT NULL DEFAULT '1',
35 | `checked_out` int(11) NOT NULL,
36 | `checked_out_time` datetime NOT NULL,
37 | PRIMARY KEY (`id`)
38 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
39 |
--------------------------------------------------------------------------------
/admin/views/extensions/view.html.php:
--------------------------------------------------------------------------------
1 | getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
37 | $limitstart = $mainframe->getUserStateFromRequest( 'limitstart', 'limitstart', 0, 'int' );
38 |
39 | // get the total number of records
40 | $query = 'SELECT COUNT(*)'
41 | . ' FROM #__mtwmultiple_extensions AS e';
42 |
43 | $db->setQuery( $query );
44 | $total = $db->loadResult();
45 |
46 | jimport('joomla.html.pagination');
47 | $pageNav = new JPagination( $total, $limitstart, $limit );
48 |
49 | $query = "SELECT e.*"
50 | . " FROM #__mtwmultiple_extensions AS e"
51 | . " ORDER BY e.type, e.name ASC";
52 | //echo $query;
53 |
54 | $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
55 | $rows = $db->loadObjectList();
56 | //print_r($db->getError());
57 |
58 | $this->assignRef('rows', $rows);
59 | $this->assignRef('lists', $lists);
60 | $this->assignRef('pageNav', $pageNav);
61 |
62 | parent::display($tpl);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/admin/models/virtual.php:
--------------------------------------------------------------------------------
1 | \n";
50 |
51 | $return = JFile::write($configFile, $configText);
52 |
53 | $virtualFile = JPATH_COMPONENT.'/mtwmultiple.virtualhost.conf';
54 |
55 | $vh = $_POST['virtual'];
56 | $vh = str_replace("\\", "", $vh);
57 |
58 | //print_r($vh);
59 | /*
60 | for($i = 0; $i < strlen($vh); $i++){
61 | // Pack this number into a 4-byte string
62 | // (Or multiple one-byte strings, depending on context.)
63 | echo "{$vh[$i]} ".ord($vh[$i]) . "
";
64 | //$str .= pack("N",$v);
65 | }
66 | */
67 | $return = JFile::write($virtualFile, $vh);
68 |
69 | return $return;
70 |
71 | }
72 | }
73 | ?>
74 |
--------------------------------------------------------------------------------
/admin/plugin/mtwFirstInstall.php:
--------------------------------------------------------------------------------
1 | id) {
40 |
41 | jimport( 'joomla.installer.installer' );
42 | jimport('joomla.installer.helper');
43 | $db =& JFactory::getDBO();
44 | //print_r($db);
45 |
46 | // Get packages to install
47 | $query = "SELECT fi.*"
48 | . " FROM #__mtwmultiple_firstinstall AS fi ORDER BY id ASC";
49 |
50 | //echo $query;
51 | $db->setQuery( $query );
52 | $rows = $db->loadObjectList();
53 |
54 | foreach ($rows as $p) {
55 | $filepath = JPATH_SITE.'/tmp/'.$p->filename;
56 | //print_r($rows);echo "
";
57 | $package = JInstallerHelper::unpack($filepath);
58 | //echo $package;
59 | $installer =& JInstaller::getInstance();
60 | $installer->install($package['dir']);
61 |
62 | $query = "DELETE FROM #__mtwmultiple_firstinstall WHERE id = " . $p->id;
63 | $db->setQuery( $query );
64 | $db->query();
65 | }
66 | }
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/admin/views/virtual/tmpl/default.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
71 |
--------------------------------------------------------------------------------
/mtwmultiple.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | mtwMultiple
5 |
6 | 2009-12-16
7 | Matias Aguirre
8 | maguirre@matware.com.ar
9 | http://www.matware.com.ar
10 | Copyleft 2006 - 2012
11 | GNU/GPL
12 |
13 | 2.5.0
14 |
15 | mtwMultiple allows Joomla duplications
16 |
17 |
18 |
19 | sql/install.sql
20 |
21 |
22 |
23 |
24 |
27 |
28 | index.html
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 | index.html
41 | admin.mtwmultiple.php
42 | config.xml
43 | controller.php
44 |
45 | controllers
46 | css
47 | extensions
48 | helpers
49 | include
50 | js
51 | languages
52 | models
53 | plugin
54 | sql
55 | tables
56 | views
57 |
58 |
59 |
60 | languages/es-ES.com_mtwmultiple.ini
61 | languages/en-GB.com_mtwmultiple.ini
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/admin/mtwmultiple.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | mtwMultiple
5 |
6 | 2009-12-16
7 | Matias Aguirre
8 | maguirre@matware.com.ar
9 | http://www.matware.com.ar
10 | Copyleft 2006 - 2012
11 | GNU/GPL
12 |
13 | 2.5.0
14 |
15 | mtwMultiple allows Joomla duplications
16 |
17 |
18 |
19 | sql/install.sql
20 |
21 |
22 |
23 |
24 |
27 |
28 | index.html
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 | index.html
41 | admin.mtwmultiple.php
42 | config.xml
43 | controller.php
44 |
45 | controllers
46 | css
47 | extensions
48 | helpers
49 | include
50 | js
51 | languages
52 | models
53 | plugin
54 | sql
55 | tables
56 | views
57 |
58 |
59 |
60 | languages/es-ES.com_mtwmultiple.ini
61 | languages/en-GB.com_mtwmultiple.ini
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/admin/controllers/sites.php:
--------------------------------------------------------------------------------
1 | getModel('sites');
47 |
48 | $data = JRequest::get( 'post' );
49 |
50 | if ($model->addSiteFiles($data)) {
51 | $msg = JText::_( 'Joomla Site Added!' );
52 | } else {
53 | $msg = JText::_( 'Error Creating Files' );
54 | }
55 |
56 | if ($model->addSiteDB($data) != false) {
57 | $msg = JText::_( 'Joomla Site Added!' );
58 | } else {
59 | $msg = JText::_( 'Error With DB Insertion' );
60 | }
61 |
62 |
63 | if ($model->addSiteConfig($data)) {
64 | $msg = JText::_( 'Joomla Site Added!' );
65 | } else {
66 | $msg = JText::_( 'Error Creating Config File' );
67 | }
68 |
69 | // @@ TODO -> Check if extensions exists
70 | if ($model->addExtensions($data)) {
71 | $msg = JText::_( 'Joomla Site Added!' );
72 | } else {
73 | $msg = JText::_( 'Error Creating Config File' );
74 | }
75 |
76 | //print_r($data);
77 | if ($data['vh'] == 1) {
78 | if ($model->addVirtual($data)) {
79 | $msg = JText::_( 'Joomla Site Added!' );
80 | } else {
81 | $msg = JText::_( 'Error Creating Config File' );
82 | }
83 | }
84 |
85 | $link = 'index.php?option=com_mtwmultiple&controller=sites';
86 | $this->setRedirect($link, $msg);
87 | }
88 |
89 | /**
90 | * cancel editing a record
91 | * @return void
92 | */
93 | function cancel()
94 | {
95 | $msg = JText::_( 'Configuration Cancelled' );
96 | $this->setRedirect( 'index.php?option=com_mtwmultiple', $msg );
97 | }
98 |
99 | /**
100 | * remove delete a record
101 | * @return void
102 | */
103 | function remove()
104 | {
105 | // Check for request forgeries
106 | JRequest::checkToken() or jexit( 'Invalid Token' );
107 |
108 | $this->setRedirect( 'index.php?option=com_mtwmultiple&controller=sites' );
109 |
110 | // Initialize variables
111 | $db =& JFactory::getDBO();
112 | $hid = JRequest::getVar( 'cid', array(), 'post', 'array' );
113 | $n = count( $hid );
114 |
115 | $model = $this->getModel('sites');
116 | for($count = 0; $count < $n; $count++) {
117 | $element = $hid[$count];
118 | $model->removeSiteDB($hid[$count]);
119 | $model->removeSiteFiles($hid[$count]);
120 | $query = 'DELETE FROM #__mtwmultiple_sites'
121 | . ' WHERE id = ' . implode( ' OR id = ', $hid );
122 |
123 | $db->setQuery( $query );
124 | if (!$db->query()) {
125 | JError::raiseWarning( 500, $db->getError() );
126 | }
127 | }
128 |
129 | $this->setMessage( JText::sprintf( 'Items removed', $n ) );
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/admin/views/extensions/tmpl/default.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 | |
19 |
20 |
50 |
110 | |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/admin/views/sites/tmpl/default.php:
--------------------------------------------------------------------------------
1 | status);
14 | //print_r($this->pageNav);
15 |
16 | JHTML::_('behavior.tooltip');
17 | ?>
18 |
124 |
--------------------------------------------------------------------------------
/admin/views/sites/view.html.php:
--------------------------------------------------------------------------------
1 | getLayout() == 'form') {
24 | $this->_displayForm($tpl);
25 | return;
26 | }
27 |
28 | // Load the parameters.
29 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
30 |
31 | JToolBarHelper::title( JText::_( 'mtwMultiple Sites' ), 'plugin.png' );
32 | JToolBarHelper::back();
33 | JToolBarHelper::deleteList();
34 | JToolBarHelper :: custom( 'add', 'new.png', 'new.png', 'Add Site', false, false );
35 | JToolBarHelper::spacer();
36 | // Add an upload button and view a popup screen width 550 and height 400
37 | $alt = "Manage Extensions";
38 | $bar=& JToolBar::getInstance( 'toolbar' );
39 | $bar->appendButton( 'Popup', 'upload', $alt, 'index.php?option=com_mtwmultiple&controller=extensions&tmpl=component', 850, 500 );
40 | JToolBarHelper::preferences('com_mtwmultiple');
41 | JToolBarHelper::spacer();
42 |
43 | $db =& JFactory::getDBO();
44 |
45 | $filter_order = $mainframe->getUserStateFromRequest( 'filter_order', 'filter_order', 's.id', 'cmd' );
46 | $filter_order_Dir = $mainframe->getUserStateFromRequest( 'filter_order_Dir', 'filter_order_Dir', '', 'word' );
47 | $search = $mainframe->getUserStateFromRequest( 'search','search','','string' );
48 |
49 | $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
50 | $limitstart = $mainframe->getUserStateFromRequest( 'limitstart', 'limitstart', 0, 'int' );
51 |
52 | $where = array();
53 |
54 | if ($search) {
55 | $where[] = 'LOWER(s.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
56 | }
57 |
58 | if ($filter_order == '') {
59 | $filter_order = 's.id';
60 | }
61 |
62 | $where = count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '';
63 | //$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
64 | $orderby = ' ORDER BY id ASC';
65 |
66 | // get the total number of records
67 | $query = 'SELECT COUNT(*)'
68 | . ' FROM #__mtwmultiple_sites AS s'
69 | . $where;
70 |
71 | $db->setQuery( $query );
72 | $total = $db->loadResult();
73 |
74 | jimport('joomla.html.pagination');
75 | $pageNav = new JPagination( $total, $limitstart, $limit );
76 |
77 | $query = 'SELECT s.*, u.username'
78 | . ' FROM #__mtwmultiple_sites AS s'
79 | . ' LEFT JOIN #__users AS u ON u.id = s.created_by'
80 | . $where
81 | . $orderby;
82 | //echo $query;
83 |
84 | $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
85 | $rows = $db->loadObjectList();
86 | print_r($db->getError());
87 |
88 | // table ordering
89 | $lists['order_Dir'] = $filter_order_Dir;
90 | $lists['order'] = $filter_order;
91 |
92 | // search filter
93 | $lists['search']= $search;
94 |
95 | $this->assignRef('rows', $rows);
96 | $this->assignRef('lists', $lists);
97 | $this->assignRef('pageNav', $pageNav);
98 | $this->assignRef('params', $params);
99 |
100 | parent::display($tpl);
101 | }
102 |
103 | function _displayForm ($tpl = null) {
104 |
105 | $mainframe = JFactory::getApplication();
106 |
107 | JToolBarHelper::title( JText::_( 'Add Joomla Site' ), 'plugin.png' );
108 | //JToolBarHelper::deleteList();
109 | //JToolBarHelper::editListX();
110 | //JToolBarHelper::addNewX();
111 | JToolBarHelper::cancel();
112 | JToolBarHelper::save();
113 | JToolBarHelper::spacer();
114 |
115 | $db =& JFactory::getDBO();
116 |
117 | $query = "SELECT e.id, CONCAT(e.name, ' ', e.version) as name"
118 | . " FROM #__mtwmultiple_extensions AS e"
119 | . " WHERE e.enable = 1 ORDER BY name ASC";
120 |
121 | //echo $query;
122 |
123 | $db->setQuery( $query );
124 | $rows = $db->loadObjectList();
125 |
126 | //print_r($rows);
127 |
128 | /*
129 | jimport("joomla.html.html.select"); Not work?
130 | */
131 | include_once JPATH_ROOT . "/libraries/joomla/html/html/select.php";
132 | $options = JHTMLSelect::Options( $rows, "id", "name" );
133 |
134 | $tblSites = new TableSites($db);
135 |
136 | $c_db = new JObject;
137 | $c_db->set('c_hostname', $mainframe->getCfg('host'));
138 | $c_db->set('c_username', $mainframe->getCfg('user'));
139 | $c_db->set('c_password', $mainframe->getCfg('password'));
140 | $c_db->set('c_database', $mainframe->getCfg('db'));
141 | $c_db->set('c_prefix', 'mtw'.$tblSites->getNewID().'_');
142 |
143 | $m_db = new JObject;
144 | $m_db->set('m_hostname', $mainframe->getCfg('host'));
145 | $m_db->set('m_username', $mainframe->getCfg('user'));
146 | $m_db->set('m_password', $mainframe->getCfg('password'));
147 | $m_db->set('m_database', $mainframe->getCfg('db'));
148 | $m_db->set('m_prefix', $mainframe->getCfg('dbprefix'));
149 |
150 | $lists['vh'] = JHTML::_('select.booleanlist', 'vh', 'disabled', 0);
151 |
152 | $this->assignRef('options', $options);
153 | $this->assignRef('lists', $lists);
154 | $this->assignRef('m_db', $m_db);
155 | $this->assignRef('c_db', $c_db);
156 |
157 | parent::display($tpl);
158 | }
159 |
160 | }
161 | ?>
162 |
--------------------------------------------------------------------------------
/admin/models/extensions.php:
--------------------------------------------------------------------------------
1 | setId((int)$array[0]);
25 | }
26 |
27 | /**
28 | * Upload a file
29 | *
30 | * @since 1.5
31 | */
32 | function upload()
33 | {
34 |
35 | $mainframe = JFactory::getApplication();
36 |
37 | require_once('components/com_mtwmultiple/helpers/upload.php' );
38 |
39 | // Check for request forgeries
40 | //JRequest::checkToken( 'request' ) or jexit( 'Invalid Token' );
41 |
42 | $file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
43 | //$folder = JRequest::getVar( 'folder', '', '', 'path' );
44 | $format = JRequest::getVar( 'format', 'html', '', 'cmd');
45 | $return = JRequest::getVar( 'return-url', null, 'post', 'base64' );
46 |
47 | $err = null;
48 |
49 | // Set FTP credentials, if given
50 | jimport('joomla.client.helper');
51 | JClientHelper::setCredentialsFromRequest('ftp');
52 |
53 | // Make the filename safe
54 | jimport('joomla.filesystem.file');
55 | $file['name'] = JFile::makeSafe($file['name']);
56 |
57 | if (isset($file['name'])) {
58 | $filepath = JPath::clean('components/com_mtwmultiple/extensions/'.strtolower($file['name']));
59 |
60 | if (!UploadHelper::canUpload( $file, $err )) {
61 | if ($format == 'json') {
62 | jimport('joomla.error.log');
63 | $log = &JLog::getInstance('upload.error.php');
64 | $log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err));
65 | header('HTTP/1.0 415 Unsupported Media Type');
66 | jexit('Error. Unsupported Media Type!');
67 | } else {
68 | JError::raiseNotice(100, JText::_($err));
69 | // REDIRECT
70 | if ($return) {
71 | $mainframe->redirect(base64_decode($return));
72 | }
73 | return;
74 | }
75 | }
76 |
77 | if (JFile::exists($filepath)) {
78 | if ($format == 'json') {
79 | jimport('joomla.error.log');
80 | $log = &JLog::getInstance('upload.error.php');
81 | $log->addEntry(array('comment' => 'File already exists: '.$filepath));
82 | header('HTTP/1.0 409 Conflict');
83 | jexit('Error. File already exists');
84 | } else {
85 | JError::raiseNotice(100, JText::_('Error. File already exists'));
86 | // REDIRECT
87 | if ($return) {
88 | $mainframe->redirect(base64_decode($return));
89 | }
90 | return;
91 | }
92 | }
93 |
94 | if (!JFile::upload($file['tmp_name'], $filepath)) {
95 | if ($format == 'json') {
96 | jimport('joomla.error.log');
97 | $log = &JLog::getInstance('upload.error.php');
98 | $log->addEntry(array('comment' => 'Cannot upload: '.$filepath));
99 | header('HTTP/1.0 400 Bad Request');
100 | jexit('Error. Unable to upload file');
101 | } else {
102 | JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
103 | // REDIRECT
104 | if ($return) {
105 | $mainframe->redirect(base64_decode($return));
106 | }
107 | return;
108 | }
109 | } else {
110 | if ($format == 'json') {
111 | jimport('joomla.error.log');
112 | $log = &JLog::getInstance();
113 | $log->addEntry(array('comment' => $folder));
114 | jexit('Upload complete');
115 | } else {
116 | //$mainframe->enqueueMessage(JText::_('Upload complete'));
117 | // REDIRECT
118 | //if ($return) {
119 | // $mainframe->redirect(base64_decode($return));
120 | //}
121 | $this->install($filepath);
122 | return true;
123 | }
124 | }
125 | } else {
126 | $mainframe->redirect('index.php', 'Invalid Request', 'error');
127 | }
128 | }
129 |
130 | /**
131 | * Upload a file
132 | *
133 | * @since 1.5
134 | */
135 | function install($filepath)
136 | {
137 | global $mainframe;
138 |
139 | //echo $filepath;
140 | jimport('joomla.installer.helper');
141 |
142 | $package = JInstallerHelper::unpack($filepath);
143 | //print_r($package);
144 |
145 | $files = JFolder::files(JPATH_ADMINISTRATOR.'/'.$package['dir'], '\.xml$', 1, true);
146 | //print_r($files);
147 |
148 | $db =& JFactory::getDBO();
149 |
150 |
151 | if (count($files) > 0) {
152 | foreach ($files as $file) {
153 |
154 | $xml = simplexml_load_file($file);
155 | //echo $xml->getName() . "
";
156 |
157 | if ($xml->getName() == "mosinstall" || $xml->getName() == "install") {
158 | //print_r($xml);
159 | //echo $xml["type"];
160 |
161 | $type = $db->quote( $db->getEscaped( $xml["type"] ) );
162 | $name = $db->quote( $db->getEscaped( $xml->name ) );
163 | $author = $db->quote( $db->getEscaped( $xml->author ) );
164 | $creationDate = $db->quote( $db->getEscaped( $xml->creationDate ) );
165 | $copyright = $db->quote( $db->getEscaped( $xml->copyright ) );
166 | $license = $db->quote( $db->getEscaped( $xml->license ) );
167 |
168 | // Insert extension
169 | $query = "INSERT INTO #__mtwmultiple_extensions "
170 | . " (filename, type, name, author, creationDate, copyright, license, authorEmail, authorUrl, version)"
171 | . " VALUES ('". basename($filepath) ."', {$type}, {$name}, {$author},"
172 | . "{$creationDate}, {$copyright}, {$license}, "
173 | . "'". $xml->authorEmail ."','". $xml->authorUrl ."','". $xml->version ."')";
174 | $db->setQuery( $query );
175 | $result = $db->query();
176 |
177 | echo $query . "
";
178 | echo $xml->getName() . "
";
179 | break;
180 | }
181 |
182 | }
183 | }
184 |
185 | jimport('joomla.filesystem.file');
186 | JFolder::delete(JPATH_ADMINISTRATOR.'/'.$package['extractdir']);
187 | }
188 | }
189 | ?>
190 |
--------------------------------------------------------------------------------
/admin/helpers/upload.php:
--------------------------------------------------------------------------------
1 | get( 'upload_extensions' ));
68 | $ignored = explode(',', $params->get( 'ignore_extensions' ));
69 | /*
70 |
71 | if (!in_array($format, $allowable) && !in_array($format,$ignored))
72 | {
73 | $err = 'WARNFILETYPE';
74 | return false;
75 | }
76 |
77 | $maxSize = (int) $params->get( 'upload_maxsize', 0 );
78 | if ($maxSize > 0 && (int) $file['size'] > $maxSize)
79 | {
80 | $err = 'WARNFILETOOLARGE';
81 | return false;
82 | }
83 | */
84 | $user = JFactory::getUser();
85 | $imginfo = null;
86 | if($params->get('restrict_uploads',1) ) {
87 | $images = explode( ',', $params->get( 'image_extensions' ));
88 | if(in_array($format, $images)) { // if its an image run it through getimagesize
89 | if(($imginfo = getimagesize($file['tmp_name'])) === FALSE) {
90 | $err = 'WARNINVALIDIMG';
91 | return false;
92 | }
93 | } else if(!in_array($format, $ignored)) {
94 | // if its not an image...and we're not ignoring it
95 | $allowed_mime = explode(',', $params->get('upload_mime'));
96 | $illegal_mime = explode(',', $params->get('upload_mime_illegal'));
97 | if(function_exists('finfo_open') && $params->get('check_mime',1)) {
98 | // We have fileinfo
99 | $finfo = finfo_open(FILEINFO_MIME);
100 | $type = finfo_file($finfo, $file['tmp_name']);
101 | if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
102 | $err = 'WARNINVALIDMIME';
103 | return false;
104 | }
105 | finfo_close($finfo);
106 | } else if(function_exists('mime_content_type') && $params->get('check_mime',1)) {
107 | // we have mime magic
108 | $type = mime_content_type($file['tmp_name']);
109 | if(strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) {
110 | $err = 'WARNINVALIDMIME';
111 | return false;
112 | }
113 | } else if(!$user->authorize( 'login', 'administrator' )) {
114 | $err = 'WARNNOTADMIN';
115 | return false;
116 | }
117 | }
118 | }
119 |
120 | $xss_check = JFile::read($file['tmp_name'],false,256);
121 | $html_tags = array('abbr','acronym','address','applet','area','audioscope','base','basefont','bdo','bgsound','big','blackface','blink','blockquote','body','bq','br','button','caption','center','cite','code','col','colgroup','comment','custom','dd','del','dfn','dir','div','dl','dt','em','embed','fieldset','fn','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','iframe','ilayer','img','input','ins','isindex','keygen','kbd','label','layer','legend','li','limittext','link','listing','map','marquee','menu','meta','multicol','nobr','noembed','noframes','noscript','nosmartquotes','object','ol','optgroup','option','param','plaintext','pre','rt','ruby','s','samp','script','select','server','shadow','sidebar','small','spacer','span','strike','strong','style','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','ul','var','wbr','xml','xmp','!DOCTYPE', '!--');
122 | foreach($html_tags as $tag) {
123 | // A tag is ''
124 | if(stristr($xss_check, '<'.$tag.' ') || stristr($xss_check, '<'.$tag.'>')) {
125 | $err = 'WARNIEXSS';
126 | return false;
127 | }
128 | }
129 | return true;
130 | }
131 |
132 | function parseSize($size)
133 | {
134 | if ($size < 1024) {
135 | return $size . ' bytes';
136 | }
137 | else
138 | {
139 | if ($size >= 1024 && $size < 1024 * 1024) {
140 | return sprintf('%01.2f', $size / 1024.0) . ' Kb';
141 | } else {
142 | return sprintf('%01.2f', $size / (1024.0 * 1024)) . ' Mb';
143 | }
144 | }
145 | }
146 |
147 | function imageResize($width, $height, $target)
148 | {
149 | //takes the larger size of the width and height and applies the
150 | //formula accordingly...this is so this script will work
151 | //dynamically with any size image
152 | if ($width > $height) {
153 | $percentage = ($target / $width);
154 | } else {
155 | $percentage = ($target / $height);
156 | }
157 |
158 | //gets the new value and applies the percentage, then rounds the value
159 | $width = round($width * $percentage);
160 | $height = round($height * $percentage);
161 |
162 | return array($width, $height);
163 | }
164 |
165 | function countFiles( $dir )
166 | {
167 | $total_file = 0;
168 | $total_dir = 0;
169 |
170 | if (is_dir($dir)) {
171 | $d = dir($dir);
172 |
173 | while (false !== ($entry = $d->read())) {
174 | if (substr($entry, 0, 1) != '.' && is_file($dir . DIRECTORY_SEPARATOR . $entry) && strpos($entry, '.html') === false && strpos($entry, '.php') === false) {
175 | $total_file++;
176 | }
177 | if (substr($entry, 0, 1) != '.' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
178 | $total_dir++;
179 | }
180 | }
181 |
182 | $d->close();
183 | }
184 |
185 | return array ( $total_file, $total_dir );
186 | }
187 |
188 | }
189 |
--------------------------------------------------------------------------------
/admin/views/sites/tmpl/form.php:
--------------------------------------------------------------------------------
1 |
13 |
14 |
53 |
72 |
73 |
74 |
75 |
238 |
--------------------------------------------------------------------------------
/admin/models/sites.php:
--------------------------------------------------------------------------------
1 | setId((int)$array[0]);
27 | }
28 |
29 |
30 | function addSiteFiles( $post ) {
31 |
32 | $mainframe = JFactory::getApplication();
33 |
34 | // Load the parameters.
35 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
36 |
37 | /* Insert into Database */
38 | $my =& JFactory::getUser();
39 | $db =& JFactory::getDBO();
40 |
41 | jimport('joomla.user.helper');
42 | $adminPassword = $post['password'];
43 |
44 | // Create random salt/password for the admin user
45 | $salt = JUserHelper::genRandomPassword(32);
46 | $crypt = JUserHelper::getCryptedPassword($adminPassword, $salt);
47 | $cryptpass = $crypt.':'.$salt;
48 |
49 | $query = "INSERT INTO #__mtwmultiple_sites (name, title, email, created_by, created, password)"
50 | ." VALUES ('" . $post['name'] . "', '" . $post['title'] . "', '" . $post['email'] . "', " . $my->id . ", NOW(), " .$db->Quote($cryptpass)." )";
51 | $db->setQuery( $query );
52 |
53 | if (!$db->query()) {
54 | return $db->getErrorMsg();
55 | }
56 |
57 | /* Create Joomla Installation */
58 | $query = "SELECT id FROM #__mtwmultiple_sites ORDER BY id DESC LIMIT 1";
59 | $db->setQuery( $query );
60 | $siteID = $db->loadResult();
61 |
62 | $sitesPath = JPATH_SITE.'/'.$params->get( 'path' );
63 | $newSitePath = $sitesPath.'/'.$siteID;
64 |
65 | if (!JFolder::exists( $sitesPath )) {
66 | JFolder::create( $sitesPath );
67 | }
68 |
69 | // Create the directory of the installation
70 | JFolder::create( $newSitePath);
71 | // Symlink the title to the installation directory
72 | symlink ( $siteID, $sitesPath.'/'.$post['title'] );
73 |
74 | /* index.php */
75 | JFile::copy( JPATH_SITE .'/index.php', $newSitePath.'/index.php');
76 |
77 | /* Administrator Files */
78 | JFolder::create( $newSitePath.'/administrator');
79 | JFolder::create( $newSitePath.'/administrator/backups');
80 | JFile::copy( JPATH_SITE .'/cache/index.html', $newSitePath.'/administrator/backups/index.html');
81 | JFolder::create( $newSitePath.'/administrator/cache');
82 | JFile::copy( JPATH_SITE .'/cache/index.html', $newSitePath.'/administrator/cache/index.html');
83 | JFolder::create( $newSitePath.'/administrator/components');
84 | symlink ( JPATH_ADMINISTRATOR .'/components/com_admin', $newSitePath .'/administrator/components/com_admin');
85 | symlink ( JPATH_ADMINISTRATOR .'/components/com_banners', $newSitePath .'/administrator/components/com_banners');
86 | symlink ( JPATH_ADMINISTRATOR .'/components/com_cache', $newSitePath .'/administrator/components/com_cache');
87 | symlink ( JPATH_ADMINISTRATOR .'/components/com_categories', $newSitePath .'/administrator/components/com_categories');
88 | symlink ( JPATH_ADMINISTRATOR .'/components/com_checkin', $newSitePath .'/administrator/components/com_checkin');
89 | symlink ( JPATH_ADMINISTRATOR .'/components/com_config', $newSitePath .'/administrator/components/com_config');
90 | symlink ( JPATH_ADMINISTRATOR .'/components/com_contact', $newSitePath .'/administrator/components/com_contact');
91 | symlink ( JPATH_ADMINISTRATOR .'/components/com_content', $newSitePath .'/administrator/components/com_content');
92 | symlink ( JPATH_ADMINISTRATOR .'/components/com_cpanel', $newSitePath .'/administrator/components/com_cpanel');
93 | symlink ( JPATH_ADMINISTRATOR .'/components/com_finder', $newSitePath .'/administrator/components/com_finder');
94 | symlink ( JPATH_ADMINISTRATOR .'/components/com_installer', $newSitePath .'/administrator/components/com_installer');
95 | symlink ( JPATH_ADMINISTRATOR .'/components/com_languages', $newSitePath .'/administrator/components/com_languages');
96 | symlink ( JPATH_ADMINISTRATOR .'/components/com_login', $newSitePath .'/administrator/components/com_login');
97 | symlink ( JPATH_ADMINISTRATOR .'/components/com_media', $newSitePath .'/administrator/components/com_media');
98 | symlink ( JPATH_ADMINISTRATOR .'/components/com_menus', $newSitePath .'/administrator/components/com_menus');
99 | symlink ( JPATH_ADMINISTRATOR .'/components/com_messages', $newSitePath .'/administrator/components/com_messages');
100 | symlink ( JPATH_ADMINISTRATOR .'/components/com_modules', $newSitePath .'/administrator/components/com_modules');
101 | symlink ( JPATH_ADMINISTRATOR .'/components/com_newsfeeds', $newSitePath .'/administrator/components/com_newsfeeds');
102 | symlink ( JPATH_ADMINISTRATOR .'/components/com_plugins', $newSitePath .'/administrator/components/com_plugins');
103 | symlink ( JPATH_ADMINISTRATOR .'/components/com_search', $newSitePath .'/administrator/components/com_search');
104 | symlink ( JPATH_ADMINISTRATOR .'/components/com_templates', $newSitePath .'/administrator/components/com_templates');
105 | symlink ( JPATH_ADMINISTRATOR .'/components/com_users', $newSitePath .'/administrator/components/com_users');
106 | symlink ( JPATH_ADMINISTRATOR .'/components/com_weblinks', $newSitePath .'/administrator/components/com_weblinks');
107 | symlink ( JPATH_ADMINISTRATOR .'/help', $newSitePath .'/administrator/help');
108 | symlink ( JPATH_ADMINISTRATOR .'/images', $newSitePath .'/administrator/images');
109 | symlink ( JPATH_ADMINISTRATOR .'/includes', $newSitePath .'/administrator/includes');
110 | JFile::copy( JPATH_ADMINISTRATOR .'/index.php', $newSitePath.'/administrator/index.php');
111 | JFolder::copy( JPATH_ADMINISTRATOR .'/language/', $newSitePath.'/administrator/language/');
112 | //symlink ( JPATH_ADMINISTRATOR .'/language/index.html', $newSitePath .'/administrator/language/index.html');
113 | //symlink ( JPATH_ADMINISTRATOR .'/language/en-GB', $newSitePath .'/administrator/language/en-GB');
114 | symlink ( JPATH_ADMINISTRATOR .'/modules', $newSitePath .'/administrator/modules');
115 | // Admin Templates
116 | JFolder::copy( JPATH_ADMINISTRATOR .'/templates/', $newSitePath.'/administrator/templates/');
117 |
118 |
119 | /* Site Components Files */
120 | JFolder::create( $newSitePath.'/components');
121 | symlink ( JPATH_SITE .'/components/com_banners', $newSitePath .'/components/com_banners');
122 | symlink ( JPATH_SITE .'/components/com_contact', $newSitePath .'/components/com_contact');
123 | symlink ( JPATH_SITE .'/components/com_content', $newSitePath .'/components/com_content');
124 | symlink ( JPATH_SITE .'/components/com_mailto', $newSitePath .'/components/com_mailto');
125 | symlink ( JPATH_SITE .'/components/com_media', $newSitePath .'/components/com_media');
126 | symlink ( JPATH_SITE .'/components/com_newsfeeds', $newSitePath .'/components/com_newsfeeds');
127 | symlink ( JPATH_SITE .'/components/com_poll', $newSitePath .'/components/com_poll');
128 | symlink ( JPATH_SITE .'/components/com_search', $newSitePath .'/components/com_search');
129 | symlink ( JPATH_SITE .'/components/com_user', $newSitePath .'/components/com_users');
130 | symlink ( JPATH_SITE .'/components/com_weblinks', $newSitePath .'/components/com_weblinks');
131 | symlink ( JPATH_SITE .'/components/com_wrapper', $newSitePath .'/components/com_wrapper');
132 |
133 | JFolder::copy( JPATH_SITE .'/images/', $newSitePath.'/images');
134 |
135 | symlink ( JPATH_SITE .'/includes', $newSitePath .'/includes');
136 | //symlink ( JPATH_SITE .'/installation', $newSitePath .'/installation');
137 | JFolder::copy( JPATH_SITE .'/language/', $newSitePath.'/language');
138 | symlink ( JPATH_SITE .'/libraries', $newSitePath .'/libraries');
139 |
140 | JFolder::copy( JPATH_SITE .'/logs/', $newSitePath.'/logs');
141 | JFolder::copy( JPATH_SITE .'/media/', $newSitePath.'/media');
142 | JFolder::create( $newSitePath.'/modules');
143 | symlink ( JPATH_SITE .'/modules/mod_archive', $newSitePath .'/modules/mod_archive');
144 | symlink ( JPATH_SITE .'/modules/mod_banners', $newSitePath .'/modules/mod_banners');
145 | symlink ( JPATH_SITE .'/modules/mod_breadcrumbs', $newSitePath .'/modules/mod_breadcrumbs');
146 | symlink ( JPATH_SITE .'/modules/mod_custom', $newSitePath .'/modules/mod_custom');
147 | symlink ( JPATH_SITE .'/modules/mod_feed', $newSitePath .'/modules/mod_feed');
148 | symlink ( JPATH_SITE .'/modules/mod_footer', $newSitePath .'/modules/mod_footer');
149 | symlink ( JPATH_SITE .'/modules/mod_latestnews', $newSitePath .'/modules/mod_latestnews');
150 | symlink ( JPATH_SITE .'/modules/mod_login', $newSitePath .'/modules/mod_login');
151 | symlink ( JPATH_SITE .'/modules/mod_mainmenu', $newSitePath .'/modules/mod_mainmenu');
152 | symlink ( JPATH_SITE .'/modules/mod_mostread', $newSitePath .'/modules/mod_mostread');
153 | symlink ( JPATH_SITE .'/modules/mod_newsflash', $newSitePath .'/modules/mod_newsflash');
154 | symlink ( JPATH_SITE .'/modules/mod_random_image', $newSitePath .'/modules/mod_random_image');
155 | symlink ( JPATH_SITE .'/modules/mod_related_items', $newSitePath .'/modules/mod_related_items');
156 | symlink ( JPATH_SITE .'/modules/mod_search', $newSitePath .'/modules/mod_search');
157 | symlink ( JPATH_SITE .'/modules/mod_sections', $newSitePath .'/modules/mod_sections');
158 | symlink ( JPATH_SITE .'/modules/mod_stats', $newSitePath .'/modules/mod_stats');
159 | symlink ( JPATH_SITE .'/modules/mod_syndicate', $newSitePath .'/modules/mod_syndicate');
160 | symlink ( JPATH_SITE .'/modules/mod_whosonline', $newSitePath .'/modules/mod_whosonline');
161 | symlink ( JPATH_SITE .'/modules/mod_wrapper', $newSitePath .'/modules/mod_wrapper');
162 |
163 | /* Plugins */
164 | JFolder::copy( JPATH_SITE .'/plugins/', $newSitePath.'/plugins');
165 | // Install mtwFirstInstall plugin
166 | $pluginPHP = JPATH_ADMINISTRATOR .'/components'.'/com_mtwmultiple'.'/plugin'.'/mtwFirstInstall.php';
167 | $pluginXML = JPATH_ADMINISTRATOR .'/components'.'/com_mtwmultiple'.'/plugin'.'/mtwFirstInstall.xml';
168 | JFile::copy( $pluginPHP, $newSitePath.'/plugins'.'/system'.'/mtwFirstInstall.php');
169 | JFile::copy( $pluginXML, $newSitePath.'/plugins'.'/system'.'/mtwFirstInstall.xml');
170 |
171 | /* FIX!! Templates */
172 | JFolder::copy( JPATH_SITE .'/templates/', $newSitePath.'/templates');
173 | /*
174 | JFolder::create( $newSitePath.'/templates');
175 | //symlink ( JPATH_SITE .'/templates', $newSitePath .'/templates');
176 | symlink ( JPATH_SITE .'/templates'.'/beez', $newSitePath .'/templates'.'/beez');
177 | symlink ( JPATH_SITE .'/templates'.'/ja_purity', $newSitePath .'/templates'.'/ja_purity');
178 | symlink ( JPATH_SITE .'/templates'.'/rhuk_milkyway', $newSitePath .'/templates'.'/rhuk_milkyway');
179 | symlink ( JPATH_SITE .'/templates'.'/system', $newSitePath .'/templates'.'/system');
180 | */
181 |
182 | JFolder::create( $newSitePath.'/tmp');
183 |
184 | symlink ( JPATH_SITE .'/xmlrpc', $newSitePath .'/xmlrpc');
185 |
186 |
187 | return true;
188 |
189 | }
190 |
191 | function addSiteDB( $post ) {
192 |
193 | $mainframe = JFactory::getApplication();
194 |
195 | $db =& JFactory::getDBO();
196 | $config =& JFactory::getConfig();
197 | require_once( JPATH_ADMINISTRATOR.'/components'.'/com_mtwmultiple'.'/include'.'/helper.php');
198 |
199 | $dbtype = $config->getValue('config.dbtype');
200 | $host = $post['c_hostname'];
201 | $user = $post['c_username'];
202 | $password = $post['c_password'];
203 | $dbname = $post['c_database'];
204 | $dbprefix = $post['c_prefix'];
205 |
206 | $newDB = & JInstallationHelper::getDBO($dbtype, $host, $user, $password, $dbname, $dbprefix);
207 |
208 | // Install original Joomla scheme
209 | $dbscheme = JPATH_ADMINISTRATOR.'/components'.'/com_mtwmultiple'.'/sql'.'/joomla.sql';
210 | if (JInstallationHelper::populateDatabase($newDB, $dbscheme, $errors) > 0 ) {
211 | return false;
212 | }
213 |
214 | // First Install Plugin table
215 | $dbscheme = JPATH_ADMINISTRATOR.'/components'.'/com_mtwmultiple'.'/sql'.'/firstinstall.sql';
216 | if (JInstallationHelper::populateDatabase($newDB, $dbscheme, $errors) > 0 ) {
217 | return false;
218 | }
219 |
220 | $rootVars = new stdClass();
221 | $rootVars->admin_password = $post['password'];
222 | $rootVars->admin_user = "admin";
223 | $rootVars->admin_email = $post['email'];
224 | $rootVars->db_prefix = $dbprefix;
225 |
226 | if (!$this->_createRootUser($rootVars) ) {
227 | return false;
228 | }
229 |
230 | return true;
231 | }
232 |
233 |
234 | function addSiteConfig( $post ) {
235 |
236 | $mainframe = JFactory::getApplication();
237 |
238 | $db =& JFactory::getDBO();
239 | $config =& JFactory::getConfig();
240 |
241 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
242 |
243 | /* Create Joomla Installation */
244 | $query = "SELECT id FROM #__mtwmultiple_sites ORDER BY id DESC LIMIT 1";
245 | $db->setQuery( $query );
246 | $siteID = $db->loadResult();
247 |
248 | /* Create Joomla Installation */
249 | $sitesPath = JPATH_SITE.'/'.$params->get( 'path' );
250 | $newSitePath = $sitesPath.'/'.$siteID;
251 |
252 | $newConfig = new JRegistry('config');
253 | $config_array = array();
254 |
255 | // SITE SETTINGS
256 | $config_array['offline'] = JRequest::getVar('offline', 0, 'post', 'int');
257 | $config_array['editor'] = JRequest::getVar('editor', 'tinymce', 'post', 'cmd');
258 | $config_array['list_limit'] = JRequest::getVar('list_limit', 20, 'post', 'int');
259 | $config_array['helpurl'] = JRequest::getVar('helpurl', 'http://help.joomla.org', 'post', 'string');
260 |
261 | // DEBUG
262 | $config_array['debug'] = JRequest::getVar('debug', 0, 'post', 'int');
263 | $config_array['debug_lang'] = JRequest::getVar('debug_lang', 0, 'post', 'int');
264 |
265 | // SEO SETTINGS
266 | $config_array['sef'] = JRequest::getVar('sef', 0, 'post', 'int');
267 | $config_array['sef_rewrite'] = JRequest::getVar('sef_rewrite', 0, 'post', 'int');
268 | $config_array['sef_suffix'] = JRequest::getVar('sef_suffix', 0, 'post', 'int');
269 |
270 | // FEED SETTINGS
271 | $config_array['feed_limit'] = JRequest::getVar('feed_limit', 10, 'post', 'int');
272 |
273 | // SERVER SETTINGS
274 | $config_array['secret'] = JRequest::getVar('secret', 0, 'post', 'string');
275 | $config_array['gzip'] = JRequest::getVar('gzip', 0, 'post', 'int');
276 | $config_array['error_reporting'] = JRequest::getVar('error_reporting', -1, 'post', 'int');
277 | $config_array['xmlrpc_server'] = JRequest::getVar('xmlrpc_server', 0, 'post', 'int');
278 | $config_array['log_path'] = JRequest::getVar('log_path', $newSitePath.'/logs', 'post', 'string');
279 | $config_array['tmp_path'] = JRequest::getVar('tmp_path', $newSitePath.'/tmp', 'post', 'string');
280 | $config_array['live_site'] = rtrim(JRequest::getVar('live_site','','post','string'), '/\\');
281 |
282 | // LOCALE SETTINGS
283 | $config_array['offset'] = JRequest::getVar('offset', 'UTC', 'post', 'string');
284 |
285 | // CACHE SETTINGS
286 | $config_array['caching'] = JRequest::getVar('caching', 0, 'post', 'int');
287 | $config_array['cachetime'] = JRequest::getVar('cachetime', 900, 'post', 'int');
288 | $config_array['cache_handler'] = JRequest::getVar('cache_handler', 'file', 'post', 'word');
289 | $config_array['memcache_settings'] = JRequest::getVar('memcache_settings', array(), 'post');
290 |
291 | // FTP SETTINGS
292 | $config_array['ftp_enable'] = JRequest::getVar('ftp_enable', 0, 'post', 'int');
293 | $config_array['ftp_host'] = JRequest::getVar('ftp_host', '', 'post', 'string');
294 | $config_array['ftp_port'] = JRequest::getVar('ftp_port', '', 'post', 'int');
295 | $config_array['ftp_user'] = JRequest::getVar('ftp_user', '', 'post', 'string');
296 | $config_array['ftp_pass'] = JRequest::getVar('ftp_pass', '', 'post', 'string', JREQUEST_ALLOWRAW);
297 | $config_array['ftp_root'] = JRequest::getVar('ftp_root', '', 'post', 'string');
298 |
299 | // DATABASE SETTINGS
300 | $config_array['dbtype'] = JRequest::getVar('dbtype', $config->getValue('config.dbtype'), 'post', 'word');
301 | $config_array['host'] = JRequest::getVar('host', $config->getValue('config.host'), 'post', 'string');
302 | $config_array['user'] = JRequest::getVar('user', $config->getValue('config.user'), 'post', 'string');
303 | $config_array['db'] = JRequest::getVar('db', $config->getValue('config.db'), 'post', 'string');
304 | $config_array['dbprefix'] = JRequest::getVar('dbprefix', 'mtw' . $siteID . '_', 'post', 'string');
305 |
306 | // MAIL SETTINGS
307 | $config_array['mailer'] = JRequest::getVar('mailer', 'mail', 'post', 'word');
308 | $config_array['mailfrom'] = JRequest::getVar('mailfrom', '', 'post', 'string');
309 | $config_array['fromname'] = JRequest::getVar('fromname', 'Joomla 1.5', 'post', 'string');
310 | $config_array['sendmail'] = JRequest::getVar('sendmail', '/usr/sbin/sendmail', 'post', 'string');
311 | $config_array['smtpauth'] = JRequest::getVar('smtpauth', 0, 'post', 'int');
312 | $config_array['smtpuser'] = JRequest::getVar('smtpuser', '', 'post', 'string');
313 | $config_array['smtppass'] = JRequest::getVar('smtppass', '', 'post', 'string', JREQUEST_ALLOWRAW);
314 | $config_array['smtphost'] = JRequest::getVar('smtphost', '', 'post', 'string');
315 |
316 | // META SETTINGS
317 | $config_array['MetaAuthor'] = JRequest::getVar('MetaAuthor', 1, 'post', 'int');
318 | $config_array['MetaTitle'] = JRequest::getVar('MetaTitle', 1, 'post', 'int');
319 |
320 | // SESSION SETTINGS
321 | $config_array['lifetime'] = JRequest::getVar('lifetime', 0, 'post', 'int');
322 | $config_array['session_handler'] = JRequest::getVar('session_handler', 'none', 'post', 'word');
323 |
324 | //LANGUAGE SETTINGS
325 | //$config_array['lang'] = JRequest::getVar('lang', 'none', 'english', 'cmd');
326 | //$config_array['language'] = JRequest::getVar('language', 'en-GB', 'post', 'cmd');
327 |
328 | $newConfig->loadArray($config_array);
329 |
330 | //override any possible database password change
331 | $newConfig->setValue('config.password', $mainframe->getCfg('password'));
332 |
333 | // handling of special characters
334 | $sitename = htmlspecialchars( JRequest::getVar( 'sitename', $post['title'], 'post', 'string' ), ENT_COMPAT, 'UTF-8' );
335 | $newConfig->setValue('config.sitename', $sitename);
336 |
337 | $MetaDesc = htmlspecialchars( JRequest::getVar( 'MetaDesc', '', 'post', 'string' ), ENT_COMPAT, 'UTF-8' );
338 | $newConfig->setValue('config.MetaDesc', $MetaDesc);
339 |
340 | $MetaKeys = htmlspecialchars( JRequest::getVar( 'MetaKeys', '', 'post', 'string' ), ENT_COMPAT, 'UTF-8' );
341 | $newConfig->setValue('config.MetaKeys', $MetaKeys);
342 |
343 | // handling of quotes (double and single) and amp characters
344 | // htmlspecialchars not used to preserve ability to insert other html characters
345 | $offline_message = JRequest::getVar( 'offline_message', '', 'post', 'string' );
346 | $offline_message = JFilterOutput::ampReplace( $offline_message );
347 | $offline_message = str_replace( '"', '"', $offline_message );
348 | $offline_message = str_replace( "'", ''', $offline_message );
349 | $newConfig->setValue('config.offline_message', $offline_message);
350 |
351 | //purge the database session table (only if we are changing to a db session store)
352 | if($mainframe->getCfg('session_handler') != 'database' && $newConfig->getValue('session_handler') == 'database')
353 | {
354 | $table =& JTable::getInstance('session');
355 | $table->purge(-1);
356 | }
357 |
358 | // Get the path of the configuration file
359 | $fname = $newSitePath.'/configuration.php';
360 |
361 | // Get the config registry in PHP class format and write it to configuation.php
362 | jimport('joomla.filesystem.file');
363 | if (JFile::write($fname, $newConfig->toString('PHP', array('class' => 'JConfig')))) {
364 | $msg = JText::_('The Configuration Details have been updated');
365 | } else {
366 | $msg = JText::_('ERRORCONFIGFILE');
367 | }
368 |
369 | return true;
370 | }
371 |
372 | function addExtensions($data){
373 |
374 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
375 |
376 | $db =& JFactory::getDBO();
377 |
378 | // new site id
379 | $query = "SELECT id FROM #__mtwmultiple_sites ORDER BY id DESC LIMIT 1";
380 | $db->setQuery( $query );
381 | $siteID = $db->loadResult();
382 |
383 | // new site database instance
384 | $config =& JFactory::getConfig();
385 | $dbconfig = array();
386 | $dbconfig['driver'] = $config->getValue('config.dbtype');
387 | $dbconfig['host'] = $config->getValue('config.host');
388 | $dbconfig['user'] = $config->getValue('config.user');
389 | $dbconfig['password'] = $config->getValue('config.password');
390 | $dbconfig['database']= $config->getValue('config.db');
391 | $dbconfig['prefix'] = "mtw" . $siteID . "_";
392 |
393 | $newDB = JDatabase::getInstance( $dbconfig );
394 | /*
395 | @@ TODO -> Check if jDatabase is created correctly
396 |
397 | if ( $newDB->message ) {
398 | //print_r($this->_externalDB);
399 | $this->setError($newDB->message);
400 | return false;
401 | }
402 | */
403 |
404 | // Setting new site path
405 | $sitesPath = JPATH_SITE.'/'.$params->get( 'path' );
406 | $newSitePath = $sitesPath.'/'.$siteID;
407 |
408 | if (isset($data['select2'])) {
409 | foreach ($data['select2'] as $id) {
410 |
411 | $query = "SELECT e.*"
412 | . " FROM #__mtwmultiple_extensions AS e"
413 | . " WHERE e.enable = 1 AND id = " . $id;
414 | //echo $query;
415 | $db->setQuery( $query );
416 | $rows = $db->loadAssoc();
417 |
418 | // Insert extension
419 | $query = "INSERT INTO #__mtwmultiple_firstinstall"
420 | . " (`filename`, `type`)"
421 | . " VALUES ('". $rows['filename'] ."','". $rows["type"] ."')";
422 | //echo $query."
--
";
423 | $newDB->setQuery( $query );
424 |
425 | if(!$newDB->query()) {
426 | echo $newDB->getError();
427 | }
428 |
429 | $filepath = JPATH_ADMINISTRATOR .'/components'.'/com_mtwmultiple'.'/extensions'.'/'.$rows['filename'];
430 | JFile::copy( $filepath, $newSitePath.'/tmp'.'/'.$rows['filename']);
431 | }
432 | }
433 |
434 | return true;
435 | }
436 |
437 | function addVirtual($data){
438 |
439 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
440 |
441 | // Getting site ID
442 | $db =& JFactory::getDBO();
443 | $query = "SELECT id FROM #__mtwmultiple_sites ORDER BY id DESC LIMIT 1";
444 | $db->setQuery( $query );
445 | $siteID = $db->loadResult();
446 |
447 | $path = JPATH_ROOT.'/'.$params->get( 'path' ).'/'.$siteID;
448 |
449 | $vh = JFile::read(JPATH_ADMINISTRATOR .'/components/com_mtwmultiple/mtwmultiple.virtualhost.conf');
450 |
451 | $vh = str_replace("{EMAIL}", $data['email'], $vh);
452 | $vh = str_replace("{DOCROOT}", $path, $vh);
453 | $vh = str_replace("{SERVER}", $data['domain'], $vh);
454 |
455 | $vhfile = JPATH_ROOT.'/'.$params->get( 'virtual' ).'/'."{$siteID}-{$data['domain']}";
456 |
457 | //echo $vhfile."
";
458 |
459 | if (!JFile::write($vhfile, $vh)) {
460 | return false;
461 | }
462 |
463 | return true;
464 | }
465 |
466 |
467 | function removeSiteDB($siteID){
468 | $db =& JFactory::getDBO();
469 | $config =& JFactory::getConfig();
470 | $dbname = $config->getValue('config.db');
471 | require_once( JPATH_ADMINISTRATOR.'/components/com_mtwmultiple/include/helper.php');
472 |
473 | $dbprefix = 'j' . $siteID . '_';
474 | $query = "SHOW TABLES LIKE '$dbprefix%'";
475 | $db->setQuery($query);
476 | if ($tables = $db->loadResultArray()){
477 | foreach ($tables as $table) {
478 | $query = "DROP TABLE IF EXISTS `$table`";
479 | $db->setQuery($query);
480 | $db->query();
481 | if ($db->getErrorNum())
482 | {
483 | $msg = JText::_($db->getErrorMsg());
484 | JError::raiseWarning( 500, $db->getError() );
485 | }
486 | }
487 | }
488 | }
489 |
490 | function removeSiteFiles($id){
491 | jimport('joomla.filesystem.file');
492 |
493 | $site = $this->getSite($id);
494 |
495 | $params = &JComponentHelper::getParams( 'com_mtwmultiple' );
496 | $sitesPath = JPATH_SITE.'/'.$params->get( 'path' );
497 |
498 | // Remove the directory
499 | JFolder::delete($sitesPath.'/'.$id);
500 | // Remove the symlink
501 | JFile::delete($sitesPath.'/'.$site->title);
502 |
503 | return true;
504 | }
505 |
506 | /**
507 | * @param int The id of the site
508 | * @return object Return an object with the data of the site
509 | * @since 2.5
510 | */
511 | function getSite($id) {
512 | // Initiate the db
513 | $db =& JFactory::getDBO();
514 |
515 | $query = "SELECT * FROM #__mtwmultiple_sites WHERE id = '{$id}' LIMIT 1";
516 | $db->setQuery( $query );
517 | return $db->loadObject();
518 | }
519 |
520 | /**
521 | * @param int The id of the site
522 | * @return object Return an object with the data of the site
523 | * @since 2.5
524 | */
525 | function _createRootUser($options)
526 | {
527 | // Get a database object.
528 | //$db = JInstallationHelperDatabase::getDBO($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix);
529 | $db =& JFactory::getDBO();
530 |
531 | // Check for errors.
532 | if ($db instanceof Exception) {
533 | $this->setError(JText::sprintf('INSTL_ERROR_CONNECT_DB', (string)$db));
534 | return false;
535 | }
536 |
537 | // Check for database errors.
538 | if ($err = $db->getErrorNum()) {
539 | $this->setError(JText::sprintf('INSTL_ERROR_CONNECT_DB', $db->getErrorNum()));
540 | return false;
541 | }
542 |
543 | // Create random salt/password for the admin user
544 | $salt = JUserHelper::genRandomPassword(32);
545 | $crypt = JUserHelper::getCryptedPassword($options->admin_password, $salt);
546 | $cryptpass = $crypt.':'.$salt;
547 |
548 | // create the admin user
549 | date_default_timezone_set('UTC');
550 | $installdate = date('Y-m-d H:i:s');
551 | $nullDate = $db->getNullDate();
552 | //sqlsrv change
553 | $query = $db->getQuery(true);
554 | $query->select('id');
555 | $query->from($options->db_prefix.'users');
556 | $query->where('id = 42');
557 |
558 | $db->setQuery($query);
559 |
560 | if($db->loadResult())
561 | {
562 | $query = $db->getQuery(true);
563 | $query->update($options->db_prefix.'users');
564 | $query->set('name = '.$db->quote('Super User'));
565 | $query->set('username = '.$db->quote($options->admin_user));
566 | $query->set('email = '.$db->quote($options->admin_email));
567 | $query->set('password = '.$db->quote($cryptpass));
568 | $query->set('usertype = '.$db->quote('deprecated'));
569 | $query->set('block = 0');
570 | $query->set('sendEmail = 1');
571 | $query->set('registerDate = '.$db->quote($installdate));
572 | $query->set('lastvisitDate = '.$db->quote($nullDate));
573 | $query->set('activation = '.$db->quote('0'));
574 | $query->set('params = '.$db->quote(''));
575 | $query->where('id = 42');
576 | } else {
577 | $query = $db->getQuery(true);
578 | $columns = array($db->quoteName('id'), $db->quoteName('name'), $db->quoteName('username'),
579 | $db->quoteName('email'), $db->quoteName('password'),
580 | $db->quoteName('usertype'),
581 | $db->quoteName('block'),
582 | $db->quoteName('sendEmail'), $db->quoteName('registerDate'),
583 | $db->quoteName('lastvisitDate'), $db->quoteName('activation'), $db->quoteName('params'));
584 | $query->insert($options->db_prefix.'users', true);
585 | $query->columns($columns);
586 |
587 | $query->values('42'. ', '. $db->quote('Super User'). ', '. $db->quote($options->admin_user). ', '.
588 | $db->quote($options->admin_email). ', '. $db->quote($cryptpass). ', '. $db->quote('deprecated').', '.$db->quote('0').', '.$db->quote('1').', '.
589 | $db->quote($installdate).', '.$db->quote($nullDate).', '.$db->quote('0').', '.$db->quote(''));
590 | }
591 | $db->setQuery($query);
592 | if (!$db->query()) {
593 | JError::raiseWarning( 500, $db->getErrorMsg() );
594 | return false;
595 | }
596 |
597 | // Map the super admin to the Super Admin Group
598 | $query = $db->getQuery(true);
599 | $query->select('user_id');
600 | $query->from($options->db_prefix.'user_usergroup_map');
601 | $query->where('user_id = 42');
602 |
603 | $db->setQuery($query);
604 |
605 | if($db->loadResult())
606 | {
607 | $query = $db->getQuery(true);
608 | $query->update($options->db_prefix.'user_usergroup_map');
609 | $query->set('user_id = 42');
610 | $query->set('group_id = 8');
611 | } else {
612 | $query = $db->getQuery(true);
613 | $query->insert($options->db_prefix.'user_usergroup_map', false);
614 | $query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
615 | $query->values('42'. ', '. '8');
616 |
617 | }
618 |
619 | $db->setQuery($query);
620 | if (!$db->query()) {
621 | JError::raiseWarning( 500, $db->getErrorMsg() );
622 | return false;
623 | }
624 |
625 | return true;
626 | }
627 |
628 | } // end class
629 |
--------------------------------------------------------------------------------
/admin/include/helper.php:
--------------------------------------------------------------------------------
1 | 'mysql', 'mysqli_connect' => 'mysqli', 'mssql_connect' => 'mssql');
31 | foreach ($map as $f => $db)
32 | {
33 | if (function_exists($f))
34 | {
35 | return $db;
36 | }
37 | }
38 | return 'mysql';
39 | }
40 |
41 | /**
42 | * @param array
43 | * @return string
44 | */
45 | function errors2string(& $errors)
46 | {
47 | $buffer = '';
48 | foreach ($errors as $error)
49 | {
50 | $buffer .= 'SQL='.$error['msg'].":\n- - - - - - - - - -\n".$error['sql']."\n= = = = = = = = = =\n\n";
51 | }
52 | return $buffer;
53 | }
54 | /**
55 | * Creates a new database
56 | * @param object Database connector
57 | * @param string Database name
58 | * @param boolean utf-8 support
59 | * @param string Selected collation
60 | * @return boolean success
61 | */
62 | function createDatabase(& $db, $DBname, $DButfSupport)
63 | {
64 | if ($DButfSupport)
65 | {
66 | $sql = "CREATE DATABASE `$DBname` CHARACTER SET `utf8`";
67 | }
68 | else
69 | {
70 | $sql = "CREATE DATABASE `$DBname`";
71 | }
72 |
73 | $db->setQuery($sql);
74 | $db->query();
75 | $result = $db->getErrorNum();
76 |
77 | if ($result != 0)
78 | {
79 | return false;
80 | }
81 |
82 | return true;
83 | }
84 |
85 | /**
86 | * Sets character set of the database to utf-8 with selected collation
87 | * Used in instances of pre-existing database
88 | * @param object Database object
89 | * @param string Database name
90 | * @param string Selected collation
91 | * @return boolean success
92 | */
93 | function setDBCharset(& $db, $DBname)
94 | {
95 | if ($db->hasUTF())
96 | {
97 | $sql = "ALTER DATABASE `$DBname` CHARACTER SET `utf8`";
98 | $db->setQuery($sql);
99 | $db->query();
100 | $result = $db->getErrorNum();
101 | if ($result != 0) {
102 | return false;
103 | }
104 | }
105 | return true;
106 | }
107 |
108 | /**
109 | * Backs up existing tables
110 | * @param object Database connector
111 | * @param array An array of errors encountered
112 | */
113 | function backupDatabase(& $db, $DBname, $DBPrefix, & $errors)
114 | {
115 | // Initialize backup prefix variable
116 | // TODO: Should this be user-defined?
117 | $BUPrefix = 'bak_';
118 |
119 | $query = "SHOW TABLES FROM `$DBname`";
120 | $db->setQuery($query);
121 | $errors = array ();
122 | if ($tables = $db->loadResultArray())
123 | {
124 | foreach ($tables as $table)
125 | {
126 | if (strpos($table, $DBPrefix) === 0)
127 | {
128 | $butable = str_replace($DBPrefix, $BUPrefix, $table);
129 | $query = "DROP TABLE IF EXISTS `$butable`";
130 | $db->setQuery($query);
131 | $db->query();
132 | if ($db->getErrorNum())
133 | {
134 | $errors[$db->getQuery()] = $db->getErrorMsg();
135 | }
136 | $query = "RENAME TABLE `$table` TO `$butable`";
137 | $db->setQuery($query);
138 | $db->query();
139 | if ($db->getErrorNum())
140 | {
141 | $errors[$db->getQuery()] = $db->getErrorMsg();
142 | }
143 | }
144 | }
145 | }
146 |
147 | return count($errors);
148 | }
149 | /**
150 | * Deletes all database tables
151 | * @param object Database connector
152 | * @param array An array of errors encountered
153 | */
154 | function deleteDatabase(& $db, $DBname, $DBPrefix, & $errors)
155 | {
156 | $query = "SHOW TABLES FROM `$DBname`";
157 | $db->setQuery($query);
158 | $errors = array ();
159 | if ($tables = $db->loadResultArray())
160 | {
161 | foreach ($tables as $table)
162 | {
163 | if (strpos($table, $DBPrefix) === 0)
164 | {
165 | $query = "DROP TABLE IF EXISTS `$table`";
166 | $db->setQuery($query);
167 | $db->query();
168 | if ($db->getErrorNum())
169 | {
170 | $errors[$db->getQuery()] = $db->getErrorMsg();
171 | }
172 | }
173 | }
174 | }
175 |
176 | return count($errors);
177 | }
178 |
179 | /**
180 | *
181 | */
182 | function populateDatabase(& $db, $sqlfile, & $errors, $nexttask='mainconfig')
183 | {
184 | if( !($buffer = file_get_contents($sqlfile)) )
185 | {
186 | return -1;
187 | }
188 |
189 | $queries = JInstallationHelper::splitSql($buffer);
190 |
191 | foreach ($queries as $query)
192 | {
193 | $query = trim($query);
194 | if ($query != '' && $query {0} != '#')
195 | {
196 | $db->setQuery($query);
197 | //echo $query .'
';
198 | $db->query() or die($db->getErrorMsg());
199 |
200 | JInstallationHelper::getDBErrors($errors, $db );
201 | }
202 | }
203 | return count($errors);
204 | }
205 |
206 | /**
207 | * @param string
208 | * @return array
209 | */
210 | function splitSql($sql)
211 | {
212 | $sql = trim($sql);
213 | $sql = preg_replace("/\n\#[^\n]*/", '', "\n".$sql);
214 | $buffer = array ();
215 | $ret = array ();
216 | $in_string = false;
217 |
218 | for ($i = 0; $i < strlen($sql) - 1; $i ++) {
219 | if ($sql[$i] == ";" && !$in_string)
220 | {
221 | $ret[] = substr($sql, 0, $i);
222 | $sql = substr($sql, $i +1);
223 | $i = 0;
224 | }
225 |
226 | if ($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\")
227 | {
228 | $in_string = false;
229 | }
230 | elseif (!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset ($buffer[0]) || $buffer[0] != "\\"))
231 | {
232 | $in_string = $sql[$i];
233 | }
234 | if (isset ($buffer[1]))
235 | {
236 | $buffer[0] = $buffer[1];
237 | }
238 | $buffer[1] = $sql[$i];
239 | }
240 |
241 | if (!empty ($sql))
242 | {
243 | $ret[] = $sql;
244 | }
245 | return ($ret);
246 | }
247 |
248 | /**
249 | * Calculates the file/dir permissions mask
250 | */
251 | function getFilePerms($input, $type = 'file')
252 | {
253 | $perms = '';
254 | if (JArrayHelper::getValue($input, $type.'PermsMode', 0))
255 | {
256 | $action = ($type == 'dir') ? 'Search' : 'Execute';
257 | $perms = '0'. (JArrayHelper::getValue($input, $type.'PermsUserRead', 0) * 4 + JArrayHelper::getValue($input, $type.'PermsUserWrite', 0) * 2 + JArrayHelper::getValue($input, $type.'PermsUser'.$action, 0)). (JArrayHelper::getValue($input, $type.'PermsGroupRead', 0) * 4 + JArrayHelper::getValue($input, $type.'PermsGroupWrite', 0) * 2 + JArrayHelper::getValue($input, $type.'PermsGroup'.$action, 0)). (JArrayHelper::getValue($input, $type.'PermsWorldRead', 0) * 4 + JArrayHelper::getValue($input, $type.'PermsWorldWrite', 0) * 2 + JArrayHelper::getValue($input, $type.'PermsWorld'.$action, 0));
258 | }
259 | return $perms;
260 | }
261 |
262 | /**
263 | * Creates the admin user
264 | */
265 | function createAdminUser(& $vars)
266 | {
267 | $DBtype = JArrayHelper::getValue($vars, 'DBtype', 'mysql');
268 | $DBhostname = JArrayHelper::getValue($vars, 'DBhostname', '');
269 | $DBuserName = JArrayHelper::getValue($vars, 'DBuserName', '');
270 | $DBpassword = JArrayHelper::getValue($vars, 'DBpassword', '');
271 | $DBname = JArrayHelper::getValue($vars, 'DBname', '');
272 | $DBPrefix = JArrayHelper::getValue($vars, 'DBPrefix', '');
273 |
274 | $adminPassword = JArrayHelper::getValue($vars, 'adminPassword', '');
275 | $adminEmail = JArrayHelper::getValue($vars, 'adminEmail', '');
276 |
277 | jimport('joomla.user.helper');
278 |
279 | // Create random salt/password for the admin user
280 | $salt = JUserHelper::genRandomPassword(32);
281 | $crypt = JUserHelper::getCryptedPassword($adminPassword, $salt);
282 | $cryptpass = $crypt.':'.$salt;
283 |
284 | $vars['adminLogin'] = 'admin';
285 |
286 | $db = & JInstallationHelper::getDBO($DBtype, $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix);
287 |
288 | // create the admin user
289 | $installdate = date('Y-m-d H:i:s');
290 | $nullDate = $db->getNullDate();
291 | $query = "INSERT INTO #__users VALUES (62, 'Administrator', 'admin', ".$db->Quote($adminEmail).", ".$db->Quote($cryptpass).", 'Super Administrator', 0, 1, 25, '$installdate', '$nullDate', '', '')";
292 | $db->setQuery($query);
293 | if (!$db->query())
294 | {
295 | // is there already and existing admin in migrated data
296 | if ( $db->getErrorNum() == 1062 )
297 | {
298 | $vars['adminLogin'] = JText::_('Admin login in migrated content was kept');
299 | $vars['adminPassword'] = JText::_('Admin password in migrated content was kept');
300 | return;
301 | }
302 | else
303 | {
304 | echo $db->getErrorMsg();
305 | return;
306 | }
307 | }
308 |
309 | // add the ARO (Access Request Object)
310 | $query = "INSERT INTO #__core_acl_aro VALUES (10,'users','62',0,'Administrator',0)";
311 | $db->setQuery($query);
312 | if (!$db->query())
313 | {
314 | echo $db->getErrorMsg();
315 | return;
316 | }
317 |
318 | // add the map between the ARO and the Group
319 | $query = "INSERT INTO #__core_acl_groups_aro_map VALUES (25,'',10)";
320 | $db->setQuery($query);
321 | if (!$db->query())
322 | {
323 | echo $db->getErrorMsg();
324 | return;
325 | }
326 | }
327 |
328 | function & getDBO($driver, $host, $user, $password, $database, $prefix, $select = true)
329 | {
330 | static $db;
331 |
332 | if ( ! $db )
333 | {
334 | jimport('joomla.database.database');
335 | $options = array ( 'driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix, 'select' => $select );
336 | $db = & JDatabase::getInstance( $options );
337 | }
338 |
339 | return $db;
340 | }
341 |
342 | /**
343 | * Check the webserver user permissions for writing files/folders
344 | *
345 | * @static
346 | * @return boolean True if correct permissions exist
347 | * @since 1.5
348 | */
349 | function fsPermissionsCheck()
350 | {
351 | if(!is_writable(JPATH_ROOT.'/tmp')) {
352 | return false;
353 | }
354 | if(!mkdir(JPATH_ROOT.'/tmp'.'/test', 0755)) {
355 | return false;
356 | }
357 | if(!copy(JPATH_ROOT.'/tmp'.'/index.html', JPATH_ROOT.'/tmp'.'/test'.'/index.html')) {
358 | return false;
359 | }
360 | if(!chmod(JPATH_ROOT.'/tmp'.'/test'.'/index.html', 0777)) {
361 | return false;
362 | }
363 | if(!unlink(JPATH_ROOT.'/tmp'.'/test'.'/index.html')) {
364 | return false;
365 | }
366 | if(!rmdir(JPATH_ROOT.'/tmp'.'/test')) {
367 | return false;
368 | }
369 | return true;
370 | }
371 |
372 | /**
373 | * Find the ftp filesystem root for a given user/pass pair
374 | *
375 | * @static
376 | * @param string $user Username of the ftp user to determine root for
377 | * @param string $pass Password of the ftp user to determine root for
378 | * @return string Filesystem root for given FTP user
379 | * @since 1.5
380 | */
381 | function findFtpRoot($user, $pass, $host='127.0.0.1', $port='21')
382 | {
383 | jimport('joomla.client.ftp');
384 | $ftpPaths = array();
385 |
386 | // Connect and login to the FTP server (using binary transfer mode to be able to compare files)
387 | $ftp =& JFTP::getInstance($host, $port, array('type'=>FTP_BINARY));
388 | if (!$ftp->isConnected()) {
389 | return JError::raiseError('31', 'NOCONNECT');
390 | }
391 | if (!$ftp->login($user, $pass)) {
392 | return JError::raiseError('31', 'NOLOGIN');
393 | }
394 |
395 | // Get the FTP CWD, in case it is not the FTP root
396 | $cwd = $ftp->pwd();
397 | if ($cwd === false) {
398 | return JError::raiseError('SOME_ERROR_CODE', 'NOPWD');
399 | }
400 | $cwd = rtrim($cwd, '/');
401 |
402 | // Get list of folders in the CWD
403 | $ftpFolders = $ftp->listDetails(null, 'folders');
404 | if ($ftpFolders === false || count($ftpFolders) == 0) {
405 | return JError::raiseError('SOME_ERROR_CODE', 'NODIRECTORYLISTING');
406 | }
407 | for ($i=0, $n=count($ftpFolders); $i<$n; $i++) {
408 | $ftpFolders[$i] = $ftpFolders[$i]['name'];
409 | }
410 |
411 | // Check if Joomla! is installed at the FTP CWD
412 | $dirList = array('administrator', 'components', 'installation', 'language', 'libraries', 'plugins');
413 | if (count(array_diff($dirList, $ftpFolders)) == 0) {
414 | $ftpPaths[] = $cwd.'/';
415 | }
416 |
417 | // Process the list: cycle through all parts of JPATH_SITE, beginning from the end
418 | $parts = explode('/', JPATH_SITE);
419 | $tmpPath = '';
420 | for ($i=count($parts)-1; $i>=0; $i--)
421 | {
422 | $tmpPath = '/'.$parts[$i].$tmpPath;
423 | if (in_array($parts[$i], $ftpFolders)) {
424 | $ftpPaths[] = $cwd.$tmpPath;
425 | }
426 | }
427 |
428 | // Check all possible paths for the real Joomla! installation
429 | $checkValue = file_get_contents(JPATH_LIBRARIES.'/joomla'.'/version.php');
430 | foreach ($ftpPaths as $tmpPath)
431 | {
432 | $filePath = rtrim($tmpPath, '/').'/libraries/joomla/version.php';
433 | $buffer = null;
434 | @$ftp->read($filePath, $buffer);
435 | if ($buffer == $checkValue)
436 | {
437 | $ftpPath = $tmpPath;
438 | break;
439 | }
440 | }
441 |
442 | // Close the FTP connection
443 | $ftp->quit();
444 |
445 | // Return the FTP root path
446 | if (isset($ftpPath)) {
447 | return $ftpPath;
448 | } else {
449 | return JError::raiseError('SOME_ERROR_CODE', 'Unable to autodetect the FTP root folder');
450 | }
451 | }
452 |
453 | /**
454 | * Verify the FTP configuration values are valid
455 | *
456 | * @static
457 | * @param string $user Username of the ftp user to determine root for
458 | * @param string $pass Password of the ftp user to determine root for
459 | * @return mixed Boolean true on success or JError object on fail
460 | * @since 1.5
461 | */
462 | function FTPVerify($user, $pass, $root, $host='127.0.0.1', $port='21')
463 | {
464 | jimport('joomla.client.ftp');
465 | $ftp = & JFTP::getInstance($host, $port);
466 |
467 | // Since the root path will be trimmed when it gets saved to configuration.php, we want to test with the same value as well
468 | $root = rtrim($root, '/');
469 |
470 | // Verify connection
471 | if (!$ftp->isConnected()) {
472 | return JError::raiseWarning('31', 'NOCONNECT');
473 | }
474 |
475 | // Verify username and password
476 | if (!$ftp->login($user, $pass)) {
477 | return JError::raiseWarning('31', 'NOLOGIN');
478 | }
479 |
480 | // Verify PWD function
481 | if ($ftp->pwd() === false) {
482 | return JError::raiseError('SOME_ERROR_CODE', 'NOPWD');
483 | }
484 |
485 | // Verify root path exists
486 | if (!$ftp->chdir($root)) {
487 | return JError::raiseWarning('31', 'NOROOT');
488 | }
489 |
490 | // Verify NLST function
491 | if (($rootList = $ftp->listNames()) === false) {
492 | return JError::raiseError('SOME_ERROR_CODE', 'NONLST');
493 | }
494 |
495 | // Verify LIST function
496 | if ($ftp->listDetails() === false) {
497 | return JError::raiseError('SOME_ERROR_CODE', 'NOLIST');
498 | }
499 |
500 | // Verify SYST function
501 | if ($ftp->syst() === false) {
502 | return JError::raiseError('SOME_ERROR_CODE', 'NOSYST');
503 | }
504 |
505 | // Verify valid root path, part one
506 | $checkList = array('CHANGELOG.php', 'COPYRIGHT.php', 'index.php', 'INSTALL.php', 'LICENSE.php');
507 | if (count(array_diff($checkList, $rootList))) {
508 | return JError::raiseWarning('31', 'INVALIDROOT');
509 | }
510 |
511 | // Verify RETR function
512 | $buffer = null;
513 | if ($ftp->read($root.'/libraries/joomla/version.php', $buffer) === false) {
514 | return JError::raiseError('SOME_ERROR_CODE', 'NORETR');
515 | }
516 |
517 | // Verify valid root path, part two
518 | $checkValue = file_get_contents(JPATH_LIBRARIES.'/joomla'.'/version.php');
519 | if ($buffer !== $checkValue) {
520 | return JError::raiseWarning('31', 'INVALIDROOT');
521 | }
522 |
523 | // Verify STOR function
524 | if ($ftp->create($root.'/ftp_testfile') === false) {
525 | return JError::raiseError('SOME_ERROR_CODE', 'NOSTOR');
526 | }
527 |
528 | // Verify DELE function
529 | if ($ftp->delete($root.'/ftp_testfile') === false) {
530 | return JError::raiseError('SOME_ERROR_CODE', 'NODELE');
531 | }
532 |
533 | // Verify MKD function
534 | if ($ftp->mkdir($root.'/ftp_testdir') === false) {
535 | return JError::raiseError('SOME_ERROR_CODE', 'NOMKD');
536 | }
537 |
538 | // Verify RMD function
539 | if ($ftp->delete($root.'/ftp_testdir') === false) {
540 | return JError::raiseError('SOME_ERROR_CODE', 'NORMD');
541 | }
542 |
543 | $ftp->quit();
544 | return true;
545 | }
546 |
547 | /**
548 | * Set default folder permissions
549 | *
550 | * @param string $path The full file path
551 | * @param string $buffer The buffer to write
552 | * @return boolean True on success
553 | * @since 1.5
554 | */
555 | function setDirPerms($dir, &$srv)
556 | {
557 | jimport('joomla.filesystem.path');
558 |
559 | /*
560 | * Initialize variables
561 | */
562 | $ftpFlag = false;
563 | $ftpRoot = $srv['ftpRoot'];
564 |
565 | /*
566 | * First we need to determine if the path is chmodable
567 | */
568 | if (!JPath::canChmod(JPath::clean(JPATH_SITE.'/'.$dir)))
569 | {
570 | $ftpFlag = true;
571 | }
572 |
573 | // Do NOT use ftp if it is not enabled
574 | if (!$srv['ftpEnable'])
575 | {
576 | $ftpFlag = false;
577 | }
578 |
579 | if ($ftpFlag == true)
580 | {
581 | // Connect the FTP client
582 | jimport('joomla.client.ftp');
583 | $ftp = & JFTP::getInstance($srv['ftpHost'], $srv['ftpPort']);
584 | $ftp->login($srv['ftpUser'],$srv['ftpPassword']);
585 |
586 | //Translate path for the FTP account
587 | $path = JPath::clean($ftpRoot."/".$dir);
588 |
589 | /*
590 | * chmod using ftp
591 | */
592 | if (!$ftp->chmod($path, '0755'))
593 | {
594 | $ret = false;
595 | }
596 |
597 | $ftp->quit();
598 | $ret = true;
599 | }
600 | else
601 | {
602 |
603 | $path = JPath::clean(JPATH_SITE.'/'.$dir);
604 |
605 | if (!@ chmod($path, octdec('0755')))
606 | {
607 | $ret = false;
608 | }
609 | else
610 | {
611 | $ret = true;
612 | }
613 | }
614 |
615 | return $ret;
616 | }
617 |
618 | function findMigration( &$args ) {
619 | print_r($args); jexit();
620 | }
621 |
622 | /**
623 | * Uploads a sql script and executes it. Script can be text file or zip/gz packed
624 | *
625 | * @static
626 | * @param array The installation variables
627 | * @param boolean true if the script is a migration script
628 | * @return string Success or error messages
629 | * @since 1.5
630 | */
631 | function uploadSql( &$args, $migration = false, $preconverted = false )
632 | {
633 | global $mainframe;
634 | $archive = '';
635 | $script = '';
636 |
637 | /*
638 | * Check for iconv
639 | */
640 | if ($migration && !$preconverted && !function_exists( 'iconv' ) ) {
641 | return JText::_( 'WARNICONV' );
642 | }
643 |
644 |
645 | /*
646 | * Get the uploaded file information
647 | */
648 | if( $migration )
649 | {
650 | $sqlFile = JRequest::getVar('migrationFile', '', 'files', 'array');
651 | }
652 | else
653 | {
654 | $sqlFile = JRequest::getVar('sqlFile', '', 'files', 'array');
655 | }
656 |
657 | /*
658 | * Make sure that file uploads are enabled in php
659 | */
660 | if (!(bool) ini_get('file_uploads'))
661 | {
662 | return JText::_('WARNINSTALLFILE');
663 | }
664 |
665 | /*
666 | * Make sure that zlib is loaded so that the package can be unpacked
667 | */
668 | if (!extension_loaded('zlib'))
669 | {
670 | return JText::_('WARNINSTALLZLIB');
671 | }
672 |
673 | /*
674 | * If there is no uploaded file, we have a problem...
675 | */
676 | if (!is_array($sqlFile) || $sqlFile['size'] < 1)
677 | {
678 | return JText::_('WARNNOFILE');
679 | }
680 |
681 | /*
682 | * Move uploaded file
683 | */
684 | // Set permissions for tmp dir
685 | JInstallationHelper::_chmod(JPATH_SITE.'/tmp', 0777);
686 | jimport('joomla.filesystem.file');
687 | $uploaded = JFile::upload($sqlFile['tmp_name'], JPATH_SITE.'/tmp/'.sqlFile['name']);
688 | if(!$uploaded) {
689 | return JText::_('WARNUPLOADFAILURE');
690 | }
691 |
692 | if( !preg_match('#\.sql$#i', $sqlFile['name']) )
693 | {
694 | $archive = JPATH_SITE.'/tmp/'.sqlFile['name'];
695 | }
696 | else
697 | {
698 | $script = JPATH_SITE.'/tmp/'.sqlFile['name'];
699 | }
700 |
701 | // unpack archived sql files
702 | if ($archive )
703 | {
704 | $package = JInstallationHelper::unpack( $archive, $args );
705 | if ( $package === false )
706 | {
707 | return JText::_('WARNUNPACK');
708 | }
709 | $script = $package['folder'].'/'.$package['script'];
710 | }
711 |
712 | $db = & JInstallationHelper::getDBO($args['DBtype'], $args['DBhostname'], $args['DBuserName'], $args['DBpassword'], $args['DBname'], $args['DBPrefix']);
713 |
714 | /*
715 | * If migration perform manipulations on script file before population
716 | */
717 | if ( $migration )
718 | {
719 | $script = JInstallationHelper::preMigrate($script, $args, $db);
720 | if ( $script == false )
721 | {
722 | return JText::_( 'Script operations failed' );
723 | }
724 | }
725 |
726 | $errors = null;
727 | $msg = '';
728 | $result = JInstallationHelper::populateDatabase($db, $script, $errors);
729 |
730 | /*
731 | * If migration, perform post population manipulations (menu table construction)
732 | */
733 | $migErrors = null;
734 | if ( $migration )
735 | {
736 | $migResult = JInstallationHelper::postMigrate( $db, $migErrors, $args );
737 |
738 | if ( $migResult != 0 )
739 | {
740 | /*
741 | * Merge populate and migrate processing errors
742 | */
743 | if( $result == 0 )
744 | {
745 | $result = $migResult;
746 | $errors = $migErrors;
747 | }
748 | else
749 | {
750 | $result += $migResult;
751 | $errors = array_merge( $errors, $migErrors );
752 | }
753 | }
754 | }
755 |
756 |
757 | /*
758 | * prepare sql error messages if returned from populate and migrate
759 | */
760 | if (!is_null($errors))
761 | {
762 | foreach($errors as $error)
763 | {
764 | $msg .= stripslashes( $error['msg'] );
765 | $msg .= chr(13)."-------------".chr(13);
766 | $txt = '';
767 | }
768 | }
769 | else
770 | {
771 | // consider other possible errors from populate
772 | $msg = $result == 0 ? JText::_('SQL script installed successfully') : JText::_('Error installing SQL script') ;
773 | $txt = '';
774 | }
775 |
776 | /*
777 | * Clean up
778 | */
779 | if ($archive)
780 | {
781 | JFile::delete( $archive );
782 | JFolder::delete( $package['folder'] );
783 | }
784 | else
785 | {
786 | JFile::delete( $script );
787 | }
788 |
789 | return $txt;
790 | }
791 |
792 | /**
793 | * Unpacks a compressed script file either as zip or gz/ Assumes single file in archive
794 | *
795 | * @static
796 | * @param string $p_filename The uploaded package filename or install directory
797 | * @return unpacked filename on success, False on error
798 | * @since 1.5
799 | */
800 | function unpack($p_filename, &$vars) {
801 |
802 | /*
803 | * Initialize variables
804 | */
805 | // Path to the archive
806 | $archivename = $p_filename;
807 | // Temporary folder to extract the archive into
808 | $tmpdir = uniqid('install_');
809 |
810 |
811 | // Clean the paths to use for archive extraction
812 | $extractdir = JPath::clean(dirname($p_filename).'/'.$tmpdir);
813 | $archivename = JPath::clean($archivename);
814 | jimport('joomla.filesystem.archive');
815 | $result = JArchive::extract( $archivename, $extractdir);
816 |
817 | if ( $result === false ) {
818 | return false;
819 | }
820 |
821 |
822 | /*
823 | * return the file found in the extract folder and also folder name
824 | */
825 | if ($handle = opendir( $extractdir ))
826 | {
827 | while (false !== ($file = readdir($handle)))
828 | {
829 | if ($file != "." && $file != "..")
830 | {
831 | $script = $file;
832 | continue;
833 | }
834 | }
835 | closedir($handle);
836 | }
837 | $retval['script'] = $script;
838 | $retval['folder'] = $extractdir;
839 | return $retval;
840 |
841 | }
842 |
843 | function return_bytes($val) {
844 | $val = trim($val);
845 | $last = strtolower($val{strlen($val)-1});
846 | switch($last) {
847 | // The 'G' modifier is available since PHP 5.1.0
848 | case 'g':
849 | $val *= 1024;
850 | case 'm':
851 | $val *= 1024;
852 | case 'k':
853 | $val *= 1024;
854 | }
855 |
856 | return $val;
857 | }
858 |
859 | function replaceBuffer(&$buffer, $oldPrefix, $newPrefix, $srcEncoding) {
860 |
861 | $buffer = str_replace( $oldPrefix, $newPrefix, $buffer );
862 |
863 | /*
864 | * give temp name to menu and modules tables
865 | */
866 | $buffer = str_replace ( $newPrefix.'modules', $newPrefix.'modules_migration', $buffer );
867 | $buffer = str_replace ( $newPrefix.'menu', $newPrefix.'menu_migration', $buffer );
868 |
869 | /*
870 | * convert to utf-8
871 | */
872 | if(function_exists('iconv')) {
873 | $buffer = iconv( $srcEncoding, 'utf-8//TRANSLIT', $buffer );
874 | }
875 | }
876 |
877 | function appendFile(&$buffer, $filename) {
878 | $fh = fopen($filename, 'a');
879 | fwrite($fh, $buffer);
880 | fclose($fh);
881 | }
882 |
883 | /**
884 | * Performs pre-populate conversions on a migration script
885 | *
886 | * @static
887 | * @param string $scriptName The uploaded / unpacked script file
888 | * $param array $args The installation varibables
889 | * @return converted filename on success, False on error
890 | * @since 1.5
891 | */
892 | function preMigrate( $scriptName, &$args, $db )
893 | {
894 | $maxread = 0;
895 | jimport('joomla.filesystem.file');
896 | if(function_exists('memory_get_usage')) {
897 | $memlimit = JInstallationHelper::return_bytes(ini_get('memory_limit'));
898 | $maxread = $memlimit / 16; // Read only a eigth of our max amount of memory, we could be up to a lot by now
899 | // By default this pegs us at 0.5MB
900 | }
901 | $buffer = '';
902 | $newPrefix = $args['DBPrefix'];
903 | /*
904 | * search and replace table prefixes
905 | */
906 | $oldPrefix = trim( $args['oldPrefix']);
907 | $oldPrefix = rtrim( $oldPrefix, '_' ) . '_';
908 | $srcEncoding = $args['srcEncoding'];
909 | if(!is_file($scriptName)) return false; // not a file?
910 | $newFile = dirname( $scriptName ).'/converted.sql';
911 | $tfilesize = filesize($scriptName);
912 | if($maxread > 0 && $tfilesize > 0 && $maxread < $tfilesize)
913 | {
914 | $parts = ceil($tfilesize / $maxread);
915 | file_put_contents( $newFile, '' ); // cleanse the file first
916 | for($i = 0; $i < $parts; $i++) {
917 | $buffer = JFile::read($scriptName, false, $maxread, $maxread,($i * $maxread));
918 | // Lets try and read a portion of the file
919 | JInstallationHelper::replaceBuffer($buffer, $oldPrefix, $newPrefix, $srcEncoding);
920 | JInstallationHelper::appendFile($buffer, $newFile);
921 | unset($buffer);
922 | }
923 | JFile::delete( $scriptName );
924 | } else {
925 | /*
926 | * read script file into buffer
927 | */
928 | if(is_file($scriptName)) {
929 | $buffer = file_get_contents( $scriptName );
930 | } else return false;
931 |
932 | if( $buffer == false ) return false;
933 | JInstallationHelper::replaceBuffer($buffer, $oldPrefix, $newPrefix, $srcEncoding);
934 |
935 | /*
936 | * write to file
937 | */
938 | //$newFile = dirname( $scriptName ).'/converted.sql';
939 | $ret = file_put_contents( $newFile, $buffer );
940 | unset($buffer); // Release the memory used by the buffer
941 | jimport('joomla.filesystem.file');
942 | JFile::delete( $scriptName );
943 | }
944 |
945 | /*
946 | * Create two empty temporary tables
947 | */
948 |
949 | $query = 'DROP TABLE IF EXISTS '.$newPrefix.'modules_migration';
950 | $db->setQuery( $query );
951 | $db->query();
952 |
953 | $query = 'DROP TABLE IF EXISTS '.$newPrefix.'menu_migration';
954 | $db->setQuery( $query );
955 | $db->query();
956 |
957 | $query = 'CREATE TABLE '.$newPrefix.'modules_migration SELECT * FROM '.$newPrefix.'modules WHERE 0';
958 | $db->setQuery( $query );
959 | $db->query();
960 |
961 | $query = 'CREATE TABLE '.$newPrefix.'modules_migration_menu SELECT * FROM '.$newPrefix.'modules_menu WHERE 0';
962 | $db->setQuery( $query );
963 | $db->Query();
964 |
965 | $query = 'CREATE TABLE '.$newPrefix.'menu_migration SELECT * FROM '.$newPrefix.'menu WHERE 0';
966 | $db->setQuery( $query );
967 | $db->query();
968 |
969 | return $newFile;
970 | }
971 |
972 | /**
973 | * Performs post-populate conversions after importing a migration script
974 | * These include constructing an appropriate menu table for core content items
975 | * and adding core modules from old site to the modules table
976 | *
977 | * @static
978 | * @param JDatabase
979 | * @param array errors (by ref)
980 | * @return error count
981 | * @since 1.5
982 | */
983 | function postMigrate( $db, & $errors, & $args ) {
984 |
985 | $newPrefix = $args['DBPrefix'];
986 |
987 | /*
988 | * Check to see if migration is from 4.5.1
989 | */
990 | $query = 'SELECT id FROM '.$newPrefix.'users WHERE usertype = "superadministrator"';
991 | $db->setQuery($query);
992 | $rows = $db->loadRowList( );
993 | JInstallationHelper::getDBErrors($errors, $db );
994 |
995 | /*
996 | * if it is, then fill usertype field with correct values from aro_group
997 | */
998 | if ( count($rows) > 0 )
999 | {
1000 | $query = 'UPDATE '.$newPrefix.'users AS u, '.$newPrefix.'core_acl_aro_groups AS g' .
1001 | ' SET u.usertype = g.value' .
1002 | ' WHERE u.gid = g.id';
1003 | $db->setQuery($query);
1004 | $db->query();
1005 | JInstallationHelper::getDBErrors($errors, $db );
1006 | }
1007 |
1008 | /*
1009 | * Construct the menu table based on old table references to core items
1010 | */
1011 | // Component - change all
1012 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `type` = "component" WHERE `type` = "components";';
1013 | $db->setQuery( $query );
1014 | $db->query();
1015 | JInstallationHelper::getDBErrors($errors, $db );
1016 |
1017 | // Component Item Link
1018 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = SUBSTRING(link, 1, LOCATE("&Itemid=", link) -1), `type` = "component" WHERE `type` = "component_item_link";';
1019 | $db->setQuery( $query );
1020 | $db->query();
1021 | JInstallationHelper::getDBErrors($errors, $db );
1022 |
1023 | // get com_contact id
1024 | $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_contact" AND `parent` = 0';
1025 | $db->setQuery( $query );
1026 | JInstallationHelper::getDBErrors($errors, $db );
1027 | $compId = $db->loadResult();
1028 |
1029 | // contact category table
1030 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 0, "view=category&"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "contact_category_table"';
1031 | $db->setQuery( $query );
1032 | $db->query();
1033 | JInstallationHelper::getDBErrors($errors, $db );
1034 |
1035 | // contact item link
1036 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=view", link), 20, "view=contact&id"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "contact_item_link"';
1037 | $db->setQuery( $query );
1038 | $db->query();
1039 | JInstallationHelper::getDBErrors($errors, $db );
1040 |
1041 | // fix up standalone contact
1042 | $query = 'UPDATE `'. $newPrefix.'menu_migration` SET `link` = "index.php?option=com_contact&view=category" WHERE `link` = "index.php?option=com_contact"';
1043 | $db->setQuery( $query );
1044 | $db->query();
1045 | JInstallationHelper::getDBErrors($errors, $db );
1046 |
1047 | // get com_content id
1048 | $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_content" AND `parent` = 0';
1049 | $db->setQuery( $query );
1050 |
1051 | $compId = $db->loadResult();
1052 | JInstallationHelper::getDBErrors($errors, $db );
1053 |
1054 | // front page
1055 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = "index.php?option=com_content&view=frontpage", `type` = "component", `componentid` = '.$compId.' WHERE `link` LIKE "%option=com_frontpage%"';
1056 | $db->setQuery( $query );
1057 | $db->query();
1058 | JInstallationHelper::getDBErrors($errors, $db );
1059 |
1060 | // content archive category or section
1061 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = "index.php?option=com_content&view=archive", `type` = "component", `componentid` = '.$compId.' WHERE (`type` = "content_archive_category" OR `type` = "content_archive_section")';
1062 | $db->setQuery( $query );
1063 | $db->query();
1064 | JInstallationHelper::getDBErrors($errors, $db );
1065 |
1066 | // content blog category
1067 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=blogcat", link), 17, "view=category&layout=blog"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_blog_category"';
1068 | $db->setQuery( $query );
1069 | $db->query();
1070 | JInstallationHelper::getDBErrors($errors, $db );
1071 |
1072 | // content blog section
1073 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=blogsec", link), 16, "view=section&layout=blog"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_blog_section";';
1074 | $db->setQuery( $query );
1075 | $db->query();
1076 | JInstallationHelper::getDBErrors($errors, $db );
1077 |
1078 | // content category
1079 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), LOCATE("&id=", link) - LOCATE("task=", link), "view=category"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_category"';
1080 | $db->setQuery( $query );
1081 | $db->query();
1082 | JInstallationHelper::getDBErrors($errors, $db );
1083 |
1084 | // content item link and typed content
1085 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 9, "view=article"), `type` = "component", `componentid` = '.$compId.' WHERE (`type` = "content_item_link" OR `type` = "content_typed")';
1086 | $db->setQuery( $query );
1087 | $db->query();
1088 | JInstallationHelper::getDBErrors($errors, $db );
1089 |
1090 | // content section
1091 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 12, "view=section"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "content_section"';
1092 | $db->setQuery( $query );
1093 | $db->query();
1094 | JInstallationHelper::getDBErrors($errors, $db );
1095 |
1096 | // get com_newsfeeds id
1097 | $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_newsfeeds" AND `parent` = 0';
1098 | $db->setQuery( $query );
1099 | $compId = $db->loadResult();
1100 | JInstallationHelper::getDBErrors($errors, $db );
1101 |
1102 |
1103 | // newsfeed categories
1104 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=categories"), `componentid` = '.$compId.' WHERE `type` = "component" AND link LIKE "%option=com_newsfeeds%"';
1105 | $db->setQuery( $query );
1106 | $db->query();
1107 | JInstallationHelper::getDBErrors($errors, $db );
1108 |
1109 | // newsfeed category table
1110 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 5, "view=category&catid"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "newsfeed_category_table"';
1111 | $db->setQuery( $query );
1112 | $db->query();
1113 | JInstallationHelper::getDBErrors($errors, $db );
1114 |
1115 | // newsfeed link
1116 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 9, "view=newsfeed"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "newsfeed_link"';
1117 | $db->setQuery( $query );
1118 | $db->query();
1119 | JInstallationHelper::getDBErrors($errors, $db );
1120 |
1121 | // user checkin items
1122 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("CheckIn", link), 7, "checkin") WHERE `type` = "url" AND link LIKE "%option=com_user&task=CheckIn%"';
1123 | $db->setQuery( $query );
1124 | $db->query();
1125 | JInstallationHelper::getDBErrors($errors, $db );
1126 |
1127 | // user edit details
1128 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("UserDetails", link), 11, "edit") WHERE `type` = "url" AND link LIKE "%option=com_user&task=UserDetails%"';
1129 | $db->setQuery( $query );
1130 | $db->query();
1131 | JInstallationHelper::getDBErrors($errors, $db );
1132 |
1133 | // get com_weblinks id
1134 | $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_weblinks" AND `parent` = 0';
1135 | $db->setQuery( $query );
1136 | $compId = $db->loadResult();
1137 | JInstallationHelper::getDBErrors($errors, $db );
1138 |
1139 | // weblinks categories
1140 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=categories"), `componentid` = '.$compId.' WHERE `type` = "component" AND link LIKE "%option=com_weblinks%"';
1141 | $db->setQuery( $query );
1142 | $db->query();
1143 | JInstallationHelper::getDBErrors($errors, $db );
1144 |
1145 | // weblinks category table
1146 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("catid=", link), 5, "view=category&catid"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "weblink_category_table"';
1147 | $db->setQuery( $query );
1148 | $db->query();
1149 | JInstallationHelper::getDBErrors($errors, $db );
1150 |
1151 | // weblinks submit new item
1152 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = INSERT(link, LOCATE("task=", link), 8, "view=weblink&layout=form") WHERE `type` = "url" AND link LIKE "%option=com_weblinks%"';
1153 | $db->setQuery( $query );
1154 | $db->query();
1155 | JInstallationHelper::getDBErrors($errors, $db );
1156 |
1157 | // get com_wrapper id
1158 | $query = 'SELECT `id` FROM `'.$newPrefix.'components` WHERE `option`="com_wrapper" AND `parent` = 0';
1159 | $db->setQuery( $query );
1160 | JInstallationHelper::getDBErrors($errors, $db );
1161 | $compId = $db->loadResult();
1162 |
1163 | // wrapper
1164 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = CONCAT(link, "&view=wrapper"), `type` = "component", `componentid` = '.$compId.' WHERE `type` = "wrapper"';
1165 | $db->setQuery( $query );
1166 | $db->query();
1167 | JInstallationHelper::getDBErrors($errors, $db );
1168 |
1169 | // set default to lowest ordering published on mainmenu
1170 | $query = 'SELECT MIN( `ordering` ) FROM `'.$newPrefix.'menu_migration` WHERE `published` = 1 AND `parent` = 0 AND `menutype` = "mainmenu"';
1171 | $db->setQuery( $query );
1172 | $minorder = $db->loadResult();
1173 | if(!$minorder) $minorder = 0;
1174 | JInstallationHelper::getDBErrors($errors, $db );
1175 | $query = 'SELECT `id` FROM `'.$newPrefix.'menu_migration` WHERE `published` = 1 AND `parent` = 0 AND `menutype` = "mainmenu" AND `ordering` = '.$minorder;
1176 | $db->setQuery( $query );
1177 | $menuitemid = $db->loadResult();
1178 | JInstallationHelper::getDBErrors($errors, $db );
1179 | if(!$menuitemid) $menuitemid = 1;
1180 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `home` = 1 WHERE `id` = '.$menuitemid;
1181 | $db->setQuery( $query );
1182 | $db->query();
1183 | JInstallationHelper::getDBErrors($errors, $db );
1184 |
1185 | // login and log out; component id and link update
1186 | $query = 'SELECT id FROM `'.$newPrefix.'components` WHERE link like "option=com_user"';
1187 | $db->setQuery($query);
1188 | $componentid = $db->loadResult();
1189 | JInstallationHelper::getDBErrors($errors, $db );
1190 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET componentid = '.$componentid .' WHERE link = "index.php?option=com_login"';
1191 | $db->setQuery($query);
1192 | $db->query();
1193 | JInstallationHelper::getDBErrors($errors, $db );
1194 |
1195 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET link = "index.php?option=com_user&view=login" WHERE link = "index.php?option=com_login"';
1196 | $db->setQuery($query);
1197 | $db->query();
1198 | JInstallationHelper::getDBErrors($errors, $db );
1199 |
1200 |
1201 | // Search - Component ID Update
1202 | $query = 'SELECT id FROM `'.$newPrefix.'components` WHERE link like "option=com_search"';
1203 | $db->setQuery($query);
1204 | $componentid = $db->loadResult();
1205 | JInstallationHelper::getDBErrors($errors, $db );
1206 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET componentid = '.$componentid .' WHERE link like "index.php?option=com_search%"';
1207 | $db->setQuery($query);
1208 | $db->query();
1209 | JInstallationHelper::getDBErrors($errors, $db );
1210 |
1211 | // tidy up urls with Itemids
1212 | $query = 'UPDATE `'.$newPrefix.'menu_migration` SET `link` = SUBSTRING(`link`,1,LOCATE("&Itemid",`link`)-1) WHERE `type` = "url" AND `link` LIKE "%&Itemid=%"';
1213 | $db->setQuery( $query );
1214 | $db->query();
1215 | JInstallationHelper::getDBErrors($errors, $db );
1216 | $query = 'SELECT DISTINCT `option` FROM '.$newPrefix.'components WHERE `option` != ""';
1217 | $db->setQuery( $query );
1218 | $lookup = $db->loadResultArray();
1219 | JInstallationHelper::getDBErrors($errors, $db );
1220 | $lookup[] = 'com_user&';
1221 |
1222 | // prepare to copy across
1223 | $query = 'SELECT * FROM '.$newPrefix.'menu_migration';
1224 | $db->setQuery( $query );
1225 | $oldMenuItems = $db->loadObjectList();
1226 | JInstallationHelper::getDBErrors($errors, $db );
1227 |
1228 |
1229 | $query = 'DELETE FROM '.$newPrefix.'menu WHERE 1';
1230 | $db->setQuery( $query );
1231 | $db->query();
1232 | JInstallationHelper::getDBErrors($errors, $db );
1233 | $query = 'SELECT * FROM '.$newPrefix.'menu';
1234 | $db->setQuery( $query );
1235 |
1236 | $newMenuItems = $db->loadObjectList();
1237 | JInstallationHelper::getDBErrors($errors, $db );
1238 |
1239 | // filter out links to 3pd components
1240 | foreach( $oldMenuItems as $item )
1241 | {
1242 | if ( $item->type == 'url' && !strpos( $item->link, 'com_') )
1243 | {
1244 | $newMenuItems[] = $item;
1245 | }
1246 | else if ( $item->type == 'url' && JInstallationHelper::isValidItem( $item->link, $lookup ) )
1247 | {
1248 | $newMenuItems[] = $item;
1249 | }
1250 | else if ( $item->type == 'component' ) //&& JInstallationHelper::isValidItem( $item->link, $lookup ))
1251 | {
1252 | // unpublish components that don't exist yet
1253 | if(!JInstallationHelper::isValidItem( $item->link, $lookup )) $item->published = 0;
1254 | $newMenuItems[] = $item;
1255 | }
1256 | }
1257 |
1258 | // build the menu table
1259 | foreach ( $newMenuItems as $item )
1260 | {
1261 | $db->insertObject( $newPrefix.'menu', $item );
1262 | JInstallationHelper::getDBErrors($errors, $db );
1263 | }
1264 |
1265 | // fix possible orphaned sub menu items
1266 | $query = 'UPDATE `'.$newPrefix.'menu` AS c LEFT OUTER JOIN `'.$newPrefix.'menu` AS p ON c.parent = p.id SET c.parent = 0 WHERE c.parent <> 0 AND p.id IS NULL';
1267 | $db->setQuery( $query );
1268 | $db->query();
1269 | JInstallationHelper::getDBErrors($errors, $db );
1270 |
1271 | /*
1272 | * Construct the menu_type table base on new menu table types
1273 | */
1274 | $query = 'SELECT DISTINCT `menutype` FROM '.$newPrefix.'menu WHERE 1';
1275 | $db->setQuery( $query );
1276 | JInstallationHelper::getDBErrors($errors, $db );
1277 | $menuTypes = $db->loadResultArray();
1278 | $query = 'TRUNCATE TABLE '.$newPrefix.'menu_types';
1279 | $db->setQuery($query);
1280 |
1281 | $db->query();
1282 | JInstallationHelper::getDBErrors($errors, $db );
1283 |
1284 | foreach( $menuTypes as $mType )
1285 | {
1286 | $query = 'INSERT INTO '.$newPrefix.'menu_types ( menutype, title ) VALUES ("'.$mType.'", "'.$mType.'");';
1287 | $db->setQuery($query);
1288 | $db->query();
1289 | JInstallationHelper::getDBErrors($errors, $db );
1290 | }
1291 |
1292 | /*
1293 | * Add core client modules from old site to modules table as unpublished
1294 | */
1295 | $query = 'SELECT id FROM '.$newPrefix.'modules_migration WHERE client_id = 0 ';
1296 | $db->setQuery( $query );
1297 | $lookup = $db->loadResultArray();
1298 | JInstallationHelper::getDBErrors($errors, $db );
1299 |
1300 | $query = 'SELECT MAX(id) FROM '.$newPrefix.'modules ';
1301 | $db->setQuery( $query );
1302 | $nextId = $db->loadResult();
1303 | JInstallationHelper::getDBErrors($errors, $db );
1304 | jimport('joomla.filesystem.folder');
1305 | jimport('joomla.filesystem.file');
1306 | foreach( $lookup as $module )
1307 | {
1308 | $qry = 'SELECT * FROM '.$newPrefix.'modules_migration WHERE id = "'.$module.'" AND client_id = 0';
1309 | $db->setQuery( $qry );
1310 | if ( $row = $db->loadObject() ) {
1311 | if($row->module == '') { $row->module = 'mod_custom'; }
1312 | if(JFolder::exists(JPATH_SITE.'/modules/'.row->module)) {
1313 | $nextId++;
1314 | $oldid = $row->id;
1315 | $row->id = $nextId;
1316 | $row->published = 0;
1317 | if($db->insertObject( $newPrefix.'modules', $row )) {
1318 | // Grab the old modules menu links and put them in too!
1319 | $qry = 'SELECT * FROM '. $newPrefix .'modules_migration_menu WHERE moduleid = '. $oldid;
1320 | $db->setQuery($qry);
1321 | $entries = $db->loadObjectList();
1322 | JInstallationHelper::getDBErrors($errors, $db );
1323 |
1324 | foreach($entries as $entry) {
1325 | $entry->moduleid = $nextId;
1326 | $db->insertObject($newPrefix.'modules_menu', $entry);
1327 | JInstallationHelper::getDBErrors($errors, $db );
1328 | }
1329 | } else JInstallationHelper::getDBErrors($errors, $db );
1330 | } // else the module doesn't exist?
1331 | } else JInstallationHelper::getDBErrors($errors, $db );
1332 | }
1333 |
1334 | // Put in breadcrumb module as per sample data
1335 | $query = "INSERT INTO `".$newPrefix ."modules` VALUES (0, 'Breadcrumbs', '', 1, 'breadcrumb', 0, '0000-00-00 00:00:00', 1, 'mod_breadcrumbs', 0, 0, 1, 'moduleclass_sfx=\ncache=0\nshowHome=1\nhomeText=Home\nshowComponent=1\nseparator=\n\n', 1, 0, '');";
1336 | $db->setQuery($query);
1337 | $db->Query();
1338 | JInstallationHelper::getDBErrors($errors, $db);
1339 |
1340 | /*
1341 | * Clean up
1342 | */
1343 |
1344 | $query = 'DROP TABLE IF EXISTS '.$newPrefix.'modules_migration';
1345 | $db->setQuery( $query );
1346 | $db->query();
1347 | JInstallationHelper::getDBErrors($errors, $db );
1348 |
1349 | $query = 'DROP TABLE IF EXISTS '.$newPrefix.'modules_migration_menu';
1350 | $db->setQuery( $query );
1351 | $db->query();
1352 | JInstallationHelper::getDBErrors($errors, $db );
1353 |
1354 | $query = 'DROP TABLE IF EXISTS '.$newPrefix.'menu_migration';
1355 | $db->setQuery( $query );
1356 | $db->query();
1357 | JInstallationHelper::getDBErrors($errors, $db );
1358 |
1359 | return count( $errors );
1360 | }
1361 |
1362 | function isValidItem ( $link, $lookup )
1363 | {
1364 | foreach( $lookup as $component )
1365 | {
1366 | if ( strpos( $link, $component ) != false )
1367 | {
1368 | return true;
1369 | }
1370 | }
1371 | return false;
1372 | }
1373 |
1374 | function getDBErrors( & $errors, $db )
1375 | {
1376 | if ($db->getErrorNum() > 0)
1377 | {
1378 | $errors[] = array('msg' => $db->getErrorMsg(), 'sql' => $db->_sql);
1379 | }
1380 | }
1381 |
1382 | /**
1383 | * Inserts ftp variables to mainframe registry
1384 | * Needed to activate ftp layer for file operations in safe mode
1385 | *
1386 | * @param array The post values
1387 | */
1388 | function setFTPCfg( $vars )
1389 | {
1390 | global $mainframe;
1391 | $arr = array();
1392 | $arr['ftp_enable'] = $vars['ftpEnable'];
1393 | $arr['ftp_user'] = $vars['ftpUser'];
1394 | $arr['ftp_pass'] = $vars['ftpPassword'];
1395 | $arr['ftp_root'] = $vars['ftpRoot'];
1396 | $arr['ftp_host'] = $vars['ftpHost'];
1397 | $arr['ftp_port'] = $vars['ftpPort'];
1398 |
1399 | $mainframe->setCfg( $arr, 'config' );
1400 | }
1401 |
1402 | function _chmod( $path, $mode )
1403 | {
1404 | global $mainframe;
1405 | $ret = false;
1406 |
1407 | // Initialize variables
1408 | $ftpFlag = true;
1409 | $ftpRoot = $mainframe->getCfg('ftp_root');
1410 |
1411 | // Do NOT use ftp if it is not enabled
1412 | if ($mainframe->getCfg('ftp_enable') != 1) {
1413 | $ftpFlag = false;
1414 | }
1415 |
1416 | if ($ftpFlag == true)
1417 | {
1418 | // Connect the FTP client
1419 | jimport('joomla.client.ftp');
1420 | $ftp = & JFTP::getInstance($mainframe->getCfg('ftp_host'), $mainframe->getCfg('ftp_port'));
1421 | $ftp->login($mainframe->getCfg('ftp_user'), $mainframe->getCfg('ftp_pass'));
1422 |
1423 | //Translate the destination path for the FTP account
1424 | $path = JPath::clean(str_replace(JPATH_SITE, $ftpRoot, $path), '/');
1425 |
1426 | // do the ftp chmod
1427 | if (!$ftp->chmod($path, $mode))
1428 | {
1429 | // FTP connector throws an error
1430 | return false;
1431 | }
1432 | $ftp->quit();
1433 | $ret = true;
1434 | }
1435 | else
1436 | {
1437 | $ret = @ chmod($path, $mode);
1438 | }
1439 |
1440 | return $ret;
1441 | }
1442 |
1443 | /** Borrowed from http://au.php.net/manual/en/ini.core.php comments */
1444 | function let_to_num($v){ //This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
1445 | $l = substr($v, -1);
1446 | $ret = substr($v, 0, -1);
1447 | switch(strtoupper($l)){
1448 | case 'P':
1449 | $ret *= 1024;
1450 | case 'T':
1451 | $ret *= 1024;
1452 | case 'G':
1453 | $ret *= 1024;
1454 | case 'M':
1455 | $ret *= 1024;
1456 | case 'K':
1457 | $ret *= 1024;
1458 | break;
1459 | }
1460 | return $ret;
1461 | }
1462 | }
1463 | ?>
1464 |
--------------------------------------------------------------------------------
/admin/js/jquery.js:
--------------------------------------------------------------------------------
1 | /*
2 | * jQuery JavaScript Library v1.3.2
3 | * http://jquery.com/
4 | *
5 | * Copyright (c) 2009 John Resig
6 | * Dual licensed under the MIT and GPL licenses.
7 | * http://docs.jquery.com/License
8 | *
9 | * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
10 | * Revision: 6246
11 | */
12 | (function(){var l=this,g,y=l.jQuery,p=l.$,o=l.jQuery=l.$=function(E,F){return new o.fn.init(E,F)},D=/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,f=/^.[^:#\[\.,]*$/;o.fn=o.prototype={init:function(E,H){E=E||document;if(E.nodeType){this[0]=E;this.length=1;this.context=E;return this}if(typeof E==="string"){var G=D.exec(E);if(G&&(G[1]||!H)){if(G[1]){E=o.clean([G[1]],H)}else{var I=document.getElementById(G[3]);if(I&&I.id!=G[3]){return o().find(E)}var F=o(I||[]);F.context=document;F.selector=E;return F}}else{return o(H).find(E)}}else{if(o.isFunction(E)){return o(document).ready(E)}}if(E.selector&&E.context){this.selector=E.selector;this.context=E.context}return this.setArray(o.isArray(E)?E:o.makeArray(E))},selector:"",jquery:"1.3.2",size:function(){return this.length},get:function(E){return E===g?Array.prototype.slice.call(this):this[E]},pushStack:function(F,H,E){var G=o(F);G.prevObject=this;G.context=this.context;if(H==="find"){G.selector=this.selector+(this.selector?" ":"")+E}else{if(H){G.selector=this.selector+"."+H+"("+E+")"}}return G},setArray:function(E){this.length=0;Array.prototype.push.apply(this,E);return this},each:function(F,E){return o.each(this,F,E)},index:function(E){return o.inArray(E&&E.jquery?E[0]:E,this)},attr:function(F,H,G){var E=F;if(typeof F==="string"){if(H===g){return this[0]&&o[G||"attr"](this[0],F)}else{E={};E[F]=H}}return this.each(function(I){for(F in E){o.attr(G?this.style:this,F,o.prop(this,E[F],G,I,F))}})},css:function(E,F){if((E=="width"||E=="height")&&parseFloat(F)<0){F=g}return this.attr(E,F,"curCSS")},text:function(F){if(typeof F!=="object"&&F!=null){return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(F))}var E="";o.each(F||this,function(){o.each(this.childNodes,function(){if(this.nodeType!=8){E+=this.nodeType!=1?this.nodeValue:o.fn.text([this])}})});return E},wrapAll:function(E){if(this[0]){var F=o(E,this[0].ownerDocument).clone();if(this[0].parentNode){F.insertBefore(this[0])}F.map(function(){var G=this;while(G.firstChild){G=G.firstChild}return G}).append(this)}return this},wrapInner:function(E){return this.each(function(){o(this).contents().wrapAll(E)})},wrap:function(E){return this.each(function(){o(this).wrapAll(E)})},append:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.appendChild(E)}})},prepend:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.insertBefore(E,this.firstChild)}})},before:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this)})},after:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this.nextSibling)})},end:function(){return this.prevObject||o([])},push:[].push,sort:[].sort,splice:[].splice,find:function(E){if(this.length===1){var F=this.pushStack([],"find",E);F.length=0;o.find(E,this[0],F);return F}else{return this.pushStack(o.unique(o.map(this,function(G){return o.find(E,G)})),"find",E)}},clone:function(G){var E=this.map(function(){if(!o.support.noCloneEvent&&!o.isXMLDoc(this)){var I=this.outerHTML;if(!I){var J=this.ownerDocument.createElement("div");J.appendChild(this.cloneNode(true));I=J.innerHTML}return o.clean([I.replace(/ jQuery\d+="(?:\d+|null)"/g,"").replace(/^\s*/,"")])[0]}else{return this.cloneNode(true)}});if(G===true){var H=this.find("*").andSelf(),F=0;E.find("*").andSelf().each(function(){if(this.nodeName!==H[F].nodeName){return}var I=o.data(H[F],"events");for(var K in I){for(var J in I[K]){o.event.add(this,K,I[K][J],I[K][J].data)}}F++})}return E},filter:function(E){return this.pushStack(o.isFunction(E)&&o.grep(this,function(G,F){return E.call(G,F)})||o.multiFilter(E,o.grep(this,function(F){return F.nodeType===1})),"filter",E)},closest:function(E){var G=o.expr.match.POS.test(E)?o(E):null,F=0;return this.map(function(){var H=this;while(H&&H.ownerDocument){if(G?G.index(H)>-1:o(H).is(E)){o.data(H,"closest",F);return H}H=H.parentNode;F++}})},not:function(E){if(typeof E==="string"){if(f.test(E)){return this.pushStack(o.multiFilter(E,this,true),"not",E)}else{E=o.multiFilter(E,this)}}var F=E.length&&E[E.length-1]!==g&&!E.nodeType;return this.filter(function(){return F?o.inArray(this,E)<0:this!=E})},add:function(E){return this.pushStack(o.unique(o.merge(this.get(),typeof E==="string"?o(E):o.makeArray(E))))},is:function(E){return !!E&&o.multiFilter(E,this).length>0},hasClass:function(E){return !!E&&this.is("."+E)},val:function(K){if(K===g){var E=this[0];if(E){if(o.nodeName(E,"option")){return(E.attributes.value||{}).specified?E.value:E.text}if(o.nodeName(E,"select")){var I=E.selectedIndex,L=[],M=E.options,H=E.type=="select-one";if(I<0){return null}for(var F=H?I:0,J=H?I+1:M.length;F=0||o.inArray(this.name,K)>=0)}else{if(o.nodeName(this,"select")){var N=o.makeArray(K);o("option",this).each(function(){this.selected=(o.inArray(this.value,N)>=0||o.inArray(this.text,N)>=0)});if(!N.length){this.selectedIndex=-1}}else{this.value=K}}})},html:function(E){return E===g?(this[0]?this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g,""):null):this.empty().append(E)},replaceWith:function(E){return this.after(E).remove()},eq:function(E){return this.slice(E,+E+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments),"slice",Array.prototype.slice.call(arguments).join(","))},map:function(E){return this.pushStack(o.map(this,function(G,F){return E.call(G,F,G)}))},andSelf:function(){return this.add(this.prevObject)},domManip:function(J,M,L){if(this[0]){var I=(this[0].ownerDocument||this[0]).createDocumentFragment(),F=o.clean(J,(this[0].ownerDocument||this[0]),I),H=I.firstChild;if(H){for(var G=0,E=this.length;G1||G>0?I.cloneNode(true):I)}}if(F){o.each(F,z)}}return this;function K(N,O){return M&&o.nodeName(N,"table")&&o.nodeName(O,"tr")?(N.getElementsByTagName("tbody")[0]||N.appendChild(N.ownerDocument.createElement("tbody"))):N}}};o.fn.init.prototype=o.fn;function z(E,F){if(F.src){o.ajax({url:F.src,async:false,dataType:"script"})}else{o.globalEval(F.text||F.textContent||F.innerHTML||"")}if(F.parentNode){F.parentNode.removeChild(F)}}function e(){return +new Date}o.extend=o.fn.extend=function(){var J=arguments[0]||{},H=1,I=arguments.length,E=false,G;if(typeof J==="boolean"){E=J;J=arguments[1]||{};H=2}if(typeof J!=="object"&&!o.isFunction(J)){J={}}if(I==H){J=this;--H}for(;H-1}},swap:function(H,G,I){var E={};for(var F in G){E[F]=H.style[F];H.style[F]=G[F]}I.call(H);for(var F in G){H.style[F]=E[F]}},css:function(H,F,J,E){if(F=="width"||F=="height"){var L,G={position:"absolute",visibility:"hidden",display:"block"},K=F=="width"?["Left","Right"]:["Top","Bottom"];function I(){L=F=="width"?H.offsetWidth:H.offsetHeight;if(E==="border"){return}o.each(K,function(){if(!E){L-=parseFloat(o.curCSS(H,"padding"+this,true))||0}if(E==="margin"){L+=parseFloat(o.curCSS(H,"margin"+this,true))||0}else{L-=parseFloat(o.curCSS(H,"border"+this+"Width",true))||0}})}if(H.offsetWidth!==0){I()}else{o.swap(H,G,I)}return Math.max(0,Math.round(L))}return o.curCSS(H,F,J)},curCSS:function(I,F,G){var L,E=I.style;if(F=="opacity"&&!o.support.opacity){L=o.attr(E,"opacity");return L==""?"1":L}if(F.match(/float/i)){F=w}if(!G&&E&&E[F]){L=E[F]}else{if(q.getComputedStyle){if(F.match(/float/i)){F="float"}F=F.replace(/([A-Z])/g,"-$1").toLowerCase();var M=q.getComputedStyle(I,null);if(M){L=M.getPropertyValue(F)}if(F=="opacity"&&L==""){L="1"}}else{if(I.currentStyle){var J=F.replace(/\-(\w)/g,function(N,O){return O.toUpperCase()});L=I.currentStyle[F]||I.currentStyle[J];if(!/^\d+(px)?$/i.test(L)&&/^\d/.test(L)){var H=E.left,K=I.runtimeStyle.left;I.runtimeStyle.left=I.currentStyle.left;E.left=L||0;L=E.pixelLeft+"px";E.left=H;I.runtimeStyle.left=K}}}}return L},clean:function(F,K,I){K=K||document;if(typeof K.createElement==="undefined"){K=K.ownerDocument||K[0]&&K[0].ownerDocument||document}if(!I&&F.length===1&&typeof F[0]==="string"){var H=/^<(\w+)\s*\/?>$/.exec(F[0]);if(H){return[K.createElement(H[1])]}}var G=[],E=[],L=K.createElement("div");o.each(F,function(P,S){if(typeof S==="number"){S+=""}if(!S){return}if(typeof S==="string"){S=S.replace(/(<(\w+)[^>]*?)\/>/g,function(U,V,T){return T.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?U:V+">"+T+">"});var O=S.replace(/^\s+/,"").substring(0,10).toLowerCase();var Q=!O.indexOf("",""]||!O.indexOf("",""]||O.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,""]||!O.indexOf("
",""]||(!O.indexOf(" | ","
"]||!O.indexOf("",""]||!o.support.htmlSerialize&&[1,"div","
"]||[0,"",""];L.innerHTML=Q[1]+S+Q[2];while(Q[0]--){L=L.lastChild}if(!o.support.tbody){var R=/"&&!R?L.childNodes:[];for(var M=N.length-1;M>=0;--M){if(o.nodeName(N[M],"tbody")&&!N[M].childNodes.length){N[M].parentNode.removeChild(N[M])}}}if(!o.support.leadingWhitespace&&/^\s/.test(S)){L.insertBefore(K.createTextNode(S.match(/^\s*/)[0]),L.firstChild)}S=o.makeArray(L.childNodes)}if(S.nodeType){G.push(S)}else{G=o.merge(G,S)}});if(I){for(var J=0;G[J];J++){if(o.nodeName(G[J],"script")&&(!G[J].type||G[J].type.toLowerCase()==="text/javascript")){E.push(G[J].parentNode?G[J].parentNode.removeChild(G[J]):G[J])}else{if(G[J].nodeType===1){G.splice.apply(G,[J+1,0].concat(o.makeArray(G[J].getElementsByTagName("script"))))}I.appendChild(G[J])}}return E}return G},attr:function(J,G,K){if(!J||J.nodeType==3||J.nodeType==8){return g}var H=!o.isXMLDoc(J),L=K!==g;G=H&&o.props[G]||G;if(J.tagName){var F=/href|src|style/.test(G);if(G=="selected"&&J.parentNode){J.parentNode.selectedIndex}if(G in J&&H&&!F){if(L){if(G=="type"&&o.nodeName(J,"input")&&J.parentNode){throw"type property can't be changed"}J[G]=K}if(o.nodeName(J,"form")&&J.getAttributeNode(G)){return J.getAttributeNode(G).nodeValue}if(G=="tabIndex"){var I=J.getAttributeNode("tabIndex");return I&&I.specified?I.value:J.nodeName.match(/(button|input|object|select|textarea)/i)?0:J.nodeName.match(/^(a|area)$/i)&&J.href?0:g}return J[G]}if(!o.support.style&&H&&G=="style"){return o.attr(J.style,"cssText",K)}if(L){J.setAttribute(G,""+K)}var E=!o.support.hrefNormalized&&H&&F?J.getAttribute(G,2):J.getAttribute(G);return E===null?g:E}if(!o.support.opacity&&G=="opacity"){if(L){J.zoom=1;J.filter=(J.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(K)+""=="NaN"?"":"alpha(opacity="+K*100+")")}return J.filter&&J.filter.indexOf("opacity=")>=0?(parseFloat(J.filter.match(/opacity=([^)]*)/)[1])/100)+"":""}G=G.replace(/-([a-z])/ig,function(M,N){return N.toUpperCase()});if(L){J[G]=K}return J[G]},trim:function(E){return(E||"").replace(/^\s+|\s+$/g,"")},makeArray:function(G){var E=[];if(G!=null){var F=G.length;if(F==null||typeof G==="string"||o.isFunction(G)||G.setInterval){E[0]=G}else{while(F){E[--F]=G[F]}}}return E},inArray:function(G,H){for(var E=0,F=H.length;E0?this.clone(true):this).get();o.fn[F].apply(o(L[K]),I);J=J.concat(I)}return this.pushStack(J,E,G)}});o.each({removeAttr:function(E){o.attr(this,E,"");if(this.nodeType==1){this.removeAttribute(E)}},addClass:function(E){o.className.add(this,E)},removeClass:function(E){o.className.remove(this,E)},toggleClass:function(F,E){if(typeof E!=="boolean"){E=!o.className.has(this,F)}o.className[E?"add":"remove"](this,F)},remove:function(E){if(!E||o.filter(E,[this]).length){o("*",this).add([this]).each(function(){o.event.remove(this);o.removeData(this)});if(this.parentNode){this.parentNode.removeChild(this)}}},empty:function(){o(this).children().remove();while(this.firstChild){this.removeChild(this.firstChild)}}},function(E,F){o.fn[E]=function(){return this.each(F,arguments)}});function j(E,F){return E[0]&&parseInt(o.curCSS(E[0],F,true),10)||0}var h="jQuery"+e(),v=0,A={};o.extend({cache:{},data:function(F,E,G){F=F==l?A:F;var H=F[h];if(!H){H=F[h]=++v}if(E&&!o.cache[H]){o.cache[H]={}}if(G!==g){o.cache[H][E]=G}return E?o.cache[H][E]:H},removeData:function(F,E){F=F==l?A:F;var H=F[h];if(E){if(o.cache[H]){delete o.cache[H][E];E="";for(E in o.cache[H]){break}if(!E){o.removeData(F)}}}else{try{delete F[h]}catch(G){if(F.removeAttribute){F.removeAttribute(h)}}delete o.cache[H]}},queue:function(F,E,H){if(F){E=(E||"fx")+"queue";var G=o.data(F,E);if(!G||o.isArray(H)){G=o.data(F,E,o.makeArray(H))}else{if(H){G.push(H)}}}return G},dequeue:function(H,G){var E=o.queue(H,G),F=E.shift();if(!G||G==="fx"){F=E[0]}if(F!==g){F.call(H)}}});o.fn.extend({data:function(E,G){var H=E.split(".");H[1]=H[1]?"."+H[1]:"";if(G===g){var F=this.triggerHandler("getData"+H[1]+"!",[H[0]]);if(F===g&&this.length){F=o.data(this[0],E)}return F===g&&H[1]?this.data(H[0]):F}else{return this.trigger("setData"+H[1]+"!",[H[0],G]).each(function(){o.data(this,E,G)})}},removeData:function(E){return this.each(function(){o.removeData(this,E)})},queue:function(E,F){if(typeof E!=="string"){F=E;E="fx"}if(F===g){return o.queue(this[0],E)}return this.each(function(){var G=o.queue(this,E,F);if(E=="fx"&&G.length==1){G[0].call(this)}})},dequeue:function(E){return this.each(function(){o.dequeue(this,E)})}});
13 | /*
14 | * Sizzle CSS Selector Engine - v0.9.3
15 | * Copyright 2009, The Dojo Foundation
16 | * Released under the MIT, BSD, and GPL Licenses.
17 | * More information: http://sizzlejs.com/
18 | */
19 | (function(){var R=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,L=0,H=Object.prototype.toString;var F=function(Y,U,ab,ac){ab=ab||[];U=U||document;if(U.nodeType!==1&&U.nodeType!==9){return[]}if(!Y||typeof Y!=="string"){return ab}var Z=[],W,af,ai,T,ad,V,X=true;R.lastIndex=0;while((W=R.exec(Y))!==null){Z.push(W[1]);if(W[2]){V=RegExp.rightContext;break}}if(Z.length>1&&M.exec(Y)){if(Z.length===2&&I.relative[Z[0]]){af=J(Z[0]+Z[1],U)}else{af=I.relative[Z[0]]?[U]:F(Z.shift(),U);while(Z.length){Y=Z.shift();if(I.relative[Y]){Y+=Z.shift()}af=J(Y,af)}}}else{var ae=ac?{expr:Z.pop(),set:E(ac)}:F.find(Z.pop(),Z.length===1&&U.parentNode?U.parentNode:U,Q(U));af=F.filter(ae.expr,ae.set);if(Z.length>0){ai=E(af)}else{X=false}while(Z.length){var ah=Z.pop(),ag=ah;if(!I.relative[ah]){ah=""}else{ag=Z.pop()}if(ag==null){ag=U}I.relative[ah](ai,ag,Q(U))}}if(!ai){ai=af}if(!ai){throw"Syntax error, unrecognized expression: "+(ah||Y)}if(H.call(ai)==="[object Array]"){if(!X){ab.push.apply(ab,ai)}else{if(U.nodeType===1){for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&(ai[aa]===true||ai[aa].nodeType===1&&K(U,ai[aa]))){ab.push(af[aa])}}}else{for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&ai[aa].nodeType===1){ab.push(af[aa])}}}}}else{E(ai,ab)}if(V){F(V,U,ab,ac);if(G){hasDuplicate=false;ab.sort(G);if(hasDuplicate){for(var aa=1;aa":function(Z,U,aa){var X=typeof U==="string";if(X&&!/\W/.test(U)){U=aa?U:U.toUpperCase();for(var V=0,T=Z.length;V=0)){if(!V){T.push(Y)}}else{if(V){U[X]=false}}}}return false},ID:function(T){return T[1].replace(/\\/g,"")},TAG:function(U,T){for(var V=0;T[V]===false;V++){}return T[V]&&Q(T[V])?U[1]:U[1].toUpperCase()},CHILD:function(T){if(T[1]=="nth"){var U=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(T[2]=="even"&&"2n"||T[2]=="odd"&&"2n+1"||!/\D/.test(T[2])&&"0n+"+T[2]||T[2]);T[2]=(U[1]+(U[2]||1))-0;T[3]=U[3]-0}T[0]=L++;return T},ATTR:function(X,U,V,T,Y,Z){var W=X[1].replace(/\\/g,"");if(!Z&&I.attrMap[W]){X[1]=I.attrMap[W]}if(X[2]==="~="){X[4]=" "+X[4]+" "}return X},PSEUDO:function(X,U,V,T,Y){if(X[1]==="not"){if(X[3].match(R).length>1||/^\w/.test(X[3])){X[3]=F(X[3],null,null,U)}else{var W=F.filter(X[3],U,V,true^Y);if(!V){T.push.apply(T,W)}return false}}else{if(I.match.POS.test(X[0])||I.match.CHILD.test(X[0])){return true}}return X},POS:function(T){T.unshift(true);return T}},filters:{enabled:function(T){return T.disabled===false&&T.type!=="hidden"},disabled:function(T){return T.disabled===true},checked:function(T){return T.checked===true},selected:function(T){T.parentNode.selectedIndex;return T.selected===true},parent:function(T){return !!T.firstChild},empty:function(T){return !T.firstChild},has:function(V,U,T){return !!F(T[3],V).length},header:function(T){return/h\d/i.test(T.nodeName)},text:function(T){return"text"===T.type},radio:function(T){return"radio"===T.type},checkbox:function(T){return"checkbox"===T.type},file:function(T){return"file"===T.type},password:function(T){return"password"===T.type},submit:function(T){return"submit"===T.type},image:function(T){return"image"===T.type},reset:function(T){return"reset"===T.type},button:function(T){return"button"===T.type||T.nodeName.toUpperCase()==="BUTTON"},input:function(T){return/input|select|textarea|button/i.test(T.nodeName)}},setFilters:{first:function(U,T){return T===0},last:function(V,U,T,W){return U===W.length-1},even:function(U,T){return T%2===0},odd:function(U,T){return T%2===1},lt:function(V,U,T){return UT[3]-0},nth:function(V,U,T){return T[3]-0==U},eq:function(V,U,T){return T[3]-0==U}},filter:{PSEUDO:function(Z,V,W,aa){var U=V[1],X=I.filters[U];if(X){return X(Z,W,V,aa)}else{if(U==="contains"){return(Z.textContent||Z.innerText||"").indexOf(V[3])>=0}else{if(U==="not"){var Y=V[3];for(var W=0,T=Y.length;W=0)}}},ID:function(U,T){return U.nodeType===1&&U.getAttribute("id")===T},TAG:function(U,T){return(T==="*"&&U.nodeType===1)||U.nodeName===T},CLASS:function(U,T){return(" "+(U.className||U.getAttribute("class"))+" ").indexOf(T)>-1},ATTR:function(Y,W){var V=W[1],T=I.attrHandle[V]?I.attrHandle[V](Y):Y[V]!=null?Y[V]:Y.getAttribute(V),Z=T+"",X=W[2],U=W[4];return T==null?X==="!=":X==="="?Z===U:X==="*="?Z.indexOf(U)>=0:X==="~="?(" "+Z+" ").indexOf(U)>=0:!U?Z&&T!==false:X==="!="?Z!=U:X==="^="?Z.indexOf(U)===0:X==="$="?Z.substr(Z.length-U.length)===U:X==="|="?Z===U||Z.substr(0,U.length+1)===U+"-":false},POS:function(X,U,V,Y){var T=U[2],W=I.setFilters[T];if(W){return W(X,V,U,Y)}}}};var M=I.match.POS;for(var O in I.match){I.match[O]=RegExp(I.match[O].source+/(?![^\[]*\])(?![^\(]*\))/.source)}var E=function(U,T){U=Array.prototype.slice.call(U);if(T){T.push.apply(T,U);return T}return U};try{Array.prototype.slice.call(document.documentElement.childNodes)}catch(N){E=function(X,W){var U=W||[];if(H.call(X)==="[object Array]"){Array.prototype.push.apply(U,X)}else{if(typeof X.length==="number"){for(var V=0,T=X.length;V";var T=document.documentElement;T.insertBefore(U,T.firstChild);if(!!document.getElementById(V)){I.find.ID=function(X,Y,Z){if(typeof Y.getElementById!=="undefined"&&!Z){var W=Y.getElementById(X[1]);return W?W.id===X[1]||typeof W.getAttributeNode!=="undefined"&&W.getAttributeNode("id").nodeValue===X[1]?[W]:g:[]}};I.filter.ID=function(Y,W){var X=typeof Y.getAttributeNode!=="undefined"&&Y.getAttributeNode("id");return Y.nodeType===1&&X&&X.nodeValue===W}}T.removeChild(U)})();(function(){var T=document.createElement("div");T.appendChild(document.createComment(""));if(T.getElementsByTagName("*").length>0){I.find.TAG=function(U,Y){var X=Y.getElementsByTagName(U[1]);if(U[1]==="*"){var W=[];for(var V=0;X[V];V++){if(X[V].nodeType===1){W.push(X[V])}}X=W}return X}}T.innerHTML="";if(T.firstChild&&typeof T.firstChild.getAttribute!=="undefined"&&T.firstChild.getAttribute("href")!=="#"){I.attrHandle.href=function(U){return U.getAttribute("href",2)}}})();if(document.querySelectorAll){(function(){var T=F,U=document.createElement("div");U.innerHTML="";if(U.querySelectorAll&&U.querySelectorAll(".TEST").length===0){return}F=function(Y,X,V,W){X=X||document;if(!W&&X.nodeType===9&&!Q(X)){try{return E(X.querySelectorAll(Y),V)}catch(Z){}}return T(Y,X,V,W)};F.find=T.find;F.filter=T.filter;F.selectors=T.selectors;F.matches=T.matches})()}if(document.getElementsByClassName&&document.documentElement.getElementsByClassName){(function(){var T=document.createElement("div");T.innerHTML="";if(T.getElementsByClassName("e").length===0){return}T.lastChild.className="e";if(T.getElementsByClassName("e").length===1){return}I.order.splice(1,0,"CLASS");I.find.CLASS=function(U,V,W){if(typeof V.getElementsByClassName!=="undefined"&&!W){return V.getElementsByClassName(U[1])}}})()}function P(U,Z,Y,ad,aa,ac){var ab=U=="previousSibling"&&!ac;for(var W=0,V=ad.length;W0){X=T;break}}}T=T[U]}ad[W]=X}}}var K=document.compareDocumentPosition?function(U,T){return U.compareDocumentPosition(T)&16}:function(U,T){return U!==T&&(U.contains?U.contains(T):true)};var Q=function(T){return T.nodeType===9&&T.documentElement.nodeName!=="HTML"||!!T.ownerDocument&&Q(T.ownerDocument)};var J=function(T,aa){var W=[],X="",Y,V=aa.nodeType?[aa]:aa;while((Y=I.match.PSEUDO.exec(T))){X+=Y[0];T=T.replace(I.match.PSEUDO,"")}T=I.relative[T]?T+"*":T;for(var Z=0,U=V.length;Z0||T.offsetHeight>0};F.selectors.filters.animated=function(T){return o.grep(o.timers,function(U){return T===U.elem}).length};o.multiFilter=function(V,T,U){if(U){V=":not("+V+")"}return F.matches(V,T)};o.dir=function(V,U){var T=[],W=V[U];while(W&&W!=document){if(W.nodeType==1){T.push(W)}W=W[U]}return T};o.nth=function(X,T,V,W){T=T||1;var U=0;for(;X;X=X[V]){if(X.nodeType==1&&++U==T){break}}return X};o.sibling=function(V,U){var T=[];for(;V;V=V.nextSibling){if(V.nodeType==1&&V!=U){T.push(V)}}return T};return;l.Sizzle=F})();o.event={add:function(I,F,H,K){if(I.nodeType==3||I.nodeType==8){return}if(I.setInterval&&I!=l){I=l}if(!H.guid){H.guid=this.guid++}if(K!==g){var G=H;H=this.proxy(G);H.data=K}var E=o.data(I,"events")||o.data(I,"events",{}),J=o.data(I,"handle")||o.data(I,"handle",function(){return typeof o!=="undefined"&&!o.event.triggered?o.event.handle.apply(arguments.callee.elem,arguments):g});J.elem=I;o.each(F.split(/\s+/),function(M,N){var O=N.split(".");N=O.shift();H.type=O.slice().sort().join(".");var L=E[N];if(o.event.specialAll[N]){o.event.specialAll[N].setup.call(I,K,O)}if(!L){L=E[N]={};if(!o.event.special[N]||o.event.special[N].setup.call(I,K,O)===false){if(I.addEventListener){I.addEventListener(N,J,false)}else{if(I.attachEvent){I.attachEvent("on"+N,J)}}}}L[H.guid]=H;o.event.global[N]=true});I=null},guid:1,global:{},remove:function(K,H,J){if(K.nodeType==3||K.nodeType==8){return}var G=o.data(K,"events"),F,E;if(G){if(H===g||(typeof H==="string"&&H.charAt(0)==".")){for(var I in G){this.remove(K,I+(H||""))}}else{if(H.type){J=H.handler;H=H.type}o.each(H.split(/\s+/),function(M,O){var Q=O.split(".");O=Q.shift();var N=RegExp("(^|\\.)"+Q.slice().sort().join(".*\\.")+"(\\.|$)");if(G[O]){if(J){delete G[O][J.guid]}else{for(var P in G[O]){if(N.test(G[O][P].type)){delete G[O][P]}}}if(o.event.specialAll[O]){o.event.specialAll[O].teardown.call(K,Q)}for(F in G[O]){break}if(!F){if(!o.event.special[O]||o.event.special[O].teardown.call(K,Q)===false){if(K.removeEventListener){K.removeEventListener(O,o.data(K,"handle"),false)}else{if(K.detachEvent){K.detachEvent("on"+O,o.data(K,"handle"))}}}F=null;delete G[O]}}})}for(F in G){break}if(!F){var L=o.data(K,"handle");if(L){L.elem=null}o.removeData(K,"events");o.removeData(K,"handle")}}},trigger:function(I,K,H,E){var G=I.type||I;if(!E){I=typeof I==="object"?I[h]?I:o.extend(o.Event(G),I):o.Event(G);if(G.indexOf("!")>=0){I.type=G=G.slice(0,-1);I.exclusive=true}if(!H){I.stopPropagation();if(this.global[G]){o.each(o.cache,function(){if(this.events&&this.events[G]){o.event.trigger(I,K,this.handle.elem)}})}}if(!H||H.nodeType==3||H.nodeType==8){return g}I.result=g;I.target=H;K=o.makeArray(K);K.unshift(I)}I.currentTarget=H;var J=o.data(H,"handle");if(J){J.apply(H,K)}if((!H[G]||(o.nodeName(H,"a")&&G=="click"))&&H["on"+G]&&H["on"+G].apply(H,K)===false){I.result=false}if(!E&&H[G]&&!I.isDefaultPrevented()&&!(o.nodeName(H,"a")&&G=="click")){this.triggered=true;try{H[G]()}catch(L){}}this.triggered=false;if(!I.isPropagationStopped()){var F=H.parentNode||H.ownerDocument;if(F){o.event.trigger(I,K,F,true)}}},handle:function(K){var J,E;K=arguments[0]=o.event.fix(K||l.event);K.currentTarget=this;var L=K.type.split(".");K.type=L.shift();J=!L.length&&!K.exclusive;var I=RegExp("(^|\\.)"+L.slice().sort().join(".*\\.")+"(\\.|$)");E=(o.data(this,"events")||{})[K.type];for(var G in E){var H=E[G];if(J||I.test(H.type)){K.handler=H;K.data=H.data;var F=H.apply(this,arguments);if(F!==g){K.result=F;if(F===false){K.preventDefault();K.stopPropagation()}}if(K.isImmediatePropagationStopped()){break}}}},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(H){if(H[h]){return H}var F=H;H=o.Event(F);for(var G=this.props.length,J;G;){J=this.props[--G];H[J]=F[J]}if(!H.target){H.target=H.srcElement||document}if(H.target.nodeType==3){H.target=H.target.parentNode}if(!H.relatedTarget&&H.fromElement){H.relatedTarget=H.fromElement==H.target?H.toElement:H.fromElement}if(H.pageX==null&&H.clientX!=null){var I=document.documentElement,E=document.body;H.pageX=H.clientX+(I&&I.scrollLeft||E&&E.scrollLeft||0)-(I.clientLeft||0);H.pageY=H.clientY+(I&&I.scrollTop||E&&E.scrollTop||0)-(I.clientTop||0)}if(!H.which&&((H.charCode||H.charCode===0)?H.charCode:H.keyCode)){H.which=H.charCode||H.keyCode}if(!H.metaKey&&H.ctrlKey){H.metaKey=H.ctrlKey}if(!H.which&&H.button){H.which=(H.button&1?1:(H.button&2?3:(H.button&4?2:0)))}return H},proxy:function(F,E){E=E||function(){return F.apply(this,arguments)};E.guid=F.guid=F.guid||E.guid||this.guid++;return E},special:{ready:{setup:B,teardown:function(){}}},specialAll:{live:{setup:function(E,F){o.event.add(this,F[0],c)},teardown:function(G){if(G.length){var E=0,F=RegExp("(^|\\.)"+G[0]+"(\\.|$)");o.each((o.data(this,"events").live||{}),function(){if(F.test(this.type)){E++}});if(E<1){o.event.remove(this,G[0],c)}}}}}};o.Event=function(E){if(!this.preventDefault){return new o.Event(E)}if(E&&E.type){this.originalEvent=E;this.type=E.type}else{this.type=E}this.timeStamp=e();this[h]=true};function k(){return false}function u(){return true}o.Event.prototype={preventDefault:function(){this.isDefaultPrevented=u;var E=this.originalEvent;if(!E){return}if(E.preventDefault){E.preventDefault()}E.returnValue=false},stopPropagation:function(){this.isPropagationStopped=u;var E=this.originalEvent;if(!E){return}if(E.stopPropagation){E.stopPropagation()}E.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=u;this.stopPropagation()},isDefaultPrevented:k,isPropagationStopped:k,isImmediatePropagationStopped:k};var a=function(F){var E=F.relatedTarget;while(E&&E!=this){try{E=E.parentNode}catch(G){E=this}}if(E!=this){F.type=F.data;o.event.handle.apply(this,arguments)}};o.each({mouseover:"mouseenter",mouseout:"mouseleave"},function(F,E){o.event.special[E]={setup:function(){o.event.add(this,F,a,E)},teardown:function(){o.event.remove(this,F,a)}}});o.fn.extend({bind:function(F,G,E){return F=="unload"?this.one(F,G,E):this.each(function(){o.event.add(this,F,E||G,E&&G)})},one:function(G,H,F){var E=o.event.proxy(F||H,function(I){o(this).unbind(I,E);return(F||H).apply(this,arguments)});return this.each(function(){o.event.add(this,G,E,F&&H)})},unbind:function(F,E){return this.each(function(){o.event.remove(this,F,E)})},trigger:function(E,F){return this.each(function(){o.event.trigger(E,F,this)})},triggerHandler:function(E,G){if(this[0]){var F=o.Event(E);F.preventDefault();F.stopPropagation();o.event.trigger(F,G,this[0]);return F.result}},toggle:function(G){var E=arguments,F=1;while(Fa';var H=K.getElementsByTagName("*"),E=K.getElementsByTagName("a")[0];if(!H||!H.length||!E){return}o.support={leadingWhitespace:K.firstChild.nodeType==3,tbody:!K.getElementsByTagName("tbody").length,objectAll:!!K.getElementsByTagName("object")[0].getElementsByTagName("*").length,htmlSerialize:!!K.getElementsByTagName("link").length,style:/red/.test(E.getAttribute("style")),hrefNormalized:E.getAttribute("href")==="/a",opacity:E.style.opacity==="0.5",cssFloat:!!E.style.cssFloat,scriptEval:false,noCloneEvent:true,boxModel:null};G.type="text/javascript";try{G.appendChild(document.createTextNode("window."+J+"=1;"))}catch(I){}F.insertBefore(G,F.firstChild);if(l[J]){o.support.scriptEval=true;delete l[J]}F.removeChild(G);if(K.attachEvent&&K.fireEvent){K.attachEvent("onclick",function(){o.support.noCloneEvent=false;K.detachEvent("onclick",arguments.callee)});K.cloneNode(true).fireEvent("onclick")}o(function(){var L=document.createElement("div");L.style.width=L.style.paddingLeft="1px";document.body.appendChild(L);o.boxModel=o.support.boxModel=L.offsetWidth===2;document.body.removeChild(L).style.display="none"})})();var w=o.support.cssFloat?"cssFloat":"styleFloat";o.props={"for":"htmlFor","class":"className","float":w,cssFloat:w,styleFloat:w,readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",tabindex:"tabIndex"};o.fn.extend({_load:o.fn.load,load:function(G,J,K){if(typeof G!=="string"){return this._load(G)}var I=G.indexOf(" ");if(I>=0){var E=G.slice(I,G.length);G=G.slice(0,I)}var H="GET";if(J){if(o.isFunction(J)){K=J;J=null}else{if(typeof J==="object"){J=o.param(J);H="POST"}}}var F=this;o.ajax({url:G,type:H,dataType:"html",data:J,complete:function(M,L){if(L=="success"||L=="notmodified"){F.html(E?o("").append(M.responseText.replace(/