/** * Installation of the extensions plugins and modules */ function installExtensions() { $db = JFactory::getDBO(); $errors = array(); $path = JNEWSPATH_ADMIN . 'extensions'; $dirs = JFolder::folders($path); $excludedExtensions = array(); if (version_compare(JVERSION, '1.6.0') < '') { //j15 $query = "DELETE FROM `#__modules` WHERE `module` LIKE '%jnewsletter%' "; $db->setQuery($query); $db->query(); $query = "SELECT CONCAT(`folder`,`element`) FROM #__plugins WHERE `folder` = 'jnews' OR `element` LIKE '%jnews%'"; $query .= " UNION SELECT `module` FROM #__modules WHERE `module` LIKE '%jnews%'"; $db->setQuery($query); $loadResultArray = $db->loadObjectList(); $existingExtensions = jnews::convertObjectList2Array($loadResultArray); } else { //j16 $db->setQuery("SELECT CONCAT(`folder`,`element`) FROM #__extensions WHERE `folder` = 'jnews' OR `element` LIKE '%jnews%'"); $loadResultArray = $db->loadObjectList(); $existingExtensions = jnews::convertObjectList2Array($loadResultArray); } $plugins = array(); $modules = array(); $extensioninfo = array(); //array('name','ordering','required table or published') $extensioninfo['mod_jnews'] = array('jNews Module'); $extensioninfo['jnewssyncuser'] = array('jNews User Synchronization', 20, 1); $extensioninfo['vmjnewssubs'] = array('jNews-Virtuemart Newsletter Subscription', 15, '#__vm_order_user_info'); $extensioninfo['forwardtofriend'] = array('jNews Forward to Friend', 5, 1); $extensioninfo['jnewsbot'] = array('jNews Content Plugin', 6, 1); $extensioninfo['jnewsbotk2'] = array('jNews K2 Plugin', 4, '#__k2_items'); $extensioninfo['jnewsshare'] = array('jNews Social Share Plugin', 9, 1); //inclusion of module in newsletter $extensioninfo['jnewsflexicontent'] = array('jNews Flexicontent Bot', 7, '#__flexicontent_cats_item_relations'); $extensioninfo['tagdatetime'] = array('jNews Tag: Date and Time', 2, 1); $extensioninfo['tagsite'] = array('jNews Tag: Site Links', 5, 1); $extensioninfo['tagsubscriber'] = array('jNews Tag: Subscriber', 3, 1); $extensioninfo['tagsubscription'] = array('jNews Tag: Subscriptions', 7); $extensioninfo['virtuemartproduct'] = array('VirtueMart Products', 8, '#__vm_product'); $listTables = $db->getTableList(); foreach ($dirs as $oneDir) { $arguments = explode('_', $oneDir); if ($arguments[0] == 'mod') { $newModule = new stdClass(); $newModule->name = $oneDir; if (isset($extensioninfo[$oneDir][0])) { $newModule->name = $extensioninfo[$oneDir][0]; } $newModule->type = 'module'; $newModule->folder = ''; $newModule->element = $oneDir; $newModule->enabled = 1; $newModule->params = '{}'; $newModule->ordering = 0; if (isset($extensioninfo[$oneDir][1])) { $newModule->ordering = $extensioninfo[$oneDir][1]; } $destinationFolder = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'modules' . DS . $oneDir; if (!jnews::createDirectory($destinationFolder)) { continue; } if (!jnews::copyFolder($path . DS . $oneDir, $destinationFolder)) { continue; } if (is_array($existingExtensions) && in_array($newModule->element, $existingExtensions)) { continue; } $modules[] = $newModule; } else { // it is a plugin $extensionKeys = array_keys($extensioninfo); $newPlugin = new stdClass(); if (in_array($oneDir, $extensionKeys)) { if (isset($extensioninfo[$oneDir][2])) { if (is_numeric($extensioninfo[$oneDir][2])) { $newPlugin->enabled = $extensioninfo[$oneDir][2]; } else { if (!in_array(str_replace('#__', $db->getPrefix(), $extensioninfo[$oneDir][2]), $listTables)) { $excludedExtensions[] = $oneDir; } } } if (!in_array($oneDir, $excludedExtensions)) { $newPlugin->name = $oneDir; if (isset($extensioninfo[$oneDir][0])) { $newPlugin->name = $extensioninfo[$oneDir][0]; } $newPlugin->type = 'plugin'; if ($oneDir == 'jnewssyncuser') { $newPlugin->folder = 'user'; } elseif ($oneDir == 'vmjnewssubs' || $oneDir == 'jnewscron') { $newPlugin->folder = 'system'; } else { $newPlugin->folder = 'jnews'; } $newPlugin->element = $oneDir; $newPlugin->enabled = 1; $newPlugin->params = '{}'; $newPlugin->ordering = 0; if (isset($extensioninfo[$oneDir][1])) { $newPlugin->ordering = $extensioninfo[$oneDir][1]; } if (!jnews::createDirectory(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'plugins' . DS . $newPlugin->folder)) { continue; } if (version_compare(JVERSION, '1.6.0', '<')) { //j15 $destinationFolder = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'plugins' . DS . $newPlugin->folder; } else { //j16 $destinationFolder = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'plugins' . DS . $newPlugin->folder . DS . $newPlugin->element; if (!jnews::createDirectory($destinationFolder)) { continue; } } if (!jnews::copyFolder($path . DS . $oneDir, $destinationFolder)) { continue; } if (is_array($existingExtensions) && in_array($newPlugin->folder . $newPlugin->element, $existingExtensions)) { continue; } $plugins[] = $newPlugin; } } } } if (!empty($errors)) { jnews::displayInfo($errors, 'error'); } if (version_compare(JVERSION, '1.6.0', '<')) { $extensions = $plugins; } else { $extensions = array_merge($plugins, $modules); } $success = array(); if (!empty($extensions)) { if (version_compare(JVERSION, '1.6.0', '<')) { $queryExtensions = 'INSERT INTO `#__plugins` (`name`,`element`,`folder`,`published`,`ordering`) VALUES '; } else { $queryExtensions = 'INSERT INTO `#__extensions` (`name`,`element`,`folder`,`enabled`,`ordering`,`type`,`access`,`manifest_cache`) VALUES '; } foreach ($extensions as $oneExt) { $queryExtensions .= '(' . $db->Quote($oneExt->name) . ',' . $db->Quote($oneExt->element) . ',' . $db->Quote($oneExt->folder) . ',' . $oneExt->enabled . ',' . $oneExt->ordering; if (version_compare(JVERSION, '1.6.0', '>=')) { $manifest_cache = '{"legacy":false,"name":"' . $oneExt->name . '","type":"plugin","creationDate":"' . date("F Y") . '","author":"Joobi Limited","copyright":"Copyright (C) 2006 - 2012 Joobi Limited. All rights reserved.","authorEmail":"*****@*****.**","authorUrl":"www.joobi.co","version":"' . jnews::getVersion() . '","description":"","group":""}'; $queryExtensions .= ',' . $db->Quote($oneExt->type) . ',1,' . $db->Quote($manifest_cache); } $queryExtensions .= '),'; if ($oneExt->type != 'module') { $success[] = JText::sprintf(_JNEWS_PLUG_INSTALLED, $oneExt->name); } } $queryExtensions = trim($queryExtensions, ','); $db->setQuery($queryExtensions); $db->query(); } if (!empty($modules)) { foreach ($modules as $oneModule) { if (version_compare(JVERSION, '1.6.0', '<')) { $queryModule = 'INSERT INTO `#__modules` (`title`,`position`,`published`,`module`) VALUES '; $queryModule .= '(' . $db->Quote($oneModule->name) . ",'left',0," . $db->Quote($oneModule->element) . ")"; } else { $queryModule = 'INSERT INTO `#__modules` (`title`,`position`,`published`,`module`,`access`,`language`) VALUES '; $queryModule .= '(' . $db->Quote($oneModule->name) . ",'position-7',0," . $db->Quote($oneModule->element) . ",1,'*')"; } $db->setQuery($queryModule); $db->query(); $moduleId = $db->insertid(); $db->setQuery('INSERT IGNORE INTO `#__modules_menu` (`moduleid`,`menuid`) VALUES (' . $moduleId . ',0)'); $db->query(); $success[] = JText::sprintf(_JNEWS_MODULE_INSTALLED, $oneModule->name); } } if (!empty($success)) { jnews::displayInfo($success, 'success'); } }
/** * CopyFolder to certain directory */ public static function copyFolder($from, $to) { $return = true; $allFiles = JFolder::files($from); foreach ($allFiles as $oneFile) { if (file_exists($to . DS . 'index.html') and $oneFile == 'index.html') { continue; } if (JFile::copy($from . DS . $oneFile, $to . DS . $oneFile) !== true) { echo '<br>Could not copy the file from ' . $from . DS . $oneFile . ' to ' . $to . DS . $oneFile; $return = false; } } $allFolders = JFolder::folders($from); if (!empty($allFolders)) { foreach ($allFolders as $oneFolder) { if (!jnews::createDirectory($to . DS . $oneFolder)) { continue; } if (!jnews::copyFolder($from . DS . $oneFolder, $to . DS . $oneFolder)) { $return = false; } } } return $return; }