Example #1
1
/**
 * Method to add menu's item.
 *
 * @return boolean true on success false on failure.
 */
function addMenuItems()
{
    $db = JFactory::getDBO();
    // Get new component id.
    $component = JComponentHelper::getComponent('com_community');
    $component_id = 0;
    if (is_object($component) && isset($component->id)) {
        $component_id = $component->id;
    }
    $column_name = JOOMLA_MENU_NAME;
    $column_cid = JOOMLA_MENU_COMPONENT_ID;
    // Get the default menu type
    // 2 Joomla bugs occur in /Administrator mode
    // Bug 1: JFactory::getApplication('site') failed. It always return id = 'administrator'.
    // Bug 2: JMenu::getDefault('*') failed. JAdministrator::getLanguageFilter() doesn't exist.
    // If these 2 bugs are fixed, we can call the following syntax:
    // $defaultMenuType	= JFactory::getApplication('sites')->getMenu()->getDefault()->menutype;
    jimport('joomla.application.application');
    $defaultMenuType = JApplication::getInstance('site')->getMenu()->getDefault('workaround_joomla_bug')->menutype;
    $query = 'SELECT ' . $db->nameQuote('ordering') . ' ' . 'FROM ' . $db->nameQuote('#__menu') . ' ' . 'ORDER BY ' . $db->nameQuote('ordering') . ' DESC LIMIT 1';
    $db->setQuery($query);
    $order = $db->loadResult() + 1;
    // Update the existing menu items.
    $row = JTable::getInstance('menu', 'JTable');
    $row->menutype = $defaultMenuType;
    $row->{$column_name} = 'JomSocial';
    $row->alias = 'JomSocial';
    $row->link = 'index.php?option=com_community&view=frontpage';
    $row->type = 'component';
    $row->published = '1';
    $row->{$column_cid} = $component_id;
    $row->ordering = $order;
    $row->id = null;
    //new item
    if (!JOOMLA_LEGACY_VERSION) {
        $row->language = '*';
    }
    $row->check();
    if (!$row->store()) {
        // $row->getError()
        return false;
    }
    //for version 1.6 only. The parent_id is not updated correctly via JTable
    if (!JOOMLA_LEGACY_VERSION) {
        $query = 'UPDATE ' . $db->nameQuote('#__menu') . ' SET `parent_id` = ' . $db->quote(1) . ', `level` = ' . $db->quote(1) . ' WHERE `id` = ' . $db->quote($row->id);
        $db->setQuery($query);
        $db->query();
        if ($db->getErrorNum()) {
            return false;
        }
    }
    if (!addDefaultToolbarMenus()) {
        return false;
    }
    // update memu items with component id
    if (!updateMenuItems()) {
        return false;
    }
    return true;
}
Example #2
0
    protected function updateDatabase($step)
    {
        $db = JFactory::getDBO();
        $html = '';
        $status = true;
        $stopUpdate = false;
        $continue = false;
        // Insert configuration codes if needed
        $hasConfig = $this->dbhelper->_isExistDefaultConfig();
        if (!$hasConfig) {
            $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_UPDATE_CONFIG') . '</div>';
            $obj = new stdClass();
            $obj->name = 'dbversion';
            $obj->params = DBVERSION;
            if (!$db->insertObject('#__community_config', $obj)) {
                $html .= $this->failedStatus;
                $status = false;
                $errorCode = '7a';
            } else {
                $default = JPATH_BASE . '/components/com_community/default.ini';
                $registry = JRegistry::getInstance('community');
                $registry->loadFile($default, 'INI', 'community');
                // Set the site name
                $app = JFactory::getApplication();
                $registry->setValue('community.sitename', $app->getCfg('sitename'));
                // Set the photos path
                $photoPath = rtrim(dirname(JPATH_BASE), '/');
                $registry->setValue('community.photospath', $photoPath . '/images');
                // Set the videos folder
                $registry->setValue('community.videofolder', 'images');
                // Store the config
                $obj = new stdClass();
                $obj->name = 'config';
                $obj->params = $registry->toString('INI', 'community');
                if (!$this->dbhelper->insertTableEntry('#__community_config', $obj)) {
                    $html .= $this->failedStatus;
                    ob_start();
                    ?>
					<div>
						Error when trying to create default configurations.
						Please proceed to the configuration and set your own configuration instead.
					</div>
					<?php 
                    $html .= ob_get_contents();
                    @ob_end_clean();
                } else {
                    $html .= $this->successStatus;
                }
            }
        } else {
            $dbversionConfig = $this->dbhelper->getDBVersion();
            $dbversion = empty($dbversionConfig) ? 0 : $dbversionConfig;
            if ($dbversion < DBVERSION) {
                $updater = new CommunityInstallerUpdate();
                $html .= '<div style="width:150px; float:left;">' . JText::_('Updating DB from version ' . $dbversion) . '</div>';
                $updateResult = call_user_func(array($updater, 'update_' . $dbversion));
                $stopUpdate = empty($updateResult->stopUpdate) ? false : true;
                if ($updateResult->status) {
                    $html .= $this->successStatus;
                    $status = true;
                    $dbversion++;
                    if ($dbversionConfig === null && $dbversionConfig !== 0) {
                        $this->dbhelper->insertDBVersion($dbversion);
                    } else {
                        $this->dbhelper->updateDBVersion($dbversion);
                    }
                    if ($dbversion < DBVERSION) {
                        $continue = true;
                    }
                } else {
                    $html .= $this->failedStatus;
                    $status = false;
                    $errorCode = $updateResult->errorCode;
                }
                $html .= $updateResult->html;
            }
        }
        if (!$stopUpdate) {
            if (!$continue) {
                // Need to update the menu's component id if this is a reinstall
                if (menuExist()) {
                    $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_UPDATE_MENU_ITEMS') . '</div>';
                    if (!updateMenuItems()) {
                        ob_start();
                        ?>
						<p style="font-weight: 700; color: red;">
							System encountered an error while trying to update the existing menu items. You will need
							to update the existing menu structure manually.
						</p>
						<?php 
                        $html .= ob_get_contents();
                        @ob_end_clean();
                        $html .= $this->failedStatus;
                    } else {
                        $html .= $this->successStatus;
                    }
                } else {
                    $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_CREATE_MENU_ITEMS') . '</div>';
                    if (!addMenuItems()) {
                        ob_start();
                        ?>
						<p style="font-weight: 700; color: red;">
							System encountered an error while trying to create a menu item. You will need
							to create your menu item manually.
						</p>
						<?php 
                        $html .= ob_get_contents();
                        @ob_end_clean();
                        $html .= $this->failedStatus;
                    } else {
                        $html .= $this->successStatus;
                    }
                }
                // Jomsocial menu types
                if (!menuTypesExist()) {
                    $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_CREATE_TOOLBAR_MENU_ITEM') . '</div>';
                    if (!addDefaultMenuTypes()) {
                        ob_start();
                        ?>
						<p style="font-weight: 700; color: red;">
							System encountered an error while trying to create a menu type item. You will need
							to create your toolbar menu type item manually.
						</p>
						<?php 
                        $html .= ob_get_contents();
                        @ob_end_clean();
                        $html .= $this->failedStatus;
                    } else {
                        $html .= $this->successStatus;
                    }
                }
                //clean up registration table if the table installed previously.
                $this->dbhelper->cleanRegistrationTable();
                // Test if we are required to add default custom fields
                $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_ADD_DEFAULT_CUSTOM_FIELD') . '</div>';
                if (needsDefaultCustomFields()) {
                    addDefaultCustomFields();
                    $html .= $this->successStatus;
                } else {
                    $html .= $this->notApplicable;
                }
                // Test if we are required to add default group categories
                $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_ADD_DEFAULT_GROUP_CATEGORIES') . '</div>';
                if (needsDefaultGroupCategories()) {
                    addDefaultGroupCategories();
                    $html .= $this->successStatus;
                } else {
                    $html .= $this->notApplicable;
                }
                // Test if we are required to add default videos categories
                $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_ADD_DEFAULT_VIDEO_CATEGORIES') . '</div>';
                if (needsDefaultVideosCategories()) {
                    addDefaultVideosCategories();
                    $html .= $this->successStatus;
                } else {
                    $html .= $this->notApplicable;
                }
                // Test if we are required to add default event categories
                $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_ADD_DEFAULT_EVENT_CATEGORIES') . '</div>';
                if (needsDefaultEventsCategories()) {
                    addDefaultEventsCategories();
                    $html .= $this->successStatus;
                } else {
                    $html .= $this->notApplicable;
                }
                // Test if we are required to add default user points
                $html .= '<div style="width:150px; float:left;">' . JText::_('COM_COMMUNITY_INSTALLATION_ADD_DEFAULT_USERPOINTS') . '</div>';
                if (needsDefaultUserPoints()) {
                    //clean up userpoints table if the table installed from previous version of 1.0.128
                    $this->dbhelper->cleanUserPointsTable();
                    addDefaultUserPoints();
                    $html .= $this->successStatus;
                } else {
                    //cleanup some unused action rules.
                    $this->dbhelper->cleanUserPointsTable(array('friends.request.add', 'friends.request.reject', 'friends.request.cancel', 'friends.invite'));
                    $html .= $this->notApplicable;
                }
            }
            if ($status) {
                if (!empty($continue)) {
                    $step = $step - 1;
                }
                $autoSubmit = $this->getAutoSubmitFunction();
                $message = $autoSubmit . $html;
            } else {
                $errorMsg = $this->getErrorMessage(7, $errorCode);
                $message = $html . $errorMsg;
                $step = $step - 1;
            }
        } else {
            $message = $html;
        }
        $drawdata = new stdClass();
        $drawdata->message = $message;
        $drawdata->status = $status;
        $drawdata->step = $step;
        $drawdata->title = JText::_('COM_COMMUNITY_INSTALLATION_UPDATING_DATABASE');
        $drawdata->install = 1;
        return $drawdata;
    }
Example #3
0
    function postflight($type, $parent)
    {
        $version = $this->version;
        $message = $this->message;
        $status = $this->status;
        // fix invalid admin menu id with Joomla 1.7
        fixMenuIds();
        //update or create menu item.
        if (menuExist()) {
            if (!updateMenuItems()) {
                $message[] = 'Warning : The system encounter an error when it tries to update the menu item. Please kindly update the menu item manually.';
            }
        } else {
            if (!createMenuItems()) {
                $message[] = 'Warning : The system encounter an error when it tries to create a menu item. Please kindly create the menu item manually.';
            }
        }
        ob_start();
        ?>

		<style type="text/css">
		/**
		 * Messages
		 */

		#eblog-message {
			color: red;
			font-size:13px;
			margin-bottom: 15px;
			padding: 5px 10px 5px 35px;
		}

		#eblog-message.error {
			border-top: solid 2px #900;
			border-bottom: solid 2px #900;
			color: #900;
		}

		#eblog-message.info {
			border-top: solid 2px #06c;
			border-bottom: solid 2px #06c;
			color: #06c;
		}

		#eblog-message.warning {
			border-top: solid 2px #f90;
			border-bottom: solid 2px #f90;
			color: #c30;
		}
		</style>

		<table width="100%" border="0">
			<tr>
				<td>
					<div><img src="http://stackideas.com/images/eblog/install_success35.png" /></div>
				</td>
			</tr>
			<?php 
        foreach ($message as $msgString) {
            $msg = explode(":", $msgString);
            switch (trim($msg[0])) {
                case 'Fatal Error':
                    $classname = 'error';
                    break;
                case 'Warning':
                    $classname = 'warning';
                    break;
                case 'Success':
                default:
                    $classname = 'info';
                    break;
            }
            ?>
					<tr>
						<td><div id="eblog-message" class="<?php 
            echo $classname;
            ?>
"><?php 
            echo $msg[0] . ' : ' . $msg[1];
            ?>
</div></td>
					</tr>
					<?php 
        }
        ?>
			<tr>
				<td><h3>Need help in starting up? Check out our <a href="http://stackideas.com/docs/easyblog/how-tos.html" target="_blank">How To</a> documentation.</h3></td>
			</tr>

		</table>
		<?php 
        $html = ob_get_contents();
        @ob_end_clean();
        echo $html;
        return $status;
    }