/** * Updates contacts information of the user * * @access public * @param int $uid User ID * @param string $country User country * @param string $city User city * @param string $address User address * @param string $postalCode User postal code * @param string $phoneNumber User phone number * @param string $mobileNumber User mobile number * @param string $faxNumber User fax number * @return array Response array (notice or error) */ function UpdateContacts($uid, $country, $city, $address, $postalCode, $phoneNumber, $mobileNumber, $faxNumber) { $jUser = new Jaws_User(); $result = $jUser->UpdateContacts($uid, array('country' => $country, 'city' => $city, 'address' => $address, 'postal_code' => $postalCode, 'phone_number' => $phoneNumber, 'mobile_number' => $mobileNumber, 'fax_number' => $faxNumber)); //TODO: catch error return $result; }
/** * Grabs notification and sends it out via available drivers * * @access public * @params string $shouter The shouting gadget * @params array $params [user, group, title, summary, description, priority, send] */ function Execute($shouter, $params) { if (isset($params['send']) && $params['send'] === false) { return; } $users = array(); $jUser = new Jaws_User(); if (isset($params['group']) && !empty($params['group'])) { $group_users = $jUser->GetGroupUsers($params['group'], true, false, true); if (!Jaws_Error::IsError($group_users) && !empty($group_users)) { $users = $group_users; } } if (isset($params['user']) && !empty($params['user'])) { $user = $jUser->GetUser($params['user'], true, false, true); if (!Jaws_Error::IsError($user) && !empty($user)) { $users[] = $user; } } if (empty($users)) { return; } if (!isset($params['summary'])) { $params['summary'] = ''; } $drivers = glob(JAWS_PATH . 'include/Jaws/Notification/*.php'); foreach ($drivers as $driver) { $driver = basename($driver, '.php'); $options = unserialize($this->gadget->registry->fetch($driver . '_options')); $driverObj = Jaws_Notification::getInstance($driver, $options); $driverObj->notify($users, strip_tags($params['title']), strip_tags($params['summary']), $params['description']); } }
/** * Fetches list of system users * * @access public * @return array Array of users or an empty array */ function GetUsers() { $gid = (int) jaws()->request->fetch('gid'); if ($gid === 0) { $gid = false; } $uModel = new Jaws_User(); $users = $uModel->GetUsers($gid, null, 1); if (Jaws_Error::IsError($users)) { return array(); } return $users; }
/** * Displays list of user's posts ordered by date * * @access public * @return string XHTML content */ function UserPosts() { $rqst = jaws()->request->fetch(array('user', 'page'), 'get'); $user = $rqst['user']; if (empty($user)) { return false; } $userModel = new Jaws_User(); $user = $userModel->GetUser($user); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; // posts per page $posts_limit = $this->gadget->registry->fetch('posts_limit'); $posts_limit = empty($posts_limit) ? 10 : (int) $posts_limit; $tpl = $this->gadget->template->load('UserPosts.html'); $pModel = $this->gadget->model->load('Posts'); $posts = $pModel->GetUserPosts($user['id'], $posts_limit, ($page - 1) * $posts_limit); if (!Jaws_Error::IsError($posts)) { // date format $date_format = $this->gadget->registry->fetch('date_format'); $date_format = empty($date_format) ? 'DN d MN Y' : $date_format; $max_size = 128; $objDate = Jaws_Date::getInstance(); $tpl->SetBlock('userposts'); // title $tpl->SetVariable('action_title', _t('FORUMS_USER_POSTS', $user['nickname'])); foreach ($posts as $post) { $tpl->SetBlock('userposts/post'); // topic subject/link $tpl->SetVariable('lbl_topic', $post['subject']); $tpl->SetVariable('url_topic', $this->gadget->urlMap('Posts', array('fid' => $post['fid'], 'tid' => $post['tid']))); // post author $tpl->SetVariable('insert_time', $objDate->Format($post['insert_time'], $date_format)); $tpl->SetVariable('insert_time_iso', $objDate->ToISO((int) $post['insert_time'])); $tpl->SetVariable('message', Jaws_UTF8::substr(strip_tags($this->gadget->ParseText($post['message'], 'Forums', 'index')), 0, $max_size) . ' ...'); // post url $url_params = array('fid' => $post['fid'], 'tid' => $post['tid']); $last_post_page = floor(($post['topic_replies'] - 1) / $posts_limit) + 1; if ($last_post_page > 1) { $url_params['page'] = $last_post_page; } $tpl->SetVariable('url_post', $this->gadget->urlMap('Posts', $url_params)); $tpl->ParseBlock('userposts/post'); } $post_counts = $pModel->GetUserPostsCount($user['id']); // page navigation $this->GetPagesNavigation($tpl, 'userposts', $page, $posts_limit, $post_counts, _t('FORUMS_POSTS_COUNT', $post_counts), 'UserPosts', array('user' => $user['username'])); $tpl->ParseBlock('userposts'); } return $tpl->Get(); }
/** * * @access public * @return string HTML content with menu and menu items */ function LoadUserInfo() { $uid = (int) jaws()->request->fetch('uid'); $uModel = new Jaws_User(); $userInfo = $uModel->GetUser($uid, true, true); $userInfo['avatar_file_name'] = ''; if (empty($userInfo['avatar'])) { $userInfo['avatar'] = $GLOBALS['app']->getSiteURL('/gadgets/AddressBook/Resources/images/photo128px.png'); } else { $userAvatar = $GLOBALS['app']->getDataURL() . 'avatar/' . $userInfo['avatar']; copy($userAvatar, Jaws_Utils::upload_tmp_dir() . '/' . $userInfo['avatar']); $userInfo['avatar_file_name'] = $userInfo['avatar']; $userInfo['avatar'] = $GLOBALS['app']->getDataURL() . 'avatar/' . $userInfo['avatar']; } return $userInfo; }
/** * Displays user comments * * @access public * @return string XHTML content */ function UserComments() { $user = (int) jaws()->request->fetch('user', 'get'); if (empty($user)) { return ''; } $userModel = new Jaws_User(); $userInfo = $userModel->GetUser($user); $tpl = $this->gadget->template->load('RecentComments.html'); $tpl->SetBlock('recent_comments'); $tpl->SetVariable('title', _t('COMMENTS_USER_COMMENTS', $userInfo['nickname'])); $cHTML = Jaws_Gadget::getInstance('Comments')->action->load('Comments'); $tpl->SetVariable('comments', $cHTML->ShowComments('', '', 0, array('action' => 'RecentComments', 'params' => array('user' => $user)), $user, 0, 0)); $tpl->ParseBlock('recent_comments'); return $tpl->Get(); }
/** * Returns an array about a blog entry * * @access public * @param string $action Action name * @param int $reference Reference id * @return array entry info */ function Execute($action, $reference) { $result = array(); if ($action == 'Post') { $pModel = $this->gadget->model->load('Posts'); $post = $pModel->GetEntry($reference); if (!Jaws_Error::IsError($post) && !empty($post)) { $uModel = new Jaws_User(); $author = $uModel->GetUser($post['user_id']); if (empty($author)) { $author = array('name' => '', 'nickname' => '', 'email' => ''); } $url = $this->gadget->urlMap('SingleView', array('id' => empty($post['fast_url']) ? $post['id'] : $post['fast_url'])); $result = array('title' => $post['title'], 'url' => $url, 'author_name' => $author['username'], 'author_nickname' => $author['nickname'], 'author_email' => $author['email']); } } return $result; }
/** * Installs the gadget * * @access public * @return mixed True on successful installation, Jaws_Error otherwise */ function Install() { $variables = array(); $variables['logon_hours'] = str_pad('', 42, 'F'); $result = $this->installSchema('schema.xml', $variables); if (Jaws_Error::IsError($result)) { return $result; } $new_dir = JAWS_DATA . 'avatar'; if (!Jaws_Utils::mkdir($new_dir)) { return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $new_dir)); } // Create the group 'users' $userModel = new Jaws_User(); $result = $userModel->AddGroup(array('name' => 'users', 'title' => 'Users', 'description' => '', 'enabled' => true, 'removable' => false)); if (Jaws_Error::IsError($result) && MDB2_ERROR_CONSTRAINT != $result->getCode()) { return $result; } return true; }
/** * Changes a password from a given key * * @access public * @param string $key Recovery key * @return mixed True on success or Jaws_Error on failure */ function ChangePassword($key) { $jUser = new Jaws_User(); $user = $jUser->GetUserByPasswordVerifyKey($key); if (Jaws_Error::IsError($user) || empty($user)) { return false; } // generate new password $password = Jaws_Utils::RandomText(8); $res = $jUser->UpdateUser($user['id'], array('username' => $user['username'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $password)); if (Jaws_Error::IsError($res)) { return $res; } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('NewPassword.txt'); $tpl->SetBlock('NewPassword'); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $user['nickname'])); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('nickname', $user['nickname']); $tpl->SetVariable('password', $password); $tpl->SetVariable('message', _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $user['username'])); $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD')); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('NewPassword'); $message = $tpl->Get(); $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT'); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user['email']); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($message)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL')); } return true; }
/** * Adds a group of users(by their IDs) to a certain group * * @access public * @param int $guid Group's ID * @param array $users Array with user id * @return mixed True on success or Jaws_Error on failure */ function AddUsersToGroup($guid, $users) { $userModel = new Jaws_User(); $group = $userModel->GetGroup((int) $guid); if (!$group) { return new Jaws_Error(_t('USERS_GROUPS_GROUP_NOT_EXIST')); } $postedUsers = array(); foreach ($users as $k => $v) { $postedUsers[$v] = $v; } $list = $userModel->GetUsers(); foreach ($list as $user) { if ($userModel->UserIsInGroup($user['id'], $guid)) { if (!isset($postedUsers[$user['id']])) { if (!$GLOBALS['app']->Session->IsSuperAdmin() && $user['superadmin']) { continue; } $userModel->DeleteUserFromGroup($user['id'], $guid); } } else { if (isset($postedUsers[$user['id']])) { $userModel->AddUserToGroup($user['id'], $guid); } } } return true; }
/** * Displays the list of Public Address Book items for selected user * * @access public * @return string HTML content with menu and menu items */ function UserAddress() { if (!$GLOBALS['app']->Session->Logged() || !jaws()->request->fetch('uid')) { return Jaws_HTTPError::Get(403); } $uid = jaws()->request->fetch('uid'); $usrModel = new Jaws_User(); $user = $usrModel->GetUser($uid, true, true); if (Jaws_Error::IsError($user) || empty($user)) { return Jaws_HTTPError::Get(404); } $model = $this->gadget->model->load('AddressBook'); $addressItems = $model->GetAddressList($user['id'], 0, true); if (Jaws_Error::IsError($addressItems) || !isset($addressItems)) { return $addressItems->getMessage(); // TODO: Show intelligible message } $this->SetTitle($this->gadget->title); $tpl = $this->gadget->template->load('UserAddress.html'); $tpl->SetBlock("address_list"); $tpl->SetVariable('title', _t('ADDRESSBOOK_USER_ADDRESS_TITLE', $user['nickname'])); $tpl->SetVariable('lbl_name', _t('ADDRESSBOOK_ITEMS_NAME')); $tpl->SetVariable('lbl_title', _t('ADDRESSBOOK_ITEMS_TITLE')); $tpl->SetVariable('back_to_my_adr', _t('ADDRESSBOOK_BACK_TO_MY_ADDRESS')); $tpl->SetVariable('back_to_my_adr_link', $this->gadget->urlMap('AddressBook')); foreach ($addressItems as $addressItem) { $tpl->SetBlock("address_list/item1"); $names = explode(';', $addressItem['name']); foreach ($names as $key => $name) { $tpl->SetVariable('name' . $key, $name); } $tpl->SetVariable('name', str_replace(';', ' ', $addressItem['name'])); $tpl->SetVariable('title', $addressItem['title']); $tpl->SetVariable('view_url', $this->gadget->urlMap('View', array('id' => $addressItem['id']))); $tpl->ParseBlock("address_list/item1"); } $tpl->ParseBlock('address_list'); 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(); }
/** * Prepares a simple form to update user's contacts information (country, city, ...) * * @access public * @return string XHTML template of a form */ function Contacts() { if (!$GLOBALS['app']->Session->Logged()) { Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))))); } $this->gadget->CheckPermission('EditUserContacts'); $this->AjaxMe('index.js'); $response = $GLOBALS['app']->Session->PopResponse('Users.Contacts'); if (!isset($response['data'])) { $jUser = new Jaws_User(); $contacts = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), false, false, true); } else { $contacts = $response['data']; } // Load the template $tpl = $this->gadget->template->load('Contacts.html'); $tpl->SetBlock('contacts'); $tpl->SetVariable('title', _t('USERS_CONTACTS_INFO')); $tpl->SetVariable('base_script', BASE_SCRIPT); $tpl->SetVariable('update', _t('USERS_USERS_ACCOUNT_UPDATE')); // Menubar $tpl->SetVariable('menubar', $this->MenuBar('Account')); $tpl->SetVariable('submenubar', $this->SubMenuBar('Contacts', array('Account', 'Personal', 'Preferences', 'Contacts'))); $tpl->SetVariable('lbl_country', _t('USERS_CONTACTS_COUNTRY')); $tpl->SetVariable('lbl_city', _t('USERS_CONTACTS_CITY')); $tpl->SetVariable('lbl_address', _t('USERS_CONTACTS_ADDRESS')); $tpl->SetVariable('lbl_postal_code', _t('USERS_CONTACTS_POSTAL_CODE')); $tpl->SetVariable('lbl_phone_number', _t('USERS_CONTACTS_PHONE_NUMBER')); $tpl->SetVariable('lbl_mobile_number', _t('USERS_CONTACTS_MOBILE_NUMBER')); $tpl->SetVariable('lbl_fax_number', _t('USERS_CONTACTS_FAX_NUMBER')); $tpl->SetVariablesArray($contacts); if (empty($contacts['avatar'])) { $user_current_avatar = $GLOBALS['app']->getSiteURL('/gadgets/Users/Resources/images/photo128px.png'); } else { $user_current_avatar = $GLOBALS['app']->getDataURL() . "avatar/" . $contacts['avatar']; $user_current_avatar .= !empty($contacts['last_update']) ? "?" . $contacts['last_update'] . "" : ''; } $avatar =& Piwi::CreateWidget('Image', $user_current_avatar); $avatar->SetID('avatar'); $tpl->SetVariable('avatar', $avatar->Get()); // countries list $ObjCountry = $this->gadget->model->load('Country'); $countries = $ObjCountry->GetCountries(); if (!Jaws_Error::IsError($Countries)) { array_unshift($countries, _t('USERS_ADVANCED_OPTS_NOT_YET')); foreach ($countries as $code => $name) { $tpl->SetBlock('contacts/country'); $tpl->SetVariable('code', $code); $tpl->SetVariable('name', $name); if ($contacts['country'] === $code) { $tpl->SetBlock('contacts/country/selected'); $tpl->ParseBlock('contacts/country/selected'); } $tpl->ParseBlock('contacts/country'); } } if (!empty($response)) { $tpl->SetVariable('type', $response['type']); $tpl->SetVariable('text', $response['text']); } $tpl->ParseBlock('contacts'); return $tpl->Get(); }
/** * Checks if user/email are valid, if they are then generates a recovery * secret key and sends it to the user * * @access public * @param string $user_email User email * @return bool True on success or Jaws_Error on failure */ function SendRecoveryKey($user_email) { $userModel = new Jaws_User(); $uInfos = $userModel->GetUserInfoByEmail($user_email); if (Jaws_Error::IsError($uInfos)) { return $uInfos; } if (empty($uInfos)) { return new Jaws_Error(_t('USERS_USER_NOT_EXIST')); } foreach ($uInfos as $info) { $verifyKey = $userModel->UpdatePasswordVerifyKey($info['id']); if (Jaws_Error::IsError($verifyKey)) { $verifyKey->SetMessage(_t('GLOBAL_ERROR_QUERY_FAILED')); return $verifyKey; } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('RecoverPassword.txt'); $tpl->SetBlock('RecoverPassword'); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $info['username']); $tpl->SetVariable('nickname', $info['nickname']); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $info['nickname'])); $tpl->SetVariable('message', _t('USERS_FORGOT_MAIL_MESSAGE')); $tpl->SetVariable('lbl_url', _t('GLOBAL_URL')); $tpl->SetVariable('url', $this->gadget->urlMap('ChangePassword', array('key' => $verifyKey), true)); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('RecoverPassword'); $message = $tpl->Get(); $subject = _t('USERS_FORGOT_REMEMBER', $site_name); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user_email); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($message)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { $mresult->SetMessage(_t('USERS_FORGOT_ERROR_SENDING_MAIL')); return $mresult; } } }
/** * Displays not editable version of one address * * @access public * @return string HTML content with menu and menu items */ function View() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(403); } $id = (int) jaws()->request->fetch('id'); // TODO: Check this ID for Me, And Can I Edit Or View This?! if ($id == 0) { return false; } $model = $this->gadget->model->load('AddressBook'); $info = $model->GetAddressInfo($id); if (Jaws_Error::IsError($info)) { return $info->getMessage(); // TODO: Show intelligible message } if (!isset($info)) { return Jaws_HTTPError::Get(404); } if ($info['user'] != $GLOBALS['app']->Session->GetAttribute('user') && $info['public'] == false) { return Jaws_HTTPError::Get(403); } $this->SetTitle(_t('ADDRESSBOOK_ITEMS_VIEW_TITLE')); $tpl = $this->gadget->template->load('ViewAddress.html'); $tpl->SetBlock("address"); $tpl->SetVariable('top_title', _t('ADDRESSBOOK_ITEMS_VIEW_TITLE')); $tpl->SetVariable('id', $info['id']); $tpl->SetVariable('action', 'UpdateAddress'); $tpl->SetVariable('lbl_name0', _t('ADDRESSBOOK_ITEMS_LASTNAME')); $tpl->SetVariable('lbl_name1', _t('ADDRESSBOOK_ITEMS_FIRSTNAME')); $tpl->SetVariable('lbl_nickname', _t('ADDRESSBOOK_ITEMS_NICKNAME')); $tpl->SetVariable('lbl_title', _t('ADDRESSBOOK_ITEMS_TITLE')); $tpl->SetVariable('lbl_notes', _t('ADDRESSBOOK_ITEMS_NOTES')); $tpl->SetVariable('nickname', $info['nickname']); $tpl->SetVariable('title', $info['title']); $tpl->SetVariable('notes', $info['notes']); $names = explode(';', $info['name']); foreach ($names as $key => $name) { $tpl->SetVariable('name' . $key, $name); } if (empty($info['image'])) { $current_image = $GLOBALS['app']->getSiteURL('/gadgets/AddressBook/Resources/images/photo128px.png'); } else { $current_image = $GLOBALS['app']->getDataURL() . "addressbook/image/" . $info['image']; $current_image .= !empty($info['updatetime']) ? "?" . $info['updatetime'] . "" : ''; } $tpl->SetVariable('image_src', $current_image); // Tel $this->GetItemsLable($tpl, 'item', $info['tel_home'], $this->_TelTypes); $this->GetItemsLable($tpl, 'item', $info['tel_work'], $this->_TelTypes); $this->GetItemsLable($tpl, 'item', $info['tel_other'], $this->_TelTypes); // Email $this->GetItemsLable($tpl, 'item', $info['email_home'], $this->_EmailTypes); $this->GetItemsLable($tpl, 'item', $info['email_work'], $this->_EmailTypes); $this->GetItemsLable($tpl, 'item', $info['email_other'], $this->_EmailTypes); // URL $this->GetItemsLable($tpl, 'item', $info['url'], null, '\\n'); if ($info['public']) { $tpl->SetBlock('address/selected'); $tpl->SetVariable('lbl_is_public', _t('ADDRESSBOOK_ITEMS_IS_PUBLIC')); $tpl->ParseBlock('address/selected'); } $agModel = $this->gadget->model->load('AddressBookGroup'); $agData = $agModel->GetData($info['id'], $info['user']); if (isset($agData)) { foreach ($agData as $gInfo) { $tpl->SetBlock('address/group'); $tpl->SetVariable('lbl_group', $gInfo['name']); $tpl->ParseBlock('address/group'); } } $tpl->SetVariable('menubar', $this->MenuBar('')); $tpl->SetBlock('address/actions'); if ($info['user'] == $GLOBALS['app']->Session->GetAttribute('user')) { $tpl->SetBlock('address/actions/action'); $tpl->SetVariable('action_lbl', _t('GLOBAL_EDIT')); $tpl->SetVariable('action_url', $this->gadget->urlMap('EditAddress', array('id' => $info['id']))); $tpl->ParseBlock('address/actions/action'); } else { $usrModel = new Jaws_User(); $user = $usrModel->GetUser((int) $info['user']); if (!Jaws_Error::IsError($user) && !empty($user)) { $tpl->SetBlock('address/actions/action'); $tpl->SetVariable('action_lbl', _t('ADDRESSBOOK_VIEW_ALL_ADDREESS_USER')); $tpl->SetVariable('action_url', $this->gadget->urlMap('UserAddress', array('uid' => $user['username']))); $tpl->ParseBlock('address/actions/action'); } } $tpl->ParseBlock('address/actions'); $tpl->ParseBlock('address'); return $tpl->Get(); }
/** * Sends the Email * * @access public * @param string $target JSON decoded array ([to, cc, bcc] or [user, group]) * @param string $subject Subject of the Email * @param string $message Message body of the Email * @param string $attachment Attachment * @return string XHTML template content */ function SendEmail($target, $subject, $message, $attachment) { $this->gadget->CheckPermission('AccessToMailer'); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->SetSubject(Jaws_XSS::defilter($subject)); // To, Cc, Bcc if (isset($target['to'])) { if (!empty($target['to'])) { $recipients = explode(',', $target['to']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'To'); } } if (!empty($target['cc'])) { $recipients = explode(',', $target['cc']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'Cc'); } } if (!empty($target['bcc'])) { $recipients = explode(',', $target['bcc']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'Bcc'); } } } else { $userModel = new Jaws_User(); if ($target['user'] != 0) { $user = $userModel->GetUser((int) $target['user']); if (!Jaws_Error::IsError($user)) { $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'To'); } } else { if ($target['group'] == 0) { $target['group'] = false; } $users = $userModel->GetUsers($target['group'], null, true); foreach ($users as $user) { $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'Bcc'); } } } $message = $this->PrepareMessage($message); $format = $this->gadget->registry->fetch('email_format'); $mail->SetBody($message, $format); if (!empty($attachment)) { $attachment = Jaws_Utils::upload_tmp_dir() . '/' . $attachment; if (file_exists($attachment)) { $mail->SetBody($attachment, 'file'); Jaws_Utils::Delete($attachment); } } $result = $mail->send(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_EMAIL_NOT_SENT'), RESPONSE_ERROR); return false; } $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_NOTICE_EMAIL_SENT'), RESPONSE_NOTICE); return true; }
/** * metaWeblog.getUserInfo * * @access public * @param array $params array of params * @return XML_RPC_Response object */ function metaWeblog_getUserInfo($params) { // parameters $user = getScalarValue($params, 1); $password = getScalarValue($params, 2); if (!$user || !$password) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 3, 'fubar user param'); } $userInfo = userAuthentication($user, $password); if (Jaws_Error::IsError($userInfo)) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 3, _t('GLOBAL_ERROR_LOGIN_WRONG')); } if (!GetBlogPermission($user, 'default_admin')) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 2, _t('GLOBAL_ERROR_NO_PRIVILEGES')); } $siteurl = $GLOBALS['app']->GetSiteURL(); $user = Jaws_User::GetUser((int) $userInfo['id'], true, true); $data = array('nickname' => new XML_RPC_Value($user['username']), 'userid' => new XML_RPC_Value($user['id']), 'url' => new XML_RPC_Value($siteurl), 'email' => new XML_RPC_Value($user['email']), 'lastname' => new XML_RPC_Value($user['lname']), 'firstName' => new XML_RPC_Value($user['fname'])); $struct = new XML_RPC_Value($data, 'struct'); return new XML_RPC_Response($struct); }
/** * Update personal information of a user such as fname, lname, gender, etc.. * * @access public * @param int $id User's ID * @param array $pData Personal information data * @return bool Returns true on success, false on failure */ function UpdatePersonal($id, $pData) { // unset invalid keys $invalids = array_diff(array_keys($pData), array('fname', 'lname', 'gender', 'ssn', 'dob', 'url', 'signature', 'about', 'experiences', 'occupations', 'interests', 'avatar', 'privacy')); foreach ($invalids as $invalid) { unset($pData[$invalid]); } if (array_key_exists('avatar', $pData)) { // get user information $user = Jaws_User::GetUser((int) $id, true, true); if (Jaws_Error::IsError($user) || empty($user)) { return false; } if (!empty($user['avatar'])) { Jaws_Utils::Delete(AVATAR_PATH . $user['avatar']); } if (!empty($pData['avatar'])) { $fileinfo = pathinfo($pData['avatar']); if (isset($fileinfo['extension']) && !empty($fileinfo['extension'])) { if (!in_array($fileinfo['extension'], array('gif', 'jpg', 'jpeg', 'png', 'svg'))) { return false; } else { $new_avatar = $user['username'] . '.' . $fileinfo['extension']; @rename(Jaws_Utils::upload_tmp_dir() . '/' . $pData['avatar'], AVATAR_PATH . $new_avatar); $pData['avatar'] = $new_avatar; } } } } $pData['last_update'] = time(); $usersTable = Jaws_ORM::getInstance()->table('users'); $result = $usersTable->update($pData)->where('id', $id)->exec(); if (Jaws_Error::IsError($result)) { return $result; } if (isset($GLOBALS['app']->Session) && $GLOBALS['app']->Session->GetAttribute('user') == $id) { foreach ($pData as $k => $v) { if ($k == 'avatar') { $GLOBALS['app']->Session->SetAttribute($k, $this->GetAvatar($v, $user['email'], 48, $pData['last_update'])); } else { $GLOBALS['app']->Session->SetAttribute($k, $v); } } } // Let everyone know a user has been updated $res = $GLOBALS['app']->Listener->Shout('Users', 'UpdateUser', $id); if (Jaws_Error::IsError($res)) { return false; } return true; }
/** * Gets users of the specified group * * @access public * @internal param int $group ID of the group * @return array array of users or false on error */ function GetUsers() { @(list($group) = jaws()->request->fetchAll('post')); $userModel = new Jaws_User(); return $userModel->GetUsers($group, null, true); }
/** * Builds admin properties UI * * @access public * @return string XHTML form */ function Properties() { $this->gadget->CheckPermission('ManageProperties'); $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('Properties.html'); $tpl->SetBlock('Properties'); $form =& Piwi::CreateWidget('Form', BASE_SCRIPT, 'post'); $form->Add(Piwi::CreateWidget('HiddenEntry', 'gadget', 'Users')); $form->Add(Piwi::CreateWidget('HiddenEntry', 'action', 'SaveProperties')); $authtype =& Piwi::CreateWidget('Combo', 'authtype'); $authtype->SetTitle(_t('GLOBAL_AUTHTYPE')); foreach ($GLOBALS['app']->GetAuthTypes() as $method) { $authtype->AddOption($method, $method); } $authtype->SetDefault($this->gadget->registry->fetch('authtype')); $authtype->SetEnabled($this->gadget->GetPermission('ManageAuthenticationMethod')); $anonRegister =& Piwi::CreateWidget('Combo', 'anon_register'); $anonRegister->SetTitle(_t('USERS_PROPERTIES_ANON_REGISTER')); $anonRegister->AddOption(_t('GLOBAL_YES'), 'true'); $anonRegister->AddOption(_t('GLOBAL_NO'), 'false'); $anonRegister->SetDefault($this->gadget->registry->fetch('anon_register')); $anonactivate =& Piwi::CreateWidget('Combo', 'anon_activation'); $anonactivate->SetTitle(_t('USERS_PROPERTIES_ANON_ACTIVATION')); $anonactivate->AddOption(_t('USERS_PROPERTIES_ACTIVATION_AUTO'), 'auto'); $anonactivate->AddOption(_t('USERS_PROPERTIES_ACTIVATION_BY_USER'), 'user'); $anonactivate->AddOption(_t('USERS_PROPERTIES_ACTIVATION_BY_ADMIN'), 'admin'); $anonactivate->SetDefault($this->gadget->registry->fetch('anon_activation')); $userModel = new Jaws_User(); $anonGroup =& Piwi::CreateWidget('Combo', 'anon_group'); $anonGroup->SetID('anon_group'); $anonGroup->SetTitle(_t('USERS_PROPERTIES_ANON_GROUP')); $anonGroup->AddOption(_t('USERS_GROUPS_NOGROUP'), 0); $groups = $userModel->GetGroups(null, 'title'); if (!Jaws_Error::IsError($groups)) { foreach ($groups as $group) { $anonGroup->AddOption($group['title'], $group['id']); } } $anonGroup->SetDefault($this->gadget->registry->fetch('anon_group')); $passRecovery =& Piwi::CreateWidget('Combo', 'password_recovery'); $passRecovery->SetTitle(_t('USERS_PROPERTIES_PASS_RECOVERY')); $passRecovery->AddOption(_t('GLOBAL_YES'), 'true'); $passRecovery->AddOption(_t('GLOBAL_NO'), 'false'); $passRecovery->SetDefault($this->gadget->registry->fetch('password_recovery')); include_once JAWS_PATH . 'include/Jaws/Widgets/FieldSet.php'; $fieldset = new Jaws_Widgets_FieldSet(''); $fieldset->SetTitle('vertical'); $fieldset->Add($authtype); $fieldset->Add($anonRegister); $fieldset->Add($anonactivate); $fieldset->Add($anonGroup); $fieldset->Add($passRecovery); $form->Add($fieldset); $buttons =& Piwi::CreateWidget('HBox'); $buttons->SetStyle(_t('GLOBAL_LANG_DIRECTION') == 'rtl' ? 'float: left;' : 'float: right;'); $save =& Piwi::CreateWidget('Button', 'save', _t('GLOBAL_SAVE'), STOCK_SAVE); $save->AddEvent(ON_CLICK, 'javascript:saveSettings();'); $buttons->Add($save); $form->Add($buttons); $tpl->SetVariable('form', $form->Get()); $tpl->SetVariable('menubar', $this->MenuBar('Properties')); $tpl->ParseBlock('Properties'); 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 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(); }
/** * 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(); }
/** * Grabs notification and sends it out via available drivers * * @access public * @param string $shouter The shouting gadget * @param array $params [user, group, title, summary, description, priority, send] * @return bool */ function Execute($shouter, $params) { if (isset($params['send']) && $params['send'] === false) { return false; } $model = $this->gadget->model->load('Notification'); $gadget = empty($params['gadget']) ? $shouter : $params['gadget']; $params['publish_time'] = !isset($params['publish_time']) ? time() : $params['publish_time']; // detect if publish_time = 0 then must delete the notifications if ($params['publish_time'] < 0) { return $model->DeleteNotificationsByKey($params['key']); } $users = array(); $jUser = new Jaws_User(); if (isset($params['group']) && !empty($params['group'])) { $group_users = $jUser->GetGroupUsers($params['group'], true, false, true); if (!Jaws_Error::IsError($group_users) && !empty($group_users)) { $users = $group_users; } } if (isset($params['emails']) && !empty($params['emails'])) { foreach ($params['emails'] as $email) { if (!empty($email)) { $users[] = array('email' => $email); } } } if (isset($params['mobiles']) && !empty($params['mobiles'])) { foreach ($params['mobiles'] as $mobile) { if (!empty($mobile)) { $users[] = array('mobile_number' => $mobile); } } } if (isset($params['user']) && !empty($params['user'])) { $user = $jUser->GetUser($params['user'], true, false, true); if (!Jaws_Error::IsError($user) && !empty($user)) { $users[] = $user; } } // FIXME: increase performance for getting users data if (isset($params['users']) && !empty($params['users'])) { foreach ($params['users'] as $userId) { if (!empty($userId)) { $user = $jUser->GetUser($userId, true, false, true); if (!Jaws_Error::IsError($user) && !empty($user)) { $users[] = $user; } } } } if (empty($users)) { return false; } // get gadget driver settings $configuration = unserialize($this->gadget->registry->fetch('configuration')); $notificationsEmails = array(); $notificationsMobiles = array(); // notification for this gadget was disabled if (isset($configuration[$gadget]) && $configuration[$gadget] == 0) { return false; } foreach ($users as $user) { // generate email array if (!isset($configuration[$gadget]) || $configuration[$gadget] == 1 || $configuration[$gadget] == 'Mail') { if (!empty($user['email'])) { $notificationsEmails[] = array('contact' => $user['email'], 'publish_time' => $params['publish_time']); } } // generate mobile array if (!isset($configuration[$gadget]) || $configuration[$gadget] == 1 || $configuration[$gadget] == 'Mobile') { if (!empty($user['mobile_number'])) { $notificationsMobiles[] = array('contact' => $user['mobile_number'], 'publish_time' => $params['publish_time']); } } } if (!empty($notificationsEmails) || !empty($notificationsMobiles)) { $res = $model->InsertNotifications(array('emails' => $notificationsEmails, 'mobiles' => $notificationsMobiles), $params['key'], strip_tags($params['title']), strip_tags($params['summary']), $params['description']); if (Jaws_Error::IsError($res)) { return $res; } return true; } return false; }
/** * Updates user profile * * @access public * @param int $uid User ID * @param array $pData First name * @return mixed True on success or Jaws_Error on failure */ function UpdatePersonal($uid, $pData) { $jUser = new Jaws_User(); $result = $jUser->UpdatePersonal($uid, $pData); return $result; }
/** * Displays list of user's posts ordered by date * * @access public * @return string XHTML content */ function UserTopics() { $rqst = jaws()->request->fetch(array('user', 'page'), 'get'); $user = $rqst['user']; if (empty($user)) { return false; } $userModel = new Jaws_User(); $user = $userModel->GetUser($user); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; // topics per page $limit = $this->gadget->registry->fetch('topics_limit'); $limit = empty($limit) ? 10 : (int) $limit; $tpl = $this->gadget->template->load('UserTopics.html'); $tModel = $this->gadget->model->load('Topics'); $topics = $tModel->GetUserTopics($user['id'], $limit, ($page - 1) * $limit); if (!Jaws_Error::IsError($topics)) { // date format $date_format = $this->gadget->registry->fetch('date_format'); $date_format = empty($date_format) ? 'DN d MN Y' : $date_format; $max_size = 128; $objDate = Jaws_Date::getInstance(); $tpl->SetBlock('topics'); $userURL = $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $user['username'])); $tpl->SetVariable('index_title', _t('FORUMS_TOPICS')); $tpl->SetVariable('title', $user['nickname']); $tpl->SetVariable('url', $userURL); $tpl->SetVariable('lbl_topics', _t('FORUMS_TOPICS')); $tpl->SetVariable('lbl_replies', _t('FORUMS_REPLIES')); $tpl->SetVariable('lbl_views', _t('FORUMS_VIEWS')); $tpl->SetVariable('lbl_lastpost', _t('FORUMS_LASTPOST')); // posts per page $posts_limit = $this->gadget->registry->fetch('posts_limit'); $posts_limit = empty($posts_limit) ? 10 : (int) $posts_limit; foreach ($topics as $topic) { $tpl->SetBlock('topics/topic'); $tpl->SetVariable('lbl_forum', _t('FORUMS_FORUM')); $tpl->SetVariable('forum', $topic['title']); $tpl->SetVariable('forum_url', $this->gadget->urlMap('Topics', array('fid' => $topic['fid']))); $tpl->SetVariable('status', (int) $topic['locked']); $published_status = (int) $topic['published'] === 1 ? 'published' : 'draft'; $tpl->SetVariable('published_status', $published_status); $tpl->SetVariable('title', $topic['subject']); $tpl->SetVariable('url', $this->gadget->urlMap('Posts', array('fid' => $topic['fid'], 'tid' => $topic['id']))); $tpl->SetVariable('replies', $topic['replies']); $tpl->SetVariable('views', $topic['views']); // first post $tpl->SetVariable('postedby_lbl', _t('FORUMS_POSTEDBY')); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('nickname', $user['nickname']); $tpl->SetVariable('user_url', $userURL); $tpl->SetVariable('firstpost_date', $objDate->Format($topic['first_post_time'], $date_format)); $tpl->SetVariable('firstpost_date_iso', $objDate->ToISO((int) $topic['first_post_time'])); // last post if (!empty($topic['last_post_id'])) { $tpl->SetBlock('topics/topic/lastpost'); $tpl->SetVariable('postedby_lbl', _t('FORUMS_POSTEDBY')); $tpl->SetVariable('username', $topic['last_username']); $tpl->SetVariable('nickname', $topic['last_nickname']); $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $topic['last_username']))); $tpl->SetVariable('lastpost_lbl', _t('FORUMS_LASTPOST')); $tpl->SetVariable('lastpost_date', $objDate->Format($topic['last_post_time'], $date_format)); $tpl->SetVariable('lastpost_date_iso', $objDate->ToISO((int) $topic['last_post_time'])); $url_params = array('fid' => $topic['fid'], 'tid' => $topic['id']); $last_post_page = floor(($topic['replies'] - 1) / $posts_limit) + 1; if ($last_post_page > 1) { $url_params['page'] = $last_post_page; } $tpl->SetVariable('lastpost_url', $this->gadget->urlMap('Posts', $url_params)); $tpl->ParseBlock('topics/topic/lastpost'); } $tpl->ParseBlock('topics/topic'); } $topicCounts = $tModel->GetUserTopicCount($user['id']); // page navigation $this->GetPagesNavigation($tpl, 'topics', $page, $limit, $topicCounts, _t('FORUMS_POSTS_COUNT', $topicCounts), 'UserTopics', array('user' => $user['username'])); $tpl->ParseBlock('topics'); } return $tpl->Get(); }
/** * Search users * * @access public * @return void */ function GetUsers() { $term = jaws()->request->fetch('term', 'post'); $userModel = new Jaws_User(); $users = $userModel->GetUsers(false, null, null, $term, 'nickname', 5); return $users; }
/** * Update a user's group * * @access public * @return void */ function UpdateGroup() { $this->gadget->CheckPermission('ManageUserGroups'); $post = jaws()->request->fetch(array('gid', 'name', 'title', 'description', 'enabled'), 'post'); $selected_members = jaws()->request->fetch('members:array', 'post'); $user = $GLOBALS['app']->Session->GetAttribute('user'); $post['enabled'] = (bool) $post['enabled']; $jUser = new Jaws_User(); $res = $jUser->UpdateGroup($post['gid'], $post, $user); $current_members_info = $jUser->GetUsers($post['gid']); $current_members = array(); foreach ($current_members_info as $member_info) { $current_members[] = $member_info['id']; } $new_member = array_diff($selected_members, $current_members); if (!Jaws_Error::isError($res) && count($new_member) > 0) { // TODO: improve performance foreach ($new_member as $member) { $res = $jUser->AddUserToGroup($member, $post['gid'], $user); } } $removed_member = array_diff($current_members, $selected_members); if (!Jaws_Error::isError($res) && count($removed_member) > 0) { // TODO: improve performance foreach ($removed_member as $member) { $res = $jUser->DeleteUserFromGroup($member, $post['gid'], $user); } } if (Jaws_Error::isError($res)) { $GLOBALS['app']->Session->PushResponse($res->getMessage(), 'Users.Groups', RESPONSE_ERROR); } elseif ($res == true) { $GLOBALS['app']->Session->PushResponse(_t('USERS_GROUPS_UPDATED', $post['title']), 'Users.Groups', RESPONSE_NOTICE); } Jaws_Header::Location($this->gadget->urlMap('Groups')); }
/** * * @access public * @return string HTML content with menu and menu items */ function Logs() { $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('Logs.html'); $tpl->SetBlock('Logs'); //Menu bar $tpl->SetVariable('menubar', $this->MenuBar('Logs')); // From Date Filter $fromDate =& Piwi::CreateWidget('DatePicker', 'from_date', ''); $fromDate->showTimePicker(true); $fromDate->setLanguageCode($this->gadget->registry->fetch('admin_language', 'Settings')); $fromDate->setCalType($this->gadget->registry->fetch('calendar', 'Settings')); $fromDate->setDateFormat('%Y-%m-%d %H:%M:%S'); $fromDate->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $tpl->SetVariable('filter_from_date', $fromDate->Get()); $tpl->SetVariable('lbl_filter_from_date', _t('LOGS_FROM_DATE')); // To Date Filter $toDate =& Piwi::CreateWidget('DatePicker', 'to_date', ''); $toDate->showTimePicker(true); $toDate->setLanguageCode($this->gadget->registry->fetch('admin_language', 'Settings')); $toDate->setCalType($this->gadget->registry->fetch('calendar', 'Settings')); $toDate->setDateFormat('%Y-%m-%d %H:%M:%S'); $toDate->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $tpl->SetVariable('filter_to_date', $toDate->Get()); $tpl->SetVariable('lbl_filter_to_date', _t('LOGS_TO_DATE')); // Gadgets Filter $gadgetsCombo =& Piwi::CreateWidget('Combo', 'filter_gadget'); $gadgetsCombo->AddOption(_t('LOGS_ALL_GADGETS'), "", false); $cmpModel = Jaws_Gadget::getInstance('Components')->model->load('Gadgets'); $gadgetList = $cmpModel->GetGadgetsList(); foreach ($gadgetList as $gadget) { $gadgetsCombo->AddOption($gadget['title'], $gadget['name']); } $gadgetsCombo->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $gadgetsCombo->SetDefault(-1); $tpl->SetVariable('filter_gadget', $gadgetsCombo->Get()); $tpl->SetVariable('lbl_filter_gadget', _t('GLOBAL_GADGETS')); // Users Filter $usersCombo =& Piwi::CreateWidget('Combo', 'filter_user'); $usersCombo->AddOption(_t('GLOBAL_ALL_USERS'), "", false); $userModel = new Jaws_User(); $users = $userModel->GetUsers(); if (!Jaws_Error::IsError($users)) { foreach ($users as $user) { $usersCombo->AddOption($user['username'] . ' - ' . $user['nickname'], $user['id']); } } $usersCombo->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $usersCombo->SetDefault(-1); $tpl->SetVariable('filter_user', $usersCombo->Get()); $tpl->SetVariable('lbl_filter_user', _t('LOGS_USERS')); // Priority $priorityCombo =& Piwi::CreateWidget('Combo', 'filter_priority'); $priorityCombo->AddOption(_t('GLOBAL_ALL'), 0, false); $priorityCombo->AddOption(_t('LOGS_PRIORITY_5'), JAWS_WARNING, false); $priorityCombo->AddOption(_t('LOGS_PRIORITY_6'), JAWS_NOTICE, false); $priorityCombo->AddOption(_t('LOGS_PRIORITY_7'), JAWS_INFO, false); $priorityCombo->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $priorityCombo->SetDefault(0); $tpl->SetVariable('filter_priority', $priorityCombo->Get()); $tpl->SetVariable('lbl_filter_priority', _t('LOGS_PRIORITY')); // Status $allStatus = array(200, 301, 302, 401, 403, 404, 410, 500, 503); $statusCombo =& Piwi::CreateWidget('Combo', 'filter_status'); $statusCombo->AddOption(_t('GLOBAL_ALL'), 0, false); foreach ($allStatus as $status) { $statusCombo->AddOption(_t('GLOBAL_HTTP_ERROR_TITLE_' . $status), $status, false); } $statusCombo->AddEvent(ON_CHANGE, "javascript:searchLogs();"); $statusCombo->SetDefault(0); $tpl->SetVariable('filter_status', $statusCombo->Get()); $tpl->SetVariable('lbl_filter_status', _t('LOGS_LOG_STATUS')); //DataGrid $tpl->SetVariable('datagrid', $this->LogsDataGrid()); //LogUI $tpl->SetVariable('log_ui', $this->LogUI()); // Actions $actions =& Piwi::CreateWidget('Combo', 'logs_actions'); $actions->SetID('logs_actions_combo'); $actions->SetTitle(_t('GLOBAL_ACTIONS')); $actions->AddOption(' ', ''); if ($this->gadget->GetPermission('DeleteLogs')) { $actions->AddOption(_t('GLOBAL_DELETE'), 'delete'); $actions->AddOption(_t('LOGS_DELETE_ALL'), 'deleteAll'); $actions->AddOption(_t('LOGS_DELETE_FILTERED'), 'deleteFiltered'); } if ($this->gadget->GetPermission('ExportLogs')) { $actions->AddOption(_t('LOGS_EXPORT_ALL'), 'export'); $actions->AddOption(_t('LOGS_EXPORT_FILTERED'), 'exportFiltered'); } $tpl->SetVariable('actions_combo', $actions->Get()); $btnExecute =& Piwi::CreateWidget('Button', 'executeLogsAction', '', STOCK_YES); $btnExecute->AddEvent(ON_CLICK, "javascript:logsDGAction(\$('#logs_actions_combo'));"); $tpl->SetVariable('btn_execute', $btnExecute->Get()); $btnCancel =& Piwi::CreateWidget('Button', 'btn_cancel', _t('GLOBAL_CANCEL'), STOCK_CANCEL); $btnCancel->AddEvent(ON_CLICK, 'stopAction();'); $btnCancel->SetStyle('display:none;'); $tpl->SetVariable('btn_cancel', $btnCancel->Get()); $tpl->SetVariable('confirmLogsDelete', _t('LOGS_CONFIRM_DELETE')); $tpl->SetVariable('legend_title', _t('LOGS_LOG_DETAILS')); $tpl->ParseBlock('Logs'); 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(); }