* @license PHP License * @package WB * @subpackage content */ /** * Load required class */ WBClass::load( 'WBContent' ); /** * Content component: Login * * @version 0.1.1 * @package WB * @subpackage content */ class WBContent_Profile extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'profile' => '__none', 'allowed' => array( 'user', 'password', 'feed' ) ); /** * table * @var WBDatasource_Table */ protected $table; /** * run * * run component * * @return array parameter list */ public function run() { if( !$this->user->isAuthenticated() ) { $this->loadTemplates( 'anon' ); return $this->config; } // only allowed feeds! if( !in_array( $this->config['profile'], $this->config['allowed'] ) ) { $this->loadTemplates( 'none' ); return $this->config; } switch( $this->config['profile'] ) { case 'none': $this->loadTemplates( 'none' ); return $this->config; case 'user': $p = $this->user->getData(); break; case 'password': $p = array(); break; default: $this->table = WBClass::create( 'WBDatasource_Table' ); $p = $this->table->get( 'skin', $this->user->getId() ); if( empty( $p ) ) { $p = array( null ); } $p = $p[0]; break; } $this->processForm( $this->config['profile'], $p ); return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate( 'snippet' ); } /** * Save user's primary data * * Update user's forename and surname * * @param patForms $form * @param array $values */ public function onUserValid( $form, $values ) { $this->user->setData( $values ); return true; } /** * Save user's password * * Update user's password * * @param patForms $form * @param array $values */ public function onPasswordValid( $form, $values ) { $save = array( 'password' => $values['passwordnew'] ); $this->user->setData( $save ); return true; } /** * Save skin settings * * @param patForms $form * @param array $values */ public function onSkinValid( $form, $values ) { $result = $this->onValidAnything( 'skin', $form, $values ); WBClass::load( 'WBService' ); WBService::addEvent( 'login' ); return $result; } /** * Save RSS feed list * * Subscribed feeds * * @param patForms $form * @param array $values */ public function onFeedValid( $form, $values ) { return $this->onValidAnything( 'feed', $form, $values ); } /** * Save anything user's skin * * * @param string $thing * @param patForms $form * @param array $values */ public function onValidAnything( $thing, $form, $values ) { $id = $this->user->getId(); $skin = $this->table->get( 'skin', $id ); if( empty( $skin ) ) { $values[$this->table->getIdentifier( 'user' )] = $id; $id = '__new'; } $this->table->save( 'skin', $id, $values ); return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'profile'; } /** * Add form rules to just created form * * This is just an emtpy function meant to bo overwriten by sub classes * * @param patForms $form object * @param string name of the xml- and template-filename * @param array $elements list of elements current form * @return bool true on success */ protected function insertFormRules( &$form, $name, $elements ) { if( $name == 'password' ) { // valid characters $rulePwdValidChars = patForms::createRule( 'Match' ); $rulePwdValidChars->setValue( '/^[a-zA-Z0-9\_\-\.,:;!ยง\/\*\+#=\?\$%]+$/' ); $fieldPwd = $form->getElementByName( 'passwordnew' ); $fieldPwd->addRule( $rulePwdValidChars, PATFORMS_RULE_BEFORE_VALIDATION ); // check retype $rulePwdRetype = patForms::createRule( 'Retype' ); $rulePwdRetype->setFieldnames( 'passwordnew', 'passwordrepeat' ); $form->addRule( $rulePwdRetype, PATFORMS_RULE_AFTER_VALIDATION ); // verify old password $rulePwdOld = patForms::createRule( 'UserPassword' ); $fieldPwdOld = $form->getElementByName( 'passwordold' ); $fieldPwdOld->addRule( $rulePwdOld, PATFORMS_RULE_AFTER_VALIDATION ); } return true; } } ?>