/** * This is the class constructor for the YDForm class. * * @param $name The name of the form. * @param $method (optional) Method used for submitting the form. * Normally, this is either POST or GET. * @param $action (optional) Action used for submitting the form. * If not specified, it will default to the URI of * the current request. * @param $target (optional) HTML target for the form. * @param $attributes (optional) Attributes for the form. */ function YDForm($name, $method = 'post', $action = '', $target = '_self', $attributes = array()) { // Initialize the parent $this->YDBase(); // Initialize the variables $this->_name = $name; $this->_method = strtoupper($method) == 'GET' ? 'get' : 'post'; $this->_action = empty($action) ? $_SERVER['REQUEST_URI'] : $action; $this->_target = empty($target) ? '_self' : $target; $this->_attributes = $attributes; $this->_legend = null; // The list of known elements, rules, filters and validators $this->_regElements = array(); $this->_regRules = array(); $this->_regFilters = array(); $this->_regValidators = array(); $this->_regRenderers = array(); // The list of elements, rules and filters $this->_elements = array(); $this->_rules = array(); $this->_comparerules = array(); $this->_formrules = array(); $this->_filters = array(); // The list of errors $this->_errors = array(); // The list of default values $this->_defaults = array(); // Some static HTML things $this->_htmlRequiredStart = ''; // Check default translations if (!isset($GLOBALS['t']['form_required'])) { $GLOBALS['t']['form_required'] = '(required)'; } if (!isset($GLOBALS['t']['form_error'])) { $GLOBALS['t']['form_error'] = 'Error: '; } $this->_htmlRequiredEnd = ' <font color="red">' . t('form_required') . '</font>'; $this->_htmlErrorStart = '<font color="red">' . t('form_error'); $this->_htmlErrorEnd = '</font>'; $this->_requiredNote = ''; // Check for post or get variables if ($this->_method == 'get') { $this->_formVars = $_GET; } else { $this->_formVars = $_POST; } // Add the standard elements $this->registerElement('bbtextarea', 'YDFormElement_BBTextArea', 'YDFormElement_BBTextArea.php'); $this->registerElement('button', 'YDFormElement_Button', 'YDFormElement_Button.php'); $this->registerElement('checkbox', 'YDFormElement_Checkbox', 'YDFormElement_Checkbox.php'); $this->registerElement('checkboxgroup', 'YDFormElement_CheckboxGroup', 'YDFormElement_CheckboxGroup.php'); $this->registerElement('date', 'YDFormElement_Date', 'YDFormElement_Date.php'); $this->registerElement('dateselect', 'YDFormElement_DateSelect', 'YDFormElement_DateSelect.php'); $this->registerElement('datetimeselect', 'YDFormElement_DateTimeSelect', 'YDFormElement_DateTimeSelect.php'); $this->registerElement('timeselect', 'YDFormElement_TimeSelect', 'YDFormElement_TimeSelect.php'); $this->registerElement('file', 'YDFormElement_File', 'YDFormElement_File.php'); $this->registerElement('hidden', 'YDFormElement_Hidden', 'YDFormElement_Hidden.php'); $this->registerElement('image', 'YDFormElement_Image', 'YDFormElement_Image.php'); $this->registerElement('password', 'YDFormElement_Password', 'YDFormElement_Password.php'); $this->registerElement('radio', 'YDFormElement_Radio', 'YDFormElement_Radio.php'); $this->registerElement('reset', 'YDFormElement_Reset', 'YDFormElement_Reset.php'); $this->registerElement('select', 'YDFormElement_Select', 'YDFormElement_Select.php'); $this->registerElement('selectimage', 'YDFormElement_SelectImage', 'YDFormElement_SelectImage.php'); $this->registerElement('submit', 'YDFormElement_Submit', 'YDFormElement_Submit.php'); $this->registerElement('text', 'YDFormElement_Text', 'YDFormElement_Text.php'); $this->registerElement('textarea', 'YDFormElement_TextArea', 'YDFormElement_TextArea.php'); $this->registerElement('textareacounter', 'YDFormElement_TextAreaCounter', 'YDFormElement_TextAreaCounter.php'); $this->registerElement('span', 'YDFormElement_Span', 'YDFormElement_Span.php'); $this->registerElement('img', 'YDFormElement_Img', 'YDFormElement_Img.php'); $this->registerElement('link', 'YDFormElement_Link', 'YDFormElement_Link.php'); $this->registerElement('div', 'YDFormElement_Div', 'YDFormElement_Div.php'); $this->registerElement('autocompleter', 'YDFormElement_Autocompleter', 'YDFormElement_Autocompleter.php'); $this->registerElement('switchmenu', 'YDFormElement_SwitchMenu', 'YDFormElement_SwitchMenu.php'); $this->registerElement('grid', 'YDFormElement_Grid', 'YDFormElement_Grid.php'); $this->registerElement('captcha', 'YDFormElement_Captcha', 'YDFormElement_Captcha.php'); $this->registerElement('timezone', 'YDFormElement_Timezone', 'YDFormElement_Timezone.php'); // Add the rules $this->registerRule('value', array('YDValidateRules', 'value'), 'YDValidateRules.php'); $this->registerRule('required', array('YDValidateRules', 'required'), 'YDValidateRules.php'); $this->registerRule('maxlength', array('YDValidateRules', 'maxlength'), 'YDValidateRules.php'); $this->registerRule('minlength', array('YDValidateRules', 'minlength'), 'YDValidateRules.php'); $this->registerRule('rangelength', array('YDValidateRules', 'rangelength'), 'YDValidateRules.php'); $this->registerRule('regex', array('YDValidateRules', 'regex'), 'YDValidateRules.php'); $this->registerRule('email', array('YDValidateRules', 'email'), 'YDValidateRules.php'); $this->registerRule('not_email', array('YDValidateRules', 'not_email'), 'YDValidateRules.php'); $this->registerRule('ip', array('YDValidateRules', 'ip'), 'YDValidateRules.php'); $this->registerRule('lettersonly', array('YDValidateRules', 'lettersonly'), 'YDValidateRules.php'); $this->registerRule('character', array('YDValidateRules', 'character'), 'YDValidateRules.php'); $this->registerRule('alphanumeric', array('YDValidateRules', 'alphanumeric'), 'YDValidateRules.php'); $this->registerRule('numeric', array('YDValidateRules', 'numeric'), 'YDValidateRules.php'); $this->registerRule('digit', array('YDValidateRules', 'digit'), 'YDValidateRules.php'); $this->registerRule('nopunctuation', array('YDValidateRules', 'nopunctuation'), 'YDValidateRules.php'); $this->registerRule('nonzero', array('YDValidateRules', 'nonzero'), 'YDValidateRules.php'); $this->registerRule('exact', array('YDValidateRules', 'exact'), 'YDValidateRules.php'); $this->registerRule('in_array', array('YDValidateRules', 'in_array'), 'YDValidateRules.php'); $this->registerRule('not_in_array', array('YDValidateRules', 'not_in_array'), 'YDValidateRules.php'); $this->registerRule('i_in_array', array('YDValidateRules', 'i_in_array'), 'YDValidateRules.php'); $this->registerRule('i_not_in_array', array('YDValidateRules', 'i_not_in_array'), 'YDValidateRules.php'); $this->registerRule('maxwords', array('YDValidateRules', 'maxwords'), 'YDValidateRules.php'); $this->registerRule('minwords', array('YDValidateRules', 'minwords'), 'YDValidateRules.php'); $this->registerRule('callback', array('YDValidateRules', 'callback'), 'YDValidateRules.php'); $this->registerRule('uploadedfile', array('YDValidateRules', 'uploadedfile'), 'YDValidateRules.php'); $this->registerRule('maxfilesize', array('YDValidateRules', 'maxfilesize'), 'YDValidateRules.php'); $this->registerRule('mimetype', array('YDValidateRules', 'mimetype'), 'YDValidateRules.php'); $this->registerRule('filename', array('YDValidateRules', 'filename'), 'YDValidateRules.php'); $this->registerRule('extension', array('YDValidateRules', 'extension'), 'YDValidateRules.php'); $this->registerRule('date', array('YDValidateRules', 'date'), 'YDValidateRules.php'); $this->registerRule('time', array('YDValidateRules', 'time'), 'YDValidateRules.php'); $this->registerRule('datetime', array('YDValidateRules', 'datetime'), 'YDValidateRules.php'); $this->registerRule('minlength_escape', array('YDValidateRules', 'minlength_escape'), 'YDValidateRules.php'); $this->registerRule('maxlength_escape', array('YDValidateRules', 'maxlength_escape'), 'YDValidateRules.php'); $this->registerRule('rangelength_escape', array('YDValidateRules', 'rangelength_escape'), 'YDValidateRules.php'); $this->registerRule('httpurl', array('YDValidateRules', 'httpurl'), 'YDValidateRules.php'); $this->registerRule('maxhyperlinks', array('YDValidateRules', 'maxhyperlinks'), 'YDValidateRules.php'); $this->registerRule('captcha', array('YDValidateRules', 'captcha'), 'YDValidateRules.php'); $this->registerRule('timezone', array('YDValidateRules', 'timezone'), 'YDValidateRules.php'); // Add the filters $this->registerFilter('trim', 'trim'); $this->registerFilter('lower', 'strtolower'); $this->registerFilter('upper', 'strtoupper'); $this->registerFilter('utf8_decode', 'utf8_decode'); $this->registerFilter('strip_html', 'strip_tags'); $this->registerFilter('safe_html', 'YDFormFilter_safe_html'); $this->registerFilter('dateformat', 'YDFormFilter_dateformat'); // Add the renderers $this->registerRenderer('array', 'YDFormRenderer_array', 'YDFormRenderer_array.php'); $this->registerRenderer('html', 'YDFormRenderer_html', 'YDFormRenderer_html.php'); $this->registerRenderer('xml', 'YDFormRenderer_xml', 'YDFormRenderer_xml.php'); // Clean the action URL $url = new YDUrl($this->_action); $this->_action = $url->getUri(); }
function actionDefault() { // Create the URL object $url = new YDUrl('http://www.yellowduck.be/directory/test/index.xml'); // The different parts echo '<br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>isDirectory( test ): ' . var_export($url->isDirectory('test'), 1); echo '<br>isDirectory( xx ): ' . var_export($url->isDirectory('xx'), 1); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Create the URL object $url = new YDUrl('http://pieter@www.yellowduck.be/directory/test/index?x[]=22&x[]=23#22'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Create the URL object $url = new YDUrl('http://*****:*****@www.yellowduck.be:8080/directory/test/?do=x&id=1#10'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); echo '<br>Getting query variable do: ' . $url->getQueryVar('do'); echo '<br>Setting query variable do to y: ' . $url->setQueryVar('do', 'y'); echo '<br>New URL: ' . $url->getUrl(); echo '<br>Deleting query variable do: ' . $url->deleteQueryVar('do'); echo '<br>New URL: ' . $url->getUrl(); // Create the URL object $url = new YDUrl('http://ydframework.berlios.de/ydf2_changelog_summary.xml'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Test the getPathSubdirectories function $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubdirectories('ydf2'), "getPathSubdirectories('ydf2')"); YDDebugUtil::dump($url->getPathSubdirectories('forum'), "getPathSubdirectories('forum')"); YDDebugUtil::dump($url->getPathSubdirectories('test'), "getPathSubdirectories('test')"); $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubdirectories('ydf2'), "getPathSubdirectories('ydf2')"); YDDebugUtil::dump($url->getPathSubdirectories('forum'), "getPathSubdirectories('forum')"); YDDebugUtil::dump($url->getPathSubdirectories('test'), "getPathSubdirectories('test')"); // Test the getPathSubsegments function $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubsegments('ydf2'), "getPathSubsegments('ydf2')"); YDDebugUtil::dump($url->getPathSubsegments('forum'), "getPathSubsegments('forum')"); YDDebugUtil::dump($url->getPathSubsegments('test'), "getPathSubsegments('test')"); $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubsegments('ydf2'), "getPathSubsegments('ydf2')"); YDDebugUtil::dump($url->getPathSubsegments('forum'), "getPathSubsegments('forum')"); YDDebugUtil::dump($url->getPathSubsegments('test'), "getPathSubsegments('test')"); // Do some more testing $x = 'http://localhostexamples/form2.php?form2_tmp%5Bday%5D=1&form2_tmp%5Bmonth%5D=1&form2_tmp%5Byear%5D=2000&do=test'; $url = new YDUrl($x); YDDebugUtil::dump($url, $x); YDDebugUtil::dump($url->getUrl(), 'Original url'); // Do some more testing $x = 'http://localhostexamples/form2.php?form2_tmp%5Bday%5D=1&form2_tmp%5Bmonth%5D=1&form2_tmp%5Byear%5D=2000&do=test'; $url = new YDUrl($x); YDDebugUtil::dump($url, $x); YDDebugUtil::dump($url->getUrl(), 'Original url'); // Get the contents $url = new YDUrl('http://ydframework.berlios.de/ydf2_changelog_summary.xml'); YDDebugUtil::dump($url->getContents(), 'URL contents'); }
function actionDefault() { // Create the URL object $url = new YDUrl('http://www.yellowduck.be/directory/test/index.xml'); // The different parts echo '<br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>isDirectory( test ): ' . var_export($url->isDirectory('test'), 1); echo '<br>isDirectory( xx ): ' . var_export($url->isDirectory('xx'), 1); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Create the URL object $url = new YDUrl('http://pieter@www.yellowduck.be/directory/test/index?x[]=22&x[]=23#22'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Create the URL object $url = new YDUrl('http://*****:*****@www.yellowduck.be:8080/directory/test/?do=x&id=1#10'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); echo '<br>Getting query variable do: ' . $url->getQueryVar('do'); echo '<br>Setting query variable do to y: ' . $url->setQueryVar('do', 'y'); echo '<br>New URL: ' . $url->getUrl(); echo '<br>Deleting query variable do: ' . $url->deleteQueryVar('do'); echo '<br>New URL: ' . $url->getUrl(); // Create the URL object $url = new YDUrl('http://www.yellowduck.be/rss.xml'); // The different parts echo '<br><br>Original URL: ' . $url->_url; echo '<br>URL: ' . $url->getUrl(); echo '<br>URI: ' . $url->getUri(); echo '<br>Scheme: ' . $url->getScheme(); echo '<br>Host: ' . $url->getHost(); echo '<br>Port: ' . $url->getPort(); echo '<br>User: '******'<br>Password: '******'<br>Path: ' . $url->getPath(); echo '<br>Path segments: ' . implode(', ', $url->getPathSegments()); echo '<br>Path directories: ' . implode(', ', $url->getPathDirectories()); echo '<br>Query: ' . var_export($url->getQuery(), 1); echo '<br>Fragment: ' . $url->getFragment(); // Test the getPathSubdirectories function $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubdirectories('ydf2'), "getPathSubdirectories('ydf2')"); YDDebugUtil::dump($url->getPathSubdirectories('forum'), "getPathSubdirectories('forum')"); YDDebugUtil::dump($url->getPathSubdirectories('test'), "getPathSubdirectories('test')"); $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubdirectories('ydf2'), "getPathSubdirectories('ydf2')"); YDDebugUtil::dump($url->getPathSubdirectories('forum'), "getPathSubdirectories('forum')"); YDDebugUtil::dump($url->getPathSubdirectories('test'), "getPathSubdirectories('test')"); // Test the getPathSubsegments function $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubsegments('ydf2'), "getPathSubsegments('ydf2')"); YDDebugUtil::dump($url->getPathSubsegments('forum'), "getPathSubsegments('forum')"); YDDebugUtil::dump($url->getPathSubsegments('test'), "getPathSubsegments('test')"); $url = new YDUrl('http://www.yellowduck.be/ydf2/forum/ydf2/forum/cool.html'); YDDebugUtil::dump($url->getUrl()); YDDebugUtil::dump($url->getPathSubsegments('ydf2'), "getPathSubsegments('ydf2')"); YDDebugUtil::dump($url->getPathSubsegments('forum'), "getPathSubsegments('forum')"); YDDebugUtil::dump($url->getPathSubsegments('test'), "getPathSubsegments('test')"); // Get the contents $url = new YDUrl('http://www.yellowduck.be/rss.xml'); YDDebugUtil::dump($url->getContents(), 'URL contents'); }