public function test_getUnameFromId() { $value1 = XoopsUser::getUnameFromId(0); $this->assertSame(\Xoops::getInstance()->getConfig('anonymous'), $value1); $value = XoopsUser::getUnameFromId(1); $this->assertInternalType('string', $value); $this->assertNotSame($value, $value1); }
public function getValues($keys = null, $format = null, $maxDepth = null) { $page = Page::getInstance(); $ret = parent::getValues($keys, $format, $maxDepth); $ret['rating'] = number_format($this->getVar('content_rating'), 1); // these next two lines are rather silly $ret['content_authorid'] = $this->getVar('content_author'); $ret['content_author'] = XoopsUser::getUnameFromId($this->getVar('content_author'), true); $ret['content_date'] = XoopsLocale::formatTimestamp($this->getVar('content_create'), $page->getConfig('page_dateformat')); $ret['content_time'] = XoopsLocale::formatTimestamp($this->getVar('content_create'), $page->getConfig('page_timeformat')); $ret['content_rating'] = number_format($this->getVar('content_rating'), 2); return $ret; }
/** * @param int $uid * @param string $subject * @param string $body * @return bool */ private function sendPM($uid, $subject, $body) { $xoops = Xoops::getInstance(); $pm_handler = $xoops->getHandlerPrivateMessage(); $pm = $pm_handler->create(); $pm->setVar("subject", $subject); // RMV-NOTIFY $pm->setVar('from_userid', !empty($this->fromUser) ? $this->fromUser->getVar('uid') : (!$xoops->isUser() ? 1 : $xoops->user->getVar('uid'))); $pm->setVar("msg_text", $body); $pm->setVar("to_userid", $uid); $pm->setVar('msg_time', time()); if (!$pm_handler->insert($pm)) { return false; } return true; }
/** * __construct * * @param XoopsUser|XoopsObject &$obj user object */ public function __construct(XoopsUser $obj) { $xoops = Xoops::getInstance(); if ($obj->isNew()) { //Add user $uid_value = ""; $uname_value = ""; $name_value = ""; $email_value = ""; $email_cbox_value = 0; $url_value = ""; $timezone_value = $xoops->getConfig('default_TZ'); $icq_value = ""; $aim_value = ""; $yim_value = ""; $msnm_value = ""; $location_value = ""; $occ_value = ""; $interest_value = ""; $sig_value = ""; $sig_cbox_value = 0; $bio_value = ""; $rank_value = 0; $mailok_value = 0; $form_title = SystemLocale::ADD_USER; $form_isedit = false; $groups = array(FixedGroups::USERS); } else { //Edit user $uid_value = $obj->getVar("uid", "E"); $uname_value = $obj->getVar("uname", "E"); $name_value = $obj->getVar("name", "E"); $email_value = $obj->getVar("email", "E"); $email_cbox_value = $obj->getVar("user_viewemail") ? 1 : 0; $url_value = $obj->getVar("url", "E"); $timezone_value = $obj->getVar("timezone_offset"); $icq_value = $obj->getVar("user_icq", "E"); $aim_value = $obj->getVar("user_aim", "E"); $yim_value = $obj->getVar("user_yim", "E"); $msnm_value = $obj->getVar("user_msnm", "E"); $location_value = $obj->getVar("user_from", "E"); $occ_value = $obj->getVar("user_occ", "E"); $interest_value = $obj->getVar("user_intrest", "E"); $sig_value = $obj->getVar("user_sig", "E"); $sig_cbox_value = $obj->getVar("attachsig") == 1 ? 1 : 0; $bio_value = $obj->getVar("bio", "E"); $rank_value = $obj->getVar('rank'); $mailok_value = $obj->getVar('user_mailok', 'E'); $form_title = sprintf(SystemLocale::F_UPDATE_USER, $obj->getVar("uname")); $form_isedit = true; $groups = array_values($obj->getGroups()); } //Affichage du formulaire parent::__construct($form_title, "form_user", "admin.php", "post", true); $this->addElement(new Xoops\Form\Text(XoopsLocale::USER_NAME, "username", 4, 25, $uname_value), true); $this->addElement(new Xoops\Form\Text(XoopsLocale::NAME, "name", 5, 60, $name_value)); $email_tray = new Xoops\Form\ElementTray(XoopsLocale::EMAIL, "<br />"); $email_text = new Xoops\Form\Text("", "email", 5, 60, $email_value); $email_tray->addElement($email_text, true); $email_cbox = new Xoops\Form\Checkbox("", "user_viewemail", $email_cbox_value); $email_cbox->addOption(1, XoopsLocale::ALLOW_OTHER_USERS_TO_VIEW_EMAIL); $email_tray->addElement($email_cbox); $this->addElement($email_tray, true); $this->addElement(new Xoops\Form\Text(XoopsLocale::WEB_URL, "url", 5, 100, $url_value)); $this->addElement(new Xoops\Form\SelectTimeZone(XoopsLocale::TIME_ZONE, "timezone_offset", $timezone_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::ICQ, "user_icq", 3, 15, $icq_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::AIM, "user_aim", 3, 18, $aim_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::YIM, "user_yim", 3, 25, $yim_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::MSNM, "user_msnm", 3, 100, $msnm_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::LOCATION, "user_from", 5, 100, $location_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::OCCUPATION, "user_occ", 5, 100, $occ_value)); $this->addElement(new Xoops\Form\Text(XoopsLocale::INTEREST, "user_intrest", 5, 150, $interest_value)); $sig_tray = new Xoops\Form\ElementTray(XoopsLocale::SIGNATURE, "<br />"); $sig_tarea = new Xoops\Form\TextArea("", "user_sig", $sig_value, 5, 5); $sig_tray->addElement($sig_tarea); $sig_cbox = new Xoops\Form\Checkbox("", "attachsig", $sig_cbox_value); $sig_cbox->addOption(1, XoopsLocale::ALWAYS_ATTACH_MY_SIGNATURE); $sig_tray->addElement($sig_cbox); $this->addElement($sig_tray); $this->addElement(new Xoops\Form\TextArea(XoopsLocale::EXTRA_INFO, "bio", $bio_value, 5, 5)); $ranklist = $xoops->service('userrank')->getAssignableUserRankList()->getValue(); if ($ranklist !== null) { $rank_select = new Xoops\Form\Select(XoopsLocale::RANK, "rank", $rank_value); $rank_select->addOption(0, "--------------"); if (count($ranklist) > 0) { $rank_select->addOptionArray($ranklist); } $this->addElement($rank_select); } else { $this->addElement(new Xoops\Form\Hidden("rank", $rank_value)); } // adding a new user requires password fields if (!$form_isedit) { $this->addElement(new Xoops\Form\Password(XoopsLocale::PASSWORD, "password", 3, 32), true); $this->addElement(new Xoops\Form\Password(XoopsLocale::RETYPE_PASSWORD, "pass2", 3, 32), true); } else { $this->addElement(new Xoops\Form\Password(XoopsLocale::PASSWORD, "password", 3, 32)); $this->addElement(new Xoops\Form\Password(XoopsLocale::RETYPE_PASSWORD, "pass2", 3, 32)); } $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::ONLY_USERS_THAT_ACCEPT_EMAIL, 'user_mailok', $mailok_value)); //Groups administration addition XOOPS 2.0.9: Mith $gperm_handler = $xoops->getHandlerGroupPermission(); $group_select = array(); //If user has admin rights on groups if ($gperm_handler->checkRight("system_admin", XOOPS_SYSTEM_GROUP, $xoops->user->getGroups(), 1)) { //add group selection $group_select[] = new Xoops\Form\SelectGroup(XoopsLocale::GROUPS, 'groups', false, $groups, 5, true); } else { //add each user groups foreach ($groups as $key => $group) { $group_select[] = new Xoops\Form\Hidden('groups[' . $key . ']', $group); } } foreach ($group_select as $group) { $this->addElement($group); unset($group); } $this->addElement(new Xoops\Form\Hidden("fct", "users")); $this->addElement(new Xoops\Form\Hidden("op", "users_save")); $this->addElement(new Xoops\Form\Button("", "submit", XoopsLocale::A_SUBMIT, "submit")); if (!empty($uid_value)) { $this->addElement(new Xoops\Form\Hidden("uid", $uid_value)); } }
} unset($pm); } $xoops->redirect("viewpmsg.php", 1, XoopsLocale::S_YOUR_MESSAGES_DELETED); } $xoops->header('module:system/system_viewpmsg.tpl'); $criteria = new Criteria('to_userid', $xoops->user->getVar('uid')); $criteria->setSort('msg_time'); $criteria->setOrder('DESC'); $pm_arr = $pm_handler->getObjects($criteria); $total_messages = count($pm_arr); $xoops->tpl()->assign('display', true); $xoops->tpl()->assign('anonymous', $xoops->getConfig('anonymous')); $xoops->tpl()->assign('uid', $xoops->user->getVar("uid")); $xoops->tpl()->assign('total_messages', $total_messages); $msg_no = 0; foreach (array_keys($pm_arr) as $i) { $messages['msg_id'] = $pm_arr[$i]->getVar("msg_id"); $messages['read_msg'] = $pm_arr[$i]->getVar("read_msg"); $messages['msg_image'] = $pm_arr[$i]->getVar("msg_image"); $messages['posteruid'] = $pm_arr[$i]->getVar('from_userid'); $messages['postername'] = XoopsUser::getUnameFromId($pm_arr[$i]->getVar('from_userid')); $messages['subject'] = $pm_arr[$i]->getVar("subject"); $messages['msg_time'] = XoopsLocale::formatTimestamp($pm_arr[$i]->getVar('msg_time')); $messages['msg_no'] = $msg_no; $xoops->tpl()->append('messages', $messages); ++$msg_no; } $xoops->tpl()->assign('token', $xoops->security()->getTokenHTML()); $xoops->footer(); }
if ($reply == 1) { $subject = $pm->getVar('subject', 'E'); if (!preg_match("/^" . XoopsLocale::C_RE . "/i", $subject)) { $subject = XoopsLocale::C_RE . ' ' . $subject; } $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, $pm_uname)); $form->addElement(new Xoops\Form\Hidden('to_userid', $pm->getVar("from_userid"))); } else { if ($sendmod == 1) { $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, XoopsUser::getUnameFromId($_POST["to_userid"]))); $form->addElement(new Xoops\Form\Hidden('to_userid', $_POST["to_userid"])); $subject = $myts->htmlSpecialChars($_POST['subject']); $message = $myts->htmlSpecialChars($_POST['message']); } else { if ($send2 == 1) { $form->addElement(new Xoops\Form\Label(XoopsLocale::C_TO, XoopsUser::getUnameFromId($to_userid, false))); $form->addElement(new Xoops\Form\Hidden('to_userid', $to_userid)); } else { $form->addElement(new Xoops\Form\SelectUser(XoopsLocale::C_TO, 'to_userid')); } $subject = ""; $message = ""; } } $form->addElement(new Xoops\Form\Text(XoopsLocale::SUBJECT, 'subject', 4, 100, $subject), true); $icons = new Xoops\Form\Radio(XoopsLocale::MESSAGE_ICON, 'msg_image', '', true); \Xoops\Core\Lists\SubjectIcon::setOptionsArray($icons); $form->addElement($icons, false); $form->addElement(new Xoops\Form\DhtmlTextArea(XoopsLocale::MESSAGE, 'message', $message, 8, 37), true); $form->addElement(new Xoops\Form\Hidden('op', 'submit')); $buttons = new Xoops\Form\ElementTray('');
$online_total = $online_handler->getCount(); $limit = $online_total > 20 ? 20 : $online_total; $criteria = new CriteriaCompo(); $criteria->setLimit($limit); $criteria->setStart($start); $onlines = $online_handler->getAll($criteria, null, false, false); $count = count($onlines); $module_handler = $xoops->getHandlerModule(); $modules = $module_handler->getNameList(new Criteria('isactive', 1)); $onlineUsers = array(); for ($i = 0; $i < $count; ++$i) { $onlineUsers[$i]['uid'] = $onlines[$i]['online_uid']; $onlineUsers[$i]['ip'] = $onlines[$i]['online_ip']; $onlineUsers[$i]['updated'] = $onlines[$i]['online_updated']; $onlineUsers[$i]['module'] = $onlines[$i]['online_module'] > 0 ? $modules[$onlines[$i]['online_module']] : ''; if ($onlines[$i]['online_uid'] != 0 && is_object($user = new XoopsUser($onlines[$i]['online_uid']))) { $onlineUsers[$i]['name'] = $user->getVar('uname'); $response = $xoops->service("Avatar")->getAvatarUrl($user); $avatar = $response->getValue(); $avatar = empty($avatar) ? $xoops_upload_url . '/blank.gif' : $avatar; $onlineUsers[$i]['avatar'] = $avatar; } else { $onlineUsers[$i]['name'] = $xoops->getConfig('anonymous'); $onlineUsers[$i]['avatar'] = $xoops_upload_url . '/blank.gif'; } } $tpl = new XoopsTpl(); if ($online_total > 20) { $nav = new XoopsPageNav($online_total, 20, $start, 'start', 'action=showpopups&type=online'); $tpl->assign('nav', $nav->renderNav()); }
/** * get the groups associated with the current user * * @return int[] */ public function getUserGroups() { $groups = $this->isUser() ? $this->user->getGroups() : array(FixedGroups::ANONYMOUS); return $groups; }
/** * Get a list of users belonging to certain groups and matching criteria * Temporary solution * * @param array $groups IDs of groups * @param CriteriaElement $criteria criteria to match * @param bool $asobject return the users as objects? * @param bool $id_as_key use the UID as key for the array if $asobject is TRUE * * @return array Array of XoopsUser objects (if $asobject is TRUE) * or of associative arrays matching the record structure in the database. */ public function getUsersByGroupLink($groups, CriteriaElement $criteria = null, $asobject = false, $id_as_key = false) { $qb = $this->userHandler->db2->createXoopsQueryBuilder(); $eb = $qb->expr(); $qb->select('DISTINCT ' . ($asobject ? 'u.*' : 'u.uid'))->fromPrefix('system_user', 'u')->leftJoinPrefix('u', 'system_usergroup', 'm', 'm.uid = u.uid'); $where = false; if (!empty($groups)) { $qb->where($eb->in('m.groupid', $groups)); $where = true; } if (isset($criteria) && $criteria instanceof CriteriaElement) { $whereMode = $where ? 'AND' : ''; $sql[] = $criteria->renderQb($qb, $whereMode); } $ret = array(); if (!($result = $qb->execute())) { return $ret; } while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { if ($asobject) { $user = new XoopsUser(); $user->assignVars($myrow); if (!$id_as_key) { $ret[] = $user; } else { $ret[$myrow['uid']] = $user; } unset($user); } else { $ret[] = $myrow['uid']; } } return $ret; }
/** * Returns a value for output of this field * * @param XoopsUser $user {@link XoopsUser} object to get the value of * @param profileProfile $profile object to get the value of * * @return string **/ public function getOutputValue(XoopsUser $user, ProfileProfile $profile) { $xoops = Xoops::getInstance(); $xoops->loadLanguage('modinfo', 'profile'); $value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name')) : $profile->getVar($this->getVar('field_name')); switch ($this->getVar('field_type')) { default: case "textbox": if ($this->getVar('field_name') == 'url' && $value != '') { return '<a href="' . $xoops->formatURL($value) . '" rel="external">' . $value . '</a>'; } else { return $value; } break; case "textarea": case "dhtml": case 'theme': case "language": case "list": return $value; break; case "select": case "radio": $options = $this->getVar('field_options'); if (isset($options[$value])) { $value = htmlspecialchars(defined($options[$value]) ? constant($options[$value]) : $options[$value]); } else { $value = ""; } return $value; break; case "select_multi": case "checkbox": $options = $this->getVar('field_options'); $ret = array(); if (count($options) > 0) { foreach (array_keys($options) as $key) { if (in_array($key, $value)) { $ret[$key] = htmlspecialchars(defined($options[$key]) ? constant($options[$key]) : $options[$key]); } } } return $ret; break; case "group": $member_handler = $xoops->getHandlerMember(); $options = $member_handler->getGroupList(); $ret = isset($options[$value]) ? $options[$value] : ''; return $ret; break; case "group_multi": $member_handler = $xoops->getHandlerMember(); $options = $member_handler->getGroupList(); $ret = array(); foreach (array_keys($options) as $key) { if (in_array($key, $value)) { $ret[$key] = htmlspecialchars($options[$key]); } } return $ret; break; case "longdate": //return YYYY/MM/DD format - not optimal as it is not using local date format, but how do we do that //when we cannot convert it to a UNIX timestamp? return str_replace("-", "/", $value); case "date": return XoopsLocale::formatTimestamp($value, 's'); break; case "datetime": if (!empty($value)) { return XoopsLocale::formatTimestamp($value, 'm'); } else { return _PROFILE_MI_NEVER_LOGGED_IN; } break; case "autotext": $value = $user->getVar($this->getVar('field_name'), 'n'); //autotext can have HTML in it $value = str_replace("{X_UID}", $user->getVar("uid"), $value); $value = str_replace("{X_URL}", \XoopsBaseConfig::get('url'), $value); $value = str_replace("{X_UNAME}", $user->getVar("uname"), $value); return $value; break; case "rank": $userrank = $user->rank(); $user_rankimage = ""; if (isset($userrank['image']) && $userrank['image'] != "") { $user_rankimage = '<img src="' . $userrank['image'] . '" alt="' . $userrank['title'] . '" /><br />'; } return $user_rankimage . $userrank['title']; break; case "yesno": return $value ? XoopsLocale::YES : XoopsLocale::NO; break; case "timezone": $timezones = XoopsLists::getTimeZoneList(); $value = empty($value) ? "0" : (string) $value; return $timezones[str_replace('.0', '', $value)]; break; } }
$xoops->theme()->addBaseScriptAssets(array('@jquery', 'media/xoops/xoops.js', 'modules/system/js/admin.js')); $admin_page = new \Xoops\Module\Admin(); $admin_page->renderNavigation('send_mails.php'); switch ($op) { case 'list': default: $display_criteria = 1; $form = new Xoops\Form\ThemeForm(_AM_MAILUSERS_LIST, "mailusers", "send_mails.php", 'post', true); //---------------------------------------- if (!empty($memberslist_id) && Request::getMethod() == 'POST') { $user_count = count($memberslist_id); $display_names = ""; for ($i = 0; $i < $user_count; ++$i) { $uid_hidden = new Xoops\Form\Hidden("mail_to_user[]", $memberslist_id[$i]); $form->addElement($uid_hidden); $display_names .= "<a href='" . \XoopsBaseConfig::get('url') . "/userinfo.php?uid=" . $memberslist_id[$i] . "' rel='external'>" . XoopsUser::getUnameFromId($memberslist_id[$i]) . "</a>, "; unset($uid_hidden); } $users_label = new Xoops\Form\Label(_AM_MAILUSERS_SENDTOUSERS2, substr($display_names, 0, -2)); $form->addElement($users_label); $form->addElement($users_label); $display_criteria = 0; } //---------------------------------------- if (!empty($display_criteria)) { $selected_groups = array(); $group_select = new Xoops\Form\SelectGroup('<div class="bold spacer">' . _AM_MAILUSERS_GROUPIS . '<span class="bold green">*</span></div>', "mail_to_group", false, $selected_groups, 5, true); $lastlog_min = new Xoops\Form\DateSelect(_AM_MAILUSERS_LASTLOGMIN . '<span class="bold green">*</span>', 'mail_lastlog_min'); $lastlog_min->setValue(''); $lastlog_max = new Xoops\Form\DateSelect(_AM_MAILUSERS_LASTLOGMAX . '<span class="bold green">*</span>', 'mail_lastlog_max'); $lastlog_max->setValue('');
/** * Get {@link Xoops\Form\ThemeForm} for editing a user * * @param XoopsUser $user * @param ProfileProfile|null $profile * @param bool $action * @return Xoops\Form\ThemeForm */ function profile_getUserForm(XoopsUser $user, ProfileProfile $profile = null, $action = false) { $xoops = Xoops::getInstance(); if ($action === false) { $action = $_SERVER['REQUEST_URI']; } $title = $user->isNew() ? _PROFILE_AM_ADDUSER : XoopsLocale::EDIT_PROFILE; $form = new Xoops\Form\ThemeForm($title, 'userinfo', $action, 'post', true); /* @var $profile_handler ProfileProfileHandler */ $profile_handler = \Xoops::getModuleHelper('profile')->getHandler('profile'); // Dynamic fields if (!$profile) { $profile = $profile_handler->getProfile($user->getVar('uid')); } // Get fields $fields = $profile_handler->loadFields(); // Get ids of fields that can be edited $gperm_handler = $xoops->getHandlerGroupPermission(); $editable_fields = $gperm_handler->getItemIds('profile_edit', $xoops->user->getGroups(), $xoops->module->getVar('mid')); if ($user->isNew() || $xoops->user->isAdmin()) { $elements[0][] = array('element' => new Xoops\Form\Text(XoopsLocale::USERNAME, 'uname', 3, $xoops->user->isAdmin() ? 60 : $xoops->getConfig('maxuname'), $user->getVar('uname', 'e')), 'required' => 1); $email_text = new Xoops\Form\Text('', 'email', 4, 60, $user->getVar('email')); } else { $elements[0][] = array('element' => new Xoops\Form\Label(XoopsLocale::USERNAME, $user->getVar('uname')), 'required' => 0); $email_text = new Xoops\Form\Label('', $user->getVar('email')); } $email_tray = new Xoops\Form\ElementTray(XoopsLocale::EMAIL, '<br />'); $email_tray->addElement($email_text, $user->isNew() || $xoops->user->isAdmin() ? 1 : 0); $weights[0][] = 0; $elements[0][] = array('element' => $email_tray, 'required' => 0); $weights[0][] = 0; if ($xoops->user->isAdmin() && $user->getVar('uid') != $xoops->user->getVar('uid')) { //If the user is an admin and is editing someone else $pwd_text = new Xoops\Form\Password('', 'password', 3, 32); $pwd_text2 = new Xoops\Form\Password('', 'vpass', 3, 32); $pwd_tray = new Xoops\Form\ElementTray(XoopsLocale::PASSWORD . '<br />' . XoopsLocale::TYPE_NEW_PASSWORD_TWICE_TO_CHANGE_IT); $pwd_tray->addElement($pwd_text); $pwd_tray->addElement($pwd_text2); $elements[0][] = array('element' => $pwd_tray, 'required' => 0); //cannot set an element tray required $weights[0][] = 0; $level_radio = new Xoops\Form\Radio(_PROFILE_MA_USERLEVEL, 'level', $user->getVar('level')); $level_radio->addOption(1, _PROFILE_MA_ACTIVE); $level_radio->addOption(0, _PROFILE_MA_INACTIVE); //$level_radio->addOption(-1, _PROFILE_MA_DISABLED); $elements[0][] = array('element' => $level_radio, 'required' => 0); $weights[0][] = 0; } $elements[0][] = array('element' => new Xoops\Form\Hidden('uid', $user->getVar('uid')), 'required' => 0); $weights[0][] = 0; $elements[0][] = array('element' => new Xoops\Form\Hidden('op', 'save'), 'required' => 0); $weights[0][] = 0; $cat_handler = \Xoops::getModuleHelper('profile')->getHandler('category'); $categories = array(); $all_categories = $cat_handler->getObjects(null, true, false); $count_fields = count($fields); /* @var ProfileField $field */ foreach ($fields as $field) { if (in_array($field->getVar('field_id'), $editable_fields)) { // Set default value for user fields if available if ($user->isNew()) { $default = $field->getVar('field_default'); if ($default !== '' && $default !== null) { $user->setVar($field->getVar('field_name'), $default); } } if ($profile->getVar($field->getVar('field_name'), 'n') === null) { $default = $field->getVar('field_default', 'n'); $profile->setVar($field->getVar('field_name'), $default); } $fieldinfo['element'] = $field->getEditElement($user, $profile); $fieldinfo['required'] = $field->getVar('field_required'); $key = @$all_categories[$field->getVar('cat_id')]['cat_weight'] * $count_fields + $field->getVar('cat_id'); $elements[$key][] = $fieldinfo; $weights[$key][] = $field->getVar('field_weight'); $categories[$key] = @$all_categories[$field->getVar('cat_id')]; } } if ($xoops->isUser() && $xoops->user->isAdmin()) { $xoops->loadLanguage('admin', 'profile'); $gperm_handler = $xoops->getHandlerGroupPermission(); //If user has admin rights on groups include_once $xoops->path('modules/system/constants.php'); if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $xoops->user->getGroups(), 1)) { //add group selection $group_select = new Xoops\Form\SelectGroup(XoopsLocale::USER_GROUPS, 'groups', false, $user->getGroups(), 5, true); $elements[0][] = array('element' => $group_select, 'required' => 0); //set as latest; $weights[0][] = $count_fields + 1; } } ksort($elements); foreach (array_keys($elements) as $k) { array_multisort($weights[$k], SORT_ASC, array_keys($elements[$k]), SORT_ASC, $elements[$k]); $title = isset($categories[$k]) ? $categories[$k]['cat_title'] : _PROFILE_MA_DEFAULT; $desc = isset($categories[$k]) ? $categories[$k]['cat_description'] : ""; //$form->addElement(new Xoops\Form\Label("<div class='break'>{$title}</div>", $desc), false); $desc = $desc != '' ? ' - ' . $desc : ''; $form->insertBreak($title . $desc); foreach (array_keys($elements[$k]) as $i) { $form->addElement($elements[$k][$i]['element'], $elements[$k][$i]['required']); } } $form->addElement(new Xoops\Form\Hidden('uid', $user->getVar('uid'))); $form->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::SAVE_CHANGES, 'submit')); return $form; }
/** * Modify user information * * @param XoopsUser $xoopsUser user object * @param string $data data * @param string $uname username * @param string $pwd password * * @return bool|XoopsUser */ public function change(XoopsUser $xoopsUser, $data, $uname, $pwd = null) { $xoops = \Xoops::getInstance(); $ret = false; $member_handler = $xoops->getHandlerMember(); $xoopsUser->setVar('pass', password_hash(stripslashes($pwd), PASSWORD_DEFAULT)); $xoopsUser->setVar('last_pass_change', time()); $this->setVarsMapping($xoopsUser, $data); if ($member_handler->insertUser($xoopsUser)) { return $xoopsUser; } else { $xoops->redirect(\XoopsBaseConfig::get('url') . '/user.php', 5, $xoopsUser->getHtmlErrors()); } return $ret; }
/** * Subscribe for notification for an event(s) * * @param string $category category of notification * @param int $item_id ID of the item * @param mixed $events event string or array of events * @param int $mode force a particular notification mode * (e.g. once_only) (default to current user preference) * @param int $module_id ID of the module (default to current module) * @param int $user_id ID of the user (default to current user) * * @return bool * * @todo: how about a function to subscribe a whole group of users??? * e.g. if we want to add all moderators to be notified of subscription * of new threads... */ public function subscribe($category, $item_id, $events, $mode = null, $module_id = null, $user_id = null) { $xoops = Xoops::getInstance(); if (!isset($user_id)) { if (!$xoops->isUser()) { return false; // anonymous cannot subscribe } else { $user_id = $xoops->user->getVar('uid'); } } if (!isset($module_id)) { $module_id = $xoops->module->getVar('mid'); } //todo, remove this from user profile if (!isset($mode)) { $user = new XoopsUser($user_id); $mode = $user->getVar('notify_mode'); } if (!is_array($events)) { $events = array($events); } foreach ($events as $event) { if ($notification = $this->getNotification($module_id, $category, $item_id, $event, $user_id)) { if ($notification->getVar('mode') != $mode) { $this->updateByField($notification, 'mode', $mode); } } else { $notification = $this->create(); $notification->setVar('modid', $module_id); $notification->setVar('category', $category); $notification->setVar('itemid', $item_id); $notification->setVar('uid', $user_id); $notification->setVar('event', $event); $notification->setVar('mode', $mode); $this->insert($notification); } } return true; }
// Criteria $content_count = $content_Handler->getCountPublished(); $content_arr = $content_Handler->getPagePublished($start, $nb_limit); // Assign Template variables $xoops->tpl()->assign('content_count', $content_count); $keywords = array(); if ($content_count > 0) { //Cleaning the content of $content, they are assign by blocks and mess the output $xoops->tpl()->assign('content', array()); foreach (array_keys($content_arr) as $i) { $content_id = $content_arr[$i]->getVar('content_id'); $content['id'] = $content_id; $content['title'] = $content_arr[$i]->getVar('content_title'); $content['shorttext'] = $content_arr[$i]->getVar('content_shorttext'); $content['authorid'] = $content_arr[$i]->getVar('content_author'); $content['author'] = XoopsUser::getUnameFromId($content_arr[$i]->getVar('content_author')); $content['date'] = XoopsLocale::formatTimestamp($content_arr[$i]->getVar('content_create'), $helper->getConfig('page_dateformat')); $content['time'] = XoopsLocale::formatTimestamp($content_arr[$i]->getVar('content_create'), $helper->getConfig('page_timeformat')); $xoops->tpl()->appendByRef('content', $content); $keywords[] = $content_arr[$i]->getVar('content_title'); unset($content); } // Display Page Navigation if ($content_count > $nb_limit) { $nav = new XoopsPageNav($content_count, $nb_limit, $start, 'start'); $xoops->tpl()->assign('nav_menu', $nav->renderNav(4)); } } else { $xoops->tpl()->assign('error_message', PageLocale::E_NO_CONTENT); } // Metas
/** * Send a message to user's email * * @param XoopsObject|PmMessage $pm * @param null|XoopsUser $user * @return bool */ public function sendEmail(PmMessage $pm, XoopsUser $user = null) { $xoops = Xoops::getInstance(); if (!is_object($user)) { $user = $xoops->user; } $msg = sprintf(_PM_EMAIL_DESC, $user->getVar("uname")); $msg .= "\n\n"; $msg .= XoopsLocale::formatTimestamp($pm->getVar("msg_time")); $msg .= "\n"; $from = new XoopsUser($pm->getVar("from_userid")); $to = new XoopsUser($pm->getVar("to_userid")); $msg .= sprintf(_PM_EMAIL_FROM, $from->getVar("uname") . " (" . \XoopsBaseConfig::get('url') . "/userinfo.php?uid=" . $pm->getVar("from_userid") . ")"); $msg .= "\n"; $msg .= sprintf(_PM_EMAIL_TO, $to->getVar("uname") . " (" . \XoopsBaseConfig::get('url') . "/userinfo.php?uid=" . $pm->getVar("to_userid") . ")"); $msg .= "\n"; $msg .= _PM_EMAIL_MESSAGE . ":\n"; $msg .= "\n" . $pm->getVar("subject") . "\n"; $msg .= "\n" . strip_tags(str_replace(array("<p>", "</p>", "<br />", "<br />"), "\n", $pm->getVar("msg_text"))) . "\n\n"; $msg .= "--------------\n"; $msg .= $xoops->getConfig('sitename') . ": " . \XoopsBaseConfig::get('url') . "\n"; $xoopsMailer = $xoops->getMailer(); $xoopsMailer->useMail(); $xoopsMailer->setToEmails($user->getVar("email")); $xoopsMailer->setFromEmail($xoops->getConfig('adminmail')); $xoopsMailer->setFromName($xoops->getConfig('sitename')); $xoopsMailer->setSubject(sprintf(_PM_EMAIL_SUBJECT, $pm->getVar("subject"))); $xoopsMailer->setBody($msg); return $xoopsMailer->send(); }
$res[$i]['image'] = $xoops->url('images/icons/posticon2.gif'); } if (!preg_match("/^http[s]*:\\/\\//i", $results[$i]['link'])) { $res[$i]['link'] = $xoops->url('modules/' . $module->getVar('dirname') . '/' . $results[$i]['link']); } else { $res[$i]['link'] = $results[$i]['link']; } $res[$i]['title'] = $myts->htmlSpecialChars($results[$i]['title']); if (isset($queries_pattern)) { $res[$i]['title_highligh'] = preg_replace($queries_pattern, "<span class='searchHighlight'>\$1</span>", $myts->htmlSpecialChars($results[$i]['title'])); } else { $res[$i]['title_highligh'] = $myts->htmlSpecialChars($results[$i]['title']); } if (!empty($results[$i]['uid'])) { $res[$i]['uid'] = @(int) $results[$i]['uid']; $res[$i]['uname'] = XoopsUser::getUnameFromId($results[$i]['uid'], true); } $res[$i]['time'] = !empty($results[$i]['time']) ? " (" . XoopsLocale::formatTimestamp((int) $results[$i]['time']) . ")" : ""; $res[$i]['content'] = empty($results[$i]['content']) ? "" : preg_replace($queries_pattern, "<span class='searchHighlight'>\$1</span>", $results[$i]['content']); } if (count($res) > 0) { $modules_result[$mid]['result'] = $res; } $search_url = $search->url('index.php?query=' . urlencode(stripslashes(implode(' ', $queries)))); $search_url .= "&mid={$mid}&action={$action}&andor={$andor}"; if ($action === 'showallbyuser') { $search_url .= "&uid={$uid}"; } if ($start > 0) { $prev = $start - 20; $search_url_prev = $search_url . "&start={$prev}";
public function renderHeader($title, $text, $uid, $timestamp) { $ret = '<table cellpadding="4" cellspacing="1" width="98%" class="outer"> <tr><td class="head">' . $title . '</td></tr><tr><td><br />'; if ($uid) { $ret .= _MD_COMMENTS_POSTER . ': <strong>' . XoopsUser::getUnameFromId($uid) . '</strong> '; } $ret .= _MD_COMMENTS_POSTED . ': <strong>' . XoopsLocale::formatTimestamp($timestamp) . '</strong><br /><br />' . $text . '<br /></td></tr>'; $ret .= '</table>'; return $ret; }