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