-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathfunctions.php
More file actions
136 lines (109 loc) · 3.72 KB
/
functions.php
File metadata and controls
136 lines (109 loc) · 3.72 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
define('PUMA_VERSION', wp_get_theme()->get('Version'));
define('PUMA_SETTING_KEY', 'puma_setting');
define('PUMA_POST_LIKE_KEY', '_postlike');
define('PUMA_POST_VIEW_KEY', 'views');
define('PUMA_ARCHIVE_VIEW_KEY', 'views');
load_theme_textdomain('Puma', get_template_directory() . '/languages');
require get_template_directory() . '/inc/setting.php';
/**
* Functional Package additions.
*/
require get_template_directory() . '/inc/pack.php';
/**
* Theme update additions.
*/
require get_template_directory() . '/inc/update.php';
/**
* Theme setting additions.
*/
require get_template_directory() . '/inc/base.php';
require get_template_directory() . '/inc/comment.php';
function puma_get_background_image($post_id, $width = null, $height = null)
{
global $pumaSetting;
if (has_post_thumbnail($post_id)) {
$timthumb_src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full');
$output = $timthumb_src[0];
} elseif (get_post_meta($post_id, '_banner', true)) {
$output = get_post_meta($post_id, '_banner', true);
} else {
$content = get_post_field('post_content', $post_id);
$defaltthubmnail = $pumaSetting->get_setting('default_thumbnail');
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if ($n > 0) {
$output = $strResult[1][0];
} else {
$output = $defaltthubmnail;
}
}
if ($height && $width) {
if ($pumaSetting->get_setting('upyun')) {
$output = $output . "!/both/{$width}x{$height}";
}
if ($pumaSetting->get_setting('oss')) {
$output = $output . "?x-oss-process=image/crop,w_{$width},h_{$height}";
}
if ($pumaSetting->get_setting('qiniu')) {
$output = $output . "?imageView2/1/w/{$width}/h/{$height}";
}
}
return $output;
}
function puma_is_has_image($post_id)
{
static $has_image;
if (has_post_thumbnail($post_id)) {
$has_image = true;
} elseif (get_post_meta($post_id, '_banner', true)) {
$has_image = true;
} else {
$content = get_post_field('post_content', $post_id);
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if ($n > 0) {
$has_image = true;
} else {
$has_image = false;
}
}
return $has_image;
}
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `<html>` element when JavaScript is detected.
*
* @since Puma 2.1.0
*/
function puma_javascript_detection()
{
echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}
add_action('wp_head', 'puma_javascript_detection', 0);
/**
* Recover comment fields since WordPress 4.4
*
* @since Puma 2.0.4
*/
function recover_comment_fields($comment_fields)
{
$comment = array_shift($comment_fields);
$comment_fields = array_merge($comment_fields, array('comment' => $comment));
return $comment_fields;
}
add_filter('comment_form_fields', 'recover_comment_fields');
/**
* Hack default search form.
*
* @since Puma 3.0.1
*/
function puma_get_search_form()
{
$form = '<form method="get" class="search-form" action="' . esc_url(home_url('/')) . '">
<input type="search" class="search-field" placeholder="' . __('Enter to search..', 'Puma') . '" value="' . get_search_query() . '" name="s" />
</form>';
return $form;
}
add_filter('get_search_form', 'puma_get_search_form');