/**
  * Renders the element
  * 
  * @access	public
  * @param string $name name of the element combined with $control_name like "$control_name[$name]"
  * @param mixed $value pre-selected value of the element
  * @param object $node reference to the XML node that defined this element
  * @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
  * @return string HTML output that renders the element
  */
 function fetchElement($name, $value, &$node, $control_name)
 {
     $htmlId = $node->attributes('id') ? $node->attributes('id') : '';
     $disabled = $value ? 'disabled="disabled"' : '';
     $pManager =& getPluginManager();
     $pManager->loadPlugins('acl');
     $aclData = $pManager->invokeMethod('acl', 'getACL', null, null);
     $aclHandlersList = array();
     $aclHandlersList[] = JHTML::_('select.option', 0, JText::_('Please Select'));
     $jsOutput = JHTML::_('jwf.indentedLine', 'var aclLists = {', 3);
     foreach ($pManager->settings['acl'] as $p) {
         if ($aclData[$p->id] == null) {
             continue;
         }
         $jsOutput .= JHTML::_('jwf.indentedLine', "'{$p->id}' : {", 4);
         foreach ($aclData[$p->id] as $groupID => $groupTitle) {
             $jsOutput .= JHTML::_('jwf.indentedLine', "{$groupID} : '{$groupTitle}',", 5);
         }
         $jsOutput = JHTML::_('jwf.trimComma', $jsOutput);
         $jsOutput .= JHTML::_('jwf.indentedLine', '},', 4);
         $aclHandlersList[] = JHTML::_('select.option', $p->id, $p->name);
     }
     $jsOutput = JHTML::_('jwf.trimComma', $jsOutput);
     $jsOutput .= JHTML::_('jwf.indentedLine', '};', 3);
     $output = JHTML::_('jwf.startJSBlock', 2);
     $output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.acl = '{$value}';", 3);
     $output .= $jsOutput;
     $output .= JHTML::_('jwf.endJSBlock', 2);
     $output .= JHTML::_('select.genericlist', $aclHandlersList, "{$control_name}[{$name}]", "{$disabled} class='inputbox' size='1' onchange='selectACLSystemFromList(this)'", 'value', 'text', $value, $htmlId);
     return $output;
 }
 /**
  * Renders the element
  *
  * @access	public
  * @param string $name name of the element combined with $control_name like "$control_name[$name]"
  * @param mixed $value pre-selected value of the element
  * @param object $node reference to the XML node that defined this element
  * @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
  * @return string HTML output that renders the element
  */
 function fetchElement($name, $value, &$node, $control_name)
 {
     $htmlId = $node->attributes('id') ? 'id="' . $node->attributes('id') . '"' : '';
     $pManager =& getPluginManager();
     $pManager->loadPlugins('component');
     $output = JHTML::_('jwf.startJSBlock', 2);
     $output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.category = '{$value}';", 3);
     $output .= JHTML::_('jwf.indentedLine', 'var categoriesData = {', 3);
     $categoryLists = $pManager->invokeMethod('component', 'getCategories', null, null);
     foreach ($categoryLists as $contentType => $data) {
         if ($data) {
             $output .= JHTML::_('jwf.indentedLine', "{$contentType}:{", 4);
             foreach ($data as $id => $obj) {
                 $output .= JHTML::_('jwf.indentedLine', $obj->getId() . ' : \'' . $obj->getTitle() . '\',', 5);
                 if (count($obj->getChildren())) {
                     $output .= $this->fetchChildren($obj, 1);
                 }
             }
             if (count($data)) {
                 $output = JHTML::_('jwf.trimComma', $output);
             }
             $output .= JHTML::_('jwf.indentedLine', "},", 4);
         }
     }
     $output = JHTML::_('jwf.trimComma', $output);
     $output .= JHTML::_('jwf.indentedLine', '};', 3);
     $output .= JHTML::_('jwf.endJSBlock', 2);
     $output .= JHTML::_('jwf.indentedLine', "<select multiple='multiple' name='{$control_name}[{$name}][]' {$htmlId} size='5'></select>", 2);
     return $output;
 }
Beispiel #3
0
 /**
  * Fetch a calendar element
  *
  * @param   string   $name          Field name
  * @param   string   $value         The date value
  * @param   object   $node          JSimpleXMLElement node object containing the settings for the element
  * @param   string   $control_name  Control name
  * 
  * @return  string   HTML string for a calendar
  *
  * @deprecated  12.1
  * @see    JFormFieldCalendar
  * @since  11.1
  */
 public function fetchElement($name, $value, &$node, $control_name)
 {
     // Deprecation warning.
     JLog::add('JElementCalendar::fetchElement() is deprecated.', JLog::WARNING, 'deprecated');
     // Load the calendar behavior
     JHtml::_('behavior.calendar');
     $format = $node->attributes('format') ? $node->attributes('format') : '%Y-%m-%d';
     $class = $node->attributes('class') ? $node->attributes('class') : 'inputbox';
     $id = $control_name . $name;
     $name = $control_name . '[' . $name . ']';
     return JHtml::_('calendar', $value, $name, $id, $format, array('class' => $class));
 }
Beispiel #4
0
 /**
  * Method to test if two values are equal. To use this rule, the form
  * XML needs a validate attribute of equals and a field attribute
  * that is equal to the field to test against.
  *
  * @param	object		$field		A reference to the form field.
  * @param	mixed		$values		The values to test for validiaty.
  * @return	mixed		JException on invalid rule, true if the value is valid, false otherwise.
  */
 public function test(&$field, &$values)
 {
     $return = false;
     $field1 = (string) $field->attributes()->name;
     $field2 = (string) $field->attributes()->field;
     // Check the rule.
     if (!$field2) {
         return new JException('Invalid Form Rule :: ' . get_class($this));
     }
     // Test the two values against each other.
     if ($values[$field1] == $values[$field2]) {
         $return = true;
     }
     return $return;
 }
 /**
  * Renders the element
  * 
  * @access	public
  * @param string $name name of the element combined with $control_name like "$control_name[$name]"
  * @param mixed $value pre-selected value of the element
  * @param object $node reference to the XML node that defined this element
  * @param string $control_name HTML element Array name , combined with $name like "$control_name[$name]"
  * @return string HTML output that renders the element
  */
 function fetchElement($name, $value, &$node, $control_name)
 {
     $htmlId = $node->attributes('id') ? $node->attributes('id') : '';
     $pManager =& getPluginManager();
     $pManager->loadPlugins('component');
     $output = JHTML::_('jwf.startJSBlock', 2);
     $output .= JHTML::_('jwf.indentedLine', "defaultWorkflow.component = '{$value}';", 3);
     $output .= JHTML::_('jwf.endJSBlock', 2);
     $contentTypesList = array();
     foreach ($pManager->settings['component'] as $p) {
         $contentTypesList[] = JHTML::_('select.option', $p->id, $p->name);
     }
     $output .= JHTML::_('select.genericlist', $contentTypesList, $control_name . '[' . $name . ']', 'onchange="updateCategoryList(this)" class="inputbox" size="1"', 'value', 'text', $value, $htmlId);
     return $output;
 }
Beispiel #6
0
 /**
  * Method to test if two values are equal. To use this rule, the form
  * XML needs a validate attribute of equals and a field attribute
  * that is equal to the field to test against.
  *
  * @param	object		$field		A reference to the form field.
  * @param	mixed		$values		The values to test for validiaty.
  * @return	mixed		JException on invalid rule, true if the value is valid, false otherwise.
  * @since	1.6
  */
 public function test(&$field, &$values)
 {
     $name = (string) $field->attributes()->name;
     // TODO: probably should check to see if the action is even available for this field.
     //		$values[$name];
     return true;
 }
Beispiel #7
0
 /**
  * Fetch the HTML code for the parameter element.
  *
  * @param   string  $name          The field name.
  * @param   mixed   $value         The value of the field.
  * @param   object  $node          The current XML node.
  * @param   string  $control_name  The name of the HTML control.
  *
  * @since   11.1
  *
  * @deprecated    12.1
  */
 public function fetchElement($name, $value, &$node, $control_name)
 {
     $ctrl = $control_name . '[' . $name . ']';
     $attribs = ' ';
     if ($v = $node->attributes('size')) {
         $attribs .= 'size="' . $v . '"';
     }
     if ($v = $node->attributes('class')) {
         $attribs .= 'class="' . $v . '"';
     } else {
         $attribs .= 'class="inputbox"';
     }
     if ($m = $node->attributes('multiple')) {
         $attribs .= 'multiple="multiple"';
         $ctrl .= '[]';
     }
     return JHtml::_('select.genericlist', $this->_getOptions($node), $ctrl, array('id' => $control_name . $name, 'list.attr' => $attribs, 'list.select' => $value));
 }
Beispiel #8
0
 /**
  * Method to test if an e-mail address is unique.
  *
  * @param	object		$field		A reference to the form field.
  * @param	mixed		$values		The values to test for validiaty.
  * @return	mixed		JException on invalid rule, true if the value is valid, false otherwise.
  * @since	1.6
  */
 public function test(&$field, &$values)
 {
     $return = false;
     $name = (string) $field->attributes()->name;
     $check = (string) $field->attributes()->unique == 'true' || (string) $field->attributes()->unique == 'unique';
     // If the field is empty and not required, the field is valid.
     if ((string) $field->attributes()->required != 'true') {
         // Get the data for the field.
         $value = array_key_exists($name, $values) ? $values[$name] : null;
         // If the data is empty, return valid.
         if ($value == null) {
             return true;
         }
     }
     // Check if we should test for uniqueness.
     if ($check) {
         $key = (string) $field->attributes()->field;
         $value = isset($values[$key]) ? $values[$key] : 0;
         // Check the rule.
         if (!$key) {
             return new JException('Invalid Form Rule :: ' . get_class($this));
         }
         // Check if the username is unique.
         $db =& JFactory::getDbo();
         $db->setQuery('SELECT count(*) FROM `#__users`' . ' WHERE `email` = ' . $db->Quote($values[$name]) . ' AND ' . $db->nameQuote($key) . ' != ' . $db->Quote($value));
         $duplicate = (bool) $db->loadResult();
         // Check for a database error.
         if ($db->getErrorNum()) {
             return new JException('Database Error :: ' . $db->getErrorMsg());
         }
         // Test the value against the regular expression.
         if (parent::test($field, $values) && !$duplicate) {
             $return = true;
         }
     } else {
         // Test the value against the regular expression.
         if (parent::test($field, $values)) {
             $return = true;
         }
     }
     return $return;
 }
Beispiel #9
0
 /**
  * Method to test if a username is unique.
  *
  * @param	object		$field		A reference to the form field.
  * @param	mixed		$values		The values to test for validiaty.
  * @return	mixed		JException on invalid rule, true if the value is valid, false otherwise.
  */
 public function test(&$field, &$values)
 {
     $return = false;
     $name = (string) $field->attributes()->name;
     $key = (string) $field->attributes()->field;
     $value = isset($values[$key]) ? $values[$key] : 0;
     // Check the rule.
     if (!$key) {
         return new JException('Invalid Form Rule :: ' . get_class($this));
     }
     // Check if the username is unique.
     $db =& JFactory::getDbo();
     $db->setQuery('SELECT count(*) FROM `#__users`' . ' WHERE `username` = ' . $db->Quote($values[$name]) . ' AND ' . $db->nameQuote($key) . ' != ' . $db->Quote($value));
     $duplicate = (bool) $db->loadResult();
     // Check for a database error.
     if ($db->getErrorNum()) {
         return new JException('Database Error :: ' . $db->getErrorMsg());
     }
     if (!$duplicate) {
         $return = true;
     }
     return $return;
 }
Beispiel #10
0
 /**
  * Method to get an attribute of the field
  *
  * @param   string  $name     Name of the attribute to get
  * @param   mixed   $default  Optional value to return if attribute not found
  * @return  mixed             Value of the attribute / default
  */
 public function getAttribute($name, $default = null)
 {
     if ($this->element instanceof SimpleXMLElement) {
         $attributes = $this->element->attributes();
         // Ensure that the attribute exists
         if (property_exists($attributes, $name)) {
             $value = $attributes->{$name};
             if ($value !== null) {
                 return (string) $value;
             }
         }
     }
     return $default;
 }
Beispiel #11
0
 /**
  * Method to test the value.
  *
  * @param	object		$field		A reference to the form field.
  * @param	mixed		$values		The values to test for validiaty.
  * @return	boolean		True if the value is valid, false otherwise.
  * @since	1.6
  * @throws	JException on invalid rule.
  */
 public function test(&$field, &$values)
 {
     $return = false;
     $name = $field->attributes('name');
     // Check for a valid regex.
     if (empty($this->_regex)) {
         throw new JException('Invalid Form Rule :: ' . get_class($this));
     }
     // Add unicode property support if available.
     if (JCOMPAT_UNICODE_PROPERTIES) {
         $this->_modifiers = strpos($this->_modifiers, 'u') ? $this->_modifiers : $this->_modifiers . 'u';
     }
     // Test the value against the regular expression.
     if (preg_match('#' . $this->_regex . '#' . $this->_modifiers, $values[$name])) {
         $return = true;
     }
     return $return;
 }
 /**
  * Функция получения названия и сроков проведения кампании
  *
  * @return array $params - параметры кампании: 'name' - название,
  *                                             'start_date' - UNIXTIMESTAMP дата начала кампании
  *                                             'end_date' - UNIXTIMESTAMP дата завершения кампании
  */
 public function get_name_date()
 {
     $result = array();
     if (!isset($this->campaign->attributes()->name)) {
         $result['name'] = NULL;
     } else {
         $result['name'] = (string) $this->campaign->attributes()->name;
     }
     /*if (!isset($this->campaign->attributes()->start_date)) {
          $result['start_date'] = NULL;
       } else {
          $result['start_date'] = (string)$this->campaign->attributes()->start_date;
       }
       
       if (!isset($this->campaign->attributes()->end_date)) {
          $result['end_date'] = NULL;
       } else {
          $result['end_date'] = (string)$this->campaign->attributes()->end_date;
       }*/
     return $result;
 }
Beispiel #13
0
 /**
  * Method to test if a value is valid for a field.
  *
  * @param	object		$field		The field to validate.
  * @param	array		$values		The values to validate.
  * @return	mixed		Boolean on success, JException on error.
  * @since	1.6
  */
 protected function _isValid(&$field, $values)
 {
     $result = true;
     // Get the validator type.
     if ($type = $field->attributes('validate')) {
         // Get the validator class.
         $class = 'JFormRule' . $type;
         if (!class_exists($class)) {
             jimport('joomla.filesystem.path');
             // Attempt to load the rule file.
             if ($file = JPath::find(EFormValidator::addRulePath(), $type . '.php')) {
                 require_once $file;
             }
             if (!class_exists($class)) {
                 return new JException(JText::sprintf('Libraries_Form_Validator_Rule_Not_Found', $type), 0, E_ERROR);
             }
         }
         // Run the validator.
         $rule = new $class();
         $result = $rule->test($field, $values);
     }
     return $result;
 }
Beispiel #14
0
 /**
  * Type case XML values based on attributes
  *
  * This method typecasts the xml values based on the
  * attributes of the SimpleXMLElement Object passed 
  * to the method. 
  *
  * @param object $valueObj SimpleXMLElement
  * @return mixed value for placing into array
  */
 private static function _typecastXmlValue($valueObj)
 {
     // get the element attributes
     $attribs = $valueObj->attributes();
     // the element is null, so jump out here
     if (isset($attribs->nil) && $attribs->nil || isset($attribs->null) && $attribs->null || (string) $valueObj == 'null') {
         return null;
     }
     // switch on the type attribute
     // switch works even if $attribs->type isn't set
     $type = isset($attribs->coerced_type) ? $attribs->coerced_type : $attribs->type;
     switch ($type) {
         case 'datetime':
             return self::_timestampToUTC((string) $valueObj);
             break;
         case 'integer':
             return (int) $valueObj;
             break;
         case 'boolean':
             $value = (string) $valueObj;
             // look for a number inside the string
             if (is_numeric($value)) {
                 return (bool) $value;
             }
             return $value == 'true';
             break;
         case 'array':
             return array();
         default:
             return (string) $valueObj;
     }
 }
Beispiel #15
0
 /**
  * Recursive method to toArray
  *
  * @param object $xml SimpleXMLElement object
  * @param array $parentData Parent array with data
  * @param string $ns Namespace of current child
  * @param array $namespaces List of namespaces in XML
  * @return void
  */
 protected static function _toArray($xml, &$parentData, $ns, $namespaces)
 {
     $data = array();
     foreach ($namespaces as $namespace) {
         foreach ($xml->attributes($namespace, true) as $key => $value) {
             if (!empty($namespace)) {
                 $key = $namespace . ':' . $key;
             }
             $data['@' . $key] = (string) $value;
         }
         foreach ($xml->children($namespace, true) as $child) {
             self::_toArray($child, $data, $namespace, $namespaces);
         }
     }
     $asString = trim((string) $xml);
     if (empty($data)) {
         $data = $asString;
     } elseif (!empty($asString)) {
         $data['@'] = $asString;
     }
     if (!empty($ns)) {
         $ns .= ':';
     }
     $name = $ns . $xml->getName();
     if (isset($parentData[$name])) {
         if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
             $parentData[$name] = array($parentData[$name]);
         }
         $parentData[$name][] = $data;
     } else {
         $parentData[$name] = $data;
     }
 }
 /**
  * Helper to retrieve field-agnostic value.
  *
  * @param object $field
  *   Field object returned from findElementByCss().
  *
  * @return mixed
  *   Field value.
  */
 protected function getFormElementValue($field)
 {
     $tag = $field->getName();
     switch ($tag) {
         case 'input':
             $attr = $field->attributes();
             $value = (string) $attr['value'];
             break;
         case 'textarea':
         default:
             $value = (string) $field;
             break;
     }
     return $value;
 }
Beispiel #17
0
 /**
  * Method to parse through a languages element of the installation manifest and take appropriate
  * action.
  *
  * @access	public
  * @param	object	$element 	The xml node to process
  * @param	int		$cid		Application ID of application to install to
  * @return	boolean	True on success
  * @since	1.5
  */
 function parseLanguages($pathSrc, $element, $cid = 0)
 {
     // TODO: work out why the below line triggers 'node no longer exists' errors with files
     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.
      *
      * 'languages' Files are copied to JPATH_BASE/language/ folder
      */
     $destination = $client->path . DS . 'language';
     /*
      * 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 && JFolder::exists($pathSrc . DS . $folder)) {
         $source = $pathSrc . DS . $folder;
     } else {
         $source = $pathSrc;
     }
     // Process each file in the $files array (children of $tagName).
     foreach ($element->children() as $file) {
         /*
          * Language files go in a subfolder based on the language code, ie.
          *
          * 		<language tag="en-US">en-US.mycomponent.ini</language>
          *
          * would go in the en-US subdirectory of the language folder.
          *
          * We will only install language files where a core language pack
          * already exists.
          */
         if ((string) $file->attributes()->tag != '') {
             $path['src'] = $source . DS . $file;
             if ((string) $file->attributes()->client != '') {
                 // override the client
                 $langclient = JApplicationHelper::getClientInfo((string) $file->attributes()->client, true);
                 $path['dest'] = $langclient->path . DS . 'language' . DS . $file->attributes()->tag . DS . basename((string) $file);
             } else {
                 // use the default client
                 $path['dest'] = $destination . DS . $file->attributes()->tag . DS . basename((string) $file);
             }
             // If the language folder is not present, then the core pack hasn't been installed... ignore
             if (!JFolder::exists(dirname($path['dest']))) {
                 continue;
             }
         } else {
             $path['src'] = $source . DS . $file;
             $path['dest'] = $destination . DS . $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;
     }
     $result = $this->copyFiles($copyfiles, true);
     return $result;
 }
Beispiel #18
0
 /**
  * Render a parameter type.
  *
  * @param   object  $node          A parameter XML element.
  * @param   string  $control_name  An optional name of the HTML form control. The default is 'params' if not supplied.
  * @param   string  $group         An optional group to render.  The default group is used if not supplied.
  *
  * @return  array  Any array of the label, the form element and the tooltip.
  *
  * @deprecated  12.1
  * @since   11.1
  */
 public function getParam(&$node, $control_name = 'params', $group = '_default')
 {
     // Get the type of the parameter.
     $type = $node->attributes('type');
     $element = $this->loadElement($type);
     // Check for an error.
     if ($element === false) {
         $result = array();
         $result[0] = $node->attributes('name');
         $result[1] = JText::_('Element not defined for type') . ' = ' . $type;
         $result[5] = $result[0];
         return $result;
     }
     // Get value.
     $value = $this->get($node->attributes('name'), $node->attributes('default'), $group);
     return $element->render($node, $value, $control_name);
 }
Beispiel #19
0
 /**
  * Inserts data to database.
  *
  * @param object $LogEntry And XML object containing data
  *
  * @return none
  */
 private function _insertToDB($LogEntry)
 {
     mysql_select_db(CONFIG_mysql_database, $this->db);
     mysql_query(sprintf('INSERT INTO svnlog ' . '(revision, author, date, commitmessage) ' . 'VALUES (%d,"%s","%s","%s")', $LogEntry->attributes()->revision, (string) $LogEntry->author, (string) $LogEntry->date, $this->_fixText((string) $LogEntry->msg)));
 }
Beispiel #20
0
 /**
  * Get title of menu item
  * 
  * @param object $item Menu item
  * 
  * @return string Link of menu item
  */
 function gettitle($item)
 {
     return $item->attributes('title');
 }
Beispiel #21
0
 /**
  * Recursively registers strings for a serialized option
  *
  * @since 1.0
  *
  * @param string $context the group in which the strings will be registered
  * @param array  $options
  * @param object $key XML node
  */
 protected function register_string_recursive($context, $options, $key)
 {
     $children = $key->children();
     if (count($children)) {
         foreach ($children as $child) {
             $attributes = $child->attributes();
             $name = (string) $attributes['name'];
             if (isset($options[$name])) {
                 $this->register_string_recursive($context, $options[$name], $child);
             }
         }
     } else {
         $attributes = $key->attributes();
         pll_register_string((string) $attributes['name'], $options, $context);
     }
 }
Beispiel #22
0
 /**
  * Xml konvertálása stdClass-é
  *
  * @param object|string $xml
  * @param object|null   $obj
  *
  * @return mixed
  */
 private function xmlToObj($xml, $obj = null)
 {
     if (count($xml->children()) <= 0) {
         if (!$xml->attributes()) {
             return (string) $xml;
         } else {
             $obj = new \stdClass();
             foreach ($xml->attributes() as $attr => $value) {
                 $obj->{$attr} = (string) $value;
             }
             $obj->value = (string) $xml;
             return $obj;
         }
     }
     $obj = isset($obj) ? $obj : new \stdClass();
     foreach ($xml->children() as $element => $node) {
         $data = new \stdClass();
         if (!isset($obj->{$element})) {
             $obj->{$element} = "";
         }
         if (!$node->attributes()) {
             $data = $this->xmlToObj($node);
         } else {
             foreach ($node->attributes() as $attr => $value) {
                 $data->{$attr} = (string) $value;
             }
             if (count($node->children()) > 0) {
                 $data = $this->xmlToObj($node, $data);
             }
         }
         if (count($xml->{$element}) > 1) {
             $obj->{$element}[] = $data;
         } else {
             $obj->{$element} = $data;
         }
     }
     foreach ($xml->attributes() as $attr => $value) {
         $obj->{$attr} = (string) $value;
     }
     return $obj;
 }
Beispiel #23
0
 /**
  * thuc hien chuyen mot doi tuong xml thanh mot mang
  *
  * @param object $xml doi tuong xml
  * @return array cac phan tu trong doi tuong xml
  * @author TinhDoan added [20100723]
  *
  */
 public function parseXML($xml)
 {
     $arXML = array();
     $arXML['name'] = trim($xml->getName());
     $arXML['value'] = trim((string) $xml);
     //lay cac thuoc tinh
     $temp = array();
     foreach ($xml->attributes() as $nameAttr => $value) {
         $temp[$nameAttr] = trim($value);
     }
     $arXML['attribute'] = $temp;
     //lay cac node con
     $arXML['children'] = array();
     foreach ($xml->children() as $nameChild => $xmlchild) {
         $temp = self::parseXML($xmlchild);
         if (!isset($arXML['children'][$nameChild])) {
             $arXML['children'][$nameChild] = array();
         }
         array_push($arXML['children'][$nameChild], $temp);
     }
     return $arXML;
 }
 /**
  * Support function for XML load function. Returns
  * attribute parts for the XML array.
  *
  * @param object $xml SimpleXML object.
  * @return array $array XML array.
  */
 private function getAttributes($xml)
 {
     foreach ($xml->attributes() as $key => $value) {
         $arr[$key] = (string) current($value);
     }
     foreach ($xml->attributes("xml", TRUE) as $key => $value) {
         $arr[$key][] = (string) current($value);
         $arr[$key]["@namespace"] = "http://www.w3.org/XML/1998/namespace";
     }
     return $arr;
 }
Beispiel #25
0
 /**
  * Takes attributes of a SimpleXML element and adds them to an object (as properties).
  *
  * @param object $element
  *   A SimpleXML element.
  *
  * @param object $object
  *   Any PHP object.
  */
 function add_simplexml_attributes($element, $object)
 {
     if (count($element->attributes())) {
         foreach ($element->attributes() as $attr => $value) {
             $object->{$attr} = (string) $value;
         }
     }
 }
Beispiel #26
0
 /**
  * Output a single unit test.
  *
  * @param object $testSuite The testsuite..
  *
  * @todo TODO - MOVE THIS SH** =;)
  *
  * @return string
  */
 private function outputSingleTest($testSuite)
 {
     $ret = '';
     $ret .= '<hr />';
     $ret .= '<h2>' . $testSuite->attributes()->name . '</h2>';
     $ret .= sprintf('Tests: <b style="color: blue;">%d</b>' . ' Assertions: <b style="color: blue;">%d</b>' . ' Failures: <b style="color: red;">%d</b>' . ' Errors: <b style="color: red;">%d</b>' . ' Time: <b style="color: green;">%d</b>', $testSuite->attributes()->tests, $testSuite->attributes()->assertions, $testSuite->attributes()->failures, $testSuite->attributes()->errors, $testSuite->attributes()->time);
     if (!isset($testSuite->testcase)) {
         return $ret;
     }
     $ret .= '<table class="adminlist">';
     $ret .= '  <thead>';
     $ret .= '    <tr>';
     $ret .= '      <th>Stat</th>';
     $ret .= '      <th>Name</th>';
     $ret .= '      <th>Class</th>';
     $ret .= '      <th>Line</th>';
     $ret .= '      <th>Asserts</th>';
     $ret .= '      <th>Time</th>';
     $ret .= '      <th>File</th>';
     $ret .= '    </tr>';
     $ret .= '  </thead>';
     $ret .= '  <tbody>';
     foreach ($testSuite->testcase as $testCase) {
         $ret .= '<tr valign="top">';
         $stat = isset($testCase->failure) ? 'fail' : 'ok';
         $ret .= '<td style="text-align: center;"><span class="img icon-16-check_' . $stat . '"></span></td>';
         $ret .= '<td>' . $testCase->attributes()->name . '</td>';
         $ret .= '<td>' . $testCase->attributes()->class . '</td>';
         $ret .= '<td>' . $testCase->attributes()->line . '</td>';
         $ret .= '<td>' . $testCase->attributes()->assertions . '</td>';
         $ret .= '<td>' . $testCase->attributes()->time . '</td>';
         $ret .= '<td>' . str_replace(JPATH_ROOT . DS, '', $testCase->attributes()->file) . '</td>';
         $ret .= '</tr>';
         if (isset($testCase->failure)) {
             $ret .= '<tr>';
             $ret .= '<td colspan="7" style="background-color: #ffb299; color: black;">';
             $ret .= '<pre>';
             $ret .= htmlentities(str_replace(JPATH_ROOT . DS, 'JPATH_ROOT' . DS, $testCase->failure));
             $ret .= '</pre>';
             $ret .= '</td>';
             $ret .= '</tr>';
         }
     }
     //foreach
     $ret .= '</tbody>';
     $ret .= '</table>';
     return $ret;
 }
Beispiel #27
0
 /**
  * typecast xml value based on attributes
  * @param object $valueObj SimpleXMLElement
  * @return mixed value for placing into array
  */
 private static function _typecastXmlValue($valueObj)
 {
     // get the element attributes
     $attribs = $valueObj->attributes();
     // the element is null, so jump out here
     if (isset($attribs->nil) && $attribs->nil) {
         return null;
     }
     // switch on the type attribute
     // switch works even if $attribs->type isn't set
     switch ($attribs->type) {
         case 'datetime':
             return self::_timestampToUTC((string) $valueObj);
             break;
         case 'date':
             return new DateTime((string) $valueObj);
             break;
         case 'integer':
             return (int) $valueObj;
             break;
         case 'boolean':
             $value = (string) $valueObj;
             // look for a number inside the string
             if (is_numeric($value)) {
                 return (bool) $value;
             } else {
                 // look for the string "true", return false in all other cases
                 return $value != "true" ? FALSE : TRUE;
             }
             break;
         case 'array':
             return array();
         default:
             return (string) $valueObj;
     }
 }
Beispiel #28
0
 /**
  * Method to parse through a files element of the installation manifest and remove
  * the files that were installed
  *
  * @param   object   $element  The XML node to process
  * @param   integer  $cid      Application ID of application to remove from
  *
  * @return  boolean  True on success
  *
  * @since   3.1
  */
 public function removeFiles($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 true;
     }
     $retval = true;
     // Get the client info if we're using a specific client
     if ($cid > -1) {
         $client = JApplicationHelper::getClientInfo($cid);
     } else {
         $client = null;
     }
     // Get the array of file nodes to process
     $files = $element->children();
     if (count($files) == 0) {
         // No files to process
         return true;
     }
     $folder = '';
     /*
      * Here we set the folder we are going to remove the files from.  There are a few
      * special cases that need to be considered for certain reserved tags.
      */
     switch ($element->getName()) {
         case 'media':
             if ((string) $element->attributes()->destination) {
                 $folder = (string) $element->attributes()->destination;
             } else {
                 $folder = '';
             }
             $source = $client->path . '/media/' . $folder;
             break;
         case 'languages':
             $lang_client = (string) $element->attributes()->client;
             if ($lang_client) {
                 $client = JApplicationHelper::getClientInfo($lang_client, true);
                 $source = $client->path . '/language';
             } else {
                 if ($client) {
                     $source = $client->path . '/language';
                 } else {
                     $source = '';
                 }
             }
             break;
         default:
             if ($client) {
                 $pathname = 'extension_' . $client->name;
                 $source = $this->getPath($pathname);
             } else {
                 $pathname = 'extension_root';
                 $source = $this->getPath($pathname);
             }
             break;
     }
     // Process each file in the $files array (children of $tagName).
     foreach ($files as $file) {
         /*
          * If the file is a language, we must handle it differently.  Language files
          * go in a subdirectory based on the language code, ie.
          * <language tag="en_US">en_US.mycomponent.ini</language>
          * would go in the en_US subdirectory of the languages directory.
          */
         if ($file->getName() == 'language' && (string) $file->attributes()->tag != '') {
             if ($source) {
                 $path = $source . '/' . $file->attributes()->tag . '/' . basename((string) $file);
             } else {
                 $target_client = JApplicationHelper::getClientInfo((string) $file->attributes()->client, true);
                 $path = $target_client->path . '/language/' . $file->attributes()->tag . '/' . basename((string) $file);
             }
             // If the language folder is not present, then the core pack hasn't been installed... ignore
             if (!JFolder::exists(dirname($path))) {
                 continue;
             }
         } else {
             $path = $source . '/' . $file;
         }
         // Actually delete the files/folders
         if (is_dir($path)) {
             $val = JFolder::delete($path);
         } else {
             $val = JFile::delete($path);
         }
         if ($val === false) {
             JLog::add('Failed to delete ' . $path, JLog::WARNING, 'jerror');
             $retval = false;
         }
     }
     if (!empty($folder)) {
         JFolder::delete($source);
     }
     return $retval;
 }
Beispiel #29
0
 /**
  * Method to replace a field in a group.
  *
  * @param	object		$field		The field object to replace.
  * @param	string		$group		The group to replace the field in.
  * @return	boolean		True on success, false when field does not exist.
  */
 public function setField(&$field, $group = '_default')
 {
     $return = false;
     // Add the fields to the group if it exists.
     if (isset($this->_groups[$group][$field->attributes()->name])) {
         $this->_groups[$group][(string) $field->attributes()->name] = $field;
         $return = true;
     }
     return $return;
 }