-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpentagon.php
674 lines (370 loc) · 16.2 KB
/
pentagon.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
<?php
/*
Plugin Name: Pentagon Rating Tool
Plugin URI: http://theginisin.com/projectpentagon
Description: A plugin which allows posts to be rated in 5 categories on a scale of 1-3
Version: 0.5
Author: Aaron Knoll
Author URI: http://aaronknoll.com
License: GPL
*/
//initial version is a proof of concept. Pending interest I could likely
// make a lot of these things much more elegant. But for now, this is
// is a personal project for my gin blog.
/* Runs when plugin is activated */
register_activation_hook(__FILE__,'projectpentagon_install');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, 'projectpentagon_remove' );
function projectpentagon_install() {
/* Creates new database field */
add_option("projectpentagon_title", 'fgfhgThis it the Title of my Pentagram', '', 'yes');
add_option("projectpentagon_name1", 'Name a', '', 'yes');
add_option("projectpentagon_name2", 'Name b', '', 'yes');
add_option("projectpentagon_name3", 'Name c', '', 'yes');
add_option("projectpentagon_name4", 'Name d', '', 'yes');
add_option("projectpentagon_name5", 'Name e', '', 'yes');
add_option("projectpentagon_color1", 'Blue', '', 'yes');
add_option("projectpentagon_color2", 'Red', '', 'yes');
add_option("projectpentagon_color3", 'Yellow', '', 'yes');
add_option("projectpentagon_color4", 'Green', '', 'yes');
add_option("projectpentagon_color5", 'Orange', '', 'yes');
add_option("projectpentagon_category", 'Category Name', '', 'yes');
add_option("projectpentagon-titleonpages", 'title for pages', '', 'yes');
//these could probably be created as an array? eventually
}
function projectpentagon_remove() {
/* Deletes the database field */
delete_option('projectpentagon_title');
delete_option('projectpentagon_name1');
delete_option('projectpentagon_name2');
delete_option('projectpentagon_name3');
delete_option('projectpentagon_name4');
delete_option('projectpentagon_name5');
delete_option('projectpentagon_color1');
delete_option('projectpentagon_color2');
delete_option('projectpentagon_color3');
delete_option('projectpentagon_color4');
delete_option('projectpentagon_color5');
delete_option('projectpentagon_category');
delete_option('projectpentagon-titleonpages');
}
if ( is_admin() ){
/* Call the html code */
/* puts the admin section for Project Pentagon on the pages */
add_action('admin_menu', 'projectpentagon_menu');
/* puts the options to add ratings on individual post pages */
add_action( 'add_meta_boxes', 'projectpentagon_custom_box' );
/* Do something with the data entered */
add_action( 'save_post', 'projectpentagon_save_postdata' );
function projectpentagon_custom_box() {
add_meta_box(
'myplugin_sectionid',
__( 'Pentagon Ratings', 'myplugin_textdomain' ),
'projectpentagon_ratingsperbottle',
'post','side','high'
);
add_meta_box(
'myplugin_sectionid2',
__( 'Pentagon Notes', 'myplugin_textdomain' ),
'projectpentagon_tastingnotes',
'post'
);
}
function projectpentagon_save_postdata($post_id) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )
return;
// Check permissions
if ( 'page' == $_POST['post_type'] )
{
if ( !current_user_can( 'edit_page', $post_id ) )
return;
}
else
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
//update the tasting notes
$outside_newvalue = $_POST['tasting-notes'];
update_post_meta($post_id, 'tasting-notes', $outside_newvalue);
// Do something with $mydata
// probably using add_post_meta(), update_post_meta(), or
// a custom table (see Further Reading section below)
for($hh=1;$hh<6;$hh++)
{
//do an update for each of the potential 5 fields....
$get_field_name = "myplugin_new_field" . $hh ."";
$create_variable_name = "pentagon-field-". $hh ."";
$create_name_of_field_to_update = "mydata" . $hh ."";
$newvalue = $_POST[$get_field_name];
//echo "$newvalue is returning ---". $newvalue ."<br />";//DEBUG
update_post_meta($post_id, $create_variable_name, $newvalue);
//echo "get field name is returning --- ". $get_field_name ."<br />";//DEBUG
//echo "create variable name name is returning --- ". $create_variable_name ."<br />";//DEBUG
//echo "$create_name_of_field_to_update is returning --- ". $create_name_of_field_to_update ."<br />";//DEBUG
}
//echo "$mydata is mydata....";//debug
}
// adds a box to the mainbox for tasting/rating notes.
function projectpentagon_tastingnotes() {
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$post_idinhere = $_GET['post']; //GET THE ID OUTSIDE OF THE LOOP
$get_field_name = get_option('projectpentagon-titleonpages');
$meta_value_field = get_post_meta($post_idinhere, 'tasting-notes', true);
if($meta_value_field1)
{
//echo "we're at debut point a";//debug
$display1 = $meta_value_field1;
}
else
{
//echo "we're at debut point b". $meta_value_field1 ."";//debug
$display1 = "enter value here.";
}
// we're not using _e because its user input text we're retrieving.
// we'll assume that the user put it in the database in their preferred language
echo '<label for="'. $get_field_name .'">';
echo $get_field_name;
echo '</label> <br /> ';
echo '<textarea id="tasting-notes" name="tasting-notes" cols="60" rows="4" tabindex="30" style="width: 97%;">'. $meta_value_field .'</textarea>';
}
/* Adds a box to the main column on the Post and Page edit screens */
function projectpentagon_ratingsperbottle() {
// Use nonce for verification
wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );
$post_idinhere = $_GET['post']; //GET THE ID OUTSIDE OF THE LOOP
// OKAY, WE NEED TO SETUP 5 OF THESE ENTRY FIELDS. (5 OF EVERYTHING)
for($jj=1;$jj<6;$jj++)
{
$get_option_name = "projectpentagon_name" . $jj ."";
$get_field_name = "myplugin_new_field" . $jj ."";
$create_variable_name = "pentagon-field-". $jj ."";
// The actual fields for data entry
echo '<label for="'. $get_field_name .'">';
// see if there's a value already in the database:
$meta_value_field1 = get_post_meta($post_idinhere, $create_variable_name, true);
if($meta_value_field1)
{
//echo "we're at debut point a";//debug
$display1 = $meta_value_field1;
}
else
{
//echo "we're at debut point b". $meta_value_field1 ."";//debug
$display1 = "enter value here.";
}
// we're not using _e because its user input text we're retrieving.
// we'll assume that the user put it in the database in their preferred language
echo get_option($get_option_name);
echo '</label> <br /> ';
echo '<input type="text" id="'. $get_field_name .'" name="'. $get_field_name .'" value="'. $display1 .'" size="25" />
<br /><br />';
}
}
function projectpentagon_menu() {
//create new top-level menu
add_menu_page('Project Pentagon', 'Project Pentagon', 'administrator', __FILE__, 'projectpentagon_htmlpage',plugins_url('/images/icon.png', __FILE__));
//call register settings function
add_action( 'admin_init', 'projectpentagon_mysettings' );
}
}
function projectpentagon_mysettings() {
//register our settings
register_setting( 'baw-settings-group', 'projectpentagon_name1' );
register_setting( 'baw-settings-group', 'projectpentagon_name2' );
register_setting( 'baw-settings-group', 'projectpentagon_name3' );
register_setting( 'baw-settings-group', 'projectpentagon_name4' );
register_setting( 'baw-settings-group', 'projectpentagon_name5' );
register_setting( 'baw-settings-group', 'projectpentagon_color1' );
register_setting( 'baw-settings-group', 'projectpentagon_color2' );
register_setting( 'baw-settings-group', 'projectpentagon_color3' );
register_setting( 'baw-settings-group', 'projectpentagon_color4' );
register_setting( 'baw-settings-group', 'projectpentagon_color5' );
register_setting( 'baw-settings-group', 'projectpentagon_category' );
register_setting( 'baw-settings-group', 'projectpentagon-titleonpages' );
}
function projectpentagon_htmlpage() {
?>
<div class="wrap">
<h2>Project Pentagon</h2>
<form method="post" action="options.php">
<?php settings_fields( 'baw-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Name or slug of category for Pentagon display</th>
<td><input type="text" name="projectpentagon_category" value="<?php echo get_option('projectpentagon_category'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Section Title [will appear on post pages in selected category]</th>
<td><input type="text" name="projectpentagon-titleonpages" value="<?php echo get_option('projectpentagon-titleonpages'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Name 1</th>
<td><input type="text" name="projectpentagon_name1" value="<?php echo get_option('projectpentagon_name1'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Color 1</th>
<td><input type="text" name="projectpentagon_color1" value="<?php echo get_option('projectpentagon_color1'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Name 2</th>
<td><input type="text" name="projectpentagon_name2" value="<?php echo get_option('projectpentagon_name2'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Color 2</th>
<td><input type="text" name="projectpentagon_color2" value="<?php echo get_option('projectpentagon_color2'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Name 3</th>
<td><input type="text" name="projectpentagon_name3" value="<?php echo get_option('projectpentagon_name3'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Color 3</th>
<td><input type="text" name="projectpentagon_color3" value="<?php echo get_option('projectpentagon_color3'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Name 4</th>
<td><input type="text" name="projectpentagon_name4" value="<?php echo get_option('projectpentagon_name4'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Color 4</th>
<td><input type="text" name="projectpentagon_color4" value="<?php echo get_option('projectpentagon_color4'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Name 5</th>
<td><input type="text" name="projectpentagon_name5" value="<?php echo get_option('projectpentagon_name5'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Color 5</th>
<td><input type="text" name="projectpentagon_color5" value="<?php echo get_option('projectpentagon_color5'); ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
/*DISPLAY FILTERS AND HOOKS */
add_filter( 'the_content', 'pentagonseverywhere', 20 );
add_action( 'wp_head', 'pentagon_front_css');
function pentagonseverywhere( $content )
{
//what category does this belong in?
$nameofcat = get_option("projectpentagon_category");
$idinloop = get_the_ID();
if ( in_category( $nameofcat ))
{
$pentarray = array(); //instantiate the array we'll use in the display to fill in the variables.
//so now we need to get all of the information for this page
//we need the names
//we need the colors
for($oo=1;$oo<6;$oo++)
{
$name = "projectpentagon_name" . $oo ."";
$color = "projectpentagon_color" . $oo ."";
$pentarray[name][$oo] = get_option($name);
$pentarray[color][$oo]= get_option($color);
//field whose post meta we want
$postmetafield = "pentagon-field-". $oo ."";
$pentarray[rating][$oo] = get_post_meta($idinloop, $postmetafield, true);
//DEBUG
//echo get_option($name);
//echo get_option($color);
//echo get_post_meta($idinloop, $postmetafield, true);
}
// and we need the ratings for this specific post.
// Returns the content.
//The words are NOT rotated:
$titular_element = get_option("projectpentagon-titleonpages");
?>
<div id="arbitrary">
<svg id="svgelem" height="100" width="200" xmlns="http://www.w3.org/2000/svg">
<text x = "125" y = "85" fill = "black" font-size = "11"><?php echo $pentarray[name][1]; ?></text>
<text x = "85" y = "65" fill = "black" font-size = "11"><?php echo $pentarray[name][2]; ?></text>
<text x = "170" y = "65" fill = "black" font-size = "11"><?php echo $pentarray[name][5]; ?></text>
<text x = "165" y = "20" fill = "black" font-size = "11"><?php echo $pentarray[name][4]; ?></text>
<text x = "75" y = "20" fill = "black" font-size = "11"><?php echo $pentarray[name][3]; ?></text>
<?php
for ($i=1; $i < 6; $i++)
{
$rotation = (($i-1) * 72);
?>
<g transform="rotate(<?php echo $rotation; ?>,139.38,42.4)" >
<?php
//if it is 3 stars, color the outside.
if($pentarray[rating][$i] == 3)
{
?>
<polygon Stroke="#000" points="139.38,42.4 117.24,71.42 161.98,71.42" fill="#<?php echo $pentarray[color][$i]; ?>" />
<polygon Stroke="#000" points="139.38,42.4 125.04,61.6 154.18,61.6" fill="#<?php echo $pentarray[color][$i]; ?>" />
<polygon Stroke="#000" points="139.38,42.4 132.46,51.72, 147.76,51.72" fill="#<?php echo $pentarray[color][$i]; ?>" />
<?php
}
elseif($pentarray[rating][$i] == 2)
{
?>
<polygon Stroke="#000" points="139.38,42.4 117.24,71.42 161.98,71.42" fill="#FFFFFF" />
<polygon Stroke="#000" points="139.38,42.4 125.04,61.6 154.18,61.6" fill="#<?php echo $pentarray[color][$i]; ?>" />
<polygon Stroke="#000" points="139.38,42.4 132.46,51.72, 147.76,51.72" fill="#<?php echo $pentarray[color][$i]; ?>" />
<?php
}
elseif($pentarray[rating][$i] == 1)
{
?>
<polygon Stroke="#000" points="139.38,42.4 117.24,71.42 161.98,71.42" fill="#FFFFFF" />
<polygon Stroke="#000" points="139.38,42.4 125.04,61.6 154.18,61.6" fill="#FFFFFF" />
<polygon Stroke="#000" points="139.38,42.4 132.46,51.72, 147.76,51.72" fill="#<?php echo $pentarray[color][$i]; ?>" />
<?php
}
elseif($pentarray[rating][$i] == 0)
{
?>
<polygon Stroke="#000" points="139.38,42.4 117.24,71.42 161.98,71.42" fill="#FFFFFF" />
<?php
}
else
{
?>
<polygon Stroke="#000" points="139.38,42.4 117.24,71.42 161.98,71.42" fill="#FFFFFF" />
<polygon Stroke="#000" points="139.38,42.4 125.04,61.6 154.18,61.6" fill="#FFFFFF" />
<polygon Stroke="#000" points="139.38,42.4 132.46,51.72, 147.76,51.72" fill="#FFFFFF" />
<?php
}
?>
</g>
<?php
}
?>
</svg>
<div id="descripter" style="float: right; width: 60%;">
<h5 style="font-size: 115%;">
<?php echo $titular_element; ?>
</h5>
<p>
<?php $tastenotespub = get_post_meta($idinloop, 'tasting-notes', true);
echo $tastenotespub;?>
</p>
</div>
</div> <!-- end of arbitrary div class-->
<?php
return $content;
}
else
{
return $content;
}
}
function pentagon_front_css()
{
$css = '<!--[if lte IE 8]><link rel="stylesheet" href="'. get_home_url().'/wp-content/plugins/projectpentagon/ie8.css" type="text/css"><![endif]-->';
echo $css;
}
?>