PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/themes/K2/app/includes/info.php

https://github.com/flyingoctopus/net.flyingoctopus
PHP | 452 lines | 310 code | 99 blank | 43 comment | 61 complexity | af8332b0b7f302a46253992e6210d5d7 MD5 | raw file
  1. <?php
  2. // Prevent users from directly loading this file
  3. defined( 'K2_CURRENT' ) or die ( 'Error: This file can not be loaded directly.' );
  4. function k2info( $show = '' ) {
  5. echo get_k2info($show);
  6. }
  7. function get_k2info( $show = '' ) {
  8. $output = '';
  9. switch ( $show ) {
  10. case 'version' :
  11. $output = K2_CURRENT;
  12. break;
  13. case 'style_footer' :
  14. if ( K2_STYLES ) {
  15. $styleinfo = get_option('k2styleinfo');
  16. if ( !empty($styleinfo['footer']) )
  17. $output = stripslashes($styleinfo['footer']);
  18. }
  19. break;
  20. case 'styles_url' :
  21. if ( K2_STYLES )
  22. $output = K2Styles::get_styles_url();
  23. break;
  24. case 'headers_url' :
  25. $output = K2_HEADERS_URL . '/';
  26. break;
  27. }
  28. return $output;
  29. }
  30. function get_rolling_page_dates($query) {
  31. global $wpdb;
  32. $per_page = intval(get_query_var('posts_per_page'));
  33. $num_pages = $query->max_num_pages;
  34. $search = '/FROM\s+?(.*)\s+?LIMIT/siU';
  35. preg_match($search, $query->request, $matches);
  36. $post_dates = $wpdb->get_results("SELECT {$wpdb->posts}.post_date_gmt FROM {$matches[1]}");
  37. $page_dates = array();
  38. setlocale(LC_TIME, WPLANG . '.' . get_option('blog_charset') );
  39. for ($i = 0; $i < $num_pages; $i++) {
  40. $page_dates[] = strftime( __('%B, %Y', 'k2_domain'), abs(strtotime($post_dates[$i * $per_page]->post_date_gmt . ' GMT')) );
  41. }
  42. return $page_dates;
  43. }
  44. function output_javascript_url($file) {
  45. echo get_bloginfo('template_url') .'/'. $file;
  46. }
  47. // Generate JavaScript array from an array
  48. function output_javascript_array($array, $print = true) {
  49. $output = '[';
  50. if ( is_array($array) and !empty($array) ) {
  51. array_walk($array, 'js_format_array');
  52. $output .= implode(', ', $array);
  53. }
  54. $output .= ']';
  55. return $print ? print($output) : $output;
  56. }
  57. // Generate JavaScript hash from an associated array
  58. function output_javascript_hash($array, $print = true) {
  59. $output = '{';
  60. if ( is_array($array) and !empty($array) ) {
  61. array_walk($array, 'js_format_hash');
  62. $output .= implode(', ', $array);
  63. }
  64. $output .= '}';
  65. return $print ? print($output) : $output;
  66. }
  67. function js_format_array(&$item, $key) {
  68. $item = js_value($item);
  69. }
  70. function js_format_hash(&$item, $key) {
  71. $item = '"' . js_escape($key) . '": ' . js_value($item);
  72. }
  73. function js_value($value) {
  74. if ( is_string($value) )
  75. return '"' . js_escape($value) . '"';
  76. if ( is_bool($value) )
  77. return $value ? 'true' : 'false';
  78. if ( is_numeric($value) )
  79. return $value;
  80. if ( empty($value) )
  81. return '0';
  82. return '""';
  83. }
  84. function get_wp_version() {
  85. global $wp_version;
  86. $version = floatval($wp_version);
  87. // Old versions of WordPress-mu
  88. if ( strpos($wp_version, 'wordpress-mu') !== false ) {
  89. $version = $version + 1.0;
  90. }
  91. return $version;
  92. }
  93. // Semantic class functions from Sandbox (http://www.plaintxt.org/themes/sandbox/)
  94. // Generates semantic classes for BODY element
  95. function k2_body_class( $print = true ) {
  96. global $wp_query, $current_user, $blog_id;
  97. $c = array('wordpress', 'k2');
  98. // Applies the time- and date-based classes (below) to BODY element
  99. k2_date_classes(time(), $c);
  100. // Generic semantic classes for what type of content is displayed
  101. is_front_page() ? $c[] = 'home' : null;
  102. is_home() ? $c[] = 'blog' : null;
  103. is_archive() ? $c[] = 'archive' : null;
  104. is_date() ? $c[] = 'date' : null;
  105. is_search() ? $c[] = 'search' : null;
  106. is_paged() ? $c[] = 'paged' : null;
  107. is_attachment() ? $c[] = 'attachment' : null;
  108. (get_option('k2rollingarchives')=='1') ? $c[] = 'rollingarchives' : null;
  109. (get_option('k2animations')=='1') ? $c[] = 'animations' : null;
  110. is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character
  111. if ( is_attachment() ) {
  112. $postID = $wp_query->post->ID;
  113. the_post();
  114. // Adds 'single' class and class with the post ID
  115. $c[] = 'postid-' . $postID . ' s-slug-' . $wp_query->post->post_name;
  116. // Adds classes for the month, day, and hour when the post was published
  117. if ( isset($wp_query->post->post_date) )
  118. k2_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-');
  119. $the_mime = get_post_mime_type();
  120. $boring_stuff = array('application/', 'image/', 'text/', 'audio/', 'video/', 'music/');
  121. $c[] = 'attachment-' . str_replace($boring_stuff, '', $the_mime);
  122. // Adds author class for the post author
  123. $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author()));
  124. rewind_posts();
  125. }
  126. // Special classes for BODY element when a single post
  127. elseif ( is_single() ) {
  128. $postID = $wp_query->post->ID;
  129. the_post();
  130. // Adds 'single' class and class with the post ID
  131. $c[] = 'single postid-' . $postID . ' s-slug-' . $wp_query->post->post_name;
  132. // Adds classes for the month, day, and hour when the post was published
  133. if ( isset($wp_query->post->post_date) )
  134. k2_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-');
  135. // Categories
  136. foreach ( (array) get_the_category() as $cat ) {
  137. if ( empty($cat->slug ) )
  138. continue;
  139. $c[] = 's-category-' . $cat->slug;
  140. }
  141. // Tags
  142. foreach ( (array) get_the_tags() as $tag ) {
  143. if ( empty($tag->slug ) )
  144. continue;
  145. $c[] = 's-tag-' . $tag->slug;
  146. }
  147. // Adds author class for the post author
  148. $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author()));
  149. if ( get_post_custom_values('sidebarless') ) {
  150. $c[] = 'sidebars-none';
  151. }
  152. if ( get_post_custom_values('hidesidebar1') ) {
  153. $c[] = 'hidesidebar-1';
  154. }
  155. if ( get_post_custom_values('hidesidebar2') ) {
  156. $c[] = 'hidesidebar-2';
  157. }
  158. rewind_posts();
  159. }
  160. // Author name classes for BODY on author archives
  161. else if ( is_author() ) {
  162. $author = $wp_query->get_queried_object();
  163. $c[] = 'author';
  164. $c[] = 'author-' . $author->user_nicename;
  165. }
  166. // Category name classes for BODY on category archvies
  167. else if ( is_category() ) {
  168. $cat = $wp_query->get_queried_object();
  169. $c[] = 'category';
  170. $c[] = 'category-' . $cat->category_nicename;
  171. }
  172. // Tag name classes for BODY on tag archives
  173. else if ( is_tag() ) {
  174. $tag = $wp_query->get_queried_object();
  175. $c[] = 'tag';
  176. $c[] = 'tag-' . $tag->slug;
  177. }
  178. // Page author for BODY on 'pages'
  179. else if ( is_page() ) {
  180. $pageID = $wp_query->post->ID;
  181. $page_children = wp_list_pages("child_of=$pageID&echo=0");
  182. the_post();
  183. $c[] = 'page pageid-' . $pageID;
  184. $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author()));
  185. $c[] = 'page-slug-'.$wp_query->post->post_name;
  186. // Checks to see if the page has children and/or is a child page; props to Adam
  187. if ( $page_children != '' ) {
  188. $c[] = 'page-parent';
  189. }
  190. if ( $wp_query->post->post_parent ) {
  191. $c[] = 'page-child parent-pageid-' . $wp_query->post->post_parent;
  192. }
  193. if ( get_post_custom_values('sidebarless') ) {
  194. $c[] = 'sidebars-none';
  195. }
  196. if ( get_post_custom_values('hidesidebar1') ) {
  197. $c[] = 'hidesidebar-1';
  198. }
  199. if ( get_post_custom_values('hidesidebar2') ) {
  200. $c[] = 'hidesidebar-2';
  201. }
  202. rewind_posts();
  203. }
  204. // Paged classes; for 'page X' classes of index, single, etc.
  205. $page = intval( $wp_query->get('paged') );
  206. if ( is_paged() && $page > 1 ) {
  207. $c[] = 'paged-'.$page.'';
  208. if ( is_single() ) {
  209. $c[] = 'single-paged-'.$page.'';
  210. } else if ( is_page() ) {
  211. $c[] = 'page-paged-'.$page.'';
  212. } else if ( is_category() ) {
  213. $c[] = 'category-paged-'.$page.'';
  214. } else if ( function_exists('is_tag') and is_tag() ) {
  215. $c[] = 'tag-paged-'.$page.'';
  216. } else if ( is_date() ) {
  217. $c[] = 'date-paged-'.$page.'';
  218. } else if ( is_author() ) {
  219. $c[] = 'author-paged-'.$page.'';
  220. } else if ( is_search() ) {
  221. $c[] = 'search-paged-'.$page.'';
  222. }
  223. }
  224. // For when a visitor is logged in while browsing
  225. if ( $current_user->ID )
  226. $c[] = 'loggedin';
  227. // Sidebar layout settings
  228. switch (get_option('k2columns')) {
  229. case '1':
  230. $c[] = 'columns-one';
  231. break;
  232. default:
  233. case '2':
  234. $c[] = 'columns-two';
  235. break;
  236. case 'dynamic':
  237. case '3':
  238. $c[] = 'columns-three';
  239. break;
  240. }
  241. // Language settings
  242. $locale = get_locale();
  243. if ( empty($locale) ) {
  244. $locale = 'en';
  245. } else {
  246. $lang_array = split('_', $locale);
  247. $locale = $lang_array[0];
  248. }
  249. $c[] = 'lang-' . $locale;
  250. // For WPMU. Set a class for the blog ID
  251. if ( isset($blog_id) )
  252. $c[] = 'wpmu-' . $blog_id;
  253. // Browser/Platform Specific Classes
  254. $c = array_merge( $c, k2_browser_classes() );
  255. // Separates classes with a single space, collates classes for BODY
  256. $c = attribute_escape( join( ' ', apply_filters('body_class', $c) ) );
  257. // And tada!
  258. return $print ? print($c) : $c;
  259. }
  260. function k2_post_class( $post_count = 1, $post_asides = false, $print = true ) {
  261. _deprecated_function(__FUNCTION__, '0.0', 'post_class()');
  262. $c = join( ' ', get_post_class() );
  263. return $print ? print($c) : $c;
  264. }
  265. function k2_post_class_filter($classes) {
  266. global $k2_post_alt, $post;
  267. if ( !$k2_post_alt )
  268. $k2_post_alt = 1;
  269. $classes[] = "p$k2_post_alt";
  270. // If it's the other to the every, then add 'alt' class
  271. if ( ++$k2_post_alt % 2 )
  272. $classes[] = 'alt';
  273. // Asides post
  274. if ( in_category( get_option('k2asidescategory') ) )
  275. $classes[] = 'k2-asides';
  276. // Applies the time- and date-based classes (below) to post DIV
  277. k2_date_classes(mysql2date('U', $post->post_date), $classes);
  278. return $classes;
  279. }
  280. add_filter('post_class', 'k2_post_class_filter');
  281. function k2_comment_class_filter($classes) {
  282. global $comment;
  283. k2_date_classes(mysql2date('U', $comment->comment_date), $classes, 'c-');
  284. return $classes;
  285. }
  286. add_filter('comment_class', 'k2_comment_class_filter');
  287. // Generates time- and date-based classes for BODY, post DIVs, and comment LIs; relative to GMT (UTC)
  288. function k2_date_classes($t, &$c, $p = '') {
  289. $t = $t + (get_option('gmt_offset') * 3600);
  290. $c[] = $p . 'y' . gmdate('Y', $t); // Year
  291. $c[] = $p . 'm' . gmdate('m', $t); // Month
  292. $c[] = $p . 'd' . gmdate('d', $t); // Day
  293. $c[] = $p . 'h' . gmdate('H', $t); // Hour
  294. }
  295. /*
  296. Adapted from PHP CSS Browser Selector v0.0.1
  297. Bastian Allgeier (http://bastian-allgeier.de)
  298. http://bastian-allgeier.de/css_browser_selector
  299. License: http://creativecommons.org/licenses/by/2.5/
  300. Credits: This is a php port from Rafael Lima's original Javascript CSS Browser Selector: http://rafael.adm.br/css_browser_selector
  301. */
  302. function k2_browser_classes($ua = null) {
  303. $ua = ($ua) ? strtolower($ua) : strtolower($_SERVER['HTTP_USER_AGENT']);
  304. $g = 'gecko';
  305. $w = 'webkit';
  306. $s = 'safari';
  307. $b = array();
  308. // browser
  309. if ( !preg_match( '/opera|webtv/i', $ua ) && preg_match( '/msie\s(\d)/', $ua, $array ) ):
  310. $b[] = 'ie ie' . $array[1];
  311. elseif ( strstr( $ua, 'firefox/2' ) ):
  312. $b[] = $g . ' ff2';
  313. elseif ( strstr( $ua, 'firefox/3.5' ) ):
  314. $b[] = $g . ' ff3 ff3_5';
  315. elseif ( strstr( $ua, 'firefox/3' ) ):
  316. $b[] = $g . ' ff3';
  317. elseif ( strstr( $ua, 'gecko/' ) ):
  318. $b[] = $g;
  319. elseif (preg_match('/opera(\s|\/)(\d+)/', $ua, $array ) ):
  320. $b[] = 'opera opera' . $array[2];
  321. elseif ( strstr( $ua, 'konqueror' ) ):
  322. $b[] = 'konqueror';
  323. elseif ( strstr( $ua, 'chrome' ) ):
  324. $b[] = $w . ' ' . $s . ' chrome';
  325. elseif ( strstr( $ua, 'iron' ) ):
  326. $b[] = $w . ' ' . $s . ' iron';
  327. elseif ( strstr( $ua, 'applewebkit/' ) ):
  328. $b[] = (preg_match('/version\/(\d+)/i', $ua, $array)) ? $w . ' ' . $s . ' ' . $s . $array[1] : $w . ' ' . $s;
  329. elseif ( strstr( $ua, 'mozilla/' ) ):
  330. $b[] = $g;
  331. endif;
  332. // platform
  333. if ( strstr( $ua, 'j2me' ) ):
  334. $b[] = 'mobile';
  335. elseif ( strstr( $ua, 'iphone' ) ):
  336. $b[] = 'iphone';
  337. elseif ( strstr( $ua, 'ipod' ) ):
  338. $b[] = 'ipod';
  339. elseif ( strstr( $ua, 'mac' ) ):
  340. $b[] = 'mac';
  341. elseif ( strstr( $ua, 'darwin' ) ):
  342. $b[] = 'mac';
  343. elseif ( strstr( $ua, 'webtv' ) ):
  344. $b[] = 'webtv';
  345. elseif ( strstr( $ua, 'win' ) ):
  346. $b[] = 'win';
  347. elseif ( strstr( $ua, 'freebsd' ) ):
  348. $b[] = 'freebsd';
  349. elseif ( strstr( $ua, 'x11' ) || strstr( $ua, 'linux' ) ):
  350. $b[] = 'linux';
  351. endif;
  352. return $b;
  353. }