/**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::Factory('Form');
     $Session = Gdn::session();
     if (is_numeric($DraftID) && $DraftID > 0) {
         $Draft = $this->DraftModel->getID($DraftID);
     }
     if ($Draft) {
         if ($Session->validateTransientKey($TransientKey) && (val('InsertUserID', $Draft) == $Session->UserID || checkPermission('Garden.Community.Manage'))) {
             // Delete the draft
             if (!$this->DraftModel->delete($DraftID)) {
                 $Form->addError('Failed to delete draft');
             }
         } else {
             throw permissionException('Garden.Community.Manage');
         }
     } else {
         throw notFoundException('Draft');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/drafts');
         redirect($Target);
     }
     // Return any errors
     if ($Form->errorCount() > 0) {
         $this->setJson('ErrorMessage', $Form->errors());
     }
     // Render default view
     $this->render();
 }
 /**
  * Allows the setting of data into one of two serialized data columns on the
  * user table: Preferences and Attributes. The method expects "Name" &
  * "Value" to be in the $_POST collection. This method always saves to the
  * row of the user id performing this action (ie. $Session->UserID). The
  * type of property column being saved should be specified in the url:
  *  ie. /dashboard/utility/set/preference/name/value/transientKey
  *  or /dashboard/utility/set/attribute/name/value/transientKey
  *
  * @param string The type of value being saved: preference or attribute.
  * @param string The name of the property being saved.
  * @param string The value of the property being saved.
  * @param string A unique transient key to authenticate that the user intended to perform this action.
  */
 public function Set($UserPropertyColumn = '', $Name = '', $Value = '', $TransientKey = '') {
    $this->_DeliveryType = DELIVERY_TYPE_BOOL;
    $Session = Gdn::Session();
    $Success = FALSE;
    if (
       in_array($UserPropertyColumn, array('preference', 'attribute'))
       && $Name != ''
       && $Value != ''
       && $Session->UserID > 0
       && $Session->ValidateTransientKey($TransientKey)
    ) {
       $UserModel = Gdn::Factory("UserModel");
       $Method = $UserPropertyColumn == 'preference' ? 'SavePreference' : 'SaveAttribute';
       $Success = $UserModel->$Method($Session->UserID, $Name, $Value) ? 'TRUE' : 'FALSE';
    }
    
    if (!$Success)
       $this->Form->AddError('ErrorBool');
    
    // Redirect back where the user came from if necessary
    if ($this->_DeliveryType == DELIVERY_TYPE_ALL)
       Redirect($_SERVER['HTTP_REFERER']);
    else
       $this->Render();
 }
 public function __construct(&$Sender = '')
 {
     $Session = Gdn::Session();
     if (property_exists($Sender, 'Conversation')) {
         $this->Conversation = $Sender->Conversation;
     }
     $this->Form = Gdn::Factory('Form', 'AddPeople');
     // $this->Form->Action = $Sender->SelfUrl;
     // If the form was posted back, check for people to add to the conversation
     if ($this->Form->AuthenticatedPostBack()) {
         $NewRecipientUserIDs = array();
         $NewRecipients = explode(',', $this->Form->GetFormValue('AddPeople', ''));
         $UserModel = Gdn::Factory("UserModel");
         foreach ($NewRecipients as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->GetByUsername(trim($Name));
                 if (is_object($User)) {
                     $NewRecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         $Sender->ConversationModel->AddUserToConversation($this->Conversation->ConversationID, $NewRecipientUserIDs);
         // if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL)
         //    Redirect('/messages/'.$this->Conversation->ConversationID);
         $Sender->StatusMessage = T('Your changes were saved.');
         $Sender->RedirectUrl = Url('/messages/' . $this->Conversation->ConversationID);
     }
     $this->_ApplicationFolder = $Sender->Application;
     $this->_ThemeFolder = $Sender->Theme;
 }
Example #4
0
 public function PluginController_LoadUp_Create(&$Sender)
 {
     $Sender->AddSideMenu('dashboard/plugin/loadup');
     $Sender->Permission('Plugins.Garden.LoadUp.Allow');
     if (!property_exists($Sender, 'Form')) {
         $Sender->Form = Gdn::Factory('Form');
     }
     $Sender->AddJsFile('jquery.livequery.js');
     $Sender->AddJsFile('jquery.autogrow.js');
     $Sender->AddJsFile('plugins/LoadUp/loadup.js');
     $Session = Gdn::Session();
     if ($Sender->Form->AuthenticatedPostBack() != False) {
         $UploadTo = $Sender->Form->GetFormValue('UploadTo');
         if (!$UploadTo) {
             $UploadTo = 'uploads/i/' . date('Y') . '/' . date('m');
         }
         $bOverwrite = $Sender->Form->GetFormValue('Overwrite') && $Session->CheckPermission('Plugins.Garden.LoadUp.Overwrite');
         $Options = array('Overwrite' => $bOverwrite, 'WebTarget' => True);
         $UploadedFiles = UploadFile($UploadTo, 'Files', $Options);
         $Sender->Form->SetFormValue('RawData', implode("\n", $UploadedFiles));
         $Sender->Form->SetFormValue('AbsoluteURL', 1);
     }
     $Sender->UploadTo = array('uploads/tmp' => 'uploads/tmp');
     $Sender->View = $this->GetView('index.php');
     $Sender->Title(T('Upload File'));
     $Sender->Render();
 }
 public function SettingsController_AutoExpire_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Form = Gdn::Factory('Form');
     if ($Sender->Form->IsPostBack() != False) {
         $Minutes = $Sender->Form->GetValue('AutoExpirePeriod_Minutes');
         $Hours = $Sender->Form->GetValue('AutoExpirePeriod_Hours');
         $Days = $Sender->Form->GetValue('AutoExpirePeriod_Days');
         $Months = $Sender->Form->GetValue('AutoExpirePeriod_Months');
         $Years = $Sender->Form->GetValue('AutoExpirePeriod_Years');
         if (!(empty($Minutes) && empty($Hours) && empty($Days) && empty($Months) && empty($Years))) {
             $Sender->Form->SetFormValue('AutoExpirePeriod', "+{$Years} years {$Months} months {$Days} days {$Hours} hours {$Minutes} minutes");
         } else {
             $Sender->Form->SetFormValue('AutoExpirePeriod', null);
         }
         $FormValues = $Sender->Form->FormValues();
         Gdn::SQL()->Put('Category', array('AutoExpirePeriod' => $FormValues['AutoExpirePeriod']), array('CategoryID' => $FormValues['CategoryID']));
         if (strtolower($FormValues['AutoExpireRetro']) == 'yes') {
             Gdn::SQL()->Put('Discussion', array('AutoExpire' => 1), array('CategoryID' => $FormValues['CategoryID']));
         }
     }
     $CategoryModel = new CategoryModel();
     $CategoryFull = $CategoryModel->GetFull();
     $CatsExpire = array();
     foreach ($CategoryFull as $Category) {
         $CatsExpire[$Category->CategoryID] = $Category->AutoExpirePeriod;
     }
     $Sender->SetData('CatsExpire', json_encode($CatsExpire));
     $Sender->AddSideMenu();
     $Sender->SetData('Title', T('AutoExpireDiscussions.Title', 'Auto Expire Discussions'));
     $Sender->SetData('Description', $this->PluginInfo['Description']);
     $Sender->Render('Settings', '', 'plugins/AutoExpireDiscussions');
 }
 /**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function Delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::Factory('Form');
     $Session = Gdn::Session();
     if (is_numeric($DraftID) && $DraftID > 0 && $Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey)) {
         // Delete the draft
         $Draft = $this->DraftModel->GetID($DraftID);
         if ($Draft && !$this->DraftModel->Delete($DraftID)) {
             $Form->AddError('Failed to delete discussion');
         }
     } else {
         // Log an error
         $Form->AddError('ErrPermission');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/vanilla/drafts');
         Redirect($Target);
     }
     // Return any errors
     if ($Form->ErrorCount() > 0) {
         $this->SetJson('ErrorMessage', $Form->Errors());
     }
     // Render default view
     $this->Render();
 }
Example #7
0
/**
 * Writes the search box to the page.
 *
 * @param array The parameters passed into the function. This currently takes no parameters.
 * @param Smarty The smarty object rendering the template.
 * @return The url.
 */
function smarty_function_searchbox($Params, &$Smarty)
{
    $Form = Gdn::Factory('Form');
    $Form->InputPrefix = '';
    $Result = $Form->Open(array('action' => Url('/search'), 'method' => 'get')) . $Form->TextBox('Search', array('placeholder' => T('Search'))) . $Form->Button('Go', array('Name' => '')) . $Form->Close();
    return $Result;
}
Example #8
0
	private function _AddCLEditor($Sender) {
		// Turn off safestyles so the inline styles get applied to comments
		$Config = Gdn::Factory(Gdn::AliasConfig);
		$Config->Set('Garden.Html.SafeStyles', FALSE);
		
		// Add the CLEditor to the form
		$Sender->RemoveJsFile('jquery.autogrow.js');
		$Sender->AddJsFile('jquery.cleditor.min.js', 'plugins/cleditor');
		$Sender->AddCssFile('jquery.cleditor.css', 'plugins/cleditor');
		$Sender->Head->AddString('
<style type="text/css">
a.PreviewButton {
	display: none !important;
}
</style>
<script type="text/javascript">
	jQuery(document).ready(function($) {
		// Make sure the removal of autogrow does not break anything
		jQuery.fn.autogrow = function(o) { return; }
		// Attach the editor to comment boxes
		jQuery("#Form_Body").livequery(function() {
			var frm = $(this).parents("div.CommentForm");
			ed = jQuery(this).cleditor({width:"100%", height:"100%"})[0];
			this.editor = ed; // Support other plugins!
			jQuery(frm).bind("clearCommentForm", {editor:ed}, function(e) {
				frm.find("textarea").hide();
				e.data.editor.clear();
			});
		});
	})(jQuery);
</script>');
   }
 /**
  * Is the application/plugin/theme removable?
  *
  * @param string $Type self::TYPE_APPLICATION or self::TYPE_PLUGIN or self::TYPE_THEME
  * @param string $Name
  * @return boolean
  */
 public static function isRemovable($Type, $Name)
 {
     switch ($Type) {
         case self::TYPE_APPLICATION:
             $ApplicationManager = Gdn::Factory('ApplicationManager');
             if ($IsRemovable = !array_key_exists($Name, $ApplicationManager->EnabledApplications())) {
                 $ApplicationInfo = arrayValue($Name, $ApplicationManager->AvailableApplications(), array());
                 $ApplicationFolder = arrayValue('Folder', $ApplicationInfo, '');
                 $IsRemovable = IsWritable(PATH_APPLICATIONS . DS . $ApplicationFolder);
             }
             break;
         case self::TYPE_PLUGIN:
             if ($IsRemovable = !array_key_exists($Name, Gdn::pluginManager()->EnabledPlugins())) {
                 $PluginInfo = arrayValue($Name, Gdn::pluginManager()->AvailablePlugins(), false);
                 $PluginFolder = arrayValue('Folder', $PluginInfo, false);
                 $IsRemovable = IsWritable(PATH_PLUGINS . DS . $PluginFolder);
             }
             break;
         case self::TYPE_THEME:
             // TODO
             $IsRemovable = false;
             break;
     }
     return $IsRemovable;
 }
/**
 * Writes the search box to the page.
 *
 * @param array The parameters passed into the function. This currently takes no parameters.
 * @param Smarty The smarty object rendering the template.
 * @return The url.
 */
function smarty_function_searchbox($Params, &$Smarty)
{
    $Placeholder = array_key_exists('placeholder', $Params) ? GetValue('placeholder', $Params, '', TRUE) : T('SearchBoxPlaceHolder', 'Search');
    $Form = Gdn::Factory('Form');
    $Form->InputPrefix = '';
    $Result = $Form->Open(array('action' => Url('/search'), 'method' => 'get')) . $Form->TextBox('Search', array('placeholder' => $Placeholder)) . $Form->Button('Go', array('Name' => '')) . $Form->Close();
    return $Result;
}
Example #11
0
 public function __construct()
 {
     parent::__construct();
     $Form = Gdn::Factory('Form');
     $Form->Method = 'get';
     $Form->InputPrefix = '';
     $this->Form = $Form;
 }
Example #12
0
 protected function CreateSection($RowID, $PostValues)
 {
     $SectionModel = Gdn::Factory('SectionModel');
     $NodeFields = array('Name' => $PostValues['Title'], 'Url' => GetValue('URI', $PostValues, Null), 'RequestUri' => 'candy/content/page/' . $RowID);
     $SectionModel->AutoIncrement($RowID);
     $ParentSectionID = GetValue('SectionID', $PostValues);
     $PageSectionID = $SectionModel->InsertNode($ParentSectionID, $NodeFields);
     $this->SQL->Update($this->Name)->Set('SectionID', $PageSectionID)->Where($this->PrimaryKey, $RowID)->Put();
 }
 /**
  * Object instantiation & form prep.
  */
 public function __construct()
 {
     parent::__construct();
     // Object instantiation
     $this->SearchModel = new SearchModel();
     $Form = Gdn::Factory('Form');
     // Form prep
     $Form->Method = 'get';
     $this->Form = $Form;
 }
 function xHtml($String)
 {
     $HtmlFormatter = Gdn::Factory('HtmlFormatter');
     if ($HtmlFormatter) {
         $String = $HtmlFormatter->Format($String);
     } else {
         $String = Gdn_Format::Text($String);
     }
     return $String;
 }
Example #15
0
 public function Refresh()
 {
     $LocalName = $this->Current();
     $ApplicationManager = Gdn::Factory('ApplicationManager');
     $ApplicationWhiteList = $ApplicationManager->EnabledApplicationFolders();
     $PluginManager = Gdn::Factory('PluginManager');
     $PluginWhiteList = $PluginManager->EnabledPluginFolders();
     $ForceRemapping = TRUE;
     $this->Set($LocalName, $ApplicationWhiteList, $PluginWhiteList, $ForceRemapping);
 }
Example #16
0
 /**
  * @return Smarty The smarty object used for rendering.
  */
 public function Smarty()
 {
     if (is_null($this->_Smarty)) {
         $Smarty = Gdn::Factory('Smarty');
         $Smarty->cache_dir = PATH_CACHE . DS . 'Smarty' . DS . 'cache';
         $Smarty->compile_dir = PATH_CACHE . DS . 'Smarty' . DS . 'compile';
         $Smarty->plugins_dir[] = PATH_LIBRARY . DS . 'vendors' . DS . 'SmartyPlugins';
         $this->_Smarty = $Smarty;
     }
     return $this->_Smarty;
 }
Example #17
0
 public function SetAjarData($SectionPath = False)
 {
     $SectionModel = Gdn::Factory('SectionModel');
     if ($SectionPath === False) {
         $SectionPath = GetValueR('SectionID', $this->_Sender);
     } elseif (is_object($SectionPath) && $SectionPath instanceof StdClass) {
         $SectionPath = $SectionPath->SectionID;
     }
     if ($SectionPath) {
         $this->SetData('Items', $SectionModel->Ajar($SectionPath, '', False));
     }
 }
 public function __construct($Config)
 {
     if (is_string($Config)) {
         $Config = Gdn::Config($Config);
     }
     $this->AuthenticateUrl = ArrayValue('AuthenticateUrl', $Config);
     $this->_RegisterUrl = ArrayValue('RegisterUrl', $Config);
     $this->_SignInUrl = ArrayValue('SignInUrl', $Config);
     $this->_SignOutUrl = ArrayValue('SignOutUrl', $Config);
     $this->Encoding = ArrayValue('Encoding', $Config, 'ini');
     $this->_Identity = Gdn::Factory('Identity');
     $this->_Identity->Init();
 }
Example #19
0
 public function SaveTranslations($Translations, $LocaleName = FALSE)
 {
     if (!$LocaleName) {
         $LocaleName = $this->_Locale;
     }
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $Path = PATH_CONF . DS . "locale-{$LocaleName}.php";
     $Config->Load($Path, 'Save', 'Definition');
     foreach ($Translations as $k => $v) {
         $Config->Set('Definition.' . $k, $v);
     }
     $this->SetTranslation($Translations);
     return $Config->Save($Path, 'Definition');
 }
 /**
  * Converts HTML to Markdown
  */
 function Markdownify($Html)
 {
     if (function_exists('Debug') && Debug()) {
         trigger_error(sprintf('%s is deprecated, use HtmlToMarkdown() instead.', __FUNCTION__), E_USER_DEPRECATED);
     }
     $Html = Gdn_Format::To($Html, 'xHtml');
     $Snoopy = Gdn::Factory('Snoopy');
     $Vars = array('input' => $Html, 'keepHTML' => 1);
     $Snoopy->Submit('http://milianw.de/projects/markdownify/demo.php', $Vars);
     $Doc = PqDocument($Snoopy->results);
     $Code = Pq('pre > code:eq(0)')->Text();
     $Result = $Code;
     return $Result;
 }
Example #21
0
 /**
  *
  * @param Gdn_Form $Sender 
  */
 public function Gdn_Form_BeforeBodyBox_Handler($Sender, $Args)
 {
     $this->_AddCLEditor(Gdn::Controller());
     $Format = $Sender->GetValue('Format');
     if ($Format) {
         $Formatter = Gdn::Factory($Format . 'Formatter');
         if ($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
             $Body = $Formatter->FormatForWysiwyg($Sender->GetValue('Body'));
             $Sender->SetValue('Body', $Body);
         } elseif (!in_array($Format, array('Html', 'Wysiwyg'))) {
             $Sender->SetValue('Body', Gdn_Format::To($Sender->GetValue('Body'), $Format));
         }
     }
     $Sender->SetValue('Format', 'Wysiwyg');
 }
Example #22
0
 public function Setup()
 {
     // Got Setup?
     $Database = Gdn::Database();
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $Drop = C('Skeleton.Version') === FALSE ? TRUE : FALSE;
     $Explicit = TRUE;
     $Validation = new Gdn_Validation();
     // This is going to be needed by structure.php to validate permission names
     include PATH_APPLICATIONS . DS . 'skeleton' . DS . 'settings' . DS . 'structure.php';
     $ApplicationInfo = array();
     include CombinePaths(array(PATH_APPLICATIONS . DS . 'skeleton' . DS . 'settings' . DS . 'about.php'));
     $Version = ArrayValue('Version', ArrayValue('Skeleton', $ApplicationInfo, array()), 'Undefined');
     SaveToConfig('Skeleton.Version', $Version);
 }
 /**
  * Allows the user to declare which values are being manipulated in the
  * $this->Name configuration array.
  *
  * @param mixed $FieldName The name of the field (or array of field names) to ensure.
  */
 public function SetField($FieldName)
 {
     $Config = Gdn::Factory(Gdn::AliasConfig);
     if (is_array($FieldName) === FALSE) {
         $FieldName = array($FieldName);
     }
     $Count = count($FieldName);
     for ($i = 0; $i < $Count; ++$i) {
         if ($this->Name == 'Configuration') {
             $Name = $FieldName[$i];
         } else {
             $Name = $this->Name . '.' . $FieldName[$i];
         }
         $this->Data[$FieldName[$i]] = $Config->Get($Name, '');
     }
 }
Example #24
0
 public function Save($FormPostValues)
 {
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->ApplyRule('Body', 'Required');
     $this->Validation->ApplyRule('ReplyCommentID', 'Required');
     // Add/define extra fields for saving
     $ReplyCommentID = intval(ArrayValue('ReplyCommentID', $FormPostValues, 0));
     $Discussion = $this->SQL->Select('c.DiscussionID, d.Name, d.CategoryID')->From('Comment c')->Join('Discussion d', 'd.DiscussionID = c.DiscussionID')->Where('c.CommentID', $ReplyCommentID)->Get()->FirstRow();
     if (is_object($Discussion)) {
         $FormPostValues['DiscussionID'] = $Discussion->DiscussionID;
     }
     $CommentID = ArrayValue('CommentID', $FormPostValues);
     $Insert = $CommentID === FALSE ? TRUE : FALSE;
     if ($Insert) {
         $this->AddInsertFields($FormPostValues);
         // Check for spam
         $this->CheckForSpam('Comment');
         // Comments and replies use the same spam check rules
     } else {
         $this->AddUpdateFields($FormPostValues);
     }
     // Validate the form posted values
     if ($this->Validation->Validate($FormPostValues, $Insert)) {
         $Fields = $this->Validation->SchemaValidationFields();
         $Fields = RemoveKeyFromArray($Fields, $this->PrimaryKey);
         $Session = Gdn::Session();
         // Make sure there are no reply drafts.
         if ($Insert === FALSE) {
             $this->SQL->Put($this->Name, $Fields, array('CommentID' => $CommentID));
         } else {
             $CommentID = $this->SQL->Insert($this->Name, $Fields);
             $this->UpdateReplyCount($ReplyCommentID);
             // Report user-comment activity
             $this->RecordActivity($ReplyCommentID, $Session->UserID, $CommentID);
         }
         // Index the comment.
         $Search = Gdn::Factory('SearchModel');
         if (!is_null($Search)) {
             // Index the discussion.
             $Document = array('TableName' => 'Comment', 'PrimaryID' => $CommentID, 'PermissionJunctionID' => $Discussion->CategoryID, 'Title' => $Discussion->Name, 'Summary' => $Fields['Body'], 'Url' => '/discussion/comment/' . $ReplyCommentID . '/#Comment_' . $CommentID, 'InsertUserID' => $Session->UserID);
             $Search->Index($Document);
         }
     }
     return $CommentID;
 }
 /**
  * Adds the formatting bar to the form used by the Controller.
  *
  * @param Gdn_Controller $Sender Sending Controller instance.
  */
 private function AttachFormattingBar(Gdn_Controller $Sender)
 {
     $this->_AddWysihtml5($Sender);
     $Form = $Sender->Form;
     $Format = $Form->GetValue('Format');
     if ($Format) {
         $Formatter = Gdn::Factory($Format . 'Formatter');
         if ($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
             $Body = $Formatter->FormatForWysiwyg($Form->GetValue('Body'));
             $Form->SetValue('Body', $Body);
         } elseif (!in_array($Format, array('Html', 'Wysiwyg'))) {
             $Form->SetValue('Body', Gdn_Format::To($Form->GetValue('Body'), $Format));
         }
     }
     $Form->SetValue('Format', 'Wysiwyg');
     echo $Sender->FetchView($this->GetView('toolbar_view.php'));
 }
Example #26
0
 protected function _AddTopMenu($Sender)
 {
     $Menu = $Sender->Menu;
     $Version = C('Candy.Version');
     if ($Menu && $Version >= 0.36) {
         $SectionModel = Gdn::Factory('SectionModel');
         $Items = $SectionModel->GetNodes(array('InTopMenu' => 1, 'CacheNodes' => True));
         foreach ($Items as $Item) {
             $ParentItem = $SectionModel->GetNode($Item->ParentID, array('InTopMenu' => 1));
             $Url = SectionUrl($Item);
             if ($ParentItem == FALSE) {
                 $Menu->AddLink($Item->Name, $Item->Name, $Url, FALSE);
             } else {
                 $Menu->AddLink($ParentItem->Name, $Item->Name, $Url, FALSE);
             }
         }
     }
 }
Example #27
0
 public function Delete($Category, $ReplacementCategoryID)
 {
     // Don't do anything if the required category object & properties are not defined.
     if (!is_object($Category) || !property_exists($Category, 'CategoryID') || !property_exists($Category, 'ParentCategoryID') || !property_exists($Category, 'AllowDiscussions') || !property_exists($Category, 'Name') || $Category->CategoryID <= 0) {
         throw new Exception(Gdn::Translate('Invalid category for deletion.'));
     } else {
         // Remove permissions.
         $PermissionModel = Gdn::PermissionModel();
         $PermissionModel->Delete(NULL, 'Category', 'CategoryID', $Category->CategoryID);
         // If there is a replacement category...
         if ($ReplacementCategoryID > 0) {
             // Update children categories
             $this->SQL->Update('Category')->Set('ParentCategoryID', $ReplacementCategoryID)->Where('ParentCategoryID', $Category->CategoryID)->Put();
             // Update discussions
             $this->SQL->Update('Discussion')->Set('CategoryID', $ReplacementCategoryID)->Where('CategoryID', $Category->CategoryID)->Put();
             // Update the discussion count
             $Count = $this->SQL->Select('DiscussionID', 'count', 'DiscussionCount')->From('Discussion')->Where('CategoryID', $ReplacementCategoryID)->Get()->FirstRow()->DiscussionCount;
             if (!is_numeric($Count)) {
                 $Count = 0;
             }
             $this->SQL->Update('Category')->Set('CountDiscussions', $Count)->Where('CategoryID', $ReplacementCategoryID)->Put();
         } else {
             // Delete comments in this category
             $this->SQL->From('Comment')->Join('Discussion d', 'c.DiscussionID = d.DiscussionID')->Delete('Comment c', array('d.CategoryID' => $Category->CategoryID));
             // Delete discussions in this category
             $this->SQL->Delete('Discussion', array('CategoryID' => $Category->CategoryID));
         }
         // Delete the category
         $this->SQL->Delete('Category', array('CategoryID' => $Category->CategoryID));
         // If there are no parent categories left, make sure that all other
         // categories are not assigned
         if ($this->SQL->Select('CategoryID')->From('Category')->Where('AllowDiscussions', '0')->Get()->NumRows() == 0) {
             $this->SQL->Update('Category')->Set('ParentCategoryID', 'null', FALSE)->Put();
         }
         // If there is only one category, make sure that Categories are not used
         $CountCategories = $this->Get()->NumRows();
         $Config = Gdn::Factory(Gdn::AliasConfig);
         $Config->Load(PATH_CONF . DS . 'config.php', 'Save');
         $Config->Set('Vanilla.Categories.Use', $CountCategories > 1, TRUE, 'ForSave');
         $Config->Save();
     }
     // Make sure to reorganize the categories after deletes
     $this->Organize();
 }
 protected function Create($Sender)
 {
     $Sender->Permission('Garden.Email.Manage');
     $Sender->CanGiveJobToCron = C('EnabledPlugins.PluginUtils') !== False;
     $Validation = new Gdn_Validation();
     $Validation->ApplyRule('RecipientEmailList', array('Required', 'ValidateEmail'));
     $Validation->ApplyRule('Subject', 'Required');
     $Validation->ApplyRule('Body', 'Required');
     $Sender->DrawConfirmSend = False;
     if ($Sender->Form->AuthenticatedPostBack() != False) {
         $FormValues = $Sender->Form->FormValues();
         $ValidationResult = $Validation->Validate($FormValues);
         $Sender->Form->SetValidationResults($Validation->Results());
         if ($ValidationResult) {
             $Emails = $this->GetUserEmails($FormValues);
             $Sender->CountEmails = count($Emails);
             if ($Sender->CountEmails == 0) {
                 $Sender->Form->AddError('No one to send');
             }
         }
         if ($Sender->Form->ErrorCount() == 0) {
             $Sender->DrawConfirmSend = True;
             if (ArrayValue('ConfirmSend', $FormValues)) {
                 $Sent = $this->Send($Emails, $FormValues);
                 if ($Sent != False) {
                     $Sender->StatusMessage = T('Your message was successfully sent.');
                 }
             }
         }
     } else {
         $SupportAddress = C('Garden.Email.SupportAddress');
         if (!$SupportAddress) {
             $SupportAddress = 'noreply@' . Gdn::Request()->Host();
         }
         $Sender->Form->SetValue('RecipientEmailList', $SupportAddress);
     }
     $Sender->View = $this->GetView('create.php');
     $RoleModel = Gdn::Factory('RoleModel');
     $Sender->RoleData = $RoleModel->Get();
     $Sender->Render();
 }
Example #29
0
 /**
  * Setup the application.
  *
  * The methods in setup controllers should not call "Render". Rendering will
  * be handled by the controller that initiated the setup. This method should
  * return a boolean value indicating success.
  *
  * @return bool True on successful setup
  */
 public function Index()
 {
     $Database = Gdn::Database();
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $Drop = Gdn::Config('Conversations.Version') === FALSE ? TRUE : FALSE;
     $Explicit = TRUE;
     $Validation = new Gdn_Validation();
     // This is going to be needed by structure.php to validate permission names
     try {
         include PATH_APPLICATIONS . DS . 'conversations' . DS . 'settings' . DS . 'structure.php';
     } catch (Exception $ex) {
         $this->Form->AddError(strip_tags($ex->getMessage()));
     }
     if ($this->Form->ErrorCount() == 0) {
         $ApplicationInfo = array();
         include CombinePaths(array(PATH_APPLICATIONS . DS . 'conversations' . DS . 'settings' . DS . 'about.php'));
         $Version = ArrayValue('Version', ArrayValue('Conversations', $ApplicationInfo, array()), 'Undefined');
         SaveToConfig('Conversations.Version', $Version);
     }
     return $this->Form->ErrorCount() > 0 ? FALSE : TRUE;
 }
 /**
  * Allows the user to declare which values are being manipulated in the
  * $this->Name configuration array.
  *
  * @param mixed $FieldName The name of the field (or array of field names) to ensure.
  */
 public function SetField($FieldName)
 {
     $Config = Gdn::Factory(Gdn::AliasConfig);
     if (is_array($FieldName) === FALSE) {
         $FieldName = array($FieldName);
     }
     foreach ($FieldName as $Index => $Value) {
         if (is_numeric($Index)) {
             $NameKey = $Value;
             $Default = '';
         } else {
             $NameKey = $Index;
             $Default = $Value;
         }
         /*
         if ($this->Name != 'Configuration')
            $Name = $NameKey;
         else
            $Name = $this->Name.'.'.$NameKey;
         */
         $this->Data[$NameKey] = $Config->Get($NameKey, $Default);
     }
 }