AnonSec Shell
Server IP : 54.36.91.62  /  Your IP : 216.73.217.112
Web Server : Apache
System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User : coopiak ( 151928)
PHP Version : 8.3.23
Disable Function : _dyuweyrj4,_dyuweyrj4r,dl
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/coopiak/amisdesseniors-fr/administrator/components/com_community/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/administrator/components/com_community/controllers/multiprofile.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\Component\ComponentHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\Filesystem\Folder;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Table\Table;
use Joomla\CMS\User\UserHelper;
use Joomla\Filesystem\File;

// Disallow direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.controller' );

class CommunityControllerMultiProfile extends CommunityController
{
	public function __construct()
	{
		parent::__construct();
		$this->registerTask( 'publish' , 'savePublish' );
		$this->registerTask( 'unpublish' , 'savePublish' );
	}

	public function orderUp()
	{
		$this->updateOrder( -1 );
	}

	public function orderDown()
	{

		$this->updateOrder( 1 );
	}

	public function removeWatermark(){

		$mainframe	= Factory::getApplication();

		$jinput 	= $mainframe->input;
		$id				= $jinput->request->get('id' , '', 'INT' ) ;

		$multiprofile	= Table::getInstance( 'MultiProfile' , 'CTable' );
		$multiprofile->load( $id );

		File::delete( JPATH_ROOT .'/'.$multiprofile->watermark);
		File::delete( JPATH_ROOT .'/'.$multiprofile->thumb);
		File::delete( JPATH_ROOT .'/'.$multiprofile->avatar);

		$multiprofile->watermark_hash = '';
		$multiprofile->watermark_location = '';
		$multiprofile->thumb = '';
		$multiprofile->watermark = '';
		$multiprofile->avatar = '';
		$multiprofile->store();

		$this->setRedirect('index.php?option=com_community&view=multiprofile&layout=edit&id='.$id , Text::_( 'COM_COMMUNITY_REMOVE_WATERMARK_SUCCESS' ),'message' );
	}

	public function updateOrder( $direction )
	{
		// Check for request forgeries
		Session::checkToken() or jexit( 'Invalid Token' );

		$mainframe	= Factory::getApplication();
		$jinput 	= $mainframe->input;
		$db			= Factory::getDBO();
		$id			= $jinput->post->get('cid', array(), 'array');


		if( isset( $id[0] ) )
		{
			$row	= Table::getInstance( 'Multiprofile' , 'CTable' );
			$row->load( (int) $id[0] );
			$row->move( $direction );

			return $this->setRedirect('index.php?option=com_community&view=multiprofile' , Text::_( 'COM_COMMUNITY_MULTIPROFILE_ORDERING_UPDATED' ) ,'message' );
		}

		$this->setRedirect('index.php?option=com_community&view=multiprofile' , Text::_( 'COM_COMMUNITY_MULTIPROFILE_ORDERING_UPDATE_ERROR' ) , 'error' );
	}

	public function saveOrder()
	{
		// Check for request forgeries
		Session::checkToken() or jexit( 'Invalid Token' );

		$mainframe	= Factory::getApplication();
		$jinput 	= $mainframe->input;

		$db			= Factory::getDBO();
		$cid		= $jinput->post->get('cid', array(0), 'array') ;
		$order		= $jinput->post->get('order', array(0), 'array') ;
		$total		= count($cid);
		$conditions	= array ();

		$cid = Joomla\Utilities\ArrayHelper::toInteger($cid, array(0));
		$order = Joomla\Utilities\ArrayHelper::toInteger($order, array(0));

		$row = Table::getInstance('MultiProfile' , 'CTable' );

		// Update the ordering for items in the cid array
		for ($i = 0; $i < $total; $i ++)
		{
			$row->load( (int) $cid[$i] );

			if ($row->ordering != $order[$i])
			{
				$row->ordering = $order[$i];
				$row->store();
			}
		}
		$mainframe		= Factory::getApplication();

		$this->setRedirect('index.php?option=com_community&view=multiprofile' , Text::_('COM_COMMUNITY_MULTIPROFILE_ORDERING_SAVED') ,'message' );
	}

	public function savePublish( $tableClass = 'Ctable')
	{
		parent::savePublish( $tableClass );
	}

	public function ajaxTogglePublish( $id , $type, $viewName=false)
	{
		$user	= Factory::getUser();

		// @rule: Disallow guests.
		if ( $user->get('guest'))
		{
            Factory::getApplication()->enqueueMessage(Text::_('COM_COMMUNITY_ACCESS_FORBIDDEN'), 'error');
			return;
		}

		$response	= new JAXResponse();

		$idArray = array();

		// Load the Table Object.
		$row	= Table::getInstance( 'MultiProfile' , 'CTable' );
		$row->load( $id );

		$idArray[] = $row->id;

		$row->publish( $idArray , (int) !$row->published );
		$row->load( $id );

		$image	= $row->published ? 'publish_x.png' : 'tick.png';

		$view	= $this->getView( 'multiprofile' , 'html' );

		$html	= $view->getPublish( $row , 'published' , 'multiprofile,ajaxTogglePublish' );

		$response->addAssign( $type . $id , 'innerHTML' , $html );

		return $response->sendResponse();
	}

	public function save()
	{
		jimport( 'joomla.filesystem.folder' );
		jimport( 'joomla.filesystem.file' );

		$mainframe  = Factory::getApplication();
		$jinput     = $mainframe->input;
		$id         = $jinput->post->getInt( 'id' , 0 );
		$post       = $jinput->post->getArray();
		$fields     = $jinput->get('fields' , '', 'NONE');
		$name       = $jinput->get('name' , '', 'STRING');
		$tmpParents = $jinput->get('parents' , '', 'NONE');
		$userGroup  = $jinput->post->getInt('multiprofileUserGroup', 0);
		$mainframe  = Factory::getApplication();
		$task       = $jinput->get('task');
		$isNew      = $id == 0 ? true : false;
		$validated  = true;

		$multiprofile = Table::getInstance( 'MultiProfile' , 'CTable' );
		$multiprofile->load( $id );

		$params = new CParameter('');
		if(!empty($multiprofile->params)){
			$params->loadString($multiprofile->params);
		}

		if (isset($post['userGroup'])) {
			$params->set('userGroup', $post['userGroup']);
		}

		// default jomsocial group (auto assign)
		if (isset($post['groupid'])) {
			$params->set('groupid', $post['groupid']);
		} else {
			$params->set('groupid', '');
		}

		$multiprofile->params = $params->toString();
		
		// Bind with form post
		$post['avatar'] = isset($post['avatar']) ? $post['avatar'] : '';
		$post['watermark'] = isset($post['watermark']) ? $post['watermark'] : '';
		$post['watermark_hash'] = isset($post['watermark_hash']) ? $post['watermark_hash'] : '';
		$post['watermark_location'] = isset($post['watermark_location']) ? $post['watermark_location'] : '';
		$post['thumb'] = isset($post['thumb']) ? $post['thumb'] : '';
		$multiprofile->bind($post);
		// Can't have an empty name now can we?
		if( empty($name) ){
			$validated = false;
			$mainframe->enqueueMessage( Text::_ ( 'COM_COMMUNITY_MULTIPROFILE_NAME_EMPTY' ), 'error' );
		}

		$date  = Date::getInstance();
		$isNew = ($multiprofile->id == 0) ? true : false;

		if( $isNew ) {
			$multiprofile->created	= $date->toSql();
		}

		// Store watermarks for profile types.
		$watermark = $jinput->files->get('watermark' , '', 'NONE');

		if(!empty($watermark['tmp_name'])){
			// Do not allow image size to exceed maximum width and height
			if( isset($watermark['name']) && !empty($watermark['name']) )
			{
				list( $width , $height ) = getimagesize( $watermark[ 'tmp_name' ] );

				/**
				* watermark can't large than 16px
				* @todo use define for min width & height instead fixed number here
				*/
				if( $width > 16 || $height > 16 )
				{
					$validated = false;
					$mainframe->enqueueMessage ( Text::_ ( 'COM_COMMUNITY_MULTIPROFILE_WATERMARK_IMAGE_EXCEEDS_SIZE' ), 'error' );
				}
			}
		}

		if($validated) {
			$multiprofile->store();

			// If image file is specified, we need to store the thumbnail.
			if(!empty($watermark['tmp_name'])){
				if( isset($watermark['name']) && !empty($watermark['name']) )
				{
					if(!is_file(JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH)){
						Folder::create(JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH);
					}
					$watermarkFile	= 'watermark_' . $multiprofile->id . CImageHelper::getExtension( $watermark['type'] );
					File::copy( $watermark[ 'tmp_name' ] , JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH .'/'. $watermarkFile );

					$multiprofile->watermark = CString::str_ireplace( '/', '/' , COMMUNITY_WATERMARKS_PATH ) .  '/' . $watermarkFile;
					$multiprofile->store();
				}
			}

			// @rule: Create the watermarks folder if doesn't exists.
			if( !is_file( JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH ) )
			{
				if(!Folder::create( JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH ) )
				{
					$mainframe->enqueueMessage( Text::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER') );
				}
			}

			// @rule: Create original folder within watermarks to store original user photos.
			if( !is_file( JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH . '/original' ) )
			{
				if(!Folder::create( JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH . '/original' ) )
				{
					$mainframe->enqueueMessage( Text::_('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_CREATE_WATERMARKS_FOLDER') );
				}
			}

			if(!empty($watermark['tmp_name'])) {
				if(isset($watermark['name']) && !empty( $watermark['name'] )) {
					$watermarkPath = $watermark[ 'tmp_name'];
					$watermark_hash	= md5( $watermark['name'] . time() );
				} else {
					$watermarkPath = JPATH_ROOT .'/'. $multiprofile->watermark;
					$watermark_hash = $multiprofile->watermark_hash;
				}

				// Create default watermarks for avatar and thumbnails.

				// Generate filename
				$fileName		= CImageHelper::getHashName( $multiprofile->id . time() ). '.jpg';
				$thumbFileName	= 'thumb_' . $fileName;

				// Paths where the thumbnail and avatar should be saved.
				$thumbPath	= JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH .'/'. $thumbFileName;
				$avatarPath	= JPATH_ROOT .'/'. COMMUNITY_WATERMARKS_PATH .'/'. $fileName;

				// Copy existing default thumbnails into the path first.
				$td_path = "default-general-avatar";
				if (file_exists(COMMUNITY_PATH_ASSETS.$td_path.'.png')) {
					$deafultAvatar = COMMUNITY_PATH_ASSETS.$td_path.'.png';
					$deafultAvatarThumb = COMMUNITY_PATH_ASSETS.$td_path.'-thumb.png';
		        } elseif (file_exists(COMMUNITY_PATH_ASSETS.$td_path.'.jpg')) {
		            $deafultAvatar = COMMUNITY_PATH_ASSETS.$td_path.'.jpg';
		            $deafultAvatarThumb = COMMUNITY_PATH_ASSETS.$td_path.'-thumb.jpg';
		        } else {
		            $deafultAvatar = JPATH_ROOT .'/'. DEFAULT_USER_AVATAR;
		            $deafultAvatarThumb = JPATH_ROOT .'/'. DEFAULT_USER_THUMB;
		        }

				File::copy( $deafultAvatarThumb , $thumbPath );
				File::copy( $deafultAvatar , $avatarPath );

				list( $watermarkWidth , $watermarkHeight )	= getimagesize( $watermarkPath );

				$oldDefaultAvatar	= $multiprofile->avatar;
				$oldDefaultThumb	= $multiprofile->thumb;

				// Avatar Properties
				$avatarInfo		= getimagesize( $avatarPath );
				$avatarWidth	= $avatarInfo[ 0 ];
				$avatarHeight	= $avatarInfo[ 1 ];
				$avatarMime		= $avatarInfo[ 'mime' ];
				$avatarPosition	= $this->_getPositions( $multiprofile->watermark_location , $avatarWidth , $avatarHeight , $watermarkWidth , $watermarkHeight );
				CImageHelper::addWatermark( $avatarPath , $avatarPath , $avatarMime , $watermarkPath , $avatarPosition->x , $avatarPosition->y );
				$multiprofile->avatar	= CString::str_ireplace( '/', '/' , COMMUNITY_WATERMARKS_PATH ) . '/' . $fileName;

				// Thumbnail properties.
				$thumbInfo		= getimagesize( $thumbPath );
				$thumbWidth		= $thumbInfo[ 0 ];
				$thumbHeight	= $thumbInfo[ 1 ];
				$thumbMime		= $thumbInfo[ 'mime' ];
				$thumbPosition	= $this->_getPositions( $multiprofile->watermark_location , $thumbWidth , $thumbHeight , $watermarkWidth , $watermarkHeight );

				CImageHelper::addWatermark( $thumbPath , $thumbPath , $thumbMime , $watermarkPath , $thumbPosition->x , $thumbPosition->y );

				$multiprofile->thumb	= CString::str_ireplace( '/', '/' , COMMUNITY_WATERMARKS_PATH ) . '/' . $thumbFileName;

				// Since the default thumbnail is used by current users, we need to update their existing values.
				$multiprofile->updateUserDefaultImage( 'avatar' , $oldDefaultAvatar );
				$multiprofile->updateUserDefaultImage( 'thumb' , $oldDefaultThumb );

				$multiprofile->watermark_hash = $watermark_hash;
				$multiprofile->store();
			}

			// Since it would be very tedious to check if previous fields were enabled or disabled.
			// We delete all existing mapping and remap it again to ensure data integrity.
			if( !$isNew && empty($fields) )
			{
				$multiprofile->deleteChilds();
			}

			if( !empty( $fields ) )
			{
				$parents	= array();

				// We need to unique the parents first.
				foreach($fields as $id )
				{
					$customProfile		= Table::getInstance( 'Profiles' , 'CommunityTable' );
					$customProfile->load( $id );

					// Need to only
					$parent				= $customProfile->getCurrentParentId();

					if( in_array( $parent , $tmpParents ) )
					{
						$parents[]	= $parent;
					}
				}
				$parents	= array_unique( $parents );

				$fields		= array_merge( $fields, $parents );

                $fieldTable = Table::getInstance( 'MultiProfileFields' , 'CTable' );
                $fieldTable->cleanField($multiprofile->id);

				foreach( $fields as $id )
				{
					$field				= Table::getInstance( 'MultiProfileFields' , 'CTable' );
					$field->parent		= $multiprofile->id;
					$field->field_id	= $id;

					$field->store();
				}
			}

			if( $isNew ) {
				$message = Text::_('COM_COMMUNITY_MULTIPROFILE_CREATED_SUCCESSFULLY');
			} else {
				$message = Text::_( 'COM_COMMUNITY_MULTIPROFILE_UPDATED_SUCCESSFULLY' );

				// update all users with saved user groups
				if (isset($post['userGroup'])) {
					$userConfig = ComponentHelper::getParams('com_users');
					$newUsertype = $userConfig->get('new_usertype');
					$multiProfileModel = $this->getModel('multiprofile');
					$users = $multiProfileModel->getUserList($multiprofile->id);
			        
			        $prevgroup = '';
			        foreach ($users as $user) {
			        	$row = Table::getInstance('users', 'CommunityTable');
			        	$row->load($user->userid);
			        	$prevgroup = $row->usergroup;
			        	$row->usergroup = implode(',', $post['userGroup']);
			        	$row->store();

			        	// add user to selected user groups
			        	if (!UserHelper::checkSuperUserInUsers(array($user->userid))) {
			        		foreach ($post['userGroup'] as $usergroupid) {
			        			if ($usergroupid != $newUsertype) UserHelper::addUserToGroup($user->userid, $usergroupid);
			        		}
			        	}

			        	// remove user from prev selected user groups
			        	if ($post['userGroup'] && $prevgroup && !UserHelper::checkSuperUserInUsers(array($userid))) {
			        		$prevgroup = array_diff(explode(',', $prevgroup), $post['userGroup']);

			        		foreach ($prevgroup as $usergroupid) {
			        			if ($usergroupid != $newUsertype) UserHelper::removeUserFromGroup($user->userid, $usergroupid);
			        		}
			        	}
			        }
		    	}
			}

			switch($task){
				case 'apply';
					$link   = 'index.php?option=com_community&view=multiprofile&layout=edit&id=' . $multiprofile->id;
					break;
				case 'save';
				default:
					$link   = 'index.php?option=com_community&view=multiprofile';
					break;
			}

			$this->setRedirect( $link, $message, 'message' );
			return;
		}

		$document = Factory::getDocument();
		$viewName = $jinput->get( 'view' , 'community' );

		// Get the view type
		$viewType = $document->getType();

		// Get the view
		$view     = $this->getView( $viewName , $viewType );
		$view->setLayout( 'edit' );

		$profileModel = $this->getModel('Profiles');
		if ($profileModel) {
			$view->setModel( $profileModel , $viewName );
		}

		$groupModel = $this->getModel('groups','CommunityAdminModel');
		if ($groupModel) {
			$view->setModel( $groupModel , $viewName );
		}

		$view->display();
	}

	public function apply()
	{
		$this->save();
	}

	/**
	 * Retrieve the proper x and y position depending on the user's choice of the watermark position.
	 **/
	private function _getPositions( $location , $imageWidth , $imageHeight , $watermarkWidth , $watermarkHeight )
	{
		$position	= new stdClass();

		// @rule: Get the appropriate X/Y position for the avatar
		switch( $location )
		{
			case 'top':
				$position->x	= ($imageWidth / 2) - ( $watermarkWidth / 2 );
				$position->y	= 0;
				break;
			case 'bottom':
				$position->x	= ($imageWidth / 2) - ( $watermarkWidth / 2 );
				$position->y	= $imageHeight - $watermarkHeight;
				break;
			case 'left':
				$position->x	= 0;
				$position->y	= ( $imageHeight / 2 ) - ($watermarkHeight / 2);
				break;
			case 'right':
				$position->x 	= $imageWidth - $watermarkWidth;
				$position->y	= ( $imageHeight / 2 ) - ($watermarkHeight / 2);
				break;
		}
		return $position;
	}

	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();

		$view		= $this->getView( $viewName , $viewType );
		$profile	= $this->getModel( 'Profiles' );
		$view->setModel( $profile , false );

		$groups	= $this->getModel( 'groups','CommunityAdminModel' );
		$view->setModel( $groups  , false );

		parent::display();
	}

	public function add()
	{
		$mainframe	= Factory::getApplication();
		$this->setRedirect( 'index.php?option=com_community&view=multiprofile&layout=edit' );
	}

	/**
	 * Responsible for deleting single or multiple profile types.
	 **/
	public function delete()
	{
		$mainframe	= Factory::getApplication();
		$jinput 	= $mainframe->input;
		$data		= $jinput->post->get('cid' , '', 'NONE') ;
		$error		= array();
		$profile	= Table::getInstance( 'MultiProfile' , 'CTable' );

		if( !is_array( $data ) )
		{
			$data[]	= $data;
		}

		if( empty($data) )
		{
            Factory::getApplication()->enqueueMessage(Text::_('COM_COMMUNITY_INVALID_ID'), 'error');
		}

		foreach($data as $id)
		{
			$profile->load( $id );

			if( $profile->hasUsers() )
			{
				return $this->setRedirect( 'index.php?option=com_community&view=multiprofile' , Text::sprintf('COM_COMMUNITY_MULTIPROFILE_UNABLE_TO_DELETE_MULTIPROFILE' , $profile->name ) , 'error' );
			}
			else
			{
				if( !$profile->delete() )
				{
					$error[]	= true;
				}
				else // in case something went wrong and deleted profile id assigned to certain users, set users to default profile ID: COMMUNITY_DEFAULT_PROFILE
				{
					$user = CFactory::getModel('user');
					$user->setDefProfileToUser($profile->id);
				}
			}
		}


		if( in_array($error, []))
		{
			$this->setRedirect( 'index.php?option=com_community&view=multiprofile' , Text::_('COM_COMMUNITY_MULTIPROFILE_REMOVING_ERROR') , 'error' );
		}
		else
		{
			$this->setRedirect( 'index.php?option=com_community&view=multiprofile' , Text::_('COM_COMMUNITY_MULTIPROFILE_DELETED') ,'message' );
		}
	}

	public function ajaxSortField($id, $move){
        //special case where id, moveby how many rows and the order are provided
        $moveBy = abs($move);
        $orderBy = $move;
        $loop = 0;

        if( $id > 0 && $moveBy > 0) {
            $loop = $moveBy;
            $direction = ($orderBy > 0) ? 1 : -1;
        }

		$row = Table::getInstance('Multiprofile', 'CTable');
		$row->load($id);

		do {
			$row->move($direction);
		} while ($loop != 0 && --$loop);

        $response = new JAXResponse();
        $response->sendResponse();
    }
}

Anon7 - 2022
AnonSec Team