Esempio n. 1
0
 public function toString()
 {
     $Form = $this->_Sender->Form;
     $this->_Sender->addJsFile('condition.js');
     if ($Form->authenticatedPostBack()) {
         // Grab the conditions from the form and convert them to the conditions array.
         $this->Conditions($this->_FromForm());
     } else {
     }
     $this->Types = array_merge(array('' => '(' . sprintf(t('Select a %s'), t('Condition Type', 'Type')) . ')'), Gdn_Condition::AllTypes());
     //die(print_r($this->Types));
     // Get all of the permissions that are valid for the permissions dropdown.
     $PermissionModel = new PermissionModel();
     $Permissions = $PermissionModel->GetGlobalPermissions(0);
     $Permissions = array_keys($Permissions);
     sort($Permissions);
     $Permissions = array_combine($Permissions, $Permissions);
     $Permissions = array_merge(array('' => '(' . sprintf(t('Select a %s'), t('Permission')) . ')'), $Permissions);
     $this->Permissions = $Permissions;
     // Get all of the roles.
     $RoleModel = new RoleModel();
     $Roles = $RoleModel->getArray();
     $Roles = array_merge(array('-' => '(' . sprintf(t('Select a %s'), t('Role')) . ')'), $Roles);
     $this->Roles = $Roles;
     $this->Form = $Form;
     return parent::ToString();
 }
Esempio n. 2
0
</th>
            <th width="30%"><?php 
echo t('Condition Expression', 'Value');
?>
</th>
            <th>&#160;</th>
        </tr>
        </thead>
        <?php 
// Write all of the conditions.
foreach ($this->Conditions() as $Condition) {
    WriteConditionEdit($Condition, $this);
}
// Write a blank row for a new condition.
if (count($this->Conditions()) == 0) {
    WriteConditionEdit(Gdn_Condition::Blank(), $this);
}
// Write a template for new rows.
echo '<tfoot style="display:none">';
WriteConditionEdit(Gdn_Condition::Blank(), $this);
echo '</tfoot>';
?>
    </table>
    <div style="text-align: right; margin-top: 10px;">
        <a class="AddCondition Button"><?php 
echo sprintf(t('Add %s'), t('Condition'));
?>
</a>
    </div>
</div>
Esempio n. 3
0
 protected function _AddEdit($Sender, $PocketID = FALSE)
 {
     $Form = new Gdn_Form();
     $PocketModel = new Gdn_Model('Pocket');
     $Form->SetModel($PocketModel);
     $Sender->ConditionModule = new ConditionModule($Sender);
     $Sender->Form = $Form;
     if ($Form->AuthenticatedPostBack()) {
         // Save the pocket.
         if ($PocketID !== FALSE) {
             $Form->SetFormValue('PocketID', $PocketID);
         }
         // Convert the form data into a format digestable by the database.
         $Repeat = $Form->GetFormValue('RepeatType');
         switch ($Repeat) {
             case Pocket::REPEAT_EVERY:
                 $PocketModel->Validation->ApplyRule('EveryFrequency', 'Integer');
                 $PocketModel->Validation->ApplyRule('EveryBegin', 'Integer');
                 $Frequency = $Form->GetFormValue('EveryFrequency', 1);
                 if (!$Frequency || !ValidateInteger($Frequency) || $Frequency < 1) {
                     $Frequency = 1;
                 }
                 $Repeat .= ' ' . $Frequency;
                 if ($Form->GetFormValue('EveryBegin', 1) > 1) {
                     $Repeat .= ',' . $Form->GetFormValue('EveryBegin');
                 }
                 break;
             case Pocket::REPEAT_INDEX:
                 $PocketModel->Validation->AddRule('IntegerArray', 'function:ValidateIntegerArray');
                 $PocketModel->Validation->ApplyRule('Indexes', 'IntegerArray');
                 $Indexes = explode(',', $Form->GetFormValue('Indexes', ''));
                 $Indexes = array_map('trim', $Indexes);
                 $Repeat .= ' ' . implode(',', $Indexes);
                 break;
             default:
                 break;
         }
         $Form->SetFormValue('Repeat', $Repeat);
         $Form->SetFormValue('Sort', 0);
         $Form->SetFormValue('Format', 'Raw');
         $Condition = Gdn_Condition::ToString($Sender->ConditionModule->Conditions(TRUE));
         $Form->SetFormValue('Condition', $Condition);
         if ($Form->GetFormValue('Ad', 0)) {
             $Form->SetFormValue('Type', Pocket::TYPE_AD);
         } else {
             $Form->SetFormValue('Type', Pocket::TYPE_DEFAULT);
         }
         $Saved = $Form->Save();
         if ($Saved) {
             $Sender->StatusMessage = T('Your changes have been saved.');
             $Sender->RedirectUrl = Url('settings/pockets');
         }
     } else {
         if ($PocketID !== FALSE) {
             // Load the pocket.
             $Pocket = $PocketModel->GetWhere(array('PocketID' => $PocketID))->FirstRow(DATASET_TYPE_ARRAY);
             if (!$Pocket) {
                 return Gdn::Dispatcher()->Dispatch('Default404');
             }
             // Convert some of the pocket data into a format digestable by the form.
             list($RepeatType, $RepeatFrequency) = Pocket::ParseRepeat($Pocket['Repeat']);
             $Pocket['RepeatType'] = $RepeatType;
             $Pocket['EveryFrequency'] = GetValue(0, $RepeatFrequency, 1);
             $Pocket['EveryBegin'] = GetValue(1, $RepeatFrequency, 1);
             $Pocket['Indexes'] = implode(',', $RepeatFrequency);
             $Pocket['Ad'] = $Pocket['Type'] == Pocket::TYPE_AD;
             $Sender->ConditionModule->Conditions(Gdn_Condition::FromString($Pocket['Condition']));
             $Form->SetData($Pocket);
         } else {
             // Default the repeat.
             $Form->SetFormValue('RepeatType', Pocket::REPEAT_ONCE);
         }
     }
     $Sender->Form = $Form;
     $Sender->SetData('Locations', $this->Locations);
     $Sender->SetData('LocationsArray', $this->GetLocationsArray());
     $Sender->SetData('Pages', array('' => '(' . T('All') . ')', 'activity' => 'activity', 'comments' => 'comments', 'dashboard' => 'dashboard', 'discussions' => 'discussions', 'inbox' => 'inbox', 'profile' => 'profile'));
     return $Sender->Render('AddEdit', '', 'plugins/Pockets');
 }
Esempio n. 4
0
 /**
  * Test an individual condition.
  *
  * @param string $Type One of the types in this condition.
  * @param string $Field The field to test against.
  * @param string $Expr The expression to test with.
  * @return bool
  */
 public static function testOne($Type, $Field, $Expr = null)
 {
     switch (strtolower($Type)) {
         case PERMISSION:
             // Check to see if the user has the given permission.
             $Result = Gdn::session()->checkPermission($Field);
             if ($Expr === false) {
                 return !$Result;
             }
             return $Result;
         case REQUEST:
             // See if the field is a specific value.
             switch (strtolower($Field)) {
                 case 'path':
                     $Value = Gdn::request()->path();
                     break;
                 default:
                     // See if the field is targetting a specific part of the request.
                     $Fields = explode('.', $Field, 2);
                     if (count($Fields) >= 2) {
                         $Value = Gdn::request()->getValueFrom($Fields[0], $Fields[1], null);
                     } else {
                         $Value = Gdn::request()->getValue($Field, null);
                     }
                     break;
             }
             $Result = Gdn_Condition::testValue($Value, $Expr);
             return $Result;
         case ROLE:
             // See if the user is in the given role.
             $RoleModel = new RoleModel();
             $Roles = $RoleModel->getByUserID(Gdn::session()->UserID)->resultArray();
             foreach ($Roles as $Role) {
                 if (is_numeric($Expr)) {
                     $Result = $Expr == val('RoleID', $Role);
                 } else {
                     $Result = Gdn_Condition::testValue(val('Name', $Role), $Expr);
                 }
                 if ($Result) {
                     return true;
                 }
             }
             return false;
     }
     return false;
 }