/** * Community Builder (TM) * @version $Id: $ * @package CommunityBuilder * @copyright (C) 2004-2016 www.joomlapolis.com / Lightning MultiCom SA - and its licensors, all rights reserved * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2 */ use CB\Application\CBApplication; // below autoload CB\Legacy\LegacyFoundationFunctions; use CBLib\Core\AutoLoader; // ensure this file is being included by a parent file if (!(defined('_VALID_CB') || defined('_JEXEC') || defined('_VALID_MOS'))) { die('Direct Access to this location is not allowed.'); } // Check that CBLib with CB Lib is installed: if (!is_readable(JPATH_SITE . '/libraries/CBLib/CB/Application/CBApplication.php')) { JFactory::getApplication()->enqueueMessage("Mandatory Community Builder lib_CBLib not installed!", 'error'); return false; } // Loads the first file: /** @noinspection PhpIncludeInspection */ include_once JPATH_SITE . '/libraries/CBLib/CB/Application/CBApplication.php'; // Initialize CB Application and Auto-load and initialize everything that was in here: CBApplication::init()->getDI()->get('\\CB\\Legacy\\LegacyFoundationFunctions'); // Add the plugins library autoloading path: AutoLoader::registerLibrary(JPATH_SITE . '/components/com_comprofiler/plugin/libraries/'); /** * The classes that were in here have moved to libraries/CBLib/CB/Legacy folder. * The functions in here have moved to libraries/CBLib/CB/Legacy/LegacyFoundationFunctions.php */
public function install($parent) { global $_CB_framework, $_CB_adminpath, $ueConfig; // Ensure PHP version is adaquete for CB: if (version_compare(phpversion(), '5.3.3', '<')) { JFactory::getApplication()->enqueueMessage(sprintf('As stated in README and prerequisites, PHP Version %s, which is obsolete since before 2009-11-19 and insecure, is not compatible with %s: Please upgrade to PHP %s or greater (CB is also compatible with PHP 5.4 and 5.5) before installing Community Builder.', phpversion(), 'Community Builder', sprintf('at least version %s, recommended version %s', '5.3.1', '5.3.10')), 'error'); JFactory::getApplication()->enqueueMessage(sprintf('Installation failed. In all cases, please require your hoster to upgrade your PHP version as soon as possible.'), 'error'); return false; } // Initialize CB Appplication library (which has delayed config lazy loading): if (is_readable(JPATH_SITE . '/libraries/CBLib/CB/Application/CBApplication.php')) { /** @noinspection PhpIncludeInspection */ include_once JPATH_SITE . '/libraries/CBLib/CB/Application/CBApplication.php'; \CB\Application\CBApplication::init(); } else { JFactory::getApplication()->enqueueMessage("Mandatory Community Builder lib_CBLib not installed!", 'error'); return false; } // Determine path to CBs backend file structure: $_CB_adminpath = JPATH_ADMINISTRATOR . '/components/com_comprofiler/'; // Disable loading of config immediately after foundation include as the db may not exist yet: \CB\Application\CBConfig::setCbConfigReadyToLoad(false); // Check if CBLib can load: /** @noinspection PhpIncludeInspection */ if (false === (include_once $_CB_adminpath . 'plugin.foundation.php')) { return false; } // Check if CBLib is up to date: if (version_compare(constant('CBLIB'), $ueConfig['version'], '<')) { JFactory::getApplication()->enqueueMessage(sprintf('Community Builder library lib_CBLib version %s is older than the Community Builder version %s tried to be installed.', constant('CBLIB'), $ueConfig['version']), 'error'); return false; } // Set location to backend: $_CB_framework->cbset('_ui', 2); if ($_CB_framework->getCfg('debug')) { ini_set('display_errors', true); error_reporting(E_ALL); } // Load in CB API: cbimport('cb.tabs'); cbimport('cb.adminfilesystem'); cbimport('cb.dbchecker'); // Define CB backend filesystem API: $adminFS = cbAdminFileSystem::getInstance(); // Delete removed files on upgrade: $filesToDelete = array($_CB_adminpath . 'comprofileg.xml', $_CB_adminpath . 'comprofilej.xml', $_CB_adminpath . 'admin.comprofiler.php', $_CB_adminpath . 'ue_config_first.php'); foreach ($filesToDelete as $deleteThisFile) { if ($adminFS->file_exists($deleteThisFile)) { $adminFS->unlink($deleteThisFile); } } $liveSite = $_CB_framework->getCfg('live_site'); $return = '<div style="margin-bottom:10px;width:100%;text-align:center;"><img alt="' . htmlspecialchars(CBTxt::T('CB Logo')) . '" src="' . $liveSite . '/components/com_comprofiler/images/smcblogo.gif" /></div>' . '<div style="font-size:14px;margin-bottom:10px;">Copyright 2004-2015 Joomlapolis.com. ' . CBTxt::T('This component is released under the GNU/GPL version 2 License. All copyright statements must be kept. Derivate work must prominently duly acknowledge original work and include visible online links.') . '</div>'; $cbDatabase = \CBLib\Application\Application::Database(); // Core database fixes: $dbChecker = new \CB\Database\CBDatabaseChecker($cbDatabase); $result = $dbChecker->checkDatabase(true, false, null, null); if ($result == true) { // All ok, Nothing to alarm user here: // $return .= '<div style="font-size:18px;color:green;margin-bottom:10px;">' . CBTxt::T( 'Automatic database upgrade applied successfully.' ) . '</div>'; } elseif (is_string($result)) { $return .= '<div style="font-size:18px;color:red;margin-bottom:10px;">' . $result . '</div>'; } else { $errors = $dbChecker->getErrors(false); if ($errors) { $return .= '<div style="color:red;margin-bottom:10px;">' . '<div style="font-size:18px;font-weight:bold;padding-bottom:5px;margin-bottom:5px;border-bottom:1px solid red;">' . CBTxt::T('Database fixing errors') . '</div>'; foreach ($errors as $error) { $return .= '<div style="margin-bottom:10px;">' . '<div style="font-size:14px;">' . $error[0] . '</div>'; if ($error[1]) { $return .= '<div style="font-size:12px;text-indent:15px;">' . $error[1] . '</div>'; } $return .= '</div>'; } $return .= '</div>'; } } if ($_CB_framework->getCfg('session_handler') != 'database') { $logs = $dbChecker->getLogs(false); if (count($logs) > 0) { $return .= '<div style="margin-bottom:10px;">' . '<div style="font-size:14px;margin-bottom:5px;">' . '<a href="javascript: void(0);" id="cbdetailsLinkShow" onclick="this.style.display=\'none\';document.getElementById(\'cbdetailsdbcheck\').style.display=\'block\';document.getElementById(\'cbdetailsLinkHide\').style.display=\'block\';return false;">' . CBTxt::T('Click to Show details') . '</a>' . '<a href="javascript: void(0);" id="cbdetailsLinkHide" onclick="this.style.display=\'none\';document.getElementById(\'cbdetailsdbcheck\').style.display=\'block\';document.getElementById(\'cbdetailsLinkShow\').style.display=\'block\';return false;" style="display:none;">' . CBTxt::T('Click to Hide details') . '</a>' . '</div>' . '<div id="cbdetailsdbcheck" style="dsiplay:none;color:green;">'; foreach ($logs as $log) { $return .= '<div style="margin-bottom:10px;">' . '<div style="font-size:14px;">' . $log[0] . '</div>'; if ($log[1]) { $return .= '<div style="font-size:12px;text-indent:15px;">' . $log[1] . '</div>'; } $return .= '</div>'; } $return .= '</div>' . '</div>'; } } // Fix old 1.x usergroups-based permissions to 2.x access-levels in lists and in tabs: $this->convertUserGroupsToViewAccessLevels(new \CB\Database\Table\TabTable(), 'CB Tab access'); $this->convertUserGroupsToViewAccessLevels(new \CB\Database\Table\ListTable(), 'CB Users list access'); // Synchronize users to CB: $query = 'INSERT IGNORE INTO ' . $cbDatabase->NameQuote('#__comprofiler') . "\n (" . $cbDatabase->NameQuote('id') . ', ' . $cbDatabase->NameQuote('user_id') . ')' . "\n SELECT " . $cbDatabase->NameQuote('id') . ', ' . $cbDatabase->NameQuote('id') . "\n FROM " . $cbDatabase->NameQuote('#__users'); $cbDatabase->setQuery($query); if (!$cbDatabase->query()) { $cbSpoofField = cbSpoofField(); $cbSpoofString = cbSpoofString(null, 'plugin'); $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('User synchronization failed. Please <a href="[url]" target="_blank">click here</a> to manually synchronize.', array('[url]' => $_CB_framework->backendUrl("index.php?option=com_comprofiler&view=syncUsers&{$cbSpoofField}={$cbSpoofString}"))) . '</div>'; } // Fix images: $imagesPath = $_CB_framework->getCfg('absolute_path') . '/images'; $cbImages = $imagesPath . '/comprofiler'; $cbImagesGallery = $cbImages . '/gallery'; $cbImagesCanvasGallery = $cbImages . '/gallery/canvas'; if ($adminFS->isUsingStandardPHP() && !$adminFS->file_exists($cbImages) && !$adminFS->is_writable($_CB_framework->getCfg('absolute_path') . '/images/')) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ is not writable.', array('[path]' => $imagesPath)) . '</div>'; } else { if (!$adminFS->file_exists($cbImages)) { if ($adminFS->mkdir($cbImages)) { // All ok, Nothing to alarm user here. // $return .= '<div style="font-size:14px;color:green;margin-bottom:10px;">' . CBTxt::P( '[path]/ successfully added.', array( '[path]' => $cbImages ) ) . '</div>'; } else { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to create, please do so manually.', array('[path]' => $cbImages)) . '</div>'; } } if (!$adminFS->file_exists($cbImagesGallery)) { if ($adminFS->mkdir($cbImagesGallery)) { // All ok, Nothing to alarm user here: // $return .= '<div style="font-size:14px;color:green;margin-bottom:10px;">' . CBTxt::P( '[path]/ successfully added.', array( '[path]' => $cbImagesGallery ) ) . '</div>'; } else { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to create, please do so manually.', array('[path]' => $cbImagesGallery)) . '</div>'; } } if (!$adminFS->file_exists($cbImagesCanvasGallery)) { if ($adminFS->mkdir($cbImagesCanvasGallery)) { // All ok, Nothing to alarm user here: // $return .= '<div style="font-size:14px;color:green;margin-bottom:10px;">' . CBTxt::P( '[path]/ successfully added.', array( '[path]' => $cbImagesCanvasGallery ) ) . '</div>'; } else { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to create, please do so manually.', array('[path]' => $cbImagesCanvasGallery)) . '</div>'; } } if ($adminFS->file_exists($cbImages)) { if (!is_writable($cbImages)) { if (!$adminFS->chmod($cbImages, 0775)) { if (!@chmod($cbImages, 0775)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to chmod to 775 please do so manually.', array('[path]' => $cbImages)) . '</div>'; } } } if (!is_writable($cbImages)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ is not writable and failed to chmod to 775 please do so manually.', array('[path]' => $cbImages)) . '</div>'; } if (!$adminFS->file_exists($cbImages . '/index.html')) { $result = @copy($imagesPath . '/index.html', $cbImages . '/index.html'); if (!$result) { $result = $adminFS->copy($imagesPath . '/index.html', $cbImages . '/index.html'); } if (!$result) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('index.html failed to be added to [path] please do so manually.', array('[path]' => $cbImages)) . '</div>'; } } } if ($adminFS->file_exists($cbImagesGallery)) { if (!is_writable($cbImagesGallery)) { if (!$adminFS->chmod($cbImagesGallery, 0775)) { if (!@chmod($cbImagesGallery, 0775)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to chmod to 775 please do so manually.', array('[path]' => $cbImagesGallery)) . '</div>'; } } } if (!is_writable($cbImagesGallery)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ is not writable and failed to chmod to 775 please do so manually.', array('[path]' => $cbImagesGallery)) . '</div>'; } $galleryPath = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler/images/gallery'; $galleryDir = @opendir($galleryPath); $galleryFiles = array(); while (true == ($file = @readdir($galleryDir))) { if ($file != '.' && $file != '..') { $galleryFiles[] = $file; } } @closedir($galleryDir); foreach ($galleryFiles as $galleryFile) { if (!(file_exists($cbImagesGallery . '/' . $galleryFile) && is_readable($cbImagesGallery . '/' . $galleryFile))) { $result = @copy($galleryPath . '/' . $galleryFile, $cbImagesGallery . '/' . $galleryFile); if (!$result) { $result = $adminFS->copy($galleryPath . '/' . $galleryFile, $cbImagesGallery . '/' . $galleryFile); } if (!$result) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[file] failed to be added to the gallery please do so manually.', array('[file]' => $galleryFile)) . '</div>'; } } } if (!$adminFS->file_exists($cbImagesGallery . '/index.html')) { $result = @copy($imagesPath . '/index.html', $cbImagesGallery . '/index.html'); if (!$result) { $result = $adminFS->copy($imagesPath . '/index.html', $cbImagesGallery . '/index.html'); } if (!$result) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('index.html failed to be added to [path] please do so manually.', array('[path]' => $cbImagesGallery)) . '</div>'; } } } if ($adminFS->file_exists($cbImagesCanvasGallery)) { if (!is_writable($cbImagesCanvasGallery)) { if (!$adminFS->chmod($cbImagesCanvasGallery, 0775)) { if (!@chmod($cbImagesCanvasGallery, 0775)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ failed to chmod to 775 please do so manually.', array('[path]' => $cbImagesCanvasGallery)) . '</div>'; } } } if (!is_writable($cbImagesCanvasGallery)) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[path]/ is not writable and failed to chmod to 775 please do so manually.', array('[path]' => $cbImagesCanvasGallery)) . '</div>'; } $galleryPath = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler/images/gallery/canvas'; $galleryDir = @opendir($galleryPath); $galleryFiles = array(); while (true == ($file = @readdir($galleryDir))) { if ($file != '.' && $file != '..') { $galleryFiles[] = $file; } } @closedir($galleryDir); foreach ($galleryFiles as $galleryFile) { if (!(file_exists($cbImagesCanvasGallery . '/' . $galleryFile) && is_readable($cbImagesCanvasGallery . '/' . $galleryFile))) { $result = @copy($galleryPath . '/' . $galleryFile, $cbImagesCanvasGallery . '/' . $galleryFile); if (!$result) { $result = $adminFS->copy($galleryPath . '/' . $galleryFile, $cbImagesCanvasGallery . '/' . $galleryFile); } if (!$result) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('[file] failed to be added to the gallery please do so manually.', array('[file]' => $galleryFile)) . '</div>'; } } } if (!$adminFS->file_exists($cbImagesCanvasGallery . '/index.html')) { $result = @copy($imagesPath . '/index.html', $cbImagesCanvasGallery . '/index.html'); if (!$result) { $result = $adminFS->copy($imagesPath . '/index.html', $cbImagesCanvasGallery . '/index.html'); } if (!$result) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('index.html failed to be added to [path] please do so manually.', array('[path]' => $cbImagesCanvasGallery)) . '</div>'; } } } } if (!($adminFS->file_exists($cbImages) && is_writable($cbImages) && $adminFS->file_exists($cbImagesGallery) && $adminFS->file_exists($cbImagesCanvasGallery))) { $return .= '<div style="margin-bottom:10px;">' . '<div style="font-size:14px;">' . CBTxt::T('Manually do the following:') . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::P('1. create [path]/ directory', array('[path]' => $cbImages)) . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::T('2. chmod it to 755 or if needed to 775') . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::P('3. create [path]/ directory', array('[path]' => $cbImagesGallery)) . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::T('4. chmod it to 755 or if needed to 775') . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::P('5. copy [from_path]/ and its contents to [to_path]/', array('[from_path]' => $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler/images/gallery', '[to_path]' => $cbImagesGallery)) . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::P('6. create [path]/ directory', array('[path]' => $cbImagesCanvasGallery)) . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::T('7. chmod it to 755 or if needed to 775') . '</div>' . '<div style="font-size:12px;text-indent:15px;">' . CBTxt::P('8. copy [from_path]/ and its contents to [to_path]/', array('[from_path]' => $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler/images/gallery/canvas', '[to_path]' => $cbImagesCanvasGallery)) . '</div>' . '</div>'; } $pluginMessages = null; if (cbInstaller_install_plugins($pluginMessages)) { // All ok, Nothing to alarm user here- // $return .= '<div style="font-size:18px;color:green;margin-bottom:10px;">' . CBTxt::T( 'Core plugins installed successfully.' ) . '</div>'; } else { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Core plugins installation failed. Please <a href="[url]" target="_blank">click here</a> to manually install.', array('[url]' => $_CB_framework->backendUrl('index.php?option=com_comprofiler&view=finishinstallation'))) . '</div>'; } $return .= $pluginMessages . '<div style="color:green;font-size:18px;font-weight:bold;margin-top:15px;margin-bottom:15px;">' . CBTxt::P('Installation done.') . '</div>' . '<div style="color:green;font-size:18px;font-weight:bold;margin-top:15px;margin-bottom:15px;">' . CBTxt::P('Now is a great time to checkout the <a href="[help_url]" target="_blank">Getting Started</a> resources.', array('[help_url]' => 'http://www.joomlapolis.com/documentation/community-builder/getting-started?pk_campaign=in-cb&pk_kwd=installedwelcomescreen')) . '</div>' . '<div style="margin-bottom:10px;">' . '<div style="font-size:12px;"><a href="http://www.joomlapolis.com/cb-solutions?pk_campaign=in-cb&pk_kwd=installedwelcomescreen" target="_blank">' . CBTxt::T('Click here to see more CB Plugins (Languages, Fields, Tabs, Signup-Connect, Paid Memberships and over 30 more) by CB Team at joomlapolis.com') . '</a></div>' . '<div style="font-size:12px;"><a href="http://extensions.joomla.org/extensions/clients-a-communities/communities/210" target="_blank">' . CBTxt::T('Click here to see our CB listing on the Joomla! Extensions Directory (JED) and find third-party add-ons for your website.') . '</a></div>' . '<div style="font-size:12px;margin:10px 0 25px;">or <a href="index.php?option=com_comprofiler&view=showconfig" class="btn btn-primary">' . CBTxt::T('Start to Configure Community Builder') . '</a></div>' . '</div>'; echo $return; // For display in packager: $_CB_framework->setUserState('com_comprofiler_install', $return); return true; }