<commit_before><?php

class Pagemill_Tag_Loop extends Pagemill_Tag {
	private $_name;
	private $_data;
	private $_stream;
	private $_as;
	private $_asKey;
	private $_cycle;
	private $_delimiter;
	private $_originalData;
	private $_sortKey;
	private static $_pointer = '';
	/**
	 * The sort callback.
	 */
	private function _cmp($a, $b) {
		// convert sort key into trimmed array of arguments
		foreach (array_map('trim', explode(',', $this->_sortKey)) as $arg) {
			// set key and direction from arg
			list($key, $dir) = (is_int(strpos($arg, ' ')) ?
							explode(' ', $arg) :
							array($arg, ''));
			// set resulting direction
			$result = (('desc' == strtolower($dir)) ? -1 : 1);
			// get values from a and b using key
			$ak = $a[$key];
			$bk = $b[$key];
			// a is less than b
			if ($ak < $bk)
				return -$result;
			// a is greater than b
			if ($ak > $bk)
				return $result;
		}
		// a and b are equal
		return 0;
	}
	public function output(Pagemill_Data $data, Pagemill_Stream $stream) {
		$oldPointer = self::$_pointer;
		$cycle = $data->parseVariables($this->getAttribute('cycle'));
		if ($cycle) {
			$cycle = explode(',', $data->parseVariables($this->getAttribute('cycle')));
		}
		$name = $data->parseVariables($this->getAttribute('name'));
		$times = $data->parseVariables($this->getAttribute('times'));
		$delimiter = $this->getAttribute('delimiter');
		$loopTimes = 0;

		// get as attribute
		$as = $this->getAttribute('as');
		$asKey = null;
		if (strpos($as, ' ') !== false) {
			list($asKey, $as) = explode(' ', $as);
			$as = trim($as);
			$asKey = trim($asKey);
			if (!$as) {
				$as = $asKey;
				$asKey = null;
			}
		}

		$this->_name = $name;
		$this->_originalData = $data->getArray();
		$this->_data = $data;
		$this->_stream = $stream;
		$this->_as = $as;
		$this->_asKey = $asKey;
		$this->_cycle = $cycle;
		$this->_delimiter = $delimiter;
		
		// if name given...
		if ($name) {
			$children = $data->evaluate($name);
			if (is_null($children) || is_scalar($children)) return;
			if (is_array($children) || $children instanceof Countable) {
				if (count($children) == 0) return;
			}
			self::$_pointer .= '[' . $name . ']';
			$data->set('pointer', self::$_pointer);<commit_msg>Ignore Pagemill_Data variables when checking count of loop value.<commit_after><?php

class Pagemill_Tag_Loop extends Pagemill_Tag {
	private $_name;
	private $_data;
	private $_stream;
	private $_as;
	private $_asKey;
	private $_cycle;
	private $_delimiter;
	private $_originalData;
	private $_sortKey;
	private static $_pointer = '';
	/**
	 * The sort callback.
	 */
	private function _cmp($a, $b) {
		// convert sort key into trimmed array of arguments
		foreach (array_map('trim', explode(',', $this->_sortKey)) as $arg) {
			// set key and direction from arg
			list($key, $dir) = (is_int(strpos($arg, ' ')) ?
							explode(' ', $arg) :
							array($arg, ''));
			// set resulting direction
			$result = (('desc' == strtolower($dir)) ? -1 : 1);
			// get values from a and b using key
			$ak = $a[$key];
			$bk = $b[$key];
			// a is less than b
			if ($ak < $bk)
				return -$result;
			// a is greater than b
			if ($ak > $bk)
				return $result;
		}
		// a and b are equal
		return 0;
	}
	public function output(Pagemill_Data $data, Pagemill_Stream $stream) {
		$oldPointer = self::$_pointer;
		$cycle = $data->parseVariables($this->getAttribute('cycle'));
		if ($cycle) {
			$cycle = explode(',', $data->parseVariables($this->getAttribute('cycle')));
		}
		$name = $data->parseVariables($this->getAttribute('name'));
		$times = $data->parseVariables($this->getAttribute('times'));
		$delimiter = $this->getAttribute('delimiter');
		$loopTimes = 0;

		// get as attribute
		$as = $this->getAttribute('as');
		$asKey = null;
		if (strpos($as, ' ') !== false) {
			list($asKey, $as) = explode(' ', $as);
			$as = trim($as);
			$asKey = trim($asKey);
			if (!$as) {
				$as = $asKey;
				$asKey = null;
			}
		}

		$this->_name = $name;
		$this->_originalData = $data->getArray();
		$this->_data = $data;
		$this->_stream = $stream;
		$this->_as = $as;
		$this->_asKey = $asKey;
		$this->_cycle = $cycle;
		$this->_delimiter = $delimiter;
		
		// if name given...
		if ($name) {
			$children = $data->evaluate($name);
			if (is_null($children) || is_scalar($children)) return;
			if (!is_a($children, 'Pagemill_Data') && (is_array($children) || $children instanceof Countable)) {
				if (count($children) == 0) return;
			}
			self::$_pointer .= '[' . $name . ']';
			$data->set('pointer', self::$_pointer);
{'fraction_non_alphanumeric': 0.1974873264271545, 'fraction_numerical': 0.002204099625303064, 'mean_word_length': 3.4359726295210167, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2108300', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1587, 'n_words': 395}