plug_login.php 13 KB

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