SHARE
TWEET

Untitled

a guest Aug 21st, 2015 3 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php if (!defined("APPLICATION")) exit();
  2. /*
  3.  *  (C) Copyright 2011, canofsleep.com
  4.  *
  5.  *  Licensed under the Apache License, Version 2.0 (the "License");
  6.  *  you may not use this file except in compliance with the License.
  7.  *  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17.  
  18. $PluginInfo["NillaBlog"] = array(
  19.         "Name" => "NillaBlog",
  20.         "Description" => "A blog plugin for Vanilla 2+ (http://vanillaforums.org)",
  21.         "Version" => "1.8.1",
  22.         "Author" => "Dan Dumont",
  23.         "AuthorEmail" => "ddumont@gmail.com",
  24.         "AuthorUrl" => "https://github.com/ddumont/nillablog",
  25.         "SettingsUrl" => "/dashboard/settings/nillablog",
  26.         "SettingsPermission" => "Garden.Settings.Manage",
  27.         "RequiredApplications" => array("Vanilla" => "2.0.18") // This needs to be bumped when Vanilla releases with my contributed changes
  28. );
  29.  
  30. /**
  31.  * NillaBlog plugin for Vanilla
  32.  * @author ddumont@gmail.com
  33.  */
  34. class NillaBlog extends Gdn_Plugin {
  35.  
  36.         /**
  37.          * Build the setting page.
  38.          * @param $Sender
  39.          */
  40.         public function SettingsController_NillaBlog_Create($Sender) {
  41.                 $Sender->Permission('Garden.Settings.Manage');
  42.  
  43.                 $Validation = new Gdn_Validation();
  44.                 $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
  45.                 $ConfigurationModel->SetField(array("Plugins.NillaBlog.CategoryIDs"));
  46.                 $ConfigurationModel->SetField("Plugins.NillaBlog.DisableCSS");
  47.                 $ConfigurationModel->SetField("Plugins.NillaBlog.PostsPerPage");
  48.                 $ConfigurationModel->SetField("Plugins.NillaBlog.GooglePlusOne");
  49.                 $Sender->Form->SetModel($ConfigurationModel);
  50.  
  51.                 if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
  52.                         $Sender->Form->SetData($ConfigurationModel->Data);
  53.                 } else {
  54.                 $Data = $Sender->Form->FormValues();
  55. //              $ConfigurationModel->Validation->ApplyRule("Plugins.NillaBlog.CategoryIDs", "RequiredArray");  // Not required
  56.                         $ConfigurationModel->Validation->ApplyRule("Plugins.NillaBlog.PostsPerPage", "Integer");
  57.                 if ($Sender->Form->Save() !== FALSE)
  58.                         $Sender->StatusMessage = T("Your settings have been saved.");
  59.                 }
  60.  
  61.                 $Sender->AddSideMenu();
  62.                 $Sender->SetData("Title", T("NillaBlog Settings"));
  63.  
  64.                 $CategoryModel = new CategoryModel();
  65.                 $Sender->SetData("CategoryData", $CategoryModel->GetAll(), TRUE);
  66.                 array_shift($Sender->CategoryData->Result());
  67.  
  68.                 $Sender->Render($this->GetView("settings.php"));
  69.         }
  70.  
  71.         /**
  72.          * Adjusts the number of posts to display in the blog category.
  73.          * @param $Sender
  74.          */
  75.         public function CategoriesController_BeforeGetDiscussions_Handler($Sender) {
  76.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) )
  77.                         return;
  78.                 $Sender->EventArguments['PerPage'] = C("Plugins.NillaBlog.PostsPerPage");
  79.         }
  80.  
  81.         /**
  82.          * Insert the first comment under the discussion title for the blog category.
  83.          * This turns the blog category into a list of blog posts.
  84.          * @param $Sender
  85.          */
  86.         public function CategoriesController_AfterDiscussionTitle_Handler($Sender) {
  87.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) )
  88.                         return;
  89.  
  90.                 $Discussion = $Sender->EventArguments['Discussion'];
  91.  
  92.                 $Body = $Discussion->Body;
  93.                 $end = strrpos($Body, "<hr");
  94.                 if ($end)
  95.                         $Body = substr($Body, 0, $end);
  96.                 $Discussion->FormatBody = Gdn_Format::To($Body, $Discussion->Format);
  97.                 ?>
  98.                         <ul class="MessageList">
  99.                                 <li>
  100.                                         <div class="Message">
  101.                                                 <?php echo $Discussion->FormatBody; ?>
  102.                                         </div>
  103.                                 </li>
  104.                                 <?php if ($end) { ?>
  105.                                         <li>
  106.                                                 <a href="<?php echo Gdn::Request()->Url(ConcatSep("/", "discussion", $Discussion->DiscussionID, Gdn_Format::Url($Discussion->Name)))?>"
  107.                                                    class="More"><?php echo T("Read more");?></a>
  108.                                         </li>
  109.                                 <?php } ?>
  110.                         </ul>
  111.                 <?php
  112.         }
  113.  
  114.         /**
  115.          * Adds the blog subscription link to each post for easier access.
  116.          * @param $Sender
  117.          */
  118.         public function CategoriesController_DiscussionMeta_Handler($Sender) {
  119.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) )
  120.                         return;
  121.  
  122.                 $Discussion = $Sender->EventArguments['Discussion'];
  123.                 ?>
  124.                         <span class='RSS'>
  125.                                 <a href='<?php echo Gdn::Request()->Url(ConcatSep("/", $Sender->SelfUrl, "feed.rss")); ?>'>
  126.                                         <img src="<?php echo Asset("/applications/dashboard/design/images/rss.gif"); ?>"></img>
  127.                                         <?php echo T("Subscribe to this blog"); ?>
  128.                                 </a>
  129.                         </span>
  130.                 <?php
  131.  
  132.                 if (C("Plugins.NillaBlog.GooglePlusOne")) {
  133.                         ?><span class='plusone'>
  134.                                 <g:plusone href="<?php echo Gdn::Request()->Url(ConcatSep("/", "discussion", $Discussion->DiscussionID, Gdn_Format::Url($Discussion->Name)), TRUE);
  135.                                         ?>" size="medium">
  136.                                 </g:plusone>
  137.                         </span><?php
  138.                 }
  139.         }
  140.  
  141.         /**
  142.          * Adds the class 'NillaBlog' to every discussion in the blog category list.
  143.          * Allows for themes to style the blog independently of the plugin.
  144.          * @param $Sender
  145.          */
  146.         public function CategoriesController_BeforeDiscussionName_Handler($Sender) {
  147.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) )
  148.                         return;
  149.                 $Sender->EventArguments["CssClass"] .= " NillaBlog NillaBlog".$Sender->CategoryID." ";
  150.         }
  151.  
  152.         /**
  153.          * Adds the class 'NillaBlog' to every comment (including the first post) in the blog category list.
  154.          * Allows for themes to style the blog independently of the plugin.
  155.          * @param $Sender
  156.          */
  157.         public function DiscussionController_BeforeCommentDisplay_Handler($Sender) {
  158.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) )
  159.                         return;
  160.                 $Sender->EventArguments["CssClass"] .= " NillaBlog NillaBlog".$Sender->CategoryID." ";
  161.         }
  162.  
  163.         /**
  164.          * Sorts blog posts by creation time rather than last comment.
  165.          * @param $Sender
  166.          */
  167.         public function DiscussionModel_BeforeGet_Handler($Sender) {
  168.                 $Wheres = $Sender->EventArguments["Wheres"];
  169.                 if (!array_key_exists("d.CategoryID", $Wheres) || !in_array($Wheres["d.CategoryID"], C("Plugins.NillaBlog.CategoryIDs")))
  170.                         return;
  171.  
  172.                 $Sender->EventArguments["SortField"] = "d.DateInserted";
  173.                 $Sender->EventArguments["SortDirection"] = "desc";
  174.         }
  175.  
  176.         /**
  177.          * Insert default CSS into the discussion list for the blog.
  178.          * @param $Sender
  179.          */
  180.         public function CategoriesController_Render_Before($Sender) {
  181.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) || C("Plugins.NillaBlog.DisableCSS") )
  182.                         return;
  183.  
  184.                 if (C("Plugins.NillaBlog.GooglePlusOne"))
  185.                         $Sender->AddJsFile('http://apis.google.com/js/plusone.js');
  186.  
  187.                 $Sender->AddCssFile($this->GetResource('design/custom.css', FALSE, FALSE));
  188.         }
  189.  
  190.         /**
  191.          * Insert default CSS into the comment list for the blog discussion.
  192.          * @param $Sender
  193.          */
  194.         public function DiscussionController_Render_Before($Sender) {
  195.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) || C("Plugins.NillaBlog.DisableCSS") )
  196.                         return;
  197.  
  198.                 if (C("Plugins.NillaBlog.GooglePlusOne"))
  199.                         $Sender->AddJsFile('http://apis.google.com/js/plusone.js');
  200.  
  201.                 $Sender->AddCssFile($this->GetResource('design/custom.css', FALSE, FALSE));
  202.         }
  203.  
  204.         /**
  205.          * Insert a clickable comments link appropriate for the blog.  We'll hide the other comment count with CSS.
  206.          * @param $Sender
  207.          */
  208.         public function CategoriesController_BeforeDiscussionMeta_Handler($Sender) {
  209.                 if ( !in_array($Sender->CategoryID, C("Plugins.NillaBlog.CategoryIDs")) || C("Plugins.NillaBlog.DisableCSS") )
  210.                         return;
  211.  
  212.                 $Discussion = $Sender->EventArguments['Discussion'];
  213.                 $Count = $Discussion->CountComments - 1;
  214.                 $Label = sprintf(Plural($Count, '%s comment', '%s comments'), $Count);
  215.                 ?>
  216.                         <span class="CommentCount NillaBlog NillaBlog<?php echo $Sender->CategoryID;?>>">
  217.                                 <a href="<?php
  218.                                         echo Gdn::Request()->Url(ConcatSep("/", "discussion", $Discussion->DiscussionID, Gdn_Format::Url($Discussion->Name).($Count > 0 ? "#Item_2" : "")));
  219.                                 ?>">
  220.                                         <?php echo $Label; ?>
  221.                                 </a>
  222.                         </span>
  223.                 <?php
  224.         }
  225.  
  226.         public function Setup() {}
  227. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top