コード例 #1
0
ファイル: manage.php プロジェクト: jinshana/tangocms
 /**
  * Lists all media items that are outstanding, for the user to add
  * meta data such as title/description
  *
  * @return string
  */
 public function outstandingSection()
 {
     $this->setTitle(t('Manage uploaded files'));
     try {
         $category = $this->_model()->getCategory($this->_input->get('cid'));
         $resource = 'media-cat_upload_' . $category['id'];
         if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) {
             throw new Module_NoPermission();
         }
         $cid = (int) $category['id'];
     } catch (Input_KeyNoExist $e) {
         $cid = null;
     } catch (Media_CategoryNoExist $e) {
         $this->_event->error(t('Media category does not exist'));
         $cid = null;
     }
     /**
      * Work out which URL to redirect back to, since if we've come from
      * the 'config' cntrlr, we want to redirect back to that always.
      */
     if (empty($_SESSION['previous_url']) || !empty($_SESSION['media']['fromConfigCntrlr'])) {
         $redirectUrl = $this->_router->makeUrl('media', 'config');
     } else {
         $parsedPreviousUrl = new Router_Url($_SESSION['previous_url']);
         if ($parsedPreviousUrl->module == 'media' && $parsedPreviousUrl->controller == 'config') {
             $_SESSION['media']['fromConfigCntrlr'] = true;
             $redirectUrl = $this->_router->makeUrl('media', 'config');
         } else {
             $redirectUrl = new Router_Url('media');
             if (isset($category['identifier'])) {
                 $redirectUrl->controller('cat')->section($category['identifier']);
             }
         }
     }
     // Get all outstanding media items
     $outstanding = $this->_model()->getOutstandingItems($cid);
     if (($count = count($outstanding)) == 0) {
         $this->_event->error(t('There are currently no outstanding media items'));
         return zula_redirect($redirectUrl);
     } else {
         $form = new View_form('manage/outstanding.html', 'media');
         $form->addElement('media/cid', $cid, 'cid', new Validator_Confirm($cid));
         $form->addElement('media/item', null, t('Items'), array(new Validator_Is('array'), new Validator_Length($count, $count)));
         if ($form->hasInput() && $form->isValid()) {
             /**
              * Update the title and description for all provided media items
              * however the ids must match the selecting outstanding items.
              */
             $validItemIds = array_keys($outstanding);
             // Validate the provided values
             $validatorName = new Validator_Length(1, 255);
             $validatorDesc = new Validator_Length(0, 1000);
             $successCount = 0;
             foreach ($form->getValues('media/item') as $key => $item) {
                 if (in_array($key, $validItemIds)) {
                     $valid = true;
                     if (($errorMsg = $validatorName->validate($item['name'])) !== true) {
                         $valid = false;
                         $this->_event->error(sprintf($errorMsg, t('Titles')));
                     }
                     if (($errorMsg = $validatorDesc->validate($item['desc'])) !== true) {
                         $valid = false;
                         $this->_event->error(sprintf($errorMsg, t('Descriptions')));
                     }
                     if ($valid) {
                         $this->_model()->editItem($key, $item['name'], $item['desc']);
                         unset($outstanding[$key]);
                         ++$successCount;
                     }
                 }
             }
             // Redirect back to the correct location
             if ($successCount > 0) {
                 $langStr = nt('Completed upload for 1 media item', 'Completed upload for %d media items', $successCount);
                 $this->_event->success(sprintf($langStr, $successCount));
             }
             if ($successCount == $count) {
                 unset($_SESSION['media']['fromConfigCntrlr']);
                 return zula_redirect($redirectUrl);
             }
         }
         $form->assign(array('CID' => $cid, 'OUTSTANDING' => $outstanding));
         return $form->getOutput();
     }
 }
コード例 #2
0
ファイル: edit.php プロジェクト: jinshana/tangocms
 /**
  * Allows the user to configure the module that is attached to a
  * sector. This, however, currently depends on JavaScript enabled.
  *
  * @return string
  */
 public function indexSection($layoutName = null)
 {
     $this->setTitle(t('Edit module'));
     $this->setOutputType(self::_OT_CONFIG);
     // Check permission and if a layout has been provided
     if (!$this->_acl->check('content_layout_config_module')) {
         throw new Module_NoPermission();
     } else {
         if ($layoutName === null) {
             $this->_event->error(t('Unable to edit attached module, no layout given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Get correct cntrlr ID that is to be edited
     try {
         $cntrlrId = $this->_router->getArgument('id');
     } catch (Router_ArgNoExist $e) {
         try {
             $cntrlrId = $this->_input->post('content_layout/cid');
         } catch (Input_KeyNoExist $e) {
             $this->_event->error(t('Unable to edit attached module, no ID given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Create the correct layout and ensure cntrlr exists
     $layout = new Layout($layoutName);
     try {
         $cntrlr = $layout->getControllerDetails($cntrlrId);
         $module = new Module($cntrlr['mod']);
         $this->setTitle(sprintf(t('Configure attached module "%1$s"'), $module->title));
         if (!isset($cntrlr['config']['clDescription'])) {
             $cntrlr['config']['clDescription'] = '';
         }
     } catch (Layout_ControllerNoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit controller "%1$d" as it does not exist'), $cntrlrId));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     } catch (Module_NoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit attached module "%1$s" as it does not exist'), $cntrlr['mod']));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     }
     /**
      * Prepare form validation
      */
     $form = new View_form('edit/module.html', $this->getDetail('name'), false);
     $form->addElement('content_layout/config/displayTitle', $cntrlr['config']['displayTitle'], t('Display Title'), new Validator_InArray(array('true', 'false', 'custom')));
     $form->addElement('content_layout/config/customTitle', $cntrlr['config']['customTitle'], t('Custom title'), new Validator_Length(0, 255));
     $form->addElement('content_layout/config/htmlWrapClass', $cntrlr['config']['htmlWrapClass'], t('HTML class'), new Validator_Length(0, 500), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/config/clDescription', $cntrlr['config']['clDescription'], t('Description'), new Validator_Length(0, 255), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/cntrlr', null, t('Controller'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/section', null, t('Section'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/config', null, t('Config'), new Validator_Is('array'), false);
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         try {
             $layout->editController($cntrlr['id'], array('con' => $fd['cntrlr'], 'sec' => $fd['section'], 'order' => $cntrlr['order'], 'config' => isset($fd['config']) ? $fd['config'] : array()));
             try {
                 $roles = $this->_input->post('acl_resources/layout_controller_' . $cntrlr['id']);
             } catch (Input_ValueNoExist $e) {
                 $roles = array();
             }
             $this->_acl->allowOnly('layout_controller_' . $cntrlr['id'], $roles);
             if ($layout->save()) {
                 $this->_event->success(sprintf(t('Configured attached module ID "%d"'), $cntrlr['id']));
             } else {
                 $this->_event->error(t('Unable to save layout, ensure file is writable'));
             }
         } catch (Layout_ControllerNoExist $e) {
             $this->_event->error(sprintf(t('Unable to edit attached module ID "%d" as it does not exist'), $cntrlr['id']));
         } catch (Theme_SectorMapNotWriteable $e) {
             $this->_event->error(sprintf(t('Unable to edit module in sector map: $s'), $e->getMessage()));
         }
         // Redirect back to correct location, FPSC layouts go back to index
         $url = new Router_Url('content_layout');
         $url->siteType($this->_router->getSiteType());
         if (strpos($layoutName, 'fpsc-') === 0) {
             $url->queryArgs(array('type' => substr($layoutName, 5)));
         } else {
             $url->controller('manage')->section($layoutName);
         }
         return zula_redirect($url);
     }
     /**
      * Gets all displays modes that this module offers, the current display
      * mode being used - once done start building up the form.
      */
     $displayModes = Hooks::notifyAll($module->name . '_display_modes');
     $currentMode = Hooks::notifyAll($module->name . '_resolve_mode', $cntrlr['con'], $cntrlr['sec'], $cntrlr['config']);
     $this->addAsset('js/edit.js');
     $form->assign(array('CID' => $cntrlr['id'], 'LAYOUT_NAME' => $layoutName, 'SECTOR' => $cntrlr['sector'], 'MODULE' => $module->getDetails(), 'DISPLAY_MODES' => empty($displayModes) ? array('default' => t('Default')) : $displayModes, 'CURRENT_MODE' => empty($currentMode) ? 'default' : $currentMode[0]));
     $jsConfig = array_merge($cntrlr, $cntrlr['config']);
     unset($jsConfig['config']);
     $form->assignHtml(array('JS_CONFIG' => zula_array_js_string($jsConfig), 'ACL_FORM' => $this->_acl->buildForm(array(t('View attached module') => 'layout_controller_' . $cntrlr['id']))));
     return $form->getOutput();
 }