Skip to content

Commit

Permalink
Version: 1.04
Browse files Browse the repository at this point in the history
  • Loading branch information
redyyu committed Jul 11, 2014
0 parents commit 471ddb6
Show file tree
Hide file tree
Showing 24 changed files with 2,227 additions and 0 deletions.
519 changes: 519 additions & 0 deletions _edit.php

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions _general.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/*
* Settings Page, It's required by WPWSLGeneral Class only.
*
*/
require_once( 'class-wpwsl-list-table.php' );

if(isset($_GET['action']) && isset($_GET['action2'])){
if($_GET['action']=='delete' || $_GET['action2']=='delete'){
if(isset($_GET['tpl'])){
foreach($_GET['tpl'] as $tpl){
delete_template($tpl);
}
}
}
}
if(isset($_GET['delete'])){
delete_template($_GET['delete']);
}

function delete_template($id){
if(!is_wp_error(get_post($id))){
wp_delete_post($id,true);
}
}

$args = array(
'post_type' => 'wpwsl_template',
'posts_per_page' => -1,
'orderby' => 'date',
'post_status' => 'any',
'order'=> 'DESC'
);

$raw=get_posts($args);

$data=array();
foreach($raw as $d){
$status=$d->post_status;

$tmp_key=trim(get_post_meta($d->ID,'_keyword',TRUE));
$key=$tmp_key;
$array_key=explode(',', $tmp_key);

if(count($array_key)>0){
foreach($array_key as $k){
if($k!=''){
foreach($raw as $e){
if($d->ID == $e->ID){
continue;
}
if(get_post_meta($e->ID,'_trigger',TRUE)!='-'){
continue;
}
$tmp_key2=trim(get_post_meta($e->ID,'_keyword',TRUE));
$array_key2=explode(',', $tmp_key2);
foreach($array_key2 as $k2){
if(strtolower(trim($k))==strtolower(trim($k2))){
$key=__('<span class="msg_conflict">'.__('Conflict','WPWSL').'</span><br>','WPWSL').'<i>'.$e->post_title.'</i>';
break;
}
}
}
}
}
}

$type=get_post_meta($d->ID,'_type',TRUE);
$_trigger=get_post_meta($d->ID,'_trigger',TRUE);

switch($_trigger){
case 'default':
$key='<span class="msg_highlight">'.__('*Default*','WPWSL').'</span>';
break;
case 'subscribe':
$key='<span class="msg_highlight">'.__('*Subscribed*','WPWSL').'</span>';
break;
}
if($d->post_status!='publish'){
$key='<span class="msg_disabled">'.__('*Deactivation*','WPWSL').'</span>';
}
$post_title=$d->post_title?$d->post_title:__('(empty)','WPWSL');
$data[]=array('ID'=>$d->ID, 'title'=>$post_title, 'type'=>$type, 'date'=>mysql2date('Y.m.d', $d->post_date), 'trigger_by' => $key);
}

//Prepare Table of elements
$wp_list_table = new WPWSL_List_Table($data);
$wp_list_table->prepare_items();

//Load content
require_once( 'content.php' );
?>
<link href="<?php echo WPWSL_PLUGIN_URL;?>/css/style.css" rel="stylesheet">
<div class="wrap">
<?php echo $content['header'];?>
<?php echo $content['tips_content'];?>
<p class="header_func">
<?php if(current_user_can('manage_options')):?>
<a href="<?php menu_page_url(WPWSL_SETTINGS_PAGE);?>"><?php _e('Settings','WPWSL');?></a>
<?php endif;?>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.imredy.com/wp_wechat/" target="_blank"><?php _e('Help','WPWSL');?></a>
</p>
<hr>
<h2><?php _e('Reply Templates','WPWSL');?> <a href="<?php menu_page_url(WPWSL_GENERAL_PAGE);?>&edit" class="add-new-h2"><?php _e('Add New Template','WPWSL');?></a></h2>
<br>
<!--<ul class='subsubsub'>
<li class='all'><a href='<?php menu_page_url( WPWSL_GENERAL_PAGE);?>' class="current">All<span class="count"> (0) </span></a> |</li>
<li class='publish'><a href='<?php menu_page_url( WPWSL_GENERAL_PAGE);?>&post_status=publish'>Published<span class="count"> (0) </span></a> |</li>
<li class='trash'><a href='<?php menu_page_url( WPWSL_GENERAL_PAGE);?>&post_status=trash'>Trash<span class="count"> (0) </span></a></li>
</ul>-->
<form action="" method="get">
<input type="hidden" name="page" value="<?php echo WPWSL_GENERAL_PAGE;?>" />
<?php $wp_list_table->display(); ?>
</form>
</div>
50 changes: 50 additions & 0 deletions _settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/*
* Settings Page, It's required by WPWSLSettings Class only.
*
*/

$options=$this->options;

$fields=array('token');

foreach($fields as $field){
if(!isset($options[$field])){
$options[$field]='';
}
}
$interface_url=isset($options['token']) && $options['token']!=''?home_url().'/?'.$options['token']:'none';

//Load content
require_once( 'content.php' );
?>
<link href="<?php echo WPWSL_PLUGIN_URL;?>/css/style.css" rel="stylesheet">
<div class="wrap">
<h2><?php _e('WeChat Subscribers Lite','WPWSL')?></h2>
<form action="options.php" method="POST">
<?php settings_fields( $this->option_group );?>
<?php do_settings_sections( $this->page_slug ); ?>
<hr>
<h4><?php _e('Account Settings','WPWSL')?></h4>
<table class="form-table">
<tr valign="top">
<th scope="row"><label>Token</label></th>
<td>
<input type="text" size="30" name="<?php echo $this->option_name ;?>[token]" value="<?php echo $options['token'];?>" class="regular-text"/>
<p class="description"><?php _e('Access verification for your WeChat public platform. Only Latin letter, number, dash and underscore. 30 character limited.','WPWSL')?></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><label>URL</label></th>
<td>
<h4><?php echo $interface_url;?></h4>
<p class="description"><?php _e('First input a TOKEN above and save the settings, then &quot;Copy&quot; and &quot;Bind&quot; this URL to WeChat Platform.','WPWSL')?></p>
</td>
</tr>
</table>

<?php submit_button(); ?>
</form>
<hr>
<?php echo $content['tips_content'];?>
</div>
65 changes: 65 additions & 0 deletions class-wpwsl-general.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
class WPWSL_General{


private $file_general_tpl='_general.php';
private $file_edit_tpl='_edit.php';


private static $_instance;

/**
* Start up
*/

public static function get_instance(){

if(!isset(self::$_instance)){
$c=__CLASS__;
self::$_instance=new $c;
}
return self::$_instance;
}

public function __clone(){
trigger_error('Clone is not allow' ,E_USER_ERROR);
}

private function __construct(){
add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
}

/**
* Add page
*/
public function add_plugin_page(){
// This page will be under "Settings"
$parent_slug=WPWSL_GENERAL_PAGE;
$page_title=__('WeChat Subscribers', 'WPWSL');
$menu_title=__('General', 'WPWSL');
$capability='edit_posts';
$menu_slug=WPWSL_GENERAL_PAGE;
add_submenu_page(
$parent_slug,
$page_title,
$menu_title,
$capability,
$menu_slug,
array( $this, 'create_admin_page' )
);
}

/**
* Options page callback
*/
public function create_admin_page(){
if(!isset($_GET['edit'])){
require_once( $this->file_general_tpl);
}else{
require_once( $this->file_edit_tpl);
}
}

}

?>
145 changes: 145 additions & 0 deletions class-wpwsl-list-table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php
/* -------------------------------------------- *
* Class Definition *
* -------------------------------------------- */

//This part is our very own WP_List_Table

class WPWSL_List_Table extends WP_List_Table {

private $rawData = array();

public function __construct($data){
global $status, $page;
$this->rawData=$data;
parent::__construct( array(
'singular' => 'tpl', //singular name of the listed records
'plural' => 'tpls', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );

}

public function no_items() {
_e( 'No Item found.','WPWSL');
}

public function column_default( $item, $column_name ) {
switch( $column_name ) {
case 'title':
case 'type':
case 'date':
case 'trigger_by':
return $item[ $column_name ];
default:
return print_r( $item, true ) ; //Show the whole array for troubleshooting purposes
}
}

public function get_sortable_columns() {
$sortable_columns = array(
'title' => array('title',false),
'type' => array('type',false),
'date' => array('date',false),
'trigger_by' => array('trigger_by',false)
);
return $sortable_columns;
}

public function get_columns(){
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'WPWSL' ),
'type' => __( 'Type', 'WPWSL' ),
'date' => __( 'Date', 'WPWSL' ),
'trigger_by' => __( 'Trigger by', 'WPWSL' ),
);
return $columns;
}

public function usort_reorder( $a, $b ) {
// If no sort, default to title
$orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'ID';
// If no order, default to asc
$order = ( ! empty($_GET['order'] ) ) ? $_GET['order'] : 'asc';
// Determine sort order
$result = strcmp( $a[$orderby], $b[$orderby] );
// Send final sort direction to usort
return ( $order === 'asc' ) ? $result : -$result;
}

public function column_title($item){
$actions = array(
'edit' => sprintf('<a href="'.menu_page_url(WPWSL_GENERAL_PAGE, false).'&edit=%s">'.__('Edit','WPWSL').'</a>',$item['ID']),
'delete' => sprintf('<a href="'.menu_page_url(WPWSL_GENERAL_PAGE, false).'&delete=%s">'.__('Delete','WPWSL').'</a>',$item['ID']),
);

return sprintf('%1$s %2$s', $item['title'], $this->row_actions($actions) );
}

public function get_bulk_actions() {
$actions = array(
'delete' => __('Delete','WPWSL')
);
return $actions;
}

// public function process_bulk_action() {
//
// if ( 'delete' === $this->current_action() ) {
// if(isset($_GET['tpl'])){
// foreach($_GET['tpl'] as $tpl){
// foreach($this->rawData as $key=>$dt){
// if($dt['ID']==$tpl){
// unset($this->rawData[$key]);
// }
// }
//
// }
// }
// }
// }

public function column_cb($item) {
return sprintf(
'<input type="checkbox" name="tpl[]" value="%s" />', $item['ID']
);
}

public function extra_tablenav( $which ) {
if ( $which == "top" ){
//The code that goes before the table is here
//echo 'top';
}
if ( $which == "bottom" ){
//The code that goes after the table is there
//echo 'bottom';
}
}


public function prepare_items() {
//$this->process_bulk_action();
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
usort( $this->rawData, array( &$this, 'usort_reorder' ) );

$per_page = 10;
$current_page = $this->get_pagenum();
$total_items = count( $this->rawData );

// only ncessary because we have sample data
$this->found_data = array_slice( $this->rawData,( ( $current_page-1 )* $per_page ), $per_page );

$this->set_pagination_args( array(
'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page //WE have to determine how many items to show on a page
));
$this->items = $this->found_data;

}
}

?>
Loading

0 comments on commit 471ddb6

Please sign in to comment.