Cheetah
ChWsbJoinProcessor.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC . 'admin.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC . 'db.inc.php' );
11 
12 ch_import('ChWsbProfileFields');
13 ch_import('ChWsbProfilesController' );
14 ch_import('ChTemplFormView');
15 
17 {
18  var $oPF; //profile fields
19  var $iPage; //currently shown page
20  var $aPages; //available pages
21  var $aValues; //inputted values
22  var $aErrors; //errors generated on page
23  var $bAjaxMode; // defines if the script were requested by ajax
24 
26  var $bCouple;
27 
28  function __construct($aParams = array())
29  {
30  $this -> aErrors = array( 0 => array(), 1 => array() );
31 
32  $this -> oPF = !empty($aParams['profile_fields']) ? $aParams['profile_fields'] : new ChWsbProfileFields(1);
33 
34  $this -> aValues = array();
35  $this -> aValues[0] = $this -> aValues[1] = $this -> oPF -> getDefaultValues();// double arrays (for couples)
36 
37  $this -> bAjaxMode = ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' );
38  }
39 
40  function process($aAddonFields = array())
41  {
42  if(!$this->oPF->aArea)
43  return 'Profile Fields cache not loaded. Cannot continue.';
44 
45  $this->aPages = array_keys($this->oPF->aArea);
46 
47  $this->iPage = isset($_POST['join_page']) ? $_POST['join_page'] : 0; // get current working page from POST
48  if($this->iPage !== 'done' )
49  $this->iPage = (int)$this->iPage;
50 
51  $this->getCoupleOptions();
52 
53  $this->processPostValues();
54 
55  if($this->bAjaxMode && ch_get('join_page_validate') !== false) {
56  echo $this->showErrorsJson();
57  exit;
58  }
59 
60  $sContent = '';
61  if($this->iPage === 'done' ) { //if all pages are finished and no errors found
62  list($iMemberId, $sStatus) = $this->registerMember();
63 
65  }
66  else
67  $sContent .= $this->showJoinForm($aAddonFields);
68 
69  return $sContent;
70  }
71 
72  function getCoupleOptions()
73  {
74  //find Couple item (check if it is active)
75  $aCoupleItem = false;
76  foreach ($this -> aPages as $iPageInd => $iPage) { //cycle pages
77  $aBlocks = $this -> oPF -> aArea[ $iPage ];
78  foreach ($aBlocks as $iBlockID => $aBlock) { //cycle blocks
79  $aItems = $aBlock['Items'];
80  foreach ($aItems as $iItemID => $aItem) { //cycle items
81  if( $aItem['Name'] == 'Couple' ) { // we found it!
82  $aCoupleItem = $aItem;
83  break;
84  }
85  }
86 
87  if( $aCoupleItem ) // we already found it
88  break;
89  }
90 
91  if( $aCoupleItem ) // we already found it
92  break;
93  }
94 
95  if( $aCoupleItem ) {
96  $this -> bCoupleEnabled = true;
97  $this -> bCouple = ( isset( $_REQUEST['Couple'] ) and $_REQUEST['Couple'] == 'yes' ) ? true : false;
98  } else {
99  $this -> bCoupleEnabled = false;
100  $this -> bCouple = false;
101  }
102  }
103 
104  function processPostValues()
105  {
106  foreach ($this -> aPages as $iPage) { //cycle pages
107 
108  if( $this -> iPage !== 'done' and $iPage >= $this -> iPage ) {
109  $this -> iPage = $iPage; // we are on the current page. dont process these values, dont go further, just show form.
110  break;
111  }
112 
113  // process post values by Profile Fields class
114  $this -> oPF -> processPostValues( $this -> bCouple, $this -> aValues, $this -> aErrors, $iPage );
115 
116  if( !empty( $this -> aErrors[0] ) or ( $this -> bCouple and !empty( $this -> aErrors[1] ) ) ) { //we found errors on previous page
117  // do not process further values, just go to erroneous page.
118  $this -> iPage = $iPage;
119  break;
120  }
121  }
122  }
123 
124  function showErrorsJson()
125  {
126  header('Content-Type:text/javascript; charset=utf-8');
127  return $this -> oPF -> genJsonErrors( $this -> aErrors, $this -> bCouple );
128  }
129 
130  function showJoinForm($aAddonFields = array())
131  {
132  $aJoinFormParams = array(
133  'dynamic' => $this->bAjaxMode,
134  'couple_enabled' => $this->bCoupleEnabled,
135  'couple' => $this->bCouple,
136  'page' => $this->iPage,
137  'hiddens' => $this->genHiddenFieldsArray($aAddonFields),
138  'errors' => $this->aErrors,
139  'values' => $this->aValues,
140  );
141 
142  return $this->oPF->getFormCode($aJoinFormParams);
143  }
144 
145  function genHiddenFieldsArray($aHiddenFields = array())
146  {
147  //retrieve next page
148  $iPageInd = (int)array_search( $this -> iPage, $this -> aPages );
149  $iNextInd = $iPageInd + 1;
150 
151  if( array_key_exists( $iNextInd, $this -> aPages ) )
152  $sNextPage = $this -> aPages[ $iNextInd ];
153  else
154  $sNextPage = 'done';
155 
156  // insert next page
157  $aHiddenFields['join_page'] = $sNextPage;
158 
159  //echoDbg( $this -> aValues );
160 
161  // insert entered values
162  $iHumans = $this -> bCouple ? 2 : 1;
163  for( $iHuman = 0; $iHuman < $iHumans; $iHuman ++ ) {
164  foreach( $this -> aPages as $iPage ) {
165  if( $iPage == $this -> iPage )
166  break; // we are on this page
167 
168  $aBlocks = $this -> oPF -> aArea[ $iPage ];
169  foreach( $aBlocks as $aBlock ) {
170  foreach( $aBlock['Items'] as $aItem ) {
171  $sItemName = $aItem['Name'];
172 
173  if( isset( $this -> aValues[$iHuman][ $sItemName ] ) ) {
174  $mValue = $this -> aValues[$iHuman][ $sItemName ];
175 
176  switch( $aItem['Type'] ) {
177  case 'pass':
178  $aHiddenFields[ $sItemName . '_confirm[' . $iHuman . ']' ] = $mValue;
179  case 'text':
180  case 'area':
181  case 'html_area':
182  case 'date':
183  case 'datetime':
184  case 'select_one':
185  case 'num':
186  $aHiddenFields[ $sItemName . '[' . $iHuman . ']' ] = $mValue;
187  break;
188 
189  case 'select_set':
190  foreach( $mValue as $iInd => $sValue )
191  $aHiddenFields[ $sItemName . '[' . $iHuman . '][' . $iInd . ']' ] = $sValue;
192  break;
193 
194  case 'range':
195  $aHiddenFields[ $sItemName . '[' . $iHuman . '][0]' ] = $mValue[0];
196  $aHiddenFields[ $sItemName . '[' . $iHuman . '][1]' ] = $mValue[1];
197  break;
198 
199  case 'bool':
200  $aHiddenFields[ $sItemName . '[' . $iHuman . ']' ] = $mValue ? 'yes' : '';
201  break;
202 
203  case 'system':
204  switch( $aItem['Name'] ) {
205  case 'Couple':
206  case 'TermsOfUse':
207  $aHiddenFields[ $sItemName ] = $mValue ? 'yes' : '';
208  break;
209 
210  case 'Captcha':
211  $aHiddenFields[ $sItemName ] = $mValue;
212  break;
213 
214  case 'ProfilePhoto':
215  $aHiddenFields['ProfilePhoto_tmp'] = $mValue;
216  break;
217  }
218  break;
219  }
220  }
221  }
222  }
223  }
224  }
225  return $aHiddenFields;
226  }
227 
228  function registerMember()
229  {
230  $oPC = new ChWsbProfilesController();
231 
232  $oZ = new ChWsbAlerts('profile', 'before_join', 0, 0, $this->aValues[0]);
233  $oZ->alert();
234 
235  $aProfile1 = $this->oPF->getProfileFromValues($this->aValues[0]);
236  if (empty($aProfile1['NickName']))
237  $aProfile1['NickName'] = uriGenerate((empty($aProfile1['FirstName']) ? genRndPwd(10, false) : $aProfile1['FirstName']), 'Profiles', 'NickName');
238 
239  // Begin Bot Detection.
240  $aProfile1['endtime'] = (int)time();
241  $aProfile1['timediff'] = $aProfile1['endtime'] - $aProfile1['starttime'];
242  $bBotCheck = ('on' == getParam(sys_antispam_bot_check) ? true : false);
243  if($bBotCheck) {
244  // Check hidden fields for content. If there, we have a bot. If bot, do not create account.
245  $bBot = false;
246  if (isset($aProfile1['youremail']) && !empty($aProfile1['youremail'])) {
247  $bBot = true;
248  }
249  if (isset($aProfile1['reg_email']) && !empty($aProfile1['reg_email'])) {
250  $bBot = true;
251  }
252  if (isset($aProfile1['reg_name']) && !empty($aProfile1['reg_name'])) {
253  $bBot = true;
254  }
255  if (isset($aProfile1['reg_nickname']) && !empty($aProfile1['reg_nickname'])) {
256  $bBot = true;
257  }
258 
259  // Check DescriptionMe for links and images.
260  if (strpos($aProfile1['DescriptionMe'], '<img src=') !== false) {
261  $bBot = true;
262  }
263  if (strpos($aProfile1['DescriptionMe'], '<a href=') !== false) {
264  $bBot = true;
265  }
266  if (strpos($aProfile1['DescriptionMe'], 'https://') !== false) {
267  $bBot = true;
268  }
269  if (strpos($aProfile1['DescriptionMe'], 'http://') !== false) {
270  $bBot = true;
271  }
272 
273  // Check time. Bots can usally submit the join form in less than 5 seconds. Humans cannot.
274  if ((int)$aProfile1['timediff'] <= 5) {
275  $bBot = true;
276  }
277 
278  if ($bBot) {
279  // Log detection.
280  $o = ch_instance('ChWsbDNSBlacklists');
281  $o->onPositiveDetection (getVisitorIP(false), 'Bot blocked on join.', 'botdetection');
282  // Fail join.
283  return array(false, 'Fail');
284  }
285 
286  // Remove bot detection fields from $aProfile1 before creating the new account
287  // because these fields don't actually exist in the Profiles table.
288  unset($aProfile1['endtime']);
289  unset($aProfile1['timediff']);
290  unset($aProfile1['starttime']); // This field is in the sys_profile_fields table
291  unset($aProfile1['youremail']); // This field is in the sys_profile_fields table
292  unset($aProfile1['reg_email']); // This field is in the sys_profile_fields table
293  unset($aProfile1['reg_name']); // This field is in the sys_profile_fields table
294  unset($aProfile1['reg_nickname']); // This field is in the sys_profile_fields table
295  }
296  // End Bot Detection.
297 
298  list($iId1, $sStatus1) = $oPC->createProfile($aProfile1);
299 
300  //--- check whether profile was created successfully or not
301  if(!$iId1) {
302  if(isset($aProfile1['ProfilePhoto']) && !empty($aProfile1['ProfilePhoto']))
303  @unlink($GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto']);
304 
305  return array(false, 'Fail');
306  }
307 
308  //--- check for couple profile
309  if($this->bCouple) {
310  $aProfile2 = $this->oPF->getProfileFromValues($this -> aValues[1]);
311  list($iId2, $sStatus2) = $oPC->createProfile($aProfile2, false, $iId1);
312 
313  if(!$iId2) {
314  $oPC->deleteProfile($iId1);
315  return array(false, 'Fail');
316  }
317  }
318 
319  ch_login($iId1);
320  check_logged();
321 
322  //--- upload profile photo
323  if(isset($aProfile1['ProfilePhoto']) && !empty($aProfile1['ProfilePhoto'])) {
324 
325  if ('sys_avatar' == getParam('sys_member_info_thumb') && ChWsbRequest::serviceExists('avatar', 'set_image_for_cropping')) {
326  ChWsbService::call('avatar', 'set_image_for_cropping', array ($iId1, $GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto']));
327  }
328  elseif (ChWsbRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader')) {
329  ch_import('ChWsbPrivacyQuery');
330  $oPrivacy = new ChWsbPrivacyQuery();
331 
332  $aFileInfo = array (
333  'medTitle' => _t('_sys_member_thumb_avatar'),
334  'medDesc' => _t('_sys_member_thumb_avatar'),
335  'medTags' => _t('_ProfilePhotos'),
336  'Categories' => array(_t('_ProfilePhotos')),
337  'album' => str_replace('{nickname}', getUsername($iId1), getParam('ch_photos_profile_album_name')),
338  'albumPrivacy' => $oPrivacy->getDefaultValueModule('photos', 'album_view'),
339  );
340  ChWsbService::call('photos', 'perform_photo_upload', array($GLOBALS['dir']['tmp'] . $aProfile1['ProfilePhoto'], $aFileInfo, false), 'Uploader');
341  }
342  }
343 
344  if (ChWsbModule::getInstance('ChWmapModule'))
345  ChWsbService::call('wmap', 'response_entry_add', array('profiles', $iId1));
346 
347  //--- create system event
348  ch_import('ChWsbAlerts');
349  $oZ = new ChWsbAlerts('profile', 'join', $iId1, 0, array('status_text' => &$sStatus1));
350  $oZ->alert();
351 
352  return array($iId1, $sStatus1);
353  }
354 
355  function showFailPage()
356  {
357  return '<div class="dbContentHtml">' . _t( '_Join failed' ) . '</div>';
358  }
359 
361  {
362  switch( $sStatus ) {
363  case 'Active': $sStatusText = ('_USER_ACTIVATION_SUCCEEDED'); break; //activated automatically
364  case 'Approval': $sStatusText = ('_USER_CONF_SUCCEEDED'); break; //automatically confirmed
365  case 'Unconfirmed': $sStatusText = ('_EMAIL_CONF_SENT'); break; //conf mail succesfully sent
366  case 'NotSent': $sStatusText = ('_EMAIL_CONF_NOT_SENT'); break; //failed to send conf mail
367  }
368 
369  if ('sys_avatar' == getParam('sys_member_info_thumb') && 'EXIT' == ChWsbService::call('avatar', 'join', array ($iMemberId, $sStatusText))) {
370  exit;
371  }
372 
373  return '<div class="dbContentHtml ch-def-font-large">' . _t( '_Join complete' ) . '<br />' . _t( $sStatusText ) . '</div>';
374  }
375 }
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
getVisitorIP
getVisitorIP($isProxyCheck=true)
Definition: utils.inc.php:643
ch_login
ch_login($iId, $bRememberMe=false, $bAlert=true)
Definition: profiles.inc.php:514
$iMemberId
$iMemberId
Definition: profile.php:91
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
ChWsbJoinProcessor\processPostValues
processPostValues()
Definition: ChWsbJoinProcessor.php:104
ChWsbProfileFields
Definition: ChWsbProfileFields.php:13
ChWsbJoinProcessor\$aValues
$aValues
Definition: ChWsbJoinProcessor.php:21
ChWsbModule\getInstance
static getInstance($sClassName)
Definition: ChWsbModule.php:89
check_logged
check_logged()
Definition: admin.inc.php:238
ChWsbRequest\serviceExists
static serviceExists($mixedModule, $sMethod, $sClass="Module")
Definition: ChWsbRequest.php:70
uriGenerate
uriGenerate($s, $sTable, $sField, $iMaxLen=255)
Definition: utils.inc.php:900
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
ChWsbPrivacyQuery
Definition: ChWsbPrivacyQuery.php:11
ChWsbJoinProcessor\showFailPage
showFailPage()
Definition: ChWsbJoinProcessor.php:355
php
$oZ
$oZ
Definition: db.php:20
ChWsbJoinProcessor\showErrorsJson
showErrorsJson()
Definition: ChWsbJoinProcessor.php:124
ChWsbJoinProcessor\getCoupleOptions
getCoupleOptions()
Definition: ChWsbJoinProcessor.php:72
ChWsbJoinProcessor\$bCoupleEnabled
$bCoupleEnabled
Definition: ChWsbJoinProcessor.php:25
ChWsbJoinProcessor\$aErrors
$aErrors
Definition: ChWsbJoinProcessor.php:22
ChWsbJoinProcessor\__construct
__construct($aParams=array())
Definition: ChWsbJoinProcessor.php:28
ChWsbJoinProcessor\process
process($aAddonFields=array())
Definition: ChWsbJoinProcessor.php:40
ChWsbAlerts
Definition: ChWsbAlerts.php:39
exit
exit
Definition: cart.php:21
and
and
Definition: license.txt:18
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbJoinProcessor
Definition: ChWsbJoinProcessor.php:17
$_REQUEST
$_REQUEST['action']
Definition: cmd.php:11
ChWsbJoinProcessor\registerMember
registerMember()
Definition: ChWsbJoinProcessor.php:228
ch_instance
ch_instance($sClassName, $aParams=array(), $aModule=array())
Definition: utils.inc.php:1264
getUsername
getUsername( $ID='')
Definition: profiles.inc.php:443
genRndPwd
genRndPwd($iLength=8, $bSpecialCharacters=true)
Definition: utils.inc.php:1618
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
ChWsbProfilesController
Definition: ChWsbProfilesController.php:12
ChWsbJoinProcessor\$aPages
$aPages
Definition: ChWsbJoinProcessor.php:20
$sStatusText
$sStatusText
Definition: db.php:25
ChWsbJoinProcessor\$iPage
$iPage
Definition: ChWsbJoinProcessor.php:19
ChWsbJoinProcessor\$bCouple
$bCouple
Definition: ChWsbJoinProcessor.php:26
ChWsbJoinProcessor\$oPF
$oPF
Definition: ChWsbJoinProcessor.php:18
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$o
$o
Definition: cmd.php:193
ChWsbJoinProcessor\showFinishPage
showFinishPage( $iMemberId, $sStatus)
Definition: ChWsbJoinProcessor.php:360
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbJoinProcessor\showJoinForm
showJoinForm($aAddonFields=array())
Definition: ChWsbJoinProcessor.php:130
ChWsbJoinProcessor\$bAjaxMode
$bAjaxMode
Definition: ChWsbJoinProcessor.php:23
ChWsbJoinProcessor\genHiddenFieldsArray
genHiddenFieldsArray($aHiddenFields=array())
Definition: ChWsbJoinProcessor.php:145
$sStatus
$sStatus
Definition: actions.inc.php:11
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
or
Voluntary License Schemes The Licensor waives the right to collect whether individually or
Definition: license.txt:37