Joomla附属注册插件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Joomla附属注册插件相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. // Check to ensure this file is included in Joomla!
  3. defined('_JEXEC') or die( 'Restricted access' );
  4.  
  5. jimport('joomla.plugin.plugin');
  6.  
  7. class plgUserPap4 extends JPlugin
  8. {
  9. function plgUserPap4(& $subject, $config) {
  10. parent::__construct($subject, $config);
  11. }
  12.  
  13. /**
  14.   * Example store user method
  15.   * Method is called after user data is stored in the database
  16.   */
  17. function onAfterStoreUser($user, $isnew, $succes, $msg)
  18. //function onBeforeStoreUser($user, $isnew)
  19. {
  20. global $mainframe;
  21.  
  22. // convert the user parameters passed to the event
  23. // to a format the external application
  24. $args = array();
  25. $args['username'] = $user['username'];
  26. $args['email'] = $user['email'];
  27. $args['fullname'] = $user['name'];
  28. $args['password'] = $user['password_clear'];
  29. $args['parentuserid'] = $user['parentuserid'];
  30. //foreach($user as $k=>$v) {
  31. // echo "$k = $v<br>";
  32. //}
  33.  
  34. if ($isnew)
  35. {
  36. // Call a function in the external app to create the user
  37. // ThirdPartyApp::createUser($user['id'], $args);
  38. require("PapApi.class.php");
  39.  
  40. // load plugin params info
  41. $plugin =& JPluginHelper::getPlugin('user', 'pap4');
  42. $pluginParams = new JParameter( $plugin->params );
  43.  
  44. $pap4Url = $pluginParams->get( 'pap4_url', 1 );
  45. $pap4Username = $pluginParams->get( 'pap4_username', 1 );
  46. $pap4Pwd = $pluginParams->get( 'pap4_password', 1 );
  47.  
  48. try {
  49. // login to API
  50. $session = new Gpf_Api_Session($pap4Url);
  51. if(!$session->login($pap4Username, $pap4Pwd)) {
  52. echo ("Cannot login. Message: ".$session->getMessage());
  53. return;
  54. }
  55.  
  56. $clickTracker = new Pap_Api_ClickTracker($session);
  57. try {
  58. $clickTracker->track();
  59. } catch (Exception $e) {
  60. }
  61.  
  62. if ($clickTracker->getAffiliate() != null) {
  63. $args['parentuserid'] = $clickTracker->getAffiliate()->getValue('userid');
  64. }
  65.  
  66. // create new affiliate
  67. $affiliate = new Pap_Api_Affiliate($session);
  68. $affiliate->setUsername($args['email']);
  69. $affiliate->setPassword($args['password']);
  70. $affiliate->setFirstname('Joomla');
  71. $affiliate->setLastname($args['fullname']);
  72. $affiliate->setParentUserId($args['parentuserid']);
  73. if(!$affiliate->add()) {
  74. echo("Cannot add record: ".$affiliate->getMessage());
  75. return;
  76. } else {
  77. echo("Affiliate successfuly added");
  78. }
  79. } catch(Exception $e) {
  80. echo("PAP4 API call error: ".$e->getMessage());
  81. return;
  82. }
  83. }
  84. }
  85. }

以上是关于Joomla附属注册插件的主要内容,如果未能解决你的问题,请参考以下文章

这应该是插件还是组件解决方案? (Joomla!)

joomla com_users 控制器覆盖

php 如何在Joomla中的任何位置访问Joomla插件参数

Joomla 注册覆盖

Joomla 中组件、模块、扩展和插件之间的区别

如何更改 Joomla 中的用户注册表单?