/** * 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 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; }
/** * 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; }