results = $results; $this->scolumns = $columns; parent::__construct( array( 'plural' => 'Tracker', 'singular' => 'Tracker', ) ); } function ajax_user_can() { return true; } function prepare_items() { $trackingManager = new AjaxyTracker(); $fields = $trackingManager->get_all_fields(); $search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : ''; $args = array( 'search' => $search, 'page' => $this->get_pagenum(), 'number' => $tags_per_page, ); if ( !empty( $_REQUEST['orderby'] ) ) $args['orderby'] = trim( stripslashes( $_REQUEST['orderby'] ) ); if ( !empty( $_REQUEST['order'] ) ) $args['order'] = trim( stripslashes( $_REQUEST['order'] ) ); $this->callback_args = $args; $this->set_pagination_args( array( 'total_items' => sizeof($fields), 'per_page' => 10, ) ); } function has_items() { // todo: populate $this->items in prepare_items() return true; } function get_bulk_actions() { $actions = array(); //$actions['hide'] = __( 'Hide from results' ); //$actions['show'] = __( 'Show in results' ); return $actions; } function current_action() { if ( isset( $_REQUEST['action'] ) && ( 'hide' == $_REQUEST['action'] || 'hide' == $_REQUEST['action2'] ) ) return 'bulk-hide'; return parent::current_action(); } function get_columns() { $columns = array( 'cb' => '', 'keyword' => __( 'Keyword' ), 'details' => __( 'Details' ), 'total' => __( 'Total' ), 'average_total_results' => __( 'Average ResultsAverage results for this keyword' ), 'date' => __( 'Date' ), 'total_results' => __( 'Total ResultsTotal search results' ), 'time'=> __( 'Date/Time' ), 'htime'=> __( 'Time' ), 'url' => __( 'Url' ), 'count_search' => __( 'Search total keywords search' ), 'count_unique' => __( 'Unique Search total unique keywords search' ), 'count_zero' => __( 'Keywords with zero resultsKeywords with zero or no results' ), 'count_zero_time' => __( 'Keywords with zero resultsKeywords with zero or no results' ), 'count_kzero' => __( 'Total searchCount searches for a specific keyword' ), ); $mcolumns = array(); foreach($this->scolumns as $value){ if(isset($columns[$value])) { $mcolumns[$value] = $columns[$value]; } } return $mcolumns; } function get_column_info() { if ( isset( $this->_column_headers ) ) return $this->_column_headers; $screen = get_current_screen(); $columns = $this->get_columns(); $hidden = array(); $this->_column_headers = array( $columns, $hidden, $this->get_sortable_columns() ); return $this->_column_headers; } /** * Print column headers, accounting for hidden and sortable columns. * * @since 3.1.0 * @access protected * * @param bool $with_id Whether to set the id attribute or not */ function print_column_headers( $with_id = true ) { $screen = get_current_screen(); list( $columns, $hidden, $sortable ) = $this->get_column_info(); $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $current_url = remove_query_arg( 'paged', $current_url ); if ( isset( $_GET['orderby'] ) ) $current_orderby = $_GET['orderby']; else $current_orderby = ''; if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) $current_order = 'desc'; else $current_order = 'asc'; foreach ( $columns as $column_key => $column_display_name ) { $class = array( 'manage-column', "column-$column_key" ); $style = ''; if ( in_array( $column_key, $hidden ) ) $style = 'display:none;'; $style = ' style="' . $style . '"'; if ( 'cb' == $column_key ) $class[] = 'check-column'; elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) $class[] = 'num'; if ( isset( $sortable[$column_key] ) ) { list( $orderby, $desc_first ) = $sortable[$column_key]; if ( $current_orderby == $orderby ) { $order = 'asc' == $current_order ? 'desc' : 'asc'; $class[] = 'sorted'; $class[] = $current_order; } else { $order = $desc_first ? 'desc' : 'asc'; $class[] = 'sortable'; $class[] = $desc_first ? 'asc' : 'desc'; } $column_ssort = "int"; if(in_array($column_key, array('date', 'keyword', 'time', 'htime'))){ $column_ssort = "string"; } $column_display_name = '' . $column_display_name . ''; } $id = $with_id ? "id='$column_key'" : ''; if ( !empty( $class ) ) $class = "class='" . join( ' ', $class ) . "'"; echo "$column_display_name"; } } function get_sortable_columns() { $columns = array( 'cb' => '', 'keyword' => __( 'Keyword' ), 'details' => __( 'Details' ), 'total' => __( 'Total' ), 'average_total_results' => __( 'Average ResultsAverage results for this keyword' ), 'date' => __( 'Date' ), 'total_results' => __( 'Total ResultsTotal search results' ), 'time'=> __( 'Date/Time' ), 'htime'=> __( 'Time' ), 'url' => __( 'Url' ), 'count_search' => __( 'Search total keywords search' ), 'count_unique' => __( 'Unique Search total unique keywords search' ), 'count_zero' => __( 'Keywords with zero resultsKeywords with zero or no results' ), 'count_zero_time' => __( 'Keywords with zero resultsKeywords with zero or no results' ), 'count_kzero' => __( 'Total searchCount searches for a specific keyword' ), ); $mcolumns = array(); foreach($this->scolumns as $value){ if(isset($columns[$value])) { $mcolumns[$value] = $columns[$value]; } } return $mcolumns; } function display_rows_or_placeholder() { $fields = $this->results; $args = wp_parse_args( $this->callback_args, array( 'page' => 1, 'number' => 20, 'search' => '', 'hide_empty' => 0 ) ); extract( $args, EXTR_SKIP ); $args['offset'] = $offset = ( $page - 1 ) * $number; // convert it to table rows $out = ''; $count = 0; $orderby = 'order'; $order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc','desc')) ? $_REQUEST['order']: 'asc'); if(!empty($fields)){ foreach($fields as $row){ $this->single_row($row); } } if ( empty( $fields ) ) { list( $columns, $hidden ) = $this->get_column_info(); echo ''; $this->no_items(); echo ''; } else { echo $out; } } function single_row( $field, $level = 0 ) { static $row_class = ''; $add_class = ''; $row_class = ( $row_class == '' ? ' class="alternate '.$add_class.'"' : ' class="'.$add_class.'"' ); echo ''; echo $this->single_row_columns( $field ); echo ''; } function column_cb( $field ) { return ''; } function column_default( $field, $column_name ) { return ''.($field->{$column_name} == '' ? 0 : $field->{$column_name}).''; } function column_details( $field ) { $m = explode(',', $field->details); $counts = array_count_values ($m); $s = array(); $l = 0; foreach($counts as $key => $value) { $l += $value; $s[] = ''.$value.' ('.$this->label_key($key).')'; } return implode(', ', $s).''; } function label_key($key) { $labels = array('s' => _('Search'), 'ls'=> _('Live Search')); if(in_array($key,array_keys($labels))){ return $labels[$key]; } return $key; } function column_count_zero( $field) { $dateFrom = (isset($field->date) ? $field->date : $this->dateFrom); $dateTo = (isset($field->date) ? $field->date : $this->dateTo); return ($field->count_zero == '' ? '0' : ''.$field->count_zero.' - ('._('View details').')'); } function column_count_zero_time( $field) { $time = explode(' - ', $field->htime); $from = explode( ':', $time[0]); $to = explode( ':', $time[1]); $timeFromHour = $from[0]; $timeToHour = $to[0]; $timeFromMinute = $from[1]; $timeToMinute = $to[1]; $timeSpan = $timeToMinute - $timeFromMinute >= 0 ? $timeToMinute - $timeFromMinute : ($timeToMinute + 60) - $timeFromMinute; $timeSpan += abs($timeFromHour - $timeToHour) > 0 ? abs($timeFromHour - $timeToHour)*60 : 0; return ($field->count_zero_time == '' ? '0' : ''.$field->count_zero_time.' - ('._('View details').')'); } /** * Outputs the hidden row displayed when inline editing * * @since 3.1.0 */ function inline_edit() { } } ?>