本文整理汇总了PHP中FD::token方法的典型用法代码示例。如果您正苦于以下问题:PHP FD::token方法的具体用法?PHP FD::token怎么用?PHP FD::token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FD
的用法示例。
在下文中一共展示了FD::token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: token
/**
* Generates token for the form.
*
* @since 1.0
* @access public
* @return string
*/
public static function token()
{
$theme = FD::themes();
$token = FD::token();
$theme->set('token', $token);
$content = $theme->output('admin/html/form.token');
return $content;
}
示例2: __construct
public function __construct()
{
$config = FD::config();
$this->namespace = "EASYSOCIAL";
$this->shortName = "es";
$this->environment = $config->get('general.environment');
$this->mode = $config->get('general.mode');
$this->inline = $config->get('general.inline');
$this->version = FD::getLocalVersion();
$this->baseUrl = FD::getBaseUrl();
$this->token = FD::token();
$this->enableCdn = $config->get('general.cdn.enabled');
// moment locale mapping against joomla language
// If the counter part doesn't exist, then we all back to the nearest possible one, or en-gb
$momentLangMap = array('af-za' => 'en-gb', 'ar-aa' => 'ar', 'bg-bg' => 'bg', 'bn-bd' => 'en-gb', 'ca-es' => 'ca', 'cs-cz' => 'cs', 'da-dk' => 'da', 'de-de' => 'de', 'el-gr' => 'el', 'en-gb' => 'en-gb', 'en-us' => 'en-gb', 'es-cl' => 'es', 'es-es' => 'es', 'fa-ir' => 'fa', 'fi-fi' => 'fi', 'fr-fr' => 'fr', 'he-il' => 'he', 'hr-hr' => 'hr', 'hu-hu' => 'hu', 'hy-am' => 'hy-am', 'id-id' => 'id', 'it-it' => 'it', 'ja-jp' => 'ja', 'ko-kr' => 'ko', 'lt-lt' => 'lt', 'ms-my' => 'ms-my', 'nb-no' => 'nb', 'nl-nl' => 'nl', 'pl-pl' => 'pl', 'pt-br' => 'pt-br', 'pt-pt' => 'pt', 'ro-ro' => 'ro', 'ru-ru' => 'ru', 'sq-al' => 'sq', 'sv-se' => 'sv', 'sw-ke' => 'en-gb', 'th-th' => 'th', 'tr-tr' => 'tr', 'uk-ua' => 'uk', 'vi-vn' => 'vi', 'zh-cn' => 'zh-cn', 'zh-hk' => 'zh-cn', 'zh-tw' => 'zh-tw');
$this->options['momentLang'] = $momentLangMap[strtolower(JFactory::getLanguage()->getTag())];
// Let the component configuration initialize all values
parent::__construct();
}
示例3: store
/**
* Saves a group
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function store()
{
// Check for request forgeries
FD::checkToken();
// Load front end's language file
FD::language()->loadSite();
// Get the current view
$view = $this->getCurrentView();
// Get the current task
$task = $this->getTask();
// Determines if this group is being edited.
$id = $this->input->get('id', 0, 'int');
// Flag to see if this is new or edit
$isNew = empty($id);
// Get the posted data
$post = $this->input->getArray('post');
$options = array();
if ($isNew) {
// Include group library
FD::import('admin:/includes/group/group');
$group = new SocialGroup();
$categoryId = $this->input->get('category_id', 0, 'int');
} else {
$group = FD::group($id);
$options['data'] = true;
$options['dataId'] = $group->id;
$options['dataType'] = SOCIAL_FIELDS_GROUP_GROUP;
$categoryId = $group->category_id;
}
// Set the necessary data
$options['uid'] = $categoryId;
$options['group'] = SOCIAL_FIELDS_GROUP_GROUP;
// Get fields model
$fieldsModel = FD::model('Fields');
// Get the custom fields
$fields = $fieldsModel->getCustomFields($options);
// Initialize default registry
$registry = FD::registry();
// Get disallowed keys so we wont get wrong values.
$disallowed = array(FD::token(), 'option', 'task', 'controller', 'autoapproval');
// Process $_POST vars
foreach ($post as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value)) {
$value = json_encode($value);
}
$registry->set($key, $value);
}
}
// Convert the values into an array.
$data = $registry->toArray();
// Get the fields lib
$fieldsLib = FD::fields();
// Build arguments to be passed to the field apps.
$args = array(&$data, &$group);
// @trigger onAdminEditValidate
$errors = $fieldsLib->trigger('onAdminEditValidate', $options['group'], $fields, $args);
// If there are errors, we should be exiting here.
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_FORM_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('form', $errors);
}
// @trigger onAdminEditBeforeSave
$errors = $fieldsLib->trigger('onAdminEditBeforeSave', $options['group'], $fields, $args);
// If there are errors, we should be exiting here.
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_FORM_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('form', $errors);
}
// Initialise group data for new group
if ($isNew) {
// Set the category id for the group
$group->category_id = $categoryId;
$group->creator_uid = $this->my->id;
$group->creator_type = SOCIAL_TYPE_USER;
$group->state = SOCIAL_STATE_PUBLISHED;
$group->hits = 0;
// Generate a unique key for this group which serves as a password
$group->key = md5(FD::date()->toSql() . $this->my->password . uniqid());
}
// Bind the user object with the form data.
$group->bind($data);
// Save the group
$group->save();
// After the group is created, assign the current user as the node item
if ($isNew) {
$group->createOwner($this->my->id);
}
//.........这里部分代码省略.........
示例4: miniRegister
/**
* Processes quick registrations
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function miniRegister()
{
FD::checkToken();
// Get current user's info
$session = JFactory::getSession();
// Get necessary info about the current registration process.
$registration = FD::table('Registration');
$registration->load($session->getId());
// Get a new registry object
$registry = FD::get('Registry');
if (!empty($registration->values)) {
$registry->load($registration->values);
}
// Load json library
$json = FD::json();
// Get the token string
$token = FD::token();
// Get post values
$post = JRequest::get('POST');
// Keys to exclude
$exclude = array($token, 'option', 'controller', 'task');
// Process $_POST vars
foreach ($post as $key => $value) {
if (!in_array($key, $exclude)) {
if (is_array($value)) {
$value = $json->encode($value);
}
$registry->set($key, $value);
}
}
$profileModel = FD::model('profiles');
$totalProfiles = $profileModel->getTotalProfiles();
$config = FD::config();
$minimode = $config->get('registrations.mini.mode', 'quick');
$miniprofile = $config->get('registrations.mini.profile', 'default');
// Might be coming from module, in which we have to respect module settings
if (isset($post['modRegisterType']) && isset($post['modRegisterProfile'])) {
$minimode = $post['modRegisterType'];
$miniprofile = $post['modRegisterProfile'];
}
$profileId = 0;
// If selected profile is default, then we check how many profiles are there
if ($miniprofile === 'default') {
// If only 1 profile is found, then we assign it directly
// if ($totalProfiles == 1) {
// $profileId = $profileModel->getDefaultProfile()->id;
// }
// We no longer allow the ability for user to select profile
// This is because the rendered field might be different from user selected profile
// Under that case, the mapping of the fields will be off and unable to validate/store accordingly
// EG. Profile 1 has a password field with id 3, while Profile 2 has a password field id 5, if the rendered field is 3, but user selected profile 2, validation will fail because of field mismatch
// Hence if the settings is set to default profile, then we always use default profile
$profileId = $profileModel->getDefaultProfile()->id;
} else {
$profileId = $miniprofile;
}
if (!empty($profileId)) {
// Set the profile id directly
$registration->profile_id = $profileId;
$registry->set('profile_id', $profileId);
// Directly set the registration step as 1
$registration->step = 1;
$registration->addStepAccess(1);
}
$registration->values = $registry->toString();
$state = $registration->store();
$view = $this->getCurrentView();
// Decide what to do here based on the configuration
// FULL -> Registration page, registration page then decides if there is 1 or more profile to choose
// QUICK && profile id assigned -> quickRegistration
// QUICK && no profile id -> Registration page with parameter quick=1
// If mode is set to full, then we redirect to registration page
if ($minimode === 'full') {
$view->setMessage(JText::_('COM_EASYSOCIAL_REGISTRATIONS_COMPLETE_REGISTRATION'), SOCIAL_MSG_INFO);
return $view->call('fullRegister', $profileId);
}
if ($minimode === 'quick') {
if (empty($profileId)) {
return $view->call('selectProfile');
} else {
return $this->quickRegister();
}
}
return $view->call(__FUNCTION__);
}
示例5: store
public function store()
{
FD::checkToken();
FD::language()->loadSite();
$my = FD::user();
$view = $this->getCurrentView();
$task = $this->getTask();
$id = JRequest::getInt('id');
$event = FD::event($id);
$isNew = empty($event->id);
$post = JRequest::get('POST');
$options = array();
if ($isNew) {
$event->category_id = JRequest::getInt('category_id');
$event->creator_uid = $my->id;
$event->creator_type = SOCIAL_TYPE_USER;
$event->state = SOCIAL_STATE_PUBLISHED;
$event->key = md5(FD::date()->toSql() . $my->password . uniqid());
} else {
$options['data'] = true;
$options['dataId'] = $event->id;
$options['dataType'] = SOCIAL_FIELDS_GROUP_EVENT;
}
$options['uid'] = $event->category_id;
$options['group'] = SOCIAL_FIELDS_GROUP_EVENT;
$fields = FD::model('fields')->getCustomFields($options);
$registry = FD::registry();
$disallowed = array(FD::token(), 'option', 'task', 'controller');
foreach ($post as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value)) {
$value = FD::json()->encode($value);
}
$registry->set($key, $value);
}
}
$data = $registry->toArray();
$fieldsLib = FD::fields();
$args = array(&$data, &$event);
$errors = $fieldsLib->trigger('onAdminEditValidate', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
if (!empty($errors)) {
$view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_FORM_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
JRequest::set($data, 'POST');
return $view->call('form', $errors);
}
$errors = $fieldsLib->trigger('onAdminEditBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
if (!empty($errors)) {
$view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_FORM_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
JRequest::set($data, 'POST');
return $view->call('form', $errors);
}
$event->bind($data);
$event->save();
if ($isNew) {
$event->createOwner();
}
$args = array(&$data, &$event);
$fieldsLib->trigger('onAdminEditAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
$event->bindCustomFields($data);
$args = array(&$data, &$event);
$fieldsLib->trigger('onAdminEditAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
if ($isNew) {
$event->createStream('create', $event->creator_uid, $event->creator_type);
}
// Jason: We do not want to create "update" stream if the edit occurs at backend?
/*else {
// Only create if applyRecurring is false or event is not a child
// applyRecurring && parent = true
// applyRecurring && child = false
// !applyRecurring && parent = true
// !applyRecurring && child = true
if (empty($data['applyRecurring']) || !$event->isRecurringEvent()) {
$event->createStream('update', $my->id, SOCIAL_TYPE_USER);
}
}*/
$message = JText::_($isNew ? 'COM_EASYSOCIAL_EVENTS_FORM_CREATE_SUCCESS' : 'COM_EASYSOCIAL_EVENTS_FORM_UPDATE_SUCCESS');
$view->setMessage($message, SOCIAL_MSG_SUCCESS);
return $view->call(__FUNCTION__, $task, $event);
}
示例6: tokenize
public static function tokenize($url, $xhtml = false, $ssl = null)
{
$url .= '&' . FD::token() . '=1';
return FRoute::_($url, $xhtml, $ssl);
}
示例7: update
/**
* Updates the group
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function update()
{
// Check for request forgeries
FD::checkToken();
// Only registered members allowed
FD::requireLogin();
// Get the current view
$view = $this->getCurrentView();
// Get the group
$id = JRequest::getInt('id');
$group = FD::group($id);
$my = FD::user();
if (!$group->id || !$id) {
$view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_INVALID_ID_PROVIDED'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__);
}
// Only allow user to edit if they have access
if (!$group->isAdmin() && !$my->isSiteAdmin()) {
$view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_NO_ACCESS'), SOCIAL_MSG_ERROR);
return $view->call(__FUNCTION__, $group);
}
// Get post data.
$post = JRequest::get('POST');
// Get all published fields apps that are available in the current form to perform validations
$fieldsModel = FD::model('Fields');
// Only fetch relevant fields for this user.
$options = array('group' => SOCIAL_TYPE_GROUP, 'uid' => $group->getCategory()->id, 'data' => true, 'dataId' => $group->id, 'dataType' => SOCIAL_TYPE_GROUP, 'visible' => SOCIAL_PROFILES_VIEW_EDIT);
$fields = $fieldsModel->getCustomFields($options);
// Load json library.
$json = FD::json();
// Initialize default registry
$registry = FD::registry();
// Get disallowed keys so we wont get wrong values.
$disallowed = array(FD::token(), 'option', 'task', 'controller');
// Process $_POST vars
foreach ($post as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value)) {
$value = $json->encode($value);
}
$registry->set($key, $value);
}
}
// Convert the values into an array.
$data = $registry->toArray();
// Perform field validations here. Validation should only trigger apps that are loaded on the form
// @trigger onRegisterValidate
$fieldsLib = FD::fields();
// Get the general field trigger handler
$handler = $fieldsLib->getHandler();
// Build arguments to be passed to the field apps.
$args = array(&$data, &$group);
// Ensure that there is no errors.
// @trigger onEditValidate
$errors = $fieldsLib->trigger('onEditValidate', SOCIAL_FIELDS_GROUP_GROUP, $fields, $args, array($handler, 'validate'));
// If there are errors, we should be exiting here.
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_GROUPS_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
// We need to set the proper vars here so that the es-wrapper contains appropriate class
JRequest::setVar('view', 'groups', 'POST');
JRequest::setVar('layout', 'edit', 'POST');
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('edit', $errors, $data);
}
// @trigger onEditBeforeSave
$errors = $fieldsLib->trigger('onEditBeforeSave', SOCIAL_FIELDS_GROUP_GROUP, $fields, $args, array($handler, 'beforeSave'));
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
// We need to set the proper vars here so that the es-wrapper contains appropriate class
JRequest::setVar('view', 'groups');
JRequest::setVar('layout', 'edit');
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('edit', $errors);
}
// Save the group now
$group->save();
// @points: groups.update
// Add points to the user that updated the group
$my = FD::user();
$points = FD::points();
$points->assign('groups.update', 'com_easysocial', $my->id);
// Reconstruct args
$args = array(&$data, &$group);
// @trigger onEditAfterSave
$fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_GROUP, $fields, $args);
// Bind custom fields for the user.
$group->bindCustomFields($data);
// Reconstruct args
$args = array(&$data, &$group);
// @trigger onEditAfterSaveFields
//.........这里部分代码省略.........
示例8: save
/**
* Save user's information.
*
* @since 1.0
* @access public
*/
public function save()
{
// Check for request forgeries.
FD::checkToken();
// Ensure that the user is registered
FD::requireLogin();
// Clear previous session
$session = JFactory::getSession();
$session->clear('easysocial.profile.errors', SOCIAL_SESSION_NAMESPACE);
// Get post data.
$post = JRequest::get('POST');
// Get the current view.
$view = $this->getCurrentView();
// Get all published fields apps that are available in the current form to perform validations
$fieldsModel = FD::model('Fields');
// Get current user.
$my = FD::user();
// Only fetch relevant fields for this user.
$options = array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER);
$fields = $fieldsModel->getCustomFields($options);
// Load json library.
$json = FD::json();
// Initialize default registry
$registry = FD::registry();
// Get disallowed keys so we wont get wrong values.
$disallowed = array(FD::token(), 'option', 'task', 'controller');
// Process $_POST vars
foreach ($post as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value)) {
$value = $json->encode($value);
}
$registry->set($key, $value);
}
}
// Convert the values into an array.
$data = $registry->toArray();
// Perform field validations here. Validation should only trigger apps that are loaded on the form
// @trigger onRegisterValidate
$fieldsLib = FD::fields();
// Get the general field trigger handler
$handler = $fieldsLib->getHandler();
// Build arguments to be passed to the field apps.
$args = array(&$data, &$my);
// Ensure that there is no errors.
// @trigger onEditValidate
$errors = $fieldsLib->trigger('onEditValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'validate'));
// If there are errors, we should be exiting here.
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
// We need to set the proper vars here so that the es-wrapper contains appropriate class
JRequest::setVar('view', 'profile', 'POST');
JRequest::setVar('layout', 'edit', 'POST');
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('edit', $errors, $data);
}
// @trigger onEditBeforeSave
$errors = $fieldsLib->trigger('onEditBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args, array($handler, 'beforeSave'));
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
// We need to set the proper vars here so that the es-wrapper contains appropriate class
JRequest::setVar('view', 'profile');
JRequest::setVar('layout', 'edit');
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('edit', $errors);
}
// Bind the my object with appropriate data.
$my->bind($data);
// Save the user object.
$my->save();
// Reconstruct args
$args = array(&$data, &$my);
// @trigger onEditAfterSave
$fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
// Bind custom fields for the user.
$my->bindCustomFields($data);
// Reconstruct args
$args = array(&$data, &$my);
// @trigger onEditAfterSaveFields
$fieldsLib->trigger('onEditAfterSaveFields', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
// Now we update the Facebook details if it is available
$associatedFacebook = $this->input->get('associatedFacebook', 0, 'int');
if (!empty($associatedFacebook)) {
$facebookPull = $this->input->get('oauth_facebook_pull', null, 'default');
$facebookPush = $this->input->get('oauth_facebook_push', null, 'default');
$my = FD::user();
$facebookTable = $my->getOAuth(SOCIAL_TYPE_FACEBOOK);
if ($facebookTable) {
$facebookTable->pull = $facebookPull;
$facebookTable->push = $facebookPush;
$facebookTable->store();
}
//.........这里部分代码省略.........
示例9: miniRegister
/**
* Processes quick registrations
*
* @since 1.2
* @access public
* @param string
* @return
*/
public function miniRegister()
{
FD::checkToken();
// Get current user's info
$session = JFactory::getSession();
// Get necessary info about the current registration process.
$registration = FD::table('Registration');
$registration->load($session->getId());
// Create a new object to store the params
$params = new stdClass();
// If registration values was previously set
if (!empty($registration->values)) {
$params = json_decode($registration->values);
}
// Get post values
$post = JRequest::get('POST');
// Keys to exclude
$exclude = array(FD::token(), 'option', 'controller', 'task');
// Go through each of the post vars
foreach ($post as $key => $value) {
if (!in_array($key, $exclude)) {
if (is_array($value)) {
$value = json_encode($value);
}
$params->{$key} = $value;
}
}
// Determines the mini registration mode
$mode = $this->config->get('registrations.mini.mode', 'quick');
// Determines the profile?
$defaultProfile = $this->config->get('registrations.mini.profile', 'default');
// Might be coming from module, in which we have to respect module settings
if (isset($post['modRegisterType']) && isset($post['modRegisterProfile'])) {
$mode = $post['modRegisterType'];
$defaultProfile = $post['modRegisterProfile'];
}
// Get the default profile id that we should use.
$profileModel = FD::model('Profiles');
// If selected profile is default, then we check how many profiles are there
if ($defaultProfile === 'default') {
// We no longer allow the ability for user to select profile
// This is because the rendered field might be different from user selected profile
// Under that case, the mapping of the fields will be off and unable to validate/store accordingly
// EG. Profile 1 has a password field with id 3, while Profile 2 has a password field id 5, if the rendered field is 3, but user selected profile 2, validation will fail because of field mismatch
// Hence if the settings is set to default profile, then we always use default profile
$defaultProfile = $profileModel->getDefaultProfile()->id;
}
// Set the profile id directly
if (!empty($defaultProfile)) {
$registration->profile_id = $defaultProfile;
// Set the profile id in the params
$params->profile_id = $defaultProfile;
// Directly set the registration step as 1
$registration->step = 1;
$registration->addStepAccess(1);
}
// Convert the
$registration->values = json_encode($params);
// Store the registration
$registration->store();
// Decide what to do here based on the configuration
// FULL -> Registration page, registration page then decides if there is 1 or more profile to choose
// QUICK && profile id assigned -> quickRegistration
// QUICK && no profile id -> Registration page with parameter quick=1
// If mode is set to full, then we redirect to registration page
if ($mode === 'full') {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_REGISTRATIONS_COMPLETE_REGISTRATION'), SOCIAL_MSG_INFO);
return $this->view->call('fullRegister', $defaultProfile);
}
// If this is quick mode, we need to check whether there's a default profile
if ($mode == 'quick' && !$defaultProfile) {
return $this->view->call('selectProfile');
}
if ($mode == 'quick') {
return $this->quickRegister();
}
return $this->view->call(__FUNCTION__);
}
示例10: getItems
/**
* Returns a list of menus for the admin sidebar.
*
* Example:
* <code>
* <?php
* $model = FD::model( 'Sidebar' );
*
* // Returns an array of menu items.
* $model->getItems();
* ?>
* </code>
*
* @since 1.0
* @access public
* @param null
* @return Array
*
* @author Mark Lee <mark@stackideas.com>
*/
public function getItems()
{
// @TODO: Configurable theme path for the back end.
// Get the sidebar ordering from defaults first
$defaults = SOCIAL_ADMIN_DEFAULTS . '/sidebar.json';
$sidebarOrdering = FD::makeObject($defaults);
if (!$sidebarOrdering) {
return false;
}
$items = array();
jimport('joomla.filesystem.folder');
$path = SOCIAL_ADMIN_DEFAULTS . '/sidebar';
$files = JFolder::files($path, '.json');
foreach ($sidebarOrdering as $sidebarItem) {
// Remove the reference from the $files array if it is defined in the ordering
$index = array_search($sidebarItem . '.json', $files);
if ($index !== false) {
unset($files[$index]);
}
// Get the sidebar items in the defined order
$content = FD::makeObject($path . '/' . $sidebarItem . '.json');
if ($content !== false) {
$items[] = $content;
}
}
// Add any remaining files into items
foreach ($files as $file) {
$content = FD::makeObject($path . '/' . $file);
if ($content !== false) {
$items[] = $content;
}
}
// If there are no items there, it should throw an error.
if (!$items) {
FD::logError(__FILE__, __LINE__, 'SIDEBAR: Unable to parse menu.json file.');
return false;
}
// Initialize default result.
$result = array();
foreach ($items as $item) {
// Generate a unique id.
$uid = uniqid();
// Generate a new group object for the sidebar.
$obj = clone $item;
// Assign the unique id.
$obj->uid = $uid;
// Initialize the counter
$obj->count = 0;
// Test if there's a counter key.
if (isset($obj->counter)) {
$namespace = explode('/', $obj->counter);
$method = $namespace[1];
$namespace = $namespace[0];
$model = FD::model($namespace);
$count = $model->{$method}();
$obj->count = $count;
}
if (!empty($obj->childs)) {
$childItems = array();
usort($obj->childs, array('EasySocialModelSidebar', 'sortItems'));
foreach ($obj->childs as $child) {
// Clone the child object.
$childObj = clone $child;
// Let's get the URL.
$url = array('index.php?option=com_easysocial');
$query = FD::makeArray($child->url);
// Set the url into the child item so that we can determine the active submenu.
$childObj->url = $child->url;
if ($query) {
foreach ($query as $queryKey => $queryValue) {
$url[] = $queryKey . '=' . $queryValue;
// If this is a call to the controller, it must have a valid token id.
if ($queryKey == 'controller') {
$url[] = FD::token() . '=1';
}
}
}
// Set the item link.
$childObj->link = implode('&', $url);
// Initialize the counter
//.........这里部分代码省略.........
示例11: store
/**
* Stores the user object
*
* @since 1.0
* @access public
*/
public function store()
{
// Check for request forgeries
FD::checkToken();
// Load front end's language file
FD::language()->loadSite();
// Get the current view
$view = $this->getCurrentView();
// Get the current task
$task = $this->getTask();
// Determine if this is an edited user.
$id = JRequest::getInt('id');
$id = !$id ? null : $id;
// Get the posted data
$post = JRequest::get('post');
// this should come from backend user management page only.
$autoApproval = isset($post['autoapproval']) ? $post['autoapproval'] : 0;
// Create an options array for custom fields
$options = array();
if (!$id) {
$user = new SocialUser();
// Get the profile id
$profileId = JRequest::getInt('profileId');
} else {
// Here we assume that the user record already exists.
$user = FD::user($id);
// Get the profile id from the user
$profileId = $user->getProfile()->id;
$options['data'] = true;
$options['dataId'] = $id;
$options['dataType'] = SOCIAL_TYPE_USER;
}
// Set the profile id
$options['profile_id'] = $profileId;
// Set the group
$options['group'] = SOCIAL_FIELDS_GROUP_USER;
// Load the profile
$profile = FD::table('Profile');
$profile->load($profileId);
// Set the visibility
$options['visible'] = SOCIAL_PROFILES_VIEW_EDIT;
// Get fields model
$fieldsModel = FD::model('Fields');
// Get the custom fields
$fields = $fieldsModel->getCustomFields($options);
// Initialize default registry
$registry = FD::registry();
// Get disallowed keys so we wont get wrong values.
$disallowed = array(FD::token(), 'option', 'task', 'controller', 'autoapproval');
// Process $_POST vars
foreach ($post as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value)) {
$value = FD::json()->encode($value);
}
$registry->set($key, $value);
}
}
// Test to see if the points has changed.
$points = JRequest::getInt('points');
// Lets get the difference of the points
$userPoints = $user->getPoints();
// If there is a difference, the admin may have altered the user points
if ($userPoints != $points) {
// Insert a new points record for this new adjustments.
if ($points > $userPoints) {
// If the result points is larger, we always need to subtract and get the balance.
$totalPoints = $points - $userPoints;
} else {
// If the result points is smaller, we always need to subtract.
$totalPoints = -($userPoints - $points);
}
$pointsLib = FD::points();
$pointsLib->assignCustom($user->id, $totalPoints, JText::_('COM_EASYSOCIAL_POINTS_ADJUSTMENTS'));
$user->points = $points;
}
// Convert the values into an array.
$data = $registry->toArray();
// Get the fields lib
$fieldsLib = FD::fields();
// Build arguments to be passed to the field apps.
$args = array(&$data, &$user);
// @trigger onAdminEditValidate
$errors = $fieldsLib->trigger('onAdminEditValidate', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
// If there are errors, we should be exiting here.
if (is_array($errors) && count($errors) > 0) {
$view->setMessage(JText::_('COM_EASYSOCIAL_PROFILE_SAVE_ERRORS'), SOCIAL_MSG_ERROR);
// We need to set the data into the post again because onEditValidate might have changed the data structure
JRequest::set($data, 'post');
return $view->call('form', $errors);
}
// @trigger onAdminEditBeforeSave
$errors = $fieldsLib->trigger('onAdminEditBeforeSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
if (is_array($errors) && count($errors) > 0) {
//.........这里部分代码省略.........
示例12: update
/**
* Post action after updating an event to redirect to appropriately.
*
* @author Jason Rey <jasonrey@stackideas.com>
* @since 1.3
* @access public
* @param SocialEvent $event The SocialEvent object.
*/
public function update($event = null)
{
// Recurring support
// If applies to all, we need to show a "progress update" page to update all childs through ajax.
$applyAll = !empty($event) && $event->hasRecurringEvents() && $this->input->getInt('applyRecurring');
// Check if need to create recurring event
$createRecurring = !empty($event->recurringData);
// If no apply, and no recurring create, then redirect accordingly.
if (!$applyAll && !$createRecurring) {
FD::info()->set($this->getMessage());
if ($this->hasErrors() || empty($event)) {
return $this->redirect(FRoute::events());
}
return $this->redirect($event->getPermalink());
}
FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_EVENTS'), FRoute::events());
FD::page()->breadcrumb($event->getName(), $event->getPermalink());
FD::page()->breadcrumb(JText::_('COM_EASYSOCIAL_PAGE_TITLE_EDIT_EVENT'));
FD::page()->title(JText::sprintf('COM_EASYSOCIAL_PAGE_TITLE_EDIT_EVENT_TITLE', $event->getName()));
$post = JRequest::get('POST');
$json = FD::json();
$data = array();
$disallowed = array(FD::token(), 'option', 'task', 'controller');
foreach ($post as $key => $value) {
if (in_array($key, $disallowed)) {
continue;
}
if (is_array($value)) {
$value = $json->encode($value);
}
$data[$key] = $value;
}
$string = $json->encode($data);
$this->set('data', $string);
$this->set('event', $event);
$updateids = array();
if ($applyAll) {
$children = $event->getRecurringEvents();
foreach ($children as $child) {
$updateids[] = $child->id;
}
}
$this->set('updateids', $json->encode($updateids));
$schedule = array();
if ($createRecurring) {
// If there is recurring data, then we back up the post values and the recurring data in the the event params
$clusterTable = FD::table('Cluster');
$clusterTable->load($event->id);
$eventParams = FD::makeObject($clusterTable->params);
$eventParams->postdata = $data;
$eventParams->recurringData = $event->recurringData;
$clusterTable->params = FD::json()->encode($eventParams);
$clusterTable->store();
// Get the recurring schedule
$schedule = FD::model('Events')->getRecurringSchedule(array('eventStart' => $event->getEventStart(), 'end' => $event->recurringData->end, 'type' => $event->recurringData->type, 'daily' => $event->recurringData->daily));
}
$this->set('schedule', $json->encode($schedule));
echo parent::display('site/events/update');
}
示例13: createEsprofile
/**
* Function create easysocial profile.
*
* @return user obj
*/
public function createEsprofile($log_user)
{
$obj = new stdClass();
if (JComponentHelper::isEnabled('com_easysocial', true)) {
$app = JFactory::getApplication();
$epost = $app->input->get('fields', '', 'ARRAY');
require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php';
// Get all published fields apps that are available in the current form to perform validations
$fieldsModel = FD::model('Fields');
// Get current user.
$my = FD::user($log_user);
// Only fetch relevant fields for this user.
$options = array('profile_id' => $my->getProfile()->id, 'data' => true, 'dataId' => $my->id, 'dataType' => SOCIAL_TYPE_USER, 'visible' => SOCIAL_PROFILES_VIEW_EDIT, 'group' => SOCIAL_FIELDS_GROUP_USER);
$fields = $fieldsModel->getCustomFields($options);
$epost = $this->create_field_arr($fields, $epost);
// Load json library.
$json = FD::json();
// Initialize default registry
$registry = FD::registry();
// Get disallowed keys so we wont get wrong values.
$disallowed = array(FD::token(), 'option', 'task', 'controller');
// Process $_POST vars
foreach ($epost as $key => $value) {
if (!in_array($key, $disallowed)) {
if (is_array($value) && $key != 'es-fields-11') {
$value = $json->encode($value);
}
$registry->set($key, $value);
}
}
// Convert the values into an array.
$data = $registry->toArray();
// Perform field validations here. Validation should only trigger apps that are loaded on the form
// @trigger onRegisterValidate
$fieldsLib = FD::fields();
// Get the general field trigger handler
$handler = $fieldsLib->getHandler();
// Build arguments to be passed to the field apps.
$args = array($data, &$my);
// Ensure that there is no errors.
// @trigger onEditValidate
//$errors = $fieldsLib->trigger( 'onEditValidate' , SOCIAL_FIELDS_GROUP_USER , $fields , $args, array( $handler, 'validate' ) );
// Bind the my object with appropriate data.
$my->bind($data);
// Save the user object.
$sval = $my->save();
// Reconstruct args
$args = array(&$data, &$my);
// @trigger onEditAfterSave
$fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
// Bind custom fields for the user.
$my->bindCustomFields($data);
// Reconstruct args
$args = array(&$data, &$my);
// @trigger onEditAfterSaveFields
$fieldsLib->trigger('onEditAfterSaveFields', SOCIAL_FIELDS_GROUP_USER, $fields, $args);
if ($sval) {
$obj->success = 1;
$obj->message = "profile created successfully";
} else {
$obj->success = 0;
$obj->message = "Unable to create profile";
}
} else {
$obj->success = 0;
$obj->message = 'Easysocial not installed';
}
return $obj;
}
示例14: update
/**
* Update an event
*
* @since 1.3
* @access public
* @param string
* @return
*/
public function update()
{
// Check for request forgeries
FD::checkToken();
// Ensure that the user is logged in
FD::requireLogin();
// Get the event data
$id = $this->input->get('id', 0, 'int');
// Load up the event
$event = FD::event($id);
if (empty($event) || empty($event->id)) {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_INVALID_EVENT_ID'), SOCIAL_MSG_ERROR);
return $this->view->call(__FUNCTION__);
}
if (!$event->isPublished()) {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_EVENT_UNAVAILABLE'), SOCIAL_MSG_ERROR);
return $this->view->call(__FUNCTION__);
}
$guest = $event->getGuest($this->my->id);
if (!$this->my->isSiteAdmin() && !$guest->isOwner() && !$event->isAdmin() && (!$event->isGroupEvent() || $event->isGroupEvent() && !$event->getGroup()->isOwner())) {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_NOT_ALLOWED_TO_EDIT_EVENT'), SOCIAL_MSG_ERROR);
return $this->view->call(__FUNCTION__, $event);
}
$post = JRequest::get('POST');
$json = FD::json();
$data = array();
$disallowed = array(FD::token(), 'option', 'task', 'controller');
foreach ($post as $key => $value) {
if (in_array($key, $disallowed)) {
continue;
}
if (is_array($value)) {
$value = $json->encode($value);
}
$data[$key] = $value;
}
$fieldsModel = FD::model('Fields');
$fields = FD::model('Fields')->getCustomFields(array('group' => SOCIAL_TYPE_EVENT, 'uid' => $event->getCategory()->id, 'visible' => SOCIAL_EVENT_VIEW_EDIT, 'data' => true, 'dataId' => $event->id, 'dataType' => SOCIAL_TYPE_EVENT));
$fieldsLib = FD::fields();
$args = array(&$data, &$event);
$errors = $fieldsLib->trigger('onEditValidate', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args, array($fieldsLib->getHandler(), 'validate'));
if (!empty($errors)) {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
JRequest::setVar('view', 'events', 'POST');
JRequest::setVar('layout', 'edit', 'POST');
JRequest::set($data, 'POST');
return $this->view->call('edit', $errors);
}
$errors = $fieldsLib->trigger('onEditBeforeSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args, array($fieldsLib->getHandler(), 'beforeSave'));
if (!empty($errors)) {
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_ERRORS_IN_FORM'), SOCIAL_MSG_ERROR);
JRequest::setVar('view', 'events', 'POST');
JRequest::setVar('layout', 'edit', 'POST');
JRequest::set($data, 'POST');
return $this->view->call('edit', $errors);
}
$event->save();
FD::points()->assign('events.update', 'com_easysocial', $this->my->id);
$fieldsLib->trigger('onEditAfterSave', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
$event->bindCustomFields($data);
$fieldsLib->trigger('onEditAfterSaveFields', SOCIAL_FIELDS_GROUP_EVENT, $fields, $args);
// Only create if applyRecurring is false or event is not a child
// applyRecurring && parent = true
// applyRecurring && child = false
// !applyRecurring && parent = true
// !applyRecurring && child = true
if (empty($data['applyRecurring']) || !$event->isRecurringEvent()) {
$event->createStream('update', $this->my->id, SOCIAL_TYPE_USER);
}
$this->view->setMessage(JText::_('COM_EASYSOCIAL_EVENTS_UPDATED_SUCCESSFULLY'), SOCIAL_MSG_SUCCESS);
return $this->view->call(__FUNCTION__, $event);
}
示例15: createEvent
public function createEvent()
{
$app = JFactory::getApplication();
$log_user = JFactory::getUser($this->plugin->get('user')->id);
$user = FD::user($log_user->id);
$config = FD::config();
//create group post structure
$ev_data = array();
$result = new stdClass();
$valid = 1;
$post['title'] = $app->input->post->get('title', null, 'STRING');
$post['parmalink'] = $app->input->post->get('parmalink', null, 'STRING');
$post['description'] = $app->input->post->get('description', null, 'STRING');
$post['event_type'] = $app->input->post->get('event_type', 0, 'INT');
$post['startDatetime'] = $app->input->post->get('startDatetime', null, 'string');
$post['endDatetime'] = $app->input->post->get('endDatetime', null, 'string');
$post['event_allday'] = $app->input->post->get('event_allday', 0, 'INT');
$post['repeat'] = $app->input->post->get('repeat', array('type' => 'none', 'end' => null), 'ARRAY');
$post['website'] = $app->input->post->get('website', 0, 'INT');
$post['allowmaybe'] = $app->input->post->get('allowmaybe', 0, 'INT');
$post['allownotgoingguest'] = $app->input->post->get('allownotgoingguest', 0, 'INT');
$post['guestlimit'] = $app->input->post->get('guestlimit', 0, 'INT');
$post['photo_albums'] = $app->input->post->get('photo_albums', 0, 'INT');
$post['announcement'] = $app->input->post->get('announcement', 0, 'INT');
$post['discussions'] = $app->input->post->get('discussions', 0, 'INT');
$post['location'] = $app->input->post->get('location', null, 'STRING');
$post['categoryId'] = $categoryId = $app->input->post->get('category_id', 0, 'INT');
$post['group_id'] = $app->input->post->get('group_id', null, 'INT');
$category = FD::table('EventCategory');
$category->load($categoryId);
$session = JFactory::getSession();
$session->set('category_id', $category->id, SOCIAL_SESSION_NAMESPACE);
$stepSession = FD::table('StepSession');
$stepSession->load(array('session_id' => $session->getId(), 'type' => SOCIAL_TYPE_EVENT));
$stepSession->session_id = $session->getId();
$stepSession->uid = $category->id;
$stepSession->type = SOCIAL_TYPE_EVENT;
$stepSession->set('step', 1);
$stepSession->addStepAccess(1);
// Check the group access for event creation
if (!empty($post['group_id'])) {
$group = FD::group($post['group_id']);
if (!$group->canCreateEvent()) {
$result->success = 0;
$result->message = JText::_('COM_EASYSOCIAL_EVENTS_NOT_ALLOWED_TO_CREATE_EVENT');
return $result;
}
$stepSession->setValue('group_id', $post['group_id']);
} else {
// Check if there is a group id set in the session, if yes then remove it
if (!empty($stepSession->values)) {
$value = FD::makeObject($stepSession->values);
unset($value->group_id);
$stepSession->values = FD::json()->encode($value);
}
}
$stepSession->store();
//step 2 - create event
$session = JFactory::getSession();
$stepSession = FD::table('StepSession');
$stepSession->load(array('session_id' => $session->getId(), 'type' => SOCIAL_TYPE_EVENT));
$category = FD::table('EventCategory');
$category->load($stepSession->uid);
$sequence = $category->getSequenceFromIndex($stepSession->step, SOCIAL_EVENT_VIEW_REGISTRATION);
//for api test purpose
if (empty($sequence)) {
$result->success = 0;
$result->message = JText::_('COM_EASYSOCIAL_EVENTS_NO_VALID_CREATION_STEP');
return $result;
}
// Load the steps and fields
$step = FD::table('FieldStep');
$step->load(array('uid' => $category->id, 'type' => SOCIAL_TYPE_CLUSTERS, 'sequence' => $sequence));
$registry = FD::registry();
$registry->load($stepSession->values);
// Get the fields
$fieldsModel = FD::model('Fields');
$customFields = $fieldsModel->getCustomFields(array('step_id' => $step->id, 'visible' => SOCIAL_EVENT_VIEW_REGISTRATION));
// Get from request
//$files = JRequest::get('FILES');
//$post = JRequest::get('POST');
$token = FD::token();
$json = FD::json();
$data = $this->createData($customFields, $post);
//add post data in registry
foreach ($data as $key => $value) {
if ($key == $token) {
continue;
}
if (is_array($value)) {
$value = $json->encode($value);
}
$registry->set($key, $value);
}
$data = $registry->toArray();
$args = array(&$data, &$stepSession);
// Load up the fields library so we can trigger the field apps
$fieldsLib = FD::fields();
$callback = array($fieldsLib->getHandler(), 'validate');
//$errors = $fieldsLib->trigger('onRegisterValidate', SOCIAL_FIELDS_GROUP_EVENT, $customFields, $args, $callback);
//.........这里部分代码省略.........