123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
- <?php
- if (!class_exists("plug_login")) {
- class plug_login {
- function __construct($ns) {
- $this->title = __("Login", "dagsopt");
- $this->pluginname = $ns->pluginname;
- $this->file = $ns->file;
- $this->ns = $ns;
- }
- function start() {
- add_action('init', array(&$this, 'override_reset_password_form_redirect'));
- add_filter("login_redirect", array(&$this, "my_login_redirect"), 10, 3);
- add_filter("admin_bar_menu", array(&$this, "replace_howdy"), 25);
- add_filter('login_headerurl', array(&$this, 'login_headerurl'));
- add_filter('login_headertext', array(&$this, 'login_headertext'));
- add_filter('login_message', array(&$this, 'login_message'));
- add_action('register_form', array(&$this, 'plugin_form'));
- if (defined("WP_SITEURL") && defined('WP_SITEURL_CDN')) {
- add_filter('stylesheet_directory_uri', array(&$this, 'l_stylesheet_directory_uri'));
- }
- add_action('login_head', array(&$this, 'login_head'));
- add_action('user_register', array(&$this, 'plugin_user_register'), 10, 3);
- add_action('personal_options_update', array(&$this, 'plugin_user_register'), 10, 3);
- add_action('admin_enqueue_scripts', function () {
- /*
- if possible try not to queue this all over the admin by adding your settings GET page val into next
- if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
- */
- wp_enqueue_media();
- });
- add_filter('register', function ($linket) {
- return "";
- });
- add_filter('upload_mimes', function ($mime_types) {
- $mime_types['m4a'] = 'audio/m4a'; //
- $mime_types['m4v'] = 'video/mp4'; //
- $mime_types['svg'] = 'image/svg+xml'; // Adding .svg extension
- $mime_types['json'] = 'application/json'; // Adding .json extension
- // unset( $mime_types['xls'] ); // Remove .xls extension
- // unset( $mime_types['xlsx'] ); // Remove .xlsx extension
- return $mime_types;
- }, 1, 1);
- add_action('register_post', array(&$this, 'register_post'), 10, 3);
- add_action('edit_user_profile', array(&$this, 'plugin_show_user_profile'), 10, 3);
- add_action('admin_footer', array(&$this, 'admin_footer'), 10, 3);
- }
- //add_action('show_user_profile', 'plugin_show_user_profile');
- function admin_footer() {
- /*
- if possible try not to queue this all over the admin by adding your settings GET page val into next
- if( empty( $_GET['page'] ) || "my-settings-page" !== $_GET['page'] ) { return; }
- */
- ?>
- <script>
- jQuery(document).ready(function($){
- $(".uploadbutton").click(function(e){
- e.preventDefault();
- var self = $(this);
- var target = jQuery('.valuereciever', self.parent())
- var preview = jQuery('img', self.parent())
- var custom_uploader;
- if (custom_uploader) {
- custom_uploader.open();
- return;
- }
- custom_uploader = wp.media.frames.file_frame = wp.media({
- title: 'Choose Image',
- button: {
- text: 'Choose Image'
- },
- multiple: false
- });
- custom_uploader.on('select', function() {
- attachment = custom_uploader.state().get('selection').first().toJSON();
- console.log(attachment);
- target.val("<?php echo WP_SITEURL_CDN ?>/"+attachment.url.split("/").slice(3).join("/"));
- preview.attr("src", target.val() );
- });
- custom_uploader.open();
- })
- /* var custom_uploader
- , click_elem = jQuery('.uploadbutton')
- , target = jQuery('.valuereciever', click_elem.parent())
- click_elem.click(function(e) {
- e.preventDefault();
- //If the uploader object has already been created, reopen the dialog
- if (custom_uploader) {
- custom_uploader.open();
- return;
- }
- //Extend the wp.media object
- custom_uploader = wp.media.frames.file_frame = wp.media({
- title: 'Choose Image',
- button: {
- text: 'Choose Image'
- },
- multiple: false
- });
- //When a file is selected, grab the URL and set it as the text field's value
- custom_uploader.on('select', function() {
- attachment = custom_uploader.state().get('selection').first().toJSON();
- console.log(attachment);
- target.val("/"+attachment.url.split("/").slice(3).join("/"));
- });
- //Open the uploader dialog
- custom_uploader.open();
- });
- */
- });
- </script>
- <?php
- }
- function plugin_show_user_profile($user) {
- ?>
- <h3><?php _e('Pro/Select information')?></h3>
- <table class="form-table">
- <tr>
- <td><input type="hidden" name="r_proselect" id="r_proselect" value="<?php echo $user->Proselect; ?>" /><?php echo $user->Proselect; ?></td>
- </tr>
- <tr>
- <th><label for="Navn"><?php _e('Navn');?></label></th>
- <td><input type="text" name="r_navn" id="r_navn" value="<?php echo $user->Navn; ?>" /></td>
- </tr>
- <tr>
- <th><label for="Medlem af"><?php _e('Medlem af');?></label></th>
- <td><input type="text" name="r_membership" id="r_membership" value="<?php echo $user->Gruppe; ?>" /></td>
- </tr>
- </table>
- <?php
- }
- function replace_howdy($wp_admin_bar) {
- $my_account = $wp_admin_bar->get_node('my-account');
- $newtitle = str_replace('Hejsa,', 'Velkommen,', $my_account->title);
- $wp_admin_bar->add_node(array(
- 'id' => 'my-account',
- 'title' => $newtitle,
- ));
- }
- function my_login_redirect($redirect_to, $request) {
- $redirect_url = WP_SITEURL;
- return $redirect_url;
- }
- function override_reset_password_form_redirect() {
- $action = isset($_GET['action']) ? $_GET['action'] : '';
- $key = isset($_GET['key']) ? $_GET['key'] : '';
- $login = isset($_GET['login']) ? $_GET['login'] : '';
- if ('wp-login.php' === $GLOBALS['pagenow'] && ('resetpass' == $action)) {
- if (isset($_POST['wp-submit']) && $_POST['wp-submit'] == "Reset Password") {
- foreach ($_COOKIE as $key => $value) {
- if (stristr($key, "wp-resetpass")) {
- $v = explode(":", $value);
- $login = array_shift($v);
- }
- # code...
- }
- //print_r($GLOBALS);
- //wp_redirect(site_url('/wp-login.php') . '?action=welcome&user_login=' . $login);
- //exit;
- }
- }
- }
- function get_page_by_name($post_name, $output = OBJECT) {
- global $wpdb;
- $post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type='page'", $post_name));
- if ($post) {
- return get_post($post, $output);
- }
- return null;
- }
- function l_stylesheet_directory_uri($t) {
- return str_replace(WP_SITEURL, WP_SITEURL_CDN, $t);
- }
- function login_headerurl($t) {
- return "/";
- }
- function login_headertext($t) {
- return "Til forsiden";
- }
- function login_message($t) {
- $login = "";
- foreach ($_COOKIE as $key => $value) {
- if (stristr($key, "wp-resetpass")) {
- $v = explode(":", $value);
- $login = array_shift($v);
- }
- }
- $str = '<style type="text/css">
- body {
- background-size: cover;
- background-position: center center;
- background-image: url(' . stripslashes(get_option($this->pluginname . "_login_background_image")) . ');
- }
- .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")) . ');}
- .login_holder {
- margin-top: 20px;
- margin-left: 0;
- padding: 26px 24px 46px;
- font-weight: 400;
- overflow: hidden;
- background: #fff;
- border: 1px solid #ccd0d4;
- box-shadow: 0 1px 3px rgb(0 0 0 / 4%);
- }
- ' . stripslashes(get_option($this->pluginname . "_login_styles")) . '
- </style>
- <script type="text/javascript">
- jQuery(document).ready(function($){
- var qq = {};
- $.each(document.location.search.substr(1).split("&"),function(c,q){
- var i = q.split("=");
- qq[i[0].toString()] = i[1].toString();
- });
- if(qq.action=="resetpass"){
- setTimeout(function(){
- window.location.href="/wp-login.php?action=welcome&user_login=' . $login . '"
- },500)
- }else{
- $("#user_login").val(qq["user_login"]);
- }
- })
- </script>
- <div class="login_holder">
- <p>';
- if (isset($_GET['action'])) {
- $type = isset($_GET['type']) ? $_GET['type'] : 'default';
- if ($type !== "default") {
- //print_r($args);
- $page = $this->get_page_by_name($type);
- if ($page) {
- $str .= apply_filters('the_content', $page->post_content);
- } else {
- $str .= stripslashes(get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false));
- }
- } else {
- $str .= stripslashes(get_option($this->pluginname . "_login_support_splash_" . $_GET['action'], false));
- }
- } else {
- $str .= stripslashes(get_option($this->pluginname . "_login_support_splash", false));
- }
- $str .= '</p></div>';
- return $str;
- }
- function plugin_user_register($id) {
- $user_info = get_userdata($id);
- update_user_meta($id, 'Proselect', $_POST['r_proselect']);
- update_user_meta($id, 'Navn', $_POST['r_navn']);
- update_user_meta($id, 'Gruppe', $_POST['r_membership']);
- // update_usermeta($id, 'Institution' , $_POST['r_institution'] );
- // update_usermeta($id, 'Fag' , $_POST['r_fag'] );
- // update_usermeta($id, 'Fødselsår' , $_POST['r_alder'] );
- }
- function register_post($login, $email, $errors) {
- if (empty($_POST['r_proselect'])) {
- $_POST['r_proselect'] = "Perspektiv";
- } else {
- if ($_POST['r_proselect'] == "default") {
- $errors->add('demo_error', __(stripslashes(get_option($this->pluginname . "_login_support_error"))));
- }
- }
- if (empty($_POST['r_navn'])) {
- $errors->add('demo_error', __('Du skal udfylde Navn'));
- }
- ;
- if (empty($_POST['r_membership']) || $_POST['r_membership'] === "Vælg gruppe") {
- $errors->add('demo_error', __('Du skal udfylde Gruppe'));
- }
- ;
- /* if(empty($_POST['r_fag'])){
- $errors->add('demo_error',__('Du skal udfylde Fag'));
- };
- if(empty($_POST['r_alder'])){
- $errors->add('demo_error',__('Du skal udfylde Alder'));
- }else{
- $alder = intval($_POST['r_alder']);
- if($alder < 1900 || $alder > 2005){
- $errors->add('demo_error',__('hmmm.. din alder virker mystisk'));
- };
- };
- */
- }
- function help() {
- ?>
- <?php echo (__("Adds logo to login page", "dagsopt")) ?>
- <a href="/wp-login.php"><?php echo (__("Login page", "dagsopt")) ?></a>
- <?php
- }
- function login_head() {
- $type = isset($_GET['type']) ? $_GET['type'] : 'default';
- if ($type !== "!!default") {
- ?>
- <script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
- <script type="text/javascript">
- jQuery(document).ready(function(){
- if(jQuery("form").length>0 && jQuery("form").attr('action').indexOf('register')>-1){
- console.log("SPECIAL REGV");
- //jQuery("form").prepend('<h3><?php echo ($type) ?></h3><br>');
- jQuery("p:contains('Brugernavn')").hide();
- jQuery("#user_email").attr("tabindex","24")
- jQuery("#r_navn").attr("tabindex","25")
- jQuery("#r_membership").attr("tabindex","26")
- jQuery("#wp-submit").attr("tabindex","27")
- var t = (jQuery('#login_error').html())+"";
- var a = t.split("\n");
- if(a.length && a[0].indexOf('brugernavn')>-1){
- a.shift();
- jQuery('#login_error').html(a.join("\n"));
- }
- jQuery("#user_login").hide();
- jQuery('label[for="user_login"]').hide();
- jQuery('#wp-submit').click(function(){
- console.log("SEND");
- jQuery('#user_login').val(jQuery('#user_email').val());
- });
- }
- });
- </script>
- <?php
- }
- ?>
- <?php
- }
- function plugin_form() {
- $type = isset($_GET['type']) ? $_GET['type'] : 'default';
- $html = '
- <div width="100%">
- <input type="hidden" name="r_proselect" id="r_proselect" value="' . $type . '">
- <p>
- <label style="display: block; margin-bottom: 5px;">' . __('Navn', 'Navn') . '
- <input type="text" name="r_navn" id="r_navn" class="input nnl" value="' . (isset($_POST['r_navn']) ? $_POST['r_navn'] : "") . '" size="20" tabindex="25" />
- </label>
- </p>
- <input type="hidden" name="r_membership" id="r_membership" value="' . $type . '">
- </div>
- ';
- echo $html;
- }
- function Option($pre) {
- update_option($pre . '_support_splash', $_POST[$pre . '_support_splash']);
- update_option($pre . '_support_splash_rp', $_POST[$pre . '_support_splash_rp']);
- update_option($pre . '_support_splash_welcome', $_POST[$pre . '_support_splash_welcome']);
- update_option($pre . '_support_splash_resetpass', $_POST[$pre . '_support_splash_resetpass']);
- update_option($pre . '_support_splash_register', $_POST[$pre . '_support_splash_register']);
- update_option($pre . '_support_error', $_POST[$pre . '_support_error']);
- update_option($pre . '_background_image', $_POST[$pre . '_background_image']);
- update_option($pre . '_image', $_POST[$pre . '_image']);
- update_option($pre . '_styles', $_POST[$pre . '_styles']);
- }
- function admin_line($pre) {
- ?>
- <hr>
- <div >
- <div style="width: 300px; height: 100px; overflow: hidden">
- <img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
- </div>
- <?php echo (__("Login image:", "dagsopt")) ?><br>
- <input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
- <button class="button uploadbutton">Upload</button>
- </div>
- <div >
- <div style="width: 300px; height: 100px; overflow: hidden">
- <img height="100" src="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>">
- </div>
- <?php echo (__("Login background image:", "dagsopt")) ?><br>
- <input type="text" name="<?php echo ($pre . '_background_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_background_image"))); ?>" />
- <button class="button uploadbutton">Upload</button>
- </div>
- <hr>
- <?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>
- <hr>
- <?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>
- <hr>
- <?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>
- <hr>
- <?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>
- <hr>
- <?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>
- <hr>
- <?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>
- <hr>
- <?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>
- <?php
- }
- }
- global $plug_login;
- $plug_login = new plug_login($this);
- $this->dagsopt['plug_login'] = $plug_login;
- }
|