function installExtension($name, $title, $type = 'component', $extra = array()) { $mainframe =& JFactory::getApplication(); // Create database object $db =& JFactory::getDBO(); $installed = 0; if (JV15) { if (function_exists('beforeInstall')) { beforeInstall($db); } switch ($type) { case 'component': $query = 'SELECT id FROM `#__components`' . ' WHERE `option` = ' . $db->quote('com_' . $name) . ' LIMIT 1'; $db->setQuery($query); $installed = $db->loadResult(); if (!$installed) { $query = 'ALTER TABLE `#__components`' . ' AUTO_INCREMENT = 1'; $db->setQuery($query); $db->query(); $row =& JTable::getInstance('component'); $row->name = $title; $row->admin_menu_alt = $title; $row->option = 'com_' . $name; $row->link = 'option=com_' . $name; $row->admin_menu_link = 'option=com_' . $name; foreach ($extra as $key => $val) { $row->{$key} = $val; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); return; } } break; case 'plugin': $folder = $extra['folder']; $query = 'SELECT id FROM `#__plugins`' . ' WHERE `element` = ' . $db->quote($name) . ' AND `folder` = ' . $db->quote($folder) . ' LIMIT 1'; $db->setQuery($query); $installed = $db->loadResult(); if (!$installed) { $query = 'ALTER TABLE `#__plugins`' . ' AUTO_INCREMENT = 1'; $db->setQuery($query); $db->query(); $row =& JTable::getInstance('plugin'); $row->name = $title; $row->element = $name; $row->published = 1; foreach ($extra as $key => $val) { $row->{$key} = $val; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); return; } } break; case 'module': $query = 'SELECT id FROM `#__modules`' . ' WHERE `module` = ' . $db->quote('mod_' . $name) . ' LIMIT 1'; $db->setQuery($query); $installed = $db->loadResult(); if (!$installed) { $query = 'ALTER TABLE `#__modules`' . ' AUTO_INCREMENT = 1'; $db->setQuery($query); $db->query(); $row =& JTable::getInstance('module'); $row->title = $title; $row->module = 'mod_' . $name; $row->ordering = $row->getNextOrder("position='left'"); $row->position = 'left'; $row->showtitle = 1; foreach ($extra as $key => $val) { $row->{$key} = $val; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); return; } // Clean up possible garbage first $query = 'DELETE FROM #__modules_menu WHERE moduleid = ' . (int) $row->id; $db->setQuery($query); $db->query(); // Time to create a menu entry for the module $query = 'INSERT INTO `#__modules_menu` VALUES ( ' . (int) $row->id . ', 0 )'; $db->setQuery($query); $db->query(); } break; } if (function_exists('afterInstall')) { afterInstall($db); } } else { if (function_exists('beforeInstall_16')) { beforeInstall_16($db); } else { if (function_exists('beforeInstall')) { beforeInstall($db); } } $where = array(); $where[] = '`type` = ' . $db->quote($type); $element = $name; $folder = ''; switch ($type) { case 'component': $element = 'com_' . $element; break; case 'plugin': $folder = isset($extra['folder']) ? $extra['folder'] : 'system'; unset($extra['folder']); $where[] = '`folder` = ' . $db->quote($folder); break; case 'module': $element = 'mod_' . $element; $query = 'SELECT id FROM `#__modules`' . ' WHERE `module` = ' . $db->quote($element) . ' LIMIT 1'; $db->setQuery($query); $installed = $db->loadResult(); if (!$installed) { $query = 'ALTER TABLE `#__modules`' . ' AUTO_INCREMENT = 1'; $db->setQuery($query); $db->query(); $row =& JTable::getInstance('module'); $row->title = $title; $row->module = $element; $row->ordering = $row->getNextOrder("position='left'"); $row->position = 'left'; $row->showtitle = 1; foreach ($extra as $key => $val) { $row->{$key} = $val; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); return; } // Clean up possible garbage first $query = 'DELETE FROM #__modules_menu WHERE moduleid = ' . (int) $row->id; $db->setQuery($query); $db->query(); // Time to create a menu entry for the module $query = 'INSERT INTO `#__modules_menu` VALUES ( ' . (int) $row->id . ', 0 )'; $db->setQuery($query); $db->query(); } break; } $where[] = '`element` = ' . $db->quote($element); $query = 'SELECT extension_id FROM `#__extensions`' . ' WHERE ' . implode(' AND ', $where) . ' LIMIT 1'; $db->setQuery($query); $installed = $db->loadResult(); $id = $installed; if (!$installed) { $query = 'ALTER TABLE `#__extensions`' . ' AUTO_INCREMENT = 1'; $db->setQuery($query); $db->query(); $row =& JTable::getInstance('extension'); $row->name = $name; $row->element = $name; $row->type = $type; $row->enabled = 1; switch ($type) { case 'component': $row->name = 'com_' . $row->name; $row->element = 'com_' . $row->element; break; case 'plugin': $row->name = 'plg_' . $folder . '_' . $row->name; $row->folder = $folder; break; case 'module': $row->name = 'mod_' . $row->name; $row->element = 'mod_' . $row->element; break; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); return; } $id = $row->extension_id; } if ($id && $type == 'component') { $query = 'DELETE FROM `#__menu`' . ' WHERE component_id = ' . (int) $id; $db->setQuery($query); $db->query(); $file = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_' . $name . DS . 'com_' . $name . '.xml'; $xml = JFactory::getXML($file); $menuElement = $xml->administration->menu; if ($menuElement) { $data = array(); $data['menutype'] = 'main'; $data['client_id'] = 1; $data['title'] = (string) $menuElement; $data['alias'] = (string) $menuElement; $data['link'] = 'index.php?option=' . 'com_' . $name; $data['type'] = 'component'; $data['published'] = 0; $data['parent_id'] = 1; $data['component_id'] = $id; $data['img'] = (string) $menuElement->attributes()->img ? (string) $menuElement->attributes()->img : 'class:component'; $data['home'] = 0; $table = JTable::getInstance('menu'); if (!$table->setLocation(1, 'last-child') || !$table->bind($data) || !$table->check() || !$table->store()) { $mainframe->enqueueMessage($table->getError(), 'error'); return; } } } if (function_exists('afterInstall_16')) { afterInstall_16($db); } else { if (function_exists('afterInstall')) { afterInstall($db); } } } $cookieName = JUtility::getHash('version_' . $name . '_version'); setcookie($cookieName, '', 0); return $installed ? 2 : 1; }
function installExtension( $name, $title, $type = 'component', $extra = array(), $reinstall = 0 ) { $mainframe =& JFactory::getApplication(); // Create database object $db =& JFactory::getDBO(); $installed = 0; if ( function_exists( 'beforeInstall_15' ) ) { beforeInstall_15( $db ); } else if ( function_exists( 'beforeInstall' ) ) { beforeInstall( $db ); } switch ( $type ) { case 'component': if ( $reinstall ) { $query = 'DELETE FROM `#__components`' .' WHERE `option` = '.$db->quote( 'com_'.$name ); $db->setQuery( $query ); $db->query(); $installed = 0; } else { $query = 'SELECT `id` FROM `#__components`' .' WHERE `option` = '.$db->quote( 'com_'.$name ) .' LIMIT 1'; $db->setQuery( $query ); $installed = (int) $db->loadResult(); } if ( !$installed ) { $query = 'ALTER TABLE `#__components`' .' AUTO_INCREMENT = 1'; $db->setQuery( $query ); $db->query(); $row =& JTable::getInstance( 'component' ); $row->name = $title; $row->admin_menu_alt = $title; $row->option = 'com_'.$name; $row->link = 'option=com_'.$name; $row->admin_menu_link = 'option=com_'.$name; foreach ( $extra as $key => $val ) { $row->$key = $val; } if ( !$row->store() ) { $mainframe->enqueueMessage( $row->getError(), 'error' ); return; } } break; case 'plugin': // Clean up possible garbage first $query = 'DELETE FROM `#__plugins`' .' WHERE `element` = '.$db->quote( $name ) .' AND `folder` = \'\''; $db->setQuery( $query ); $db->query(); $folder = $extra['folder']; if ( $reinstall ) { $query = 'DELETE FROM `#__plugins`' .' WHERE `element` = '.$db->quote( $name ) .' AND `folder` = '.$db->quote( $folder ); $db->setQuery( $query ); $db->query(); $installed = 0; } else { $query = 'SELECT `id` FROM `#__plugins`' .' WHERE `element` = '.$db->quote( $name ) .' AND `folder` = '.$db->quote( $folder ) .' LIMIT 1'; $db->setQuery( $query ); $installed = (int) $db->loadResult(); } if ( !$installed ) { $query = 'ALTER TABLE `#__plugins`' .' AUTO_INCREMENT = 1'; $db->setQuery( $query ); $db->query(); $row =& JTable::getInstance( 'plugin' ); $row->name = $title; $row->element = $name; $row->published = 1; foreach ( $extra as $key => $val ) { $row->$key = $val; } if ( !$row->store() ) { $mainframe->enqueueMessage( $row->getError(), 'error' ); return; } } break; case 'module': if ( $reinstall ) { $query = 'DELETE FROM `#__modules`' .' WHERE `module` = '.$db->quote( 'mod_'.$name ); $db->setQuery( $query ); $db->query(); $installed = 0; } else { $query = 'SELECT `id` FROM `#__modules`' .' WHERE `module` = '.$db->quote( 'mod_'.$name ) .' LIMIT 1'; $db->setQuery( $query ); $installed = (int) $db->loadResult(); } if ( !$installed ) { $query = 'ALTER TABLE `#__modules`' .' AUTO_INCREMENT = 1'; $db->setQuery( $query ); $db->query(); $row =& JTable::getInstance( 'module' ); $row->title = $title; $row->module = 'mod_'.$name; $row->ordering = $row->getNextOrder( "position='left'" ); $row->position = 'left'; $row->showtitle = 1; foreach ( $extra as $key => $val ) { $row->$key = $val; } if ( !$row->store() ) { $mainframe->enqueueMessage( $row->getError(), 'error' ); return; } // Clean up possible garbage first $query = 'DELETE FROM `#__modules_menu` WHERE `moduleid` = '.( int ) $row->id; $db->setQuery( $query ); $db->query(); // Time to create a menu entry for the module $query = 'INSERT INTO `#__modules_menu` VALUES ( '.( int ) $row->id.', 0 )'; $db->setQuery( $query ); $db->query(); } break; } if ( function_exists( 'afterInstall_15' ) ) { afterInstall_15( $db ); } else if ( function_exists( 'afterInstall' ) ) { afterInstall( $db ); } $cookieName = JUtility::getHash( 'version_'.$name.'_version' ); setcookie( $cookieName, '', 0 ); return ( $installed ) ? 2 : 1; }
} return $res; } function getInstallActions() { if (!isset($_POST['action'])) { return 0; } $action = str_replace('.', '##', $_POST['action']); if (file_exists("actions/" . $action . '.php')) { return $action; } return 0; } $action = getInstallActions(); if ($action) { include "actions/{$action}.php"; $action = new action(0); $action->execute(); } $route = getroute(); if (beforeInstall()) { $curpage = 'controller/beforeInstall'; } else { $curpage = 'controller/' . $route; } include "{$curpage}.php"; $page = new page($curpage, 0, 0); $page->prepare(); $page->render(); echo $page->show();
function installExtension( $name, $title, $type = 'component', $extra = array(), $reinstall = 0 ) { $mainframe =& JFactory::getApplication(); // Create database object $db =& JFactory::getDBO(); $installed = 0; if ( function_exists( 'beforeInstall' ) ) { beforeInstall( $db ); } $where = array(); $where[] = '`type` = '.$db->quote( $type ); $element = $name; $folder = ''; switch ( $type ) { case 'component': $element = 'com_'.$element; break; case 'plugin': $folder = isset( $extra['folder'] ) ? $extra['folder'] : 'system'; unset( $extra['folder'] ); $where[] = '`folder` = '.$db->quote( $folder ); break; case 'module': $element = 'mod_'.$element; if ( $reinstall ) { $query = 'DELETE FROM `#__modules`' .' WHERE `module` = '.$db->quote( $element ); $db->setQuery( $query ); $db->query(); $installed = 0; } else { $query = 'SELECT `id` FROM `#__modules`' .' WHERE `module` = '.$db->quote( $element ) .' LIMIT 1'; $db->setQuery( $query ); $installed = (int) $db->loadResult(); } if ( !$installed ) { $query = 'ALTER TABLE `#__modules`' .' AUTO_INCREMENT = 1'; $db->setQuery( $query ); $db->query(); $row =& JTable::getInstance( 'module' ); $row->title = $title; $row->module = $element; $row->ordering = $row->getNextOrder( "position='left'" ); $row->position = 'left'; $row->showtitle = 1; $row->language = '*'; foreach ( $extra as $key => $val ) { if ( property_exists( $row, $key ) ) { $row->$key = $val; } } if ( !$row->store() ) { $mainframe->enqueueMessage( $row->getError(), 'error' ); return 0; } // Clean up possible garbage first $query = 'DELETE FROM `#__modules_menu` WHERE `moduleid` = '.( int ) $row->id; $db->setQuery( $query ); $db->query(); // Time to create a menu entry for the module $query = 'INSERT INTO `#__modules_menu` VALUES ( '.( int ) $row->id.', 0 )'; $db->setQuery( $query ); $db->query(); } break; } $where[] = '`element` = '.$db->quote( $element ); if ( $reinstall ) { $query = 'DELETE FROM `#__extensions`' .' WHERE '.implode( ' AND ', $where ); $db->setQuery( $query ); $db->query(); $installed = 0; } else { $query = 'SELECT `extension_id` FROM `#__extensions`' .' WHERE '.implode( ' AND ', $where ) .' LIMIT 1'; $db->setQuery( $query ); $installed = (int) $db->loadResult(); } $id = $installed; if ( !$installed ) { $query = 'ALTER TABLE `#__extensions`' .' AUTO_INCREMENT = 1'; $db->setQuery( $query ); $db->query(); $row =& JTable::getInstance( 'extension' ); $row->name = strtoupper( $name ); $row->element = $name; $row->type = $type; $row->enabled = 1; $row->client_id = 0; $row->access = 1; switch ( $type ) { case 'component': $row->name = strtoupper( 'com_'.$row->name ); $row->element = 'com_'.$row->element; $row->access = 0; $row->client_id = 1; break; case 'plugin': $row->name = strtoupper( 'plg_'.$folder.'_'.$row->name ); $row->folder = $folder; break; case 'module': $row->name = strtoupper( 'mod_'.$row->name ); $row->element = 'mod_'.$row->element; break; } foreach ( $extra as $key => $val ) { if ( property_exists( $row, $key ) ) { $row->$key = $val; } } if ( !$row->store() ) { $mainframe->enqueueMessage( $row->getError(), 'error' ); return 0; } $id = (int) $row->extension_id; } if ( !$id ) { return 0; } $query = 'UPDATE `#__extensions`' .' SET `manifest_cache` = \'\'' .' WHERE `extension_id` = '.(int) $id; ; $db->setQuery( $query ); $db->query(); if ( in_array( $name, array( 'nnframework', 'nonumberelements' ) ) ) { $installer = JInstaller::getInstance(); $installer->refreshManifestCache( (int) $id ); } if ( $type == 'component' ) { $query = 'DELETE FROM `#__menu`' .' WHERE `link` = '.$db->quote( 'index.php?option=com_'.$name ); $db->setQuery( $query ); $db->query(); $file = dirname( dirname( __FILE__ ) ).'/extensions/16/administrator/components/com_'.$name.'/'.$name.'.xml'; $xml = JFactory::getXML( $file ); if ( isset( $xml->administration ) && isset( $xml->administration->menu ) ) { $menuElement = $xml->administration->menu; if ( $menuElement ) { $data = array(); $data['menutype'] = 'menu'; $data['client_id'] = 1; $data['title'] = (string) $menuElement; $data['alias'] = $name; $data['link'] = 'index.php?option='.'com_'.$name; $data['type'] = 'component'; $data['published'] = 1; $data['parent_id'] = 1; $data['component_id'] = $id; $attribs = $menuElement->attributes(); $data['img'] = ( (string) $attribs->img ) ? (string) $attribs->img : 'class:component'; $data['home'] = 0; $data['language'] = '*'; $table = JTable::getInstance( 'menu' ); if ( !$table->setLocation( 1, 'last-child' ) || !$table->bind( $data ) || !$table->check() || !$table->store() ) { $mainframe->enqueueMessage( $table->getError(), 'error' ); return 0; } } } } if ( function_exists( 'afterInstall' ) ) { afterInstall( $db ); } $cookieName = JUtility::getHash( 'version_'.$name.'_version' ); setcookie( $cookieName, '', 0 ); return array( ( ( $installed ) ? 2 : 1 ), $id ); }