private static function getDevice($ua, $exact = false) { $db = AmddDatabase::getInstance(AmddConfig::$dbHandlerName); self::$matchType = 2; // load matched device $data = $db->getDevice($ua); if ($data !== null) { return $data; } if ($exact) { return null; } // fast test for bots and desktop browsers $group = AmddUA::getGroup($ua); if ($group === 'bot') { return null; } // load device from cache if (AmddConfig::$cacheSize != 0) { self::$matchType = 3; $data = $db->getDeviceFromCache($ua); if ($data !== null) { return empty($data) ? null : $data; } } // find closest device $devices = $db->getDevices($group); if (preg_match('#^(Mozilla|Opera|NetFront)/#', $ua)) { self::$matchType = 5; $data = self::findByLevenshtein($ua, $devices); if ($data === null) { $pos = strpos($ua, ')'); if (!$pos) { $pos = strlen($ua); } self::$matchType = 4; $data = self::findByPrefix($ua, $devices, $pos); } } else { preg_match('#^(DoCoMo|portalmmm)/.*?(\\(|$)#', $ua, $match) or preg_match('#^.{5,}?[ /]#', $ua, $match); $pos = isset($match[0]) ? strlen($match[0]) : strlen($ua); self::$matchType = 4; $data = self::findByPrefix($ua, $devices, $pos); if ($data === null) { self::$matchType = 5; $data = self::findByLevenshtein($ua, $devices); } } // save to cache $db->putDeviceToCache($ua, empty($data) ? '' : $data, AmddConfig::$cacheSize); return $data; }
static function install() { JError::setErrorHandling(E_ERROR, 'Message'); @set_time_limit(1200); @ini_set('max_execution_time', 1200); ignore_user_abort(true); $db = JFactory::getDBO(); $mj_memory_limit = '32M'; $memory_limit = @ini_get('memory_limit'); if ($memory_limit && self::str2int($memory_limit) < self::str2int($mj_memory_limit)) { @ini_set('memory_limit', $mj_memory_limit); } $lang = JFactory::getLanguage(); $lang->load('com_mobilejoomla'); // check for upgrade $upgrade = false; $prev_version = ''; $manifest = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/mobilejoomla.xml'; if (is_file($manifest)) { $xml = simplexml_load_file($manifest); if (isset($xml->version)) { $prev_version = (string) $xml->version; } if ($prev_version) { $upgrade = true; } } $xm_files = JFolder::files(JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages', '\\.xm_$', 2, true); if (!empty($xm_files)) { foreach ($xm_files as $file) { $newfile = str_replace('.xm_', '.xml', $file); JFile::move($file, $newfile); if (self::isJoomla15()) { $content = file_get_contents($newfile); $content = str_replace('<extension ', '<install ', $content); $content = str_replace('</extension>', '</install>', $content); JFile::write($newfile, $content); } } } $addons_installer = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/install.addons.php'; if (JFile::exists($addons_installer)) { include $addons_installer; } //update config & files self::UpdateConfig($prev_version); // install templates if (version_compare(JVERSION, '3.0', '>=')) { $TemplateSource = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates30'; $TemplateSource16 = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates16'; JFolder::move($TemplateSource16 . '/mobile_iphone/jqtouch-src', $TemplateSource . '/mobile_iphone/jqtouch-src'); JFolder::move($TemplateSource16 . '/mobile_smartphone/resources', $TemplateSource . '/mobile_smartphone/resources'); JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates15'); JFolder::delete($TemplateSource16); } elseif (version_compare(JVERSION, '1.6', '>=')) { $TemplateSource = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates16'; JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates15'); JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates30'); } else { $TemplateSource = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates15'; $TemplateSource16 = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates16'; JFolder::move($TemplateSource16 . '/mobile_iphone/jqtouch-src', $TemplateSource . '/mobile_iphone/jqtouch-src'); JFolder::move($TemplateSource16 . '/mobile_smartphone/resources', $TemplateSource . '/mobile_smartphone/resources'); JFolder::delete($TemplateSource16); JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/templates30'); } $templates = array('mobile_smartphone', 'mobile_wap', 'mobile_imode', 'mobile_iphone'); $status = true; foreach ($templates as $template) { if (!self::InstallTemplate($TemplateSource, $template)) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . " Mobile Joomla '{$template}' template."); } } $apple_touch_icon = JPATH_SITE . '/templates/mobile_iphone/apple-touch-icon.png'; if (!JFile::exists($apple_touch_icon)) { JFile::move($TemplateSource . '/mobile_iphone/apple-touch-icon.png', $apple_touch_icon); } if (function_exists('MJAddonInstallTemplates')) { $status = MJAddonInstallTemplates($TemplateSource) && $status; } if ($status) { JFolder::delete($TemplateSource); } //install modules $ModuleSource = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/modules'; $status = true; $status = self::InstallModule($ModuleSource, 'mod_mj_header', 'Header Module', 'mj_smartphone_header', 1, 0) && $status; $status = self::InstallModule($ModuleSource, 'mod_mj_menu', 'Mobile Menu', 'mj_all_header', !$upgrade, 0) && $status; $status = self::InstallModule($ModuleSource, 'mod_mj_markupchooser', 'Select Markup', array('footer', 'mj_all_footer'), 1, 0) && $status; if (version_compare(JVERSION, '2.5', '<')) { $status = self::InstallModule($ModuleSource, 'mod_mj_adminicon', 'MobileJoomla CPanel Icons', 'icon', 1, 0, 1) && $status; } if (function_exists('MJAddonInstallModules')) { $status = MJAddonInstallModules($ModuleSource) && $status; } if ($status) { JFolder::delete($ModuleSource); } else { JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . ' Mobile Joomla modules.'); } //install plugins $PluginSource = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/packages/plugins'; $status = true; if (!self::InstallPlugin('system', $PluginSource, 'mobilebot')) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . ' Mobile Joomla Plugin.'); } $plugin_table = self::isJoomla15() ? '#__plugins' : '#__extensions'; $query = "SELECT element, ordering FROM {$plugin_table} WHERE element IN ('mobilebot', 'cache') AND folder='system'"; $db->setQuery($query); $rows = $db->loadObjectList('element'); if (isset($rows['cache']) && $rows['cache']->ordering <= $rows['mobilebot']->ordering) { $ordering = max(0, $rows['mobilebot']->ordering + 1); $query = "UPDATE {$plugin_table} SET ordering={$ordering} WHERE element='cache' AND folder='system'"; $db->setQuery($query); $db->query(); } // install quickicon plugin if (!self::InstallPlugin('quickicon', $PluginSource, 'mjcpanel')) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . ' Quickicon - Mobile Joomla! CPanel Icon.'); } // install mobile plugins if (!JFolder::create(JPATH_PLUGINS . '/mobile')) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_CREATE_DIRECTORY') . ' ' . JPATH_PLUGINS . '/mobile'); } $checkers = array('simple' => 7, 'always' => 8, 'domains' => 9); foreach ($checkers as $plugin => $order) { if (!self::InstallPlugin('mobile', $PluginSource, $plugin, 1, $order)) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . ' Mobile - ' . ucfirst($plugin) . '.'); } } // install amdd plugin $amddSQL = $PluginSource . '/amdd/amdd_dump.sql.gz'; if (file_exists($amddSQL)) { if (!self::InstallPlugin('mobile', $PluginSource, 'amdd', 1, 0, 1)) { $status = false; JError::raiseError(0, JText::_('COM_MJ__CANNOT_INSTALL') . ' Mobile - AMDD'); } else { require_once JPATH_PLUGINS . '/mobile/' . (self::isJoomla15() ? '' : 'amdd/') . 'amdd/database/database.php'; $amdddb = AmddDatabase::getInstance('joomla'); $amdddb->createTables(); self::load_mysql_dump($amddSQL); JFile::delete($amddSQL); } } //tables for extmanager $db = JFactory::getDBO(); $query = "CREATE TABLE IF NOT EXISTS `#__mj_modules` (" . " `id` integer(10) UNSIGNED NOT NULL," . " `markup` varchar(16) NOT NULL," . " PRIMARY KEY (`markup`, `id`)" . ") DEFAULT CHARSET=utf8"; $db->setQuery($query); $db->query(); $query = "CREATE TABLE IF NOT EXISTS `#__mj_plugins` (" . " `id` integer(10) UNSIGNED NOT NULL," . " `markup` varchar(16) NOT NULL," . " PRIMARY KEY (`markup`, `id`)" . ") DEFAULT CHARSET=utf8"; $db->setQuery($query); $db->query(); if (function_exists('MJAddonInstallPlugins')) { $status = MJAddonInstallPlugins($PluginSource) && $status; } if ($status) { JFolder::delete($PluginSource); } self::cleanPluginsCache(); //Show install status $msg = ''; $count = 0; /** @var JException $error */ foreach (JError::getErrors() as $error) { if ($error->get('level') & E_ERROR) { $count++; } } if ($count == 0) { $msg .= str_replace('[VER]', self::MJ_publicVersion(), JText::_('COM_MJ__INSTALL_OK')); } ?> <link rel="stylesheet" type="text/css" href="http://www.mobilejoomla.com/checker.php?v=<?php echo urlencode(self::MJ_version()); ?> &s=1&j=<?php echo urlencode(JVERSION); ?> "/> <a href="http://www.mobilejoomla.com/" id="mjupdate" target="_blank"></a> <?php echo $msg; $postInstallActions = array(); if (function_exists('MJAddonPostInstall')) { MJAddonPostInstall($postInstallActions); } return true; }