diff --git a/deployed/mightysites/administrator/components/com_mightysites/access.xml b/deployed/mightysites/administrator/components/com_mightysites/access.xml
new file mode 100644
index 00000000..7a0de162
--- /dev/null
+++ b/deployed/mightysites/administrator/components/com_mightysites/access.xml
@@ -0,0 +1,11 @@
+
+
', JText::sprintf('COM_MIGHTYSITES_VISIT_DADDY', 'http://alterbrains.com.');
+ }
+ }
+ jexit();
+ }
+
+}
\ No newline at end of file
diff --git a/deployed/mightysites/administrator/components/com_mightysites/controllers/database.php b/deployed/mightysites/administrator/components/com_mightysites/controllers/database.php
new file mode 100644
index 00000000..d23b534a
--- /dev/null
+++ b/deployed/mightysites/administrator/components/com_mightysites/controllers/database.php
@@ -0,0 +1,312 @@
+ false))
+ {
+ $model = parent::getModel($name, $prefix, $config);
+ return $model;
+ }
+
+ public function create()
+ {
+ // Access check.
+ if (!JFactory::getUser()->authorise('core.create', 'com_mightysites')) {
+ return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
+ }
+
+ $app = JFactory::getApplication();
+ $db = JFactory::getDBO();
+
+ // Check for request forgeries
+ JSession::checkToken() or jexit('Invalid Token');
+
+ // Get vars
+ $dbname = $app->input->getString('db');
+
+ if (!$db->connected()) {
+ echo '', JText::_('COM_MIGHTYSITES_ERROR_INVALID_USER'), '';
+ }
+ else {
+ $db->setQuery('CREATE DATABASE `'.$dbname.'` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
+
+ try {
+ $db->execute();
+ }
+ catch (RuntimeException $e) {
+ echo '', JText::sprintf('COM_MIGHTYSITES_ERROR_CUSTOM', $db->getErrorMsg()), '';
+ exit();
+ }
+
+ echo '', JText::sprintf('COM_MIGHTYSITES_DATABASE_CREATED', $dbname), '';
+ }
+
+ JFactory::getApplication()->close();
+ }
+
+ public function check()
+ {
+ $app = JFactory::getApplication();
+
+ // Check for request forgeries
+ JSession::checkToken() or jexit('Invalid Token');
+
+ // Get vars
+ $db = $app->input->getString('db');
+ $dbprefix = $app->input->getString('dbprefix');
+ $user = $app->input->getString('user');
+ $password = $app->input->getString('password');
+ $id = $app->input->getInt('id');
+ $type = $app->input->getInt('type');
+
+ // Use current?
+ if (empty($user)) {
+ $user = $app->getCfg('user');
+ $password = $app->getCfg('password');
+ }
+
+ // Close current connection, otherwise no mysql_connect() errors
+ JFactory::getDBO()->__destruct();
+
+ // Check connection
+ $link = @mysql_connect($app->getCfg('host'), $user, $password);
+ if ($link === false) {
+ echo '', JText::_('COM_MIGHTYSITES_ERROR_INVALID_USER'), '';
+ } else {
+ if (!mysql_select_db($db, $link)) {
+ echo '', JText::sprintf('COM_MIGHTYSITES_ERROR_CUSTOM', mysql_error($link)), '';
+ } else {
+ if ($type == 1) {
+ if ($id) {
+ echo '', JText::_('COM_MIGHTYSITES_CONNECTED'), '';
+ } else {
+ if (mysql_query('SELECT COUNT(*) FROM '.$dbprefix.'users', $link)) {
+ echo '', JText::sprintf('COM_MIGHTYSITES_ERROR_TABLES_EXIST', $dbprefix, $db), '';
+ } else {
+ echo '', JText::_('COM_MIGHTYSITES_CONNECTED'), '';
+ }
+ }
+ }
+ if ($type == 2) {
+ if (!mysql_query('SELECT COUNT(*) FROM '.$dbprefix.'users', $link)) {
+ echo '', JText::sprintf('COM_MIGHTYSITES_ERROR_NO_TABLES_EXIST', $dbprefix, $db), '';
+ } else {
+ echo '', JText::_('COM_MIGHTYSITES_CONNECTED'), '';
+ }
+ }
+ mysql_close($link);
+ }
+ }
+
+ // Fix Joomla db
+ $this->restoreDB();
+
+ // Fix ugly mysqli notice
+ error_reporting(0);
+
+ JFactory::getApplication()->close();
+ }
+
+ public function copy()
+ {
+ $app = JFactory::getApplication();
+
+ // Access check.
+ if (!JFactory::getUser()->authorise('core.create', 'com_mightysites')) {
+ return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
+ }
+
+ $from = $app->input->get('from');
+ $to = $app->input->get('to');
+ $table = $app->input->getInt('table', 0);
+ $tmpl = $app->input->get('tmpl');
+
+ // Get source site
+ $from = MightysitesHelper::getSite($from, true);
+ if (!isset($from->id)) {
+ JError::raiseError(500, JText::_('COM_MIGHTYSITES_INVALID_SOURCE'));
+ }
+
+ // Get destination site
+ $to = MightysitesHelper::getSite($to, true);
+
+ // Check
+ if (($from->db == $to->db) && ($from->dbprefix == $to->dbprefix)) {
+ $this->setRedirect('index.php?option=com_mightysites', JText::_('COM_MIGHTYSITES_SOURCE_DEST_EQUAL'));
+ }
+
+ // Get Dbo
+ $db = MightysitesHelper::getDBO($from);
+
+ // Get tables & views list from site.
+ $tables = MightysitesHelper::getTables($db);
+ $views = MightysitesHelper::getViews($db);
+
+ // Main array, tables are copied first because they are used in views.
+ $tables_views = array_merge($tables, $views);
+
+ // Filter tables without source prefix
+ if (sizeof($tables_views)) {
+ foreach($tables_views as $key => $value) {
+ if (strpos($value, $from->dbprefix) !== 0) {
+ unset($tables_views[$key]);
+ }
+ // Filter dest tables if we use same db
+ if ($from->db == $to->db && strpos($value, $to->dbprefix) === 0) {
+ unset($tables_views[$key]);
+ }
+ }
+ // Rebuild keys
+ $tables_views = explode(',,,', implode(',,,', $tables_views));
+ }
+
+ // Remember views code.
+ $views_code = array();
+ foreach($tables_views as $tables_view) {
+ if (in_array($tables_view, $views)) {
+ $db->setQuery('SHOW CREATE VIEW `'.$tables_view.'`');
+ $vres = $db->loadAssoc();
+ if (isset($vres['Create View'])) {
+ $views_code[$tables_view] = $vres['Create View'];
+ }
+ }
+ }
+
+ // Check tables
+ if (!sizeof($tables_views)) {
+ JError::raiseError(500, JText::sprintf('COM_MIGHTYSITES_NO_TABLES', $from->domain, $from->db));
+ }
+
+ // source
+ $source_table = $tables_views[$table];
+
+ // destination
+ $dest_table = $to->dbprefix . substr($source_table, strlen($from->dbprefix));
+
+ // Table or View?
+ $isTable = in_array($source_table, $tables);
+ $isView = in_array($source_table, $views);
+
+ // Connect to dest DB
+ $db2 = MightysitesHelper::getDBO($to);
+
+ JToolBarHelper::title('MightySites : ' . JText::_('COM_MIGHTYSITES_COPYING_TABLES'), 'config');
+
+ echo '
'.$db2->getErrorMsg().'
'; + $error = true; + } + else { + + // Next copy data table + if ($isTable) { + $query = 'INSERT INTO `'.$dest_table.'` SELECT * FROM `'.$from->db.'`.`'.$source_table.'`'; + $db2->setQuery($query); + + if (JDEBUG) { + echo $db2->getQuery().'', JText::sprintf('COM_MIGHTYSITES_CANT_WRITE_FILE', $fname), '
'; + die; + } + + $link = 'http://'.$domain.'/administrator/index.php?mighty_token='.$token; + + $this->setRedirect($link); + } + +} diff --git a/deployed/mightysites/administrator/components/com_mightysites/controllers/sites.php b/deployed/mightysites/administrator/components/com_mightysites/controllers/sites.php new file mode 100644 index 00000000..d16492c5 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/controllers/sites.php @@ -0,0 +1,209 @@ + true)) + { + $model = parent::getModel($name, $prefix, $config); + return $model; + } + + public function remove() + { + // Access check. + if (!JFactory::getUser()->authorise('core.delete', 'com_mightysites')) { + return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); + } + + $app = JFactory::getApplication(); + + $ids = $app->input->get('cid', array(), 'array'); + $n = count($ids); + JArrayHelper::toInteger($ids); + + $delete_tables = $app->input->get('delete_tables'); + + if ($n) { + $n = 0; + foreach($ids as $id) { + $site = MightysitesHelper::getSite($id, true); + + $config_domain = MightysitesHelper::prepareDomain($site->domain); + if ($config_domain) { + // don't delete ourself :) + if ($site->id == 1 && MightysitesHelper::prepareDomain() == $config_domain) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_NOT_DELETE_CURRENT', $site->domain), 'notice'); + } else { + if ($site->type == 1) { + // Delete Tables & Views + if ($delete_tables == 'true') { + $db2 = MightysitesHelper::getDBO($site); + + $tables = MightysitesHelper::getTables($db2); + if (sizeof($tables)) { + foreach($tables as $table) { + if (strpos($table, $site->dbprefix) === 0) { + $db2->setQuery('DROP TABLE `'.$table.'`'); + $db2->execute() or $app->enqueueMessage($db2->getErrorMsg(), 'error'); + } + } + } + + $views = MightysitesHelper::getViews($db2); + if (sizeof($views)) { + foreach($views as $view) { + if (strpos($view, $site->dbprefix) === 0) { + $db2->setQuery('DROP VIEW `'.$view.'`'); + $db2->execute() or $app->enqueueMessage($db2->getErrorMsg(), 'error'); + } + } + } + + // restore current $db + $db = JFactory::getDBO(); + $db = null; + } + + // Delete config + $fname = MightySitesHelper::getConfigFilename($config_domain); + if (!JFile::delete($fname)) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_CANT_DELETE_CONFIG', $fname), 'error'); + } + + // Delete symlink + if (strpos($site->domain, '/') !== false) { + $parts = explode('/', $site->domain); + array_shift($parts); + + $path = implode('/', $parts); + $file = JPATH_SITE.'/'.$path; + + if (file_exists($file) && is_link($file)) { + if (!unlink($file)) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_ERROR_SYMLINK_DELETE', $file), 'error'); + } + } + } + } + + // Delete in database + $db = JFactory::getDBO(); + $query = 'DELETE FROM #__mightysites WHERE id = ' . $id; + $db->setQuery($query); + if (!$db->execute()) { + JError::raiseWarning( 500, $row->getError()); + } + $n++; + } + } + } + } + + $mes = $n ? JText::_('COM_MIGHTYSITES_DOMAINS_DELETED') : null; + $this->setRedirect('index.php?option=com_mightysites&view=sites', $mes); + } + + public function publish() + { + // Access check. + if (!JFactory::getUser()->authorise('core.edit.state', 'com_mightysites')) { + return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); + } + + jimport('joomla.filesystem.path'); + jimport('joomla.filesystem.file'); + + $app = JFactory::getApplication(); + + $db = JFactory::getDBO(); + $user = JFactory::getUser(); + $ids = $app->input->get('cid', array(), 'array'); + $task = $app->input->get('task'); + $publish = ($task == 'publish'); + $n = count($ids); + + if (empty($ids)) { + return JError::raiseWarning( 500, JText::_('COM_MIGHTYSITES_NO_ITEMS')); + } + + JArrayHelper::toInteger($ids); + + if (sizeof($ids)) { + foreach($ids as $id) { + $config_site = MightysitesHelper::getSite($id); + + if ($config_site->type == 1 && isset($config_site->domain)) { + $file = MightysitesHelper::getConfigFilename($config_site->domain); + if (!file_exists($file)) { + $app->redirect('index.php?option=com_mightysites', JText::sprintf('COM_MIGHTYSITES_FILE_DOESNT_EXIST', $file), 'error'); + } + if (!is_readable($file)) { + $app->redirect('index.php?option=com_mightysites', JText::sprintf('COM_MIGHTYSITES_FILE_NOT_READABLE', $file), 'error'); + } + + $config = JFile::read($file); + + if ($publish) { + $config = preg_replace('#public \$offline = \'1\';#u', 'public $offline = \'0\';', $config); + } else { + $config = preg_replace('#public \$offline = \'0\';#u', 'public $offline = \'1\';', $config); + } + + $ftp = JClientHelper::getCredentials('ftp'); + + // Attempt to make the file writeable if using FTP. + if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) + { + JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE')); + } + + if (!is_writable(JPATH_CONFIGURATION)) { + $app->redirect('index.php?option=com_mightysites', JText::sprintf('COM_MIGHTYSITES_FILE_NOT_WRITABLE', $file), 'error'); + } + + if (!JFile::write($file, $config)) { + $app->redirect('index.php?option=com_mightysites', JText::sprintf('COM_MIGHTYSITES_CANT_WRITE_FILE', $file), 'error'); + } + + // Attempt to make the file unwriteable if using FTP. + if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) + { + JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE')); + } + + $mes = $publish ? 'COM_MIGHTYSITES_SITE_PUBLISHED' : 'COM_MIGHTYSITES_SITE_UNPUBLISHED'; + $app->enqueueMessage(JText::sprintf($mes, $config_site->domain)); + } + } + } + + $this->setRedirect('index.php?option=com_mightysites&view=sites'); + } + + public function cancel() + { + $this->setRedirect('index.php?option=com_mightysites&view=sites'); + + // Initialize variables + $db = JFactory::getDBO(); + $post = JRequest::get('post'); + $row = JTable::getInstance('Site', 'Mightysites'); + $row->bind($post); + $row->checkin(); + } + +} \ No newline at end of file diff --git a/deployed/mightysites/administrator/components/com_mightysites/helpers/helper.php b/deployed/mightysites/administrator/components/com_mightysites/helpers/helper.php new file mode 100644 index 00000000..8385a643 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/helpers/helper.php @@ -0,0 +1,629 @@ +triggerEvent('onMightysitesGetSynchs', array(&$custom)); + + // Sort by name + $custom2 = array(); + foreach($custom as $key) { + $custom2[$key] = JText::_('COM_MIGHTYSITES_SYNCH_LABEL_'.$key); + } + natcasesort($custom2); + $custom = array_keys($custom2); + + $core = array( + 'extensions', + 'permissions', + 'users', + + // Users don't understand how it works, better skip + // 'sessions', + + 'templates', + 'categories', + 'content', + 'languages', + 'menus', + 'modules', + 'newsfeeds', + 'weblinks', + 'banners', + 'contacts', + 'messages', + 'smartsearch', + 'tags', + 'tags_refs', + 'redirect', + ); + asort($core); + + switch($type) { + case 'custom': + return $custom; + break; + + case 'core': + return $core; + break; + + default: + return array_merge($core, $custom); + break; + } + } + + // In fact returns all Sites & Databases + public static function getSites($key = 'domain') + { + static $sites; + + if (!isset($sites[$key])) + { + $db = JFactory::getDBO(); + + $db->setQuery('SELECT * FROM #__mightysites ORDER BY `domain`'); + + $sites[$key] = $db->loadObjectList($key); + + foreach($sites[$key] as &$site) { + // Prepare domain cmd + $site->domain_cmd = preg_replace('#([^A-Z0-9])#i', '_', $site->domain); + // Params + $site->params = new JRegistry($site->params); + } + } + + return $sites[$key]; + } + + // In fact returns a Site or Database + public static function getSite($id, $attach_config = false) + { + $sites = self::getSites(); + + // By domain + if (isset($sites[$id])) { + return $attach_config ? self::attachConfig($sites[$id]) : $sites[$id]; + } + + // By id or parsed domain + foreach($sites as $site) { + if ($id == $site->id || $id == $site->domain_cmd) { + return $attach_config ? self::attachConfig($site) : $site; + } + } + + return false; + } + + public static function getCurrentSite($attach_config = false) + { + $site = self::getSite(defined('MIGHTY_DOMAIN') ? MIGHTY_DOMAIN : self::getHost(), $attach_config); + + return $site; + } + + public static function sitesList($name, $value = null, $script = null, $skip = null, $first = null, $type = false, $first_value = '', $second = null, $second_value = null) + { + $options = array(); + + if ($first) { + $options[] = JHTML::_('select.option', $first_value, $first, 'value', 'text'); + } + + if ($second) { + $options[] = JHTML::_('select.option', $second_value, $second, 'value', 'text'); + } + + $sites = self::getSites(); + + foreach ($sites as $site) { + if (empty($skip) || ($skip != $site->domain)) { + if ($type && $site->type != $type) {} + else { + $options[] = JHTML::_('select.option', $site->id, $site->domain, 'value', 'text'); + } + } + } + + return JHTML::_('select.genericlist', $options, $name, 'class="inputbox" '.$script, 'value', 'text', $value); + } + + public static function getDatabases($key = 'id') + { + static $databases; + + if (!isset($databases[$key])) { + $db = JFactory::getDBO(); + $db->setQuery('SELECT * FROM #__mightysites ORDER BY `domain`'); + $databases[$key] = $db->loadObjectList($key); + } + + return $databases[$key]; + } + + + public static function databasesList($name, $value = null, $script = null, $skip = array('information_schema')) + { + $options = array(); + $options[] = JHTML::_('select.option', '', JText::_('COM_MIGHTYSITES_SELECT_DATABASE'), 'value', 'text'); + + $db = JFactory::getDBO(); + $db->setQuery('SHOW DATABASES'); + $rows = $db->loadColumn(); + + if (sizeof($rows)) { + foreach($rows as $row) { + if (!in_array($row, $skip)) { + $options[] = JHTML::_('select.option', $row, $row, 'value', 'text'); + } + } + } + return JHTML::_('select.genericlist', $options, $name, 'class="inputbox" '.$script, 'value', 'text', $value); + } + + public static function menuitemsList($name, $value, $script = null) + { + $types = array('default' => array(JHTML::_('select.option', '', JText::_('COM_MIGHTYSITES_DEFAULT_MENUITEM'), 'value', 'text'))); + + $db = JFactory::getDBO(); + $query = 'SELECT id, menutype, title, level FROM #__menu WHERE client_id=0 AND id > 1 AND published=1 ORDER BY lft'; + $db->setQuery($query); + + foreach($db->loadObjectList() as $item) { + if (!isset($types[$item->menutype])) { + $types[$item->menutype] = array(); + } + $types[$item->menutype][] = JHTML::_('select.option', $item->id, str_repeat(' - ', $item->level-1).$item->title, 'value', 'text'); + } + + return JHTML::_('select.groupedlist', $types, $name, array( + 'list.attr' => 'class="inputbox" '.$script, + 'id' => $name, + 'list.select' => $value, + 'group.items' => null, + 'option.key.toHtml' => false, + 'option.text.toHtml' => false + )); + } + + public static function prepareDomain($domain = null) + { + if (!$domain) { + $domain = self::getHost(); + } + + if (substr($domain, 0, 4) == 'www.') { + $domain = substr($domain, 4); + } + + // Use Punycode! + + // Joomla 3.3 + if (class_exists('JStringPunycode')) { + $domain = JStringPunycode::toPunycode($domain); + } + // Joomla 2.5 + else { + require_once(JPATH_SITE.'/libraries/simplepie/idn/idna_convert.class.php'); + $idn = new idna_convert; + $domain = $idn->encode($domain); + } + + // Normalize filename. + $domain = preg_replace('#([^A-Za-z0-9])#i', '_', $domain); + + return $domain; + } + + public static function getConfigFilename($domain = null, $force_root = false) + { + // current config + if (!$domain) { + if (defined('MIGHTY_CONFIG')) { + return MIGHTY_CONFIG; + } + + $domain = self::getHost(); + } + + $fname = JPATH_SITE.'/configuration_'.self::prepareDomain($domain).'.php'; + + if (!file_exists($fname) && !$force_root) { + $fname = JPATH_SITE.'/components/com_mightysites/configuration/configuration_'.self::prepareDomain($domain).'.php'; + } + + return $fname; + } + + public static function attachConfig(&$row, $config = null) + { + $app = JFactory::getApplication(); + + if ($row->type == 1) { + // Load as file into string. + if (!$config) { + $fname = self::getConfigFilename($row->domain); + if (file_exists($fname)) { + $config = JFile::read($fname); + } else { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_NO_CONFIG', $fname, $row->domain), 'error'); + return $row; + } + } + + // Parse into object. + if (is_string($config)) { + $classname = 'JConfig'.$row->id; + + if (!class_exists($classname)) { + $config = strtr($config, array( + ' "\n", + ' "\r\n", + ' "\r", + 'class JConfig' => 'class '.$classname, + )); + eval($config); + } + + if (class_exists($classname)) { + $config = new $classname; + } + } + + // Parse object + if (is_object($config)) { + foreach((array)$config as $key => $value) { + $row->$key = $value; + } + $row->published = !@$row->offline; + } + } + + return $row; + } + + /* + public static function getToken() + { + $params = JComponentHelper::getParams('com_mightysites'); + return $params->get('support_token'); + } + */ + + public static function patchConfiguration() + { + // Update Joomla config. + $file = JPATH_SITE.'/configuration.php'; + $str = 'load('com_mightysites'); + + // Get the new FTP credentials. + $ftp = JClientHelper::getCredentials('ftp', true); + + // Attempt to make the file writeable if using FTP. + if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_ERROR_CONFIG_PATCH_FAILED', $file), 'error'); + return false; + } + + if (JFile::write($file, $str)) { + // Attempt to make the file unwriteable if using FTP. + if (JFactory::getConfig()->get('ftp_enable') == 0 && !$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_ERROR_CONFIG_PATCH_FAILED', $file), 'error'); + return false; + } + } + else { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_ERROR_CONFIG_PATCH_FAILED', $file), 'error'); + return false; + } + } + + // Update/create default config. + $default_file = JPATH_SITE.'/components/com_mightysites/configuration/default.php'; + + // Reload master domain from DB, it can be cached in our data. + $db = JFactory::getDbo(); + + $query = 'SELECT domain FROM `#__mightysites` WHERE id=1'; + $db->setQuery($query, 0, 1); + $master_domain = $db->loadResult(); + + if (!file_exists($default_file) + || + (strpos(file_get_contents($default_file), self::getConfigFilename($master_domain)) === false) + ) + { + + $default_str = 'enqueueMessage(JText::sprintf('COM_MIGHTYSITES_CANT_WRITE_FILE', $default_file), 'error'); + } + } + + return true; + } + + public static function &getDBO(&$site, $force_select = false) + { + if (!isset(self::$dbo[$site->id])) { + $conf = JFactory::getConfig(); + $options = array( + 'driver' => isset($site->dbtype) ? $site->dbtype : $conf->get('dbtype'), // can be absent if Database + 'host' => isset($site->host) ? $site->host : $conf->get('host'), // can be absent if Database + 'user' => isset($site->user) ? $site->user : $conf->get('user'), // can be absent if Database + 'password' => isset($site->password) ? $site->password : $conf->get('password'), // can be absent if Database + 'database' => $site->db, + 'prefix' => $site->dbprefix, + 'dummy' => md5(uniqid(mt_rand(), true)) // always get new instance, otherwise it can return db + ); + + // old legacy + // todo - remove in Joomla 3.0 + if ($options['driver'] == 'mightysites') { + $options['driver'] = 'mysql'; + } + + self::$dbo[$site->id] = JDatabase::getInstance($options); + + $version = new JVersion; + if ($version->RELEASE != '2.5') { + if (self::$dbo[$site->id]) { + self::$dbo[$site->id]->connect(); + } + } + + if (!self::$dbo[$site->id] || !self::$dbo[$site->id]->connected()) { + JError::raiseError(500, JText::sprintf('COM_MIGHTYSITES_CANT_CONNECT_DB', $options['database'], $options['user'], @self::$dbo[$site->id]->getErrorMsg())); + } + } + + if ($force_select) { + self::$dbo[$site->id]->select($site->db); + } + + return self::$dbo[$site->id]; + } + + public static function getTables(&$db) + { + $db->setQuery('SHOW FULL TABLES WHERE Table_Type = "BASE TABLE"'); + return $db->loadColumn(); + } + + public static function getViews(&$db) + { + $db->setQuery('SHOW FULL TABLES WHERE Table_Type = "VIEW"'); + return $db->loadColumn(); + } + + public static function topmenu() + { + $app = JFactory::getApplication(); + + $view = $app->input->get('view', 'sites'); + + $version = new JVersion; + if ($version->RELEASE == '2.5') { + $classname = 'JSubMenuHelper'; + } else { + $classname = 'JHtmlSidebar'; + } + + $classname::addEntry(JText::_('COM_MIGHTYSITES_SUBMENU_SITES'), 'index.php?option=com_mightysites&view=sites', $view == 'sites'); + $classname::addEntry(JText::_('COM_MIGHTYSITES_SUBMENU_DATABASES'), 'index.php?option=com_mightysites&view=databases', $view == 'databases'); + $classname::addEntry(JText::_('COM_MIGHTYSITES_SUBMENU_ABOUT'), 'index.php?option=com_mightysites&view=about', $view == 'about'); + + // check plugins + $db = JFactory::getDBO(); + $query = 'SELECT * FROM #__extensions WHERE `element`="mightysites" AND type="plugin"'; + $db->setQuery($query, 0, 1); + $plg_sys = $db->loadObject(); + + if (!$plg_sys) { + $app->enqueueMessage(JText::_('COM_MIGHTYSITES_PLUGIN_INSTALL_ERROR'), 'notice'); + } + else if (!$plg_sys->enabled) { + $app->enqueueMessage(JText::sprintf('COM_MIGHTYSITES_PLUGIN_UNPUBLISHED', 'System - MightySites'), 'notice'); + } + + // Auto correct ordering: move to first place + if ($plg_sys && $plg_sys->ordering != -99999) { + $query = 'UPDATE #__extensions SET ordering = -99999 WHERE `element`="mightysites" AND type="plugin"'; + $db->setQuery($query); + $db->query(); + + // Clear cache + $conf = JFactory::getConfig(); + $cache = JCache::getInstance('', array( + 'defaultgroup' => '', + 'storage' => $conf->get('cache_handler', ''), + 'caching' => true, + 'cachebase' => $conf->get('cache_path', JPATH_SITE . '/cache') + )); + $cache->clean('com_plugins'); + } + } + +} diff --git a/deployed/mightysites/administrator/components/com_mightysites/helpers/index.html b/deployed/mightysites/administrator/components/com_mightysites/helpers/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/helpers/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/deployed/mightysites/administrator/components/com_mightysites/images/icon_16.png b/deployed/mightysites/administrator/components/com_mightysites/images/icon_16.png new file mode 100644 index 00000000..16faccad Binary files /dev/null and b/deployed/mightysites/administrator/components/com_mightysites/images/icon_16.png differ diff --git a/deployed/mightysites/administrator/components/com_mightysites/images/index.html b/deployed/mightysites/administrator/components/com_mightysites/images/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/images/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/deployed/mightysites/administrator/components/com_mightysites/images/mightysites.png b/deployed/mightysites/administrator/components/com_mightysites/images/mightysites.png new file mode 100644 index 00000000..7641ceaa Binary files /dev/null and b/deployed/mightysites/administrator/components/com_mightysites/images/mightysites.png differ diff --git a/deployed/mightysites/administrator/components/com_mightysites/index.html b/deployed/mightysites/administrator/components/com_mightysites/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/deployed/mightysites/administrator/components/com_mightysites/mightysites.php b/deployed/mightysites/administrator/components/com_mightysites/mightysites.php new file mode 100644 index 00000000..fe8fe9da --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/mightysites.php @@ -0,0 +1,35 @@ +authorise('core.manage', 'com_mightysites')) { + return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); +} + +// Set the table directory +JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_mightysites/tables'); + +// Load Helper +require_once(JPATH_ADMINISTRATOR.'/components/com_mightysites/helpers/helper.php'); + +// Load Plugins +JPluginHelper::importPlugin('mightysites'); + +// Only Daddy rocks! +$host_site = MightysitesHelper::getCurrentSite(); +if (!isset($host_site->id) || $host_site->id != 1) { + JFactory::getApplication()->redirect('index.php', JText::sprintf('COM_MIGHTYSITES_INVALID_HOST', MightysitesHelper::getSite(1)->domain), 'error'); +} + +$controller = JControllerLegacy::getInstance('Mightysites'); +$controller->execute(JFactory::getApplication()->input->get('task')); +$controller->redirect(); diff --git a/deployed/mightysites/administrator/components/com_mightysites/mightysites.script.php b/deployed/mightysites/administrator/components/com_mightysites/mightysites.script.php new file mode 100644 index 00000000..c52ae1f2 --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/mightysites.script.php @@ -0,0 +1,139 @@ +enqueueMessage('MightySites requires PHP 5.3+, please ask your hosting provider to update PHP.', 'error'); + return; + } + + require_once(JPATH_ADMINISTRATOR.'/components/com_mightysites/helpers/helper.php'); + + // Load our language + JFactory::getLanguage()->load('com_mightysites'); + + // Create current site + $domain = MightysitesHelper::getHost(); + + $query = 'INSERT IGNORE INTO `#__mightysites` (`id`, `type`, `domain`) VALUES(1, 1, '.$db->quote($domain).')'; + $db->setQuery($query); + $db->execute(); + + // Create new config + $fname = MightysitesHelper::getConfigFilename(); + + if (!file_exists($fname)) + { + $config = JFile::read(JPATH_CONFIGURATION.'/configuration.php'); + + if ($config) + { + if (JFile::write($fname, $config)) + { + // Try to make configuration.php unwriteable + $ftp = JClientHelper::getCredentials('ftp'); + jimport('joomla.filesystem.path'); + if (!$ftp['enabled'] && JPath::isOwner($fname) && !JPath::setPermissions($fname, '0644')) { + //JError::raiseNotice('SOME_ERROR_CODE', 'Could not make configuration.php writable'); + } + } + else + { + return; + } + } + } + + // Patch configuration.php! + MightysitesHelper::patchConfiguration(); + + // delete old admin file before 2.1.0 + $old = JPATH_SITE.'/administrator/components/com_mightysites/admin.mightysites.php'; + if (file_exists($old)) + { + jimport('joomla.filesystem.path'); + JFile::delete($old); + } + + // Get columns + $query = 'SELECT * FROM `#__mightysites`'; + $db->setQuery($query, 0, 1); + $columns = $db->loadObject(); + + // New in 3.2.3 + if (!property_exists($columns, 'aliases')) { + $query = 'ALTER TABLE `#__mightysites` ADD `aliases` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `domain`'; + $db->setQuery($query); + $db->execute(); + } + + // Move old config files to new location - since 3.2.5 + foreach(MightysitesHelper::getSites() as $site) + { + $fname = JPATH_SITE.'/configuration_'.MightysitesHelper::prepareDomain($site->domain).'.php'; + $fname2 = JPATH_SITE.'/components/com_mightysites/configuration/configuration_'.MightysitesHelper::prepareDomain($site->domain).'.php'; + + if (file_exists($fname) && is_writable(JPATH_SITE.'/components/com_mightysites/configuration')) + { + JFile::move($fname, $fname2); + } + } + } + + function uninstall($parent) + { + // revert config + $db = JFactory::getDBO(); + + $query = 'SELECT * FROM `#__mightysites` WHERE id=1'; + $db->setQuery($query, 0, 1); + $root = $db->loadObject(); + + require_once(JPATH_ADMINISTRATOR.'/components/com_mightysites/helpers/helper.php'); + + jimport('joomla.filesystem.file'); + + if (isset($root->id)) + { + $error = true; + + $fname = MightysitesHelper::getConfigFilename($root->domain); + + if (file_exists($fname)) + { + $new_config = JFile::read($fname); + $old_config = JFile::read(JPATH_SITE.'/configuration.php'); + + if ($new_config && JString::strpos($old_config, 'class JConfig') === false) + { + /* + if (JString::strpos($config, 'var $mighty =') !== false) { + $config = preg_replace('/var \$mighty \= array ([^\;]*)\;\n/u', '', $config); + } + */ + if (JFile::write(JPATH_SITE.'/configuration.php', $new_config)) + { + $error = false; + } + } + } + + if ($error) + { + JFactory::getApplication()->enqueueMessage('Please re-save Global configuration!', 'error'); + } + } + } +} diff --git a/deployed/mightysites/administrator/components/com_mightysites/mightysites.xml b/deployed/mightysites/administrator/components/com_mightysites/mightysites.xml new file mode 100644 index 00000000..6e479e7a --- /dev/null +++ b/deployed/mightysites/administrator/components/com_mightysites/mightysites.xml @@ -0,0 +1,54 @@ + +