public function initializeMetaboxes()
 {
     foreach ($this->metaboxes as $metabox) {
         $callback = isset($metabox['requestAction']) ? $metabox['requestAction'] : array('controller' => 'metaboxes', 'action' => 'edit');
         $callback = GummDispatcher::getCallbackToDispatch($callback);
         if (!$callback) {
             trigger_error(__('Invalid callback to dispatch for metabox', 'gummfw'));
         }
         $metabox['page'] = (array) $metabox['page'];
         $pages = array();
         foreach ($metabox['page'] as $k => $page) {
             $type = $page;
             $not = array();
             if (is_array($page)) {
                 $type = $k;
                 if (isset($page['NOT'])) {
                     $not = (array) $page['NOT'];
                 }
             }
             if ($type === 'single') {
                 $postTypes = $this->Post->getPostTypes();
                 foreach ($postTypes as $postType) {
                     if (!in_array($postType, $not)) {
                         $this->addMetaBox($metabox, $callback, $postType);
                         $pages[] = $postType;
                     }
                 }
             } else {
                 $shouldAdd = true;
                 if (isset($_REQUEST['post']) && in_array($_REQUEST['post'], $not)) {
                     $shouldAdd = false;
                 }
                 if ($shouldAdd) {
                     $this->addMetaBox($metabox, $callback, $type);
                     $pages[] = $type;
                 }
             }
         }
         if (isset($metabox['hidden']) && $metabox['hidden']) {
             $hideOn = $pages;
             if ($metabox['hidden'] !== true) {
                 $hideOn = array();
                 $metabox['hidden'] = (array) $metabox['hidden'];
                 foreach ($metabox['hidden'] as $hideOnType) {
                     if ($hideOnType === 'single') {
                         $hideOn = array_merge($hideOn, $this->Post->getPostTypes());
                     } else {
                         $hideOn[] = $hideOnType;
                     }
                 }
             }
             foreach ($hideOn as $page) {
                 if (!isset($this->hiddenMetaboxes[$page])) {
                     $this->hiddenMetaboxes[$page] = array();
                 }
                 $this->hiddenMetaboxes[$page][] = $metabox['id'];
             }
         }
     }
 }
예제 #2
0
 /**
  * @param array $callback
  * @param mixed $params
  * @return void
  */
 public function requestAction($requested, $render = true)
 {
     if (!isset($requested['controller'])) {
         if (is_a($this, 'View')) {
             if (isset($this->controller)) {
                 $requested['controller'] = str_replace('_controller', '', Inflector::underscore(get_class($this->controller)));
             }
         }
     }
     if (!isset($requested['controller']) || !isset($requested['action'])) {
         return false;
     }
     $callback = GummDispatcher::getCallbackToDispatch($requested);
     if (!$callback) {
         return false;
     }
     $args = GummRouter::getUrlParams($requested);
     $params = $args['params'];
     $controller =& $callback[0];
     $controller->startupProcess();
     $return = call_user_func_array($callback, $params);
     if ($render === false) {
         ob_start();
         $controller->shutdownProcess(false);
         $return = ob_get_clean();
     } else {
         $controller->shutdownProcess(false);
     }
     return $return;
 }