forked from owncloud-archive/owncloud.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
203 lines (189 loc) · 6.07 KB
/
functions.php
File metadata and controls
203 lines (189 loc) · 6.07 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
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
<?php
/* Disable the Admin Bar. */
add_filter( 'show_admin_bar', '__return_false' );
add_action( 'init', 'register_my_menus' );
// register the menus
function register_my_menus() {
register_nav_menus(
array(
'dev-nav' => __( 'Dev Centre Nav' ),
'support-nav' => __( 'Support Centre Nav' ),
'header-nav' => __( 'Main Page Nav' )
)
);
}
// register the sidebar shortcode
add_shortcode( 'sidebarsc', 'sidebar_sc' );
// register shortcode functions to output widgets
function sidebar_sc( $atts ) {
extract( shortcode_atts( array(
'sidebar' => 'Dev widgets 1',
), $atts ) );
ob_start();
dynamic_sidebar($sidebar);
$html = '<div class="row">';
$html .= ob_get_contents();
$html .= '</div>';
ob_end_clean();
return $html;
}
// register sidebars
add_action( 'init', 'ilc_register_sidebars');
function ilc_register_sidebars(){
register_sidebar(array(
'name' => 'Dev large 1',
'description' => 'one large widget',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div class="span9">',
'after_widget' => '</div>'
));
register_sidebar(array(
'name' => 'Dev large 2',
'description' => 'one large widget',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div class="span9">',
'after_widget' => '</div>'
));
register_sidebar(array(
'name' => 'Dev widgets 1',
'description' => 'Two widgets',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div class="span6">',
'after_widget' => '</div>'
));
register_sidebar(array(
'name' => 'Support Top Widgets',
'description' => 'two widgets',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div class="span6">',
'after_widget' => '</div>'
));
register_sidebar(array(
'name' => 'Support Bottom Widgets',
'description' => 'two widgets',
'before_title' => '<h2>',
'after_title' => '</h2>',
'before_widget' => '<div class="span6">',
'after_widget' => '</div>'
));
}
// TODO FIXME
// @brief Checks if a post has a gven ancestor
// @param ancestor the ancestor to look for
// @param postid the current post id
// @return boolean
function has_ancestor($ancestortitle,$postid){
$ancestors = get_post_ancestors($postid);
$has_ancestor = false;
foreach($ancestors as $ancestor)
{
$title = strtolower(get_the_title($ancestor));
if($title==strtolower($ancestortitle))
{
$has_ancestor = true;
}
}
return $has_ancestor;
}
function neat_trim($str, $n, $delim='...') {
$len = strlen($str);
if ($len > $n) {
preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches);
return rtrim($matches[1]) . $delim;
}
else {
return $str;
}
}
//allow shortocodes in widgets
add_filter('widget_text', 'do_shortcode');
// include widgets
include('recentdocswidget.php');
include('recentblogswidget.php');
// DATE FUNCTIONS
// convert a date into a string that tells how long ago that date was.... eg: 2 days ago, 3 minutes ago.
function ago($d) {
$c = getdate();
$p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds');
$display = array('year', 'month', 'day', 'hour', 'minute', 'second');
$factor = array(0, 12, 30, 24, 60, 60);
$d = datetoarr($d);
for ($w = 0; $w < 6; $w++) {
if ($w > 0) {
$c[$p[$w]] += $c[$p[$w-1]] * $factor[$w];
$d[$p[$w]] += $d[$p[$w-1]] * $factor[$w];
}
if ($c[$p[$w]] - $d[$p[$w]] > 1) {
return ($c[$p[$w]] - $d[$p[$w]]).' '.$display[$w].'s ago';
}
}
return '';
}
// you can replace this if need be. This converts my dates returned from a mysql date string into
// an array object similar to that returned by getdate().
function datetoarr($d) {
preg_match("/([0-9]{4})(\\-)([0-9]{2})(\\-)([0-9]{2}) ([0-9]{2})(\\:)([0-9]{2})(\\:)([0-9]{2})/", $d, $matches);
return array(
'seconds' => $matches[10],
'minutes' => $matches[8],
'hours' => $matches[6],
'mday' => $matches[5],
'mon' => $matches[3],
'year' => $matches[1],
);
}
// https://gist.github.com/1189639
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 512 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param boole $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
* @source http://gravatar.com/site/implement/images/php/
*/
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
// Displays the posts tags
function get_the_tags_html($postid){
// Define the colours
$tagcolours = array(
'release'=>'important'
);
$tags = get_the_tags($postid);
if($tags){
$output = '';
foreach( $tags as $tag ){
if(strtolower($tag->name)!='owncloud'){
$colour = array_key_exists($tag->name,$tagcolours) ? $tagcolours[$tag->name] : '';
$output .= '<a href="'.get_tag_link($tag).'"><span class="label '.$colour.'">'.$tag->name.'</span></a>';
}
}
return $output;
} else {
return false;
}
}
?>