-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmoa-footnotes.php
More file actions
113 lines (100 loc) · 2.42 KB
/
Copy pathcmoa-footnotes.php
File metadata and controls
113 lines (100 loc) · 2.42 KB
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
<?php
require_once 'vendor/autoload.php';
class CMOA_Footnotes {
private static $instance;
protected $notes;
/*
* getInstance
*
* Return singleton instance of class
*
* @type function
* @date 10/18/16
* @since 1.0.0
*
* @return instance of CMOA_Footnotes
*/
public static function getInstance() {
if (null === static::$instance) {
static::$instance = new static();
static::$instance->notes = [];
$options = array('extension' => '.html');
static::$instance->mustache = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(__DIR__.'/templates', $options)]);
}
return static::$instance;
}
/*
* getNotes
*
* Return array of footnotes
*
* @type function
* @date 10/18/16
* @since 1.0.0
*
* @return array
*/
public function getNotes() {
return $this->notes;
}
/*
* addNote
*
* Add content to array of footnotes
*
* @type function
* @date 10/18/16
* @since 1.0.0
*
* @param string Content to add to footnote
* @return null
*/
public function addNote($content) {
$count = count($this->notes);
$this->notes[] = ['id' => $count + 1, 'content' => $content];
}
}
/*
* footnote_filter
*
* Augments the_content() to output list of footnotes
*
* @type function
* @date 10/18/16
* @since 1.0.0
*
* @param array $content Content of post (automatically passed in by filter)
* @return string Formatted string based on template
*/
function footnote_filter($content) {
$foot = CMOA_Footnotes::getInstance();
$footnotes = $foot->getNotes();
if (is_singular() && count($footnotes) > 0) {
return $content.$foot->mustache->render('footnotes.html', array('footnotes' => $footnotes));
}
else {
return $content;
}
}
add_filter('the_content', 'footnote_filter');
/*
* ref_shortcode
*
* Creates footnotes with shortcode [ref]Footnote content[/ref]
*
* @type function
* @date 10/18/16
* @since 1.0.0
*
* @param array $atts Arguments for the shortcodes
* @param array $content Content between shortcode tags
* @return string Superscript link to footnote
*/
function ref_shortcode($atts, $content = "") {
$foot = CMOA_Footnotes::getInstance();
$foot->addNote($content);
$count = count($foot->getNotes());
return $foot->mustache->render('footnote-link.html', array('count' => $count, 'content' => $content));
}
add_shortcode('ref', 'ref_shortcode');
?>