/** * Builds account settings for logged users * * @access public * @return string XHTML content */ function MyAccount() { $this->gadget->CheckPermission('EditUserName,EditUserNickname,EditUserEmail,EditUserPassword', false); $uModel = new Jaws_User(); $uInfo = $uModel->GetUser($GLOBALS['app']->Session->GetAttribute('user'), true, true); if (Jaws_Error::IsError($uInfo) || empty($uInfo)) { return false; } $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('MyAccount.html'); $tpl->SetBlock('MyAccount'); $tpl->SetVariable('uid', $uInfo['id']); $tpl->SetVariable('legend_title', _t('USERS_USERS_ACCOUNT')); $JCrypt = Jaws_Crypt::getInstance(); if (!Jaws_Error::IsError($JCrypt)) { $GLOBALS['app']->Layout->AddScriptLink('libraries/js/rsa.lib.js'); $tpl->SetBlock('MyAccount/encryption'); // key length $length =& Piwi::CreateWidget('HiddenEntry', 'length', $JCrypt->length()); $length->SetID('length'); $tpl->SetVariable('length', $length->Get()); // modulus $modulus =& Piwi::CreateWidget('HiddenEntry', 'modulus', $JCrypt->modulus()); $modulus->SetID('modulus'); $tpl->SetVariable('modulus', $modulus->Get()); //exponent $exponent =& Piwi::CreateWidget('HiddenEntry', 'exponent', $JCrypt->exponent()); $modulus->SetID('exponent'); $tpl->SetVariable('exponent', $exponent->Get()); $tpl->ParseBlock('MyAccount/encryption'); } // username $username =& Piwi::CreateWidget('Entry', 'username', $uInfo['username']); $username->SetID('username'); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $username->Get()); // nickname $nickname =& Piwi::CreateWidget('Entry', 'nickname', $uInfo['nickname']); $nickname->SetID('nickname'); $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME')); $tpl->SetVariable('nickname', $nickname->Get()); // email $email =& Piwi::CreateWidget('Entry', 'email', $uInfo['email']); $email->SetID('email'); $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL')); $tpl->SetVariable('email', $email->Get()); // pass1 $pass1 =& Piwi::CreateWidget('PasswordEntry', 'pass1', ''); $pass1->SetID('pass1'); $tpl->SetVariable('lbl_pass1', _t('USERS_USERS_PASSWORD')); $tpl->SetVariable('pass1', $pass1->Get()); // pass2 $pass2 =& Piwi::CreateWidget('PasswordEntry', 'pass2', ''); $pass2->SetID('pass2'); $tpl->SetVariable('lbl_pass2', _t('USERS_USERS_PASSWORD_VERIFY')); $tpl->SetVariable('pass2', $pass2->Get()); $avatar =& Piwi::CreateWidget('Image', $uModel->GetAvatar($uInfo['avatar'], $uInfo['email'], 128, $uInfo['last_update']), $uInfo['username']); $avatar->SetID('avatar'); $tpl->SetVariable('avatar', $avatar->Get()); $btnSave =& Piwi::CreateWidget('Button', 'SubmitButton', _t('GLOBAL_UPDATE'), STOCK_SAVE); $btnSave->AddEvent(ON_CLICK, "javascript: updateMyAccount();"); $tpl->SetVariable('save', $btnSave->Get()); $tpl->SetVariable('incompleteUserFields', _t('USERS_MYACCOUNT_INCOMPLETE_FIELDS')); $tpl->SetVariable('wrongPassword', _t('USERS_MYACCOUNT_PASSWORDS_DONT_MATCH')); $tpl->ParseBlock('MyAccount'); return $tpl->Get(); }
/** * Display Compose page * * @access public * @return string XHTML template content */ function Compose() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(401); } $this->gadget->CheckPermission('SendMessage'); $user = $GLOBALS['app']->Session->GetAttribute('user'); $this->AjaxMe('site_script.js'); $data = jaws()->request->fetch(array('id', 'user', 'reply', 'users:array')); $id = $data['id']; $userModel = new Jaws_User(); $model = $this->gadget->model->load('Message'); $tpl = $this->gadget->template->load('Compose.html'); $tpl->SetBlock('compose'); // Menubar $tpl->SetVariable('menubar', $this->MenuBar('Compose')); $body_value = ""; $recipient_users = array(); $recipient_groups = array(); $show_recipient = true; // draft or reply if (!empty($id)) { $message = $model->GetMessage($id, true, false); // Check permissions if (!($message['from'] == $user && $message['to'] == 0) && $message['to'] != $user) { return Jaws_HTTPError::Get(403); } // open draft if (empty($data['reply'])) { // Check draft status if ($message['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_DRAFT) { return Jaws_HTTPError::Get(404); } $tpl->SetVariable('title', _t('PRIVATEMESSAGE_COMPOSE_MESSAGE')); $tpl->SetVariable('id', $id); $recipient_users = array_map('intval', explode(',', $message['recipient_users'])); $recipient_groups = array_map('intval', explode(',', $message['recipient_groups'])); $body_value = $message['body']; $tpl->SetVariable('subject', $message['subject']); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); $tpl->SetVariable('attachment_ui', $this->GetMessageAttachmentUI($id)); // reply a message } else { if (!empty($data['reply']) && $data['reply'] == 'true') { $date_format = $this->gadget->registry->fetch('date_format'); $date = Jaws_Date::getInstance(); $usrModel = new Jaws_User(); $show_recipient = false; $body_value = '[quote]' . $message['body'] . "[/quote]\r\n"; // show parent message $tpl->SetBlock('compose/parent_message'); $tpl->SetBlock('compose/parent_message/message'); $tpl->SetVariable('confirmDelete', _t('PRIVATEMESSAGE_MESSAGE_CONFIRM_DELETE')); $tpl->SetVariable('lbl_from', _t('PRIVATEMESSAGE_MESSAGE_FROM')); $tpl->SetVariable('lbl_send_time', _t('PRIVATEMESSAGE_MESSAGE_SEND_TIME')); $tpl->SetVariable('lbl_subject', _t('PRIVATEMESSAGE_MESSAGE_SUBJECT')); $tpl->SetVariable('lbl_body', _t('PRIVATEMESSAGE_MESSAGE_BODY')); $tpl->SetVariable('from', $message['from_nickname']); $tpl->SetVariable('username', $message['from_username']); $tpl->SetVariable('nickname', $message['from_nickname']); $tpl->SetVariable('send_time', $date->Format($message['insert_time'], $date_format)); $tpl->SetVariable('subject', $message['subject']); $tpl->SetVariable('body', $message['body']); // user's avatar $tpl->SetVariable('avatar', $usrModel->GetAvatar($message['avatar'], $message['email'], 80)); // user's profile $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $message['from_username']))); if (!empty($message['attachments'])) { $tpl->SetBlock('compose/parent_message/message/attachment'); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); foreach ($message['attachments'] as $file) { $tpl->SetBlock('compose/parent_message/message/attachment/file'); $tpl->SetVariable('lbl_file_size', _t('PRIVATEMESSAGE_MESSAGE_FILE_SIZE')); $tpl->SetVariable('file_name', $file['title']); $tpl->SetVariable('file_size', Jaws_Utils::FormatSize($file['filesize'])); $tpl->SetVariable('file_download_link', $file['title']); $file_url = $this->gadget->urlMap('Attachment', array('uid' => $message['to'], 'mid' => $message['id'], 'aid' => $file['id'])); $tpl->SetVariable('file_download_link', $file_url); $tpl->ParseBlock('compose/parent_message/message/attachment/file'); } $tpl->ParseBlock('compose/parent_message/message/attachment'); } $tpl->ParseBlock('compose/parent_message/message'); $tpl->ParseBlock('compose/parent_message'); // $tpl->SetVariable('parent', $id); $tpl->SetVariable('title', _t('PRIVATEMESSAGE_REPLY')); $tpl->SetVariable('subject', _t('PRIVATEMESSAGE_REPLY_ON', $message['subject'])); $tpl->SetVariable('recipient_user', $message['from']); $recipient_users = array($message['from']); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); $tpl->SetVariable('attachment_ui', $this->GetMessageAttachmentUI($id, false)); // forward a message } else { if (!empty($data['reply']) && $data['reply'] == 'false') { $tpl->SetVariable('title', _t('PRIVATEMESSAGE_FORWARD_MESSAGE')); $body_value = $message['body']; $tpl->SetVariable('subject', _t('PRIVATEMESSAGE_FORWARD_ABBREVIATION') . ' ' . $message['subject']); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); $tpl->SetVariable('attachment_ui', $this->GetMessageAttachmentUI($id)); } } } } else { if (!empty($data['users'])) { $recipient_users = $data['users']; } else { if (!empty($data['user'])) { $recipient_users = array($data['user']); } } $tpl->SetVariable('title', _t('PRIVATEMESSAGE_COMPOSE_MESSAGE')); $tpl->SetVariable('attachment_ui', $this->GetMessageAttachmentUI()); } $body =& $GLOBALS['app']->LoadEditor('PrivateMessage', 'body', $body_value); $body->TextArea->SetRows(8); $body->setID('body'); $body->SetWidth('100%'); $tpl->SetVariable('body', $body->Get()); if ($show_recipient) { $tpl->SetBlock('compose/recipients'); $tpl->SetVariable('lbl_recipient', _t('PRIVATEMESSAGE_MESSAGE_RECIPIENTS')); $tpl->SetVariable('lbl_recipient_users', _t('PRIVATEMESSAGE_MESSAGE_RECIPIENT_USERS')); if (!empty($recipient_users)) { foreach ($recipient_users as $userId) { $user_info = $userModel->GetUser($userId, true); $tpl->SetBlock('compose/recipients/user'); $tpl->SetVariable('title', $user_info['nickname']); $tpl->SetVariable('value', $user_info['id']); $tpl->ParseBlock('compose/recipients/user'); } } // Group List $bGroups =& Piwi::CreateWidget('Combo', 'recipient_groups'); $bGroups->SetID('recipient_groups'); $bGroups->setMultiple(true); $groups = $userModel->GetGroups($user, true); foreach ($groups as $group) { $bGroups->AddOption($group['title'], $group['id']); } $bGroups->setDefault($recipient_groups); $tpl->SetVariable('lbl_recipient_groups', _t('PRIVATEMESSAGE_MESSAGE_RECIPIENT_GROUPS')); $tpl->SetVariable('recipient_groups_opt', $bGroups->Get()); $tpl->ParseBlock('compose/recipients'); } else { $tpl->SetBlock('compose/recipient'); $tpl->SetVariable('lbl_recipient', _t('PRIVATEMESSAGE_MESSAGE_RECIPIENTS')); $user_info = $userModel->GetUser($recipient_users[0]); // user's profile $tpl->SetVariable('recipient_user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $user_info['username']))); $tpl->SetVariable('recipient_user', $user_info['nickname']); $tpl->ParseBlock('compose/recipient'); } $tpl->SetVariable('lbl_subject', _t('PRIVATEMESSAGE_MESSAGE_SUBJECT')); $tpl->SetVariable('lbl_body', _t('PRIVATEMESSAGE_MESSAGE_BODY')); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); $tpl->SetVariable('lbl_save_draft', _t('PRIVATEMESSAGE_SAVE_DRAFT')); $tpl->SetVariable('lbl_send', _t('PRIVATEMESSAGE_SEND')); $tpl->SetVariable('lbl_back', _t('PRIVATEMESSAGE_BACK')); $tpl->SetVariable('lbl_file', _t('PRIVATEMESSAGE_FILE')); $tpl->SetVariable('lbl_add_file', _t('PRIVATEMESSAGE_ADD_ANOTHER_FILE')); $tpl->SetVariable('back_url', $this->gadget->urlMap('Messages', array('folder' => PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_INBOX))); $tpl->SetVariable('icon_add', STOCK_ADD); $tpl->SetVariable('icon_remove', STOCK_REMOVE); $tpl->ParseBlock('compose'); return $tpl->Get(); }
/** * Builds user information page include (personal, contact, ... information) * * @access public * @return string XHTML template content */ function Profile() { $user = jaws()->request->fetch('user', 'get'); if (empty($user)) { return Jaws_HTTPError::Get(404); } $usrModel = new Jaws_User(); $user = $usrModel->GetUser($user, true, true, true); if (Jaws_Error::IsError($user) || empty($user)) { return Jaws_HTTPError::Get(404); } // Avatar $user['avatar'] = $usrModel->GetAvatar($user['avatar'], $user['email'], 128, $user['last_update']); // Gender $user['gender'] = _t('USERS_USERS_GENDER_' . $user['gender']); // Date of birth $objDate = Jaws_Date::getInstance(); $user['dob'] = $objDate->Format($user['dob'], 'd MN Y'); if (!empty($user['registered_date'])) { $user['registered_date'] = $objDate->Format($user['registered_date'], 'd MN Y'); } else { $user['registered_date'] = ''; } // Load the template $tpl = $this->gadget->template->load('Profile.html'); $tpl->SetBlock('profile'); $tpl->SetVariable('title', _t('USERS_PROFILE_INFO')); $tpl->SetVariable('menubar', $this->MenuBar('Profile')); $tpl->SetVariable('submenubar', $this->SubMenuBar('Profile', array('Profile', 'Account', 'Personal', 'Preferences', 'Contacts'))); $tpl->SetVariable('avatar', $user['avatar']); // username $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $user['username']); // nickname $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME')); $tpl->SetVariable('nickname', $user['nickname']); // registered_date $tpl->SetVariable('lbl_registered_date', _t('USERS_USERS_REGISTRATION_DATE')); $tpl->SetVariable('registered_date', $user['registered_date']); // auto paragraph content $user['about'] = Jaws_String::AutoParagraph($user['about']); $user = $user + array('lbl_private' => _t('USERS_USERS_PRIVATE'), 'lbl_fname' => _t('USERS_USERS_FIRSTNAME'), 'lbl_lname' => _t('USERS_USERS_LASTNAME'), 'lbl_gender' => _t('USERS_USERS_GENDER'), 'lbl_ssn' => _t('USERS_USERS_SSN'), 'lbl_dob' => _t('USERS_USERS_BIRTHDAY'), 'lbl_public' => _t('USERS_USERS_PUBLIC'), 'lbl_url' => _t('GLOBAL_URL'), 'lbl_about' => _t('USERS_USERS_ABOUT'), 'lbl_experiences' => _t('USERS_USERS_EXPERIENCES'), 'lbl_occupations' => _t('USERS_USERS_OCCUPATIONS'), 'lbl_interests' => _t('USERS_USERS_INTERESTS')); if (!$GLOBALS['app']->Session->IsSuperAdmin() && $GLOBALS['app']->Session->GetAttribute('user') != $user['id']) { $user['ssn'] = _t('GLOBAL_ERROR_ACCESS_DENIED'); } // set about item data $tpl->SetVariablesArray($user); if ($user['public'] || $GLOBALS['app']->Session->Logged()) { $tpl->SetBlock('profile/public'); // set profile item data $tpl->SetVariablesArray($user); if (!empty($user['url'])) { $tpl->SetBlock('profile/public/website'); $tpl->SetVariable('url', $user['url']); $tpl->ParseBlock('profile/public/website'); } $tpl->ParseBlock('profile/public'); } $tpl->SetBlock('profile/activity'); $tpl->SetVariable('lbl_activities', _t('USERS_USER_ACTIVITIES')); $this->Activity($tpl, $user['id'], $user['username']); $tpl->ParseBlock('profile/activity'); $tpl->ParseBlock('profile'); return $tpl->Get(); }
/** * Get the comments messages list * * @access public * @return string XHTML template content */ function GetMessages() { $rqst = jaws()->request->fetch(array('order', 'perpage', 'page'), 'get'); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; if (!empty($rqst['perpage'])) { $perPage = (int) $rqst['perpage']; $orderBy = (int) $rqst['order']; } else { $perPage = $this->gadget->registry->fetch('comments_per_page'); $orderBy = 0; } $model = $this->gadget->model->load('Comments'); $comments = $model->GetComments($this->gadget->name, '', '', '', array(Comments_Info::COMMENTS_STATUS_APPROVED), $perPage, ($page - 1) * $perPage, $orderBy); $comments_count = $model->GetCommentsCount($this->gadget->name, '', '', '', array(Comments_Info::COMMENTS_STATUS_APPROVED)); $tpl = $this->gadget->template->load('Comments.html'); $tpl->SetBlock('comments'); $tpl->SetVariable('gadget', strtolower($this->gadget->name)); $objDate = Jaws_Date::getInstance(); $usrModel = new Jaws_User(); if (!Jaws_Error::IsError($comments) && $comments != null) { foreach ($comments as $entry) { $tpl->SetBlock('comments/entry'); $tpl->SetVariable('postedby_lbl', _t('COMMENTS_POSTEDBY')); if ($entry['user_registered_date']) { $tpl->SetBlock('comments/entry/registered_date'); $tpl->SetVariable('registered_date_lbl', _t('COMMENTS_USERS_REGISTERED_DATE')); $tpl->SetVariable('registered_date', $objDate->Format($entry['user_registered_date'], 'd MN Y')); $tpl->ParseBlock('comments/entry/registered_date'); } if (!empty($entry['username'])) { // user's profile $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $entry['username']))); } else { $tpl->SetVariable('user_url', Jaws_XSS::filter($entry['url'])); } $nickname = empty($entry['nickname']) ? $entry['name'] : $entry['nickname']; $email = empty($entry['user_email']) ? $entry['email'] : $entry['user_email']; $tpl->SetVariable('nickname', Jaws_XSS::filter($nickname)); $tpl->SetVariable('email', Jaws_XSS::filter($email)); $tpl->SetVariable('username', Jaws_XSS::filter($entry['username'])); // user's avatar $tpl->SetVariable('avatar', $usrModel->GetAvatar($entry['avatar'], $entry['email'], 80)); $tpl->SetVariable('insert_time', $objDate->Format($entry['createtime'])); $tpl->SetVariable('insert_time_iso', $objDate->ToISO($entry['createtime'])); $tpl->SetVariable('message', Jaws_String::AutoParagraph($entry['msg_txt'])); $tpl->ParseBlock('comments/entry'); } } // page navigation $this->GetPagesNavigation($tpl, 'comments', $page, $perPage, $comments_count, _t('COMMENTS_COMMENTS_COUNT', $comments_count), 'Comments', array('perpage' => $perPage, 'order' => $orderBy)); $tpl->ParseBlock('comments'); return $tpl->Get(); }
/** * Display a message Info * * @access public * @return string XHTML template content */ function Message() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(401); } $id = jaws()->request->fetch('id', 'get'); $date = Jaws_Date::getInstance(); $model = $this->gadget->model->load('Message'); $user = $GLOBALS['app']->Session->GetAttribute('user'); $usrModel = new Jaws_User(); $message = $model->GetMessage($id, true); if (empty($message)) { return Jaws_HTTPError::Get(404); } // Check permissions if (!($message['from'] == $user && $message['to'] == 0) && $message['to'] != $user) { return Jaws_HTTPError::Get(403); } // Detect message folder if ($message['from'] == $user && $message['to'] != $user) { $folder = PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_OUTBOX; } else { $folder = PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_INBOX; } if ($folder == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_INBOX && $message['read'] == false) { $user = $GLOBALS['app']->Session->GetAttribute('user'); $model->MarkMessages($id, true, $user); } $date_format = $this->gadget->registry->fetch('date_format'); $tpl = $this->gadget->template->load('Message.html'); $tpl->SetBlock('message'); $tpl->SetVariable('id', $id); $tpl->SetBlock('message'); $tpl->SetVariable('confirmTrash', _t('PRIVATEMESSAGE_MESSAGE_CONFIRM_TRASH')); $tpl->SetVariable('confirmDelete', _t('PRIVATEMESSAGE_MESSAGE_CONFIRM_DELETE')); $tpl->SetVariable('lbl_from', _t('PRIVATEMESSAGE_MESSAGE_FROM')); $tpl->SetVariable('lbl_send_time', _t('PRIVATEMESSAGE_MESSAGE_SEND_TIME')); $tpl->SetVariable('lbl_subject', _t('PRIVATEMESSAGE_MESSAGE_SUBJECT')); $tpl->SetVariable('lbl_body', _t('PRIVATEMESSAGE_MESSAGE_BODY')); $tpl->SetVariable('from', $message['from_nickname']); $tpl->SetVariable('username', $message['from_username']); $tpl->SetVariable('nickname', $message['from_nickname']); $tpl->SetVariable('send_time', $date->Format($message['insert_time'], $date_format)); $tpl->SetVariable('subject', $message['subject']); $tpl->SetVariable('body', $this->gadget->ParseText($message['body'], 'PrivateMessage', 'index')); $tpl->SetVariable('trash_url', $this->gadget->urlMap('TrashMessage', array('id' => $id))); $tpl->SetVariable('delete_url', $this->gadget->urlMap('DeleteMessage', array('id' => $id))); // user's avatar $tpl->SetVariable('avatar', $usrModel->GetAvatar($message['avatar'], $message['email'], 80)); // user's profile $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $message['from_username']))); if (!empty($message['attachments'])) { $tpl->SetBlock('message/attachment'); $tpl->SetVariable('lbl_attachments', _t('PRIVATEMESSAGE_MESSAGE_ATTACHMENTS')); foreach ($message['attachments'] as $file) { $tpl->SetBlock('message/attachment/file'); $tpl->SetVariable('lbl_file_size', _t('PRIVATEMESSAGE_MESSAGE_FILE_SIZE')); $tpl->SetVariable('file_name', $file['title']); $tpl->SetVariable('file_size', Jaws_Utils::FormatSize($file['filesize'])); $tpl->SetVariable('file_download_link', $file['title']); $file_url = $this->gadget->urlMap('Attachment', array('uid' => $user, 'mid' => $message['id'], 'aid' => $file['id'])); $tpl->SetVariable('file_download_link', $file_url); $tpl->ParseBlock('message/attachment/file'); } $tpl->ParseBlock('message/attachment'); } if ($message['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_TRASH) { $tpl->SetBlock('message/archive'); if ($message['folder'] == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_ARCHIVED) { $tpl->SetVariable('icon_archive', 'gadgets/PrivateMessage/Resources/images/unarchive-mini.png'); $tpl->SetVariable('archive', _t('PRIVATEMESSAGE_UNARCHIVE')); $tpl->SetVariable('archive_url', $this->gadget->urlMap('UnArchiveMessage', array('id' => $id))); } else { $tpl->SetVariable('icon_archive', 'gadgets/PrivateMessage/Resources/images/archive-mini.png'); $tpl->SetVariable('archive', _t('PRIVATEMESSAGE_ARCHIVE')); $tpl->SetVariable('archive_url', $this->gadget->urlMap('ArchiveMessage', array('id' => $id))); } $tpl->ParseBlock('message/archive'); } if ($message['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_DRAFT && $message['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_TRASH) { if ($folder == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_INBOX) { $tpl->SetBlock('message/reply'); $tpl->SetVariable('reply_url', $this->gadget->urlMap('Compose', array('id' => $message['id'], 'reply' => 'true'))); $tpl->SetVariable('icon_reply', 'gadgets/PrivateMessage/Resources/images/reply-mini.png'); $tpl->SetVariable('reply', _t('PRIVATEMESSAGE_REPLY')); $tpl->ParseBlock('message/reply'); } $tpl->SetBlock('message/forward'); $tpl->SetVariable('forward_url', $this->gadget->urlMap('Compose', array('id' => $message['id'], 'reply' => 'false'))); $tpl->SetVariable('icon_forward', 'gadgets/PrivateMessage/Resources/images/forward-mini.png'); $tpl->SetVariable('forward', _t('PRIVATEMESSAGE_FORWARD')); $tpl->ParseBlock('message/forward'); } if ($message['folder'] != PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_TRASH) { $tpl->SetBlock('message/trash'); $tpl->SetVariable('icon_trash', 'gadgets/PrivateMessage/Resources/images/trash-mini.png'); $tpl->SetVariable('trash', _t('PRIVATEMESSAGE_TRASH')); $tpl->ParseBlock('message/trash'); } if ($message['folder'] == PrivateMessage_Info::PRIVATEMESSAGE_FOLDER_TRASH) { $tpl->SetBlock('message/restore_trash'); $tpl->SetVariable('restore_trash_url', $this->gadget->urlMap('RestoreTrashMessage', array('id' => $id))); $tpl->SetVariable('icon_restore_trash', ''); $tpl->SetVariable('restore_trash', _t('PRIVATEMESSAGE_RESTORE_TRASH')); $tpl->ParseBlock('message/restore_trash'); $tpl->SetBlock('message/delete'); $tpl->SetVariable('icon_delete', STOCK_DELETE); $tpl->SetVariable('delete', _t('GLOBAL_DELETE')); $tpl->ParseBlock('message/delete'); } $tpl->SetBlock('message/back'); $tpl->SetVariable('back_url', $this->gadget->urlMap('Messages')); $tpl->SetVariable('icon_back', 'gadgets/PrivateMessage/Resources/images/back-mini.png'); $tpl->SetVariable('back', _t('PRIVATEMESSAGE_BACK')); $tpl->ParseBlock('message/back'); $tpl->ParseBlock('message'); return $tpl->Get(); }
/** * Display topic posts * * @access public * @return string XHTML template content */ function Posts() { $rqst = jaws()->request->fetch(array('fid', 'tid', 'page'), 'get'); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; $tModel = $this->gadget->model->load('Topics'); $topic = $tModel->GetTopic($rqst['tid'], $rqst['fid']); if (Jaws_Error::IsError($topic)) { return Jaws_HTTPError::Get($topic->getCode()); } if (!$topic['published']) { $logged_user = (int) $GLOBALS['app']->Session->GetAttribute('user'); if ($logged_user != $topic['first_post_uid'] && !$this->gadget->GetPermission('ForumManage', $rqst['fid'])) { return Jaws_HTTPError::Get(403); } } $limit = (int) $this->gadget->registry->fetch('posts_limit'); $pModel = $this->gadget->model->load('Posts'); $posts = $pModel->GetPosts($rqst['tid'], $limit, ($page - 1) * $limit); if (Jaws_Error::IsError($posts)) { return false; } $res = $tModel->UpdateTopicViews($topic['id']); if (Jaws_Error::IsError($res)) { // do nothing } $tpl = $this->gadget->template->load('Posts.html'); $tpl->SetBlock('posts'); $tpl->SetVariable('findex_title', _t('FORUMS_FORUMS')); $tpl->SetVariable('findex_url', $this->gadget->urlMap('Forums')); $tpl->SetVariable('forum_title', $topic['forum_title']); $tpl->SetVariable('forum_url', $this->gadget->urlMap('Topics', array('fid' => $topic['fid']))); $tpl->SetVariable('title', $topic['subject']); $tpl->SetVariable('url', $this->gadget->urlMap('Posts', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); // display subscription if installed if (Jaws_Gadget::IsGadgetInstalled('Subscription')) { $sHTML = Jaws_Gadget::getInstance('Subscription')->action->load('Subscription'); $tpl->SetVariable('subscription', $sHTML->ShowSubscription('Forums', 'Topic', $rqst['tid'])); } // date format $date_format = $this->gadget->registry->fetch('date_format'); $date_format = empty($date_format) ? 'DN d MN Y' : $date_format; // edit max/min limit time $edit_max_limit_time = (int) $this->gadget->registry->fetch('edit_max_limit_time'); $edit_min_limit_time = (int) $this->gadget->registry->fetch('edit_min_limit_time'); $objDate = Jaws_Date::getInstance(); $usrModel = new Jaws_User(); $startPostNumber = $limit * ($page - 1); $forumManage = $this->gadget->GetPermission('ForumManage', $topic['fid']); foreach ($posts as $pnum => $post) { $tpl->SetBlock('posts/post'); $startPostNumber++; $tpl->SetVariable('post_number', $startPostNumber); $tpl->SetVariable('title', $topic['subject']); $tpl->SetVariable('posts_count_lbl', _t('FORUMS_USERS_POSTS_COUNT')); $tpl->SetVariable('registered_date_lbl', _t('FORUMS_USERS_REGISTERED_DATE')); $tpl->SetVariable('postedby_lbl', _t('FORUMS_POSTEDBY')); $tpl->SetVariable('posts_count', $pModel->GetUserPostsCount($post['uid'])); $tpl->SetVariable('user_posts', $this->gadget->urlMap('UserPosts', array('user' => $post['username']))); $tpl->SetVariable('registered_date', $objDate->Format($post['user_registered_date'], 'd MN Y')); $tpl->SetVariable('insert_time', $objDate->Format($post['insert_time'], $date_format)); $tpl->SetVariable('insert_time_iso', $objDate->ToISO((int) $post['insert_time'])); $tpl->SetVariable('post_id', $post['id']); $tpl->SetVariable('message', $this->gadget->ParseText($post['message'], 'Forums', 'index')); $tpl->SetVariable('username', $post['username']); $tpl->SetVariable('nickname', $post['nickname']); // user's avatar $tpl->SetVariable('avatar', $usrModel->GetAvatar($post['avatar'], $post['email'], 80, $post['user_last_update'])); // user's profile $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $post['username']))); // attachment if ($post['attachments'] > 0) { $aModel = $this->gadget->model->load('Attachments'); $attachments = $aModel->GetAttachments($post['id']); foreach ($attachments as $attachment) { $tpl->SetBlock('posts/post/attachment'); $tpl->SetVariable('user_fname', $attachment['title']); $tpl->SetVariable('lbl_attachment', _t('FORUMS_POSTS_ATTACHMENT')); $tpl->SetVariable('hitcount', _t('FORUMS_POSTS_ATTACHMENT_HITS', $attachment['hitcount'])); $tpl->SetVariable('url_attachment', $this->gadget->urlMap('Attachment', array('fid' => $rqst['fid'], 'tid' => $rqst['tid'], 'pid' => $post['id'], 'attach' => $attachment['id']))); $tpl->ParseBlock('posts/post/attachment'); } } // update information if ($post['update_uid'] != 0) { $tpl->SetBlock('posts/post/update'); $tpl->SetVariable('updatedby_lbl', _t('FORUMS_POSTS_UPDATEDBY')); $tpl->SetVariable('username', $post['updater_username']); $tpl->SetVariable('nickname', $post['updater_nickname']); $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $post['updater_username']))); $tpl->SetVariable('update_time', $objDate->Format($post['update_time'], $date_format)); $tpl->SetVariable('update_time_iso', $objDate->ToISO($post['update_time'])); if (!empty($post['update_reason'])) { $tpl->SetBlock('posts/post/update/reason'); $tpl->SetVariable('lbl_update_reason', _t('FORUMS_POSTS_EDIT_REASON')); $tpl->SetVariable('update_reason', $post['update_reason']); $tpl->ParseBlock('posts/post/update/reason'); } $tpl->ParseBlock('posts/post/update'); } // reply: check permission for add post if ($this->gadget->GetPermission('AddPost') && (!$topic['locked'] || $forumManage)) { $tpl->SetBlock('posts/post/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_POSTS_REPLY')); $tpl->SetVariable('action_title', _t('FORUMS_POSTS_REPLY_TITLE')); $tpl->SetVariable('action_url', $this->gadget->urlMap('ReplyPost', array('fid' => $rqst['fid'], 'tid' => $rqst['tid'], 'pid' => $post['id']))); $tpl->ParseBlock('posts/post/action'); } if ($topic['first_post_id'] == $post['id']) { // check permission for edit topic if ($this->gadget->GetPermission('EditTopic') && ($post['uid'] == (int) $GLOBALS['app']->Session->GetAttribute('user') || $forumManage) && (!$topic['locked'] || $forumManage) && (time() - $post['insert_time'] <= $edit_max_limit_time || $forumManage)) { $tpl->SetBlock('posts/post/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_TOPICS_EDIT')); $tpl->SetVariable('action_title', _t('FORUMS_TOPICS_EDIT_TITLE')); $tpl->SetVariable('action_url', $this->gadget->urlMap('EditTopic', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); $tpl->ParseBlock('posts/post/action'); } // check permission for delete topic if ($this->gadget->GetPermission('DeleteTopic') && ($post['uid'] == (int) $GLOBALS['app']->Session->GetAttribute('user') || $forumManage) && (time() - $post['insert_time'] <= $edit_min_limit_time || $forumManage)) { $tpl->SetBlock('posts/post/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_TOPICS_DELETE')); $tpl->SetVariable('action_title', _t('FORUMS_TOPICS_DELETE_TITLE')); $tpl->SetVariable('action_url', $this->gadget->urlMap('DeleteTopic', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); $tpl->ParseBlock('posts/post/action'); } } else { // check permission for edit post if ($this->gadget->GetPermission('EditPost') && ($post['uid'] == (int) $GLOBALS['app']->Session->GetAttribute('user') || $forumManage) && (!$topic['locked'] || $forumManage) && (time() - $post['insert_time'] <= $edit_max_limit_time || $forumManage)) { $tpl->SetBlock('posts/post/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_POSTS_EDIT')); $tpl->SetVariable('action_title', _t('FORUMS_POSTS_EDIT_TITLE')); $tpl->SetVariable('action_url', $this->gadget->urlMap('EditPost', array('fid' => $rqst['fid'], 'tid' => $rqst['tid'], 'pid' => $post['id']))); $tpl->ParseBlock('posts/post/action'); } // check permission for delete post if ($this->gadget->GetPermission('DeletePost') && ($post['uid'] == (int) $GLOBALS['app']->Session->GetAttribute('user') || $forumManage) && (!$topic['locked'] || $forumManage) && (time() - $post['insert_time'] <= $edit_min_limit_time || $forumManage)) { $tpl->SetBlock('posts/post/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_POSTS_DELETE')); $tpl->SetVariable('action_title', _t('FORUMS_POSTS_DELETE_TITLE')); $tpl->SetVariable('action_url', $this->gadget->urlMap('DeletePost', array('fid' => $rqst['fid'], 'tid' => $rqst['tid'], 'pid' => $post['id']))); $tpl->ParseBlock('posts/post/action'); } } $tpl->ParseBlock('posts/post'); } // foreach posts // page navigation $this->GetPagesNavigation($tpl, 'posts', $page, $limit, $topic['replies'], _t('FORUMS_POSTS_COUNT', $topic['replies']), 'Posts', array('fid' => $topic['fid'], 'tid' => $topic['id'])); // check permission to add new post if ($this->gadget->GetPermission('AddPost') && (!$topic['locked'] || $forumManage)) { $tpl->SetBlock('posts/action'); $tpl->SetVariable('action_lbl', _t('FORUMS_POSTS_NEW')); $tpl->SetVariable('action_url', $this->gadget->urlMap('NewPost', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); $tpl->ParseBlock('posts/action'); } // check permission to lock/unlock topic if ($forumManage) { $tpl->SetBlock('posts/action'); $tpl->SetVariable('action_lbl', $topic['locked'] ? _t('FORUMS_TOPICS_UNLOCK') : _t('FORUMS_TOPICS_LOCK')); $tpl->SetVariable('action_url', $this->gadget->urlMap('LockTopic', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); $tpl->ParseBlock('posts/action'); } // check permission to publish/draft topic if ($this->gadget->GetPermission('PublishTopic') && $forumManage) { $tpl->SetBlock('posts/action'); $tpl->SetVariable('action_lbl', $topic['published'] ? _t('FORUMS_TOPICS_DRAFT') : _t('FORUMS_TOPICS_PUBLISH')); $tpl->SetVariable('action_url', $this->gadget->urlMap('PublishTopic', array('fid' => $rqst['fid'], 'tid' => $rqst['tid']))); $tpl->ParseBlock('posts/action'); } $tpl->ParseBlock('posts'); return $tpl->Get(); }