Exemple #1
0
 public function Save($PostValues, $PreviousValues = False)
 {
     ReplaceEmpty($PostValues, Null);
     $URI = GetValue('URI', $PostValues, Null);
     $bCreateSection = GetValue('CreateSection', $PostValues);
     $RowID = GetValue('PageID', $PostValues);
     $Insert = $RowID === False;
     if ($bCreateSection) {
         $SectionModel = Gdn::Factory('SectionModel');
         $this->Validation->ApplyRule('URI', 'UrlPath');
         $this->Validation->ApplyRule('SectionID', 'Required');
         if ($Insert && $URI && CandyModel::GetRoute($URI)) {
             $this->Validation->AddValidationResult('URI', '%s: Already exists.');
         }
     }
     $this->EventArguments['PostValues'] =& $PostValues;
     $this->FireEvent('BeforeSave');
     $RowID = parent::Save($PostValues);
     if ($RowID) {
         if ($URI) {
             CandyModel::SaveRoute($URI, 'candy/content/page/' . $RowID);
         }
         if ($bCreateSection) {
             $this->CreateSection($RowID, $PostValues);
         }
     }
     return $RowID;
 }
 public function Slug()
 {
     $Session = Gdn::Session();
     if ($Session->IsValid()) {
         $Text = GetIncomingValue('Text');
         echo CandyModel::Slug($Text);
     }
 }
 public function Delete($EncodedURI)
 {
     $this->Permission('Candy.Routes.Manage');
     $URI = base64_decode($EncodedURI);
     CandyModel::DeleteRoute($URI);
     if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
         Redirect('/candy/routes');
     }
 }
Exemple #4
0
 public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender)
 {
     $Request = Gdn::Request();
     $RequestUri = $Request->RequestUri();
     if (Gdn::Router()->GetRoute($RequestUri) === False) {
         $RequestArgs = SplitUpString($RequestUri, '/', 'strtolower');
         if (array_key_exists(0, $RequestArgs)) {
             $ApplicationFolders = $Sender->EnabledApplicationFolders();
             $bFoundApplication = in_array($RequestArgs[0], $ApplicationFolders);
             if ($bFoundApplication === False) {
                 $PathParts = array('controllers', 'class.' . $RequestArgs[0] . 'controller.php');
                 $ControllerFileName = CombinePaths($PathParts);
                 $ControllerPath = Gdn_FileSystem::FindByMapping('controller', PATH_APPLICATIONS, $ApplicationFolders, $ControllerFileName);
                 if (!$ControllerPath || !file_exists($ControllerPath)) {
                     $Sender->EventArguments['RequestUri'] =& $RequestUri;
                     $Sender->FireEvent('BeforeGetRoute');
                     $NewRequest = CandyModel::GetRouteRequestUri($RequestUri);
                     if ($NewRequest) {
                         $Request->WithURI($NewRequest);
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
 public function Save($PostValues, $PreviousValues = False)
 {
     ReplaceEmpty($PostValues, Null);
     $RowID = GetValue($this->PrimaryKey, $PostValues);
     $Insert = $RowID === False;
     $URI = GetValue('URI', $PostValues, Null);
     if ($URI !== Null) {
         $this->Validation->ApplyRule('URI', 'UrlPath');
     }
     if ($Insert && !$this->CheckUniqueURI($URI)) {
         $this->Validation->AddValidationResult('URI', '%s: Already exists.');
     }
     if (GetValue('ParentID', $PostValues) === Null) {
         SetValue('ParentID', $PostValues, 1);
     }
     if (array_key_exists('Mask', $PostValues)) {
         $PostValues['Mask'] = self::CalculateMask($PostValues['Mask']);
     }
     $this->DefineSchema();
     $this->AddUpdateFields($PostValues);
     if ($Insert) {
         $this->AddInsertFields($PostValues);
     }
     if ($this->Validate($PostValues, $Insert) === True) {
         $Fields = $this->Validation->SchemaValidationFields();
         if ($Insert) {
             $ParentID = GetValue('ParentID', $PostValues);
             $RowID = parent::InsertNode($ParentID, $Fields);
             if (!$RowID) {
                 $this->Validation->AddValidationResult('RowID', '%s: InsertNode operation failed.');
             }
         } else {
             $this->Update($Fields, array('SectionID' => $RowID));
         }
         if (count($this->Validation->Results()) == 0) {
             CandyModel::SaveRoute($PostValues);
         }
     } else {
         $RowID = False;
     }
     return $RowID;
 }
 /**
  * Mask note. 
  * 
  */
 public function Mask()
 {
     $this->Form->IDPrefix = 'Mask_';
     $this->Permission('Candy.Settings.View');
     $Validation = new Gdn_Validation();
     if ($this->Form->IsPostBack() != False) {
         $PostValues = $this->Form->FormValues();
         CandyModel::SaveMaskInfo($PostValues, $Validation);
         $this->Form->SetValidationResults($Validation->Results());
         if ($this->Form->ErrorCount() == 0) {
             $this->InformMessage(T('Saved'), array('Sprite' => 'Check', 'CssClass' => 'Dismissable AutoDismiss'));
             $this->RedirectUrl = Url('candy/section/tree');
         }
     }
     $this->MaskInfo = K('Candy.Mask.Info');
     if (!is_array($this->MaskInfo)) {
         $this->MaskInfo = array();
     }
     $this->Title('Mask');
     $this->Render();
 }