Răsfoiți Sursa

Bumped version to 0.0.30

Jannick Knudsen 4 ani în urmă
părinte
comite
0f1a0e98cf
6 a modificat fișierele cu 285 adăugiri și 31 ștergeri
  1. 1 1
      VERSION
  2. 1 0
      VERSIONLOG
  3. 1 1
      package.json
  4. 255 0
      plug_usermanager.php
  5. 25 28
      plugin.php
  6. 2 1
      style_backend.css

+ 1 - 1
VERSION

@@ -1 +1 @@
-v0.0.29
+v0.0.30

+ 1 - 0
VERSIONLOG

@@ -28,3 +28,4 @@ v0.0.26
 v0.0.27
 v0.0.27
 v0.0.28
 v0.0.28
 v0.0.29
 v0.0.29
+v0.0.30

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "dagsplug",
   "name": "dagsplug",
-  "version": "0.0.29",
+  "version": "0.0.30",
   "description": "",
   "description": "",
   "main": "script_backend.js",
   "main": "script_backend.js",
   "scripts": {
   "scripts": {

+ 255 - 0
plug_usermanager.php

@@ -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;
+	
+}
+
+
+
+
+
+

+ 25 - 28
plugin.php

@@ -4,7 +4,7 @@
  Plugin URI: https://git.tum.dk/tum.dk/dagsplug/
  Plugin URI: https://git.tum.dk/tum.dk/dagsplug/
  Description: Tools 
  Description: Tools 
  Author: iskedk
  Author: iskedk
- Version: 0.0.29
+ Version: 0.0.30
  Date: 2021-01-14
  Date: 2021-01-14
  Author URI: https://iske.dk/
  Author URI: https://iske.dk/
  Text Domain: dagsopt
  Text Domain: dagsopt
@@ -17,7 +17,7 @@ function wppluginspage() {
 $wp_dagsopt = new dagsopt ( );
 $wp_dagsopt = new dagsopt ( );
 
 
 class dagsopt {
 class dagsopt {
-	var $version = "0.0.29";
+	var $version = "0.0.30";
 	var $publish_date = "2021-01-14";
 	var $publish_date = "2021-01-14";
 	var $pluginname;
 	var $pluginname;
 	var $plugintitle;
 	var $plugintitle;
@@ -49,7 +49,7 @@ class dagsopt {
 
 
 		add_filter ( 'plugin_action_links', array(&$this,'SettingsLink'), 9, 2 );
 		add_filter ( 'plugin_action_links', array(&$this,'SettingsLink'), 9, 2 );
 
 
-		if (isset ( $_GET [ 'page' ] ) && $_GET [ 'page' ] == $this->pluginname.'-options') {
+		if (isset ( $_GET [ 'page' ] ) && $_GET [ 'page' ] == $this->pluginname.'-options' && !(isset($_REQUEST['crunchit']))) {
 			ob_start ();
 			ob_start ();
 		}
 		}
 		$this->setCron();
 		$this->setCron();
@@ -210,41 +210,38 @@ class dagsopt {
 
 
 					update_option ( $this->pluginname.'_last_build', date("U") );
 					update_option ( $this->pluginname.'_last_build', date("U") );
 
 
-	   foreach($this->dagsopt as $plugname => $plug){
-			$short = str_replace("plug_","",$plugname);
-			$setname = $this->pluginname.'_'.$short;
-			$vis = get_option($setname,true);
-			update_option ($setname, $_POST[$setname] );
+				   foreach($this->dagsopt as $plugname => $plug){
+						$short = str_replace("plug_","",$plugname);
+						$setname = $this->pluginname.'_'.$short;
+						$vis = get_option($setname,true);
+						update_option ($setname, $_POST[$setname] );
 
 
-			if($vis && method_exists($plug,'Option')){
-			   $plug->Option($setname);
-			}
-		}
-		 $pluginmessage ="";
+						if($vis && method_exists($plug,'Option')){
+						   $plug->Option($setname);
+						}
+					}
+			 $pluginmessage ="";
 
 
 			ob_end_clean ();
 			ob_end_clean ();
 			wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
 			wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
 			exit ();
 			exit ();
 		}
 		}
 
 
-
-		if(isset( $_POST['Updateras'])){
+		if(isset( $_REQUEST['crunchit'])){
 		 $pluginmessage ="";
 		 $pluginmessage ="";
-
-
-		foreach($this->dagsopt as $plugname => $plug){
-			$short = str_replace("plug_","",$plugname);
-			$setname = $this->pluginname.'_'.$short;
-			$vis = get_option($setname,true);
-			//update_option ($setname, $_POST[$setname] );
-
-			if($vis && method_exists($plug,'Updateras')){
-			   		 $pluginmessage .= $plug->Updateras($setname);
+	   		 foreach($this->dagsopt as $plugname => $plug){
+				$short = str_replace("plug_","",$plugname);
+				$setname = $this->pluginname.'_'.$short;
+				$vis = get_option($setname,true);
+				//update_option ($setname, $_POST[$setname] );
+
+				if($vis && method_exists($plug,'Cruncher')){
+					$pluginmessage .= $plug->Cruncher($setname);
+				}
 			}
 			}
-		}
 
 
-			ob_end_clean ();
-			wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
+			//ob_end_clean ();
+			//wp_redirect ( 'admin.php?page='.$this->pluginname.'-options&msg=' . urlencode ( $pluginmessage ) );
 			exit ();
 			exit ();
 
 
 		}
 		}

+ 2 - 1
style_backend.css

@@ -1,7 +1,8 @@
 
 
 
 
 body {
 body {
-	background-color: #ff00ff;
+
+
 }
 }