function display($tpl = null) { // Get data from the model require_once JPATH_COMPONENT . '/models/ajaxvote.php'; $model = new AcepollsModelAjaxvote(); $vote = $model->getVoted(); $data = $model->getData(); $total = $model->getTotal(); $poll_id = JRequest::getInt('id', 0, 'post'); // create root node $xml = new JXMLElement('<poll></poll>'); $xml->addAttribute('id', $poll_id); //get total votes $sum = 0; foreach ($data as $row) { $sum += $row->votes; } $number_voters = 0; $options =& $xml->addChild('options'); for ($i = 0; $i < $total; $i++) { $option =& $options->addChild('option'); $option->addAttribute('id', $data[$i]->id); $option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum)); $option->addAttribute('color', $data[$i]->color); $option->addChild('text', $data[$i]->text); $number_voters += $data[$i]->votes; } $xml->addChild('voters', $number_voters); $this->assign('xml', $xml->asFormattedXML()); $this->setLayout('raw'); parent::display($tpl); }
public function getField($type, $attributes = array(), $field_value = '') { static $types = null; $defaults = array('name' => '', 'id' => ''); if (!$types) { jimport('joomla.form.helper'); $types = array(); } if (!in_array($type, $types)) { JFormHelper::loadFieldClass($type); } try { $attributes = array_merge($defaults, $attributes); $xml = new JXMLElement('<?xml version="1.0" encoding="utf-8"?><field />'); foreach ($attributes as $key => $value) { if ('_options' == $key) { foreach ($value as $_opt_value) { $xml->addChild('option', $_opt_value->text)->addAttribute('value', $_opt_value->value); } continue; } $xml->addAttribute($key, $value); } $class = 'JFormField' . $type; $field = new $class(); $field->setup($xml, $field_value); return $field; } catch (Exception $e) { return false; } }
public function getCategories($config = array('showlist_id' => 0)) { $objJSNImages = JSNISFactory::getObj('classes.jsn_is_images'); $syncAlbum = $objJSNImages->getSyncAlbumsByShowlistID($config['showlist_id']); $syncAlbum = count($syncAlbum) > 0 ? $syncAlbum : array(); $path = JPath::clean(JPATH_ROOT . DS . $this->_folder); if (!is_dir($path)) { return false; } $xmlObj = new JXMLElement('<node></node>'); $xmlObj->addAttribute('label', 'images'); $xmlObj->addAttribute('data', 'images'); $xmlObj->addAttribute('type', 'root'); $this->drawTree($xmlObj, $path, $syncAlbum); return $xmlObj->asFormattedXML(); }
/** * Method to attach a JForm object to the field. * * @param object &$element The JXmlElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * * @return boolean True on success. * * @since 11.1 */ public function setup(&$element, $value, $group = null) { // Make sure there is a valid JFormField XML element. if (!$element instanceof JXMLElement || (string) $element->getName() != 'field') { return false; } // Reset the input and label values. $this->input = null; $this->label = null; // Set the XML element object. $this->element = $element; // Get some important attributes from the form field element. $class = (string) $element['class']; $id = (string) $element['id']; $multiple = (string) $element['multiple']; $name = (string) $element['name']; $required = (string) $element['required']; // Set the required and validation options. $this->required = $required == 'true' || $required == 'required' || $required == '1'; $this->validate = (string) $element['validate']; // Add the required class if the field is required. if ($this->required) { if ($class) { if (strpos($class, 'required') === false) { $this->element['class'] = $class . ' required'; } } else { $this->element->addAttribute('class', 'required'); } } // Set the multiple values option. $this->multiple = $multiple == 'true' || $multiple == 'multiple'; // Allow for field classes to force the multiple values option. if (isset($this->forceMultiple)) { $this->multiple = (bool) $this->forceMultiple; } // Set the field description text. $this->description = (string) $element['description']; // Set the visibility. $this->hidden = (string) $element['type'] == 'hidden' || (string) $element['hidden'] == 'true'; // Determine whether to translate the field label and/or description. $this->translateLabel = !((string) $this->element['translate_label'] == 'false' || (string) $this->element['translate_label'] == '0'); $this->translateDescription = !((string) $this->element['translate_description'] == 'false' || (string) $this->element['translate_description'] == '0'); // Set the group of the field. $this->group = $group; // Set the field name and id. $this->fieldname = $this->getFieldName($name); $this->name = $this->getName($this->fieldname); $this->id = $this->getId($id, $this->fieldname); // Set the field default value. $this->value = $value; // Set the CSS class of field label $this->labelClass = (string) $element['labelclass']; return true; }
/** * $type, $domId, $value, $options = array(), $formName = null, $disabled = false */ public static function element() { list($type, $domId, $value, $options) = func_get_args(); $options = (array) $options; // Load the JFormField object for the field. JFormHelper::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'fields'); $field = JFormHelper::loadFieldType($type, true); // If the object could not be loaded, get a text field object. if ($field === false) { throw new Exception('Cannot load field type ' . $type); } $element = new JXMLElement('<field></field>'); $element->addAttribute('id', $domId); if (!empty($options)) { foreach ($options as $name => $val) { $element->addAttribute($name, $val); } } if (!$field->setup($element, $value, null)) { throw new Exception('Cannot setup field ' . $type); } return $field->input; }
/** * Method to get the list of possible permission action names for the form field. * * @param JXMLElement $element The JXMLElement object representing the <field /> tag for the * form field object. * * @return array A list of permission action names from the form field element definition. * * @since 11.1 */ protected function getFieldActions($element) { // Initialise variables. $actions = array(); // Initialise some field attributes. $section = $element['section'] ? (string) $element['section'] : ''; $component = $element['component'] ? (string) $element['component'] : ''; // Get the asset actions for the element. $elActions = JAccess::getActions($component, $section); // Iterate over the asset actions and add to the actions. foreach ($elActions as $item) { $actions[] = $item->name; } // Iterate over the children and add to the actions. foreach ($element->children() as $el) { if ($el->getName() == 'action') { $actions[] = (string) $el['name']; } } return $actions; }
/** * Method to parse through a files element of the installation manifest and take appropriate * action. * * @access public * @param JXMLElement $element The xml node to process * @param int $cid Application ID of application to install to * @param Array $oldFiles List of old files (JXMLElement's) * @param Array $oldMD5 List of old MD5 sums (indexed by filename with value as MD5) * @return boolean True on success * @since 1.5 */ function parseFiles($element, $cid = 0, $oldFiles = null, $oldMD5 = null) { // Get the array of file nodes to process; we checked this had children above if (!$element || !count($element->children())) { // Either the tag does not exist or has no children (hence no files to process) therefore we return zero files processed. return 0; } // Initialise variables. $copyfiles = array(); // Get the client info jimport('joomla.application.helper'); $client = JApplicationHelper::getClientInfo($cid); /* * Here we set the folder we are going to remove the files from. */ if ($client) { $pathname = 'extension_' . $client->name; $destination = $this->getPath($pathname); } else { $pathname = 'extension_root'; $destination = $this->getPath($pathname); } /* * Here we set the folder we are going to copy the files from. * * Does the element have a folder attribute? * * If so this indicates that the files are in a subdirectory of the source * folder and we should append the folder attribute to the source path when * copying files. */ $folder = (string) $element->attributes()->folder; if ($folder && file_exists($this->getPath('source') . DS . $folder)) { $source = $this->getPath('source') . DS . $folder; } else { $source = $this->getPath('source'); } // Process each file in the $files array (children of $tagName). foreach ($element->children() as $file) { $path['src'] = $source . DS . $file; $path['dest'] = $destination . DS . $file; // Is this path a file or folder? $path['type'] = $file->getName() == 'folder' ? 'folder' : 'file'; /* * Before we can add a file to the copyfiles array we need to ensure * that the folder we are copying our file to exits and if it doesn't, * we need to create it. */ if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); if (!JFolder::create($newdir)) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir)); return false; } } // Add the file to the copyfiles array $copyfiles[] = $path; } return $this->copyFiles($copyfiles); }
/** * @param $form * @param $data * * @return mixed */ protected function processModuleConfig($form, $data) { // check the module to see if it has a rokconfig.xml $module_type = $this->getModuleType($data); $app = JFactory::getApplication(); $container = RokCommon_Service::getContainer(); $options = new RokCommon_Options(); $section = new RokCommon_Options_Section('roksprocket_module', 'module_config.xml'); $section->addPath(JPATH_SITE . '/components/com_roksprocket/'); $section->addPath($container['roksprocket.template.override.path']); $options->addSection($section); $provider = null; $layout = null; if (empty($data) && $app->input->get('jform', false, 'array') !== false) { $data = $app->input->get('jform', false, 'array'); $provider = $data['params']['provider']; $layout = $data['params']['layout']; } elseif (isset($data->params['provider']) && isset($data->params['layout'])) { $provider = $data->params['provider']; $layout = $data->params['layout']; } if (!empty($data) && isset($provider) && isset($layout)) { // load up the Providers $provider_key = "roksprocket.providers.registered.{$provider}"; if ($container->hasParameter($provider_key)) { $providerinfo = $container->getParameter($provider_key); $provider_class = $container[sprintf('roksprocket.providers.registered.%s.class', $provider)]; $available = call_user_func(array($provider_class, 'isAvailable')); if ($available) { $section = new RokCommon_Options_Section('provider_' . $provider, $providerinfo->optionfile); $section->addPath($providerinfo->path); $options->addSection($section); } } // load up the layouts $layout_key = "roksprocket.layouts.{$layout}"; if ($container->hasParameter($layout_key)) { $layoutinfo = $container->getParameter($layout_key); $section = new RokCommon_Options_Section('layout_' . $layout, $layoutinfo->options->file); foreach ($layoutinfo->paths as $layoutpath) { $section->addPath($layoutpath); } $options->addSection($section); } } $rcform = new RokCommon_Config_Form($form); $xml = $options->getJoinedXml(); $jxml = new JXMLElement($xml->asXML()); $fieldsets = $jxml->xpath('/config/fields[@name = "params"]/fieldset'); foreach ($fieldsets as $fieldset) { $overwrite = (string) $fieldset['overwrite'] == 'true' ? true : false; $rcform->load($fieldset, $overwrite, '/config'); } JForm::addFieldPath(JPATH_SITE . '/components/com_roksprocket/fields'); }
/** * @param object $form A form object. * @param mixed $data The data expected for the form. * * @return void * @since 1.6 * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { // Initialise variables. $link = $this->getState('item.link'); $type = $this->getState('item.type'); $formFile = false; // Initialise form with component view params if available. if ($type == 'component') { $link = htmlspecialchars_decode($link); // Parse the link arguments. $args = array(); parse_str(parse_url(htmlspecialchars_decode($link), PHP_URL_QUERY), $args); // Confirm that the option is defined. $option = ''; $base = ''; if (isset($args['option'])) { // The option determines the base path to work with. $option = $args['option']; $base = JPATH_SITE . '/components/' . $option; } // Confirm a view is defined. $formFile = false; if (isset($args['view'])) { $view = $args['view']; // Determine the layout to search for. if (isset($args['layout'])) { $layout = $args['layout']; } else { $layout = 'default'; } $formFile = false; // Check for the layout XML file. Use standard xml file if it exists. $path = JPath::clean($base . '/views/' . $view . '/tmpl/' . $layout . '.xml'); if (JFile::exists($path)) { $formFile = $path; } // if custom layout, get the xml file from the template folder // template folder is first part of file name -- template:folder if (!$formFile && strpos($layout, ':') > 0) { $temp = explode(':', $layout); $templatePath = JPATH::clean(JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $option . '/' . $view . '/' . $temp[1] . '.xml'); if (JFile::exists($templatePath)) { $formFile = $templatePath; } } } //Now check for a view manifest file if (!$formFile) { if (isset($view) && JFile::exists($path = JPath::clean($base . '/views/' . $view . '/metadata.xml'))) { $formFile = $path; } else { //Now check for a component manifest file $path = JPath::clean($base . '/metadata.xml'); if (JFile::exists($path)) { $formFile = $path; } } } } if ($formFile) { // If an XML file was found in the component, load it first. // We need to qualify the full path to avoid collisions with component file names. if ($form->loadFile($formFile, true, '/metadata') == false) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Attempt to load the xml file. if (!($xml = simplexml_load_file($formFile))) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Get the help data from the XML file if present. $help = $xml->xpath('/metadata/layout/help'); if (!empty($help)) { $helpKey = trim((string) $help[0]['key']); $helpURL = trim((string) $help[0]['url']); $helpLoc = trim((string) $help[0]['local']); $this->helpKey = $helpKey ? $helpKey : $this->helpKey; $this->helpURL = $helpURL ? $helpURL : $this->helpURL; $this->helpLocal = $helpLoc == 'true' || $helpLoc == '1' || $helpLoc == 'local' ? true : false; } } // Now load the component params. // TODO: Work out why 'fixing' this breaks JForm if ($isNew = false) { $path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/config.xml'); } else { $path = 'null'; } if (JFile::exists($path)) { // Add the component params last of all to the existing form. if (!$form->load($path, true, '/config')) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } } // Load the specific type file if (!$form->loadFile('item_' . $type, false, false)) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Association menu items if (JFactory::getApplication()->get('menu_associations', 0)) { $languages = JLanguageHelper::getLanguages('lang_code'); $addform = new JXMLElement('<form />'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', 'associations'); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_MENUS_ITEM_ASSOCIATIONS_FIELDSET_DESC'); $add = false; foreach ($languages as $tag => $language) { if ($tag != $data['language']) { $add = true; $field = $fieldset->addChild('field'); $field->addAttribute('name', $tag); $field->addAttribute('type', 'menuitem'); $field->addAttribute('language', $tag); $field->addAttribute('label', $language->title); $field->addAttribute('translate_label', 'false'); $option = $field->addChild('option', 'COM_MENUS_ITEM_FIELD_ASSOCIATION_NO_VALUE'); $option->addAttribute('value', ''); } } if ($add) { $form->load($addform, false); } } // Trigger the default form events. parent::preprocessForm($form, $data); }
/** * Method to parse through a media element of the installation manifest and take appropriate * action. * * @param JXMLElement $element The XML node to process * @param integer $cid Application ID of application to install to * * @return boolean True on success * @since 11.1 */ public function parseMedia($element, $cid = 0) { if (!$element || !count($element->children())) { // Either the tag does not exist or has no children therefore we return zero files processed. return 0; } // Initialise variables. $copyfiles = array(); // Get the client info jimport('joomla.application.helper'); $client = JApplicationHelper::getClientInfo($cid); // Here we set the folder we are going to copy the files to. // Default 'media' Files are copied to the JPATH_BASE/media folder $folder = (string) $element->attributes()->destination ? DS . $element->attributes()->destination : null; $destination = JPath::clean(JPATH_ROOT . DS . 'media' . $folder); // Here we set the folder we are going to copy the files from. // Does the element have a folder attribute? // If so this indicates that the files are in a subdirectory of the source // folder and we should append the folder attribute to the source path when // copying files. $folder = (string) $element->attributes()->folder; if ($folder && file_exists($this->getPath('source') . DS . $folder)) { $source = $this->getPath('source') . DS . $folder; } else { $source = $this->getPath('source'); } // Process each file in the $files array (children of $tagName). foreach ($element->children() as $file) { $path['src'] = $source . DS . $file; $path['dest'] = $destination . DS . $file; // Is this path a file or folder? $path['type'] = $file->getName() == 'folder' ? 'folder' : 'file'; // Before we can add a file to the copyfiles array we need to ensure // that the folder we are copying our file to exits and if it doesn't, // we need to create it. if (basename($path['dest']) != $path['dest']) { $newdir = dirname($path['dest']); if (!JFolder::create($newdir)) { JError::raiseWarning(1, JText::sprintf('JLIB_INSTALLER_ERROR_CREATE_DIRECTORY', $newdir)); return false; } } // Add the file to the copyfiles array $copyfiles[] = $path; } return $this->copyFiles($copyfiles); }
/** * Method to get the field input markup. * * @return string The field input markup. * @since 11.1 */ protected function getInput() { // Initialize variables. $html = array(); // Initialize some field attributes. $class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"'; // get extensions installed $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('element AS value, name AS text, params'); $query->from('#__extensions AS a'); $query->where('type = "component" AND protected = 0 AND enabled = 1'); $query->order('a.name'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // get plan params $id = JRequest::getVar('id'); $query = $db->getQuery(true); $query->select('*'); $query->from('#__jms_plans'); $query->where('id = ' . (int) $id); // Get param values. $db->setQuery($query); $row = $db->loadObject(); $params = new JRegistry(); if (isset($row->params)) { $params->loadString($row->params); } // Start the checkbox field output. $html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; // Build the checkbox field output. $html[] = '<div>'; // make 2 columns for the div $extensions = $options; $cols = 2; $count = count($extensions); if ($count % $cols > 0) { for ($e = 0; $e < $cols - $count % $cols; $e++) { $extensions[] = ' '; } } //print_r($count); $addform = new JXMLElement('<form />'); $fields = $addform->addChild('fields'); $fields->addAttribute('name', 'params'); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); $fieldset->addAttribute('description', 'COM_MENUS_ITEM_ASSOCIATIONS_FIELDSET_DESC'); foreach ($options as $i => $option) { // Initialize some option attributes. $checked = in_array((string) $option->value, (array) $this->value) ? ' checked="checked"' : ''; $class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; $disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; // Initialize some JavaScript option attributes. // onclick="jmsShowComParams('component_name', 'component_name[]') if ($i % $cols == 0) { $html[] = '<div class="jmsblock">'; } $html[] = '<div class="col-' . ($i % $cols + 1) . '">'; $onclick = " onclick=\"jmsShowComParams('" . $option->value . "', '" . $option->value . "');\""; $html[] = '<div class="label-pad">'; $html[] = '<input type="checkbox" id="check_' . $option->value . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . JText::_($option->text) . '</label>'; $html[] = '<div class="clr"></div>'; $html[] = '</div>'; if (!in_array($option->value, $options) && !$checked) { $html[] = '<div id="params_' . $option->value . '" class="jmsblockhide">'; } else { $html[] = '<div id="params_' . $option->value . '" class="jmsblockshow">'; } $html[] = '<div class="jmsblockshow-pad">'; $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">'; $html[] = '<tr>'; $html[] = '<td class="key" align="right" width="100">'; $html[] = JText::_('URL Variable 1:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '1" value="' . $params->get($option->value . '_task1') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '<tr>'; $html[] = '<td class="key" nowrap="" align="right" width="100">'; $html[] = JText::_('Variable Value 1:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '1" value="' . $params->get($option->value . '_value1') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '</table>'; $html[] = '<strong>AND</strong>'; $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">'; $html[] = '<tr>'; $html[] = '<td class="key" align="right" width="100">'; $html[] = JText::_('URL Variable 2:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '2" value="' . $params->get($option->value . '_task2') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '<tr>'; $html[] = '<td class="key" nowrap="" align="right" width="100">'; $html[] = JText::_('Variable Value 2:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '2" value="' . $params->get($option->value . '_value2') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '</table>'; $html[] = '</div>'; $html[] = '<strong>OR</strong>'; $html[] = '<div class="jmsblockshow-pad">'; $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">'; $html[] = '<tr>'; $html[] = '<td class="key" align="right" width="100">'; $html[] = JText::_('URL Variable 1:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '3" value="' . $params->get($option->value . '_task3') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '<tr>'; $html[] = '<td class="key" nowrap="" align="right" width="100">'; $html[] = JText::_('Variable Value 1:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '3" value="' . $params->get($option->value . '_value3') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '</table>'; $html[] = '<strong>AND</strong>'; $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">'; $html[] = '<tr>'; $html[] = '<td class="key" align="right" width="100">'; $html[] = JText::_('URL Variable 2:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '4" value="' . $params->get($option->value . '_task4') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '<tr>'; $html[] = '<td class="key" nowrap="" align="right" width="100">'; $html[] = JText::_('Variable Value 2:'); $html[] = '</td>'; $html[] = '<td>'; $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '4" value="' . $params->get($option->value . '_value4') . '" size="30" />'; $html[] = '</td>'; $html[] = '</tr>'; $html[] = '</table>'; $html[] = '</div><!-- pad -->'; $html[] = '</div><!-- jmsblockhide-show -->'; $html[] = '</div><!-- col div -->'; if ($i % $cols == $cols - 1) { $html[] = '</div><!-- block div -->'; $html[] = '<div class="clr"></div>'; } } $html[] = '</div>'; // End the checkbox field output. $html[] = '</fieldset>'; return implode($html); }
/** * @param $type * * @return RokCommon_Config_Form */ protected function getPerItemsForm($type) { JForm::addFieldPath(JPATH_SITE . '/components/com_roksprocket/fields'); $options = new RokCommon_Options(); $container = RokCommon_Service::getContainer(); // load up the layouts $layoutinfo = $container['roksprocket.layouts.' . $type]; if (isset($layoutinfo->options->peritem)) { $section = new RokCommon_Options_Section('peritem_' . $type, $layoutinfo->options->peritem); foreach ($layoutinfo->paths as $layoutpath) { $section->addPath($layoutpath); } $options->addSection($section); } $rcform = $rcform = new RokCommon_Config_Form(new JForm('roksprocket_peritem')); $xml = $options->getJoinedXml(); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0', '>=')) { $jxml = new SimpleXMLElement($xml->asXML()); } elseif (version_compare($version->getShortVersion(), '3.0', '<')) { $jxml = new JXMLElement($xml->asXML()); } $fieldsets = $jxml->xpath('/config/fields[@name = "params"]/fieldset'); foreach ($fieldsets as $fieldset) { $overwrite = (string) $fieldset['overwrite'] == 'true' ? true : false; $rcform->load($fieldset, $overwrite, '/config'); } return $rcform; }
/** * @param $form * @param $data * * @return mixed */ protected function processModuleConfig($form, $data) { // check the module to see if it has a rokconfig.xml $module_type = $this->getModuleType($data); $container = RokCommon_Service::getContainer(); $options = new RokCommon_Options(); $section = new RokCommon_Options_Section('roksprocket_module', 'module_config.xml'); $section->addPath(JPATH_SITE . '/components/com_roksprocket/'); $section->addPath($container['roksprocket.template.override.path']); $options->addSection($section); // load up the Providers foreach ($container['roksprocket.providers.registered'] as $type => $providerinfo) { $provider_class = $container[sprintf('roksprocket.providers.registered.%s.class', $type)]; $available = call_user_func(array($provider_class, 'isAvailable')); if ($available) { $section = new RokCommon_Options_Section('provider_' . $type, $providerinfo->optionfile); $section->addPath($providerinfo->path); $options->addSection($section); } } // load up the layouts foreach ($container['roksprocket.layouts'] as $type => $layoutinfo) { $section = new RokCommon_Options_Section('layout_' . $type, $layoutinfo->options->file); foreach ($layoutinfo->paths as $layoutpath) { $section->addPath($layoutpath); } $options->addSection($section); } $container = RokCommon_Service::getContainer(); $rcform = new RokCommon_Config_Form($form); $xml = $options->getJoinedXml(); $jxml = new JXMLElement($xml->asXML()); $fieldsets = $jxml->xpath('/config/fields[@name = "params"]/fieldset'); foreach ($fieldsets as $fieldset) { $overwrite = (string) $fieldset['overwrite'] == 'true' ? true : false; $rcform->load($fieldset, $overwrite, '/config'); } JForm::addFieldPath(JPATH_SITE . '/components/com_roksprocket/fields'); }
/** * Method to allow derived classes to preprocess the form. * * @param object A form object. * @param mixed The data expected for the form. * @param string The name of the plugin group to import (defaults to "content"). * @throws Exception if there is an error in the form event. * @since 1.6 */ protected function preprocessForm(JForm $form, $item, $group = 'content') { // Initialize variables. $filename = $this->getState('translation.filename'); $client = $this->getState('translation.client'); $tag = $this->getState('translation.tag'); $origin = LocaliseHelper::getOrigin($filename, $client); $app = JFactory::getApplication(); $false = false; // Compute all known languages static $languages = array(); jimport('joomla.language.language'); if (!array_key_exists($client, $languages)) { $languages[$client] = JLanguage::getKnownLanguages(constant('LOCALISEPATH_' . strtoupper($client))); } if (is_object($item)) { $form->setFieldAttribute('legend', 'unchanged', $item->unchanged, 'legend'); $form->setFieldAttribute('legend', 'translated', $item->translated, 'legend'); $form->setFieldAttribute('legend', 'untranslated', $item->total - $item->translated - $item->unchanged, 'legend'); $form->setFieldAttribute('legend', 'extra', $item->extra, 'legend'); } if ($this->getState('translation.layout') != 'raw') { $path = $this->getState('translation.path'); $refpath = $this->getState('translation.refpath'); $sections = LocaliseHelper::parseSections($path); $refsections = LocaliseHelper::parseSections($refpath); $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', 'Default'); $fieldset->addAttribute('label', 'Default'); if (JFile::exists($refpath)) { $stream = new JStream(); $stream->open($refpath); $header = true; $lineNumber = 0; while (!$stream->eof()) { $line = $stream->gets(); $lineNumber++; // Blank lines if (preg_match('/^\\s*$/', $line)) { $header = true; $field = $fieldset->addChild('field'); $field->addAttribute('label', ''); $field->addAttribute('type', 'spacer'); $field->addAttribute('class', 'text'); continue; } elseif (preg_match('/^\\[([^\\]]*)\\]\\s*$/', $line, $matches)) { $header = false; $form->load($addform, false); $section = $matches[1]; $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', $section); $fieldset->addAttribute('label', $section); continue; } elseif (!$header && preg_match('/^;(.*)$/', $line, $matches)) { $key = $matches[1]; $field = $fieldset->addChild('field'); $field->addAttribute('label', $key); $field->addAttribute('type', 'spacer'); $field->addAttribute('class', 'text'); continue; } elseif (preg_match('/^([A-Z][A-Z0-9_\\-\\.]*)\\s*=/', $line, $matches)) { $header = false; $key = $matches[1]; $field = $fieldset->addChild('field'); $string = $refsections['keys'][$key]; $translated = isset($sections['keys'][$key]); $modified = $translated && $sections['keys'][$key] != $refsections['keys'][$key]; $status = $modified ? 'translated' : ($translated ? 'unchanged' : 'untranslated'); $default = $translated ? $sections['keys'][$key] : ''; $label = '<b>' . $key . '</b><br />' . htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); $field->addAttribute('status', $status); $field->addAttribute('description', $string); if ($default) { $field->addAttribute('default', $default); } else { $field->addAttribute('default', $string); } $field->addAttribute('label', $label); $field->addAttribute('name', $key); $field->addAttribute('type', 'key'); $field->addAttribute('filter', 'raw'); continue; } elseif (!preg_match('/^(|(\\[[^\\]]*\\])|([A-Z][A-Z0-9_\\-\\.]*\\s*=(\\s*(("[^"]*")|(_QQ_)))+))\\s*(;.*)?$/', $line)) { $this->item->error[] = $lineNumber; } } $stream->close(); $newstrings = false; if (!empty($sections['keys'])) { foreach ($sections['keys'] as $key => $string) { if (!isset($refsections['keys'][$key])) { if (!$newstrings) { $newstrings = true; $form->load($addform, false); $section = 'New Strings'; $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', $section); $fieldset->addAttribute('label', $section); } $field = $fieldset->addChild('field'); $status = 'extra'; $default = $string; $label = '<b>' . $key . '</b>'; $field->addAttribute('status', $status); $field->addAttribute('description', $string); if ($default) { $field->addAttribute('default', $default); } else { $field->addAttribute('default', $string); } $field->addAttribute('label', $label); $field->addAttribute('name', $key); $field->addAttribute('type', 'key'); $field->addAttribute('filter', 'raw'); } } } } $form->load($addform, false); } // Check the session for previously entered form data. $data = $app->getUserState('com_localise.edit.translation.data', array()); // Bind the form data if present. if (!empty($data)) { $form->bind($data); } if ($origin != '_thirdparty' && $origin != '_override') { $packages = LocaliseHelper::getPackages(); $package = $packages[$origin]; if (!empty($package->author)) { $form->setValue('author', $package->author); $form->setFieldAttribute('author', 'readonly', 'true'); } if (!empty($package->copyright)) { $form->setValue('maincopyright', $package->copyright); $form->setFieldAttribute('maincopyright', 'readonly', 'true'); } if (!empty($package->license)) { $form->setValue('license', $package->license); $form->setFieldAttribute('license', 'readonly', 'true'); } } if ($form->getValue('description') == '' && array_key_exists($tag, $languages[$client])) { $form->setValue('description', $filename . ' ' . $languages[$client][$tag]['name']); } return $form; }
/** * @param $type * * @return \RokCommon_Config_Form */ public function getPerItemsForm($type = null) { $options = new RokCommon_Options(); $container = RokCommon_Service::getContainer(); // load up the layouts if (null == $type) { foreach ($container['roksprocket.layouts'] as $type => $layoutinfo) { $this->addPerItemsOptionsForLayout($type, $options); } } else { $this->addPerItemsOptionsForLayout($type, $options); } $rcform = $rcform = new RokCommon_Config_Form(new JForm('roksprocket_peritem')); $xml = $options->getJoinedXml(); $jxml = new JXMLElement($xml->asXML()); $fieldsets = $jxml->xpath('/config/fields[@name = "params"]/fieldset'); foreach ($fieldsets as $fieldset) { $overwrite = (string) $fieldset['overwrite'] == 'true' ? true : false; $rcform->load($fieldset, $overwrite, '/config'); } JForm::addFieldPath(JPATH_SITE . '/components/com_roksprocket/fields'); return $rcform; }
/** * Scans a directory for XML manifest files. The first XML file to be a * manifest wins. * * @var $path string The path to look into * * @return string|bool The full path to a manifest file or false if not found */ private function searchForManifest($path) { jimport('joomla.filesystem.folder'); $files = JFolder::files($path, '\\.xml$', false, true); if (!empty($files)) { foreach ($files as $filename) { if (version_compare(JVERSION, '3.0.0', 'ge')) { try { $xml = new JXMLElement($filename, LIBXML_NONET, true); } catch (Exception $e) { continue; } if ($xml->getName() != 'extension') { continue; } unset($xml); return $filename; } else { $xml = JFactory::getXMLParser('simple'); $result = $xml->loadFile($filename); if (!$result) { continue; } if ($xml->document->name() != 'install' && $xml->document->name() != 'extension' && $xml->document->name() != 'mosinstall') { continue; } unset($xml); return $filename; } } } return false; }