Преглед на файлове

Bumped version to 0.0.37

Jannick Knudsen преди 4 години
родител
ревизия
9ea434eb39
променени са 8 файла, в които са добавени 847 реда и са изтрити 411 реда
  1. 1 1
      VERSION
  2. 1 0
      VERSIONLOG
  3. 1 1
      package.json
  4. 157 138
      plug_admin_bar.php
  5. 395 38
      plug_login.php
  6. 227 222
      plug_shortcodes.php
  7. 63 9
      plug_woohook.php
  8. 2 2
      plugin.php

+ 1 - 1
VERSION

@@ -1 +1 @@
-v0.0.36
+v0.0.37

+ 1 - 0
VERSIONLOG

@@ -35,3 +35,4 @@ v0.0.33
 v0.0.34
 v0.0.35
 v0.0.36
+v0.0.37

+ 1 - 1
package.json

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

+ 157 - 138
plug_admin_bar.php

@@ -3,56 +3,56 @@
 if (!class_exists("plug_admin_bar")) {
 	class plug_admin_bar {
 		function __construct($ns) {
-			$this->title = __("Admin bar","dagsopt");
+			$this->title = __("Admin bar", "dagsopt");
 			$this->pluginname = $ns->pluginname;
 			$this->file = $ns->file;
 			$this->ns = $ns;
 		}
-		function start(){
-			add_action( 'admin_bar_menu'		, array(&$this,'bu_admin_link_first'), 1 );
-			add_action( 'admin_bar_menu'		, array(&$this,'bu_admin_link_last'), 200 );
-			if(get_option( $this->pluginname."_admin_bar".'_remove_comments' ,false)){
-				add_action( 'wp_before_admin_bar_render'		, array(&$this,'bu_admin_link_remove_comments'), 210 );
+		function start() {
+			add_action('admin_bar_menu', array(&$this, 'bu_admin_link_first'), 1);
+			add_action('admin_bar_menu', array(&$this, 'bu_admin_link_last'), 200);
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_comments', false)) {
+				add_action('wp_before_admin_bar_render', array(&$this, 'bu_admin_link_remove_comments'), 210);
 			}
-			if(!function_exists('wp_get_current_user')) {
-				include(ABSPATH . "wp-includes/pluggable.php"); 
+			if (!function_exists('wp_get_current_user')) {
+				include ABSPATH . "wp-includes/pluggable.php";
 			}
 			//	remove_submenu_page('index.php','update-core.php');
-			$current_user =    wp_get_current_user();
-			if( current_user_can( 'manage_options' ) && $current_user->user_login == "admin") {
-					add_action( 'admin_menu'		, array(&$this,'setup_menus'), 220 );
+			$current_user = wp_get_current_user();
+			if (current_user_can('manage_options') && $current_user->user_login == "admin") {
+				add_action('admin_menu', array(&$this, 'setup_menus'), 220);
 			} else {
-				add_action( 'admin_menu'		, array(&$this,'remove_menus'), 220 );
-				add_action( 'wp_before_admin_bar_render'		, array(&$this,'remove_menus2'), 210 );
+				add_action('admin_menu', array(&$this, 'remove_menus'), 220);
+				add_action('wp_before_admin_bar_render', array(&$this, 'remove_menus2'), 210);
 			}
 		}
 
 		function remove_menus2() {
 			global $wp_admin_bar;
-				if(get_option( $this->pluginname."_admin_bar".'_remove_new-post' ,false)){
-					$wp_admin_bar->remove_menu("new-post");
-				}
-				if(get_option( $this->pluginname."_admin_bar".'_remove_new-link' ,false)){
-					$wp_admin_bar->remove_menu("new-link");
-				}
-				if(get_option( $this->pluginname."_admin_bar".'_remove_new-page' ,false)){
-					$wp_admin_bar->remove_menu("new-page");
-				}
-				if(get_option( $this->pluginname."_admin_bar".'_remove_new-media' ,false)){
-					$wp_admin_bar->remove_menu("new-media");
-				}
-				if(get_option( $this->pluginname."_admin_bar".'_remove_new-user' ,false)){
-					$wp_admin_bar->remove_menu("new-user");
-				}
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_new-post', false)) {
+				$wp_admin_bar->remove_menu("new-post");
+			}
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_new-link', false)) {
+				$wp_admin_bar->remove_menu("new-link");
+			}
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_new-page', false)) {
+				$wp_admin_bar->remove_menu("new-page");
+			}
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_new-media', false)) {
+				$wp_admin_bar->remove_menu("new-media");
+			}
+			if (get_option($this->pluginname . "_admin_bar" . '_remove_new-user', false)) {
+				$wp_admin_bar->remove_menu("new-user");
+			}
 		}
 
-		function setup_menus () {
+		function setup_menus() {
 			global $menu;
-				$this->gmenu = $menu;
+			$this->gmenu = $menu;
 		}
-		function remove_menus () {
+		function remove_menus() {
 			global $menu;
-				$this->setup_menus();
+			/*	$this->setup_menus();
 				$rr = array();
 				foreach($this->gmenu as $id => $mm){
 					if(get_option($this->pluginname."_admin_bar".'_remove_'.$mm[5],false)){
@@ -64,50 +64,50 @@ if (!class_exists("plug_admin_bar")) {
 						unset($menu[$id]);
 					}
 				}
-				remove_submenu_page('index.php','update-core.php'); 
-				remove_submenu_page('themes.php','update'); 
-				remove_submenu_page('themes.php','checkupdate'); 
-				remove_submenu_page('themes.php','custom-header'); 
-				remove_submenu_page('themes.php','custom-background'); 
-				remove_submenu_page('themes.php','theme-editor.php'); 
-				remove_submenu_page('themes.php','themes.php'); 
+				remove_submenu_page('index.php','update-core.php');
+				remove_submenu_page('themes.php','update');
+				remove_submenu_page('themes.php','checkupdate');
+				remove_submenu_page('themes.php','custom-header');
+				remove_submenu_page('themes.php','custom-background');
+				remove_submenu_page('themes.php','theme-editor.php');
+				remove_submenu_page('themes.php','themes.php');
 				//add_submenu_page( 'themes.php', "Customize", "Customize", "", "customize.php", "");
+				*/
 		}
 		function bu_admin_link_first() {
 			global $wp_admin_bar;
-			if(get_option( $this->pluginname."_admin_bar".'_dags_logo' ,true)){
-				$wp_admin_bar->add_menu( array('id' => 'dags-logo',	'title' => '<img src="/wp-content/plugins/dagsplug/logo.png" style="margin-top: 4px;">',	'href'  => 'https://dags.dk/' , 'meta'  => array('title' => __('Dags dk','dagsopt'), ),	) );
+			if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
+				$wp_admin_bar->add_menu(array('id' => 'dags-logo', 'title' => '<img src="/wp-content/plugins/dagsplug/logo.png" style="margin-top: 4px;">', 'href' => 'https://dags.dk/', 'meta' => array('title' => __('Dags dk', 'dagsopt'))));
 			}
 		}
 		function bu_admin_link_remove_comments() {
 			global $wp_admin_bar;
 			$wp_admin_bar->remove_menu('comments');
 		}
-	
-	
+
 		function bu_admin_link_last() {
 			global $wp_admin_bar;
-			if(get_option( $this->pluginname."_admin_bar".'_dags_logo' ,true)){
+			if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
 				$wp_admin_bar->remove_node("wp-logo");
 			}
-			if(get_option( $this->pluginname."_admin_bar".'_show_ip' ,true)){
-				$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'IP', 'title' => 'IP: '.$_SERVER['SERVER_ADDR'], 'href' => admin_url( 'admin.php?page='.$this->pluginname.'-options' )  ) );
+			if (get_option($this->pluginname . "_admin_bar" . '_show_ip', true)) {
+				$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'IP', 'title' => 'IP: ' . $_SERVER['SERVER_ADDR'], 'href' => admin_url('admin.php?page=' . $this->pluginname . '-options')));
 			}
-			if ( current_user_can( 'manage_options' ) && get_option( $this->pluginname."_admin_bar_live_url" )) {
-
-				if(get_option( $this->pluginname."_admin_bar".'_show_switcher' ,true)){
-					if($_SERVER['HTTP_HOST']==get_option( $this->pluginname."_admin_bar_live_url" )){
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' =>  get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-					}else if($_SERVER['HTTP_HOST']==get_option( $this->pluginname."_admin_bar_stage_url" )){
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-					}else{
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option( $this->pluginname."_admin_bar_live_title" ), 'href' => get_option( $this->pluginname."_admin_bar_live_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option( $this->pluginname."_admin_bar_stage_title" ), 'href' => get_option( $this->pluginname."_admin_bar_stage_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> '')  ) );
-						$wp_admin_bar->add_menu( array( 'parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option( $this->pluginname."_admin_bar_local_title" ), 'href' => get_option( $this->pluginname."_admin_bar_local_url" ).$_SERVER['REQUEST_URI'], 'meta'=>array('class'=> 'active')  ) );
+			if (current_user_can('manage_options') && get_option($this->pluginname . "_admin_bar_live_url")) {
+
+				if (get_option($this->pluginname . "_admin_bar" . '_show_switcher', true)) {
+					if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_live_url")) {
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+					} else if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_stage_url")) {
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+					} else {
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
+						$wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
 					}
 				}
 
@@ -116,83 +116,87 @@ if (!class_exists("plug_admin_bar")) {
 			}
 		}
 
-		function help(){
+		function help() {
 			?>
-			<?php echo(__("Server switcher : local > stage > live","dagsopt")) ?><br>
-			<?php echo(__("Swap WP for dags logo","dagsopt")) ?><br>
-			<?php echo(__("Show server ip","dagsopt")) ?><br>
+			<?php echo (__("Server switcher : local > stage > live", "dagsopt")) ?><br>
+			<?php echo (__("Swap WP for dags logo", "dagsopt")) ?><br>
+			<?php echo (__("Show server ip", "dagsopt")) ?><br>
 
 		<?php
-		}
-
-			function Option($pre){
-				update_option ( $pre.'_show_switcher', $_POST [ $pre.'_show_switcher' ] );
-				if(!empty($_POST [ $pre.'_live_url' ])){
-					update_option ( $pre.'_live_url', $_POST [ $pre.'_live_url' ] );
-				}
-				if(!empty($_POST [ $pre.'_live_title' ])){
-					update_option ( $pre.'_live_title', $_POST [ $pre.'_live_title' ] );
-				}
-				if(!empty($_POST [ $pre.'_stage_url' ])){
-					update_option ( $pre.'_stage_url', $_POST [ $pre.'_stage_url' ] );
-				}
-				if(!empty($_POST [ $pre.'_stage_title' ])){
-					update_option ( $pre.'_stage_title', $_POST [ $pre.'_stage_title' ] );
-				}
-				if(!empty($_POST [ $pre.'_local_url' ])){
-					update_option ( $pre.'_local_url', $_POST [ $pre.'_local_url' ] );
-				}
-				if(!empty($_POST [ $pre.'_local_title' ])){
-					update_option ( $pre.'_local_title', $_POST [ $pre.'_local_title' ] );
-				}
-
-				update_option ( $pre.'_dags_logo', $_POST [ $pre.'_dags_logo' ] );
-				update_option ( $pre.'_show_ip', $_POST [ $pre.'_show_ip' ] );
-
-				update_option ( $pre.'_remove_comments', $_POST [ $pre.'_remove_comments' ] );
-
-				update_option ( $pre.'_remove_new-post', $_POST [ $pre.'_remove_new-post' ] );
-				update_option ( $pre.'_remove_new-link', $_POST [ $pre.'_remove_new-link' ] );
-				update_option ( $pre.'_remove_new-media', $_POST [ $pre.'_remove_new-media' ] );
-				update_option ( $pre.'_remove_new-page', $_POST [ $pre.'_remove_new-page' ] );
-				update_option ( $pre.'_remove_new-user', $_POST [ $pre.'_remove_new-user' ] );
+}
 
+		function Option($pre) {
+			update_option($pre . '_show_switcher', $_POST[$pre . '_show_switcher']);
+			if (!empty($_POST[$pre . '_live_url'])) {
+				update_option($pre . '_live_url', $_POST[$pre . '_live_url']);
+			}
+			if (!empty($_POST[$pre . '_live_title'])) {
+				update_option($pre . '_live_title', $_POST[$pre . '_live_title']);
+			}
+			if (!empty($_POST[$pre . '_stage_url'])) {
+				update_option($pre . '_stage_url', $_POST[$pre . '_stage_url']);
+			}
+			if (!empty($_POST[$pre . '_stage_title'])) {
+				update_option($pre . '_stage_title', $_POST[$pre . '_stage_title']);
+			}
+			if (!empty($_POST[$pre . '_local_url'])) {
+				update_option($pre . '_local_url', $_POST[$pre . '_local_url']);
+			}
+			if (!empty($_POST[$pre . '_local_title'])) {
+				update_option($pre . '_local_title', $_POST[$pre . '_local_title']);
+			}
 
-				
+			update_option($pre . '_dags_logo', $_POST[$pre . '_dags_logo']);
+			update_option($pre . '_show_ip', $_POST[$pre . '_show_ip']);
 
-				foreach($this->gmenu as $id => $mm){
-						update_option ( $pre.'_remove_'.$mm[5], $_POST [ $pre.'_remove_'.$mm[5] ] );
-				}
+			update_option($pre . '_remove_comments', $_POST[$pre . '_remove_comments']);
 
+			update_option($pre . '_remove_new-post', $_POST[$pre . '_remove_new-post']);
+			update_option($pre . '_remove_new-link', $_POST[$pre . '_remove_new-link']);
+			update_option($pre . '_remove_new-media', $_POST[$pre . '_remove_new-media']);
+			update_option($pre . '_remove_new-page', $_POST[$pre . '_remove_new-page']);
+			update_option($pre . '_remove_new-user', $_POST[$pre . '_remove_new-user']);
 
+			foreach ($this->gmenu as $id => $mm) {
+				update_option($pre . '_remove_' . $mm[5], $_POST[$pre . '_remove_' . $mm[5]]);
 			}
 
+		}
 
-		 	function admin_line($pre){
-				?>
+		function admin_line($pre) {
+			?>
 				<table>
-				<tr><td ><?php echo(__("Server switcher","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_show_switcher' ); ?>" type="checkbox" id="<?php echo( $pre.'_show_switcher' ); ?>" <?php if(get_option( $pre.'_show_switcher' ,true)) echo 'checked'; ?> />
+				<tr><td ><?php echo (__("Server switcher", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_show_switcher'); ?>" type="checkbox" id="<?php echo ($pre . '_show_switcher'); ?>" <?php if (get_option($pre . '_show_switcher', true)) {
+				echo 'checked';
+			}
+			?> />
 
-				<?php if(get_option( $pre.'_show_switcher' ,true)){
-					?>
+				<?php if (get_option($pre . '_show_switcher', true)) {
+				?>
 						<table>
-							<tr><td ><input type="text" name="<?php echo( $pre.'_live_title' ); ?>" value="<?php echo( get_option( $pre.'_live_title','live' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_live_url' ); ?>" value="<?php echo( get_option( $pre.'_live_url' ) ); ?>"></td></tr>
-							<tr><td><input type="text" name="<?php echo( $pre.'_stage_title' ); ?>" value="<?php echo( get_option( $pre.'_stage_title','stage' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_stage_url' ); ?>" value="<?php echo( get_option( $pre.'_stage_url' ) ); ?>"></td></tr>
-							<tr><td><input type="text" name="<?php echo( $pre.'_local_title' ); ?>" value="<?php echo( get_option( $pre.'_local_title','local' ) ); ?>"></td><td><input type="text" name="<?php echo( $pre.'_local_url' ); ?>" value="<?php echo( get_option( $pre.'_local_url' ) ); ?>"></td></tr>
+							<tr><td ><input type="text" name="<?php echo ($pre . '_live_title'); ?>" value="<?php echo (get_option($pre . '_live_title', 'live')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_live_url'); ?>" value="<?php echo (get_option($pre . '_live_url')); ?>"></td></tr>
+							<tr><td><input type="text" name="<?php echo ($pre . '_stage_title'); ?>" value="<?php echo (get_option($pre . '_stage_title', 'stage')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_stage_url'); ?>" value="<?php echo (get_option($pre . '_stage_url')); ?>"></td></tr>
+							<tr><td><input type="text" name="<?php echo ($pre . '_local_title'); ?>" value="<?php echo (get_option($pre . '_local_title', 'local')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_local_url'); ?>" value="<?php echo (get_option($pre . '_local_url')); ?>"></td></tr>
 
 
 						</table>
 					<?php
-					} ?>
+}?>
 
 				</td></tr>
 
 
 
-				<tr><td ><?php echo(__("Dags logo","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_dags_logo' ); ?>" type="checkbox" id="<?php echo( $pre.'_dags_logo' ); ?>" <?php if(get_option( $pre.'_dags_logo' ,true)) echo 'checked'; ?> /></td></tr>
+				<tr><td ><?php echo (__("Dags logo", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_dags_logo'); ?>" type="checkbox" id="<?php echo ($pre . '_dags_logo'); ?>" <?php if (get_option($pre . '_dags_logo', true)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
 
 
-				<tr><td ><?php echo(__("Show IP","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_show_ip' ); ?>" type="checkbox" id="<?php echo( $pre.'_show_ip' ); ?>" <?php if(get_option( $pre.'_show_ip' ,true)) echo 'checked'; ?> /></td></tr>
+				<tr><td ><?php echo (__("Show IP", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_show_ip'); ?>" type="checkbox" id="<?php echo ($pre . '_show_ip'); ?>" <?php if (get_option($pre . '_show_ip', true)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
 
 
 
@@ -202,29 +206,50 @@ if (!class_exists("plug_admin_bar")) {
 <table id="dags_tools_menus" style="display: none;">
 <tr><td colspan="2">Remove Admin Top Bar</td></tr>
 
-				<tr><td ><?php echo(__("Comments","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_comments' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_comments' ); ?>" <?php if(get_option( $pre.'_remove_comments' ,false)) echo 'checked'; ?> /></td></tr>
-				<tr><td ><?php echo(__("New Post","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-post' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-post' ); ?>" <?php if(get_option( $pre.'_remove_new-post' ,false)) echo 'checked'; ?> /></td></tr>
-				<tr><td ><?php echo(__("New Link","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-link' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-link' ); ?>" <?php if(get_option( $pre.'_remove_new-link' ,false)) echo 'checked'; ?> /></td></tr>
-				<tr><td ><?php echo(__("New Media","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-media' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-media' ); ?>" <?php if(get_option( $pre.'_remove_new-media' ,false)) echo 'checked'; ?> /></td></tr>
-				<tr><td ><?php echo(__("New Page","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-page' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-page' ); ?>" <?php if(get_option( $pre.'_remove_new-page' ,false)) echo 'checked'; ?> /></td></tr>
-				<tr><td ><?php echo(__("New User","dagsopt")) ?></td><td><input name="<?php echo( $pre.'_remove_new-user' ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_new-user' ); ?>" <?php if(get_option( $pre.'_remove_new-user' ,false)) echo 'checked'; ?> /></td></tr>
+				<tr><td ><?php echo (__("Comments", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_comments'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_comments'); ?>" <?php if (get_option($pre . '_remove_comments', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
+				<tr><td ><?php echo (__("New Post", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-post'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-post'); ?>" <?php if (get_option($pre . '_remove_new-post', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
+				<tr><td ><?php echo (__("New Link", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-link'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-link'); ?>" <?php if (get_option($pre . '_remove_new-link', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
+				<tr><td ><?php echo (__("New Media", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-media'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-media'); ?>" <?php if (get_option($pre . '_remove_new-media', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
+				<tr><td ><?php echo (__("New Page", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-page'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-page'); ?>" <?php if (get_option($pre . '_remove_new-page', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
+				<tr><td ><?php echo (__("New User", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-user'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-user'); ?>" <?php if (get_option($pre . '_remove_new-user', false)) {
+				echo 'checked';
+			}
+			?> /></td></tr>
 
 
 <tr><td colspan="2">Remove Admin Mode Bar</td></tr>
-	
+
 	<?php
-				foreach($this->gmenu as $id => $mm){
-					if(strstr($mm[2],"separator")){
-						continue;
-						}
+foreach ($this->gmenu as $id => $mm) {
+				if (strstr($mm[2], "separator")) {
+					continue;
+				}
 				?>
-				<tr><td ><?php echo($mm[0]) ?> </td><td><input name="<?php echo( $pre.'_remove_'.$mm[5] ); ?>" type="checkbox" id="<?php echo( $pre.'_remove_'.$mm[5] ); ?>" <?php if(get_option( $pre.'_remove_'.$mm[5] ,false)) echo 'checked'; ?> /> <?php echo($mm[5]); ?></td></tr>
-					
+				<tr><td ><?php echo ($mm[0]) ?> </td><td><input name="<?php echo ($pre . '_remove_' . $mm[5]); ?>" type="checkbox" id="<?php echo ($pre . '_remove_' . $mm[5]); ?>" <?php if (get_option($pre . '_remove_' . $mm[5], false)) {
+					echo 'checked';
+				}
+				?> /> <?php echo ($mm[5]); ?></td></tr>
 
-<?php					
-					}
-					
-					?>
+
+<?php
+}
+
+			?>
 
 
 </table>
@@ -243,18 +268,12 @@ if (!class_exists("plug_admin_bar")) {
 
 
 		  <?php
-		}
+}
 
 	}
 
 	global $plug_admin_bar;
 	$plug_admin_bar = new plug_admin_bar($this);
-		$this->dagsopt['plug_admin_bar'] = $plug_admin_bar;
+	$this->dagsopt['plug_admin_bar'] = $plug_admin_bar;
 
 }
-
-
-
-
-
-

+ 395 - 38
plug_login.php

@@ -1,63 +1,420 @@
 <?php
 
 if (!class_exists("plug_login")) {
-	class plug_login {	
+	class plug_login {
 		function __construct($ns) {
-			$this->title = __("Login","dagsopt");
+			$this->title = __("Login", "dagsopt");
 			$this->pluginname = $ns->pluginname;
 			$this->file = $ns->file;
 			$this->ns = $ns;
-			}
+		}
 		function start() {
+			add_action('init', array(&$this, 'override_reset_password_form_redirect'));
+
+			add_filter('login_headerurl', array(&$this, 'login_headerurl'));
+			add_filter('login_headertext', array(&$this, 'login_headertext'));
+			add_filter('login_message', array(&$this, 'login_message'));
+
+			add_action('register_form', array(&$this, 'plugin_form'));
+
+			if (defined("WP_SITEURL") && defined('WP_SITEURL_CDN')) {
+				add_filter('stylesheet_directory_uri', array(&$this, 'l_stylesheet_directory_uri'));
+
+			}
+			add_action('login_head', array(&$this, 'login_head'));
+
+			add_action('admin_enqueue_scripts', function () {
+				/*
+					    if possible try not to queue this all over the admin by adding your settings GET page val into next
+					    if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
+				*/
+
+				wp_enqueue_media();
+			});
+
+			add_filter('upload_mimes', function ($mime_types) {
+				$mime_types['svg'] = 'image/svg+xml'; // Adding .svg extension
+				$mime_types['json'] = 'application/json'; // Adding .json extension
+
+				// unset( $mime_types['xls'] );  // Remove .xls extension
+				// unset( $mime_types['xlsx'] ); // Remove .xlsx extension
+
+				return $mime_types;
+			}, 1, 1);
+
+			add_action('admin_footer', function () {
+
+				/*
+					    if possible try not to queue this all over the admin by adding your settings GET page val into next
+					    if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
+				*/
+
+				?>
+
+    <script>
+        jQuery(document).ready(function($){
+
+        	$(".uploadbutton").click(function(e){
+                e.preventDefault();
+
+        		var self = $(this);
+				var target = jQuery('.valuereciever', self.parent())
+				var preview = jQuery('img', self.parent())
+
+				var custom_uploader;
+				if (custom_uploader) {
+                    custom_uploader.open();
+                    return;
+                }
+
+                custom_uploader = wp.media.frames.file_frame = wp.media({
+                    title: 'Choose Image',
+                    button: {
+                        text: 'Choose Image'
+                    },
+                    multiple: false
+                });
+              	custom_uploader.on('select', function() {
+                    attachment = custom_uploader.state().get('selection').first().toJSON();
+                    console.log(attachment);
+                    target.val("/"+attachment.url.split("/").slice(3).join("/"));
+
+					preview.attr("src", target.val() );
+
+                });
+
+                custom_uploader.open();
+
+
+        	})
+
+
+/*            var custom_uploader
+              , click_elem = jQuery('.uploadbutton')
+              , target = jQuery('.valuereciever', click_elem.parent())
+
+            click_elem.click(function(e) {
+                e.preventDefault();
+                //If the uploader object has already been created, reopen the dialog
+                if (custom_uploader) {
+                    custom_uploader.open();
+                    return;
+                }
+                //Extend the wp.media object
+                custom_uploader = wp.media.frames.file_frame = wp.media({
+                    title: 'Choose Image',
+                    button: {
+                        text: 'Choose Image'
+                    },
+                    multiple: false
+                });
+                //When a file is selected, grab the URL and set it as the text field's value
+                custom_uploader.on('select', function() {
+                    attachment = custom_uploader.state().get('selection').first().toJSON();
+                    console.log(attachment);
+                    target.val("/"+attachment.url.split("/").slice(3).join("/"));
+                });
+                //Open the uploader dialog
+                custom_uploader.open();
+            });
+
+            */
+
+        });
+    </script>
 
-			add_filter('login_headerurl',array(&$this,'login_headerurl'));
-			add_filter('login_headertext',array(&$this,'login_headertitle'));
-			add_filter('login_message',array(&$this,'login_message'));
+    <?php
+});
+
+		}
+
+		function override_reset_password_form_redirect() {
+			$action = isset($_GET['action']) ? $_GET['action'] : '';
+			$key = isset($_GET['key']) ? $_GET['key'] : '';
+			$login = isset($_GET['login']) ? $_GET['login'] : '';
+			if ('wp-login.php' === $GLOBALS['pagenow'] && ('resetpass' == $action)) {
+				if (isset($_POST['wp-submit']) && $_POST['wp-submit'] == "Reset Password") {
+					foreach ($_COOKIE as $key => $value) {
+						if (stristr($key, "wp-resetpass")) {
+							$v = explode(":", $value);
+							$login = array_shift($v);
+						}
+						# code...
+					}
+
+					//print_r($GLOBALS);
+
+					//wp_redirect(site_url('/wp-login.php') . '?action=welcome&user_login=' . $login);
+					//exit;
+				}
+
+			}
 		}
 
+		function l_stylesheet_directory_uri($t) {
+			return str_replace(WP_SITEURL, WP_SITEURL_CDN, $t);
+		}
+
+		function login_headerurl($t) {
+			return "/";
+		}
+		function login_headertext($t) {
+			return "Til forsiden";
+		}
+		function login_message($t) {
+			$login = "";
+			foreach ($_COOKIE as $key => $value) {
+				if (stristr($key, "wp-resetpass")) {
+					$v = explode(":", $value);
+					$login = array_shift($v);
+				}
+			}
+
+			$str = '<style type="text/css">
+							body {
+								background-size: cover;
+								background-position: center center;
+								background-image: url(' . stripslashes(get_option($this->pluginname . "_login_background_image")) . ');
+							}
+							.login h1 a  {margin-top:-50px;padding-bottom: 5px; width: auto; height: 110px; background-size: auto; background-image: url(' . stripslashes(get_option($this->pluginname . "_login_image")) . ');}
+							.login_holder {
+									   margin-top: 20px;
+								    margin-left: 0;
+								    padding: 26px 24px 46px;
+								    font-weight: 400;
+								    overflow: hidden;
+								    background: #fff;
+								    border: 1px solid #ccd0d4;
+								    box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
 
-			function login_headerurl($t){	return "https://dags.dk/";	}
-			function login_headertitle($t){	return "Dags dk";	}
-			function login_message($t){	
-				return '<style type="text/css"> 
-							.login h1 a  {padding-bottom: 5px; width: auto; height: 65px; background-size: auto; background-image: url(/wp-content/plugins/dagsplug/login_logo.png);} 
-							.login_holder {margin: 0px 0px 20px 0px; text-align: center}
+							}
 						</style>
+		<script type="text/javascript">
+			jQuery(document).ready(function($){
+				  var qq = {};
+					  $.each(document.location.search.substr(1).split("&"),function(c,q){
+					    var i = q.split("=");
+					    qq[i[0].toString()] = i[1].toString();
+					  });
+					  if(qq.action=="resetpass"){
+					  	setTimeout(function(){
+					  		window.location.href="/wp-login.php?action=welcome&user_login=' . $login . '"
+					  		},500)
+					  }else{
+						 $("#user_login").val(qq["user_login"]);
+
+					  }
+
+				})
+			</script>
 							<div class="login_holder">
-									<p>'.get_option($this->pluginname."_login_support_splash").'</p>
-							</div>';	
-				}
-				
+									<p>';
+
+			if (isset($_GET['action'])) {
+				$str .= get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false);
+			} else {
+				$str .= get_option($this->pluginname . "_login_support_splash", false);
+			}
+			$str .= '</p></div>';
+
+			return $str;
+		}
 
+		function help() {
+			?>
+				<?php echo (__("Adds logo to login page", "dagsopt")) ?>
+ 				<a href="/wp-login.php"><?php echo (__("Login page", "dagsopt")) ?></a>
+			<?php
+}
 
-			function help(){
+		function login_head() {
+//			$type = (empty($_REQUEST['type']) || !($_REQUEST['type'] == "Select" || $_REQUEST['type'] == "Pro")) ? "Select" :  $_REQUEST['type'];
+			$type = "Perspektiv";
+			if ($type !== "") {
 				?>
-				<?php echo(__("Adds logo to login page","dagsopt")) ?>
- 				<a href="/wp-login.php"><?php echo(__("Login page","dagsopt")) ?></a>
-			<?php		
-			}
-	 
-	 	function Option($pre){
-			update_option ( $pre.'_support_splash', $_POST [ $pre.'_support_splash' ] );
- 		}
- 
-	 	function admin_line($pre){
-		  ?>
-		  <?php echo(__("Login splash html:","dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo( $pre.'_support_splash' ); ?>"><?php echo(get_option($pre."_support_splash")); ?></textarea>
-		  <?php  
-		}	
-		
-	 	 
-	}
+		<script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
+		<script type="text/javascript">
+			jQuery(document).ready(function(){
+				if(jQuery("form").attr('action').indexOf('register')>-1){
+					jQuery("form").prepend('<h3>Ræson <?php echo ($type) ?></h3><br>');
+					jQuery("p:contains('Brugernavn')").hide();
 
-	global $plug_login;
-	$plug_login = new plug_login($this);		
-			$this->dagsopt['plug_login'] = $plug_login;
-			
+					jQuery("#user_email").attr("tabindex","24")
+
+					jQuery("#r_navn").attr("tabindex","25")
+					jQuery("#r_membership").attr("tabindex","26")
+					jQuery("#wp-submit").attr("tabindex","27")
+
+
+				var t = (jQuery('#login_error').html())+"";
+				var a = t.split("\n");
+					if(a.length && a[0].indexOf('brugernavn')>-1){
+						a.shift();
+						jQuery('#login_error').html(a.join("\n"));
+					}
+
+
+					 jQuery("#user_login").hide();
+					 jQuery('label[for="user_login"]').hide();
+
+				jQuery('#wp-submit').click(function(){
+					console.log("SEND");
+					jQuery('#user_login').val(jQuery('#user_email').val());
+
+
+					});
+
+
+				}
+
+
+			});
+
+		</script>
+
+	<?php
 }
+			?>
+
+		<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory');?>/style2.css">
+
+
+<?php
+
+		}
+
+		function plugin_form() {
+			$type = "Perspektiv"; //;(empty($_REQUEST['type']) || !($_REQUEST['type'] == "Select" || $_REQUEST['type'] == "Pro")) ? "Select" :  $_REQUEST['type'];
+
+			//19094	__system_side_medlem_af
+			//$tt = get_post( 19094);
+			//print_r($_REQUEST);
+			//$arra = explode("<hr>","".$tt->post_content);
+			//$listen = array_pop($arra);
+			$content = get_option($this->pluginname . "_login_groups", false) . "::::" . ($this->pluginname . "_login_groups");
+			//$arr = explode("\n","".$listen);
+
+			$arr = explode("\n", get_option($this->pluginname . "_login_groups", false));
+
+			$sel = '<select name="r_membership" id="r_membership" class="input nnl"  tabindex="26">';
+			$sel .= '<option ' . ((!isset($_POST['r_membership']) || $_POST['r_membership'] === "") ? "selected" : "") . '>Vælg gruppe</option>';
+			foreach ($arr as $ii => $title) {
+				if (strlen($title) > 3) {
+					$sel .= '<option value="' . $title . '" ' . ($_POST['r_membership'] === $title ? "selected" : "") . '>' . $title . '</option>';
+				}
+			}
+			$sel .= '</select>';
+
+			$html = '
+ 			<style type="text/css">
+ 				.nnl {
+					background:#FBFBFB none repeat scroll 0 0;
+					border:1px solid #E5E5E5;
+					font-size:20px;
+					margin-bottom:16px;
+					margin-right:6px;
+					margin-top:2px;
+					padding:3px;
+					width:97%;
+				}
+ 			</style>
+
+
+ 				<div width="100%">
+ 				 	<div>
+ 				 		' . $content . '
+ 				 	</div>
+
+					<input type="hidden" name="r_proselect" id="r_proselect" value="' . $type . '">
+
+ 					<p>
+ 						<label style="display: block; margin-bottom: 5px;">' . __('Navn', 'Navn') . '
+ 							<input type="text" name="r_navn" id="r_navn" class="input nnl" value="' . $_POST['r_navn'] . '" size="20" tabindex="25" />
+ 						</label>
+					</p>
+
 
+ 					<p>
+ 						<label style="display: block; margin-bottom: 5px;">' . __('Medlem af', 'Medlem af') . '
+ 								' . $sel . '
+					</label>
+					</p>
 
 
 
 
+			</div>
+			';
+			echo $html;
+		}
+
+		function Option($pre) {
+			update_option($pre . '_support_splash', $_POST[$pre . '_support_splash']);
+			update_option($pre . '_support_splash_rp', $_POST[$pre . '_support_splash_rp']);
+			update_option($pre . '_support_splash_welcome', $_POST[$pre . '_support_splash_welcome']);
+			update_option($pre . '_support_splash_resetpass', $_POST[$pre . '_support_splash_resetpass']);
+
+			update_option($pre . '_background_image', $_POST[$pre . '_background_image']);
+			update_option($pre . '_image', $_POST[$pre . '_image']);
+			update_option($pre . '_groups', $_POST[$pre . '_groups']);
+		}
+
+		function admin_line($pre) {
+			?>
+
+		<hr>
+		<div >
+			<div style="width: 300px; height: 100px; overflow: hidden">
+				<img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
+			</div>
+
+		  <?php echo (__("Login image:", "dagsopt")) ?><br>
+		<input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
+
+		<button class="button uploadbutton">Upload</button>
+		</div>
+
+		<div >
+			<div style="width: 300px; height: 100px; overflow: hidden">
+				<img height="100" src="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>">
+			</div>
+
+		  <?php echo (__("Login background image:", "dagsopt")) ?><br>
+		<input type="text" name="<?php echo ($pre . '_background_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>" />
+
+		<button class="button uploadbutton">Upload</button>
+		</div>
+
+		<hr>
+
+		  <?php echo (__("Login splash html:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash"))); ?></textarea>
+
+		<hr>
+
+		  <?php echo (__("Login splash html rp:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_rp'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_rp"))); ?></textarea>
 
+
+		<hr>
+
+		  <?php echo (__("Login splash html welcome:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_welcome'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_welcome"))); ?></textarea>
+
+	<hr>
+
+		  <?php echo (__("Login splash html resetpass:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_resetpass'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_resetpass"))); ?></textarea>
+
+
+		<hr>
+		  <?php echo (__("Groups", "dagsopt")) ?><br>
+ 				<textarea name="<?php echo ($pre . '_groups'); ?>" rows="7" class="large-text code"><?php echo (stripcslashes(get_option($pre . "_groups"))); ?></textarea>
+
+
+		  <?php
+}
+
+	}
+
+	global $plug_login;
+	$plug_login = new plug_login($this);
+	$this->dagsopt['plug_login'] = $plug_login;
+
+}

+ 227 - 222
plug_shortcodes.php

@@ -1,289 +1,294 @@
 <?php
 
 if (!class_exists("plug_shortcodes")) {
-	class plug_shortcodes {	
+	class plug_shortcodes {
 		function __construct($ns) {
-			$this->title = __("Misc Shortcodes","dagsopt");
+			$this->title = __("Misc Shortcodes", "dagsopt");
 			$this->pluginname = $ns->pluginname;
 			$this->file = $ns->file;
 			$this->ns = $ns;
 		}
 		function start() {
-			add_filter('the_content', array(&$this,'CSV_Parse'));
+			add_filter('the_content', array(&$this, 'CSV_Parse'));
 
-			add_filter('the_content', array(&$this,'CSV_Parse2'));
-
-			add_shortcode( 'acc-page', array(&$this,'getpage') );
+			add_filter('the_content', array(&$this, 'CSV_Parse2'));
 
+			add_shortcode('acc-page', array(&$this, 'getpage'));
 
+			add_shortcode('posts', array(&$this, 'r_get_posts'));
 
 		}
 
+		function r_get_posts($atts, $content = null) {
+			extract(shortcode_atts(array(
+				"num" => '5',
+				"cat" => '',
+				"tpl" => '1big',
+				"wrap" => 'box',
+			), $atts));
+			global $post, $r_get_posts_excluded, $r_get_posts_cat_collect;
+			$oldpost = $post;
+			$caten = get_category_by_slug($cat);
+			$catid = $caten->cat_ID;
+			$r_get_posts_cat_collect[] = $catid;
+
+			$myposts = get_posts('numberposts=' . $num . '&order=DESC&orderby=post_date&category=' . $catid . "&exclude=" . implode(",", $r_get_posts_excluded));
+			$ret = '';
+			ob_start();
+			ob_clean();
+			foreach ($myposts as $post):
+				$r_get_posts_excluded[] = $post->ID;
+				setup_postdata($post);
+				if (file_exists(TEMPLATEPATH . '/tpl_' . $tpl . '.php')) {
+					include TEMPLATEPATH . '/tpl_' . $tpl . '.php';
+				}
+			endforeach;
 
+			if (isset($_REQUEST['debug'])) {
+				echo ("atts:" . print_r($atts, true) . "\n");
+				echo ("CAT:" . $cat . "\n");
+				echo ("caten:" . print_r($caten, true) . "\n");
+				echo ("posts:" . print_r($myposts, true) . "\n");
+				echo ("r_get_posts_cat_collect:" . print_r($r_get_posts_cat_collect, true) . "\n");
+				echo ("r_get_posts_excluded:" . print_r($r_get_posts_excluded, true) . "\n");
 
-function getpage( $atts ) {
-	extract( shortcode_atts( array(
-		'id' => 0
-	), $atts ) );
-	$s = "";
+			}
 
-	if($id!==0){
-		$page = get_page( $id );
-
-		$s .= '<div class="hbox embed-page page-id-'.$id.'" >';
-		$s .= '<div class="arrow">'.$page->post_title.'</div>';
-		$s .= '<div class="box">';
-		$s .= apply_filters('the_content',$page->post_content);
-		$s .= '</div>';
-		$s .= '</div>';
-	}
+			$ret = ob_get_contents();
+			ob_clean();
+			$ret .= '';
+			$post = $oldpost;
 
+			return $ret;
+		}
 
-	return $s;
-}
+		function getpage($atts) {
+			extract(shortcode_atts(array(
+				'id' => 0,
+			), $atts));
+			$s = "";
+
+			if ($id !== 0) {
+				$page = get_page($id);
+
+				$s .= '<div class="hbox embed-page page-id-' . $id . '" >';
+				$s .= '<div class="arrow">' . $page->post_title . '</div>';
+				$s .= '<div class="box">';
+				$s .= apply_filters('the_content', $page->post_content);
+				$s .= '</div>';
+				$s .= '</div>';
+			}
 
+			return $s;
+		}
 
- 
-	function CSV_Parse2($content) {
-			$content = preg_replace_callback("/\<a href=\'(.*).csv\'(.*)\>(.*)\<\/a\>/i", array(&$this,"CSV_Render2"), $content);
+		function CSV_Parse2($content) {
+			$content = preg_replace_callback("/\<a href=\'(.*).csv\'(.*)\>(.*)\<\/a\>/i", array(&$this, "CSV_Render2"), $content);
 			return $content;
 		}
-		
-function CSV_Render2($matches) {
-	//0 full 1 filename 2 attributes 3 title
-	
-	$filen = explode("/",$matches[1]);
-	$class = array_pop($filen);
-	$filen[] = $class;
-	$filen = implode("/",$filen).".csv";
-	$arguments = array();
-	$arguments['filename'] = $filen;
-	$arguments['class'] = "tablesorter ".$class;
-	$arguments['id'] = "".$class;
-	$arguments['title'] = "".$matches[3];
-	return $this->CSV_Render_($arguments);
-}
 
-		
-	function CSV_Render($matches) {
-		$matches[1] = str_replace(array('&#8221;','&#8243;'), '', $matches[1]);
-		preg_match_all('/(\w*)=(.*?)" /i', $matches[1], $attributes);
-		$arguments = array();
-		foreach ( (array) $attributes[1] as $key => $value ) {
-			$arguments[$value] = str_replace('"', '', $attributes[2][$key]);
-		}
-		if(!isset($arguments['filename']) || !is_file(ABSPATH.$arguments['filename'])){
-			return "csv error: filename ".ABSPATH.$arguments['filename']." not readable";
+		function CSV_Render2($matches) {
+			//0 full 1 filename 2 attributes 3 title
+
+			$filen = explode("/", $matches[1]);
+			$class = array_pop($filen);
+			$filen[] = $class;
+			$filen = implode("/", $filen) . ".csv";
+			$arguments = array();
+			$arguments['filename'] = $filen;
+			$arguments['class'] = "tablesorter " . $class;
+			$arguments['id'] = "" . $class;
+			$arguments['title'] = "" . $matches[3];
+			return $this->CSV_Render_($arguments);
 		}
-		return $this->CSV_Render_($arguments);
-	}
 
+		function CSV_Render($matches) {
+			$matches[1] = str_replace(array('&#8221;', '&#8243;'), '', $matches[1]);
+			preg_match_all('/(\w*)=(.*?)" /i', $matches[1], $attributes);
+			$arguments = array();
+			foreach ((array) $attributes[1] as $key => $value) {
+				$arguments[$value] = str_replace('"', '', $attributes[2][$key]);
+			}
+			if (!isset($arguments['filename']) || !is_file(ABSPATH . $arguments['filename'])) {
+				return "csv error: filename " . ABSPATH . $arguments['filename'] . " not readable";
+			}
+			return $this->CSV_Render_($arguments);
+		}
 
 		function CSV_Parse($content) {
-			$content = preg_replace_callback("/\[\[csv ([^]]*)\/\]\]/i", array(&$this,"CSV_Render"), $content);
+			$content = preg_replace_callback("/\[\[csv ([^]]*)\/\]\]/i", array(&$this, "CSV_Render"), $content);
 			return $content;
 		}
-		
 
+		function CSV_Render_($arguments) {
+
+			if (!isset($arguments['filename']) || !is_file(ABSPATH . $arguments['filename'])) {
+				return "csv error: filename " . ABSPATH . $arguments['filename'] . " not readable";
+			}
 
+			$maxread = isset($arguments['read']) ? $arguments['read'] : (1024 * 1024 * 5);
+			$delimiter = isset($arguments['delimiter']) ? $arguments['delimiter'] : ',';
+			$quotechar = isset($arguments['quotechar']) ? $arguments['quotechar'] : '"';
+			$headers = isset($arguments['headers']) ? $arguments['headers'] : false;
+			$fields = isset($arguments['fields']) ? explode(",", $arguments['fields']) : false;
 
-function CSV_Render_($arguments) {
+			$tid = isset($arguments['id']) ? $arguments['id'] : 'mytable';
+			$class = isset($arguments['class']) ? $arguments['class'] : 'tablesorter';
 
-	if(!isset($arguments['filename']) || !is_file(ABSPATH.$arguments['filename'])){
-		return "csv error: filename ".ABSPATH.$arguments['filename']." not readable";
-	}
+			$tables = array();
 
-	$maxread = isset($arguments['read']) ? $arguments['read'] : (1024*1024*5);
-	$delimiter = isset($arguments['delimiter']) ? $arguments['delimiter'] : ',';
-	$quotechar = isset($arguments['quotechar']) ? $arguments['quotechar'] : '"';
-	$headers = isset($arguments['headers']) ? $arguments['headers'] : false;
-	$fields = isset($arguments['fields']) ? explode(",",$arguments['fields']) : false;
-
-	$tid = isset($arguments['id']) ? $arguments['id'] : 'mytable';
-	$class = isset($arguments['class']) ? $arguments['class'] : 'tablesorter';
-
-	$tables = array();
-
-	$rows = array();
-	$tmp = "";
-	$tmpheaders = array();
-	$handle = fopen(ABSPATH.$arguments['filename'], "r");
-	
- 
-	
-	
-	while (($data = fgetcsv($handle, $maxread, $delimiter,$quotechar)) !== FALSE) {
-		
-		if(substr($data[0],0,1) == "!"){
-			$tables[] = array($tmp,$tmpheaders,$rows);
 			$rows = array();
-			$tmp = substr($data[0],1);
+			$tmp = "";
+			$tmpheaders = array();
+			$handle = fopen(ABSPATH . $arguments['filename'], "r");
+
+			while (($data = fgetcsv($handle, $maxread, $delimiter, $quotechar)) !== FALSE) {
+
+				if (substr($data[0], 0, 1) == "!") {
+					$tables[] = array($tmp, $tmpheaders, $rows);
+					$rows = array();
+					$tmp = substr($data[0], 1);
+
+					if ($fields) {
+						$tmpheaders = array();
+						$num = count($fields);
+						for ($c = 0; $c < $num; $c++) {
+							$tmpheaders[] = $data[$fields[$c]];
+						}
+					} else {
+						array_shift($data);
+						$tmpheaders = $data;
+						//print_r($tmpheaders);
+						//die();
+					}
 
-			if($fields){
-				$tmpheaders = array();
-				$num = count($fields);
- 				for ($c=0; $c < $num; $c++) {
-					$tmpheaders[] = $data[$fields[$c]];
+				} else {
+					if ($fields) {
+						$num = count($fields);
+						$obj = array();
+						for ($c = 0; $c < $num; $c++) {
+							$obj[] = $data[$fields[$c]];
+						}
+						$rows[] = $obj;
+					} else {
+						$num = count($data);
+						$diff = count($tmpheaders) < $num ? $num - count($tmpheaders) : 0;
+						$obj = array();
+						for ($c = 0; $c < $num; $c++) {
+							$obj[] = $data[$c + $diff];
+						}
+						$rows[] = $obj;
+					}
 				}
-			}else{
-				array_shift($data);
-				$tmpheaders = $data;
-				//print_r($tmpheaders);
-				//die();
 			}
- 			
-		}else{
-			if($fields){
-				$num = count($fields);
-				$obj = array();
-				for ($c=0; $c < $num; $c++) {
-					$obj[] = $data[$fields[$c]];
-				}
-				$rows[] = $obj;
-			}else{
-				$num = count($data);
-				$diff = count($tmpheaders) < $num ? $num - count($tmpheaders) : 0;
-				$obj = array();
-				for ($c=0; $c < $num; $c++) {
-					$obj[] = $data[$c+$diff];
+
+			if ($headers) {
+				$tmpheaders = explode(",", $headers);
+			} else {
+				if (count($tmpheaders) == 0) {
+					$tmpheaders = array_shift($rows);
 				}
-				$rows[] = $obj;
 			}
-		}
-	}
 
-	if($headers){
-		$tmpheaders = explode(",",$headers);
-	}else{
-		if(count($tmpheaders) == 0){
-			$tmpheaders = array_shift($rows);		
-		}
-	}
-	
+			$tables[] = array($tmp, $tmpheaders, $rows);
+			if (count($tables) > 1) {
+				array_shift($tables);
+			}
+			fclose($handle);
+
+			$sa = "";
+			$index = 0;
+			$menu = "";
+			foreach ($tables as $table) {
+				$title = $table[0];
+				$tt = explode("\n", $title);
+				if (count($tt) > 1) {
+					$title = array_shift($tt);
+				}
 
-	$tables[] = array($tmp,$tmpheaders,$rows);
-	if(count($tables)>1){
-		array_shift($tables);
-		}
-	fclose($handle);
+				$menu .= '<li><a href="#' . $title . '">' . $title . '</a></li>';
+			}
 
+			$sa .= '<ul id="' . $tid . '_menu" class="csvelement anchormenu">' . $menu . '</ul>';
 
-	$sa = "";
-	$index = 0;
-	$menu = "";
-	foreach($tables as $table){
-		$title = $table[0];
-			$tt = explode("\n",$title);
-				if(count($tt)>1){
-						$title = array_shift($tt);
-						}
+			foreach ($tables as $table) {
+				$index++;
 
-		$menu .= '<li><a href="#'.$title.'">'.$title.'</a></li>';
-	}
+				$title = $table[0];
+				$heads = $table[1];
+				$rows = $table[2];
 
-		$sa .=  '<ul id="'.$tid.'_menu" class="csvelement anchormenu">'.$menu.'</ul>';
-	
-	foreach($tables as $table){
-		$index ++;
-		
-		$title = $table[0];
-		$heads = $table[1];
-		$rows = $table[2];
-		
 				$hhe = "";
-				$tt = explode("\n",$title);
-				if(count($tt)>1){
-						$title = array_shift($tt);
-						$hhe .= '<h3>'.$title.'</a></h3>';
-						$hhe .= '<p>'.implode("<br>",$tt).'</p>';
-					}else{
-						$hhe .= '<h3>'.$title.'</h3>';
-						}
-
+				$tt = explode("\n", $title);
+				if (count($tt) > 1) {
+					$title = array_shift($tt);
+					$hhe .= '<h3>' . $title . '</a></h3>';
+					$hhe .= '<p>' . implode("<br>", $tt) . '</p>';
+				} else {
+					$hhe .= '<h3>' . $title . '</h3>';
+				}
 
-			$sa .= '<a name="'.$title.'" class="anchor">&nbsp;</a>';
-		 
-			$sa .= '<div id="'.$tid.'_'.$index.'" class="csvelement '.$tid.'">';
-			$sa .= $hhe;
-			$sa .= '<table  class="'.$class.'">';
-			$sa .= '<thead><tr>';
-			$cols = count($heads);
-			for($y=0;$y<$cols;$y++){
-				$sa .= '<th class="col'.$y.'">';
-				$sa .= $heads[$y];
-				$sa .= '</th>';
-			}		
-			$sa .= '</tr></thead><tbody>';
-			for($i=0,$n=count($rows);$i<$n;$i++){
-				$row = $rows[$i];
-				if(strlen(join("",$row))==0){
-				}else{
-					$sa .= '<tr>';		
-					for($y=0;$y<$cols;$y++){
-						$sa .= '<td class="col'.$y.'">';
-						$tt = explode("\n",$row[$y]);
-						if(count($tt)>1){
-								$sa .= '<strong>'.array_shift($tt).'</strong><br>';
+				$sa .= '<a name="' . $title . '" class="anchor">&nbsp;</a>';
+
+				$sa .= '<div id="' . $tid . '_' . $index . '" class="csvelement ' . $tid . '">';
+				$sa .= $hhe;
+				$sa .= '<table  class="' . $class . '">';
+				$sa .= '<thead><tr>';
+				$cols = count($heads);
+				for ($y = 0; $y < $cols; $y++) {
+					$sa .= '<th class="col' . $y . '">';
+					$sa .= $heads[$y];
+					$sa .= '</th>';
+				}
+				$sa .= '</tr></thead><tbody>';
+				for ($i = 0, $n = count($rows); $i < $n; $i++) {
+					$row = $rows[$i];
+					if (strlen(join("", $row)) == 0) {
+					} else {
+						$sa .= '<tr>';
+						for ($y = 0; $y < $cols; $y++) {
+							$sa .= '<td class="col' . $y . '">';
+							$tt = explode("\n", $row[$y]);
+							if (count($tt) > 1) {
+								$sa .= '<strong>' . array_shift($tt) . '</strong><br>';
 							}
-						$sa .= implode("<br>",$tt);
-						$sa .= '</td>';
+							$sa .= implode("<br>", $tt);
+							$sa .= '</td>';
+						}
+						$sa .= '</tr>';
 					}
-					$sa .= '</tr>';
 				}
+				$sa .= '</tbody></table><div class="totoplink"><a href="#TOP">Top</a></div></div>';
 			}
-			$sa .= '</tbody></table><div class="totoplink"><a href="#TOP">Top</a></div></div>';
+
+			/*file_put_contents($cachefn,$sa);*/
+
+			return $sa;
+
 		}
 
-	
-	/*file_put_contents($cachefn,$sa);*/
-	
-	return $sa;
-	
-	
-}
-		
-		
-		
-		
-		
-		
-		
-		function help(){
+		function help() {
 			?>
 
 	[csv filename="" read="" delimiter="," quotechar='"' headers=false fields=false id="mytable" class="tablesorter"] <br>
 	< a href='test.csv' >Title < /a >
 
 
-			 
-			
-		<?php		
-		}
-	 
-	 
-		function admin_line(){
-			?>
- 		  <?php  
-		}	
-	}
 
-	global $plug_shortcodes;
-	$plug_shortcodes = new plug_shortcodes($this);		
-		$this->dagsopt['plug_shortcodes'] = $plug_shortcodes;
-	
-
- 
-	
-	
-	
-	
-	
-	
-			
-}
 
+		<?php
+}
 
+		function admin_line() {
+			?>
+ 		  <?php
+}
+	}
 
- 
+	global $plug_shortcodes, $r_get_posts_excluded, $r_get_posts_cat_collect;
+	$r_get_posts_excluded = array();
+	$r_get_posts_cat_collect = array();
+	$plug_shortcodes = new plug_shortcodes($this);
+	$this->dagsopt['plug_shortcodes'] = $plug_shortcodes;
 
- 
+}

+ 63 - 9
plug_woohook.php

@@ -24,15 +24,28 @@ if (!class_exists("plug_wookook")) {
 
 		}
 		function start() {
- 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+			add_action( 'init', array(&$this,'xx__update_custom_roles') );
 			add_action('wp_loaded',array(&$this,'header'),1);
+ 			add_role( "suspenderet-abonnent", "Suspenderet abonnent", array( 'read' => true, 'level_0' => false ) );
+ 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+
 		}
  
+	 	function xx__update_custom_roles() {
+			    if ( get_option( 'custom_roles_version' ) < 3 ) {
+//		 			add_role( "suspenderet-abonnent", "Suspenderet abonnent", array( 'read' => true, 'level_0' => false ) );
+//		 			add_role( "betalende-abonnent", "Betalende abonnent", array( 'read' => true, 'level_0' => true ) );
+			        update_option( 'custom_roles_version', 3 );
+			    }
+			}
+
+
 
 		 function header(){
 
 		 	if(isset($_REQUEST['woohook'])){
 		 		$thecode = get_option($this->pluginname."_wookook_code",false);
+		 		$exitrole = trim(get_option($this->pluginname."_wookook_exitrole",false));
 
 		 		if($_REQUEST['woohook']!=="$thecode"){
 		 			die("code not right");
@@ -50,32 +63,59 @@ if (!class_exists("plug_wookook")) {
 						$role = $a[1];
 						foreach ($nums as $pp => $itemnum) {
 							if(strlen($role)>0){
-								$itemroles[$itemnum] = $role;
+								$itemroles[trim($itemnum)] = trim($role);
 							}
 						}
 					}
 				}
+				
 
 				$found = false;
 				try {
 					$order = json_decode($rr,true);
-					if(isset($order['date_paid_gmt'])){
+					if(isset($order['line_items'])){
 						foreach ($order['line_items'] as $num => $line) {
 							if(isset($itemroles["".$line['product_id']])){
 								$found = true;
 								$therole = $itemroles["".$line['product_id']];
 							}
 						}
+
 					}
 				} catch (Exception $e) {
 				    echo 'Caught exception: ',  $e->getMessage(), "\n";
 				}
+
+				$active = false;
+
+				if(isset($order['status'])){
+				
+				if($order['status']=="active"){
+					$found = true;
+					$active = true;
+				}else if($order['status']=="processing"){
+					if(isset($order['date_paid_gmt']) && strlen($order['date_paid_gmt'])>0){
+						$found = true;
+						$active = true;
+					}else{
+						$found = false;
+					}
+				}else if($order['status']=="on-hold"){
+					$active = false;					
+				}
+
+				}
+			 
+
+			//	echo($order['status']."::".$found."::".$active." : ".$order['date_paid']." : ".$order['date_paid_gmt']);
+			//	die("\n\nDONE");
+
 				$testmode = false;
 
 				if($found){
 						$resu = array();
 							$user_email = $order['billing']['email'];
-							$user_name = sanitize_username("O".$order['id']);
+							$user_name = $user_email;//sanitize_username("O".$order['id']);
 				    		$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 );
@@ -83,13 +123,24 @@ if (!class_exists("plug_wookook")) {
 									$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' => $therole) );
+
+									$xrole = $active ? $therole : $exitrole;
+								    wp_update_user( array( 'ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'],'last_name'=> $order['billing']['last_name']) );
+
 									wp_send_new_user_notifications($user_id,'both');
-									$resu[] = "$user_id created : $user_name $user_email ";
+									$resu[] = "CREATED: ".$order['status']." $active $user_id or $user_email exists role > '$xrole'";
+
 								   }
 								} else {
-									$resu[] = "$user_id or $user_email exists";
-								    $random_password = __( 'User already exists.  Password inherited.', 'textdomain' );
+									$xrole = $active ? $therole : $exitrole;
+									
+									  wp_update_user( array( 'ID' => $user_id, 'role' => $xrole, 'first_name' => $order['billing']['first_name'],'last_name'=> $order['billing']['last_name']) );
+
+									$u = new WP_User(  $user_id );
+									$u->set_role( $xrole );
+
+								    
+								    $resu[] = "UPDATED: ".$order['status']." $active $user_id or $user_email exists role > '$xrole'";
 								}
 							  $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));
@@ -117,6 +168,7 @@ if (!class_exists("plug_wookook")) {
 			//update_option ( $pre.'_items', $_POST [ $pre.'_items' ] );
  
 			update_option ( $pre.'_code', $_POST [ $pre.'_code' ] );
+			update_option ( $pre.'_exitrole', $_POST [ $pre.'_exitrole' ] );
  
 
 			update_option ( $pre.'_item_roles', $_POST [ $pre.'_item_roles' ] );
@@ -141,7 +193,9 @@ if (!class_exists("plug_wookook")) {
 <?php echo(__("Code:","dagsopt")) ?><br>
  				<textarea name="<?php echo( $pre.'_code' ); ?>" rows="2" class="large-text code"><?php echo(stripcslashes(get_option($pre."_code"))); ?></textarea> 
 
-   
+<?php echo(__("Exitrole:","dagsopt")) ?><br>
+ 				<input name="<?php echo( $pre.'_exitrole' ); ?>"  value="<?php echo(stripcslashes(get_option($pre."_exitrole"))); ?>"> 
+
 	  <?php  
 }	
 }

+ 2 - 2
plugin.php

@@ -4,7 +4,7 @@
  Plugin URI: https://git.tum.dk/tum.dk/dagsplug/
  Description: Tools 
  Author: iskedk
- Version: 0.0.36
+ Version: 0.0.37
  Date: 2021-01-14
  Author URI: https://iske.dk/
  Text Domain: dagsopt
@@ -17,7 +17,7 @@ function wppluginspage() {
 $wp_dagsopt = new dagsopt ( );
 
 class dagsopt {
-	var $version = "0.0.36";
+	var $version = "0.0.37";
 	var $publish_date = "2021-01-14";
 	var $pluginname;
 	var $plugintitle;