plug_login.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <?php
  2. if (!class_exists("plug_login")) {
  3. class plug_login {
  4. function __construct($ns) {
  5. $this->title = __("Login", "dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. add_action('init', array(&$this, 'override_reset_password_form_redirect'));
  12. add_filter('login_headerurl', array(&$this, 'login_headerurl'));
  13. add_filter('login_headertext', array(&$this, 'login_headertext'));
  14. add_filter('login_message', array(&$this, 'login_message'));
  15. add_action('register_form', array(&$this, 'plugin_form'));
  16. if (defined("WP_SITEURL") && defined('WP_SITEURL_CDN')) {
  17. add_filter('stylesheet_directory_uri', array(&$this, 'l_stylesheet_directory_uri'));
  18. }
  19. add_action('login_head', array(&$this, 'login_head'));
  20. add_action('admin_enqueue_scripts', function () {
  21. /*
  22. if possible try not to queue this all over the admin by adding your settings GET page val into next
  23. if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
  24. */
  25. wp_enqueue_media();
  26. });
  27. add_filter('upload_mimes', function ($mime_types) {
  28. $mime_types['svg'] = 'image/svg+xml'; // Adding .svg extension
  29. $mime_types['json'] = 'application/json'; // Adding .json extension
  30. // unset( $mime_types['xls'] ); // Remove .xls extension
  31. // unset( $mime_types['xlsx'] ); // Remove .xlsx extension
  32. return $mime_types;
  33. }, 1, 1);
  34. add_action('admin_footer', function () {
  35. /*
  36. if possible try not to queue this all over the admin by adding your settings GET page val into next
  37. if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
  38. */
  39. ?>
  40. <script>
  41. jQuery(document).ready(function($){
  42. $(".uploadbutton").click(function(e){
  43. e.preventDefault();
  44. var self = $(this);
  45. var target = jQuery('.valuereciever', self.parent())
  46. var preview = jQuery('img', self.parent())
  47. var custom_uploader;
  48. if (custom_uploader) {
  49. custom_uploader.open();
  50. return;
  51. }
  52. custom_uploader = wp.media.frames.file_frame = wp.media({
  53. title: 'Choose Image',
  54. button: {
  55. text: 'Choose Image'
  56. },
  57. multiple: false
  58. });
  59. custom_uploader.on('select', function() {
  60. attachment = custom_uploader.state().get('selection').first().toJSON();
  61. console.log(attachment);
  62. target.val("/"+attachment.url.split("/").slice(3).join("/"));
  63. preview.attr("src", target.val() );
  64. });
  65. custom_uploader.open();
  66. })
  67. /* var custom_uploader
  68. , click_elem = jQuery('.uploadbutton')
  69. , target = jQuery('.valuereciever', click_elem.parent())
  70. click_elem.click(function(e) {
  71. e.preventDefault();
  72. //If the uploader object has already been created, reopen the dialog
  73. if (custom_uploader) {
  74. custom_uploader.open();
  75. return;
  76. }
  77. //Extend the wp.media object
  78. custom_uploader = wp.media.frames.file_frame = wp.media({
  79. title: 'Choose Image',
  80. button: {
  81. text: 'Choose Image'
  82. },
  83. multiple: false
  84. });
  85. //When a file is selected, grab the URL and set it as the text field's value
  86. custom_uploader.on('select', function() {
  87. attachment = custom_uploader.state().get('selection').first().toJSON();
  88. console.log(attachment);
  89. target.val("/"+attachment.url.split("/").slice(3).join("/"));
  90. });
  91. //Open the uploader dialog
  92. custom_uploader.open();
  93. });
  94. */
  95. });
  96. </script>
  97. <?php
  98. });
  99. }
  100. function override_reset_password_form_redirect() {
  101. $action = isset($_GET['action']) ? $_GET['action'] : '';
  102. $key = isset($_GET['key']) ? $_GET['key'] : '';
  103. $login = isset($_GET['login']) ? $_GET['login'] : '';
  104. if ('wp-login.php' === $GLOBALS['pagenow'] && ('resetpass' == $action)) {
  105. if (isset($_POST['wp-submit']) && $_POST['wp-submit'] == "Reset Password") {
  106. foreach ($_COOKIE as $key => $value) {
  107. if (stristr($key, "wp-resetpass")) {
  108. $v = explode(":", $value);
  109. $login = array_shift($v);
  110. }
  111. # code...
  112. }
  113. //print_r($GLOBALS);
  114. //wp_redirect(site_url('/wp-login.php') . '?action=welcome&user_login=' . $login);
  115. //exit;
  116. }
  117. }
  118. }
  119. function get_page_by_name($post_name, $output = OBJECT) {
  120. global $wpdb;
  121. $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $post_name));
  122. if ($post) {
  123. return get_post($post, $output);
  124. }
  125. return null;
  126. }
  127. function l_stylesheet_directory_uri($t) {
  128. return str_replace(WP_SITEURL, WP_SITEURL_CDN, $t);
  129. }
  130. function login_headerurl($t) {
  131. return "/";
  132. }
  133. function login_headertext($t) {
  134. return "Til forsiden";
  135. }
  136. function login_message($t) {
  137. $login = "";
  138. foreach ($_COOKIE as $key => $value) {
  139. if (stristr($key, "wp-resetpass")) {
  140. $v = explode(":", $value);
  141. $login = array_shift($v);
  142. }
  143. }
  144. $str = '<style type="text/css">
  145. body {
  146. background-size: cover;
  147. background-position: center center;
  148. background-image: url(' . stripslashes(get_option($this->pluginname . "_login_background_image")) . ');
  149. }
  150. .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")) . ');}
  151. .login_holder {
  152. margin-top: 20px;
  153. margin-left: 0;
  154. padding: 26px 24px 46px;
  155. font-weight: 400;
  156. overflow: hidden;
  157. background: #fff;
  158. border: 1px solid #ccd0d4;
  159. box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
  160. }
  161. </style>
  162. <script type="text/javascript">
  163. jQuery(document).ready(function($){
  164. var qq = {};
  165. $.each(document.location.search.substr(1).split("&"),function(c,q){
  166. var i = q.split("=");
  167. qq[i[0].toString()] = i[1].toString();
  168. });
  169. if(qq.action=="resetpass"){
  170. setTimeout(function(){
  171. window.location.href="/wp-login.php?action=welcome&user_login=' . $login . '"
  172. },500)
  173. }else{
  174. $("#user_login").val(qq["user_login"]);
  175. }
  176. })
  177. </script>
  178. <div class="login_holder">
  179. <p>';
  180. if (isset($_GET['action'])) {
  181. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  182. if ($type !== "default") {
  183. //print_r($args);
  184. $page = $this->get_page_by_name($type);
  185. if ($page) {
  186. $str .= apply_filters('the_content', $page->post_content);
  187. } else {
  188. $str .= get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false);
  189. }
  190. } else {
  191. $str .= get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false);
  192. }
  193. } else {
  194. $str .= get_option($this->pluginname . "_login_support_splash", false);
  195. }
  196. $str .= '</p></div>';
  197. return $str;
  198. }
  199. function help() {
  200. ?>
  201. <?php echo (__("Adds logo to login page", "dagsopt")) ?>
  202. <a href="/wp-login.php"><?php echo (__("Login page", "dagsopt")) ?></a>
  203. <?php
  204. }
  205. function login_head() {
  206. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  207. if ($type !== "default") {
  208. ?>
  209. <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
  210. <script type="text/javascript">
  211. jQuery(document).ready(function(){
  212. if(jQuery("form").length>0 && jQuery("form").attr('action').indexOf('register')>-1){
  213. console.log("SPECIAL REGV");
  214. //jQuery("form").prepend('<h3><?php echo ($type) ?></h3><br>');
  215. jQuery("p:contains('Brugernavn')").hide();
  216. jQuery("#user_email").attr("tabindex","24")
  217. jQuery("#r_navn").attr("tabindex","25")
  218. jQuery("#r_membership").attr("tabindex","26")
  219. jQuery("#wp-submit").attr("tabindex","27")
  220. var t = (jQuery('#login_error').html())+"";
  221. var a = t.split("\n");
  222. if(a.length && a[0].indexOf('brugernavn')>-1){
  223. a.shift();
  224. jQuery('#login_error').html(a.join("\n"));
  225. }
  226. jQuery("#user_login").hide();
  227. jQuery('label[for="user_login"]').hide();
  228. jQuery('#wp-submit').click(function(){
  229. console.log("SEND");
  230. jQuery('#user_login').val(jQuery('#user_email').val());
  231. });
  232. }
  233. });
  234. </script>
  235. <?php
  236. }
  237. ?>
  238. <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory');?>/style2.css">
  239. <?php
  240. }
  241. function plugin_form() {
  242. $type = isset($_GET['type']) ? $_GET['type'] : 'default';
  243. //19094 __system_side_medlem_af
  244. //$tt = get_post( 19094);
  245. //print_r($_REQUEST);
  246. //$arra = explode("<hr>","".$tt->post_content);
  247. //$listen = array_pop($arra);
  248. $content = "";
  249. //$arr = explode("\n","".$listen);
  250. $arr = explode("\n", get_option($this->pluginname . "_login_groups", false));
  251. /* $sel = '<select name="r_membership" id="r_membership" class="input nnl" tabindex="26">';
  252. $sel .= '<option ' . ((!isset($_POST['r_membership']) || $_POST['r_membership'] === "") ? "selected" : "") . '>Vælg </option>';
  253. foreach ($arr as $ii => $title) {
  254. if (strlen($title) > 3) {
  255. $sel .= '<option value="' . $title . '" ' . (isset($_POST['r_membership']) && $_POST['r_membership'] === $title ? "selected" : "") . '>' . $title . '</option>';
  256. }
  257. }
  258. $sel .= '</select>';
  259. */
  260. $sel = '<input type="hidden" name="r_membership" id="r_membership" value="' . $type . '">';
  261. $html = '
  262. <style type="text/css">
  263. .nnl {
  264. background:#FBFBFB none repeat scroll 0 0;
  265. border:1px solid #E5E5E5;
  266. font-size:20px;
  267. margin-bottom:16px;
  268. margin-right:6px;
  269. margin-top:2px;
  270. padding:3px;
  271. width:97%;
  272. }
  273. </style>
  274. <div width="100%">
  275. <div>
  276. ' . $content . '
  277. </div>
  278. <input type="hidden" name="r_proselect" id="r_proselect" value="' . $type . '">
  279. <p>
  280. <label style="display: block; margin-bottom: 5px;">' . __('Navn', 'Navn') . '
  281. <input type="text" name="r_navn" id="r_navn" class="input nnl" value="' . (isset($_POST['r_navn']) ? $_POST['r_navn'] : "") . '" size="20" tabindex="25" />
  282. </label>
  283. </p>
  284. <p>
  285. ' . $sel . '
  286. </p>
  287. </div>
  288. ';
  289. echo $html;
  290. }
  291. function Option($pre) {
  292. update_option($pre . '_support_splash', $_POST[$pre . '_support_splash']);
  293. update_option($pre . '_support_splash_rp', $_POST[$pre . '_support_splash_rp']);
  294. update_option($pre . '_support_splash_welcome', $_POST[$pre . '_support_splash_welcome']);
  295. update_option($pre . '_support_splash_resetpass', $_POST[$pre . '_support_splash_resetpass']);
  296. update_option($pre . '_support_splash_register', $_POST[$pre . '_support_splash_register']);
  297. update_option($pre . '_background_image', $_POST[$pre . '_background_image']);
  298. update_option($pre . '_image', $_POST[$pre . '_image']);
  299. update_option($pre . '_groups', $_POST[$pre . '_groups']);
  300. }
  301. function admin_line($pre) {
  302. ?>
  303. <hr>
  304. <div >
  305. <div style="width: 300px; height: 100px; overflow: hidden">
  306. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
  307. </div>
  308. <?php echo (__("Login image:", "dagsopt")) ?><br>
  309. <input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
  310. <button class="button uploadbutton">Upload</button>
  311. </div>
  312. <div >
  313. <div style="width: 300px; height: 100px; overflow: hidden">
  314. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>">
  315. </div>
  316. <?php echo (__("Login background image:", "dagsopt")) ?><br>
  317. <input type="text" name="<?php echo ($pre . '_background_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>" />
  318. <button class="button uploadbutton">Upload</button>
  319. </div>
  320. <hr>
  321. <?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>
  322. <hr>
  323. <?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>
  324. <hr>
  325. <?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>
  326. <hr>
  327. <?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>
  328. <hr>
  329. <?php echo (__("Login splash html register:", "dagsopt")) ?><br><textarea style="width: 100%; height: 150px;" name="<?php echo ($pre . '_support_splash_register'); ?>"><?php echo (stripslashes(get_option($pre . "_support_splash_register"))); ?></textarea>
  330. <hr>
  331. <?php echo (__("Groups", "dagsopt")) ?><br>
  332. <textarea name="<?php echo ($pre . '_groups'); ?>" rows="7" class="large-text code"><?php echo (stripcslashes(get_option($pre . "_groups"))); ?></textarea>
  333. <?php
  334. }
  335. }
  336. global $plug_login;
  337. $plug_login = new plug_login($this);
  338. $this->dagsopt['plug_login'] = $plug_login;
  339. }