PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/assets/snippets/jot/actions/comments.inc.php

https://github.com/good-web-master/modx.evo.custom
PHP | 105 lines | 79 code | 13 blank | 13 comment | 20 complexity | 7f918ee520faa4cae45943f1cf6a22a6 MD5 | raw file
  1<?php
  2	// Display comments
  3	function comments_mode(&$object) {
  4		global $modx;
  5		
  6		$output_comments = NULL;
  7		// Check if viewing is allowed
  8		if($object->canView) {
  9			
 10			// View (Moderation)
 11			$view = 1;
 12			if ($object->isModerator) { 
 13				$view = $object->config["moderation"]["view"];
 14				$object->config["moderation"]["unpublished"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],0,$object->config["userids"]);
 15				$object->config["moderation"]["published"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],1,$object->config["userids"]);
 16				$object->config["moderation"]["mixed"] = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],2,$object->config["userids"]);
 17			}
 18			
 19			// Get total number of comments
 20			$commentTotal = $object->provider->GetCommentCount($object->config["docids"],$object->config["tagids"],$view,$object->config["userids"]);
 21			$limit = $object->config["limit"];
 22			$commentTotal = ($limit>0 && $limit<$commentTotal) ? $limit : $commentTotal;
 23			$pagination = (isset($_GET[$object->config["querykey"]["navigation"]]) && $_GET[$object->config["querykey"]["navigation"]] == 0) ? 0 : $object->config["pagination"];
 24			
 25			// Apply pagination if enabled
 26			if ($pagination > 0) {
 27				$pageLength = ($limit>0 && $limit<$pagination) ? $limit : $pagination;
 28				$pageTotal = ceil($commentTotal / $pageLength);
 29				$pageCurrent = isset($_GET[$object->config["querykey"]["navigation"]]) ? $_GET[$object->config["querykey"]["navigation"]]: 1;
 30				if ( ($pageCurrent < 1) || ($pageCurrent > $pageTotal) ) { $pageCurrent = 1; };
 31				$pageOffset = (($pageCurrent*$pageLength)-$pageLength);
 32				$navStart = ($pageOffset+1);
 33				$navEnd = ($pageOffset+$pageLength) > $commentTotal ? $commentTotal : ($pageOffset+$pageLength);
 34			} else {
 35				$pageLength = $limit;
 36				$pageOffset = 0;
 37				$pageTotal = 1;
 38				$pageCurrent = 1;
 39				$navStart = 0;
 40				$navEnd = $commentTotal;
 41			}
 42			
 43			// Navigation
 44			$object->config['nav'] = array('total'=>$commentTotal,'start'=>$navStart,'end'=> $navEnd);
 45			$object->config['page'] = array('length'=>$pageLength,'total'=>$pageTotal,'current'=>$pageCurrent);
 46			
 47			// Render Moderation Options
 48			if ($object->isModerator) { 
 49				$tpl = new CChunkie($object->templates["moderate"]);
 50				$tpl->AddVar('jot',$object->config);
 51				$object->config["html"]["moderate"] = $tpl->Render();
 52			}
 53			
 54			// Get comments
 55			$array_comments = $object->provider->GetComments($object->config["docids"],$object->config["tagids"],$view,$object->config["upc"],$object->config["sortby"],$pageOffset,$pageLength,$object->config["userids"]);
 56			
 57			// Render navigation
 58			if (($pagination > 0) && ($pageTotal > 1) ) {
 59				$tpl = new CChunkie($object->templates["navigation"]);
 60				$tplPage = $tpl->getTemplate($object->templates["navPage"]);
 61				$tplPageCur = $tpl->getTemplate($object->templates["navPageCur"]);
 62				$tplPageSpl = $tpl->getTemplate($object->templates["navPageSpl"]);
 63				$pages = '';
 64				for ($i = 1; $i <= $pageTotal; $i++) {
 65					$pages .= ($i == $pageCurrent) ? str_replace('[+jot.page.num+]',$i,$tplPageCur) : str_replace('[+jot.page.num+]',$i,$tplPage);
 66					if ($i< $pageTotal) $pages .= $tplPageSpl;
 67				}
 68				$tpl->template = str_replace('[+jot.pages+]',$pages,$tpl->template);
 69				$tpl->AddVar('jot',$object->config);
 70				$object->config["html"]["navigation"] = $tpl->Render();
 71			}	
 72			
 73			// Render subscription options
 74			$tpl = new CChunkie($object->templates["subscribe"]);
 75			$tpl->AddVar('jot',$object->config);
 76			$object->config["html"]["subscribe"] = $output_subscribe = $tpl->Render();
 77			
 78			// Render comments
 79			$count = count($array_comments);
 80			$comments = array();
 81			
 82			// Comment Numbering
 83			for ($i = 0; $i < $count; $i++) {
 84				$num = ($object->config["numdir"]) ? $commentTotal - ($pageOffset + $i) :  $pageOffset + ($i+1);
 85				$array_comments[$i]["postnumber"] = $num;
 86			}
 87			for ($i = 0; $i < $count; $i++) {
 88				$chunk["rowclass"] = $object->getChunkRowClass($i+1,$array_comments[$i]["createdby"]);
 89				$tpl = new CChunkie($object->templates["comments"]);
 90				$tpl->AddVar('jot',$object->config);
 91				$tpl->AddVar('comment',$array_comments[$i]);
 92				$tpl->AddVar('chunk',$chunk);
 93				$comments[] = $tpl->Render();
 94			}
 95			$object->config["html"]["comments"] = join("",$comments);
 96			
 97			//onSetCommentsOutput event
 98			if (null !== ($output = $object->doEvent("onSetCommentsOutput"))) return $output;
 99			
100			$output_comments = $object->config["html"]["subscribe"] . $object->config["html"]["moderate"] .
101			$object->config["html"]["navigation"] . $object->config["html"]["comments"] . $object->config["html"]["navigation"];
102		}
103		if ($object->config["output"]) return $output_comments;
104	}
105?>