plug_login.php 16 KB

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