]> git.nbdom.net Git - nb.git/commitdiff
wp
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 22 Apr 2016 15:39:51 +0000 (16:39 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 22 Apr 2016 15:39:51 +0000 (16:39 +0100)
lib/php/db/wp.php

index 8bfcd927316cb0a34486bf95cd66f1b3982961f5..9cb221248d7b06618394e63e0ccab7bbdcdfebe1 100644 (file)
@@ -11,32 +11,89 @@ class html_table extends WP_List_Table {
     #$fields = $this->get_columns();
     #debug($sort);
     $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
+
+    $this->search_box();
     return;
   }
 
-       public function search_box( $text='Search', $input_id='db' ) {
-               if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
-                       return;
+       public function search_box( $text='Search', $input_id='search' ) {
+    echo '<form role="search" method="get" action="'.$_SERVER['SCRIPT_NAME'].'">';
+
+    echo '<h1>Table: '
+
+      .'<select name="table" onchange="if(this.value != \'0\') this.form.submit();">'
+      .join("",array_map(function($a){
+        return sprintf('<option%s value="%s">%s</option>',$this->_table->p('table') == $a ? ' selected="selected"' : '',$a
+          ,$this->_table->prettyText(preg_replace('/^'.$GLOBALS['wpdb']->prefix.'/','',$a))
+        );},array_keys($this->_table->db()->tables())))
+      .'</select>'
+
+      #.'<select name="db" onchange="if(this.value != \'0\') this.form.submit();">'
+      .'<select name="db" onchange="document.location=\''.preg_replace('/\?.*?(page=\w+).*$/','?\1',$_SERVER['REQUEST_URI']).'&db=\'+this.value">'
+      #.'<select name="db" onchange="if(this.value != \'0\'){var v=this.value;this.form.reset();this.value=v;this.form.submit();}">'
+      .join("",array_map(function($a){
+        return sprintf('<option%s value="%s">%s</option>',$this->_table->p('db') == $a ? ' selected="selected"' : '',$a
+          ,$this->_table->prettyText($a)
+        );},$this->_table->db()->dbs))
+      .'</select>'
+
+      .'<select name="limit" onchange="if(this.value != \'0\') this.form.submit();">'
+      .join("",array_map(function($a){
+        return sprintf('<option%s value="%s">%s</option>',$this->_table->p('limit') == $a ? ' selected="selected"' : '',$a
+          ,$a
+        );},[10,50,100,500]))
+      .'</select>'
+/*
+*/
+
+      .'<a class="page-title-action" href="/wp-admin/post-new.php?post_type=page&amp;action=edit&amp;table='.($this->_table->db()->p('table')).'">Add New</a>'
+    .'</h1>';
+    echo '<p id="search" class="search-box">';
 
-    echo '<p class="search-box">';
-               $input_id = $input_id . '-search-input';
+    foreach ([
+      'orderby',
+      'order',
+      'post_mime_type',
+      'detached',
+      'page',
+      #'limit',
+    ] as $p) {
+      if ( ! empty( $_REQUEST[$p] ) )
+        echo '<input type="hidden" name="'.$p.'" value="' . esc_attr( $_REQUEST[$p] ) . '" />';
+    }
 
-               if ( ! empty( $_REQUEST['orderby'] ) )
-                       echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
-               if ( ! empty( $_REQUEST['order'] ) )
-                       echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
-               if ( ! empty( $_REQUEST['post_mime_type'] ) )
-                       echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
-               if ( ! empty( $_REQUEST['detached'] ) )
-                       echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
+    foreach ($this->get_columns() as $k =>$v) {
+      #echo '<div>';
+      echo '<label for="'.$input_id.'-'.$k.'">'.$v.': ';
+      echo '</label>';
+      echo '<input type="text" id="'.$input_id.'-'.$k.'" name="'.$k.'" value="' .( isset($_REQUEST[$k]) ? esc_attr( $_REQUEST[$k] ) : '' ). '" />';
+      #echo '<div>';
+    }
 
-         submit_button( $text, 'button', '', false, array('id' => 'search-submit') );
+         submit_button( __( 'Search' ), 'button', '', false, array('id' => 'search-submit') );
     echo '</p>';
-  /*
-       <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
-       <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
-  */
+    echo '</form>';
+
+    if (0) {
+      // Query / Search
+      $qin = !empty($_REQUEST['qin']) ? $_REQUEST['qin'] : '';
+      $qout = '';
+      if ($qin) {
+        $q = '[q:'.$qin.']';
+        $qout = "<blockquote>$q</blockquote>".$htis->_table->q($qin);
+      }
+      echo '<div class="wrap">'
+        .'<h2>Query / Search: [q:]'
+        .'<form method="get" action="'.$_SERVER['SCRIPT_NAME'].'">'
+          .'<input type="hidden" name="page" value="'.(isset($_REQUEST['page']) ? $_REQUEST['page'] : '').'"/>'
+          .'<input size="50" type="text" name="qin" value="'.$qin.'"/>'
+          .get_submit_button('Submit','small',null,false)
+        .'</form>'
+        .'<div id="qout">'.$qout.'</div>'
+      .'</div>';
+    }
        }
+
        protected function column_default( $item, $column_name ) { return $item[$column_name]; }
 
        public function get_columns() {