-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b7057f
commit bfefb21
Showing
3 changed files
with
307 additions
and
4 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
classes/views/class-jaiminho-view-subscribers-csvimport.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
// Prevent loading this file directly | ||
if ( !defined('SENDPRESS_VERSION') ) { | ||
header('HTTP/1.0 403 Forbidden'); | ||
die; | ||
} | ||
|
||
class Jaiminho_View_Subscribers_Csvimport extends Jaiminho_View_Subscribers { | ||
|
||
|
||
// function save(){ | ||
// //$this->security_check(); | ||
// $uploadfiles = $_FILES['uploadfiles']; | ||
// if (is_array($uploadfiles)) { | ||
// foreach ($uploadfiles['name'] as $key => $value) { | ||
// | ||
// // look only for uploded files | ||
// if ($uploadfiles['error'][$key] == 0) { | ||
// | ||
// $filetmp = $uploadfiles['tmp_name'][$key]; | ||
// | ||
// //clean filename and extract extension | ||
// $filename = $uploadfiles['name'][$key]; | ||
// | ||
// // get file info | ||
// // @fixme: wp checks the file extension.... | ||
// $filetype = wp_check_filetype( basename( $filename ), null ); | ||
// $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) ); | ||
// $filename = $filetitle . '.' . $filetype['ext']; | ||
// $upload_dir = wp_upload_dir(); | ||
// if( $filetype['ext'] != 'csv' ){ | ||
// SendPress_Admin::redirect('Subscribers_Csvimport',array('listID'=> SPNL()->validate->_int( 'listID' ))); | ||
// } | ||
// | ||
// /** | ||
// * Check if the filename already exist in the directory and rename the | ||
// * file if necessary | ||
// */ | ||
// $i = 0; | ||
// while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) { | ||
// $filename = $filetitle . '_' . $i . '.' . $filetype['ext']; | ||
// $i++; | ||
// } | ||
// $filedest = $upload_dir['path'] . '/' . $filename; | ||
// | ||
// $filedest = str_replace('\\','/', $filedest); | ||
// /** | ||
// * Check write permissions | ||
// */ | ||
// if ( !is_writeable( $upload_dir['path'] ) ) { | ||
// SendPress_Option::set('import_error', true); | ||
// //$this->_error = true; | ||
// //$this->msg_e('Unable to write to directory %s. Is this directory writable by the server?'); | ||
// //return; | ||
// } | ||
// | ||
// /** | ||
// * Save temporary file to uploads dir | ||
// */ | ||
// if ( !@move_uploaded_file($filetmp, $filedest) ){ | ||
// SendPress_Option::set('import_error', true); | ||
// //$this->msg_e("Error, the file $filetmp could not moved to : $filedest "); | ||
// //continue; | ||
// } | ||
// | ||
// update_post_meta(SPNL()->validate->_int( 'listID' ),'csv_import',$filedest); | ||
// if(SendPress_Option::get('import_error', false) == false ){ | ||
// SendPress_Admin::redirect('Subscribers_Csvprep',array('listID'=> SPNL()->validate->_int( 'listID' ))); | ||
// } | ||
// /* | ||
// $attachment = array( | ||
// 'post_mime_type' => $filetype['type'], | ||
// 'post_title' => $filetitle, | ||
// 'post_content' => '', | ||
// 'post_status' => 'inherit' | ||
// ); | ||
// | ||
// $attach_id = wp_insert_attachment( $attachment, $filedest ); | ||
// require_once( ABSPATH . "wp-admin" . '/includes/image.php' ); | ||
// $attach_data = wp_generate_attachment_metadata( $attach_id, $filedest ); | ||
// wp_update_attachment_metadata( $attach_id, $attach_data ); | ||
// */ | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
function html() { ?> | ||
<?php | ||
if( SendPress_Option::get('import_error', false) == true ) { ?> | ||
<div class="alert alert-danger"> | ||
<?php _e('We had a problem saving your upload','sendpress'); ?>. | ||
</div> | ||
<?php } ?> | ||
<div id="taskbar" class="lists-dashboard rounded group"> | ||
<h2><?php _e('Import CSV to ','sendpress'); ?><?php echo get_the_title(SPNL()->validate->_int( 'listID' )); ?></h2> | ||
</div> | ||
<div class="boxer"> | ||
<div class="boxer-inner"> | ||
<form method="post" action="<?php echo esc_url( admin_url('admin.php') ); ?>" enctype="multipart/form-data" > | ||
<input type="hidden" name="action" value="import"> | ||
<input type="hidden" name="listID" value="<?php echo SPNL()->validate->_int( 'listID' ); ?>" /> | ||
<input type="file" name="uploadfiles" id="uploadfiles" size="35" class="uploadfiles" /> | ||
<button class="button-primary" type="submit" name="uploadfile" id="uploadfile_btn" >Upload</button> | ||
<?php | ||
SendPress_Option::set('import_error', false); | ||
SendPress_Data::nonce_field(); ?> | ||
</form> | ||
</div> | ||
</div> | ||
<?php | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
// Prevent loading this file directly | ||
if ( !defined('SENDPRESS_VERSION') ) { | ||
header('HTTP/1.0 403 Forbidden'); | ||
die; | ||
} | ||
|
||
class Jaiminho_View_Subscribers extends SendPress_View { | ||
function _get_called_class(){ | ||
return "Jaiminho_View_Subscribers"; | ||
} | ||
|
||
function admin_init(){ | ||
add_action('load-sendpress_page_sp-subscribers',array($this,'screen_options')); | ||
//add_action('sendpress-subscribers-sub-menu', array('SendPress_View_Subscribers','default_header')); | ||
} | ||
|
||
function delete_list(){ | ||
SendPress_Data::delete_list( SPNL()->validate->_int('listID') ); | ||
wp_redirect( esc_url_raw( admin_url('admin.php?page='.SPNL()->validate->page() ) ) ); | ||
} | ||
|
||
function delete_lists_bulk(){ | ||
$list_delete = SPNL()->validate->_int_array('list'); | ||
foreach ($list_delete as $listID) { | ||
SendPress_Data::delete_list( SPNL()->validate->int($listID)); | ||
} | ||
wp_redirect( esc_url_raw( admin_url('admin.php?page='.SPNL()->validate->page() ) ) ); | ||
} | ||
|
||
|
||
function export_list(){ | ||
//$this->security_check(); | ||
$l = SPNL()->validate->_int('listID'); | ||
if( $l > 0 ){ | ||
$items = SendPress_Data::export_subscirbers( $l ); | ||
header("Content-type:text/octect-stream"); | ||
header("Content-Disposition:attachment;filename=sendpress.csv"); | ||
print "email,firstname,lastname,status \n"; | ||
foreach($items as $user) { | ||
print $user->email . ",". $user->firstname.",". $user->lastname.",". $user->status."\n" ; | ||
} | ||
} | ||
exit; | ||
} | ||
|
||
function sub_menu(){ | ||
?> | ||
<div class="navbar navbar-default" > | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> | ||
<span class="sr-only"><?php _e('Toggle navigation','sendpress'); ?></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
|
||
</button> | ||
<a class="navbar-brand" href="#"><?php _e('Subscribers','sendpress'); ?></a> | ||
</div> | ||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | ||
<ul class="nav navbar-nav"> | ||
<li <?php if(! SPNL()->validate->_isset('view') ){ ?>class="active"<?php } ?> > | ||
<a href="<?php echo SendPress_Admin::link('Subscribers'); ?>"><i class="icon-list "></i> <?php _e('Lists','sendpress'); ?></a> | ||
</li> | ||
<?php do_action('sendpress-add-submenu-item', SPNL() );?> | ||
<li <?php if(SPNL()->validate->_string('view') === 'all'){ ?>class="active"<?php } ?> > | ||
<a href="<?php echo SendPress_Admin::link('Subscribers_All'); ?>"><i class="icon-user "></i> <?php _e('All Subscribers','sendpress'); ?></a> | ||
</li> | ||
<?php if(SendPress_Option::get('beta')){ ?> | ||
<li <?php if(SPNL()->validate->_string('view') === 'custom'){ ?>class="active"<?php } ?> > | ||
<a href="<?php echo SendPress_Admin::link('Subscribers_Custom'); ?>"><i class="icon-list "></i> <?php _e('Custom Fields','sendpress'); ?></a> | ||
</li> | ||
<?php } ?> | ||
|
||
</ul> | ||
</div> | ||
</div> | ||
|
||
<?php | ||
|
||
do_action('sendpress-subscribers-sub-menu'); | ||
} | ||
|
||
function screen_options(){ | ||
|
||
$screen = get_current_screen(); | ||
|
||
$args = array( | ||
'label' => __('Lists per page', 'sendpress'), | ||
'default' => 10, | ||
'option' => 'sendpress_lists_per_page' | ||
); | ||
add_screen_option( 'per_page', $args ); | ||
} | ||
|
||
function default_header(){ | ||
?> | ||
|
||
<?php | ||
} | ||
|
||
function html() { | ||
SendPress_Tracking::event('Lists Tab'); | ||
//Create an instance of our package class... | ||
$testListTable = new SendPress_Lists_Table(); | ||
//Fetch, prepare, sort, and filter our data... | ||
$testListTable->prepare_items(); | ||
|
||
?> | ||
<!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions --> | ||
<div id="button-area"> | ||
<a class="btn btn-primary btn-large" href="?page=<?php echo SPNL()->validate->page(); ?>&view=listcreate"><?php _e('Create List','sendpress'); ?></a> | ||
</div> | ||
<h2><?php _e('Lists','sendpress'); ?></h2> | ||
<form id="sendpress-lists" method="get"> | ||
<!-- For plugins, we also need to ensure that the form posts back to our current page --> | ||
<input type="hidden" name="page" value="<?php echo SPNL()->validate->page() ?>" /> | ||
<!-- Now we can render the completed list table --> | ||
<?php $testListTable->display(); ?> | ||
<?php wp_nonce_field($this->_nonce_value); ?> | ||
</form> | ||
<?php | ||
} | ||
|
||
} | ||
SendPress_Admin::add_cap('Subscribers','sendpress_subscribers'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters