function lastcomments_mode(&$object) { global $modx; $output_comments = NULL; // Check if viewing is allowed if ($object->canView) { // Get comments $limit = $object->config["limit"] > 0 ? $object->config["limit"] : 3; $array_comments = $object->provider->GetComments("*", $object->config["tagids"], 1, $object->config["upc"], $object->config["sortby"], 0, $limit, $object->config["userids"]); // Render comments $count = count($array_comments); $comments = array(); // Comment Numbering for ($i = 0; $i < $count; $i++) { $num = $object->config["numdir"] ? $count - $i : $i + 1; $array_comments[$i]["postnumber"] = $num; } for ($i = 0; $i < $count; $i++) { $chunk["rowclass"] = $object->getChunkRowClass($i + 1, $array_comments[$i]["createdby"]); $tpl = new CChunkie($object->templates["comments"]); $tpl->AddVar('jot', $object->config); $tpl->AddVar('comment', $array_comments[$i]); $tpl->AddVar('chunk', $chunk); $comments[] = $tpl->Render(); } $object->config["html"]["comments"] = join("", $comments); //onSetCommentsOutput event if (null !== ($output = $object->doEvent("onSetCommentsOutput"))) { return $output; } $output_comments = $object->config["html"]["comments"]; } if ($object->config["output"]) { return $output_comments; } }
function form_mode(&$object) { global $modx; $output_form = NULL; //---- Allow post? if ($object->canPost) { // Render Form $tpl = new CChunkie($object->templates["form"]); $tpl->AddVar('jot', $object->config); $tpl->AddVar('form', $object->form); $object->config["html"]["form"] = $tpl->Render(); $object->config["html"]["form"] = preg_replace('~\\[\\+(.*?)\\+\\]~s', '', $object->config["html"]["form"]); //onSetFormOutput event if (null !== ($output = $object->doEvent("onSetFormOutput"))) { return $output; } $output_form = $object->config["html"]["form"]; } // ----- // Output or placeholder? if ($object->config["output"]) { return $output_form; } }
function doNotifyAuthor($commentid = 0) { echo '<!-- notifying author -->'; global $modx; if ($this->config["moderation"]["notifyAuthor"]) { // What is the e-mail address of the article author? $author_id = $this->config['authorid']; $res = $modx->db->select('*', $modx->getFullTableName('user_attributes'), "id = '{$author_id}'"); $results_array = $modx->db->makeArray($res); $user = $results_array[0]; // Assume there is only one result // Get comment fields (copied from doNotifyModerators) $cObj = $this->provider; $cObj->Comment($commentid); $comment = $cObj->getFields(); unset($cObj); $tpl = new CChunkie($this->templates["notifyauthor"]); $tpl->AddVar('jot', $this->config); $tpl->AddVar('comment', $comment); $tpl->AddVar('siteurl', "http://" . $_SERVER["SERVER_NAME"]); $tpl->AddVar('recipient', $user); $message = $tpl->Render(); mail($user["email"], $this->config["subject"]["author"], $message, "From: " . $modx->config['emailsender'] . "\r\n" . "X-Mailer: Content Manager - PHP/" . phpversion()); } }
function comments_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"]); } // Get total number of comments $commentTotal = $object->provider->GetCommentCount($object->config["docids"], $object->config["tagids"], $view, $object->config["userids"]); $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"]; $pageAdjacents = $object->config["pageAdjacents"]; // Apply pagination if enabled if ($pagination > 0) { $pageLength = $limit > 0 && $limit < $pagination ? $limit : $pagination; $lastPage = $pageTotal = ceil($commentTotal / $pageLength); $pageCurrent = isset($_GET[$object->config["querykey"]["navigation"]]) ? $_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 = $limit; $pageOffset = 0; $lastPage = $pageTotal = 1; $pageCurrent = 1; $navStart = 0; $navEnd = $commentTotal; } // Navigation $object->config['nav'] = array('total' => $commentTotal, 'start' => $navStart, 'end' => $navEnd); $object->config['page'] = array('length' => $pageLength, 'total' => $pageTotal, 'current' => $pageCurrent); // Render Moderation Options if ($object->isModerator) { $tpl = new CChunkie($object->templates["moderate"]); $tpl->AddVar('jot', $object->config); $object->config["html"]["moderate"] = $tpl->Render(); } // Get comments $array_comments = $object->provider->GetComments($object->config["docids"], $object->config["tagids"], $view, $object->config["upc"], $object->config["sortby"], $pageOffset, $pageLength, $object->config["userids"]); // 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"]); $tplDots = $tpl->getTemplate($object->templates["navPageDots"]); $pages = ''; //pages if ($lastPage < 7 + $pageAdjacents * 2) { //not enough pages to bother breaking it up for ($counter = 1; $counter <= $lastPage; $counter++) { if ($counter == $pageCurrent) { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPageCur); } else { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPage); } // other pages } } elseif ($lastPage > 5 + $pageAdjacents * 2) { //enough pages to hide some //close to beginning; only hide later pages if ($pageCurrent < 1 + $pageAdjacents * 2) { for ($counter = 1; $counter < 4 + $pageAdjacents * 2; $counter++) { if ($counter == $pageCurrent) { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPageCur) . $tplPageSpl; } else { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPage) . $tplPageSpl; } // other pages } $pages .= str_replace('[+jot.page.num+]', $counter, $tplDots) . $tplPageSpl; $pages .= str_replace('[+jot.page.num+]', $lastPage - 1, $tplPage) . $tplPageSpl; $pages .= str_replace('[+jot.page.num+]', $lastPage, $tplPage); } elseif ($lastPage - $pageAdjacents * 2 > $pageCurrent && $pageCurrent > $pageAdjacents * 2) { $pages .= str_replace('[+jot.page.num+]', 1, $tplPage) . $tplPageSpl; // first page $pages .= str_replace('[+jot.page.num+]', 2, $tplPage) . $tplPageSpl; // second page $pages .= str_replace('[+jot.page.num+]', 3, $tplDots) . $tplPageSpl; for ($counter = $pageCurrent - $pageAdjacents; $counter <= $pageCurrent + $pageAdjacents; $counter++) { if ($counter == $pageCurrent) { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPageCur) . $tplPageSpl; } else { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPage) . $tplPageSpl; } } // other pages $pages .= str_replace('[+jot.page.num+]', $counter, $tplDots) . $tplPageSpl; $pages .= str_replace('[+jot.page.num+]', $lastPage - 1, $tplPage) . $tplPageSpl; // page before the last $pages .= str_replace('[+jot.page.num+]', $lastPage, $tplPage); // last page } else { $pages .= str_replace('[+jot.page.num+]', 1, $tplPage) . $tplPageSpl; // first page $pages .= str_replace('[+jot.page.num+]', 2, $tplPage) . $tplPageSpl; // second page; $pages .= str_replace('[+jot.page.num+]', 3, $tplDots) . $tplPageSpl; for ($counter = $lastPage - (2 + $pageAdjacents * 2); $counter <= $lastPage; $counter++) { if ($counter == $pageCurrent) { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPageCur); } else { $pages .= str_replace('[+jot.page.num+]', $counter, $tplPage); } // other pages if ($counter < $lastPage) { $pages .= $tplPageSpl; } } } } $tpl->template = str_replace('[+jot.pages+]', $pages, $tpl->template); $tpl->AddVar('jot', $object->config); $object->config["html"]["navigation"] = $tpl->Render(); } // Render subscription options $tpl = new CChunkie($object->templates["subscribe"]); $tpl->AddVar('jot', $object->config); $object->config["html"]["subscribe"] = $output_subscribe = $tpl->Render(); // Render comments $count = count($array_comments); $comments = array(); // Comment Numbering for ($i = 0; $i < $count; $i++) { $num = $object->config["numdir"] ? $commentTotal - ($pageOffset + $i) : $pageOffset + ($i + 1); $array_comments[$i]["postnumber"] = $num; } for ($i = 0; $i < $count; $i++) { $chunk["rowclass"] = $object->getChunkRowClass($i + 1, $array_comments[$i]["createdby"]); $tpl = new CChunkie($object->templates["comments"]); $tpl->AddVar('jot', $object->config); $tpl->AddVar('comment', $array_comments[$i]); $tpl->AddVar('chunk', $chunk); $comments[] = $tpl->Render(); } $object->config["html"]["comments"] = join("", $comments); //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; } }
function doNotify($commentid = 0, $action = "notify") { global $modx; // Get comment fields $cObj = $this->provider; $cObj->Comment($commentid); $comment = $cObj->getFields(); unset($cObj); switch ($action) { case "notify": $user_ids = $this->provider->getSubscriptions($this->config["docid"], $this->config["tagid"]); $subject = $this->config["subject"]["subscribe"]; break; case "notifymoderator": $user_ids = $this->getMembersOfWebGroup($this->config["permissions"]["moderate"]); $subject = $this->config["subject"]["moderate"]; break; case "notifyauthor": $user_ids = array($this->config["authorid"]); $subject = $this->config["subject"]["author"]; break; case "notifyemails": $user_ids = $this->config["notifyEmails"]; $subject = $this->config["subject"]["emails"]; break; } include_once MODX_MANAGER_PATH . "includes/controls/class.phpmailer.php"; foreach ($user_ids as $user_id) { if ($this->config["user"]["id"] !== $user_id) { if ($action == "notifyemails") { $user = array(); $user["email"] = $user_id; $user["username"] = $this->config["notifyNames"][$user_id]; } else { $user = $this->getUserInfo($user_id); } $tpl = new CChunkie($this->templates[$action]); $tpl->AddVar("siteurl", "http://" . $_SERVER["SERVER_NAME"]); //onBeforeNotify event if (null === $this->doEvent("onBeforeNotify", array("commentid" => $commentid, "action" => $action, "tpl" => &$tpl, "subject" => &$subject, "comment" => &$comment, "user" => &$user))) { $tpl->AddVar("jot", $this->config); $tpl->AddVar("comment", $comment); $tpl->AddVar("recipient", $user); $mail = new PHPMailer(); $mail->IsMail(); $mail->CharSet = $modx->config["modx_charset"]; $mail->IsHTML(false); $mail->From = $modx->config["emailsender"]; $mail->FromName = $modx->config["site_name"]; $mail->Subject = $subject; $mail->Body = $tpl->Render(); $mail->AddAddress($user["email"]); $mail->Send(); } } } }
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)); } else { $tpl->AddVar('jot.wrapper', ''); } $res .= $tpl->Render(); } return $res; }