Файловый менеджер - Редактировать - /var/www/html/administrator/components/com_community/controllers/users.php
Ðазад
<?php /** * @copyright (C) 2013 iJoomla, Inc. - All rights reserved. * @license GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) * @author iJoomla.com <webmaster@ijoomla.com> * @url https://www.jomsocial.com/license-agreement * The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 * More info at https://www.jomsocial.com/license-agreement */ use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Session\Session; use Joomla\CMS\Table\Table; use Joomla\CMS\Uri\Uri; use Joomla\CMS\User\UserHelper; use Joomla\CMS\User\User; // Disallow direct access to this file defined('_JEXEC') or die('Restricted access'); jimport( 'joomla.application.component.controller' ); require_once( JPATH_ROOT . '/components/com_community/libraries/core.php' ); /** * JomSocial Component Controller */ class CommunityControllerUsers extends CommunityController { public function __construct() { parent::__construct(); } public function display( $cachable = false, $urlparams = array() ) { $jinput = Factory::getApplication()->input; $viewName = $jinput->get( 'view' , 'community' ); // Set the default layout and view name $layout = $jinput->get( 'layout' , 'default' ); // Get the document object $document = Factory::getDocument(); // Get the view type $viewType = $document->getType(); // Get the view $view = $this->getView( $viewName , $viewType ); $model = $this->getModel( $viewName ); if( $model ) { $view->setModel( $model , $viewName ); $multiprofiles = $this->getModel( 'MultiProfile' ); $view->setModel( $multiprofiles , false ); } // Set the layout $view->setLayout( $layout ); // Display the view $view->display(); // Display Toolbar. View must have setToolBar method if( method_exists( $view , 'setToolBar') ) { $view->setToolBar(); } } public function importUsersForm(){ $response = new JAXResponse(); //get the list of available groups $model = $this->getModel( 'groups', 'CommunityAdminModel' ); $groups = $model->getAllGroups('name'); //get the list of available events $events = $this->getModel('Events'); $events = $events->getActiveEvent('title'); //before everything started, we must disable the email trigger in joomla user plugin $userPlugin = PluginHelper::getPlugin('user', 'joomla'); $params = new CParameter($userPlugin->params); $sendNotification = $params->get('mail_to_user',1); $db=Factory::getDbo(); $db->setQuery( 'SELECT extension_id FROM '.$db->quoteName('#__extensions').' WHERE '.$db->quoteName('element').'='.$db->quote('joomla') .' AND '.$db->quoteName('folder').'='.$db->quote('user') ); $pluginId = $db->loadResult(); $pluginLink = CRoute::_('index.php?option=com_plugins&view=plugin&layout=edit&extension_id='.$pluginId); //lets display the upload form here ob_start(); ?> <div class="alert alert-info"> <p><?php echo Text::_('COM_COMMUNITY_USERS_IMPORT_MESSAGE'); ?></p> <a href="http://tiny.cc/import-export-users" class="btn btn-small btn-info" target="_blank" ><?php echo Text::_('COM_COMMUNITY_DOC') ?></a> </div> <?php if($sendNotification){ ?> <a href="<?php echo $pluginLink; ?>"> <span class="label label-yellow"><?php echo Text::sprintf('COM_COMMUNITY_EMAIL_IMPORT_USER_PLUGIN_SETTING_ENABLED_ERROR'); ?></span> </a> <?php }else{ ?> <form enctype="multipart/form-data" action="<?php echo CRoute::_('index.php?option=com_community&view=users&task=importUsers'); ?>" method="post" onsubmit="return joms_js_import_users(this);"> <table> <tr> <td width="110"></td> <td width="400"><input name="csv" type="file" /></td> </tr> <?php if(count($groups) > 0){ ?> <tr> <td><?php echo Text::_('COM_COMMUNITY_CONFIGURATION_GROUPS_IMPORT_TO'); ?></td> <td> <select name="group[]" multiple="true" style="width:100%;" size="3"> <?php foreach($groups as $row ) { ?> <option value="<?php echo $row->id;?>"><?php echo $row->name;?></option> <?php } ?> </select> </td> </tr> <?php } ?> <?php if(count($events) > 0){ ?> <tr> <td><?php echo Text::_('COM_COMMUNITY_CONFIGURATION_EVENTS_IMPORT_TO'); ?></td> <td> <select name="event[]" multiple="true" style="width:100%;" size="3"> <?php foreach($events as $row ) { ?> <option value="<?php echo $row->id;?>"><?php echo $row->title;?></option> <?php } ?> </select> </td> </tr> <?php } ?> <?php if(!$sendNotification){ ?> <tr> <td></td> <td><input class="btn btn-small btn-primary" type="submit" value="<?php echo Text::_('COM_COMMUNITY_CONFIGURATION_IMPORT_MEMBERS'); ?>" /></td> </tr> <?php } ?> </table> </form> <?php } ?> <?php $html = ob_get_contents(); ob_end_clean(); $response->addAssign( 'cWindowContent' , 'innerHTML' , $html ); return $response->sendResponse(); } public function importUsers(){ $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $csv = $jinput->files->get('csv'); $groups = $jinput->get('group',array(),'array'); // selected groups $events = $jinput->get('event',array(),'array'); // selected events $users = array(); $i = 0; ini_set('auto_detect_line_endings',true); // we need to detect the new line break automatically $handle = fopen($csv['tmp_name'],"r"); if($handle){ while(!feof($handle)){ $results = fgetcsv($handle); //we must check if every results exists, else, return the error if(!$results[0] || !$results[1] || !$results[2] || count($results) < 3){ //do nothing } else { $users[$i] = $results; $i++; } } }else{ //redirect and display error $url = Route::_('index.php?option=com_community&view=users' , false ); $message = Text::_('COM_COMMUNITY_USERS_CSV_FILE_ERROR'); return $this->setRedirect( $url , $message ,'error'); } fclose($handle); $totalusers = count($users); if(!$totalusers){ //if it's empty //redirect and display error $url = Route::_('index.php?option=com_community&view=users' , false ); $message = Text::_('COM_COMMUNITY_USERS_CSV_FILE_ERROR'); return $this->setRedirect( $url , $message ,'error'); } $duplicates = 0; $db = Factory::getDbo(); $groupTable = Table::getInstance('Groups','CommunityTable'); $eventTable = Table::getInstance('Events','CommunityTable'); //we must make sure the mail notification is set to no before proceeding $userPlugin = PluginHelper::getPlugin('user', 'joomla'); $params = new CParameter($userPlugin->params); $sendNotification = $params->get('mail_to_user',1); if($sendNotification){ //redirect and display error $url = Route::_('index.php?option=com_community&view=users' , false ); $message = Text::_('COM_COMMUNITY_EMAIL_IMPORT_USER_PLUGIN_SETTING_ENABLED_ERROR'); return $this->setRedirect( $url , $message ,'error'); } //lets try to create the users foreach($users as $user){ //check if the user already exists in the system $name = trim($user[0]); $username = trim($user[1]); $email = trim($user[2]); $query = 'SELECT id FROM '.$db->quoteName('#__users').' WHERE email='.$db->quote($email).' OR username='.$db->quote($username); $db->setQuery($query); $result = $db->loadResult(); if($result){ //if the email already exists, we will skip this user $duplicates++; //new requirement : skip the user creation but we still need to assign the user to the respective group $newUser = CFactory::getUser($result); }else{ //lets register the user here $randomPassword = UserHelper::genRandomPassword(10); $data = array( 'name' => $name, 'username' => $username, "password"=>$randomPassword, "password2"=>$randomPassword, "email"=>$email, "block"=>0, "groups"=>array(2) ); $newUser = new User(); $newUser->bind($data); if($newUser->save()){ $cuser = CFactory::getUser($newUser->id); $cuser->save(); } $mailq = CFactory::getModel('Mailq'); $emailSubject = Text::sprintf('COM_COMMUNITY_EMAIL_IMPORT_USER_WELCOME_SUBJECT', Factory::getConfig()->get('sitename')); $mailBody = Text::_("COM_COMMUNITY_EMAIL_IMPORT_USER_WELCOME_BODY"); $params = new CParameter(); $params->set('site_url', Uri::root()); $params->set('username',$username); $params->set('password', $randomPassword); $params->set('target',$name); //add the user details to mail queue $mailq->add($email, $emailSubject, $mailBody, '', $params, 0, 'etype_users_new_invite'); } //if we have groups, we will assign this user to the group if(count($groups) > 0){ foreach($groups as $group){ $data = new stdClass(); $data->groupid = $group; $data->memberid = $newUser->id; $data->approved = 1; $data->permissions = 0; //members $groupTable->addMember($data); $groupTable->addMembersCount($group); } } // same goes for events if(count($events) > 0){ foreach($events as $event){ $data = new stdClass(); $data->eventid = $event; $data->memberid = $newUser->id; $data->approval = 0; $data->permission = 3; //members $data->status = 1; $eventTable->addMember($data); } } } $url = Route::_('index.php?option=com_community&view=users' , false ); $message = Text::sprintf('COM_COMMUNITY_USERS_IMPORT_USER_SUCCESS',$totalusers-$duplicates, $duplicates); $this->setRedirect( $url , $message ,'message'); } /** * Element display- Pop-up user window * */ public function element(){ $jinput = Factory::getApplication()->input; $viewName = $jinput->get( 'view' , 'community' ); // Set the default layout and view name $layout = $jinput->get( 'layout' , 'select' ); // Get the document object $document = Factory::getDocument(); // Get the view type $viewType = $document->getType(); // Get the view $view = $this->getView( $viewName , $viewType ); $model = $this->getModel( $viewName ); if( $model ) { $view->setModel( $model , $viewName ); $multiprofiles = $this->getModel( 'MultiProfile' ); $view->setModel( $multiprofiles , false ); } // Set the layout $view->setLayout( $layout ); // Display the view $view->element(); } /** * Export users list into respective formats **/ public function export() { $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $model = $this->getModel( 'Users' ); $format = $jinput->get('format', 'csv', 'STRING'); $ids = $model->getAllUserId(); /** * TODO: Currently it only supports CSV export. In the future we may want to support other types as well **/ switch( $format ) { case 'csv': default: $this->_exportCSV( $ids ); break; } } public function _exportCSV( $ids ) { header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="users.csv"'); $model = CFactory::getModel( 'Profile' ); $lang = Factory::getLanguage(); $lang->load( 'com_community' , JPATH_ROOT ); //CFactory::load( 'helpers' , 'string' ); foreach( $ids as $id ) { if($id->id == ''){ continue; } $user = CFactory::getUser( $id->id ); $profile = $model->getEditableProfile( $id->id , $user->getProfileType() ); $profileType = Table::getInstance( 'MultiProfile' , 'CTable' ); $profileType->load( $user->getProfileType() ); echo $user->id . ',' . $profileType->getName() . ',' . $user->name . ',' . $user->username . ',' . $user->email . ',' . $user->getThumbAvatar() . ',' . $user->getAvatar() . ',' . $user->getKarmaPoint() . ','; echo $user->registerDate . ',' . $user->lastvisitDate . ',' . $user->block . ',"' . $user->getStatus() . '",' . $user->getViewCount() . ',' . $user->getAlias() . ',' . $user->getFriendCount(); foreach( $profile['fields'] as $group => $groupFields ) { foreach( $groupFields as $field ) { $field = Joomla\Utilities\ArrayHelper::toObject ( $field ); $field->value = CStringHelper::nl2br( $field->value ); $field->value = CStringHelper::escape( $field->value ); echo '"'.$field->value . '",'; } } echo "\r\n"; } exit; } public function delete() { // Check for request forgeries Session::checkToken('get') or jexit( 'Invalid Token' ); $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $db = Factory::getDBO(); $currentUser = Factory::getUser(); $cid = $jinput->get( 'cid', array(), 'array'); $cacl = CACL::getInstance(); $cid = Joomla\Utilities\ArrayHelper::toInteger( $cid ); if (count( $cid ) < 1) { $msg = Text::_('COM_COMMUNITY_USERS_DELETE'); } foreach ($cid as $id) { $this_group = $cacl->getGroupsByUserId($id); $success = false; if ( $this_group == 'super administrator' ) { $msg = Text::_('COM_COMMUNITY_USERS_SUPER_ADMINISTRATOR_DELETE'); } else if ( $id == $currentUser->get( 'id' ) ) { $msg = Text::_('COM_COMMUNITY_USERS_CANNOT_DELETE_YOURSELF'); } else if ( ( $this_group == 'administrator' ) && ( $currentUser->get( 'gid' ) == 24 ) ) { $msg = Text::_('COM_COMMUNITY_USERS_WARNDELETE'); } else { $user = User::getInstance((int)$id); $count = 2; if ( $user->get( 'gid' ) == 25 ) { // count number of active super admins $query = 'SELECT COUNT( ' . $db->quoteName('id') . ' )' . ' FROM ' . $db->quoteName('#__users') . ' WHERE ' . $db->quoteName('gid') . ' = ' . $db->Quote(25) . ' AND ' . $db->quoteName('block') . ' = ' . $db->Quote(0) ; $db->setQuery( $query ); $count = $db->loadResult(); } if ( $count <= 1 && $user->get( 'gid' ) == 25 ) { // cannot delete Super Admin where it is the only one that exists $msg = Text::_('COM_COMMUNITY_USERS_DELETE_ACTIVE_ADMIN'); } else { // delete user $user->delete(); $msg = Text::_('COM_COMMUNITY_USERS_DELETED'); $jinput->set( 'task', 'remove' ); $jinput->set( 'cid', $id ); // delete user acounts active sessions $this->logout(); } } } $this->setRedirect( 'index.php?option=com_community&view=users', $msg); } /** * Force log out a user */ public function logout( ) { // Check for request forgeries Session::checkToken('get') or jexit( 'Invalid Token' ); $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $db = Factory::getDBO(); $task = $this->getTask(); $cids = $jinput->request->get('cid', array(), 'array'); $client = $jinput->request->get('client', 0, 'int'); $id = $jinput->request->get('id', 0, 'int'); $cids = Joomla\Utilities\ArrayHelper::toInteger($cids); if ( count( $cids ) < 1 ) { $this->setRedirect( 'index.php?option=com_users', Text::_('COM_COMMUNITY_USERS_DELETED') ); return false; } foreach($cids as $cid) { $options = array(); if ($task == 'logout' || $task == 'block') { $options['clientid'][] = 0; //site $options['clientid'][] = 1; //administrator } else if ($task == 'flogout') { $options['clientid'][] = $client; } $mainframe->logout((int)$cid, $options); } $msg = Text::_('COM_COMMUNITY_USERS_SESSION_ENDED'); switch ( $task ) { case 'flogout': $this->setRedirect( 'index.php', $msg ); break; case 'remove': case 'block': return; break; default: $this->setRedirect( 'index.php?option=com_users', $msg ); break; } } /** * Save controller that receives arguments via HTTP POST. **/ public function save() { // Check for request forgeries Session::checkToken() or jexit( 'Invalid Token' ); $lang = Factory::getLanguage(); $lang->load('com_users'); $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $userId = $jinput->post->get('userid' , '', 'INT'); $message = ''; $url = Route::_('index.php?option=com_community&view=users' , false ); $my = Factory::getUser(); $cacl = CACL::getInstance(); $db = Factory::getDbo(); $mailFrom = $mainframe->get('mailfrom'); $fromName = $mainframe->get('fromname'); $siteName = $mainframe->get('sitename'); if( empty( $userId ) ) { $message = Text::_('COM_COMMUNITY_USERS_EMPTY_USER_ID'); return $this->setRedirect( $url , $message ,'error'); } // Create a new JUser object try { $user = new User($userId); } catch (Exception $e) { $errorMsg = $e->getMessage(); } $original_gid = $user->get('gid'); $post = $jinput->post->getArray(); $post['username'] = $jinput->post->get('username', '', 'RAW'); $post['password'] = $jinput->post->get('password', '', 'RAW'); $post['password2'] = $jinput->post->get('password2', '', 'RAW'); $notifyEmailSystem = $jinput->post->get('sendEmail', '', 'STRING'); $redirect = $jinput->post->get('redirect', false, 'STRING'); $block = $jinput->post->get('block', false, 'INT'); if (!$user->bind($post)) { $message = Text::_('COM_COMMUNITY_USERS_SAVE_USER_INFORMATION_ERROR') . ' : ' . $errorMsg; $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'error'); } $this_group = $cacl->getGroupsByUserId($user->get('id')); if( $user->get('id') == $my->get( 'id' ) && $user->get('block') == 1 ) { $message = Text::_('COM_COMMUNITY_USERS_BLOCK_YOURSELF'); $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'error'); } if(( $this_group == 'super administrator' ) && $user->get('block') == 1 ) { $message = Text::_('COM_COMMUNITY_USERS_BLOCK_SUPER_ADMINISTRATOR'); $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'error'); } if(( $this_group == 'administrator' ) && ( $my->get( 'gid' ) == 24 ) && $user->get('block') == 1 ) { $message = Text::_('COM_COMMUNITY_USERS_WARNBLOCK'); $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'error'); } if(( $this_group == 'super administrator' ) && ( $my->get( 'gid' ) != 25 ) ) { $message = Text::_('COM_COMMUNITY_USERS_SUPER_ADMINISTRATOR_EDIT'); $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'error'); } $isNew = $user->get('id') == 0; if (!$isNew) { if ( $user->get('gid') != $original_gid && $original_gid == 25 ) { $query = 'SELECT COUNT( ' . $db->quoteName('id') . ' )' . ' FROM ' . $db->quoteName('#__users') . ' WHERE ' . $db->quoteName('gid') . ' = ' . $db->Quote(25) . ' AND ' . $db->quoteName('block') . ' = ' . $db->Quote(0); $db->setQuery( $query ); $count = $db->loadResult(); if( $count <= 1 ) { $message = Text::_('COM_COMMUNITY_USERS_WARN_ONLY_SUPER'); $url = Route::_('index.php?option=com_community&view=users&layout=edit&id=' . $userId , false ); return $this->setRedirect( $url , $message ,'message'); } } } //Joomla 1.6 patch to keep the group ID of user intact when saving if(property_exists($user, 'groups')){ foreach($user->groups as $groupid => $groupname){ $user->groups[$groupid] = $groupid; } } try { $user->save(); } catch (Exception $e) { $message = Text::_('COM_COMMUNITY_USERS_SAVE_USER_INFORMATION_ERROR') . ' : ' . $e->getMessage(); return $this->setRedirect( $url , $message ,'message'); } $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); $userRow = array(); $userRow[] = $user; $appsLib->triggerEvent( 'onUserDetailsUpdate' , $userRow ); // @rule: Send out email if it is a new user. if($isNew) { $adminEmail = $my->get('email'); $adminName = $my->get('name'); $subject = sprintf ( Text::_('COM_COMMUNITY_USERS_NEW_USER_MESSAGE_SUBJECT') , $siteName); $message = sprintf ( Text::_('COM_COMMUNITY_USERS_NEW_USER_MESSAGE'), $user->get('name'), $siteName, Uri::root(), $user->get('username'), $user->password_clear ); if ( !empty( $mailfrom ) && !empty( $fromName ) ) { $adminName = $fromName; $adminEmail = $mailFrom; } $mail = Factory::getMailer(); $mail->sendMail( $adminEmail, $adminName, $user->get('email'), $subject, $message ); } // If updating self, load the new user object into the session if ($user->get('id') == $my->get('id')) { $grp_name = $cacl->getGroupUser($user->get('id')); // Mark the user as logged in $user->set('guest', 0); $user->set('aid', 1); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($cacl->is_group_child_of($grp_name, 'Registered') || $cacl->is_group_child_of($grp_name, 'Public Backend')){ $user->set('aid', 2); } // Set the usertype based on the ACL group name $user->set('usertype', $grp_name); $session = Factory::getSession(); $session->set('user', $user); } $juser = $user; // Process and save custom fields $user = CFactory::getUser( $userId ); $user->setProperties($juser->getProperties()); //bind the properties from the previous changes $model = $this->getModel( 'users' ); $userModel = CFactory::getModel( 'profile' ); $values = array(); $profile = $userModel->getEditableProfile( $userId , $user->getProfileType() ); //CFactory::load( 'libraries' , 'profile' ); foreach( $profile['fields'] as $group => $fields ) { foreach( $fields as $data ) { // Get value from posted data and map it to the field. // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id. $postData = $jinput->post->get('field' . $data['id'] , '', 'NONE'); $values[ $data['id'] ] = CProfileLibrary::formatData( $data['type'] , $postData ); // @rule: Validate custom profile if necessary if( !CProfileLibrary::validateField( $data['id'], $data['type'] , $values[ $data['id'] ] , $data['required'] ) ) { $session = Factory::getSession(); $session->set('postData',$post); // If there are errors on the form, display to the user. $message = Text::sprintf('COM_COMMUNITY_THE_FIELD_CONTAIN_IMPROPER_VALUES',$data['name'] ); $mainframe->enqueueMessage($message, 'error'); return $this->setRedirect( 'index.php?option=com_community&view=users&layout=edit&id=' . $user->id); } } } // Update user's parameter DST $params = $user->getParams(); $offset = $post['daylightsavingoffset']; $params->set('daylightsavingoffset',$offset); $user->setParam('params',$params->toString()); $user->setParam('params', $offset ); $user->setParam('notifyEmailSystem', $notifyEmailSystem ); //set the data to the #__user table $user->sendEmail = $notifyEmailSystem; $user->block = $block; // Update user's point $points = $jinput->request->get('userpoint' , '' , 'NONE'); if( $points != '' ) { $user->_points = $points; $user->save(); } //update user's profile $profile_id = $jinput->request->get('profiletype' , '' , 'INT'); if( $profile_id > 0 ) { $user->_profile_id = $profile_id; $user->save(); } // Update user's status if( $user->getStatus() != $post['status'] ) { $user->setStatus( $post['status'] ); } $user->save('params'); $valuesCode = array(); foreach( $values as $key => &$val ) { $fieldCode = $userModel->getFieldCode($key); if( $fieldCode ) { $valuesCode[$fieldCode] = &$val; } } // Trigger before onBeforeUserProfileUpdate $args = array(); $args[] = $userId; $args[] = $valuesCode; $saveSuccess = false; $result = $appsLib->triggerEvent( 'onBeforeProfileUpdate' , $args ); if(!$result || ( !in_array(false, $result) ) ) { $saveSuccess = true; $userModel->saveProfile($userId, $values); } // Trigger before onAfterUserProfileUpdate $args = array(); $args[] = $userId; $args[] = $saveSuccess; $result = $appsLib->triggerEvent( 'onAfterProfileUpdate' , $args ); if(!$saveSuccess) { $message = Text::_('COM_COMMUNITY_USERS_PROFILE_NOT_UPDATED'); return $this->setRedirect( $url , $message , 'error'); } if($redirect == false) { $message = Text::_('COM_COMMUNITY_USERS_UPDATED_SUCCESSFULLY'); $mainframe->enqueueMessage($message); return $this->setRedirect( 'index.php?option=com_community&view=users&layout=edit&id=' . $user->id); } $message = Text::_('COM_COMMUNITY_USERS_UPDATED_SUCCESSFULLY'); $mainframe->enqueueMessage($message); return $this->setRedirect( $url ); } // Override parent's toggle publish method public function ajaxTogglePublish( $id, $field, $viewName= false ) { $user = Factory::getUser(); // @rule: Disallow guests. if ( $user->get('guest') || !CFactory::getUser()->authorise('community.profileeditstate', 'com_community')) { Factory::getApplication()->enqueueMessage(Text::_('COM_COMMUNITY_ACCESS_FORBIDDEN'), 'error'); return; } $response = new JAXResponse(); // Load the JTable Object. $row = Table::getInstance( 'User' , 'JTable' ); $row->load( $id ); if( isset($row->groups[8]) ) { $response->addScriptCall( 'alert' , Text::_('COM_COMMUNITY_USERS_BLOCK_SUPER_ADMINISTRATORS') ); } else { if( $row->$field == 1 ) { $row->$field = 0; $row->activation = ""; $row->store(); $image = 'tick.png'; // @rule: If the new user is just activated, send an email to the user. if( $row->lastvisitDate == '0000-00-00 00:00:00' && empty($row->activation) ) { $lang = Factory::getLanguage(); $lang->load( 'com_community' , JPATH_ROOT ); $mainframe = Factory::getApplication(); $config = CFactory::getConfig(); $sitename = $mainframe->get( 'sitename' ); $mailfrom = $mainframe->get( 'mailfrom' ); $fromname = $mainframe->get( 'fromname' ); $siteURL = Uri::root(); $name = $row->get('name'); $email = $row->get('email'); $username = $row->get('username'); $subject = Text::sprintf( 'COM_COMMUNITY_ACCOUNT_APPROVED_SUBJECT' , $name, $sitename); $subject = html_entity_decode($subject, ENT_QUOTES); $message = sprintf ( Text::_( 'COM_COMMUNITY_ACCOUNT_APPROVED_MESSAGE' ), $siteURL , $row->name , $row->email , $row->username ); $message = html_entity_decode($message, ENT_QUOTES); // Send email to user $mail = Factory::getMailer(); $mail->sendMail($mailfrom, $fromname, $email, $subject, $message); } } else { $row->$field = 1; $row->store(); $image = 'publish_x.png'; } // Get the view $view = $this->getView( 'users' , 'html' ); $html = $view->getPublish( $row , $field , 'users,ajaxTogglePublish' ); $response->addAssign( $field . $id , 'innerHTML' , $html ); } return $response->sendResponse(); } public function ajaxRemoveAvatar( $userId ) { require_once( JPATH_ROOT .'/components/com_community/libraries/core.php' ); require_once( JPATH_ROOT .'/components/com_community/libraries/apps.php' ); $user = CFactory::getUser( $userId ); $model = $this->getModel( 'Users' ); $model->removeProfilePicture( $user->id , 'avatar' ); $model->removeProfilePicture( $user->id , 'thumb' ); $message = Text::_('COM_COMMUNITY_USERS_PROFILE_PICTURE_REMOVED'); $response = new JAXResponse(); $profileModel = CFactory::getModel ( 'Profile' ); $gender = $profileModel->getGender($user->id); //Do convert into translate string $tGender = strtoupper($gender); if (strpos($tGender, 'COM_COMMUNITY_') === false) { $tGender = 'COM_COMMUNITY_' . $tGender; } switch ($tGender) { case 'COM_COMMUNITY_MALE': $gender = 'male'; break; case 'COM_COMMUNITY_FEMALE': $gender = 'female'; break; default: $gender = 'male'; break; } $avatar = Uri::root() . 'components/com_community/assets/user-'.$gender.'.png'; $response->addScriptCall('joms.jQuery("#user-avatar").attr("src","' . $avatar . '");'); $response->addScriptCall('joms.jQuery("#user-avatar-message").html("' . $message . '");' ); $response->addScriptCall('joms.jQuery("#user-avatar-message").hide(5000);' ); return $response->sendResponse(); } public function ajaxToggleStatus($id,$status) { $response = new JAXResponse(); $row = Table::getInstance( 'User' , 'JTable' ); $row->load( $id ); switch ($status) { case '1': $row->block = 0; $row->store(); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").removeClass','label-important'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").removeClass','label-warning'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").addClass','label-success'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").addClass','arrowed-in'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").html',Text::_('approved')); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' div.inline").remove'); break; case '0': $row->block = 1; $row->store(); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").removeClass','label-important'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").removeClass','label-warning'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").addClass','label-important'); $response->addScriptCall('joms.jQuery("#member-label-'.$id.' span.label").html',Text::_('blocked')); break; case '2': $user = User::getInstance((int)$id); $user->delete(); $response->addScriptCall('joms.jQuery("#member-'.$id.'").remove'); break; } return $response->sendResponse(); } public function approveselected() { $mainframe = Factory::getApplication(); $jinput = $mainframe->input; $ids = $jinput->get('cid',array(),'Array'); foreach($ids as $id) { $row = Table::getInstance( 'User' , 'JTable' ); $row->load( $id ); $row->block = 0; $row->store(); } $search = $jinput->get('search','','String'); $userType = $jinput->get('user','','String'); $profileType = $jinput->get('profiletype','','String'); $status = $jinput->get('status','2','String'); $url = 'index.php?option=com_community&view=users&search='.$search.'&usertype='.$userType.'&profiletype='.$profileType.'&status='.$status; $message = Text::_('COM_COMMUNITY_USERS_UPDATED_SUCCESSFULLY'); $mainframe->enqueueMessage($message); $mainframe->redirect( $url ); } }
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка