|
@@ -0,0 +1,255 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+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 sanitize_username($username) {
|
|
|
|
+ $parts = explode("@", $username);
|
|
|
|
+ if (count($parts) == 2) {
|
|
|
|
+ $username = $parts[0];
|
|
|
|
+ }
|
|
|
|
+ return $username;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ class plug_usermanager {
|
|
|
|
+ function __construct($ns) {
|
|
|
|
+ $this->title = __("plug_usermanager","dagsopt");
|
|
|
|
+ $this->pluginname = $ns->pluginname;
|
|
|
|
+ $this->file = $ns->file;
|
|
|
|
+ $this->ns = $ns;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ function start() {
|
|
|
|
+// register_setting("section", "demo-file", array(&this,"handle_file_upload"));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ function help(){
|
|
|
|
+ ?>
|
|
|
|
+ plug_usermanager
|
|
|
|
+ <?php
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ function Option($pre){
|
|
|
|
+
|
|
|
|
+ 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']){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $upload = wp_upload_dir();
|
|
|
|
+ $upload_dir = $upload['basedir'];
|
|
|
|
+ $upload_dir = $upload_dir . '/assets';
|
|
|
|
+
|
|
|
|
+ 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']=="" ){
|
|
|
|
+ if($testmode){
|
|
|
|
+ $user_email = str_replace("@","_",$user['E-mail'])."@bloggen.dk";
|
|
|
|
+ }else{
|
|
|
|
+ $user_email = str_replace("@","_",$user['E-mail'])."@ere.dk";
|
|
|
|
+ }
|
|
|
|
+ $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 );
|
|
|
|
+ $user_id = wp_create_user( $user_name, $random_password, $user_email );
|
|
|
|
+ wp_send_new_user_notifications($user_id,'both');
|
|
|
|
+ $resu[] = "$user_id created : $user_name $user_email ";
|
|
|
|
+ } else {
|
|
|
|
+ $random_password = __( 'User already exists. Password inherited.', 'textdomain' );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ echo ("$user_id, $user_name, $random_password, $user_email <br>");
|
|
|
|
+ flush();
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(count($resu)){
|
|
|
|
+ echo("SEND NOTIFY");
|
|
|
|
+ $rr = wp_mail('jannick@bloggen.dk', 'CCR '. count($resu)." : ". getenv('HOSTNAME')." : ".$_SERVER['REMOTE_ADDR']." : " . $_SERVER['SERVER_ADDR'] . " : ". $_SERVER['SERVER_NAME']." ".date("U"), "::".print_r($resu,true));
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ echo("no noti");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!isset($_REQUEST['nodryrun'])){
|
|
|
|
+ ?>
|
|
|
|
+ <a href="/wp-admin/admin.php?page=dagsopt-options&crunchit=1&nodryrun=1" class="btn">Crunch live</a>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <?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';
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+?>
|
|
|
|
+<table>
|
|
|
|
+<?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);
|
|
|
|
+
|
|
|
|
+ ?>
|
|
|
|
+
|
|
|
|
+ <tr><td>
|
|
|
|
+ Sidste opdateret
|
|
|
|
+ </td><td>
|
|
|
|
+ <?php echo $lastmodified ?>
|
|
|
|
+ </td></tr>
|
|
|
|
+ <tr><td>
|
|
|
|
+ Størrelse
|
|
|
|
+ </td><td>
|
|
|
|
+ <?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>
|
|
|
|
+
|
|
|
|
+<?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
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $nonce = wp_create_nonce( 'filen-nonce' );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+?>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <input type="file" name="filen">
|
|
|
|
+ <input type="hidden" name="_wpnonce" value="<?php echo $nonce ?>">
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <?php
|
|
|
|
+}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+global $plug_usermanager;
|
|
|
|
+$plug_usermanager = new plug_usermanager($this);
|
|
|
|
+ $this->dagsopt['plug_usermanager'] = $plug_usermanager;
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|