-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.php
163 lines (128 loc) · 4.44 KB
/
theme.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
<?php
namespace Habari;
if( !defined( 'HABARI_PATH' ) ) {
die('No direct access');
}
class Dopetrope extends Theme
{
const D_CACHE = '3600'; // cache for an hour
const P_CACHE = '86400'; // cache for a day
public function action_theme_activated() {}
public function action_init_theme() {
Format::apply( 'autop', 'comment_content_out' );
Format::apply_with_hook_params( 'more', 'post_excerpt', '', 100, 0 );
}
public function action_add_template_vars() {}
public function action_template_header() {}
public function dribbble() {
if ( Cache::has( array('DPT', 'dribbble' ) ) ) {
$return = Cache::get( array('DPT', 'dribbble' ) );
} else {
$url = "http://api.dribbble.com/players/chrisjdavis/shots?per_page=3";
$r = new RemoteRequest( $url );
$r->execute();
$shots = json_decode($r->get_response_body());
$return = $shots->shots;
Cache::set( array('DPT', 'dribbble' ), $return, self::D_CACHE, true );
}
return $return;
}
public function newest() {
if ( Cache::has( array('DPT', 'newest' ) ) ) {
$content = Cache::get( array('DPT', 'newest' ) );
} else {
$content = Post::get( array('status' => Post::status('published'), 'orderby' => 'pubdate DESC', 'content_type' => Post:: type('entry')) );
Cache::set( array('DPT', 'newest' ), $content, self::P_CACHE, true );
}
return $content;
}
public function latest($ignore) {
if ( Cache::has( array('DPT', 'latest' ) ) ) {
$content = Cache::get( array('DPT', 'latest' ) );
} else {
$content = Posts::get( array('status' => Post::status('published'), 'orderby' => 'pubdate DESC', 'limit' => 2, 'not:id' => $ignore, 'content_type' => Post:: type('entry')) );
Cache::set( array('DPT', 'latest' ), $content, self::P_CACHE, true );
}
return $content;
}
public function recent($ignore) {
if( Cache::has( array('DPT', 'recent') ) ) {
$content = Cache::get( array('DPT', 'recent' ) );
} else {
$content = Posts::get( array('status' => Post::status('published'), 'orderby' => 'pubdate DESC', 'limit' => 4, 'not:id' => $ignore, 'content_type' => Post:: type('entry')) );
Cache::set( array('DPT', 'recent' ), $content, self::P_CACHE, true );
}
return $content;
}
public function t_and_l( $terms, $between = ', ', $between_last = null, $sort_alphabetical = false, $linked = true ) {
$array = array();
if ( !$terms instanceof Terms ) {
$terms = new Terms( $terms );
}
foreach ( $terms as $term ) {
$array[$term->term] = $term->term_display;
}
if ( $sort_alphabetical ) {
ksort( $array );
}
if ( $between_last === null ) {
// @locale The default string used between the last two items in a series of tags (one, two, three *and* four).
$between_last = _t( ' and ' );
}
if( $linked == true ) {
$fn = function($a, $b) {
return "<span class=\"tag\"><a href=\"" . URL::get("display_entries_by_tag", array( "tag" => $b) ) . "\" rel=\"tag\">" . $a . "</a></span>";
};
} else {
$fn = function($a, $b) {
return "<span class=\"tag\">" . $a . "</span>";
};
}
$array = array_map( $fn, $array, array_keys( $array ) );
$last = array_pop( $array );
$out = implode( $between, $array );
$out .= ( $out == '' ) ? $last : $between_last . $last;
return $out;
}
public function parse( $terms, $between = ', ', $between_last = null, $sort_alphabetical = false, $linked = true ) {
$array = array();
if ( !$terms instanceof Terms ) {
$terms = new Terms( $terms );
}
foreach ( $terms as $term ) {
$array[$term->term] = $term->term_display;
}
if ( $sort_alphabetical ) {
ksort( $array );
}
if ( $between_last === null ) {
// @locale The default string used between the last two items in a series of tags (one, two, three *and* four).
$between_last = _t( ',' );
}
if( $linked == true ) {
$fn = function($a, $b) {
return $a;
};
} else {
$fn = function($a, $b) {
return $a;
};
}
$array = array_map( $fn, $array, array_keys( $array ) );
$last = array_pop( $array );
$out = implode( $between, $array );
$out .= ( $out == '' ) ? $last : $between_last . $last;
return $out;
}
public function exerptor($string, $limit, $break = ".", $pad = "...") {
if(strlen($string) <= $limit) return $string;
if( false !== ($breakpoint = strpos($string, $break, $limit)) ) {
if( $breakpoint < strlen($string) - 1 ) {
$string = strip_tags( $string );
$string = substr( $string, 0, $breakpoint ) . $pad;
}
}
return $string;
}
}
?>