modx.evo.custom /assets/snippets/jot/actions/treecomments.inc.php

Language PHP Lines 132
MD5 Hash 0cc4ae7550112406f78271ad7eff6613
Repository https://github.com/good-web-master/modx.evo.custom.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
	// Display comments
	function treecomments_mode(&$object) {
		global $modx;
		
		$output_comments = NULL;
		// Check if viewing is allowed
		if($object->canView) {
			
			// View (Moderation)
			$view = 1;
			if ($object->isModerator) { 
				$view = $object->config["moderation"]["view"];
				$object->config["moderation"]["unpublished"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],0,$object->config["userids"]);
				$object->config["moderation"]["published"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],1,$object->config["userids"]);
				$object->config["moderation"]["mixed"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],2,$object->config["userids"]);
			}
			
			// Render Moderation Options
			if ($object->isModerator) { 
				$tpl = new CChunkie($object->templates["moderate"]);
				$tpl->AddVar('jot',$object->config);
				$object->config["html"]["moderate"] = $tpl->Render();
			}
			
			// Render subscription options
			$tpl = new CChunkie($object->templates["subscribe"]);
			$tpl->AddVar('jot',$object->config);
			$object->config["html"]["subscribe"] = $tpl->Render();
			
			// Get comments
			$array_comments = $object->provider->GetComments($object->config["docids"],$object->config["tagids"],$view,$object->config["upc"],$object->config["sortby"],0,0,$object->config["userids"]);	
			
			// Get comments count
			$count = count($array_comments);
			
			// Comment Numbering
			for ($i = 0; $i < $count; $i++) {
				$num = ($object->config["numdir"]) ? $count-$i :  $i+1;
				if (substr($object->config["sortby"], -1)=='a') $array_comments[$i]["postnumber"] = $count - $num + 1;
				else $array_comments[$i]["postnumber"] = $num;
			}
			
			// Get tree
			$tree = array();
			foreach ($array_comments as $row) {
				$tree[(int) $row['parent']][] = $row;
			}
			unset($array_comments);
			
			// Get first level comments count
			$commentTotal = count($tree[0]);
			
			// Get total number of comments
			$limit = $object->config["limit"];
			$commentTotal = ($limit>0 && $limit<$commentTotal) ? $limit : $commentTotal;
			$pagination = (isset($_GET[$object->config["querykey"]["navigation"]]) && $_GET[$object->config["querykey"]["navigation"]] == 0) ? 0 : $object->config["pagination"];
			
			// Apply pagination if enabled
			if ($pagination > 0) {
				$pageLength = ($limit>0 && $limit<$pagination) ? $limit : $pagination;
				$pageTotal = ceil($commentTotal / $pageLength);
				$pageCurrent = isset($_GET[$object->config["querykey"]["navigation"]]) ? intval($_GET[$object->config["querykey"]["navigation"]]): 1;
				if ( ($pageCurrent < 1) || ($pageCurrent > $pageTotal) ) { $pageCurrent = 1; };
				$pageOffset = (($pageCurrent*$pageLength)-$pageLength);
				$navStart = ($pageOffset+1);
				$navEnd = ($pageOffset+$pageLength) > $commentTotal ? $commentTotal : ($pageOffset+$pageLength);
			} else {
				$pageLength = $commentTotal;
				$pageOffset = 0;
				$pageTotal = 1;
				$pageCurrent = 1;
				$navStart = 0;
				$navEnd = $commentTotal;
			}
			
			if (is_array($tree[0]))  $tree[0] = array_slice($tree[0],$pageOffset,$pageLength);
			
			// Navigation
			$object->config['nav'] = array('total'=>$commentTotal,'start'=>$navStart,'end'=> $navEnd);
			$object->config['page'] = array('length'=>$pageLength,'total'=>$pageTotal,'current'=>$pageCurrent);
			
			// Render navigation
			if (($pagination > 0) && ($pageTotal > 1) ) {
				$tpl = new CChunkie($object->templates["navigation"]);
				$tplPage = $tpl->getTemplate($object->templates["navPage"]);
				$tplPageCur = $tpl->getTemplate($object->templates["navPageCur"]);
				$tplPageSpl = $tpl->getTemplate($object->templates["navPageSpl"]);
				$pages = '';
				for ($i = 1; $i <= $pageTotal; $i++) {
					$pages .= ($i == $pageCurrent) ? str_replace('[+jot.page.num+]',$i,$tplPageCur) : str_replace('[+jot.page.num+]',$i,$tplPage);
					if ($i< $pageTotal) $pages .= $tplPageSpl;
				}
				$tpl->template = str_replace('[+jot.pages+]',$pages,$tpl->template);
				$tpl->AddVar('jot',$object->config);
				$object->config["html"]["navigation"] = $tpl->Render();
			}
			
			function treeRender($tree, $pid, &$object, $depth) {
				global $modx;
				if (empty($tree[$pid])) return;
				$res = '';
				foreach ($tree[$pid] as $k=>$row) {
					$chunk["rowclass"] = $object->getChunkRowClass($k+1,$row["createdby"]);
					$tpl = new CChunkie($object->templates["comments"]);
					$row["parentlink"] = $object->preserveUrl($modx->documentIdentifier,'',array_merge($object->_link,array('parent'=>$row["id"])));
					$row["depth"] = $depth;
					$tpl->AddVar('jot',$object->config);
					$tpl->AddVar('comment',$row);
					$tpl->AddVar('chunk',$chunk);
					if (isset($tree[$row['id']]) &&  $object->config["depth"] > $depth) {
						$tpl->AddVar('jot.wrapper',treeRender($tree, $row['id'], $object, $depth+1));
					}
					$res .= $tpl->Render();
				}
				return $res;
			}
			
			/* Render comments */
			$object->config["html"]["comments"] = treeRender($tree, 0 , $object, 1);
			unset($tree);
			
			//onSetCommentsOutput event
			if (null !== ($output = $object->doEvent("onSetCommentsOutput"))) return $output;
			
			$output_comments = $object->config["html"]["subscribe"] . $object->config["html"]["moderate"] .
			$object->config["html"]["navigation"] . $object->config["html"]["comments"] . $object->config["html"]["navigation"];
		}
		if ($object->config["output"]) return $output_comments;
	}
?>
Back to Top