Ejemplo n.º 1
0
 function actionAddNote()
 {
     // Create the add form
     $form = new YDForm('addEntryForm');
     // Add the elements
     $form->addElement('text', 'title', 'Title:');
     $form->addElement('textarea', 'body', 'Contents:');
     $form->addElement('submit', 'cmdSubmit', 'Save');
     // Apply filters
     $form->addFilter('title', 'trim');
     $form->addFilter('body', 'trim');
     // Add a rule
     $form->addRule('title', 'required', 'Title is required');
     $form->addRule('body', 'required', 'Contents is required');
     // Process the form
     if ($form->validate()) {
         // Save the entries in an array
         $entry = array('id' => md5($form->getValue('title') . $form->getValue('body')), 'title' => $form->getValue('title'), 'body' => $form->getValue('body'));
         // Save the serialized entry to a file
         $this->dataDir->createFile($entry['id'] . '.dat', YDObjectUtil::serialize($entry));
         // Forward to the list view
         $this->forward('default');
         // Return
         return;
     }
     // Add the form to the template
     $this->template->assignForm('form', $form);
     // Output the template
     $this->template->display();
 }
 /**
  *	The execute function will start the YDExecutor class and process the request.
  */
 function execute()
 {
     // Do nothing if we already processed a request
     if (defined('YD_REQ_PROCESSED')) {
         return;
     }
     // Construct the name of the request class
     $clsName = basename($this->_file, YD_SCR_EXT);
     $this->clsInst = new $clsName();
     // Check if the object a YDRequest object
     if (!YDObjectUtil::isSubClass($this->clsInst, 'YDRequest')) {
         $ancestors = YDObjectUtil::getAncestors($this->clsInst);
         trigger_error('Class "' . $clsName . '" should be derived from the YDRequest class. Currently, this class has the ' . 'following ancestors: ' . implode(' -> ', $ancestors), YD_ERROR);
     }
     // Check if the class is properly initialized
     if ($this->clsInst->isInitialized() != true) {
         trigger_error('Class "' . $clsName . '" is not initialized properly. Make  sure loaded the base class YDRequest ' . 'and initialized it.', YD_ERROR);
     }
     // Only if authentication is required
     if ($this->clsInst->getRequiresAuthentication()) {
         $result = $this->clsInst->isAuthenticated();
         if ($result) {
             $this->clsInst->authenticationSucceeded();
         } else {
             $this->clsInst->authenticationFailed();
             $this->finish();
         }
     }
     // Get the action name
     $action = 'action' . $this->clsInst->getActionName();
     // Check if the action exists
     if (!$this->clsInst->hasMethod($action)) {
         $this->clsInst->errorMissingAction($action);
         $this->finish();
     }
     // Check if the current action is allowed or not and execute errorActionNotAllowed if failed
     if (!$this->clsInst->isActionAllowed()) {
         $this->clsInst->errorActionNotAllowed();
         $this->finish();
     }
     // Process the request
     $this->clsInst->process();
     $this->finish();
 }
Ejemplo n.º 3
0
 /**
  *	Function to get all the ancestors of a class. The list will contain the parent class first, and then it's
  *	parent class, etc. You can pass both the name of the class or an object instance to this function
  *
  *	@param $classname	Name of the class or object.
  *
  *	@returns	Array with all the ancestors.
  */
 function getAncestors($classname)
 {
     if (is_object($classname)) {
         $classname = strtolower(get_class($classname));
     }
     $ancestors = array();
     $father = get_parent_class($classname);
     if ($father != '') {
         $ancestors = YDObjectUtil::getAncestors($father);
         $ancestors[] = $father;
     }
     return array_reverse($ancestors);
 }
Ejemplo n.º 4
0
 /**
  *	If sending an HTML message with embedded images, use this function
  *	to add the image.
  *
  *	@param $file	The image file path.
  *	@param $c_type	(optional) The content type of the image or file.
  *	@param $name	(optional) The filename of the image.
  */
 function addHTMLImage($file, $c_type = '', $name = '')
 {
     if (!YDObjectUtil::isSubClass($file, 'YDFSImage')) {
         $file = new YDFSImage($file);
     }
     $data = $file->getContents();
     if (empty($name)) {
         $name = $file->getBaseName();
     }
     if (empty($c_type)) {
         $c_type = $file->getMimeType();
     }
     $this->_msg->addHTMLImage($data, $name, $c_type);
 }
 /**
  *  This function will parse the contents of a render and return
  *  a new YDForm object.
  *
  *  @returns    A YDForm object.
  */
 function import($content, $options = array())
 {
     $class = isset($options['class']) ? $options['class'] : 'YDForm';
     $type = isset($options['type']) ? $options['type'] : YD_XML_STRING;
     $xml = new YDXml($content, $type);
     $arr = $xml->toArray();
     // Form Name, Method, Action, Target
     $f_name = $arr['form'][0]['@']['name'];
     $f_method = $arr['form'][0]['@']['method'];
     $f_action = $arr['form'][0]['@']['action'];
     $f_target = $arr['form'][0]['@']['target'];
     $f_legend = $arr['form'][0]['@']['legend'];
     // References
     $form =& $arr['form'][0]['#'];
     $attr =& $form['attributes'][0]['#'];
     $elem =& $form['elements'][0]['#'];
     $rule =& $form['rules'][0]['#'];
     $comp =& $form['comparerules'][0]['#'];
     $frul =& $form['formrules'][0]['#'];
     $filt =& $form['filters'][0]['#'];
     $r_elem =& $form['registered'][0]['#']['elements'][0]['#'];
     $r_filt =& $form['registered'][0]['#']['filters'][0]['#'];
     $r_rule =& $form['registered'][0]['#']['rules'][0]['#'];
     $r_rend =& $form['registered'][0]['#']['renderers'][0]['#'];
     // Attributes
     $f_attr = array();
     if (is_array($attr)) {
         $attr =& $attr['attribute'];
         for ($i = 0; $i < count($attr); $i++) {
             $f_attr[$attr[$i]['@']['name']] = $attr[$i]['@']['value'];
         }
     }
     // YDForm object
     $f = new $class($f_name, $f_method, $f_action, $f_target, $f_attr);
     $f->setLegend($f_legend);
     // Elements
     if (is_array($elem)) {
         $elem =& $elem['element'];
         for ($i = 0; $i < count($elem); $i++) {
             // Name, Type, Label, Value
             $name = $elem[$i]['@']['name'];
             $type = $elem[$i]['@']['type'];
             $label = $elem[$i]['#']['labels'][0]['#']['label'][0]['@']['value'];
             $value = $elem[$i]['#']['values'][0]['#']['value'][0]['@']['value'];
             // Attributes
             $attributes = array();
             $attr =& $elem[$i]['#']['attributes'][0]['#'];
             if (is_array($attr)) {
                 $attr =& $attr['attribute'];
                 for ($j = 0; $j < count($attr); $j++) {
                     $attributes[$attr[$j]['@']['name']] = $attr[$j]['@']['value'];
                 }
             }
             // Options
             $options = array();
             $opts =& $elem[$i]['#']['options'][0]['#'];
             if (is_array($opts)) {
                 $opts =& $opts['option'];
                 for ($j = 0; $j < count($opts); $j++) {
                     $options[$opts[$j]['@']['name']] = $opts[$j]['@']['value'];
                 }
             }
             // Add
             $e =& $f->addElement($type, $name, $label, $attributes, $options);
             $e->setValue($value);
         }
     }
     // Rules
     if (is_array($rule)) {
         $rule =& $rule['rule'];
         for ($i = 0; $i < count($rule); $i++) {
             // Element, Type, Error
             $element = $rule[$i]['@']['element'];
             $type = $rule[$i]['@']['type'];
             $error = $rule[$i]['#']['errors'][0]['#']['error'][0]['@']['value'];
             // Options
             $options = array();
             $opts =& $rule[$i]['#']['options'][0]['#'];
             if (is_array($opts)) {
                 $opts =& $opts['option'];
                 for ($j = 0; $j < count($opts); $j++) {
                     if ($opts[$j]['@']['serialized'] == 'true') {
                         $opts[$j]['@']['value'] = YDObjectUtil::unserialize($opts[$j]['@']['value']);
                     }
                     if ($opts[$j]['@']['id'] == '') {
                         $options = $opts[$j]['@']['value'];
                     } else {
                         $options[$opts[$j]['@']['id']] = $opts[$j]['@']['value'];
                     }
                 }
             }
             // Add
             $f->addRule($element, $type, $error, $options);
         }
     }
     // Compare Rules
     if (is_array($comp)) {
         $comp =& $comp['rule'];
         for ($i = 0; $i < count($comp); $i++) {
             // Type, Error
             $type = $comp[$i]['@']['type'];
             $error = $comp[$i]['#']['errors'][0]['#']['error'][0]['@']['value'];
             // Elements
             $elements = array();
             $elem =& $comp[$i]['#']['elements'][0]['#'];
             if (is_array($elem)) {
                 $elem =& $elem['element'];
                 for ($j = 0; $j < count($elem); $j++) {
                     $elements[] = $elem[$j]['@']['name'];
                 }
             }
             // Add
             $f->addCompareRule($elements, $type, $error);
         }
     }
     // Form Rules
     if (is_array($frul)) {
         $frul =& $frul['rule'];
         for ($i = 0; $i < count($frul); $i++) {
             // Callback
             $callback = $frul[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->addFormRule($callback);
         }
     }
     // Filters
     if (is_array($filt)) {
         $filt =& $filt['element'];
         for ($i = 0; $i < count($filt); $i++) {
             // Element, Type
             $element = $filt[$i]['@']['name'];
             $type = $filt[$i]['@']['filter'];
             // Add
             $f->addFilter($element, $type);
         }
     }
     // Registered Elements
     if (is_array($r_elem)) {
         $r_elem =& $r_elem['element'];
         for ($i = 0; $i < count($r_elem); $i++) {
             // Name, Class, File
             $name = $r_elem[$i]['@']['name'];
             $class = $r_elem[$i]['@']['class'];
             $file = $r_elem[$i]['@']['file'];
             // Add
             $f->registerElement($name, $class, $file);
         }
     }
     // Registered Renderers
     if (is_array($r_rend)) {
         $r_rend =& $r_rend['renderer'];
         for ($i = 0; $i < count($r_rend); $i++) {
             // Name, Class, File
             $name = $r_rend[$i]['@']['name'];
             $class = $r_rend[$i]['@']['class'];
             $file = $r_rend[$i]['@']['file'];
             // Add
             $f->registerRenderer($name, $class, $file);
         }
     }
     // Registered Filters
     if (is_array($r_filt)) {
         $r_filt =& $r_filt['filter'];
         for ($i = 0; $i < count($r_filt); $i++) {
             // Name, File
             $name = $r_filt[$i]['@']['name'];
             $file = $r_filt[$i]['@']['file'];
             // Callback
             $callback = $r_filt[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->registerFilter($name, $callback, $file);
         }
     }
     // Registered Rules
     if (is_array($r_rule)) {
         $r_rule =& $r_rule['rule'];
         for ($i = 0; $i < count($r_rule); $i++) {
             // Name, File
             $name = $r_rule[$i]['@']['name'];
             $file = $r_rule[$i]['@']['file'];
             // Callback
             $callback = $r_rule[$i]['@']['callback'];
             if (strpos($callback, '::') !== false) {
                 $c = explode('::', $callback);
                 $callback = array($c[0], $c[1]);
             }
             // Add
             $f->registerFilter($name, $callback, $file);
         }
     }
     return $f;
 }
Ejemplo n.º 6
0
 function actionDefault()
 {
     YDDebugUtil::dump(YDObjectUtil::getAncestors($this), 'ancestors of this request:');
 }
Ejemplo n.º 7
0
 /**
  *	This function will serialize the object.
  */
 function serialize($obj)
 {
     return YDObjectUtil::serialize($this);
 }
 /**
  *	This function will add a YDForm object to the template. It will automatically convert the form to an array
  *	using the template object so that you don't have to do it manually.
  *
  *	If the form specified when calling this function is not a class derived from the YDForm class, a fatal error
  *	will be thrown.
  *
  *	@param $name	Name you want to use for this form for referencing it in the template.
  *	@param $form	The form you want to add.
  */
 function assignForm($name, $form)
 {
     if (!YDObjectUtil::isSubclass($form, 'YDForm')) {
         trigger_error('The form you have tried to add to the form is not a subclass of the YDForm class.', YD_ERROR);
     }
     $this->assign($name, $form->toArray($this));
 }
Ejemplo n.º 9
0
 /**
  *	If sending an HTML message with embedded images, use this function
  *	to add the image.
  *
  *	@param $file	The image file path.
  *	@param $c_type	(optional) The content type of the image or file.
  *	@param $name	(optional) The filename of the image.
  */
 function addHTMLImage($file, $c_type = '', $name = '')
 {
     if (!YDObjectUtil::isSubClass($file, 'YDFSImage')) {
         $file = new YDFSImage($file);
     }
     if (empty($name)) {
         $name = $file->getBaseName();
     }
     if (empty($c_type)) {
         $c_type = $file->getMimeType();
     }
     $this->_msg->AddEmbeddedImage($file->getAbsolutePath(), $name, $name, 'base64', $c_type);
 }
Ejemplo n.º 10
0
 function actionSuscribe()
 {
     if (!$this->user->authentificated) {
         // Create the profile form
         $form = new YDForm('suscribeForm');
         $form->addElement('text', 'suscribeLogin', t('user.login'));
         $form->addElement('textarea', 'suscribeDescription', t('user.desc'));
         $form->addElement('password', 'suscribePassUn', t('user.pwd'));
         $form->addElement('password', 'suscribePassDeux', t('user.confirmpwd'));
         $form->addElement('submit', 'cmdSubmit', t('user.valid'));
         // Add rules
         $form->addFormRule(array(&$this, 'checkSuscribe'));
         // Process the form
         if ($form->validate()) {
             // Insert profile
             $this->user->id = '';
             $this->user->login = $form->getValue('suscribeLogin');
             $this->user->description = $form->getValue('suscribeDescription');
             $this->user->password = md5($form->getValue('suscribePassUn'));
             $this->user->insert();
             $this->user->auth();
             $_GET['idUser'] = $this->user->id;
             $_SESSION['s_user'] = YDObjectUtil::serialize($this->user);
             // Redirect sur les forums
             header('location: forums.php');
             return;
         }
         // Assign variables to the template
         $this->actionTpl->assign('form', $form->toArray());
         $content = new page($this->actionTpl->fetch('templates/user.suscribe.tpl'), 'Inscription');
         // Display the action template into the master template
         $this->display($content);
     } else {
         $this->actionMonProfil();
         return;
     }
 }
Ejemplo n.º 11
0
 function checkLogin($fields)
 {
     $user = new userObject($fields['loginName'], md5($fields['loginPass']));
     $temp = $user->auth();
     // errors during authentification ?
     if (is_array($temp)) {
         return $temp;
     } else {
         // else log the user
         $this->user = $user;
         $_SESSION['s_user'] = YDObjectUtil::serialize($user);
         return true;
     }
 }