Example #1
0
 /**
  * Adds a resourced based route possibility based on a custom
  * post type or taxonomy.
  * @param WordpressEntity $model
  */
 public function addResourcePossibility(WordpressEntity $model)
 {
     $slug = null;
     if (property_exists($model, "routed") && is_array($model->routed) && array_key_exists("controller", $model->routed)) {
         $controllerName = $model->routed['controller'];
         $controllerObject = new $controllerName();
         $controller = $controllerObject->getShortName();
     } else {
         $controller = Controller::generateClassName($model->getShortName());
     }
     $i18n = Strata::i18n();
     if ($i18n->isLocalized()) {
         $currentLocale = $i18n->getCurrentLocale();
         if ($currentLocale && !$currentLocale->isDefault()) {
             $slugInfo = $model->extractConfig("i18n." . $currentLocale->getCode() . ".rewrite.slug");
             $slug = array_pop($slugInfo);
             if (!is_null($slug)) {
                 $this->automatedRoutes[] = array('*', "/{$slug}/page/[i:pageNumber]/?", "{$controller}#index");
                 $this->automatedRoutes[] = array('*', "/{$slug}/[:slug]/?", "{$controller}#show");
                 $this->automatedRoutes[] = array('*', "/{$slug}/?", "{$controller}#index");
             }
         }
     }
     $slugInfo = $model->extractConfig("rewrite.slug");
     $slug = array_pop($slugInfo);
     if (is_null($slug)) {
         $slug = $model->getWordpressKey();
     }
     $this->automatedRoutes[] = array('*', "/{$slug}/page/[i:pageNumber]/?", "{$controller}#index");
     $this->automatedRoutes[] = array('*', "/{$slug}/[:slug]/?", "{$controller}#show");
     $this->automatedRoutes[] = array('*', "/{$slug}/?", "{$controller}#index");
 }
 /**
  * Wordpress callback that attemps to register additional
  * administration links in Wordpress's backend based on the
  * attached model.
  */
 public function action_addAdminMenus()
 {
     // Default to the model's likely controller.
     $defaultController = Controller::generateClassName($this->model->getShortName());
     $parentSlug = 'edit.php?post_type=' . $this->model->getWordpressKey();
     foreach ($this->getConfiguration() as $func => $config) {
         $config += array('title' => ucfirst($func), 'menu-title' => ucfirst($func), 'capability' => "manage_options", 'icon' => null, 'route' => array($defaultController, $func), 'position' => null);
         // This is to circumvent how Wordpress doesn't let you pass arguments to
         // callbacks so we can send the controller and function to the router.
         // We dont want people to have to specify that odd function name.
         // Allow them to send the controller string name and take care of the rest.
         if (is_string($config['route'])) {
             $route = Router::callback($config['route'], $func);
         } else {
             $route = Router::callback($config['route'][0], $config['route'][1]);
         }
         $uniquePage = $this->model->getWordpressKey() . "_" . $func;
         add_submenu_page($parentSlug, $config['title'], $config['menu-title'], $config['capability'], $uniquePage, $route, $config['icon'], $config['position']);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function applyOptions(array $args)
 {
     $this->keyword = $args[0];
     $this->classname = Controller::generateClassName($this->keyword);
 }