Ejemplo n.º 1
0
 /**
  * Add all tables in which the user is allowed to create records to the
  * Admin Bar new-content menu.
  * @global \WP_Admin_Bar $wp_admin_bar
  * @global \wpdb $wpdb
  */
 public function admin_bar_menu()
 {
     global $wp_admin_bar, $wpdb;
     $db = new DB\Database($wpdb);
     foreach ($db->get_tables() as $table) {
         if (!DB\Grants::current_user_can(DB\Grants::CREATE, $table->get_name())) {
             continue;
         }
         $wp_admin_bar->add_menu(array('parent' => 'new-content', 'id' => TABULATE_SLUG . '-' . $table->get_name(), 'title' => $table->get_title(), 'href' => $table->get_url('index', null, 'record')));
     }
 }
Ejemplo n.º 2
0
 /**
  * Render the template and return the output.
  * @return string
  */
 public function render()
 {
     if (isset($_SESSION[$this->transientNotices])) {
         unset($_SESSION[$this->transientNotices]);
     }
     $twig = new \Twig_Environment($this->loader);
     // Add titlecase filter.
     $titlecase_filter = new \Twig_SimpleFilter('titlecase', '\\Tabulate\\Text::titlecase');
     $twig->addFilter($titlecase_filter);
     // Add strtolower filter.
     $strtolower_filter = new \Twig_SimpleFilter('strtolower', function ($str) {
         if (is_array($str)) {
             return array_map('strtolower', $str);
         } else {
             return strtolower($str);
         }
     });
     $twig->addFilter($strtolower_filter);
     // Enable debugging.
     if (Config::debug()) {
         $this->queries = DB\Database::getQueries();
         $twig->enableDebug();
         $twig->addExtension(new \Twig_Extension_Debug());
     }
     // Render the template.
     if (!empty($this->templateString)) {
         $template = $twig->createTemplate($this->templateString);
     } else {
         $template = $twig->loadTemplate($this->templateName);
     }
     return $template->render($this->data);
 }