/** * 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']); } }
/** * Displays the list of Address Book items, this items can filter by $uid(user ID) param. * * @access public * $gid Group ID * @return string HTML content with menu and menu items */ function AddressBook() { if (!$GLOBALS['app']->Session->Logged()) { return Jaws_HTTPError::Get(403); } $uid = (int) $GLOBALS['app']->Session->GetAttribute('user'); $usrModel = new Jaws_User(); $user = $usrModel->GetUser($uid); if (Jaws_Error::IsError($user) || empty($user)) { return Jaws_HTTPError::Get(404); } $this->AjaxMe('site_script.js'); $this->SetTitle($this->gadget->title); $tpl = $this->gadget->template->load('AddressBook.html'); $tpl->SetBlock("address_list"); $tpl->SetVariable('title', $this->gadget->title); $tpl->SetVariable('confirmDelete', _t('ADDRESSBOOK_DELETE_CONFIRM')); // Set default delete URL for use in javascript $tpl->SetVariable('deleteURL', $this->gadget->urlMap('DeleteAddress', array('id' => ''))); $response = $GLOBALS['app']->Session->PopResponse('AddressBook'); if (!empty($response)) { $tpl->SetVariable('type', $response['type']); $tpl->SetVariable('text', $response['text']); } $tpl->SetVariable('menubar', $this->MenuBar('AddressBook')); $tpl->SetVariable('lbl_group', _t('ADDRESSBOOK_GROUP')); $tpl->SetVariable('lbl_term', _t('ADDRESSBOOK_TERM')); $tpl->SetVariable('lbl_delete', _t('GLOBAL_DELETE')); $tpl->SetVariable('lbl_export', _t('ADDRESSBOOK_EXPORT_VCARD')); $tpl->SetVariable('lbl_all_groups', _t('GLOBAL_ALL_GROUPS')); $tpl->SetVariable('lbl_no_action', _t('GLOBAL_NO_ACTION')); $tpl->SetVariable('lbl_search', _t('GLOBAL_SEARCH')); $tpl->SetVariable('icon_ok', STOCK_OK); $gModel = $this->gadget->model->load('Groups'); $groupList = $gModel->GetGroups($uid); foreach ($groupList as $gInfo) { $tpl->SetBlock('address_list/group_item'); $tpl->SetVariable('group_name', $gInfo['name']); $tpl->SetVariable('gid', $gInfo['id']); $tpl->ParseBlock('address_list/group_item'); } $tpl->SetVariable('icon_filter', STOCK_SEARCH); $tpl->SetVariable('addressbook', $this->AddressList()); // Add New $tpl->SetBlock("address_list/actions"); $tpl->SetVariable('action_lbl', _t('ADDRESSBOOK_ITEMS_ADD')); $tpl->SetVariable('action_url', $this->gadget->urlMap('AddAddress')); $tpl->ParseBlock("address_list/actions"); // Import vCard $tpl->SetBlock("address_list/actions"); $tpl->SetVariable('action_lbl', _t('ADDRESSBOOK_IMPORT_VCARD')); $tpl->SetVariable('action_url', $this->gadget->urlMap('VCardImport')); $tpl->ParseBlock("address_list/actions"); $tpl->ParseBlock('address_list'); return $tpl->Get(); }
/** * Builds a simple form to update user account info(nickname, email, password) * * @access public * @return string XHTML form */ function Account() { if (!$GLOBALS['app']->Session->Logged()) { Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))))); } $this->gadget->CheckPermission('EditUserName,EditUserNickname,EditUserEmail,EditUserPassword', '', false); $response = $GLOBALS['app']->Session->PopResponse('Users.Account.Response'); if (!isset($response['data'])) { $jUser = new Jaws_User(); $account = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), true, true); } else { $account = $response['data']; } // Menubar $account['menubar'] = $this->MenuBar('Account'); $account['submenubar'] = $this->SubMenuBar('Account', array('Account', 'Personal', 'Preferences', 'Contacts')); $account['title'] = _t('USERS_ACCOUNT_INFO'); $account['update'] = _t('USERS_USERS_ACCOUNT_UPDATE'); $account['lbl_username'] = _t('USERS_USERS_USERNAME'); $account['lbl_nickname'] = _t('USERS_USERS_NICKNAME'); $account['lbl_email'] = _t('GLOBAL_EMAIL'); $account['lbl_password'] = _t('USERS_USERS_PASSWORD'); $account['emptypassword'] = _t('USERS_NOCHANGE_PASSWORD'); $account['lbl_chkpassword'] = _t('USERS_USERS_PASSWORD_VERIFY'); if (!$this->gadget->GetPermission('EditUserName')) { $account['username_disabled'] = 'disabled="disabled"'; } if (!$this->gadget->GetPermission('EditUserNickname')) { $account['nickname_disabled'] = 'disabled="disabled"'; } if (!$this->gadget->GetPermission('EditUserEmail')) { $account['email_disabled'] = 'disabled="disabled"'; } if (!$this->gadget->GetPermission('EditUserPassword')) { $account['password_disabled'] = 'disabled="disabled"'; } if (empty($account['avatar'])) { $user_current_avatar = $GLOBALS['app']->getSiteURL('/gadgets/Users/Resources/images/photo128px.png'); } else { $user_current_avatar = $GLOBALS['app']->getDataURL() . "avatar/" . $account['avatar']; $user_current_avatar .= !empty($account['last_update']) ? "?" . $account['last_update'] . "" : ''; } $avatar =& Piwi::CreateWidget('Image', $user_current_avatar); $avatar->SetID('avatar'); $account['avatar'] = $avatar->Get(); $account['type'] = $response['type']; $account['text'] = $response['text']; // Load the template $tpl = $this->gadget->template->load('Account.html'); return $tpl->fetch($account); }
/** * 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; }
/** * 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(); }
/** * 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 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(); }
/** * 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(); }
/** * 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; }
/** * 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(); }
/** * 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(); }
/** * 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); }
/** * Creates a valid(registered) n user for an anonymous user * * @access public * @param string $username Username * @param string $user_email User's email * @param string $nickname User's display name * @param string $fname First name * @param string $lname Last name * @param string $gender User gender * @param string $ssn Social Security number * @param string $dob Birth date * @param string $url User's URL * @param string $password Password * @param string $group Default user group * @return mixed True on success or message string */ function CreateUser($username, $user_email, $nickname, $fname, $lname, $gender, $ssn, $dob, $url, $password, $group = null) { if (empty($username) || empty($nickname) || empty($user_email)) { return _t('USERS_USERS_INCOMPLETE_FIELDS'); } $random = false; if (trim($password) == '') { $random = true; $password = Jaws_Utils::RandomText(8); } $jUser = new Jaws_User(); //We already have a $username in the DB? $info = $jUser->GetUser($username); if (Jaws_Error::IsError($info) || isset($info['username'])) { return _t('USERS_USERS_ALREADY_EXISTS', $username); } if ($jUser->UserEmailExists($user_email)) { return _t('USERS_EMAIL_ALREADY_EXISTS', $user_email); } $user_enabled = $this->gadget->registry->fetch('anon_activation') == 'auto' ? 1 : 2; $user_id = $jUser->AddUser(array('username' => $username, 'nickname' => $nickname, 'email' => $user_email, 'password' => $password, 'status' => $user_enabled)); if (Jaws_Error::IsError($user_id)) { return $user_id->getMessage(); } $result = $jUser->UpdatePersonal($user_id, array('fname' => $fname, 'lname' => $lname, 'gender' => $gender, 'ssn' => $ssn, 'dob' => $dob, 'url' => $url)); if ($result !== true) { //do nothing } if (!is_null($group) && is_numeric($group)) { $jUser->AddUserToGroup($user_id, $group); } $mail = Jaws_Mail::getInstance(); $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $site_author = $this->gadget->registry->fetch('site_author', 'Settings'); $activation = $this->gadget->registry->fetch('anon_activation'); $notification = $this->gadget->registry->fetch('register_notification'); $delete_user = false; $message = ''; if ($random === true || $activation != 'admin') { $tpl = $this->gadget->template->load('UserNotification.txt'); $tpl->SetBlock('Notification'); $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $nickname)); if ($random === true) { switch ($activation) { case 'admin': $tpl->SetVariable('message', _t('USERS_REGISTER_BY_ADMIN_RANDOM_MAIL_MSG')); break; case 'user': $tpl->SetVariable('message', _t('USERS_REGISTER_BY_USER_RANDOM_MAIL_MSG')); break; default: $tpl->SetVariable('message', _t('USERS_REGISTER_RANDOM_MAIL_MSG')); } $tpl->SetBlock('Notification/Password'); $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD')); $tpl->SetVariable('password', $password); $tpl->ParseBlock('Notification/Password'); } elseif ($activation == 'user') { $tpl->SetVariable('message', _t('USERS_REGISTER_ACTIVATION_MAIL_MSG')); } else { $tpl->SetVariable('message', _t('USERS_REGISTER_MAIL_MSG')); } $tpl->SetBlock('Notification/IP'); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); $tpl->ParseBlock('Notification/IP'); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $username); if ($activation == 'user') { $verifyKey = $jUser->UpdateEmailVerifyKey($user_id); if (Jaws_Error::IsError($verifyKey)) { $delete_user = true; $message = _t('GLOBAL_ERROR_QUERY_FAILED'); } else { $tpl->SetBlock('Notification/Activation'); $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK')); $tpl->SetVariable('activation_link', $this->gadget->urlMap('ActivateUser', array('key' => $verifyKey), true)); $tpl->ParseBlock('Notification/Activation'); } } $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('Notification'); $body = $tpl->Get(); if (!$delete_user) { $subject = _t('USERS_REGISTER_SUBJECT', $site_name); $mail->SetFrom(); $mail->AddRecipient($user_email); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($body)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { if ($activation == 'user') { $delete_user = true; $message = _t('USERS_REGISTER_ACTIVATION_SENDMAIL_FAILED', $user_email); } elseif ($random === true) { $delete_user = true; $message = _t('USERS_REGISTER_RANDOM_SENDMAIL_FAILED', $user_email); } } } } //Send an email to website owner $mail->reset(); if (!$delete_user && ($notification == 'true' || $activation == 'admin')) { $tpl = $this->gadget->template->load('AdminNotification.txt'); $tpl->SetBlock('Notification'); $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $site_author)); $tpl->SetVariable('message', _t('USERS_REGISTER_ADMIN_MAIL_MSG')); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $username); $tpl->SetVariable('lbl_nickname', _t('USERS_USERS_NICKNAME')); $tpl->SetVariable('nickname', $nickname); $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL')); $tpl->SetVariable('email', $user_email); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); if ($activation == 'admin') { $verifyKey = $jUser->UpdateEmailVerifyKey($user_id); if (!Jaws_Error::IsError($verifyKey)) { $tpl->SetBlock('Notification/Activation'); $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK')); $tpl->SetVariable('activation_link', $this->gadget->urlMap('ActivateUser', array('key' => $verifyKey), true)); $tpl->ParseBlock('Notification/Activation'); } } $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('Notification'); $body = $tpl->Get(); if (!$delete_user) { $subject = _t('USERS_REGISTER_SUBJECT', $site_name); $mail->SetFrom(); $mail->AddRecipient(); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($body)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult) && $activation == 'admin') { // do nothing //$delete_user = true; //$message = _t('USERS_ACTIVATE_NOT_ACTIVATED_SENDMAIL', $user_email); } } } if ($delete_user) { $jUser->DeleteUser($user_id); return $message; } return true; }
/** * 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; }
/** * 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; }
/** * Does any actions required to finish the stage, such as DB queries. * * @access public * @return bool|Jaws_Error Either true on success, or a Jaws_Error * containing the reason for failure. */ function Run() { $request = Jaws_Request::getInstance(); $post = $request->fetch(array('username', 'email', 'nickname', 'password'), 'post'); if (isset($_SESSION['install']['data']['CreateUser'])) { $post = $_SESSION['install']['data']['CreateUser'] + $post; } if ($_SESSION['secure']) { require_once JAWS_PATH . 'include/Jaws/Crypt.php'; $JCrypt = Jaws_Crypt::getInstance(array('pvt_key' => $_SESSION['pvt_key'], 'pub_key' => $_SESSION['pub_key'])); if (!Jaws_Error::isError($JCrypt)) { $post['password'] = $JCrypt->decrypt($post['password']); } else { return $JCrypt; } } $_SESSION['install']['CreateUser'] = array('username' => $post['username'], 'email' => $post['email'], 'nickname' => $post['nickname']); require_once JAWS_PATH . 'include/Jaws/DB.php'; $objDatabase = Jaws_DB::getInstance('default', $_SESSION['install']['Database']); #if (Jaws_Error::IsError($objDatabase)) { # return new Jaws_Error("There was a problem connecting to the database, please check the details and try again.", 0, JAWS_ERROR_WARNING); #} require_once JAWS_PATH . 'include/Jaws.php'; $GLOBALS['app'] = jaws(); $GLOBALS['app']->Registry->Init(); $GLOBALS['app']->loadPreferences(array('language' => $_SESSION['install']['language']), false); Jaws_Translate::getInstance()->LoadTranslation('Install', JAWS_COMPONENT_INSTALL); require_once JAWS_PATH . 'include/Jaws/User.php'; $userModel = new Jaws_User(); $userInfo = $userModel->GetUser($post['username']); if (!Jaws_Error::IsError($userInfo)) { //username exists if (isset($userInfo['username'])) { _log(JAWS_LOG_DEBUG, "Update existing user"); $res = $userModel->UpdateUser($userInfo['id'], array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'])); } else { _log(JAWS_LOG_DEBUG, "Adding first/new admin user to Jaws"); $res = $userModel->AddUser(array('username' => $post['username'], 'nickname' => $post['nickname'], 'email' => $post['email'], 'password' => $post['password'], 'superadmin' => true)); } } else { $res = $userInfo; } if (Jaws_Error::IsError($res)) { _log(JAWS_LOG_DEBUG, "There was a problem while creating your user:"); _log(JAWS_LOG_DEBUG, $res->GetMessage()); return new Jaws_Error(_t('INSTALL_USER_RESPONSE_CREATE_FAILED'), 0, JAWS_ERROR_ERROR); } return true; }
/** * Builds a simple form to update user personal (fname, lname, gender, ...) * * @access public * @return string XHTML form */ function Personal() { if (!$GLOBALS['app']->Session->Logged()) { Jaws_Header::Location($this->gadget->urlMap('LoginBox', array('referrer' => bin2hex(Jaws_Utils::getRequestURL(true))))); } $this->gadget->CheckPermission('EditUserPersonal'); $response = $GLOBALS['app']->Session->PopResponse('Users.Personal.Response'); if (!isset($response['data'])) { $jUser = new Jaws_User(); $personal = $jUser->GetUser($GLOBALS['app']->Session->GetAttribute('user'), true, true); } else { $personal = $response['data']; } // Load the template $tpl = $this->gadget->template->load('Personal.html'); $tpl->SetBlock('personal'); $tpl->SetVariable('title', _t('USERS_PERSONAL_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('Personal', array('Account', 'Personal', 'Preferences', 'Contacts'))); if (empty($personal['avatar'])) { $user_current_avatar = $GLOBALS['app']->getSiteURL('/gadgets/Users/Resources/images/photo128px.png'); } else { $user_current_avatar = $GLOBALS['app']->getDataURL() . "avatar/" . $personal['avatar']; $user_current_avatar .= !empty($personal['last_update']) ? "?" . $personal['last_update'] . "" : ''; } $avatar =& Piwi::CreateWidget('Image', $user_current_avatar); $avatar->SetID('avatar'); $tpl->SetVariable('avatar', $avatar->Get()); $tpl->SetVariable('lbl_fname', _t('USERS_USERS_FIRSTNAME')); $tpl->SetVariable('fname', $personal['fname']); $tpl->SetVariable('lbl_lname', _t('USERS_USERS_LASTNAME')); $tpl->SetVariable('lname', $personal['lname']); $tpl->SetVariable('lbl_gender', _t('USERS_USERS_GENDER')); $tpl->SetVariable('gender_0', _t('USERS_USERS_GENDER_0')); $tpl->SetVariable('gender_1', _t('USERS_USERS_GENDER_1')); $tpl->SetVariable('gender_2', _t('USERS_USERS_GENDER_2')); $tpl->SetVariable('selected_gender_' . (int) $personal['gender'], 'selected="selected"'); $tpl->SetVariable('lbl_ssn', _t('USERS_USERS_SSN')); $tpl->SetVariable('ssn', $personal['ssn']); if (!empty($personal['dob'])) { $personal['dob'] = Jaws_Date::getInstance()->Format($personal['dob'], 'Y-m-d'); } $tpl->SetVariable('lbl_dob', _t('USERS_USERS_BIRTHDAY')); $tpl->SetVariable('dob', $personal['dob']); $tpl->SetVariable('dob_sample', _t('USERS_USERS_BIRTHDAY_SAMPLE')); // website $tpl->SetVariable('lbl_url', _t('GLOBAL_URL')); $tpl->SetVariable('url', empty($personal['url']) ? 'http://' : $personal['url']); // upload/delete avatar $tpl->SetVariable('lbl_upload_avatar', _t('USERS_USERS_AVATAR_UPLOAD')); $tpl->SetVariable('lbl_delete_avatar', _t('USERS_USERS_AVATAR_DELETE')); // signature $tpl->SetVariable('lbl_signature', _t('USERS_USERS_SIGNATURE')); $tpl->SetVariable('signature', $personal['signature']); // about $tpl->SetVariable('lbl_about', _t('USERS_USERS_ABOUT')); $tpl->SetVariable('about', $personal['about']); // experiences $tpl->SetVariable('lbl_experiences', _t('USERS_USERS_EXPERIENCES')); $tpl->SetVariable('experiences', $personal['experiences']); // occupations $tpl->SetVariable('lbl_occupations', _t('USERS_USERS_OCCUPATIONS')); $tpl->SetVariable('occupations', $personal['occupations']); // interests $tpl->SetVariable('lbl_interests', _t('USERS_USERS_INTERESTS')); $tpl->SetVariable('interests', $personal['interests']); if (!empty($response)) { $tpl->SetVariable('type', $response['type']); $tpl->SetVariable('text', $response['text']); } $tpl->ParseBlock('personal'); return $tpl->Get(); }
/** * 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(); }