plug_login.php 14 KB

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