You've already forked joomla_test
first commit
This commit is contained in:
109
plugins/user/contactcreator/contactcreator.php
Normal file
109
plugins/user/contactcreator/contactcreator.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.contactcreator
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Class for Contact Creator
|
||||
*
|
||||
* A tool to automatically create and synchronise contacts with a user
|
||||
*
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.contactcreator
|
||||
* @since 1.6
|
||||
*/
|
||||
class PlgUserContactCreator extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
public function onUserAfterSave($user, $isnew, $success, $msg)
|
||||
{
|
||||
if (!$success)
|
||||
{
|
||||
return false; // if the user wasn't stored we don't resync
|
||||
}
|
||||
|
||||
if (!$isnew)
|
||||
{
|
||||
return false; // if the user isn't new we don't sync
|
||||
}
|
||||
|
||||
// ensure the user id is really an int
|
||||
$user_id = (int) $user['id'];
|
||||
|
||||
if (empty($user_id))
|
||||
{
|
||||
die('invalid userid');
|
||||
return false; // if the user id appears invalid then bail out just in case
|
||||
}
|
||||
|
||||
$category = $this->params->get('category', 0);
|
||||
if (empty($category))
|
||||
{
|
||||
JError::raiseWarning(41, JText::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'));
|
||||
return false; // bail out if we don't have a category
|
||||
}
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
// grab the contact ID for this user; note $user_id is cleaned above
|
||||
$db->setQuery('SELECT id FROM #__contact_details WHERE user_id = '. $user_id);
|
||||
$id = $db->loadResult();
|
||||
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_contact/tables');
|
||||
$contact = JTable::getInstance('contact', 'ContactTable');
|
||||
|
||||
if (!$contact)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($id)
|
||||
{
|
||||
$contact->load($id);
|
||||
}
|
||||
elseif ($this->params->get('autopublish', 0))
|
||||
{
|
||||
$contact->published = 1;
|
||||
}
|
||||
|
||||
$contact->name = $user['name'];
|
||||
$contact->user_id = $user_id;
|
||||
$contact->email_to = $user['email'];
|
||||
$contact->catid = $category;
|
||||
$contact->language = '*';
|
||||
|
||||
$autowebpage = $this->params->get('autowebpage', '');
|
||||
|
||||
if (!empty($autowebpage))
|
||||
{
|
||||
// search terms
|
||||
$search_array = array('[name]', '[username]', '[userid]', '[email]');
|
||||
// replacement terms, urlencoded
|
||||
$replace_array = array_map('urlencode', array($user['name'], $user['username'], $user['id'], $user['email']));
|
||||
// now replace it in together
|
||||
$contact->webpage = str_replace($search_array, $replace_array, $autowebpage);
|
||||
}
|
||||
|
||||
if ($contact->check())
|
||||
{
|
||||
$result = $contact->store();
|
||||
}
|
||||
|
||||
if (!(isset($result)) || !$result)
|
||||
{
|
||||
JError::raiseError(42, JText::sprintf('PLG_CONTACTCREATOR_ERR_FAILED_UPDATE', $contact->getError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
48
plugins/user/contactcreator/contactcreator.xml
Normal file
48
plugins/user/contactcreator/contactcreator.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.1" type="plugin" group="user">
|
||||
<name>plg_user_contactcreator</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>August 2009</creationDate>
|
||||
<copyright>(C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>PLG_CONTACTCREATOR_XML_DESCRIPTION</description>
|
||||
<files>
|
||||
<filename plugin="contactcreator">contactcreator.php</filename>
|
||||
<filename>index.html</filename>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">en-GB.plg_user_contactcreator.ini</language>
|
||||
<language tag="en-GB">en-GB.plg_user_contactcreator.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
|
||||
<fieldset name="basic">
|
||||
<field name="autowebpage" type="text" size="40"
|
||||
description="PLG_CONTACTCREATOR_FIELD_AUTOMATIC_WEBPAGE_DESC"
|
||||
label="PLG_CONTACTCREATOR_FIELD_AUTOMATIC_WEBPAGE_LABEL"
|
||||
/>
|
||||
|
||||
<field name="category" type="category"
|
||||
description="PLG_CONTACTCREATOR_FIELD_CATEGORY_DESC"
|
||||
extension="com_contact"
|
||||
label="JCATEGORY"
|
||||
/>
|
||||
|
||||
<field name="autopublish" type="radio"
|
||||
class="btn-group"
|
||||
default="0"
|
||||
description="PLG_CONTACTCREATOR_FIELD_AUTOPUBLISH_DESC"
|
||||
label="PLG_CONTACTCREATOR_FIELD_AUTOPUBLISH_LABEL"
|
||||
>
|
||||
<option value="0">JNo</option>
|
||||
<option value="1">JYes</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
1
plugins/user/contactcreator/index.html
Normal file
1
plugins/user/contactcreator/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
1
plugins/user/index.html
Normal file
1
plugins/user/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
1
plugins/user/joomla/index.html
Normal file
1
plugins/user/joomla/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
290
plugins/user/joomla/joomla.php
Normal file
290
plugins/user/joomla/joomla.php
Normal file
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.joomla
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Joomla User plugin
|
||||
*
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.joomla
|
||||
* @since 1.5
|
||||
*/
|
||||
class PlgUserJoomla extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Remove all sessions for the user name
|
||||
*
|
||||
* Method is called after user data is deleted from the database
|
||||
*
|
||||
* @param array $user Holds the user data
|
||||
* @param boolean $succes True if user was succesfully stored in the database
|
||||
* @param string $msg Message
|
||||
*
|
||||
* @return boolean
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onUserAfterDelete($user, $succes, $msg)
|
||||
{
|
||||
if (!$succes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery(
|
||||
'DELETE FROM ' . $db->quoteName('#__session') .
|
||||
' WHERE ' . $db->quoteName('userid') . ' = ' . (int) $user['id']
|
||||
);
|
||||
$db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to act on a user after it has been saved.
|
||||
*
|
||||
* This method sends a registration email to new users created in the backend.
|
||||
*
|
||||
* @param array $user Holds the new user data.
|
||||
* @param boolean $isnew True if a new user is stored.
|
||||
* @param boolean $success True if user was succesfully stored in the database.
|
||||
* @param string $msg Message.
|
||||
*
|
||||
* @return void
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onUserAfterSave($user, $isnew, $success, $msg)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$config = JFactory::getConfig();
|
||||
$mail_to_user = $this->params->get('mail_to_user', 1);
|
||||
|
||||
if ($isnew)
|
||||
{
|
||||
// TODO: Suck in the frontend registration emails here as well. Job for a rainy day.
|
||||
|
||||
if ($app->isAdmin())
|
||||
{
|
||||
if ($mail_to_user)
|
||||
{
|
||||
|
||||
// Load user_joomla plugin language (not done automatically).
|
||||
$lang = JFactory::getLanguage();
|
||||
$lang->load('plg_user_joomla', JPATH_ADMINISTRATOR);
|
||||
|
||||
// Compute the mail subject.
|
||||
$emailSubject = JText::sprintf(
|
||||
'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT',
|
||||
$user['name'],
|
||||
$config->get('sitename')
|
||||
);
|
||||
|
||||
// Compute the mail body.
|
||||
$emailBody = JText::sprintf(
|
||||
'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY',
|
||||
$user['name'],
|
||||
$config->get('sitename'),
|
||||
JUri::root(),
|
||||
$user['username'],
|
||||
$user['password_clear']
|
||||
);
|
||||
|
||||
// Assemble the email data...the sexy way!
|
||||
$mail = JFactory::getMailer()
|
||||
->setSender(
|
||||
array(
|
||||
$config->get('mailfrom'),
|
||||
$config->get('fromname')
|
||||
)
|
||||
)
|
||||
->addRecipient($user['email'])
|
||||
->setSubject($emailSubject)
|
||||
->setBody($emailBody);
|
||||
|
||||
if (!$mail->Send())
|
||||
{
|
||||
// TODO: Probably should raise a plugin error but this event is not error checked.
|
||||
JError::raiseWarning(500, JText::_('ERROR_SENDING_EMAIL'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Existing user - nothing to do...yet.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should handle any login logic and report back to the subject
|
||||
*
|
||||
* @param array $user Holds the user data
|
||||
* @param array $options Array holding options (remember, autoregister, group)
|
||||
*
|
||||
* @return boolean True on success
|
||||
* @since 1.5
|
||||
*/
|
||||
public function onUserLogin($user, $options = array())
|
||||
{
|
||||
$instance = $this->_getUser($user, $options);
|
||||
|
||||
// If _getUser returned an error, then pass it back.
|
||||
if ($instance instanceof Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the user is blocked, redirect with an error
|
||||
if ($instance->get('block') == 1)
|
||||
{
|
||||
JError::raiseWarning('SOME_ERROR_CODE', JText::_('JERROR_NOLOGIN_BLOCKED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Authorise the user based on the group information
|
||||
if (!isset($options['group']))
|
||||
{
|
||||
$options['group'] = 'USERS';
|
||||
}
|
||||
|
||||
// Check the user can login.
|
||||
$result = $instance->authorise($options['action']);
|
||||
if (!$result)
|
||||
{
|
||||
|
||||
JError::raiseWarning(401, JText::_('JERROR_LOGIN_DENIED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mark the user as logged in
|
||||
$instance->set('guest', 0);
|
||||
|
||||
// Register the needed session variables
|
||||
$session = JFactory::getSession();
|
||||
$session->set('user', $instance);
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
// Check to see the the session already exists.
|
||||
$app = JFactory::getApplication();
|
||||
$app->checkSession();
|
||||
|
||||
// Update the user related fields for the Joomla sessions table.
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName('#__session'))
|
||||
->set($db->quoteName('guest') . ' = ' . $db->quote($instance->get('guest')))
|
||||
->set($db->quoteName('username') . ' = ' . $db->quote($instance->get('username')))
|
||||
->set($db->quoteName('userid') . ' = ' . (int) $instance->get('id'))
|
||||
->where($db->quoteName('session_id') . ' = ' . $db->quote($session->getId()));
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
// Hit the user last visit field
|
||||
$instance->setLastVisit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should handle any logout logic and report back to the subject
|
||||
*
|
||||
* @param array $user Holds the user data.
|
||||
* @param array $options Array holding options (client, ...).
|
||||
*
|
||||
* @return object True on success
|
||||
* @since 1.5
|
||||
*/
|
||||
public function onUserLogout($user, $options = array())
|
||||
{
|
||||
$my = JFactory::getUser();
|
||||
$session = JFactory::getSession();
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Make sure we're a valid user first
|
||||
if ($user['id'] == 0 && !$my->get('tmp_user'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check to see if we're deleting the current session
|
||||
if ($my->get('id') == $user['id'] && $options['clientid'] == $app->getClientId())
|
||||
{
|
||||
// Hit the user last visit field
|
||||
$my->setLastVisit();
|
||||
|
||||
// Destroy the php session for this user
|
||||
$session->destroy();
|
||||
}
|
||||
|
||||
// Force logout all users with that userid
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__session'))
|
||||
->where($db->quoteName('userid') . ' = ' . (int) $user['id'])
|
||||
->where($db->quoteName('client_id') . ' = ' . (int) $options['clientid']);
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a user object
|
||||
*
|
||||
* If options['autoregister'] is true, if the user doesn't exist yet he will be created
|
||||
*
|
||||
* @param array $user Holds the user data.
|
||||
* @param array $options Array holding options (remember, autoregister, group).
|
||||
*
|
||||
* @return object A JUser object
|
||||
* @since 1.5
|
||||
*/
|
||||
protected function _getUser($user, $options = array())
|
||||
{
|
||||
$instance = JUser::getInstance();
|
||||
$id = (int) JUserHelper::getUserId($user['username']);
|
||||
if ($id)
|
||||
{
|
||||
$instance->load($id);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
//TODO : move this out of the plugin
|
||||
$config = JComponentHelper::getParams('com_users');
|
||||
// Default to Registered.
|
||||
$defaultUserGroup = $config->get('new_usertype', 2);
|
||||
|
||||
$instance->set('id', 0);
|
||||
$instance->set('name', $user['fullname']);
|
||||
$instance->set('username', $user['username']);
|
||||
$instance->set('password_clear', $user['password_clear']);
|
||||
// Result should contain an email (check)
|
||||
$instance->set('email', $user['email']);
|
||||
$instance->set('groups', array($defaultUserGroup));
|
||||
|
||||
//If autoregister is set let's register the user
|
||||
$autoregister = isset($options['autoregister']) ? $options['autoregister'] : $this->params->get('autoregister', 1);
|
||||
|
||||
if ($autoregister)
|
||||
{
|
||||
if (!$instance->save())
|
||||
{
|
||||
return JError::raiseWarning('SOME_ERROR_CODE', $instance->getError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No existing user and autoregister off, this is a temporary user.
|
||||
$instance->set('tmp_user', true);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
50
plugins/user/joomla/joomla.xml
Normal file
50
plugins/user/joomla/joomla.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.1" type="plugin" group="user">
|
||||
<name>plg_user_joomla</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>December 2006</creationDate>
|
||||
<copyright>(C) 2005 - 2009 Open Source Matters. All rights reserved.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>PLG_USER_JOOMLA_XML_DESCRIPTION</description>
|
||||
<files>
|
||||
<filename plugin="joomla">joomla.php</filename>
|
||||
<filename>index.html</filename>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">en-GB.plg_user_joomla.ini</language>
|
||||
<language tag="en-GB">en-GB.plg_user_joomla.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
|
||||
<fieldset name="basic">
|
||||
<field name="autoregister" type="radio"
|
||||
class="btn-group"
|
||||
default="1"
|
||||
description="PLG_USER_JOOMLA_FIELD_AUTOREGISTER_DESC"
|
||||
label="PLG_USER_JOOMLA_FIELD_AUTOREGISTER_LABEL"
|
||||
>
|
||||
<option value="0">JNo</option>
|
||||
<option value="1">JYes</option>
|
||||
</field>
|
||||
|
||||
<field name="mail_to_user"
|
||||
type="radio"
|
||||
class="btn-group"
|
||||
default="1"
|
||||
label="PLG_USER_JOOMLA_FIELD_MAILTOUSER_LABEL"
|
||||
description="PLG_USER_JOOMLA_FIELD_MAILTOUSER_DESC">
|
||||
<option
|
||||
value="0">JNO</option>
|
||||
<option
|
||||
value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
290
plugins/user/k2/k2.php
Normal file
290
plugins/user/k2/k2.php
Normal file
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* @version $Id: k2.php 1966 2013-04-29 16:54:48Z lefteris.kavadas $
|
||||
* @package K2
|
||||
* @author JoomlaWorks http://www.joomlaworks.net
|
||||
* @copyright Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
|
||||
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die ;
|
||||
|
||||
jimport('joomla.plugin.plugin');
|
||||
|
||||
class plgUserK2 extends JPlugin
|
||||
{
|
||||
|
||||
function plgUserK2(&$subject, $config)
|
||||
{
|
||||
|
||||
parent::__construct($subject, $config);
|
||||
}
|
||||
|
||||
function onUserAfterSave($user, $isnew, $success, $msg)
|
||||
{
|
||||
return $this->onAfterStoreUser($user, $isnew, $success, $msg);
|
||||
}
|
||||
|
||||
function onUserLogin($user, $options)
|
||||
{
|
||||
return $this->onLoginUser($user, $options);
|
||||
}
|
||||
|
||||
function onUserLogout($user)
|
||||
{
|
||||
return $this->onLogoutUser($user);
|
||||
}
|
||||
|
||||
function onUserAfterDelete($user, $success, $msg)
|
||||
{
|
||||
return $this->onAfterDeleteUser($user, $success, $msg);
|
||||
}
|
||||
|
||||
function onUserBeforeSave($user, $isNew)
|
||||
{
|
||||
return $this->onBeforeStoreUser($user, $isNew);
|
||||
}
|
||||
|
||||
function onAfterStoreUser($user, $isnew, $success, $msg)
|
||||
{
|
||||
|
||||
$mainframe = JFactory::getApplication();
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
jimport('joomla.filesystem.file');
|
||||
$task = JRequest::getCmd('task');
|
||||
|
||||
if ($mainframe->isSite() && ($task == 'activate' || $isnew) && $params->get('stopForumSpam'))
|
||||
{
|
||||
$this->checkSpammer($user);
|
||||
|
||||
}
|
||||
|
||||
if ($mainframe->isSite() && $task != 'activate' && JRequest::getInt('K2UserForm'))
|
||||
{
|
||||
JPlugin::loadLanguage('com_k2');
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'tables');
|
||||
$row = JTable::getInstance('K2User', 'Table');
|
||||
$k2id = $this->getK2UserID($user['id']);
|
||||
JRequest::setVar('id', $k2id, 'post');
|
||||
$row->bind(JRequest::get('post'));
|
||||
$row->set('userID', $user['id']);
|
||||
$row->set('userName', $user['name']);
|
||||
$row->set('ip', $_SERVER['REMOTE_ADDR']);
|
||||
$row->set('hostname', gethostbyaddr($_SERVER['REMOTE_ADDR']));
|
||||
if (isset($user['notes']))
|
||||
{
|
||||
$row->set('notes', $user['notes']);
|
||||
}
|
||||
if ($isnew)
|
||||
{
|
||||
$row->set('group', $params->get('K2UserGroup', 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
$row->set('group', NULL);
|
||||
$row->set('gender', JRequest::getVar('gender'));
|
||||
$row->set('url', JRequest::getString('url'));
|
||||
}
|
||||
if ($row->gender != 'm' && $row->gender != 'f')
|
||||
{
|
||||
$row->gender = 'm';
|
||||
}
|
||||
$row->url = JString::str_ireplace(' ', '', $row->url);
|
||||
$row->url = JString::str_ireplace('"', '', $row->url);
|
||||
$row->url = JString::str_ireplace('<', '', $row->url);
|
||||
$row->url = JString::str_ireplace('>', '', $row->url);
|
||||
$row->url = JString::str_ireplace('\'', '', $row->url);
|
||||
$row->set('description', JRequest::getVar('description', '', 'post', 'string', 4));
|
||||
if ($params->get('xssFiltering'))
|
||||
{
|
||||
$filter = new JFilterInput( array(), array(), 1, 1, 0);
|
||||
$row->description = $filter->clean($row->description);
|
||||
}
|
||||
|
||||
$file = JRequest::get('files');
|
||||
|
||||
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'class.upload.php');
|
||||
$savepath = JPATH_ROOT.DS.'media'.DS.'k2'.DS.'users'.DS;
|
||||
|
||||
if (isset($file['image']) && $file['image']['error'] == 0 && !JRequest::getBool('del_image'))
|
||||
{
|
||||
$handle = new Upload($file['image']);
|
||||
$handle->allowed = array('image/*');
|
||||
if ($handle->uploaded)
|
||||
{
|
||||
$handle->file_auto_rename = false;
|
||||
$handle->file_overwrite = true;
|
||||
$handle->file_new_name_body = $row->id;
|
||||
$handle->image_resize = true;
|
||||
$handle->image_ratio_y = true;
|
||||
$handle->image_x = $params->get('userImageWidth', '100');
|
||||
$handle->Process($savepath);
|
||||
$handle->Clean();
|
||||
}
|
||||
else
|
||||
{
|
||||
$mainframe->enqueueMessage(JText::_('K2_COULD_NOT_UPLOAD_YOUR_IMAGE').$handle->error, 'notice');
|
||||
}
|
||||
$row->image = $handle->file_dst_name;
|
||||
}
|
||||
|
||||
if (JRequest::getBool('del_image'))
|
||||
{
|
||||
|
||||
if (JFile::exists(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'users'.DS.$row->image))
|
||||
{
|
||||
JFile::delete(JPATH_ROOT.DS.'media'.DS.'k2'.DS.'users'.DS.$row->image);
|
||||
}
|
||||
$row->image = '';
|
||||
}
|
||||
|
||||
$row->store();
|
||||
$itemid = $params->get('redirect');
|
||||
|
||||
if (!$isnew && $itemid)
|
||||
{
|
||||
$menu = JSite::getMenu();
|
||||
$item = $menu->getItem($itemid);
|
||||
$url = JRoute::_($item->link.'&Itemid='.$itemid, false);
|
||||
if (JURI::isInternal($url))
|
||||
{
|
||||
$mainframe->redirect($url, JText::_('K2_YOUR_SETTINGS_HAVE_BEEN_SAVED'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onLoginUser($user, $options)
|
||||
{
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
$mainframe = JFactory::getApplication();
|
||||
if ($mainframe->isSite())
|
||||
{
|
||||
// Get the user id
|
||||
$db = JFactory::getDBO();
|
||||
$db->setQuery("SELECT id FROM #__users WHERE username = ".$db->Quote($user['username']));
|
||||
$id = $db->loadResult();
|
||||
|
||||
// If K2 profiles are enabled assign non-existing K2 users to the default K2 group. Update user info for existing K2 users.
|
||||
if ($params->get('K2UserProfile') && $id)
|
||||
{
|
||||
$k2id = $this->getK2UserID($id);
|
||||
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'tables');
|
||||
$row = JTable::getInstance('K2User', 'Table');
|
||||
if ($k2id)
|
||||
{
|
||||
$row->load($k2id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$row->set('userID', $id);
|
||||
$row->set('userName', $user['fullname']);
|
||||
$row->set('group', $params->get('K2UserGroup', 1));
|
||||
}
|
||||
$row->ip = $_SERVER['REMOTE_ADDR'];
|
||||
$row->hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
|
||||
$row->store();
|
||||
}
|
||||
|
||||
// Set the Cookie domain for user based on K2 parameters
|
||||
if ($params->get('cookieDomain') && $id)
|
||||
{
|
||||
setcookie("userID", $id, 0, '/', $params->get('cookieDomain'), 0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function onLogoutUser($user)
|
||||
{
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
$mainframe = JFactory::getApplication();
|
||||
if ($mainframe->isSite() && $params->get('cookieDomain'))
|
||||
{
|
||||
setcookie("userID", "", time() - 3600, '/', $params->get('cookieDomain'), 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function onAfterDeleteUser($user, $succes, $msg)
|
||||
{
|
||||
|
||||
$mainframe = JFactory::getApplication();
|
||||
$db = JFactory::getDBO();
|
||||
$query = "DELETE FROM #__k2_users WHERE userID={$user['id']}";
|
||||
$db->setQuery($query);
|
||||
$db->query();
|
||||
}
|
||||
|
||||
function onBeforeStoreUser($user, $isNew)
|
||||
{
|
||||
$mainframe = JFactory::getApplication();
|
||||
$params = JComponentHelper::getParams('com_k2');
|
||||
$session = JFactory::getSession();
|
||||
if ($params->get('K2UserProfile') && $isNew && $params->get('recaptchaOnRegistration') && $mainframe->isSite() && !$session->get('socialConnectData'))
|
||||
{
|
||||
if (!function_exists('_recaptcha_qsencode'))
|
||||
{
|
||||
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'recaptchalib.php');
|
||||
}
|
||||
$privatekey = $params->get('recaptcha_private_key');
|
||||
$recaptcha_challenge_field = isset($_POST["recaptcha_challenge_field"]) ? $_POST["recaptcha_challenge_field"] : '';
|
||||
$recaptcha_response_field = isset($_POST["recaptcha_response_field"]) ? $_POST["recaptcha_response_field"] : '';
|
||||
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);
|
||||
if (!$resp->is_valid)
|
||||
{
|
||||
if (K2_JVERSION != '15')
|
||||
{
|
||||
$url = 'index.php?option=com_users&view=registration';
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = 'index.php?option=com_user&view=register';
|
||||
}
|
||||
$mainframe->redirect($url, JText::_('K2_THE_WORDS_YOU_TYPED_DID_NOT_MATCH_THE_ONES_DISPLAYED_PLEASE_TRY_AGAIN'), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getK2UserID($id)
|
||||
{
|
||||
|
||||
$db = JFactory::getDBO();
|
||||
$query = "SELECT id FROM #__k2_users WHERE userID={$id}";
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadResult();
|
||||
return $result;
|
||||
}
|
||||
|
||||
function checkSpammer(&$user)
|
||||
{
|
||||
if (!$user['block'])
|
||||
{
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$email = urlencode($user['email']);
|
||||
$username = urlencode($user['username']);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://www.stopforumspam.com/api?ip='.$ip.'&email='.$email.'&username='.$username.'&f=json');
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($httpCode == 200)
|
||||
{
|
||||
$response = json_decode($response);
|
||||
if ($response->ip->appears || $response->email->appears || $response->username->appears)
|
||||
{
|
||||
$db = JFactory::getDBO();
|
||||
$db->setQuery("UPDATE #__users SET block = 1 WHERE id = ".$user['id']);
|
||||
$db->query();
|
||||
$user['notes'] = JText::_('K2_POSSIBLE_SPAMMER_DETECTED_BY_STOPFORUMSPAM');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
15
plugins/user/k2/k2.xml
Normal file
15
plugins/user/k2/k2.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="2.5" type="plugin" group="user" method="upgrade">
|
||||
<name>User - K2</name>
|
||||
<author>JoomlaWorks</author>
|
||||
<creationDate>July 8th, 2013</creationDate>
|
||||
<copyright>Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.</copyright>
|
||||
<authorEmail>please-use-the-contact-form@joomlaworks.net</authorEmail>
|
||||
<authorUrl>www.joomlaworks.net</authorUrl>
|
||||
<version>2.6.7</version>
|
||||
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
|
||||
<description>K2_A_USER_SYNCHRONIZATION_PLUGIN_FOR_K2</description>
|
||||
<files>
|
||||
<filename plugin="k2">k2.php</filename>
|
||||
</files>
|
||||
</extension>
|
||||
1
plugins/user/profile/fields/index.html
Normal file
1
plugins/user/profile/fields/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
89
plugins/user/profile/fields/tos.php
Normal file
89
plugins/user/profile/fields/tos.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.profile
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
JFormHelper::loadFieldClass('radio');
|
||||
|
||||
/**
|
||||
* Provides input for TOS
|
||||
*
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.profile
|
||||
* @since 2.5.5
|
||||
*/
|
||||
class JFormFieldTos extends JFormFieldRadio
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 2.5.5
|
||||
*/
|
||||
protected $type = 'Tos';
|
||||
|
||||
/**
|
||||
* Method to get the field label markup.
|
||||
*
|
||||
* @return string The field label markup.
|
||||
*
|
||||
* @since 2.5.5
|
||||
*/
|
||||
protected function getLabel()
|
||||
{
|
||||
$label = '';
|
||||
|
||||
if ($this->hidden)
|
||||
{
|
||||
return $label;
|
||||
}
|
||||
|
||||
// Get the label text from the XML element, defaulting to the element name.
|
||||
$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
|
||||
$text = $this->translateLabel ? JText::_($text) : $text;
|
||||
|
||||
// Set required to true as this field is not displayed at all if not required.
|
||||
$this->required = true;
|
||||
|
||||
// Add CSS and JS for the TOS field
|
||||
$doc = JFactory::getDocument();
|
||||
$css = "#jform_profile_tos {width: 18em; margin: 0 !important; padding: 0 2px !important;}
|
||||
#jform_profile_tos input {margin:0 5px 0 0 !important; width:10px !important;}
|
||||
#jform_profile_tos label {margin:0 15px 0 0 !important; width:auto;}
|
||||
";
|
||||
$doc->addStyleDeclaration($css);
|
||||
JHtml::_('behavior.modal');
|
||||
|
||||
// Build the class for the label.
|
||||
$class = !empty($this->description) ? 'hasTip' : '';
|
||||
$class = $class . ' required';
|
||||
$class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
|
||||
|
||||
// Add the opening label tag and main attributes attributes.
|
||||
$label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"';
|
||||
|
||||
// If a description is specified, use it to build a tooltip.
|
||||
if (!empty($this->description))
|
||||
{
|
||||
$label .= ' title="'
|
||||
. htmlspecialchars(
|
||||
trim($text, ':') . '::' . ($this->translateDescription ? JText::_($this->description) : $this->description),
|
||||
ENT_COMPAT, 'UTF-8'
|
||||
) . '"';
|
||||
}
|
||||
|
||||
$tosarticle = $this->element['article'] ? (int) $this->element['article'] : 1;
|
||||
$link = '<a class="modal" title="" href="index.php?option=com_content&view=article&layout=modal&id=' . $tosarticle . '&tmpl=component" rel="{handler: \'iframe\', size: {x:800, y:500}}">' . $text . '</a>';
|
||||
|
||||
// Add the label text and closing tag.
|
||||
$label .= '>' . $link . '<span class="star"> *</span></label>';
|
||||
|
||||
return $label;
|
||||
}
|
||||
}
|
||||
1
plugins/user/profile/index.html
Normal file
1
plugins/user/profile/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
412
plugins/user/profile/profile.php
Normal file
412
plugins/user/profile/profile.php
Normal file
@ -0,0 +1,412 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.profile
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* An example custom profile plugin.
|
||||
*
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage User.profile
|
||||
* @since 1.6
|
||||
*/
|
||||
class PlgUserProfile extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Date of birth.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.1
|
||||
*/
|
||||
private $_date = '';
|
||||
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $subject The object to observe
|
||||
* @param array $config An array that holds the plugin configuration
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function __construct(& $subject, $config)
|
||||
{
|
||||
parent::__construct($subject, $config);
|
||||
JFormHelper::addFieldPath(__DIR__ . '/fields');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $context The context for the data
|
||||
* @param integer $data The user id
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onContentPrepareData($context, $data)
|
||||
{
|
||||
// Check we are manipulating a valid form.
|
||||
if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_admin.profile')))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_object($data))
|
||||
{
|
||||
$userId = isset($data->id) ? $data->id : 0;
|
||||
|
||||
if (!isset($data->profile) and $userId > 0)
|
||||
{
|
||||
// Load the profile data from the database.
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery(
|
||||
'SELECT profile_key, profile_value FROM #__user_profiles' .
|
||||
' WHERE user_id = ' . (int) $userId . " AND profile_key LIKE 'profile.%'" .
|
||||
' ORDER BY ordering'
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$results = $db->loadRowList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->_subject->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Merge the profile data.
|
||||
$data->profile = array();
|
||||
|
||||
foreach ($results as $v)
|
||||
{
|
||||
$k = str_replace('profile.', '', $v[0]);
|
||||
$data->profile[$k] = json_decode($v[1], true);
|
||||
if ($data->profile[$k] === null)
|
||||
{
|
||||
$data->profile[$k] = $v[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!JHtml::isRegistered('users.url'))
|
||||
{
|
||||
JHtml::register('users.url', array(__CLASS__, 'url'));
|
||||
}
|
||||
if (!JHtml::isRegistered('users.calendar'))
|
||||
{
|
||||
JHtml::register('users.calendar', array(__CLASS__, 'calendar'));
|
||||
}
|
||||
if (!JHtml::isRegistered('users.tos'))
|
||||
{
|
||||
JHtml::register('users.tos', array(__CLASS__, 'tos'));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function url($value)
|
||||
{
|
||||
if (empty($value))
|
||||
{
|
||||
return JHtml::_('users.value', $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert website url to utf8 for display
|
||||
$value = JStringPunycode::urlToUTF8(htmlspecialchars($value));
|
||||
|
||||
if (substr($value, 0, 4) == "http")
|
||||
{
|
||||
return '<a href="' . $value . '">' . $value . '</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '<a href="http://' . $value . '">' . $value . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function calendar($value)
|
||||
{
|
||||
if (empty($value))
|
||||
{
|
||||
return JHtml::_('users.value', $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return JHtml::_('date', $value, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tos($value)
|
||||
{
|
||||
if ($value)
|
||||
{
|
||||
return JText::_('JYES');
|
||||
}
|
||||
else
|
||||
{
|
||||
return JText::_('JNO');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JForm $form The form to be altered.
|
||||
* @param array $data The associated data for the form.
|
||||
*
|
||||
* @return boolean
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onContentPrepareForm($form, $data)
|
||||
{
|
||||
if (!($form instanceof JForm))
|
||||
{
|
||||
$this->_subject->setError('JERROR_NOT_A_FORM');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check we are manipulating a valid form.
|
||||
$name = $form->getName();
|
||||
if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration')))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add the registration fields to the form.
|
||||
JForm::addFormPath(__DIR__ . '/profiles');
|
||||
$form->loadFile('profile', false);
|
||||
|
||||
$fields = array(
|
||||
'address1',
|
||||
'address2',
|
||||
'city',
|
||||
'region',
|
||||
'country',
|
||||
'postal_code',
|
||||
'phone',
|
||||
'website',
|
||||
'favoritebook',
|
||||
'aboutme',
|
||||
'dob',
|
||||
'tos',
|
||||
);
|
||||
|
||||
//Change fields description when displayed in front-end
|
||||
$app = JFactory::getApplication();
|
||||
if ($app->isSite())
|
||||
{
|
||||
$form->setFieldAttribute('address1', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('address2', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('city', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('region', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('country', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('postal_code', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('phone', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('website', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('favoritebook', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('aboutme', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('dob', 'description', 'PLG_USER_PROFILE_FILL_FIELD_DESC_SITE', 'profile');
|
||||
$form->setFieldAttribute('tos', 'description', 'PLG_USER_PROFILE_FIELD_TOS_DESC_SITE', 'profile');
|
||||
}
|
||||
|
||||
$tosarticle = $this->params->get('register_tos_article');
|
||||
$tosenabled = $this->params->get('register-require_tos', 0);
|
||||
|
||||
// We need to be in the registration form, field needs to be enabled and we need an article ID
|
||||
if ($name != 'com_users.registration' || !$tosenabled || !$tosarticle)
|
||||
{
|
||||
// We only want the TOS in the registration form
|
||||
$form->removeField('tos', 'profile');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Push the TOS article ID into the TOS field.
|
||||
$form->setFieldAttribute('tos', 'article', $tosarticle, 'profile');
|
||||
}
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// Case using the users manager in admin
|
||||
if ($name == 'com_users.user')
|
||||
{
|
||||
// Remove the field if it is disabled in registration and profile
|
||||
if ($this->params->get('register-require_' . $field, 1) == 0
|
||||
&& $this->params->get('profile-require_' . $field, 1) == 0
|
||||
)
|
||||
{
|
||||
$form->removeField($field, 'profile');
|
||||
}
|
||||
}
|
||||
// Case registration
|
||||
elseif ($name == 'com_users.registration')
|
||||
{
|
||||
// Toggle whether the field is required.
|
||||
if ($this->params->get('register-require_' . $field, 1) > 0)
|
||||
{
|
||||
$form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profile');
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->removeField($field, 'profile');
|
||||
}
|
||||
|
||||
if ($this->params->get('register-require_dob', 1) > 0)
|
||||
{
|
||||
$form->setFieldAttribute('spacer', 'type', 'spacer', 'profile');
|
||||
}
|
||||
}
|
||||
// Case profile in site or admin
|
||||
elseif ($name == 'com_users.profile' || $name == 'com_admin.profile')
|
||||
{
|
||||
// Toggle whether the field is required.
|
||||
if ($this->params->get('profile-require_' . $field, 1) > 0)
|
||||
{
|
||||
$form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'profile');
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->removeField($field, 'profile');
|
||||
}
|
||||
|
||||
if ($this->params->get('profile-require_dob', 1) > 0)
|
||||
{
|
||||
$form->setFieldAttribute('spacer', 'type', 'spacer', 'profile');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is called before user data is stored in the database
|
||||
*
|
||||
* @param array $user Holds the old user data.
|
||||
* @param boolean $isnew True if a new user is stored.
|
||||
* @param array $data Holds the new user data.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 3.1
|
||||
* @throws InvalidArgumentException on invalid date.
|
||||
*/
|
||||
public function onUserBeforeSave($user, $isnew, $data)
|
||||
{
|
||||
// Check that the date is valid.
|
||||
if (!empty($data['profile']['dob']))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Convert website url to punycode
|
||||
$data['profile']['website'] = JStringPunycode::urlToPunycode($data['profile']['website']);
|
||||
|
||||
$date = new JDate($data['profile']['dob']);
|
||||
$this->_date = $date->format('Y-m-d');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// Throw an exception if date is not valid.
|
||||
throw new InvalidArgumentException(JText::_('PLG_USER_PROFILE_ERROR_INVALID_DOB'));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onUserAfterSave($data, $isNew, $result, $error)
|
||||
{
|
||||
$userId = JArrayHelper::getValue($data, 'id', 0, 'int');
|
||||
|
||||
if ($userId && $result && isset($data['profile']) && (count($data['profile'])))
|
||||
{
|
||||
try
|
||||
{
|
||||
// Sanitize the date
|
||||
$data['profile']['dob'] = $this->_date;
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__user_profiles'))
|
||||
->where($db->quoteName('user_id') . ' = ' . (int) $userId)
|
||||
->where($db->quoteName('profile_key') . ' LIKE ' . $db->quote('profile.%'));
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
$tuples = array();
|
||||
$order = 1;
|
||||
|
||||
foreach ($data['profile'] as $k => $v)
|
||||
{
|
||||
$tuples[] = '(' . $userId . ', ' . $db->quote('profile.' . $k) . ', ' . $db->quote(json_encode($v)) . ', ' . $order++ . ')';
|
||||
}
|
||||
|
||||
$db->setQuery('INSERT INTO #__user_profiles VALUES ' . implode(', ', $tuples));
|
||||
$db->execute();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->_subject->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all user profile information for the given user ID
|
||||
*
|
||||
* Method is called after user data is deleted from the database
|
||||
*
|
||||
* @param array $user Holds the user data
|
||||
* @param boolean $success True if user was succesfully stored in the database
|
||||
* @param string $msg Message
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onUserAfterDelete($user, $success, $msg)
|
||||
{
|
||||
if (!$success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$userId = JArrayHelper::getValue($user, 'id', 0, 'int');
|
||||
|
||||
if ($userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery(
|
||||
'DELETE FROM #__user_profiles WHERE user_id = ' . $userId .
|
||||
" AND profile_key LIKE 'profile.%'"
|
||||
);
|
||||
|
||||
$db->execute();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->_subject->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
277
plugins/user/profile/profile.xml
Normal file
277
plugins/user/profile/profile.xml
Normal file
@ -0,0 +1,277 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.1" type="plugin" group="user">
|
||||
<name>plg_user_profile</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>January 2008</creationDate>
|
||||
<copyright>(C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>PLG_USER_PROFILE_XML_DESCRIPTION</description>
|
||||
|
||||
<files>
|
||||
<filename plugin="profile">profile.php</filename>
|
||||
<filename>index.html</filename>
|
||||
<folder>profiles</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">en-GB.plg_user_profile.ini</language>
|
||||
<language tag="en-GB">en-GB.plg_user_profile.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
|
||||
<fieldset name="basic"
|
||||
addfieldpath="/administrator/components/com_content/models/fields">
|
||||
<field name="register-require-user" type="spacer" class="text"
|
||||
label="PLG_USER_PROFILE_FIELD_NAME_REGISTER_REQUIRE_USER"
|
||||
/>
|
||||
|
||||
<field name="register-require_address1" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_address2" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS2_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS2_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_city" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_CITY_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_CITY_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_region" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_REGION_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_REGION_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_country" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_COUNTRY_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_COUNTRY_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_postal_code" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_POSTAL_CODE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_POSTAL_CODE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_phone" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_PHONE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_PHONE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="register-require_website" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_WEB_SITE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_WEB_SITE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field name="register-require_favoritebook"
|
||||
type="list"
|
||||
|
||||
label="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_DESC"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="register-require_aboutme"
|
||||
type="list"
|
||||
|
||||
label="PLG_USER_PROFILE_FIELD_ABOUT_ME_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_ABOUT_ME_DESC"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field
|
||||
name="register-require_tos"
|
||||
type="list"
|
||||
default="0"
|
||||
label="PLG_USER_PROFILE_FIELD_TOS_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_TOS_DESC"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field
|
||||
name="register_tos_article"
|
||||
type="modal_article"
|
||||
|
||||
label="PLG_USER_PROFILE_FIELD_TOS_ARTICLE_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_TOS_ARTICLE_DESC"
|
||||
/>
|
||||
<field
|
||||
name="register-require_dob"
|
||||
type="list"
|
||||
|
||||
label="PLG_USER_PROFILE_FIELD_DOB_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_DOB_DESC">
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field name="spacer1" type="spacer"
|
||||
hr="true"
|
||||
/>
|
||||
<field name="profile-require-user" type="spacer" class="text"
|
||||
label="PLG_USER_PROFILE_FIELD_NAME_PROFILE_REQUIRE_USER"
|
||||
/>
|
||||
|
||||
<field name="profile-require_address1" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_address2" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS2_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS2_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_city" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_CITY_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_CITY_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_region" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_REGION_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_REGION_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_country" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_COUNTRY_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_COUNTRY_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_postal_code" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_POSTAL_CODE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_POSTAL_CODE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_phone" type="list"
|
||||
description="PLG_USER_PROFILE_FIELD_PHONE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_PHONE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field name="profile-require_website" type="list"
|
||||
|
||||
description="PLG_USER_PROFILE_FIELD_WEB_SITE_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_WEB_SITE_LABEL"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field name="profile-require_favoritebook"
|
||||
type="list"
|
||||
label="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_DESC">
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="profile-require_aboutme"
|
||||
type="list"
|
||||
label="PLG_USER_PROFILE_FIELD_ABOUT_ME_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_ABOUT_ME_DESC">
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
<field
|
||||
name="profile-require_dob"
|
||||
type="list"
|
||||
label="PLG_USER_PROFILE_FIELD_DOB_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_DOB_DESC"
|
||||
>
|
||||
<option value="2">JOPTION_REQUIRED</option>
|
||||
<option value="1">JOPTION_OPTIONAL</option>
|
||||
<option value="0">JDISABLED</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
1
plugins/user/profile/profiles/index.html
Normal file
1
plugins/user/profile/profiles/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
||||
124
plugins/user/profile/profiles/profile.xml
Normal file
124
plugins/user/profile/profiles/profile.xml
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fields name="profile">
|
||||
<fieldset name="profile"
|
||||
label="PLG_USER_PROFILE_SLIDER_LABEL"
|
||||
>
|
||||
<field
|
||||
name="address1"
|
||||
type="text"
|
||||
id="address1"
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS1_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="address2"
|
||||
type="text"
|
||||
id="address2"
|
||||
description="PLG_USER_PROFILE_FIELD_ADDRESS2_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_ADDRESS2_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="city"
|
||||
type="text"
|
||||
id="city"
|
||||
description="PLG_USER_PROFILE_FIELD_CITY_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_CITY_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="region"
|
||||
type="text"
|
||||
id="region"
|
||||
description="PLG_USER_PROFILE_FIELD_REGION_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_REGION_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="country"
|
||||
type="text"
|
||||
id="country"
|
||||
description="PLG_USER_PROFILE_FIELD_COUNTRY_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_COUNTRY_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="postal_code"
|
||||
type="text"
|
||||
id="postal_code"
|
||||
description="PLG_USER_PROFILE_FIELD_POSTAL_CODE_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_POSTAL_CODE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="phone"
|
||||
type="tel"
|
||||
id="phone"
|
||||
description="PLG_USER_PROFILE_FIELD_PHONE_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_PHONE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="website"
|
||||
type="url"
|
||||
id="website"
|
||||
description="PLG_USER_PROFILE_FIELD_WEB_SITE_DESC"
|
||||
filter="url"
|
||||
label="PLG_USER_PROFILE_FIELD_WEB_SITE_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
<field
|
||||
name="favoritebook"
|
||||
type="text"
|
||||
description="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_DESC"
|
||||
filter="string"
|
||||
label="PLG_USER_PROFILE_FIELD_FAVORITE_BOOK_LABEL"
|
||||
size="30"
|
||||
/>
|
||||
<field
|
||||
name="aboutme"
|
||||
type="textarea"
|
||||
description="PLG_USER_PROFILE_FIELD_ABOUT_ME_DESC"
|
||||
label="PLG_USER_PROFILE_FIELD_ABOUT_ME_LABEL"
|
||||
cols="30"
|
||||
rows="5"
|
||||
filter="safehtml"
|
||||
/>
|
||||
<field name="spacer" type="hidden" class="text"
|
||||
label="PLG_USER_PROFILE_SPACER_DOB"
|
||||
/>
|
||||
<field
|
||||
name="dob"
|
||||
type="calendar"
|
||||
label="PLG_USER_PROFILE_FIELD_DOB_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_DOB_DESC"
|
||||
format="%Y-%m-%d"
|
||||
/>
|
||||
<field
|
||||
name="tos"
|
||||
type="tos"
|
||||
default=""
|
||||
label="PLG_USER_PROFILE_FIELD_TOS_LABEL"
|
||||
description="PLG_USER_PROFILE_FIELD_TOS_DESC">
|
||||
<option value="1">PLG_USER_PROFILE_OPTION_AGREE</option>
|
||||
<option value="">JNO</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
Reference in New Issue
Block a user