/**
  *	This function will parse the template and will return the parsed contents.
  *
  *	You can specify the name of the template which should be in the template directory. If no name is specified,
  *	the basename of the PHP script with the extension '.tpl' will be used.
  *
  *	This function automatically adds some variables to the template, which you can use as well in the template:
  *	YD_FW_NAME, YD_FW_VERSION, YD_FW_NAMEVERS, YD_FW_HOMEPAGE, YD_SELF_SCRIPT, YD_SELF_URI, YD_ACTION_PARAM.
  *
  *	@param $file		(optional) The name of the template you want to parse and output.
  *	@param $cache_id	(optional) ID for the cache of the template (must be unique).
  *	@param $display		(optional) Whether the output should be displayed or returned.
  *
  *	@returns	This function returns the output of the parsed template.
  */
 function fetch($file = '', $cache_id = null, $display = false)
 {
     // Add some default variables
     $this->assign('YD_FW_NAME', YD_FW_NAME);
     $this->assign('YD_FW_VERSION', YD_FW_VERSION);
     $this->assign('YD_FW_NAMEVERS', YD_FW_NAMEVERS);
     $this->assign('YD_FW_HOMEPAGE', YD_FW_HOMEPAGE);
     $this->assign('YD_SELF_SCRIPT', YD_SELF_SCRIPT);
     $this->assign('YD_SELF_URI', YD_SELF_URI);
     $this->assign('YD_ACTION_PARAM', YD_ACTION_PARAM);
     $this->assign('YD_ACTION', YDRequest::getActionName());
     // Get the template name
     $tplName = $this->_getTemplateName($file);
     // Output the template
     $result = parent::fetch($tplName, $cache_id, false);
     // Save the cache if needed
     if (!empty($cache_id) && !$this->force_compile && $this->caching) {
         $cacheFile = $this->_getCachePath($cache_id);
         $fp = fopen($cacheFile, 'wb');
         fwrite($fp, $result);
         fclose($fp);
     }
     if ($display == true) {
         echo $result;
     } else {
         return $result;
     }
 }
 /**
  *	This is the class constructor for the YDFormElement_Captcha class.
  *
  *	@param $form		The name of the form to which this element is connected.
  *	@param $name		The name of the form element.
  *	@param $label		(optional) The label for the form element.
  *	@param $attributes	(optional) The attributes for the form element.
  *	@param $options		(optional) The options for the elment.
  */
 function YDFormElement_Captcha($form, $name, $label = '', $attributes = array(), $options = array())
 {
     // init parent
     $this->YDFormElement($form, $name, $label, $attributes, $options);
     // set type
     $this->_type = 'captcha';
     $attributes = '';
     foreach (YDConfig::get('YD_FORMELEMENT_CAPTCHA_URLATTRIBUTES') as $k => $v) {
         $attributes .= '&' . $k . '=' . $v;
     }
     // create default image url
     $this->_url = YDRequest::getCurrentUrl(true) . '?do=ShowCaptcha' . $attributes . '&id=' . md5(microtime());
     // text box position
     $this->_textPosition_left = false;
     // refresh button or refresh image. not added by default
     $this->_button = null;
     $this->_refreshimage = false;
     $this->_refreshcaption = YDConfig::get('YD_FORMELEMENT_CAPTCHA_LABEL');
     // add refresh button
     if (isset($options['refreshbutton']) || in_array('refreshbutton', $options)) {
         $this->addRefreshButton();
     }
     if (isset($options['refreshimage']) || in_array('refreshimage', $options)) {
         $this->addRefreshImage();
     }
     if (isset($options['refreshcaption'])) {
         $this->_refreshcaption = $options['refreshcaption'];
     }
     // compute image
     $this->img = new YDFormElement_Img($form, $name . 'captcha', $this->_url, array('width' => 200, 'height' => 40));
     // compute on click
     $this->_onclick = "document.getElementById('" . $this->img->getAttribute('id') . "').src = document.getElementById('" . $this->img->getAttribute('id') . "').src.split('&id=')[0] + '&id=' + Math.random();document.getElementById('" . $this->getAttribute('id') . "').value='';document.getElementById('" . $this->getAttribute('id') . "').focus();";
 }
 /**
  *	This is the class constructor for the YDFormElement_Captcha class.
  *
  *	@param $form		The name of the form to which this element is connected.
  *	@param $name		The name of the form element.
  *	@param $label		(optional) The label for the form element.
  *	@param $attributes	(optional) The attributes for the form element.
  *	@param $options		(optional) The options for the elment.
  */
 function YDFormElement_Captcha($form, $name, $label = '', $attributes = array(), $options = array())
 {
     // init parent
     $this->YDFormElement($form, $name, $label, $attributes, $options);
     // set type
     $this->_type = 'captcha';
     // create default image url
     $this->_url = YDRequest::getCurrentUrl(true) . '?do=ShowCaptcha&id=' . md5(microtime());
     // text box position
     $this->_textPosition_left = false;
     // refresh button. not added by default
     $this->_button = null;
 }
function YDTplModLinkWithID($base, $item, $suffix = null)
{
    $base .= strpos($base, '?') === false ? '?id=' : '&id=';
    if (is_numeric($item)) {
        $base .= $item;
    } else {
        $base .= isset($item['id']) ? $item['id'] : $item;
    }
    if (!is_null($suffix)) {
        $base = $base . $suffix;
    }
    return YDUrl::makeLinkAbsolute($base, YDRequest::getCurrentUrl(true));
}
 /**
  *	This is the class constructor for the YDFeedCreator class.
  */
 function YDFeedCreator()
 {
     // Initialize YDBase
     $this->YDAddOnModule();
     // Setup the module
     $this->_author = 'Pieter Claerhout';
     $this->_version = '1.0';
     $this->_copyright = '(c) 2005 Pieter Claerhout, pieter@yellowduck.be';
     $this->_description = 'This addon class defines a RSS/ATOM feed. You can use this class to create RSS and ' . 'Atom feeds in a very easy and straightforward way. If you set up your class instance, ' . 'you can automatically output to the different versions of RSS and ATOM with the same ' . 'source data.';
     // Start with the general variables
     $this->_encoding = 'ISO-8859-1';
     $this->_title = '';
     $this->_description = '';
     $this->_link = YDRequest::getCurrentUrl();
     $this->_items = array();
     $this->_generator = YD_FW_NAMEVERS . ' - YDFeedCreator';
 }
 function _assignJavascript($tpl_source, &$smarty)
 {
     // load autocompleter css
     $html = $this->autocompleterCss;
     // start javascript code
     $html .= "\n<script type=\"text/javascript\">\n";
     // use default url
     $html .= "var xajaxRequestUri     = \"" . YDRequest::getNormalizedUri() . "\";\n";
     // check debug option
     $html .= "var xajaxDebug          = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     $html .= "var xajaxStatusMessages = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     $html .= "var xajaxWaitCursor     = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     // use post
     $html .= "var xajaxDefinedGet     = 0;\n";
     $html .= "var xajaxDefinedPost    = 1;\n";
     // get standard xajax code
     $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js');
     // include generic effects lib .. yes, it must be ALWAYS included
     $html .= "\n" . file_get_contents(dirname(__FILE__) . '/js/prototype.lite.js_moo.fx.js_moo.fx.pack.js');
     // send autocompleter code
     $html .= "\n" . $this->autocompleterCode;
     // compute ONLOAD code
     $onload = '';
     // export effects js
     foreach ($this->effects as $eff_name => $eff_code) {
         $onload .= $eff_code . "\n\t";
     }
     // send js waiting message creation code
     if ($this->waitingMessageCode != '') {
         $onload .= $this->waitingMessageCode . "\n\t";
     }
     // send autocompleter functions code
     $onload .= implode("\n\t", $this->autocompleterCodeFunctions);
     // if there are on load js just export it
     if ($onload != '') {
         $html .= "\nwindow.onload = function() {\n\t" . $onload . "\n}";
     }
     // send js function to hide waiting message
     $html .= $this->waitingMessageCodeFunction . "\n";
     // loop xajax functions created on-the-fly
     foreach ($this->aFunctions as $sFunction => $bExists) {
         $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]);
     }
     // add custom js TOP code
     if (!empty($this->customjsTop)) {
         $html .= implode("\n", $this->customjsTop) . "\n";
     }
     // add YDAjax js variables
     foreach ($this->customjsVariables as $variable => $declaration) {
         $html .= "var " . $variable . " = " . $declaration . ";\n";
     }
     // add YDAjax js functions
     foreach ($this->customjs as $function => $declaration) {
         $html .= "function " . $function . "{" . $declaration . "}\n";
     }
     // add js custom BOTTOM code
     if (!empty($this->customjsBottom)) {
         $html .= implode("\n", $this->customjsBottom) . "\n";
     }
     // end javascript code
     $html .= "</script>\n";
     // get html tag to use
     $tag = YDConfig::get('YD_AJAX_TAG');
     // add js code to template
     if (YDConfig::get('YD_AJAX_AFTERTAG')) {
         return eregi_replace($tag, $tag . "\n" . $html, $tpl_source);
     } else {
         return eregi_replace($tag, $html . "\n" . $tag, $tpl_source);
     }
 }
 /**
  *	This function will return a normalized URI. This is the URI without the debug information and will all keys
  *	sorted alphabetically.
  *
  *	@returns	Normalized request URI.
  */
 function getNormalizedUri()
 {
     $url = parse_url(YDRequest::getCurrentUrl());
     $params = $_GET;
     ksort($params);
     if (isset($params['YD_DEBUG'])) {
         unset($params['YD_DEBUG']);
     }
     $query = array();
     foreach ($params as $key => $val) {
         if ($key != 'PHPSESSID') {
             array_push($query, urlencode($key) . '=' . urlencode($val));
         }
     }
     $url['query'] = implode('&', $query);
     if (!empty($url['query'])) {
         $url['query'] = '?' . $url['query'];
     }
     return $url['path'] . $url['query'];
 }
 function __assignTemplateCode()
 {
     // use default url
     $html = "var xajaxRequestUri     = \"" . YDRequest::getNormalizedUri() . "\";\n";
     // check debug option
     $html .= "var xajaxDebug          = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     $html .= "var xajaxStatusMessages = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     $html .= "var xajaxWaitCursor     = " . (YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false") . ";\n";
     // use post
     $html .= "var xajaxDefinedGet     = 0;\n";
     $html .= "var xajaxDefinedPost    = 1;\n";
     // get standard xajax code
     $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js') . "\n";
     // include generic effects lib .. yes, it must be ALWAYS included
     $html .= file_get_contents(dirname(__FILE__) . '/js/prototype.lite.js_moo.fx.js_moo.fx.pack.js') . "\n";
     // send autocompleter code
     $html .= $this->autocompleterCode;
     // send js function to hide waiting message
     $html .= $this->waitingMessageCodeFunction;
     // loop xajax functions created on-the-fly
     foreach ($this->aFunctions as $sFunction => $bExists) {
         $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]);
     }
     // add custom js TOP code
     if (!empty($this->customjsTop)) {
         $html .= implode("\n", $this->customjsTop) . "\n";
     }
     // add YDAjax js variables
     foreach ($this->customjsVariables as $variable => $declaration) {
         $html .= "var " . $variable . " = " . $declaration . ";\n";
     }
     // add YDAjax js functions
     foreach ($this->customjs as $function => $declaration) {
         $html .= "function " . $function . "{" . $declaration . "}\n";
     }
     // add js custom BOTTOM code
     if (!empty($this->customjsBottom)) {
         $html .= implode("\n", $this->customjsBottom) . "\n";
     }
     // add all code to template html
     $this->template->addJavascript(trim($html), true);
     // compute ONLOAD code
     $onload = '';
     // export effects js
     foreach ($this->effects as $eff_name => $eff_code) {
         $onload .= "\n\t" . $eff_code;
     }
     // send js waiting message creation code
     if ($this->waitingMessageCode != '') {
         $onload .= "\n\t" . $this->waitingMessageCode;
     }
     // send autocompleter functions code
     if (!empty($this->autocompleterCodeFunctions)) {
         $onload .= "\n\t" . implode("\n\t", $this->autocompleterCodeFunctions);
     }
     // add all code to template html
     $this->template->addJavascript($onload, false, true);
 }
 /**
  *	This is the class constructor for the YDAjax class.
  *
  *	@param $template		Template object.
  */
 function YDAjax(&$template, $url_string = null, $outputFiles = true)
 {
     // Setup the module
     $this->_author = 'Francisco Azevedo';
     $this->_version = '3.0b';
     $this->_copyright = '(c) Copyright 2002-2006 Francisco Azevedo';
     $this->_description = 'This class makes ajax easy for YDF developers';
     // prefix string used in js function names
     $this->prefix = YDConfig::get('YD_AJAX_PREFIX');
     // initialize xajax object
     $this->xajax("", $this->prefix, YDConfig::get('YD_AJAX_ENCODING'));
     // initilize all possible forms (4)
     $this->form_0 = null;
     $this->form_1 = null;
     $this->form_2 = null;
     $this->form_3 = null;
     // initilize template
     $this->template =& $template;
     // response object
     $this->response = new YDAjaxResponse(YDConfig::get('YD_AJAX_ENCODING'));
     // by default we don't use effects (then js effects lib won't be loaded)
     $this->effects = array();
     // autocompleter code
     $this->autocompleterCode = '';
     $this->autocompleterCss = '';
     $this->autocompleterCodeFunctions = array();
     // init wysiwyg editors
     $this->wysiwyg_editorpath = dirname(__FILE__) . '/editors/YDAjaxEditor.php';
     $this->wysiwyg_editorclass = 'YDAjaxEditor';
     $this->wysiwyg_forms = array();
     // check url
     if (is_null($url_string)) {
         $url_string = YDRequest::getNormalizedUri();
     }
     // compute default ajax header
     $html = "var xajaxRequestUri     = \"" . $url_string . "\";\n";
     $debug = YDConfig::get('YD_AJAX_DEBUG') ? "true" : "false";
     // check debug option
     $html .= "var xajaxDebug          = " . $debug . ";\n";
     $html .= "var xajaxStatusMessages = " . $debug . ";\n";
     $html .= "var xajaxWaitCursor     = " . $debug . ";\n";
     // use post
     $html .= "var xajaxDefinedGet  = 0;\n";
     $html .= "var xajaxDefinedPost = 1;\n";
     // get standard xajax code
     if ($outputFiles) {
         $html .= file_get_contents(dirname(__FILE__) . '/js/xajax.js') . "\n";
     }
     // add default header to template
     $this->template->addJavascript($html, true, false);
     // array to store events already added
     $this->_eventsAdded = array();
 }
 function YDWeblogAPI()
 {
     // Initialize the parent
     $this->YDBase();
     // Get the database connection
     $this->db = YDDatabase::getInstance('mysql', YDConfig::get('db_name', 'YDWeblog'), YDConfig::get('db_user', 'root'), YDConfig::get('db_pass', ''), YDConfig::get('db_host', 'localhost'));
     // Get a link to the database metadata
     $this->dbmeta = new YDDatabaseMetaData($this->db);
     // Upgrade the schema if needed
     $this->upgradeSchemaIfNeeded();
     // The array that will hold the image metadata
     $this->imagemetadata = null;
     // Delete spam comments older than 7 days
     $sql = 'DELETE FROM #_comments WHERE is_spam = 1 AND created < (unix_timestamp()-604800)';
     $this->db->executeSql($sql);
     // Delete the old IP numbers from spam check
     $comment_interval = YDConfig::get('comment_interval', 10);
     if ($comment_interval != '' && is_numeric($comment_interval)) {
         $sql = 'DELETE FROM #_spamcheck WHERE lastvisit < (unix_timestamp()-' . $comment_interval . ')';
         $this->db->executeSql($sql);
     }
     // Cleanup the bad behaviour table part 1
     $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 1 day ) < DATE_SUB( CURDATE(), INTERVAL 1 day ) AND request_method = \'GET\' AND `key` = \'00000000\'';
     $this->db->executeSql($sql);
     // Cleanup the bad behaviour table part 2
     $sql = 'DELETE FROM #_bad_behavior WHERE DATE_SUB( `date`, INTERVAL 7 day ) < DATE_SUB( CURDATE(), INTERVAL 7 day )';
     $this->db->executeSql($sql);
     // Check against akismet if a key is there
     if (YDConfig::get('akismet_key', '') != '') {
         // Include the YDAkismet addon
         include_once YD_DIR_HOME_ADD . '/YDAkismet/YDAkismet.php';
         // Get the URL of the weblog
         $weblog_url = dirname(YDRequest::getCurrentUrl(true)) . '/';
         // Initialize YDAkismet
         $this->akismet = new YDAkismet($weblog_url, YDConfig::get('akismet_key', ''));
     } else {
         // No akismet
         $this->akismet = null;
     }
 }
function YDTplModLinkWithID($base, $item, $suffix = null)
{
    $ori_base = $base;
    $base .= strpos($base, '?') === false ? '?id=' : '&id=';
    if (is_numeric($item)) {
        $base .= $item;
    } else {
        $base .= is_array($item) && isset($item['id']) ? $item['id'] : $item;
    }
    if (YDConfig::get('friendly_urls', false)) {
        if ($ori_base == 'item_gallery.php') {
            $base = str_replace('item_gallery.php?id=', 'image/', $base);
        } else {
            $base = str_replace('.php?id=', '_', $base) . '.php';
        }
    }
    if (!is_null($suffix)) {
        $base = $base . $suffix;
    }
    return YDUrl::makeLinkAbsolute($base, YDRequest::getCurrentUrl(true));
}
 /**
  *  This function forces the user to logout.
  */
 function action_admin_logout()
 {
     YDRequest::redirect(YD_SELF_SCRIPT . '?do=logout');
 }
 /**
  *	This function will parse the template and will return the parsed contents.
  *
  *	You can specify the name of the template which should be in the template directory. If no name is specified,
  *	the basename of the PHP script with the extension '.tpl' will be used.
  *
  *	This function automatically adds some variables to the template, which you can use as well in the template:
  *	YD_FW_NAME, YD_FW_VERSION, YD_FW_NAMEVERS, YD_FW_HOMEPAGE, YD_SELF_SCRIPT, YD_SELF_URI, YD_ACTION_PARAM.
  *
  *	@param $file		(optional) The name of the template you want to parse and output.
  *	@param $cache_id	(optional) ID for the cache of the template (must be unique).
  *	@param $compile_id	(optional) ID for the compilation of the template (must be unique).
  *	@param $display		(optional) Whether the output should be displayed or returned.
  *
  *	@returns	This function returns the output of the parsed template.
  */
 function fetch($file = '', $cache_id = null, $compile_id = null, $display = false)
 {
     // Create the cache dir if it doesn't exist
     if ($this->caching && !is_dir($this->cache_dir)) {
         @mkdir($this->cache_dir);
     }
     // Add some default variables
     $this->assign('YD_FW_NAME', YD_FW_NAME);
     $this->assign('YD_FW_VERSION', YD_FW_VERSION);
     $this->assign('YD_FW_NAMEVERS', YD_FW_NAMEVERS);
     $this->assign('YD_FW_HOMEPAGE', YD_FW_HOMEPAGE);
     $this->assign('YD_SELF_SCRIPT', YD_SELF_SCRIPT);
     $this->assign('YD_SELF_FILE', YD_SELF_FILE);
     $this->assign('YD_SELF_URI', YD_SELF_URI);
     $this->assign('YD_ACTION_PARAM', YD_ACTION_PARAM);
     $this->assign('YD_ACTION', YDRequest::getActionName());
     // Get the template name
     $tplName = $this->_getTemplateName($file);
     // Add pseudo compile id
     if (is_null($compile_id)) {
         $compile_id = sprintf('%u', crc32(realpath($this->template_dir) . '/' . $tplName));
     }
     // Output the template
     $result = parent::fetch($tplName, $cache_id, $compile_id);
     // Display the template or return the result
     if ($display == true) {
         echo $result;
     } else {
         return $result;
     }
 }
 /**
  *	This function will return the form as an array.
  *
  *	@returns	The form as an array.
  */
 function toArray()
 {
     // Start with an empty array
     $form = array();
     // Add the list of attributes
     $attribs = array('name' => $this->_name, 'id' => $this->_name, 'method' => strtoupper($this->_method), 'action' => $this->_action, 'target' => $this->_target);
     $attribs = array_merge($this->_attributes, $attribs);
     $form['attribs'] = $this->_convertToHtmlAttrib($attribs);
     $form['tag'] = '<form' . $form['attribs'] . '>';
     $form['requirednote'] = $this->_requiredNote;
     // Add the errors
     $form['errors'] = $this->_errors;
     // Loop over the list of elements
     foreach ($this->_elements as $name => $element) {
         // Update the value
         $element->_value = $this->getValue($name);
         // Add the form element
         $form[$name] = $element->toArray();
         // Add errors if any
         if (array_key_exists($name, $this->_errors)) {
             $form[$name]['error'] = $this->_errors[$name];
         } else {
             $form[$name]['error'] = '';
         }
         // Check if the field is required
         if (array_key_exists($name, $this->_rules)) {
             $form[$name]['required'] = true;
         } else {
             $form[$name]['required'] = false;
         }
         // Add the HTML labels
         if ($form[$name]['isButton'] === false && $form[$name]['type'] != 'hidden') {
             $form[$name]['label_html'] = '';
             if ($form[$name]['required']) {
                 $form[$name]['label_html'] .= $this->_htmlRequiredStart;
             }
             if (!empty($form[$name]['label'])) {
                 $form[$name]['label_html'] .= $form[$name]['label'];
             }
             if ($form[$name]['required']) {
                 $form[$name]['label_html'] .= $this->_htmlRequiredEnd;
             }
             if (!empty($form[$name]['error'])) {
                 $form[$name]['error_html'] = $this->_htmlErrorStart . $form[$name]['error'] . $this->_htmlErrorEnd;
             }
         }
     }
     // Add the do parameter if it's a get form
     if ($this->_method == 'get') {
         $form[YD_ACTION_PARAM] = array();
         $form[YD_ACTION_PARAM]['name'] = YD_ACTION_PARAM;
         $form[YD_ACTION_PARAM]['value'] = YDRequest::getActionName();
         $form[YD_ACTION_PARAM]['type'] = 'hidden';
         $form[YD_ACTION_PARAM]['label'] = '';
         $form[YD_ACTION_PARAM]['options'] = array();
         $form[YD_ACTION_PARAM]['placeLabel'] = 'before';
         $form[YD_ACTION_PARAM]['html'] = '<input type="hidden" name="' . YD_ACTION_PARAM . '" value="' . YDRequest::getActionName() . '">';
         $form[YD_ACTION_PARAM]['isButton'] = false;
         $form[YD_ACTION_PARAM]['error'] = '';
         $form[YD_ACTION_PARAM]['required'] = false;
     }
     // Return the form array
     return $form;
 }
 function YDWeblogAdminRequest($req_admin = false)
 {
     // Initialize the parent
     $this->YDWeblogRequest();
     // Check if we allow caching
     $this->caching = false;
     // Delete the cache
     if (sizeof($_POST) > 0 || YDRequest::getActionName() == 'delete') {
         @$this->clearCache();
     }
     // Change the template directory
     $this->tpl->template_dir = YD_SELF_DIR;
     // Get a link to the database metadata
     $dbmeta = new YDDatabaseMetaData($this->weblog->db);
     // Optimize the tables
     foreach ($dbmeta->getTables() as $table) {
         $this->weblog->db->executeSql('optimize table ' . $table);
     }
     // Check for admin access
     $this->req_admin = $req_admin;
 }
 /**
  *  Helper function for the makeLinksAbsolute function.
  *
  *  @param  $rel_uri    The uri to convert to an absolute one.
  *  @param  $base       (optional) The base url. By default, it uses the current url.
  *
  *  @returns    The link converted to an absolute one.
  *
  *  @static
  */
 function makeLinkAbsolute($rel_uri, $base = null)
 {
     if (substr(strtolower($rel_uri), 0, 7) == 'http://') {
         return rtrim($rel_uri, '/.');
     }
     if (is_null($base)) {
         $base = YDRequest::getCurrentUrl(true);
     }
     preg_match("'^([^:]+://[^/]+)/'", $base, $m);
     $base_start = $m[1];
     if (preg_match("'^/'", $rel_uri)) {
         return rtrim($base_start . $rel_uri, '/.');
     }
     $base = preg_replace("{[^/]+\$}", '', $base);
     $base .= $rel_uri;
     $base = preg_replace("{^[^:]+://[^/]+}", '', $base);
     $base_array = explode('/', $base);
     if (count($base_array) && !strlen($base_array[0])) {
         array_shift($base_array);
     }
     $i = 1;
     while ($i < count($base_array)) {
         if ($base_array[$i - 1] == ".") {
             array_splice($base_array, $i - 1, 1);
             if ($i > 1) {
                 $i--;
             }
         } elseif ($base_array[$i] == ".." && $base_array[$i - 1] != "..") {
             array_splice($base_array, $i - 1, 2);
             if ($i > 1) {
                 $i--;
                 if ($i == count($base_array)) {
                     array_push($base_array, "");
                 }
             }
         } else {
             $i++;
         }
     }
     if (count($base_array) && isset($base_array[-1]) && $base_array[-1] == ".") {
         $base_array[-1] = "";
     }
     while (count($base_array) && preg_match("/^\\.\\.?\$/", $base_array[0])) {
         array_shift($base_array);
     }
     return rtrim($base_start . '/' . implode("/", $base_array), '/.');
 }
 /**
  *	This function will render the form.
  *
  *	@returns	The rendered form.
  */
 function render()
 {
     // Start with an empty array
     $form = array();
     // Add the list of attributes
     $attribs = array('name' => $this->_form->_name, 'id' => $this->_form->_name, 'method' => $this->_form->_method, 'action' => $this->_form->_action, 'target' => $this->_form->_target);
     $attribs = array_merge($attribs, $this->_form->_attributes);
     if ($attribs['target'] == '_self') {
         unset($attribs['target']);
     }
     // Add the rest of the form attributes
     $form['attribs'] = $this->_form->_convertToHtmlAttrib($attribs);
     $form['tag'] = '<form' . $form['attribs'] . '>';
     $form['requirednote'] = $this->_form->_requiredNote;
     $form['endtag'] = '</form>';
     // Add the errors
     $form['name'] = $this->_form->_name;
     $form['errors'] = $this->_form->_errors;
     $form['errors_unique_messages'] = array_unique(array_values($this->_form->_errors));
     // Loop over the list of elements
     foreach ($this->_form->_elements as $name => $element) {
         // Update the value
         $element->_value = $this->_form->getValue($name);
         // Add the form element
         $form[$name] = $element->toArray();
         // Add errors if any
         if (array_key_exists($name, $this->_form->_errors)) {
             $form[$name]['error'] = $this->_form->_errors[$name];
         } else {
             $form[$name]['error'] = '';
         }
         // Check if the field is required
         $required = false;
         if (array_key_exists($name, $this->_form->_rules)) {
             foreach ($this->_form->_rules[$name] as $rules) {
                 if (strtolower($rules['rule']) == 'required') {
                     $required = true;
                     break;
                 }
             }
         }
         $form[$name]['required'] = $required;
         // Add the HTML labels
         if ($form[$name]['isButton'] === false) {
             $form[$name]['label_html'] = '';
             if ($form[$name]['placeLabel'] != 'none') {
                 if (!empty($form[$name]['label'])) {
                     $form[$name]['label_html'] .= $form[$name]['label'];
                 }
                 $obj = $this->_form->getElement($name);
                 if ($form[$name]['required']) {
                     $form[$name]['label_html'] = $this->_form->_htmlRequiredStart . $form[$name]['label_html'] . $this->_form->_htmlRequiredEnd;
                 }
                 if (!empty($form[$name]['error'])) {
                     $form[$name]['error_html'] = $this->_form->_htmlErrorStart . $form[$name]['error'] . $this->_form->_htmlErrorEnd;
                 }
             }
         }
         // Fix the labels
         $form[$name]['label'] = $form[$name]['labelname'];
         unset($form[$name]['labelname']);
     }
     // Add the do parameter if it's a get form
     if ($this->_form->_method == 'get') {
         $form['do'] = array();
         $form['do']['name'] = 'do';
         $form['do']['value'] = YDRequest::getActionName();
         $form['do']['type'] = 'hidden';
         $form['do']['label'] = '';
         $form['do']['options'] = array();
         $form['do']['placeLabel'] = 'none';
         $form['do']['html'] = '<input type="hidden" name="do" value="' . YDRequest::getActionName() . '" />';
         $form['do']['isButton'] = false;
         $form['do']['error'] = '';
         $form['do']['required'] = false;
     }
     // Return the form array
     return $form;
 }
 /**
  *	This function will render the form.
  *
  *	@returns	The rendered form.
  */
 function render()
 {
     // Start with an empty array
     $form = array();
     // Add the list of attributes
     $attribs = array('name' => $this->_form->_name, 'id' => $this->_form->_name, 'method' => $this->_form->_method, 'action' => $this->_form->_action, 'target' => $this->_form->_target);
     $attribs = array_merge($attribs, $this->_form->_attributes);
     if ($attribs['target'] == '_self') {
         unset($attribs['target']);
     }
     // Add the rest of the form attributes
     $form['attribs'] = $this->_form->_convertToHtmlAttrib($attribs);
     $form['tag'] = '<form' . $form['attribs'] . '>';
     $form['requirednote'] = $this->_form->_requiredNote;
     $form['endtag'] = '</form>';
     $form['name'] = $this->_form->_name;
     $form['legend'] = $this->_form->_legend;
     // Add a script for the default item
     if (!empty($this->_form->_defaultItem) && array_key_exists($this->_form->_defaultItem, $this->_form->_elements)) {
         $form['endtag'] .= sprintf('<script type="text/javascript">document.getElementById("%s").focus();</script>', addslashes($this->_form->_name . '_' . $this->_form->_defaultItem));
     }
     // Add the fieldset and legend tag if any
     if (!empty($this->_form->_legend)) {
         // Add it to the start tag
         $form['tag'] .= '<fieldset><legend>' . $this->_form->_legend . '</legend>';
         // Add it to the end tag
         $form['endtag'] = '</fieldset>' . $form['endtag'];
     }
     // Add the errors
     $form['errors'] = $this->_form->_errors;
     $form['errors_unique_messages'] = array_unique(array_values($this->_form->_errors));
     // Loop over the list of elements
     foreach ($this->_form->_elements as $name => $element) {
         // Update the value
         $element->_value = $this->_form->getValue($name);
         // Add the hidden_html value
         $elementArray = $element->toArray();
         $attribs = array('type' => 'hidden', 'name' => $elementArray['id'], 'value' => $elementArray['value']);
         $elementArray['hidden_html'] = '<input' . YDForm::_convertToHtmlAttrib($attribs) . ' />';
         // Add the form element
         $form[$name] = $elementArray;
         // Add errors if any
         if (array_key_exists($name, $this->_form->_errors)) {
             $form[$name]['error'] = $this->_form->_errors[$name];
         } else {
             $form[$name]['error'] = '';
         }
         // Check if the field is required
         $required = false;
         if (array_key_exists($name, $this->_form->_rules)) {
             foreach ($this->_form->_rules[$name] as $rules) {
                 if (strtolower($rules['rule']) == 'required') {
                     $required = true;
                     break;
                 }
             }
         }
         $form[$name]['required'] = $required;
         // Add required and error HTML
         if ($form[$name]['isButton'] === false && $form[$name]['placeLabel'] != 'none') {
             if ($form[$name]['required']) {
                 $form[$name]['label_html'] = $this->_form->_htmlRequiredStart . $form[$name]['label_html'] . $this->_form->_htmlRequiredEnd;
             }
             if (!empty($form[$name]['error'])) {
                 $form[$name]['error_html'] = $this->_form->_htmlErrorStart . $form[$name]['error'] . $this->_form->_htmlErrorEnd;
             }
         }
     }
     // Add the do parameter if it's a get form
     if ($this->_form->_method == 'get') {
         $form['do'] = array();
         $form['do']['name'] = 'do';
         $form['do']['id'] = 'do';
         $form['do']['value'] = YDRequest::getActionName();
         $form['do']['type'] = 'hidden';
         $form['do']['label'] = '';
         $form['do']['label_html'] = '';
         $form['do']['options'] = array();
         $form['do']['placeLabel'] = 'none';
         $form['do']['html'] = '<input type="hidden" name="do" id="do" value="' . YDRequest::getActionName() . '" />';
         $form['do']['isButton'] = false;
         $form['do']['error'] = '';
         $form['do']['required'] = false;
     }
     // Return the form array
     return $form;
 }