-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLitteraturnettAuthorPageController.class.php
207 lines (184 loc) · 7.81 KB
/
LitteraturnettAuthorPageController.class.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
<?php
/*
This class contains methods for displaying the content of the Author pages. It can be subclassed, if you do,
override the filter 'litteraturnett_author_page_controller_class' to return your class name.
*/
class LitteraturnettAuthorPageController {
// Shared instance so removing and modifying actions will be simpler. IOK 2019-11-21
protected static $instance = null;
// This class should only get instantiated with this method. IOK 2019-10-14
public static function instance() {
if (!static::$instance) static::$instance = new static();
return static::$instance;
}
public function single_author_content() {
global $post;
$wiki = Litteraturnett::get_wikipedia();
$wikiUrl = $wiki."?curid=".get_post_meta($post->ID, "page_id",true);
$localContent = get_field('localcontent');
if(!empty($post->post_content)):
?>
<div class="author-page-content">
<?php the_content(); ?>
</div>
<div class="post-detail-author">
<?php echo __("This page uses material from", 'wl-wiki-import').' <a href="'.$wikiUrl.'" target="_blank">'.__("Wikipedia").'</a>, ' . __("licensed under", 'wl-wiki-import') . ' <a href="http://creativecommons.org/licenses/by-sa/3.0/" target="_blank"> CC-BY-SA </a>' ; ?>
</div>
<?php
endif;
if (!empty($localContent)):
?>
<div class="author-page-content local-content"><?php echo $localContent; ?></div><br>
<?php
endif;
}
public function before_single_author () {
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<?php
}
public function after_single_author() {
?>
</div>
</article>
<?php
}
// Wrapper for the main content element.
public function before_main_content () {
?>
<main class="content author-content <?php do_action('litteraturnett_author_main_classes'); ?>"
<?php do_action('litteraturnett_author_main_attributes'); ?>
>
<?php
}
public function after_main_content() {
?>
</main>
<?php
}
public function before_single_author_summary() {
?>
<div class="author-page-top <?php echo get_the_post_thumbnail() ? "has-image" : "" ?>">
<?php
}
public function after_single_author_summary() {
?>
</div>
<?php
}
// This encapsulates the main part of the top bit, the author summary
public function before_author_page_info() {
?>
<div class="author-page-info">
<?php
}
public function after_author_page_info() {
?>
</div>
<?php
}
public function author_page_image () {
$wikiapi = Litteraturnett::get_wikipedia_api();
if(get_the_post_thumbnail()):?>
<div class="author-page-image">
<?php if ( has_post_thumbnail() ) {
$thumbz = get_the_post_thumbnail();
echo $thumbz;
echo '<span class="img-creator"></span><span class="ic-expand"></span>';
$image_name = "";
$file_title = get_post(( get_post_thumbnail_id()) )->post_title;
$file_name = basename ( get_attached_file( get_post_thumbnail_id()) );
$image_name = $file_title.".".end(explode('.', $file_name)); //This is for get the image file name + extension with special character
// This depends on local popup code entirely IOK FIXME
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
if ( ! empty( $large_image_url[0] ) ) {
printf( '<div id="authorImageInfo" class="image-info-popup white-popup mfp-with-anim mfp-hide" data-image-name="%1$s" data-wiki-url="%2$s">
<img src="%3$s" alt="%4$s"/>
<div class="image-info-content" id="imageInfoContent"></div>
</div>',
$image_name,
$wikiapi,
esc_url( $large_image_url[0] ),
get_the_title()
);
}
}
?>
</div>
<?php endif;
}
public function author_page_detail () {
$infoBox = html_entity_decode(get_field('infobox'));
$infoBox = preg_replace_callback('/u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $infoBox);
?>
<div class="author-page-detail">
<h1><?php echo get_the_title(); ?></h1>
<?php echo $infoBox; ?>
</div>
<?php
}
public function author_page_navigation () {
$sections = html_entity_decode(get_field('sections'));
$sections = preg_replace_callback('/u([0-9a-fA-F]{4})/', function ($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, $sections);
?>
<div class="author-page-navigation">
<?php echo $sections; ?>
<a href="#authorCommentForm"><?php echo __("Do you have information to add?", 'wl-wiki-import') ?></a>
</div>
<?php
}
public function author_sidebar() {
get_sidebar();
}
public function author_taglist() {
global $post;
$tagList = wp_get_post_tags($post->ID);
$tagListHtml = "";
$containerclass = esc_attr(apply_filters('litteraturnett_author_container_class','entry-content'));
foreach ($tagList as $tag) {
if($tag->description!=""){
$tagListHtml .= '<a href="/tag/'.$tag->slug.'/" rel="tag" data-tag="'.$tag->name.'">'.$tag->description.'</a> | ';
}
}
if($tagListHtml!=""){
$tagListHtml = substr($tagListHtml, 0, -3); // remove the last seperator
echo "<div class='entry'><div class='$containerclass author-page-tag'><h2>".__('Tags','wl-wiki-import')."</h2><div class='author-page-tag-content'>$tagListHtml</div></div></div>";
}
}
public function author_related_book () {
global $post;
if (!$post) return;
$authorName = '';
$namedata = '';
$disableBookSection = get_field('disable_book_section',$post->ID);
if (!$disableBookSection) {
$firstName = get_field('book_first_name',$post->ID);
$lastName = get_field('book_last_name',$post->ID);
$authorName = esc_attr($lastName." ".$firstName); // PM ask for searching by Lastname Firstname . See B-10341
$namedata = " data-author='$authorName' ";
}
$containerclass = esc_attr(apply_filters('litteraturnett_author_container_class','entry-content'));
?>
<div class="entry">
<div class="<?php echo $containerclass;?>">
<div id="relatedBook" class='author-page-related-book litteraturnett-book-slider wl-bookshelf-slider' <?php echo $namedata; ?>></div>
</div>
</div>
<?php
}
public function author_comments() {
$containerclass = esc_attr(apply_filters('litteraturnett_author_container_class','entry-content'));
?>
<div class="<?php echo $containerclass;?>">
<div id="authorCommentForm" class="author-conmment-form">
<?php comments_template(); ?>
</div>
</div>
<?php
}
}