Exemplo n.º 1
0
function simpleXMLToArray($xml, $flattenValues=true, $flattenAttributes = true, $flattenChildren=true, $valueKey='@value', $attributesKey='@attributes', $childrenKey='@children') {
	$return = array();
	if (!($xml instanceof SimpleXMLElement)) {
		return $return;
	}
	$name = $xml->getName();
	$_value = trim((string) $xml);

	if (strlen($_value) == 0) {
		$_value = null;
	}

	if ($_value != null) {
		if (!$flattenValues) {
			$return[$valueKey] = $_value;
		} else {
			$return = $_value;
		}
	}

	$children = array();
	$first = true;
	foreach ($xml->children() as $elementName => $child) {
		$value = simpleXMLToArray($child, $flattenValues, $flattenAttributes, $flattenChildren, $valueKey, $attributesKey, $childrenKey);
		if (isset($children[$elementName])) {
			if ($first) {
				$temp = $children[$elementName];
				unset($children[$elementName]);
				$children[$elementName][] = $temp;
				$first = false;
			}
			$children[$elementName][] = $value;
		} else {
			$children[$elementName] = $value;
		}
	}
	if (count($children) > 0) {
		if (!$flattenChildren) {
			$return[$childrenKey] = $children;
		} else {
			$return = array_merge($return, $children);
		}
	}

	$attributes = array();
	foreach ($xml->attributes() as $name => $value) {
		$attributes[$name] = trim($value);
	}
	if (count($attributes) > 0) {
		if (!$flattenAttributes) {
			$return[$attributesKey] = $attributes;
		} else {
			$return = array_merge($return, $attributes);
		}
	}

	return $return;
}
Exemplo n.º 2
0
 /**
  * This function checks if the theme designer has thunk to make his theme compatible 1.4,
  * and noticed it on the $theme_dir/config.xml file. If not, some new functionnalities has
  * to be desactivated
  *
  * @since 1.4
  *
  * @param string $theme_dir theme directory
  *
  * @return boolean Validity is ok or not
  */
 protected function _isThemeCompatible($theme_dir)
 {
     $return = true;
     $check_version = AdminThemes::$check_features_version;
     if (!is_file(_PS_ALL_THEMES_DIR_ . $theme_dir . '/config.xml')) {
         $this->errors[] = Tools::displayError('config.xml is missing in your theme path.') . '<br/>';
         $xml = null;
     } else {
         $xml = @simplexml_load_file(_PS_ALL_THEMES_DIR_ . $theme_dir . '/config.xml');
         if (!$xml) {
             $this->errors[] = Tools::displayError('config.xml is not a valid xml file in your theme path.') . '<br/>';
         }
     }
     // will be set to false if any version node in xml is correct
     $xml_version_too_old = true;
     // foreach version in xml file,
     // node means feature, attributes has to match
     // the corresponding value in AdminThemes::$check_features[feature] array
     $xmlArray = simpleXMLToArray($xml);
     foreach ($xmlArray as $version) {
         if (isset($version['value']) && version_compare($version['value'], $check_version) >= 0) {
             foreach (AdminThemes::$check_features as $codeFeature => $arrConfigToCheck) {
                 foreach ($arrConfigToCheck['attributes'] as $attr => $v) {
                     if (!isset($version[$codeFeature]) || !isset($version[$codeFeature][$attr]) || $version[$codeFeature][$attr] != $v['value']) {
                         if (!$this->_checkConfigForFeatures($codeFeature, $attr)) {
                             // feature missing in config.xml file, or wrong attribute value
                             $return = false;
                         }
                     }
                 }
             }
             $xml_version_too_old = false;
         }
     }
     if ($xml_version_too_old && !$this->_checkConfigForFeatures(array_keys(AdminThemes::$check_features))) {
         $this->errors[] .= Tools::displayError('config.xml theme file has not been created for this version of PrestaShop.');
         $return = false;
     }
     return $return;
 }
Exemplo n.º 3
0
function xmlStringToArray($string)
{
    $xmlObj = simplexml_load_string($string);
    $xmlArray = simpleXMLToArray($xmlObj);
    return $xmlArray;
}
Exemplo n.º 4
0
 function get($count = 20)
 {
     $username = $this->username;
     // Append the count
     $url = $this->feedUrl;
     $url .= '?count=' . $count;
     $tweets_cache_path = get_template_directory() . '/cache/twitter_' . $username . '_' . $count . '.cache';
     if (file_exists($tweets_cache_path)) {
         $tweets_cache_timer = intval((time() - filemtime($tweets_cache_path)) / 60);
     } else {
         $tweets_cache_timer = 0;
     }
     if (!file_exists($tweets_cache_path) or $tweets_cache_timer > 15) {
         // The http CURL thingy
         $curl_handle = curl_init();
         curl_setopt($curl_handle, CURLOPT_URL, $url);
         curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($curl_handle, CURLOPT_TIMEOUT, 10);
         //10 secs max
         $data = curl_exec($curl_handle);
         curl_close($curl_handle);
         // Some error? Return an empty array
         // You may want to extend this to know the exact error
         // echo curl_error($curl_handle);
         // or know the http status
         // echo curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
         if (!$data) {
             return array();
         }
         // Some reformatting
         $pattern = array('/[^(:\\/\\/)](www\\.[^ \\n\\r]+)/', '/(https?:\\/\\/[^ \\n\\r]+)/', '/@(\\w+)/', '/^' . $username . ':\\s*/i');
         $replace = array('<a href="http://$1" rel="nofollow">$1</a>', '<a href="$1" rel="nofollow">$1</a>', '<a href="http://twitter.com/$1" rel="nofollow">@$1</a>' . '');
         $tweets = array();
         $xml = simplexml_load_string($data);
         $array_tweets = simpleXMLToArray($xml);
         if (!empty($array_tweets['channel']['item']) && isset($array_tweets['channel']['item'])) {
             foreach ($array_tweets['channel']['item'] as $item) {
                 $tweet = preg_replace($pattern, $replace, $item['description']);
                 $date = $this->since($item['pubDate']);
                 $permalink = $item['link'];
                 $tweets[] = array($tweet, $date, $permalink);
             }
         }
         if (file_exists($tweets_cache_path)) {
             unlink($tweets_cache_path);
         }
         if (!empty($array_tweets)) {
             $myFile = $tweets_cache_path;
             $fh = fopen($myFile, 'w') or die("can't open file");
             $stringData = serialize($array_tweets);
             fwrite($fh, $stringData);
             fclose($fh);
         }
     } else {
         error_reporting(0);
         $file = file_get_contents($tweets_cache_path, true);
         // Some reformatting
         $pattern = array('/[^(:\\/\\/)](www\\.[^ \\n\\r]+)/', '/(https?:\\/\\/[^ \\n\\r]+)/', '/@(\\w+)/', '/^' . $username . ':\\s*/i');
         $replace = array('<a href="http://$1" rel="nofollow">$1</a>', '<a href="$1" rel="nofollow">$1</a>', '<a href="http://twitter.com/$1" rel="nofollow">@$1</a>' . '');
         if (!empty($file)) {
             $array_tweets = unserialize($file);
             $tweets = array();
             if (!empty($array_tweets['channel']['item']) && isset($array_tweets['channel']['item'])) {
                 foreach ($array_tweets['channel']['item'] as $item) {
                     $tweet = preg_replace($pattern, $replace, $item['description']);
                     $date = $this->since($item['pubDate']);
                     $permalink = $item['link'];
                     $tweets[] = array($tweet, $date, $permalink);
                 }
             }
         }
     }
     return $tweets;
 }