|
@@ -2,36 +2,38 @@
|
|
|
|
|
|
if (!class_exists("plug_usermanager")) {
|
|
if (!class_exists("plug_usermanager")) {
|
|
|
|
|
|
- function arrayFromCSV($file, $hasFieldNames = false, $delimiter = ',', $enclosure='') {
|
|
|
|
- $result = Array();
|
|
|
|
- $size = filesize($file) +1;
|
|
|
|
- $file = fopen($file, 'r');
|
|
|
|
- #TO DO: There must be a better way of finding out the size of the longest row... until then
|
|
|
|
- if ($hasFieldNames) $keys = fgetcsv($file, $size, $delimiter, $enclosure);
|
|
|
|
- while ($row = fgetcsv($file, $size, $delimiter, $enclosure)) {
|
|
|
|
- $n = count($row); $res=array();
|
|
|
|
- for($i = 0; $i < $n; $i++) {
|
|
|
|
- $idx = ($hasFieldNames) ? $keys[$i] : $i;
|
|
|
|
- $res[$idx] = $row[$i];
|
|
|
|
- }
|
|
|
|
- $result[] = $res;
|
|
|
|
- }
|
|
|
|
- fclose($file);
|
|
|
|
- return $result;
|
|
|
|
- }
|
|
|
|
|
|
+ function arrayFromCSV($file, $hasFieldNames = false, $delimiter = ',', $enclosure = '') {
|
|
|
|
+ $result = Array();
|
|
|
|
+ $size = filesize($file) + 1;
|
|
|
|
+ $file = fopen($file, 'r');
|
|
|
|
+ #TO DO: There must be a better way of finding out the size of the longest row... until then
|
|
|
|
+ if ($hasFieldNames) {
|
|
|
|
+ $keys = fgetcsv($file, $size, $delimiter, $enclosure);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ while ($row = fgetcsv($file, $size, $delimiter, $enclosure)) {
|
|
|
|
+ $n = count($row);
|
|
|
|
+ $res = array();
|
|
|
|
+ for ($i = 0; $i < $n; $i++) {
|
|
|
|
+ $idx = ($hasFieldNames) ? $keys[$i] : $i;
|
|
|
|
+ $res[$idx] = $row[$i];
|
|
|
|
+ }
|
|
|
|
+ $result[] = $res;
|
|
|
|
+ }
|
|
|
|
+ fclose($file);
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
function sanitize_username($username) {
|
|
function sanitize_username($username) {
|
|
- $parts = explode("@", $username);
|
|
|
|
- if (count($parts) == 2) {
|
|
|
|
- $username = $parts[0];
|
|
|
|
- }
|
|
|
|
- return $username;
|
|
|
|
|
|
+ $parts = explode("@", $username);
|
|
|
|
+ if (count($parts) == 2) {
|
|
|
|
+ $username = $parts[0];
|
|
|
|
+ }
|
|
|
|
+ return $username;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- class plug_usermanager {
|
|
|
|
|
|
+ class plug_usermanager {
|
|
function __construct($ns) {
|
|
function __construct($ns) {
|
|
- $this->title = __("plug_usermanager","dagsopt");
|
|
|
|
|
|
+ $this->title = __("plug_usermanager", "dagsopt");
|
|
$this->pluginname = $ns->pluginname;
|
|
$this->pluginname = $ns->pluginname;
|
|
$this->file = $ns->file;
|
|
$this->file = $ns->file;
|
|
$this->ns = $ns;
|
|
$this->ns = $ns;
|
|
@@ -40,229 +42,190 @@ if (!class_exists("plug_usermanager")) {
|
|
function start() {
|
|
function start() {
|
|
// register_setting("section", "demo-file", array(&this,"handle_file_upload"));
|
|
// register_setting("section", "demo-file", array(&this,"handle_file_upload"));
|
|
|
|
|
|
- add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
|
|
|
|
|
|
+ add_role("betalende-abonnent", "Betalende abonnent", array('read' => true, 'level_0' => true));
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function handle_file_upload($option)
|
|
|
|
- {
|
|
|
|
- if(!empty($_FILES["demo-file"]["tmp_name"]))
|
|
|
|
- {
|
|
|
|
- $urls = wp_handle_upload($_FILES["demo-file"], array('test_form' => FALSE));
|
|
|
|
- $temp = $urls["url"];
|
|
|
|
- return $temp;
|
|
|
|
- }
|
|
|
|
|
|
+ function handle_file_upload($option) {
|
|
|
|
+ if (!empty($_FILES["demo-file"]["tmp_name"])) {
|
|
|
|
+ $urls = wp_handle_upload($_FILES["demo-file"], array('test_form' => FALSE));
|
|
|
|
+ $temp = $urls["url"];
|
|
|
|
+ return $temp;
|
|
|
|
+ }
|
|
|
|
|
|
- return $option;
|
|
|
|
|
|
+ return $option;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- function help(){
|
|
|
|
- ?>
|
|
|
|
- plug_usermanager
|
|
|
|
- <?php
|
|
|
|
- }
|
|
|
|
|
|
+ function help() {
|
|
|
|
+ ?>
|
|
|
|
+ plug_usermanager
|
|
|
|
+ <?php
|
|
|
|
+}
|
|
|
|
|
|
|
|
+ function Option($pre) {
|
|
|
|
|
|
-
|
|
|
|
- function Option($pre){
|
|
|
|
-
|
|
|
|
- update_option ( $pre.'_delimiter', $_POST [ $pre.'_delimiter' ] );
|
|
|
|
- update_option ( $pre.'_textenclose', $_POST [ $pre.'_textenclose' ] );
|
|
|
|
|
|
+ update_option($pre . '_delimiter', $_POST[$pre . '_delimiter']);
|
|
|
|
+ update_option($pre . '_textenclose', $_POST[$pre . '_textenclose']);
|
|
|
|
|
|
- $nonce = $_REQUEST['_wpnonce'];
|
|
|
|
- if ( ! wp_verify_nonce( $nonce, 'filen-nonce' ) ) {
|
|
|
|
- // This nonce is not valid.
|
|
|
|
- die( __( 'Security check', 'textdomain' ) );
|
|
|
|
- } else {
|
|
|
|
- // The nonce was valid.
|
|
|
|
- // Do stuff here.
|
|
|
|
- if(isset($_FILES) && !empty($_FILES)){
|
|
|
|
- if($_FILES['filen']){
|
|
|
|
|
|
+ $nonce = $_REQUEST['_wpnonce'];
|
|
|
|
+ if (!wp_verify_nonce($nonce, 'filen-nonce')) {
|
|
|
|
+ // This nonce is not valid.
|
|
|
|
+ die(__('Security check', 'textdomain'));
|
|
|
|
+ } else {
|
|
|
|
+ // The nonce was valid.
|
|
|
|
+ // Do stuff here.
|
|
|
|
+ if (isset($_FILES) && !empty($_FILES)) {
|
|
|
|
+ if ($_FILES['filen']) {
|
|
|
|
|
|
|
|
+ $upload = wp_upload_dir();
|
|
|
|
+ $upload_dir = $upload['basedir'];
|
|
|
|
+ $upload_dir = $upload_dir . '/assets';
|
|
|
|
|
|
- $upload = wp_upload_dir();
|
|
|
|
- $upload_dir = $upload['basedir'];
|
|
|
|
- $upload_dir = $upload_dir . '/assets';
|
|
|
|
-
|
|
|
|
- move_uploaded_file($_FILES['filen']['tmp_name'], $upload_dir."/users.csv");
|
|
|
|
|
|
+ move_uploaded_file($_FILES['filen']['tmp_name'], $upload_dir . "/users.csv");
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function Cruncher($pre) {
|
|
|
|
+ if (isset($_REQUEST['nodryrun'])) {
|
|
|
|
+ $testmode = false;
|
|
|
|
+ echo ("RUNNING LIVE<br>");
|
|
|
|
+ } else {
|
|
|
|
+ echo ("RUNNING TEST<br>");
|
|
|
|
+ $testmode = true;
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ $upload = wp_upload_dir();
|
|
|
|
+ $upload_dir = $upload['basedir'];
|
|
|
|
+ $upload_dir = $upload_dir . '/assets';
|
|
|
|
+
|
|
|
|
+ $arr = arrayFromCSV($upload_dir . "/users.csv", true, get_option($pre . '_delimiter', ';'), get_option($pre . '_textenclose', 'double') == "double" ? '"' : "'");
|
|
|
|
+ $ii = 0;
|
|
|
|
+ $max = count($arr);
|
|
|
|
+ $resu = array();
|
|
|
|
+ foreach ($arr as $num => $user) {
|
|
|
|
+ $ii++;
|
|
|
|
+ echo ("$max : $ii -> ");
|
|
|
|
+ flush();
|
|
|
|
+ if ($user['Spærret'] == "") {
|
|
|
|
+
|
|
|
|
+ $user_email = $user['E-mail'];
|
|
|
|
+
|
|
|
|
+ $user_name = sanitize_username("T" . $user['Telefon']);
|
|
|
|
+ $user_id = username_exists($user_name);
|
|
|
|
+ if (!$user_id && false == email_exists($user_email)) {
|
|
|
|
+ $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
|
|
|
|
+ if ($testmode) {
|
|
|
|
+ //$user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
|
|
+ //wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
|
|
|
|
+ //wp_send_new_user_notifications($user_id,'both');
|
|
|
|
+ $resu[] = "$user_id mock created : $user_name $user_email ";
|
|
|
|
+ } else {
|
|
|
|
+ $user_id = wp_create_user($user_name, $random_password, $user_email);
|
|
|
|
+ wp_update_user(array('ID' => $user_id, 'role' => 'betalende-abonnent'));
|
|
|
|
+
|
|
|
|
+ wp_send_new_user_notifications($user_id, 'both');
|
|
|
|
+ $resu[] = "$user_id created : $user_name $user_email ";
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $resu[] = "$user_id or $user_email exists";
|
|
|
|
+ $random_password = __('User already exists. Password inherited.', 'textdomain');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ echo ("$user_id, $user_name, $random_password, $user_email <br>");
|
|
|
|
+ flush();
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ $resu[] = "$user_email spærret";
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ if ($testmode) {
|
|
|
|
+ print_r($resu);
|
|
|
|
+ echo ("DONE test");
|
|
|
|
+ } else {
|
|
|
|
|
|
|
|
+ $aemail = get_bloginfo('admin_email');
|
|
|
|
+ $rr = wp_mail($aemail, 'CCR ' . count($resu) . " : " . getenv('HOSTNAME') . " : " . $_SERVER['REMOTE_ADDR'] . " : " . $_SERVER['SERVER_ADDR'] . " : " . $_SERVER['SERVER_NAME'] . " " . date("U"), "::" . print_r($resu, true));
|
|
|
|
+ echo ("DONE live");
|
|
|
|
|
|
- function Cruncher($pre){
|
|
|
|
- if(isset($_REQUEST['nodryrun'])){
|
|
|
|
- $testmode = false;
|
|
|
|
- echo("RUNNING LIVE<br>");
|
|
|
|
- }else{
|
|
|
|
- echo("RUNNING TEST<br>");
|
|
|
|
- $testmode = true;
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- $upload = wp_upload_dir();
|
|
|
|
- $upload_dir = $upload['basedir'];
|
|
|
|
- $upload_dir = $upload_dir . '/assets';
|
|
|
|
-
|
|
|
|
- $arr = arrayFromCSV($upload_dir."/users.csv",true,get_option( $pre.'_delimiter',';' ), get_option( $pre.'_textenclose','double' )=="double"?'"':"'");
|
|
|
|
- $ii= 0;
|
|
|
|
- $max = count($arr);
|
|
|
|
- $resu = array();
|
|
|
|
- foreach ($arr as $num => $user) {
|
|
|
|
- $ii ++;
|
|
|
|
- echo("$max : $ii -> ");
|
|
|
|
- flush();
|
|
|
|
- if($user['Spærret']=="" ){
|
|
|
|
-
|
|
|
|
- $user_email =$user['E-mail'];
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- $user_name = sanitize_username("T".$user['Telefon']);
|
|
|
|
- $user_id = username_exists( $user_name );
|
|
|
|
- if ( ! $user_id && false == email_exists( $user_email ) ) {
|
|
|
|
- $random_password = wp_generate_password( $length = 12, $include_standard_special_chars = false );
|
|
|
|
- if($testmode){
|
|
|
|
- //$user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
|
|
- //wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
|
|
|
|
- //wp_send_new_user_notifications($user_id,'both');
|
|
|
|
- $resu[] = "$user_id mock created : $user_name $user_email ";
|
|
|
|
- }else{
|
|
|
|
- $user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
|
|
- wp_update_user( array( 'ID' => $user_id, 'role' => 'betalende-abonnent' ) );
|
|
|
|
- wp_send_new_user_notifications($user_id,'both');
|
|
|
|
- $resu[] = "$user_id created : $user_name $user_email ";
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- $resu[] = "$user_id or $user_email exists";
|
|
|
|
- $random_password = __( 'User already exists. Password inherited.', 'textdomain' );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- echo ("$user_id, $user_name, $random_password, $user_email <br>");
|
|
|
|
- flush();
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- $resu[] = "$user_email spærret";
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if($testmode){
|
|
|
|
- print_r($resu);
|
|
|
|
- echo("DONE test");
|
|
|
|
- }else{
|
|
|
|
-
|
|
|
|
- $aemail = get_bloginfo('admin_email');
|
|
|
|
- $rr = wp_mail($aemail, 'CCR '. count($resu)." : ". getenv('HOSTNAME')." : ".$_SERVER['REMOTE_ADDR']." : " . $_SERVER['SERVER_ADDR'] . " : ". $_SERVER['SERVER_NAME']." ".date("U"), "::".print_r($resu,true));
|
|
|
|
- echo("DONE live");
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if(!isset($_REQUEST['nodryrun'])){
|
|
|
|
- ?>
|
|
|
|
|
|
+ if (!isset($_REQUEST['nodryrun'])) {
|
|
|
|
+ ?>
|
|
<a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1&nodryrun=1" class="btn">Crunch live</a>
|
|
<a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1&nodryrun=1" class="btn">Crunch live</a>
|
|
|
|
|
|
|
|
|
|
<?php
|
|
<?php
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /*<input id="link_image" value="test">
|
|
|
|
- <img src="" id="background_image">
|
|
|
|
-
|
|
|
|
- <a id="upload_image_button" href="#"><?php _e('Set image', 'dagsopt'); ?></a>
|
|
|
|
- */
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- function admin_line($pre){
|
|
|
|
- $upload = wp_upload_dir();
|
|
|
|
- $upload_dir = $upload['basedir'];
|
|
|
|
- $upload_dir = $upload_dir . '/assets';
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /*<input id="link_image" value="test">
|
|
|
|
+ <img src="" id="background_image">
|
|
|
|
|
|
|
|
+ <a id="upload_image_button" href="#"><?php _e('Set image', 'dagsopt'); ?></a>
|
|
|
|
+ */
|
|
|
|
|
|
|
|
+ function admin_line($pre) {
|
|
|
|
+ $upload = wp_upload_dir();
|
|
|
|
+ $upload_dir = $upload['basedir'];
|
|
|
|
+ $upload_dir = $upload_dir . '/assets';
|
|
|
|
|
|
-?>
|
|
|
|
|
|
+ ?>
|
|
<table>
|
|
<table>
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if(file_exists($upload_dir."/users.csv")){
|
|
|
|
- $lastmodified = date ("F d Y H:i:s.", filemtime($upload_dir."/users.csv"));
|
|
|
|
- $data = file_get_contents($upload_dir."/users.csv");
|
|
|
|
- $lines = explode("\n",$data);
|
|
|
|
|
|
+ if (file_exists($upload_dir . "/users.csv")) {
|
|
|
|
+ $lastmodified = date("F d Y H:i:s.", filemtime($upload_dir . "/users.csv"));
|
|
|
|
+ $data = file_get_contents($upload_dir . "/users.csv");
|
|
|
|
+ $lines = explode("\n", $data);
|
|
|
|
|
|
- ?>
|
|
|
|
|
|
+ ?>
|
|
|
|
|
|
<tr><td>
|
|
<tr><td>
|
|
Sidste opdateret
|
|
Sidste opdateret
|
|
</td><td>
|
|
</td><td>
|
|
<?php echo $lastmodified ?>
|
|
<?php echo $lastmodified ?>
|
|
- </td></tr>
|
|
|
|
|
|
+ </td></tr>
|
|
<tr><td>
|
|
<tr><td>
|
|
- Størrelse
|
|
|
|
|
|
+ Størrelse
|
|
</td><td>
|
|
</td><td>
|
|
- <?php echo strlen($data) ?> bytes / linier: <?php echo(count($lines)-1); ?>
|
|
|
|
- </td></tr>
|
|
|
|
|
|
+ <?php echo strlen($data) ?> bytes / linier: <?php echo (count($lines) - 1); ?>
|
|
|
|
+ </td></tr>
|
|
<tr><td>Kør opdatering</td><td><a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1" class="btn">Crunch</a></td></tr>
|
|
<tr><td>Kør opdatering</td><td><a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1" class="btn">Crunch</a></td></tr>
|
|
|
|
|
|
-<?php } ?>
|
|
|
|
- <tr><td><?php echo(__("delimiter:","dagsopt")) ?></td><td><input type="text" name="<?php echo( $pre.'_delimiter' ) ?>" value="<?php echo( get_option( $pre.'_delimiter',';' ) ) ?>"></td></tr>
|
|
|
|
-
|
|
|
|
- <tr><td><?php echo(__("textenclose:","dagsopt")) ?></td><td><input type="text" name="<?php echo( $pre.'_textenclose' ) ?>" value="<?php echo( get_option( $pre.'_textenclose','"' ) ) ?>"></td></tr>
|
|
|
|
-
|
|
|
|
- </table>
|
|
|
|
|
|
+<?php }?>
|
|
|
|
+ <tr><td><?php echo (__("delimiter:", "dagsopt")) ?></td><td><input type="text" name="<?php echo ($pre . '_delimiter') ?>" value="<?php echo (get_option($pre . '_delimiter', ';')) ?>"></td></tr>
|
|
|
|
+
|
|
|
|
+ <tr><td><?php echo (__("textenclose:", "dagsopt")) ?></td><td><input type="text" name="<?php echo ($pre . '_textenclose') ?>" value="<?php echo (get_option($pre . '_textenclose', '"')) ?>"></td></tr>
|
|
|
|
+
|
|
|
|
+ </table>
|
|
|
|
|
|
|
|
|
|
<?php
|
|
<?php
|
|
-
|
|
|
|
|
|
|
|
- $nonce = wp_create_nonce( 'filen-nonce' );
|
|
|
|
|
|
+ $nonce = wp_create_nonce('filen-nonce');
|
|
|
|
|
|
|
|
+ ?>
|
|
|
|
|
|
-?>
|
|
|
|
|
|
|
|
-
|
|
|
|
<input type="file" name="filen">
|
|
<input type="file" name="filen">
|
|
<input type="hidden" name="_wpnonce" value="<?php echo $nonce ?>">
|
|
<input type="hidden" name="_wpnonce" value="<?php echo $nonce ?>">
|
|
|
|
|
|
|
|
|
|
- <?php
|
|
|
|
-}
|
|
|
|
|
|
+ <?php
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
-global $plug_usermanager;
|
|
|
|
-$plug_usermanager = new plug_usermanager($this);
|
|
|
|
|
|
+ global $plug_usermanager;
|
|
|
|
+ $plug_usermanager = new plug_usermanager($this);
|
|
$this->dagsopt['plug_usermanager'] = $plug_usermanager;
|
|
$this->dagsopt['plug_usermanager'] = $plug_usermanager;
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+}
|