/** * Convert an array of details into a form element. * @param String $fieldName The name of the form element * @param Array $fieldDetails The list of details for the form element. */ protected function createElementObject($fieldName, $fieldDetails) { // Extract fields $label = $this->formObj->getArrayValue($fieldDetails, 'label'); $type = $this->formObj->getArrayValue($fieldDetails, 'type'); // Required 'true' or true are valid $required = $this->formObj->getArrayValue($fieldDetails, 'required'); $required = $required == 'true' || $required == '1'; // Start creating form element if anything other than a break. $elem = false; if ($type != 'break') { $elem = new FormElement($fieldName, $label, $required); } // Handle specific types switch ($type) { // Text Area case 'textarea': $rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0; if ($rows == 0) { $rows = 5; } $elem->setTypeAsTextArea($rows, 70); break; // Select/Dropdown // Select/Dropdown case 'select': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsComboBox($options); break; // Radio Buttons // Radio Buttons case 'radio': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsRadioButtons($options); break; // Checkbox // Checkbox case 'checkbox': $label = false; if (isset($fieldDetails['extralabel'])) { $label = $fieldDetails['extralabel']; } $elem->setTypeAsCheckbox($label); break; // Checkbox List // Checkbox List case 'checkboxlist': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsCheckboxList($options); break; // Merged Fields - process each sub element // Merged Fields - process each sub element case 'merge': $elementList = array(); if (!empty($fieldDetails['merge'])) { foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) { $elementList[] = $this->createElementObject($fieldName, $fieldDetails); } } $elem->setTypeAsMergedElements($elementList); break; // File upload // File upload case 'uploadfile': $elem->setTypeAsUploadFile($this->formObj->getArrayValue($fieldDetails, 'show_existing'), $this->formObj->getArrayValue($fieldDetails, 'valid_if_value')); break; // Custom HTML // Custom HTML case 'custom': $elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html')); break; // Hidden field // Hidden field case 'hidden': $elem->setTypeAsHidden(); break; // Section break // Section break case 'break': $this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html')); break; // Text box // Text box default: break; } // Add optional fields if ($type != 'break') { // Element description if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) { $elem->description = $desc; } // Extra CSS if ($cssclass = $this->formObj->getArrayValue($fieldDetails, 'cssclass')) { $elem->cssclass = $cssclass; } // Add extra HTML if provided. $extraHTML = $this->formObj->getArrayValue($fieldDetails, 'extrahtml'); if ($extraHTML) { $elem->afterFormElementHTML = $extraHTML; } // Add custom error message if there is one $elem->errorMessage = $this->formObj->getArrayValue($fieldDetails, 'errormsg'); // Validation rules if (isset($fieldDetails['validate']) && is_array($fieldDetails['validate'])) { // Is it a custom function? If so, get the function name. if ($this->formObj->getArrayValue($fieldDetails['validate'], 'type') == 'function') { $elem->validationFn = $this->formObj->getArrayValue($fieldDetails['validate'], 'fname'); $elem->errorMessage = $this->formObj->getArrayValue($fieldDetails['validate'], 'error'); } else { $elem->setValidationRules($fieldDetails['validate']); } } // See if there are any suffix items? If so, parse them. // See wiki for documentation on how to structure this. if (!empty($fieldDetails['suffix_subitems'])) { $suffixItems = array(); // suffix_subitems contains a list of 'position' => array(fieldName => fieldDetails) foreach ($fieldDetails['suffix_subitems'] as $position => $elementDetails) { $suffixItems[$position] = array(); // Need to process each field now we know the position. foreach ($elementDetails as $fieldName => $fieldDetails) { // Add the position of this item (in order), with the object for this element. $suffixItems[$position][] = $this->createElementObject($fieldName, $fieldDetails); } } // Update the form element with the subitems $elem->setSuffixItems($suffixItems); } } return $elem; }
/** * Show only the settings relating to layout of the portfolio. */ function WPPortfolio_showLayoutSettingsPage() { ?> <div class="wrap"> <div id="icon-themes" class="icon32"> <br/> </div> <h2>WP Portfolio - Layout Settings</h2> <?php // Get all the options from the database $settingsList = WPPortfolio_getSettingList(false, true); // Get all the options from the database for the form $settings = array(); foreach ($settingsList as $settingName => $settingDefault) { $settings[$settingName] = stripslashes(get_option('WPPortfolio_' . $settingName)); } // If we don't have the version in the settings, we're not installed if (!get_option('WPPortfolio_version')) { WPPortfolio_showMessage(__('No WP Portfolio settings were found, so it appears that the plugin has been uninstalled. Please <b>deactivate</b> and then <b>activate</b> the WP Portfolio plugin again to fix this.', 'wp-portfolio'), true); return false; } // Check if updated data. if (isset($_POST) && isset($_POST['update'])) { // Copy settings from $_POST $settings = array(); foreach ($settingsList as $settingName => $settingDefault) { $settings[$settingName] = stripslashes(trim(WPPortfolio_getArrayValue($_POST, $settingName))); } // Save settings foreach ($settingsList as $settingName => $settingDefault) { update_option('WPPortfolio_' . $settingName, $settings[$settingName]); } WPPortfolio_showMessage(); } $form = new FormBuilder(); $formElem = new FormElement("setting_template_website", __("Website HTML Template", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_website']); $formElem->description = '• ' . __('This is the template used to render each of the websites.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-layout">Portfolio Layout Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION); $formElem->setTypeAsTextArea(8, 70); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_group", __("Group HTML Template", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_group']); $formElem->description = '• ' . __('This is the template used to render each of the groups that the websites belong to.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-layout">Portfolio Layout Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION); $formElem->setTypeAsTextArea(3, 70); $form->addFormElement($formElem); $form->addBreak('settings_paging', '<div class="settings-spacer"> </div><h2>' . __('Portfolio Paging Settings', 'wp-portfolio') . '</h2>'); $formElem = new FormElement("setting_template_paging", __("Paging HTML Template", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_paging']); $formElem->description = '• ' . __('This is the template used to render the paging for the thumbnails.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-paging">Portfolio Paging Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION); $formElem->setTypeAsTextArea(3, 70); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_paging_previous", __("Text for 'Previous' link", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_paging_previous']); $formElem->description = __('The text to use for the \'Previous\' page link used in the thumbnail paging.', 'wp-portfolio'); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_paging_next", __("Text for 'Next' link", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_paging_next']); $formElem->description = __('The text to use for the \'Next\' page link used in the thumbnail paging.', 'wp-portfolio'); $form->addFormElement($formElem); $form->addBreak('settings_css', '<div class="settings-spacer"> </div><h2>' . __('Portfolio Stylesheet (CSS) Settings', 'wp-portfolio') . '</h2>'); // Enable/Disable CSS mode $formElem = new FormElement("setting_disable_plugin_css", __("Disable Plugin CSS", 'wp-portfolio')); $formElem->value = $settings['setting_disable_plugin_css']; $formElem->setTypeAsCheckbox(__("If ticked, don't use the WP Portfolio CSS below.", 'wp-portfolio')); $formElem->description = '• ' . __('Allows you to switch off the default CSS so that you can use CSS in your template CSS file.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('<strong>Advanced Tip:</strong> Once you\'re happy with the styles, you should really move all the CSS below into your template %s. This is so that visitor browsers can cache the stylesheet and reduce loading times. Any CSS placed here will be injected into the template <head> tag, which is not the most efficient method of delivering CSS.', 'wp-portfolio'), '<code>style.css</code>'); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_css", __("Template CSS", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_css']); $formElem->description = __('This is the CSS code used to style the portfolio.', 'wp-portfolio'); $formElem->setTypeAsTextArea(10, 70); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_css_paging", __("Paging CSS", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_css_paging']); $formElem->description = __('This is the CSS code used to style the paging area if you are showing your portfolio on several pages.', 'wp-portfolio'); $formElem->setTypeAsTextArea(6, 70); $form->addFormElement($formElem); $formElem = new FormElement("setting_template_css_widget", __("Widget CSS", 'wp-portfolio')); $formElem->value = htmlentities($settings['setting_template_css_widget']); $formElem->description = __('This is the CSS code used to style the websites in the widget area.', 'wp-portfolio'); $formElem->setTypeAsTextArea(6, 70); $form->addFormElement($formElem); echo $form->toString(); ?> </div> <?php }
/** * Convert an array of details into a form element. * @param String $fieldName The name of the form element * @param Array $fieldDetails The list of details for the form element. */ protected function createElementObject($fieldName, $fieldDetails) { // Extract fields $label = $this->formObj->getArrayValue($fieldDetails, 'label'); $type = $this->formObj->getArrayValue($fieldDetails, 'type'); // Required 'true' or true are valid $required = $this->formObj->getArrayValue($fieldDetails, 'required'); $required = $required == 'true' || $required == '1'; // Start creating form element if anything other than a break. $elem = false; if ($type != 'break') { $elem = new FormElement($fieldName, $label, $required); } // Handle specific types switch ($type) { // Text Area case 'textarea': $rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0; if ($rows == 0) { $rows = 5; } $elem->setTypeAsTextArea($rows, 70); break; // Select/Dropdown // Select/Dropdown case 'select': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsComboBox($options); break; // Radio Buttons // Radio Buttons case 'radio': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsRadioButtons($options); break; // Checkbox // Checkbox case 'checkbox': $label = false; if (isset($fieldDetails['extralabel'])) { $label = $fieldDetails['extralabel']; } $elem->setTypeAsCheckbox($label); break; // Checkbox List // Checkbox List case 'checkboxlist': $options = false; if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) { $options = $fieldDetails['data']; } $elem->setTypeAsCheckboxList($options); break; // Merged Fields - process each sub element // Merged Fields - process each sub element case 'merge': $elementList = array(); if (!empty($fieldDetails['merge'])) { foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) { $elementList[] = $this->createElementObject($fieldName, $fieldDetails); } } $elem->setTypeAsMergedElements($elementList); break; // Custom HTML // Custom HTML case 'custom': $elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html')); break; // Hidden field // Hidden field case 'hidden': $elem->setTypeAsHidden(); break; // Section break // Section break case 'break': $this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html')); break; // Text box // Text box default: break; } // Add optional fields if ($type != 'break') { // Element description if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) { $elem->description = $desc; } // Extra CSS if ($cssclass = $this->formObj->getArrayValue($fieldDetails, 'cssclass')) { $elem->cssclass = $cssclass; } // Add extra HTML if provided. $extraHTML = $this->formObj->getArrayValue($fieldDetails, 'extrahtml'); if ($extraHTML) { $elem->afterFormElementHTML = $extraHTML; } // Validation rules if (isset($fieldDetails['validate']) && is_array($fieldDetails['validate'])) { // Is it a custom function? If so, get the function name. if ($this->formObj->getArrayValue($fieldDetails['validate'], 'type') == 'function') { $elem->validationFn = $this->formObj->getArrayValue($fieldDetails['validate'], 'fname'); $elem->errorMessage = $this->formObj->getArrayValue($fieldDetails['validate'], 'error'); } else { $elem->setValidationRules($fieldDetails['validate']); } } } return $elem; }