-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteleport.php
128 lines (119 loc) · 5.05 KB
/
teleport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
Plugin Name: Teleport
Plugin URI: http://wordpress.org/extend/plugins/teleport/
Description: Teleport is all about getting around WordPress quickly! It uses keyboard shortcuts to get you to the most important places with just two taps. The intuitive teleporter is arranged exactly like the keyboard shortcuts - the e, d, s, a, and q keys make a 'u' shape around the w key. This matches the layout the teleporter. <strong>To get started:</strong> 1) Activate the plugin. 2) Go to your homepage. 3) Once the page has finished loading, press "w". This will activate the teleporter. To learn more about the teleporter, read the plugin documentation.
Version: 1.0.1
Author: Stephen Coley
Author URI: http://dknewmedia.com
Copyright 2012 DK New Media (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Register Teleports resources
function teleport_init() {
if (!is_admin()) {
wp_register_script('teleport_script', get_bloginfo('url') . "/wp-content/plugins/teleport/js/script.js", "jquery");
wp_register_script('teleport_effects', get_bloginfo('url') . "/wp-content/plugins/teleport/js/jquery.ui.effects.min.js", "jquery");
}
}
// Injects Teleporters resources into the header
// Determines if there's a front page
// Localize script.js to pass it some data and namespace it as Teleport
function teleport_head() {
if (!is_admin()) {
global $wp_query;
$front_id = 0;
echo "<link rel='stylesheet' href='" . get_bloginfo('url') . "/wp-content/plugins/teleport/css/style.css' />";
if(is_front_page()) {
$type = "page";
$front_id = get_option('page_on_front');
} else if(is_page()) {
$type = "page";
} else {
$type = "post";
}
wp_enqueue_script('jquery');
wp_enqueue_script('teleport_effects');
wp_enqueue_script('teleport_script');
wp_localize_script(
'teleport_script',
'Teleport',
array(
'ajaxurl' => admin_url('admin-ajax.php'),
'postid' => $wp_query->post->ID,
'type' => $type,
'front_id' => $front_id
)
);
}
}
// This ajax handler gets appended to the body tag.
// This puts the Teleport markup on the site.
// Links are formatted here as well.
function teleport_ajax() {
// Gather needed variables
$postid = $_POST['postid'];
$cururl = $_POST['cururl'];
$type = $_POST['type'];
$front_id = $_POST['front_id'];
// If no home page is set...
if($front_id == 0) {
// Edit posts
$edit = get_bloginfo('wpurl') . "/wp-admin/post.php?post=" . $postid . "&action=edit";
// If a home page is set
} else {
// Edit page
$edit = get_bloginfo('wpurl') . "/wp-admin/post.php?post=" . $front_id . "&action=edit";
}
$archive = get_bloginfo('wpurl') . "/wp-admin/edit.php?post_type=" . get_post_type($postid);
// If the user is logged in, show the full Teleporter
if(is_user_logged_in()) {
echo '</p><div id="teleport">
<div id="teleport_overlay"></div>
<div id="teleporter">
<div id="teleport_icon_teleporter" class="teleport_front teleport_face"></div>
<div id="teleport_dknewmedia" class="teleport_back teleport_face" data-url="http://dknewmedia.com"></div>
</div>
<div id="teleport_first" class="teleport_button">
<div id="teleport_icon_first" class="teleport_icon" data-url="' . get_bloginfo('wpurl') . '/wp-admin/options-general.php"></div>
</div>
<div id="teleport_second" class="teleport_button">
<div id="teleport_icon_second" class="teleport_icon" data-url="' . get_bloginfo('wpurl') . '/wp-admin/index.php"></div>
</div>
<div id="teleport_third" class="teleport_button">
<div id="teleport_icon_third" class="teleport_icon" data-url="' . $edit . '"></div>
</div>
<div id="teleport_fourth" class="teleport_button">
<div id="teleport_icon_fourth" class="teleport_icon" data-url="' . wp_logout_url($cururl) . '"></div>
</div>
<div id="teleport_fifth" class="teleport_button">
<div id="teleport_icon_fifth" class="teleport_icon" data-url="' . $archive . '"></div>
</div>
</div>';
// If the user isn't logged in, show the login Teleporter
} else {
echo '<div id="teleport" data-url="' . wp_login_url($cururl) . '">
<div id="teleport_overlay"></div>
<div id="teleporter">
<div id="teleport_icon_teleporter" class="teleport_login" data-url="' . wp_login_url($cururl) . '"></div>
</div>
</div>';
}
// Quit execution, required by WP
die();
}
// Hook it up
add_action('init', 'teleport_init');
add_action('wp_head', 'teleport_head');
add_action('wp_ajax_teleport', 'teleport_ajax');
add_action('wp_ajax_nopriv_teleport', 'teleport_ajax');
?>