-
Notifications
You must be signed in to change notification settings - Fork 4
/
eexcess-functionality.php
247 lines (224 loc) · 11.2 KB
/
eexcess-functionality.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* Plugin Name: EEXCESS
* Plugin URI: https://github.com/EEXCESS/eexcess
* Description: Gives you the ability to enrich your blog with well-selected and high quality content
* Version: 0.6.1
* Author: Nils Witt
* Author URI: https://github.com/n-witt
* License: Apache 2.0
*/
/* Copyright 2014 University of Passau
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
?>
<?php
add_action( 'admin_init', 'init_eexcess_plugin' );
function init_eexcess_plugin() {
global $pagenow;
// Load the scripts for the post creation / editing page
if($pagenow == 'post-new.php' || $pagenow == 'post.php') {
$eventsScripts = array(
'jquery-ui-sortable',
'wp-backbone'
);
wp_deregister_script( $eventsScripts );
wp_enqueue_script( 'requirejs', plugins_url( '/js/lib/require.js', __FILE__ ));
// make the plugins url available in scripts
wp_localize_script( 'requirejs', 'plugin_url', plugins_url( '/', __FILE__ ) );
// read all citeproc style files and make them available on the client side
$citeprocStylesPath = plugin_dir_path(__FILE__) . 'js/lib/citationBuilder/citationStyles';
if ($handle = opendir($citeprocStylesPath)) {
$citationStyles = array();
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$entry = str_replace(".csl", "", $entry);
$citationStyles[] = $entry;
}
}
closedir($handle);
wp_localize_script( 'requirejs', 'citationStyles', $citationStyles );
}
// init styles
wp_enqueue_style( 'eexcess-styles', plugins_url( '/styles/eexcess-styles.css', __FILE__ ) );
wp_enqueue_style( 'onOffSwitch', plugins_url( '/styles/toggle-switch.css', __FILE__ ) );
wp_enqueue_style( 'bootstrap', plugins_url( '/styles/bootstrap.css', __FILE__ ) );
wp_enqueue_style( 'bootstrap-theme', plugins_url( '/styles/bootstrap-theme.css', __FILE__ ) );
wp_enqueue_style( 'jquery-ui', plugins_url( '/styles/jquery-ui.css', __FILE__ ) );
}
}
// This injects the html-tag that configure reuireJS
add_filter( 'script_loader_tag', 'my_script_loader_tag', 10, 3 );
function my_script_loader_tag( $tag, $handle, $src ) {
if ( 'requirejs' == $handle ) {
$app = plugins_url( '/js/requireJSConfig.js', __FILE__ );
$tag = "<script data-main='{$app}' src='{$src}'></script>\n";
}
return $tag;
}
/**
* Adds a box to the main column on the Post edit screen.
*/
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );
function myplugin_add_meta_box() {
// @see http://codex.wordpress.org/Function_Reference/add_meta_box
add_meta_box(
'eexcess_container', // id
'EEXCESS', // title
'eexcess_meta_box_callback', // callback
'post' // post_type
);
}
/**
* Prints the box content.
*
* @param WP_Post $post The object for the current post/page.
*/
function eexcess_meta_box_callback( $post ) { ?>
<?php // List template ?>
<!-- Visualization thickbox-->
<?php add_thickbox(); ?>
<div id="visualizationThickbox" style="display:none;">
<!-- thickbox content-->
<!--<iframe id="dashboard" src=<?php echo plugin_dir_url(__FILE__) . 'js/lib/visualization-widgets/Dashboard/index.html';?> style="position:relative;width:1000px;height:625px;"></iframe> -->
<iframe id="dashboard" src="https://eexcess.github.io/visualization-widgets-files/Dashboard/index.html" style="position:relative;width:1000px;height:625px;"></iframe>
<!-- /thickbox content-->
</div>
<!-- / Visualization thickbox-->
<div id="resultListContainer">
<iframe id="resultList" src=<?php echo plugin_dir_url(__FILE__) . 'js/lib/visualization-widgets/SearchResultList/index.html';?> style="position:relative;width:1000px;height:625px;"></iframe>
</div>
<div id="privacySettingsForm">
<hr>
<!-- privacy settings thickbox-->
<?php add_thickbox(); ?>
<div id="privacyThickbox" style="display:none;">
<div id="privacyPanel" class="panel panel-primary">
<div class="panel-heading" style="background-color: white;">
<h3 class="panel-title"> User Profile
</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-12">
<div class="panel-body">
<div class="content">
<form class="form-income">
<div class="form-group">
<label for="" class="control-label">Address</label>
<div class="row">
<div class="col-lg-6">
<input data-eexcess-profile-field="address.city" type="text" class="form-control" placeholder="City">
</div>
<div class="col-lg-6">
<input data-eexcess-profile-field="address.country" type="text" class="form-control" placeholder="Country">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<div class="col-lg-3">
<label for="" class="control-label">Gender</label>
</div>
<div class="col-lg-6">
<label for="" class="control-label">Age</label>
</div>
<div class="col-lg-3">
<label for="" class="control-label">Allow Logging</label>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<select data-eexcess-profile-field="gender" class="form-control">
<option value="notSpecified">Not Specified</option>
<option value="other">Other</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="col-lg-6">
<div class="btn-group" data-eexcess-profile-field="age" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" value="0" /> Child
</label>
<label class="btn btn-default">
<input type="radio" value="1" /> Young Adult
</label>
<label class="btn btn-default">
<input type="radio" value="2" /> Adult
</label>
</div>
</div>
<div class="col-lg-3">
<input id="loggingEnabled" data-eexcess-profile-field="logging" class="cmn-toggle cmn-toggle-round" type="checkbox" checked>
<label for="loggingEnabled"></label>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Atif: User profile panel ends here-->
</div>
<a href="#TB_inline?width=600&height=550&inlineId=privacyThickbox" title="Profile Settings" class="thickbox">
<input id="privacySettingsBtn" style="width: 100px;" name="privacySettings" class="button button-small" value="Profile Settings">
</a>
</div>
<!-- /privacy settings thickbox-->
<?php }
// Hook for the WYSIWYG editor
add_filter( 'tiny_mce_before_init', 'tiny_mce_before_init' );
// Setting up the onKeyUp event for the WYSIWYG editor
function tiny_mce_before_init( $initArray ) {
$initArray['setup'] = "function(ed) {
ed.onKeyDown.add(function(ed, e) {
require(['recommendationEventsHelper'], function(helper){
if(helper.assessKeystroke(e)){
helper.getTextAndRecommend();
}
});
})
}";
return $initArray;
}
//adding a button to tinyMCE
add_action( 'admin_head', 'EEXCESS_add_tinymce' );
function EEXCESS_add_tinymce() {
global $typenow;
// only on Post Type: post and page
if( ! in_array( $typenow, array( 'post', 'page' ) ) )
return ;
// registers the method that registers our javascript file that implements our button
add_filter( 'mce_external_plugins', 'EEXCESS_add_tinymce_plugin' );
// registers the method that registers our button
add_filter( 'mce_buttons', 'EEXCESS_add_tinymce_button' );
}
// inlcude the js for tinymce
function EEXCESS_add_tinymce_plugin( $plugin_array ) {
$plugin_array['EEXCESS_get_recommendations'] = plugins_url( 'js/tinyMCE_plugins/tinyMCE_Get_Recommendations_Button.js', __FILE__ );
$plugin_array['EEXCESS_delete_citations'] = plugins_url( 'js/tinyMCE_plugins/tinyMCE_Delete_Citations_Button.js', __FILE__ );
$plugin_array['EEXCESS_vis_dashboard'] = plugins_url( 'js/tinyMCE_plugins/tinyMCE_Vis_Dashboard.js', __FILE__ );
$plugin_array['EEXCESS_citation_styles'] = plugins_url( 'js/tinyMCE_plugins/tinyMCE_Citation_Styles.js', __FILE__ );
return $plugin_array;
}
// Add the button key for address via JS
function EEXCESS_add_tinymce_button( $buttons ) {
array_push( $buttons, 'Get_Recommendations_Button');
array_push( $buttons, 'Delete_Citations_Button');
array_push( $buttons, 'Vis_Dashboard');
array_push( $buttons, 'Citation_Styles');
return $buttons;
}
?>