plug_login.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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 l_stylesheet_directory_uri($t) {
  120. return str_replace(WP_SITEURL, WP_SITEURL_CDN, $t);
  121. }
  122. function login_headerurl($t) {
  123. return "/";
  124. }
  125. function login_headertext($t) {
  126. return "Til forsiden";
  127. }
  128. function login_message($t) {
  129. $login = "";
  130. foreach ($_COOKIE as $key => $value) {
  131. if (stristr($key, "wp-resetpass")) {
  132. $v = explode(":", $value);
  133. $login = array_shift($v);
  134. }
  135. }
  136. $str = '<style type="text/css">
  137. body {
  138. background-size: cover;
  139. background-position: center center;
  140. background-image: url(' . stripslashes(get_option($this->pluginname . "_login_background_image")) . ');
  141. }
  142. .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")) . ');}
  143. .login_holder {
  144. margin-top: 20px;
  145. margin-left: 0;
  146. padding: 26px 24px 46px;
  147. font-weight: 400;
  148. overflow: hidden;
  149. background: #fff;
  150. border: 1px solid #ccd0d4;
  151. box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
  152. }
  153. </style>
  154. <script type="text/javascript">
  155. jQuery(document).ready(function($){
  156. var qq = {};
  157. $.each(document.location.search.substr(1).split("&"),function(c,q){
  158. var i = q.split("=");
  159. qq[i[0].toString()] = i[1].toString();
  160. });
  161. if(qq.action=="resetpass"){
  162. setTimeout(function(){
  163. window.location.href="/wp-login.php?action=welcome&user_login=' . $login . '"
  164. },500)
  165. }else{
  166. $("#user_login").val(qq["user_login"]);
  167. }
  168. })
  169. </script>
  170. <div class="login_holder">
  171. <p>';
  172. if (isset($_GET['action'])) {
  173. $str .= get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false);
  174. } else {
  175. $str .= get_option($this->pluginname . "_login_support_splash", false);
  176. }
  177. $str .= '</p></div>';
  178. return $str;
  179. }
  180. function help() {
  181. ?>
  182. <?php echo (__("Adds logo to login page", "dagsopt")) ?>
  183. <a href="/wp-login.php"><?php echo (__("Login page", "dagsopt")) ?></a>
  184. <?php
  185. }
  186. function login_head() {
  187. // $type = (empty($_REQUEST['type']) || !($_REQUEST['type'] == "Select" || $_REQUEST['type'] == "Pro")) ? "Select" : $_REQUEST['type'];
  188. $type = "Perspektiv";
  189. if ($type !== "") {
  190. ?>
  191. <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
  192. <script type="text/javascript">
  193. jQuery(document).ready(function(){
  194. if(jQuery("form").attr('action').indexOf('register')>-1){
  195. jQuery("form").prepend('<h3>Ræson <?php echo ($type) ?></h3><br>');
  196. jQuery("p:contains('Brugernavn')").hide();
  197. jQuery("#user_email").attr("tabindex","24")
  198. jQuery("#r_navn").attr("tabindex","25")
  199. jQuery("#r_membership").attr("tabindex","26")
  200. jQuery("#wp-submit").attr("tabindex","27")
  201. var t = (jQuery('#login_error').html())+"";
  202. var a = t.split("\n");
  203. if(a.length && a[0].indexOf('brugernavn')>-1){
  204. a.shift();
  205. jQuery('#login_error').html(a.join("\n"));
  206. }
  207. jQuery("#user_login").hide();
  208. jQuery('label[for="user_login"]').hide();
  209. jQuery('#wp-submit').click(function(){
  210. console.log("SEND");
  211. jQuery('#user_login').val(jQuery('#user_email').val());
  212. });
  213. }
  214. });
  215. </script>
  216. <?php
  217. }
  218. ?>
  219. <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory');?>/style2.css">
  220. <?php
  221. }
  222. function plugin_form() {
  223. $type = "Perspektiv"; //;(empty($_REQUEST['type']) || !($_REQUEST['type'] == "Select" || $_REQUEST['type'] == "Pro")) ? "Select" : $_REQUEST['type'];
  224. //19094 __system_side_medlem_af
  225. //$tt = get_post( 19094);
  226. //print_r($_REQUEST);
  227. //$arra = explode("<hr>","".$tt->post_content);
  228. //$listen = array_pop($arra);
  229. $content = get_option($this->pluginname . "_login_groups", false) . "::::" . ($this->pluginname . "_login_groups");
  230. //$arr = explode("\n","".$listen);
  231. $arr = explode("\n", get_option($this->pluginname . "_login_groups", false));
  232. $sel = '<select name="r_membership" id="r_membership" class="input nnl" tabindex="26">';
  233. $sel .= '<option ' . ((!isset($_POST['r_membership']) || $_POST['r_membership'] === "") ? "selected" : "") . '>Vælg gruppe</option>';
  234. foreach ($arr as $ii => $title) {
  235. if (strlen($title) > 3) {
  236. $sel .= '<option value="' . $title . '" ' . ($_POST['r_membership'] === $title ? "selected" : "") . '>' . $title . '</option>';
  237. }
  238. }
  239. $sel .= '</select>';
  240. $html = '
  241. <style type="text/css">
  242. .nnl {
  243. background:#FBFBFB none repeat scroll 0 0;
  244. border:1px solid #E5E5E5;
  245. font-size:20px;
  246. margin-bottom:16px;
  247. margin-right:6px;
  248. margin-top:2px;
  249. padding:3px;
  250. width:97%;
  251. }
  252. </style>
  253. <div width="100%">
  254. <div>
  255. ' . $content . '
  256. </div>
  257. <input type="hidden" name="r_proselect" id="r_proselect" value="' . $type . '">
  258. <p>
  259. <label style="display: block; margin-bottom: 5px;">' . __('Navn', 'Navn') . '
  260. <input type="text" name="r_navn" id="r_navn" class="input nnl" value="' . $_POST['r_navn'] . '" size="20" tabindex="25" />
  261. </label>
  262. </p>
  263. <p>
  264. <label style="display: block; margin-bottom: 5px;">' . __('Medlem af', 'Medlem af') . '
  265. ' . $sel . '
  266. </label>
  267. </p>
  268. </div>
  269. ';
  270. echo $html;
  271. }
  272. function Option($pre) {
  273. update_option($pre . '_support_splash', $_POST[$pre . '_support_splash']);
  274. update_option($pre . '_support_splash_rp', $_POST[$pre . '_support_splash_rp']);
  275. update_option($pre . '_support_splash_welcome', $_POST[$pre . '_support_splash_welcome']);
  276. update_option($pre . '_support_splash_resetpass', $_POST[$pre . '_support_splash_resetpass']);
  277. update_option($pre . '_background_image', $_POST[$pre . '_background_image']);
  278. update_option($pre . '_image', $_POST[$pre . '_image']);
  279. update_option($pre . '_groups', $_POST[$pre . '_groups']);
  280. }
  281. function admin_line($pre) {
  282. ?>
  283. <hr>
  284. <div >
  285. <div style="width: 300px; height: 100px; overflow: hidden">
  286. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
  287. </div>
  288. <?php echo (__("Login image:", "dagsopt")) ?><br>
  289. <input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
  290. <button class="button uploadbutton">Upload</button>
  291. </div>
  292. <div >
  293. <div style="width: 300px; height: 100px; overflow: hidden">
  294. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>">
  295. </div>
  296. <?php echo (__("Login background image:", "dagsopt")) ?><br>
  297. <input type="text" name="<?php echo ($pre . '_background_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>" />
  298. <button class="button uploadbutton">Upload</button>
  299. </div>
  300. <hr>
  301. <?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>
  302. <hr>
  303. <?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>
  304. <hr>
  305. <?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>
  306. <hr>
  307. <?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>
  308. <hr>
  309. <?php echo (__("Groups", "dagsopt")) ?><br>
  310. <textarea name="<?php echo ($pre . '_groups'); ?>" rows="7" class="large-text code"><?php echo (stripcslashes(get_option($pre . "_groups"))); ?></textarea>
  311. <?php
  312. }
  313. }
  314. global $plug_login;
  315. $plug_login = new plug_login($this);
  316. $this->dagsopt['plug_login'] = $plug_login;
  317. }