Improving performance of index.php

skala
Julio Montoya 12 years ago
parent dd7e423d99
commit a1ec5931fd
  1. 7
      index.php
  2. 21
      main/inc/lib/group_portal_manager.lib.php
  3. 10
      main/inc/lib/mail.lib.inc.php
  4. 35
      main/inc/lib/main_api.lib.php
  5. 39
      main/inc/lib/message.lib.php
  6. 43
      main/inc/lib/template.lib.php
  7. 17
      main/messages/new_message.php
  8. 9
      main/template/default/layout/head.tpl
  9. 16
      main/template/default/layout/menu.tpl
  10. 12
      main/template/default/layout/topbar.tpl

@ -119,6 +119,7 @@ class IndexController
}
}
//Hot courses & announcements
$hot_courses = null;
$announcements_block = null;
@ -132,8 +133,11 @@ class IndexController
$app['template']->assign('hot_courses', $hot_courses);
$app['template']->assign('announcements_block', $announcements_block);
//Homepage
$app['template']->assign('home_page_block', PageController::return_home_page());
//Navigation links
$nav_links = $app['template']->return_navigation_links();
$app['template']->assign('navigation_course_links', $nav_links);
@ -145,7 +149,6 @@ class IndexController
if (api_is_platform_admin() || api_is_drh()) {
PageController::return_skills_links();
}
$response = $app['template']->render_layout('layout_2_col.tpl');
//return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, public'));
@ -158,7 +161,7 @@ class IndexController
* @todo Check if this code is used. I think this code is never executed because after clicking the submit button
* the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
* on api_get_setting('page_after_login').
* @deprecated
* @deprecated seems not to be used
*/
function check_last_login() {
if (!empty($_POST['submitAuth'])) {

@ -9,25 +9,6 @@
/**
* Code
*/
// Group permissions
define('GROUP_PERMISSION_OPEN' , '1');
define('GROUP_PERMISSION_CLOSED', '2');
// Group user permissions
define('GROUP_USER_PERMISSION_ADMIN' , '1'); // the admin of a group
define('GROUP_USER_PERMISSION_READER', '2'); // a normal user
define('GROUP_USER_PERMISSION_PENDING_INVITATION', '3'); // When an admin/moderator invites a user
define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', '4'); // an user joins a group
define('GROUP_USER_PERMISSION_MODERATOR', '5'); // a moderator
define('GROUP_USER_PERMISSION_ANONYMOUS' , '6'); // an anonymous user
define('GROUP_USER_PERMISSION_HRM', '7'); // a human resources manager
define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
define('GROUP_IMAGE_SIZE_BIG', 2);
define('GROUP_IMAGE_SIZE_MEDIUM', 3);
define('GROUP_IMAGE_SIZE_SMALL', 4);
define('GROUP_TITLE_LENGTH', 50);
/**
* Class
@ -1097,7 +1078,7 @@ class GroupPortalManager
$sql = "UPDATE $table_message SET msg_status=3 WHERE group_id = $group_id AND (id = '$topic_id' OR parent_id = $topic_id) ";
Database::query($sql);
}
public static function get_groups_by_user_count($user_id = '', $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) {
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);

@ -203,5 +203,15 @@ function api_mail_html($recipient_name, $recipient_email, $subject, $message, $s
// Clear all the addresses.
$mail->ClearAddresses();
/*
$body = $message;
$message = \Swift_Message::newInstance()
->setSubject('[YourSite] Feedback')
->setFrom(array($sender_email , $sender_name))
->setTo(array($recipient_email => $recipient_name))
->setBody($body);
global $app;
$app['mailer']->send($message);*/
return 1;
}

@ -323,6 +323,40 @@ define('SHOW_TEXT_NEAR_ICONS', false);
define ('EVENT_EMAIL_TEMPLATE_ACTIVE', 1);
define ('EVENT_EMAIL_TEMPLATE_INACTIVE',0);
// Group permissions
define('GROUP_PERMISSION_OPEN' , '1');
define('GROUP_PERMISSION_CLOSED', '2');
// Group user permissions
define('GROUP_USER_PERMISSION_ADMIN' , '1'); // the admin of a group
define('GROUP_USER_PERMISSION_READER', '2'); // a normal user
define('GROUP_USER_PERMISSION_PENDING_INVITATION', '3'); // When an admin/moderator invites a user
define('GROUP_USER_PERMISSION_PENDING_INVITATION_SENT_BY_USER', '4'); // an user joins a group
define('GROUP_USER_PERMISSION_MODERATOR', '5'); // a moderator
define('GROUP_USER_PERMISSION_ANONYMOUS' , '6'); // an anonymous user
define('GROUP_USER_PERMISSION_HRM', '7'); // a human resources manager
define('GROUP_IMAGE_SIZE_ORIGINAL', 1);
define('GROUP_IMAGE_SIZE_BIG', 2);
define('GROUP_IMAGE_SIZE_MEDIUM', 3);
define('GROUP_IMAGE_SIZE_SMALL', 4);
define('GROUP_TITLE_LENGTH', 50);
// Messages
/*
* @todo use constants!
*/
define('MESSAGE_STATUS_NEW', '0');
define('MESSAGE_STATUS_UNREAD', '1');
//2 ??
define('MESSAGE_STATUS_DELETED', '3');
define('MESSAGE_STATUS_OUTBOX', '4');
define('MESSAGE_STATUS_INVITATION_PENDING', '5');
define('MESSAGE_STATUS_INVITATION_ACCEPTED', '6');
define('MESSAGE_STATUS_INVITATION_DENIED', '7');
/**
* Inclusion of internationalization libraries
@ -2917,7 +2951,6 @@ function api_not_found($print_headers = false) {
if ((!headers_sent() || $print_headers) && $origin != 'learnpath') {
$show_headers = 1;
}
//$tpl = new Template(null, $show_headers, $show_headers);
$app['template.show_header'] = $show_headers;
$app['template.show_footer'] = $show_headers;

@ -9,22 +9,8 @@
/**
* Code
*/
require_once api_get_path(LIBRARY_PATH).'online.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
/*
* @todo use constants!
*/
define('MESSAGE_STATUS_NEW', '0');
define('MESSAGE_STATUS_UNREAD', '1');
//2 ??
define('MESSAGE_STATUS_DELETED', '3');
define('MESSAGE_STATUS_OUTBOX', '4');
define('MESSAGE_STATUS_INVITATION_PENDING', '5');
define('MESSAGE_STATUS_INVITATION_ACCEPTED', '6');
define('MESSAGE_STATUS_INVITATION_DENIED', '7');
/**
* Class
@ -52,10 +38,13 @@ class MessageManager
if (!api_get_user_id()) {
return false;
}
$query = "SELECT * FROM $table_message WHERE user_receiver_id = ".api_get_user_id()." AND msg_status = ".MESSAGE_STATUS_UNREAD;
$query = "SELECT count(id) as count FROM $table_message WHERE user_receiver_id = ".api_get_user_id()." AND msg_status = ".MESSAGE_STATUS_UNREAD;
$result = Database::query($query);
$i = Database::num_rows($result);
return $i;
if (Database::num_rows($result)) {
$result = Database::fetch_array($result);
return $result['count'];
};
return 0;
}
/**
@ -74,7 +63,7 @@ class MessageManager
/**
* Gets the total number of messages, used for the inbox sortable table
*/
public static function get_number_of_messages ($unread = false) {
public static function get_number_of_messages($unread = false) {
$table_message = Database::get_main_table(TABLE_MESSAGE);
$condition_msg_status = '';
@ -1216,11 +1205,10 @@ class MessageManager
//@todo this functions should be in the message class
static function inbox_display() {
global $charset;
$success = get_lang('SelectedMessagesDeleted');
$html = '';
if (isset ($_REQUEST['action'])) {
if (isset($_REQUEST['action'])) {
switch ($_REQUEST['action']) {
case 'delete' :
$number_of_selected_messages = count($_POST['id']);
@ -1239,13 +1227,12 @@ class MessageManager
// display sortable table with messages of the current user
$table = new SortableTable('message_inbox', array('MessageManager','get_number_of_messages'), array('MessageManager','get_message_data'),3,20,'DESC');
$table->set_header(0, '', false,array ('style' => 'width:15px;'));
$title=api_xml_http_response_encode(get_lang('Title'));
$action=api_xml_http_response_encode(get_lang('Modify'));
$table->set_header(1,api_xml_http_response_encode(get_lang('Messages')),false);
$table->set_header(2,api_xml_http_response_encode(get_lang('Date')),true, array('style' => 'width:180px;'));
$table->set_header(3,$action,false,array ('style' => 'width:70px;'));
if ($_REQUEST['f']=='social') {
$table->set_header(1,get_lang('Messages'),false);
$table->set_header(2,get_lang('Date'),true, array('style' => 'width:180px;'));
$table->set_header(3,get_lang('Modify'),false,array ('style' => 'width:70px;'));
if (isset($_REQUEST['f']) && $_REQUEST['f']=='social') {
$parameters['f'] = 'social';
$table->set_additional_parameters($parameters);
}

@ -46,12 +46,6 @@ class Template {
$hide_global_chat = $app['template.hide_global_chat'];
$load_plugins = $app['template.load_plugins'];
$cache_folder = api_get_path(SYS_ARCHIVE_PATH) . 'twig';
if (!is_dir($cache_folder)) {
mkdir($cache_folder, api_get_permissions_for_new_directories());
}
//Page title
$this->title = $title;
$this->show_learnpath = $show_learnpath;
@ -284,10 +278,10 @@ class Template {
if (api_is_platform_admin()) {
$user_info['is_admin'] = 1;
}
$user_info['messages_count'] = MessageManager::get_new_messages();
$user_info['messages_invitations_count'] = GroupPortalManager::get_groups_by_user_count($user_info['user_id'], GROUP_USER_PERMISSION_PENDING_INVITATION, false);
$new_messages = MessageManager::get_new_messages();
$user_info['messages_count'] = $new_messages != 0 ? Display::label($new_messages, 'warning') : null;
$messages_invitations_count = GroupPortalManager::get_groups_by_user_count($user_info['user_id'], GROUP_USER_PERMISSION_PENDING_INVITATION, false);
$user_info['messages_invitations_count'] = $messages_invitations_count != 0 ? Display::label($messages_invitations_count, 'warning') : null;
$this->user_is_logged_in = true;
}
//Setting the $_u array that could be use in any template
@ -299,7 +293,8 @@ class Template {
global $_configuration;
//Setting app paths/URLs
$_p = array('web' => api_get_path(WEB_PATH),
$_p = array(
'web' => api_get_path(WEB_PATH),
'web_course' => api_get_path(WEB_COURSE_PATH),
'web_main' => api_get_path(WEB_CODE_PATH),
'web_css' => api_get_path(WEB_CSS_PATH),
@ -455,18 +450,14 @@ class Template {
global $httpHeadXtra, $_course, $interbreadcrumb, $language_file, $_configuration, $this_section;
$nameTools = $this->title;
$navigation = $this->return_navigation_array();
$this->menu_navigation = $navigation['menu_navigation'];
$this->assign('system_charset', api_get_system_encoding());
if (isset($httpHeadXtra) && $httpHeadXtra) {
foreach ($httpHeadXtra as & $thisHttpHead) {
//header($thisHttpHead);
}
}
$this->assign('online_button', Display::return_icon('online.png'));
$this->assign('offline_button', Display::return_icon('offline.png'));
$this->assign('online_button', Security::remove_XSS(Display::return_icon('online.png')));
$this->assign('offline_button', Security::remove_XSS(Display::return_icon('offline.png')));
// Get language iso-code for this page - ignore errors
$this->assign('document_language', api_get_language_isocode());
@ -591,11 +582,6 @@ class Template {
$extra_header = trim(api_get_setting('header_extra_content'));
}
$this->assign('header_extra_content', $extra_header);
if ($this->show_header == 1) {
//header('Content-Type: text/html; charset=' . api_get_system_encoding());
//header('X-Powered-By: ' . $_configuration['software_name'] . ' ' . substr($_configuration['system_version'], 0, 1));
}
}
/**
@ -865,6 +851,7 @@ class Template {
$navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
$navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
// My Courses
if(api_is_allowed_to_create_course()) {
@ -902,23 +889,24 @@ class Template {
$navigation['session_my_progress']['title'] = get_lang('MyProgress');
}
// Social
if (api_get_setting('allow_social_tool')=='true') {
$navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
/*
// get count unread message and total invitations
$count_unread_message = MessageManager::get_number_of_messages(true);
$number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
$group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
$group_pending_invitations = 0;
if (!empty($group_pending_invitations )) {
$group_pending_invitations = count($group_pending_invitations);
}
$total_invitations = intval($number_of_new_messages_of_friend) + $group_pending_invitations + intval($count_unread_message);
$total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) :'');
$total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) :'');*/
$navigation['social']['title'] = get_lang('SocialNetwork'). $total_invitations;
$navigation['social']['title'] = get_lang('SocialNetwork');
}
// Dashboard
@ -1162,7 +1150,6 @@ class Template {
return $return;
}
function return_breadcrumb($interbreadcrumb, $language_file, $nameTools) {
$session_id = api_get_session_id();

@ -17,7 +17,6 @@
$language_file= array('messages','userInfo', 'admin');
$cidReset = true;
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
api_block_anonymous_users();
@ -25,13 +24,8 @@ if (api_get_setting('allow_message_tool') !='true') {
api_not_allowed();
}
require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
$nameTools = api_xml_http_response_encode(get_lang('Messages'));
/* Constants and variables */
$htmlHeadXtra[]='
<script language="javascript">
<script>
function validate(form,list) {
if(list.selectedIndex<0) {
alert("Please select someone to send the message to.")
@ -45,16 +39,18 @@ function validate(form,list) {
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = '<script type="text/javascript">
$htmlHeadXtra[] = '<script>
$(document).ready(function () {
$("#users").fcbkcomplete({
json_url: "'.api_get_path(WEB_AJAX_PATH).'message.ajax.php?a=find_users",
addontab: false,
cache: false,
filter_case: false,
filter_hide: true,
complete_text:"'.get_lang('StartToType').'",
firstselected: true,
//onremove: "testme",
onselect:"check_users",
filter_selected: true,
newel: true
@ -299,7 +295,7 @@ if ($group_id != 0) {
if (api_get_setting('allow_social_tool') == 'true') {
$social_left_content = SocialManager::show_social_menu('messages');
$social_right_content .= '<div class="span9">';
$social_right_content = '<div class="span9">';
$social_right_content .= '<div class="actions">';
$social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php?f=social">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>';
$social_right_content .= '</div>';
@ -356,7 +352,6 @@ if (api_get_setting('allow_social_tool') == 'true') {
$tpl = new Template(get_lang('ComposeMessage'));
if (api_get_setting('allow_social_tool') == 'true') {
$tpl->assign('social_left_content', $social_left_content);
$tpl->assign('social_left_menu', $social_left_menu);
$tpl->assign('social_right_content', $social_right_content);
$social_layout = $tpl->get_template('layout/social_layout.tpl');
$tpl->display($social_layout);

@ -62,11 +62,12 @@ function action_click(element, table_id) {
}
/* Global chat variables */
var ajax_url = '{{ _p.web_ajax }}chat.ajax.php';
var online_button = '{{ online_button }}';
var offline_button = '{{ offline_button }}';
var connect_lang = '{{ "ChatConnected"|get_lang }}';
var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';
var online_button = '{{ online_button |e('js') }}';
var offline_button = '{{ offline_button |e('js') }}';
var connect_lang = '{{ "ChatConnected"|get_lang |e('js') }}';
var disconnect_lang = '{{ "ChatDisconnected"|get_lang |e('js') }}';
function get_url_params(q, attribute) {
var vars;

@ -1,9 +1,9 @@
{% if menu is not null %}
<div class="navbar subnav">
<div class="navbar-inner">
<div class="container">
<a data-toggle="collapse" data-target=".nav-collapse" class="btn btn-navbar">
<a data-toggle="collapse" data-target=".nav-collapse" class="btn btn-navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@ -16,16 +16,16 @@
{% if _u.logged == 1 %}
<ul class="nav pull-right">
{% if user_notifications is not null %}
<li>
<a href="{{ profile_url }}">{{ user_notifications }}</a>
</li>
</li>
{% endif %}
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<img src="{{ _u.avatar_small }}"/>
{{ _u.messages_count }} <img src="{{ _u.avatar_small }}"/>
{{ _u.complete_name }}
<b class="caret"></b>
</a>
@ -38,9 +38,9 @@
<li>
<a id="logout_button" class="logout" title="{{ "Logout"|get_lang }}" href="{{ logout_link }}" >
<img src="{{ "exit.png"|icon(22) }}">
<img src="{{ "exit.png"|icon(22) }}">
</a>
</li>
</li>
</ul>
{% endif %}
</div>

@ -2,13 +2,13 @@
{% if show_toolbar == 1 %}
<div id="topbar" class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<div class="container">
<a class="brand" href="{{ _p.web }}">
{{ "siteName" | get_setting }}
</a>
{% if _u.logged %}
<div class="nav-collapse">
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="{{ _p.web }}user_portal.php"> {{ "MyCourses"|get_lang }}</a></li>
{#
@ -56,18 +56,18 @@
</li>
{% endif %}
</ul>
{% if _u.is_admin == 1 %}
<form class="navbar-search pull-left" action="{{ _p.web_main }}admin/user_list.php" method="get">
<input type="text" class="search-query span2" placeholder="{{'SearchUsers'|get_lang }}" name="keyword">
</form>
{% endif %}
<ul class="nav pull-right">
<li><a href="{{ _p.web_main }}social/home.php"><img src="{{ _u.avatar_small }}"/></a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ _u.complete_name }}<b class="caret"></b></a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ _u.complete_name }}<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="{{ _p.web_main }}social/home.php">{{ "Profile"|get_lang }}</a></li>
<li><a href="{{ _p.web_main }}calendar/agenda_js.php?type=personal">{{ "MyAgenda"|get_lang }}</a></li>
@ -80,7 +80,7 @@
<li><a href="{{ _p.web }}index.php?logout=logout">{{ "Logout"|get_lang }}</a></li>
</ul>
</div> <!-- /nav collapse -->
{% endif %}
{% endif %}
</div> <!-- /container-fluid-->
</div><!-- /navbar-inner -->
</div><!-- /topbar -->

Loading…
Cancel
Save