Guest User

Untitled

a guest
Dec 10th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.51 KB | None | 0 0
  1. <?php
  2. define('THEME_NAME', "Wp");
  3. global $wp_version;
  4. define('WP_VERSION', $wp_version);
  5. define('THEME_NS', 'twentyten');
  6. define('THEME_LANGS_FOLDER', '/languages');
  7. if (class_exists('xili_language')) {
  8. define('THEME_TEXTDOMAIN', THEME_NS);
  9. } else {
  10. load_theme_textdomain(THEME_NS, TEMPLATEPATH . THEME_LANGS_FOLDER);
  11. }
  12.  
  13. if (function_exists('mb_internal_encoding')) {
  14. mb_internal_encoding(get_bloginfo('charset'));
  15. }
  16. if (function_exists('mb_regex_encoding')) {
  17. mb_regex_encoding(get_bloginfo('charset'));
  18. }
  19.  
  20. if (WP_VERSION < 3.0) {
  21. add_action('admin_notices', 'theme_unsupported_version_notice1');
  22. add_action('wp_head', 'theme_unsupported_version_notice2');
  23. function theme_unsupported_version_notice1() {
  24. ?>
  25. <div id='theme-warning' class='error fade'><p><strong><?php _e('Current theme requires WordPress 3.0 or higher.', THEME_NS); ?></strong>
  26. <?php
  27. echo sprintf(__('Please <a href="%s">upgrade WordPress</a>, or <a href="%s">use an earlier version of Artisteer (2.6 - 3.1)</a> to create themes for WordPress 2.6-2.9.', THEME_NS),
  28. 'http://codex.wordpress.org/Upgrading_WordPress', 'http://www.artisteer.com/Default.aspx?p=license_info');
  29. ?>
  30. </p></div>
  31. <?php
  32. }
  33. function theme_unsupported_version_notice2() {
  34. ?>
  35. </head>
  36. <body>
  37. <strong><?php _e('Current theme requires WordPress 3.0 or higher.', THEME_NS); ?></strong>
  38. <?php
  39. echo sprintf(__('Please <a href="%s">upgrade WordPress</a>, or <a href="%s">use an earlier version of Artisteer (2.6 - 3.1)</a> to create themes for WordPress 2.6-2.9.', THEME_NS),
  40. 'http://codex.wordpress.org/Upgrading_WordPress', 'http://www.artisteer.com/Default.aspx?p=license_info');
  41. ?>
  42. </body>
  43. </html>
  44. <?php
  45. die();
  46. }
  47. return;
  48. }
  49.  
  50. theme_include_lib('defaults.php');
  51. theme_include_lib('misc.php');
  52. theme_include_lib('wrappers.php');
  53. theme_include_lib('sidebars.php');
  54. theme_include_lib('navigation.php');
  55. theme_include_lib('shortcodes.php');
  56. theme_include_lib('widgets.php');
  57.  
  58. function theme_favicon() {
  59. if (is_file(TEMPLATEPATH . '/favicon.ico')):
  60. ?><link rel="shortcut icon" href="<?php bloginfo('template_directory'); ?>/favicon.ico" /><?php
  61. endif;
  62. }
  63.  
  64. add_action('wp', 'theme_init_layout');
  65. add_action('wp_head', 'theme_favicon');
  66. add_action('wp_head', 'theme_update_page_meta');
  67. add_action('wp_enqueue_scripts', 'theme_update_scripts', 1000);
  68. add_action('wp_enqueue_scripts', 'theme_update_styles', 1000);
  69. add_action('wp_print_scripts', 'theme_update_jquery_scripts', 1000);
  70. add_action('wp_head', 'theme_update_posts_styles', 1000);
  71. add_action('wp_head', 'theme_header_image_script');
  72. add_action('admin_head', 'theme_favicon');
  73. add_action('login_head', 'theme_favicon');
  74.  
  75. add_filter( 'wp_title', 'theme_update_title',1,3);
  76. add_action('media_upload_image_header', 'wp_media_upload_handler');
  77.  
  78. function theme_header_rel_link() {
  79. if (theme_get_option('theme_header_clickable')):
  80. ?><link rel='header_link' href='<?php echo esc_url(theme_get_option('theme_header_link')); ?>' /><?php
  81. endif;
  82. }
  83. add_action('wp_head', 'theme_header_rel_link');
  84. add_action('login_head', 'theme_header_rel_link');
  85.  
  86. add_theme_support('post-thumbnails');
  87. add_theme_support('nav-menus');
  88. add_theme_support('automatic-feed-links');
  89. add_theme_support('post-formats', array('aside', 'gallery'));
  90.  
  91. register_nav_menus(array('primary-menu' => __('Primary Navigation', THEME_NS)));
  92.  
  93.  
  94. function theme_header_image_script() {
  95. $theme_header_image = theme_get_meta_option(get_queried_object_id(), 'theme_header_image');
  96. if ($theme_header_image) {
  97. ?>
  98. <style>
  99. .art-header {
  100. background-image : url(<?php echo $theme_header_image; ?>);
  101. background-position : center center;
  102. }
  103. </style>
  104. <?php
  105. }
  106. }
  107.  
  108. function theme_has_header_image() {
  109. return (bool) theme_get_meta_option(get_queried_object_id(), 'theme_header_image');
  110. }
  111. function theme_show_flash() {
  112. return (bool) theme_get_meta_option(get_queried_object_id(), 'theme_header_image_with_flash');
  113. }
  114.  
  115. function theme_init_layout() {
  116. global $theme_layout;
  117. $theme_layout = array(
  118. 'header' => 1,
  119. 'default_sidebar' => 1,
  120.  
  121. );
  122. $page_id = 0;
  123. if (is_page()) {
  124. $page_id = (int)theme_get_the_ID();
  125. }
  126. if (is_home()) {
  127. $posts_page_id = (int)get_option( 'page_for_posts');
  128. if ($posts_page_id > 0) {
  129. $page_id = $posts_page_id;
  130. }
  131. }
  132. if ($page_id > 0) {
  133. foreach ($theme_layout as $layout_part_name => $included) {
  134. $theme_layout[$layout_part_name] = theme_get_meta_option($page_id, 'theme_layout_template_' . $layout_part_name);
  135. }
  136. }
  137. if(is_attachment()) {
  138. $theme_layout['default_sidebar'] = 0;
  139.  
  140. }
  141. }
  142.  
  143. function theme_has_layout_part($name) {
  144. global $theme_layout;
  145. return (bool) theme_get_array_value($theme_layout, $name);
  146. }
  147.  
  148. if (is_admin()) {
  149. theme_include_lib('options.php');
  150. theme_include_lib('admins.php');
  151.  
  152. function theme_add_option_page() {
  153. add_theme_page(__('Theme Options', THEME_NS), __('Theme Options', THEME_NS), 'edit_themes', basename(__FILE__), 'theme_print_options');
  154. }
  155.  
  156. add_action('admin_menu', 'theme_add_option_page');
  157. add_action('sidebar_admin_setup', 'theme_widget_process_control');
  158. add_filter('widget_update_callback', 'theme_update_widget_additional');
  159. add_action('add_meta_boxes', 'theme_add_meta_boxes');
  160. add_action('save_post', 'theme_save_post');
  161.  
  162. if (file_exists(TEMPLATEPATH . '/content/content-importer.php')) {
  163. include(TEMPLATEPATH . '/content/content-importer.php');
  164. }
  165. return;
  166. }
  167.  
  168. function theme_update_scripts() {
  169. global $wp_scripts;
  170. wp_register_script("script.js", get_bloginfo('template_url', 'display') . '/script.js', array('jquery'));
  171. wp_enqueue_script("script.js");
  172. wp_register_script("script.responsive.js", get_bloginfo('template_url', 'display') . '/script.responsive.js', array('jquery'));
  173. wp_enqueue_script("script.responsive.js");
  174.  
  175. }
  176.  
  177. function theme_update_jquery_scripts() {
  178. if(is_admin()) {
  179. return;
  180. }
  181. wp_deregister_script('jquery');
  182. if (theme_get_option('theme_iclude_scripts_from_cdn')) {
  183. wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js');
  184. } else {
  185. wp_register_script('jquery', get_bloginfo('template_url', 'display') . '/jquery.js');
  186. }
  187. }
  188.  
  189. function theme_update_styles() {
  190. global $wp_styles;
  191. wp_register_style("style.ie7.css", get_bloginfo('template_url', 'display') . '/style.ie7.css', array(), false, "screen");
  192. wp_enqueue_style("style.ie7.css");
  193. $wp_styles->add_data("style.ie7.css", "conditional", "lte IE 7");
  194. wp_register_style("style.responsive.css", get_bloginfo('template_url', 'display') . '/style.responsive.css', array(), false, "all");
  195. wp_enqueue_style("style.responsive.css");
  196.  
  197. }
  198.  
  199. function theme_update_title($title, $sep, $seplocation) {
  200. global $wp_query;
  201. $post_id = get_queried_object_id();
  202. if ($post_id == 0 && theme_is_home()) {
  203. $post_id = get_option('page_for_posts');
  204. }
  205. $meta_title = get_post_meta($post_id, 'page_title', true);
  206. if (!empty($meta_title)) {
  207. $title = ( 'right' == $seplocation ? $meta_title . " $sep " : " $sep " . $meta_title);
  208. }
  209. return $title;
  210. }
  211.  
  212. function theme_update_page_meta() {
  213. global $wp_query;
  214. $res = '';
  215. $post_id = get_queried_object_id();
  216. if ($post_id == 0 && theme_is_home()) {
  217. $post_id = get_option('page_for_posts');
  218. }
  219. $description = get_post_meta($post_id, 'page_description', true);
  220. if (!empty($description)) {
  221. $res .= "<meta name=\"description\" content=\"$description\">\n";
  222. }
  223. $keywords = get_post_meta($post_id, 'page_keywords', true);
  224. if (!empty($keywords)) {
  225. $res .= "<meta name=\"keywords\" content=\"$keywords\">\n";
  226. }
  227. $metaTags = get_post_meta($post_id, 'page_metaTags', true);
  228. if (!empty($metaTags)) {
  229. $res .= $metaTags . "\n";
  230. }
  231. if (!empty($res)) {
  232. echo "\n" . $res;
  233. }
  234. }
  235.  
  236. function theme_update_posts_styles() {
  237. global $wp_query;
  238. $res = '';
  239. if(!is_singular()) {
  240. $post_id = get_queried_object_id();
  241. if ($post_id == 0 && theme_is_home()) {
  242. $post_id = get_option('page_for_posts');
  243. }
  244. $res .= get_post_meta($post_id, 'theme_head', true);
  245. }
  246. while ($wp_query->have_posts()) {
  247. the_post();
  248. $post_id = theme_get_the_ID();
  249. $res .= get_post_meta($post_id, 'theme_head', true);
  250. }
  251. if (!empty($res)) {
  252. echo $res;
  253. }
  254. wp_reset_postdata();
  255. }
  256.  
  257. function theme_get_option($name) {
  258. global $theme_default_options;
  259. $result = get_option($name);
  260. if ($result === false) {
  261. $result = theme_get_array_value($theme_default_options, $name);
  262. }
  263. return $result;
  264. }
  265.  
  266.  
  267.  
  268. function theme_get_widget_meta_option($widget_id, $name) {
  269. global $theme_default_meta_options;
  270. if (!preg_match('/^(.*[^-])-([0-9]+)$/', $widget_id, $matches) || !isset($matches[1]) || !isset($matches[2])) {
  271. return theme_get_array_value($theme_default_meta_options, $name);
  272. }
  273. $type = $matches[1];
  274. $id = $matches[2];
  275. $wp_widget = get_option('widget_' . $type);
  276. if (!$wp_widget || !isset($wp_widget[$id])) {
  277. return theme_get_array_value($theme_default_meta_options, $name);
  278. }
  279. if (!isset($wp_widget[$id][$name])) {
  280. $wp_widget[$id][$name] = theme_get_array_value(get_option($name), $widget_id, theme_get_array_value($theme_default_meta_options, $name));
  281. update_option('widget_' . $type, $wp_widget);
  282. }
  283. return $wp_widget[$id][$name];
  284. }
  285.  
  286. function theme_set_widget_meta_option($widget_id, $name, $value) {
  287. if (!preg_match('/^(.*[^-])-([0-9]+)$/', $widget_id, $matches) || !isset($matches[1]) || !isset($matches[2])) {
  288. return;
  289. }
  290. $type = $matches[1];
  291. $id = $matches[2];
  292. $wp_widget = get_option('widget_' . $type);
  293. if (!$wp_widget || !isset($wp_widget[$id])) {
  294. return;
  295. }
  296. $wp_widget[$id][$name] = $value;
  297. update_option('widget_' . $type, $wp_widget);
  298. }
  299.  
  300. function theme_get_meta_option($id, $name) {
  301. global $theme_default_meta_options;
  302. if (!is_numeric($id)) {
  303. return theme_get_array_value($theme_default_meta_options, $name);
  304. }
  305. $value = get_post_meta($id, '_' . $name, true);
  306. if ('' === $value) {
  307. $value = theme_get_array_value(get_option($name), $id, theme_get_array_value($theme_default_meta_options, $name));
  308. theme_set_meta_option($id, $name, $value);
  309. }
  310. return $value;
  311. }
  312.  
  313. function theme_set_meta_option($id, $name, $value) {
  314. update_post_meta($id, '_' . $name, $value);
  315. }
  316.  
  317. function theme_get_post_id() {
  318. $post_id = theme_get_the_ID();
  319. if ($post_id != '') {
  320. $post_id = 'post-' . $post_id;
  321. }
  322. return $post_id;
  323. }
  324.  
  325. function theme_get_the_ID() {
  326. global $post;
  327. return $post->ID;
  328. }
  329.  
  330. function theme_get_post_class() {
  331. return implode(' ', get_post_class());
  332. }
  333.  
  334. function theme_include_lib($name) {
  335. locate_template(array('library/' . $name), true);
  336. }
  337.  
  338. function theme_get_metadata_icons($icons = '', $class = '') {
  339. global $post;
  340. if (!is_string($icons) || theme_strlen($icons) == 0)
  341. return;
  342. $icons = explode(",", str_replace(' ', '', $icons));
  343. if (!is_array($icons) || count($icons) == 0)
  344. return;
  345. $result = array();
  346. for ($i = 0; $i < count($icons); $i++) {
  347. $icon = $icons[$i];
  348. switch ($icon) {
  349. case 'date':
  350. $result[] = '<span class="art-postdateicon">' . sprintf(__('<span class="%1$s">Published</span> %2$s', THEME_NS),
  351. 'date',
  352. sprintf( '<span class="entry-date" title="%1$s">%2$s</span>',
  353. esc_attr( get_the_time() ),
  354. get_the_date()
  355. )
  356. ) . '</span>';
  357. break;
  358. case 'author':
  359. $result[] = '<span class="art-postauthoricon">' . sprintf(__('<span class="%1$s">By</span> %2$s', THEME_NS),
  360. 'author',
  361. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  362. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  363. sprintf( esc_attr(__( 'View all posts by %s', THEME_NS )), get_the_author() ),
  364. get_the_author()
  365. )
  366. ) . '</span>';
  367. break;
  368. case 'category':
  369. $categories = get_the_category_list(', ');
  370. if (theme_strlen($categories) == 0)
  371. break;
  372. $result[] = '<span class="art-postcategoryicon">' . sprintf(__('<span class="%1$s">Posted in</span> %2$s', THEME_NS), 'categories', get_the_category_list(', ')) . '</span>';
  373. break;
  374. case 'tag':
  375. $tags_list = get_the_tag_list('', ', ');
  376. if (!$tags_list)
  377. break;
  378. $result[] = '<span class="art-posttagicon">' . sprintf(__('<span class="%1$s">Tagged</span> %2$s', THEME_NS), 'tags', $tags_list) . '</span>';
  379. break;
  380. case 'comments':
  381. if (!comments_open() || !theme_get_option('theme_allow_comments'))
  382. break;
  383. theme_ob_start();
  384. comments_popup_link(__('Leave a comment', THEME_NS), __('1 Comment', THEME_NS), __('% Comments', THEME_NS));
  385. $result[] = '<span class="art-postcommentsicon">' . theme_ob_get_clean() . '</span>';
  386. break;
  387. case 'edit':
  388. if (!current_user_can('edit_post', $post->ID))
  389. break;
  390. theme_ob_start();
  391. edit_post_link(__('Edit', THEME_NS), '');
  392. $result[] = '<span class="art-postediticon">' . theme_ob_get_clean() . '</span>';
  393. break;
  394. }
  395. }
  396. $result = implode(theme_get_option('theme_metadata_separator'), $result);
  397. if (theme_is_empty_html($result))
  398. return;
  399. return "<div class=\"art-post{$class}icons art-metadata-icons\">{$result}</div>";
  400. }
  401.  
  402. function theme_get_post_thumbnail($args = array()) {
  403. global $post;
  404.  
  405. $size = theme_get_array_value($args, 'size', array(theme_get_option('theme_metadata_thumbnail_width'), theme_get_option('theme_metadata_thumbnail_height')));
  406. $auto = theme_get_array_value($args, 'auto', theme_get_option('theme_metadata_thumbnail_auto'));
  407. $featured = theme_get_array_value($args, 'featured', theme_get_option('theme_metadata_use_featured_image_as_thumbnail'));
  408. $title = theme_get_array_value($args, 'title', get_the_title());
  409.  
  410.  
  411. $result = '';
  412.  
  413. if ($featured && (has_post_thumbnail())) {
  414. theme_ob_start();
  415. the_post_thumbnail($size, array('alt' => '', 'title' => $title));
  416. $result = theme_ob_get_clean();
  417. } elseif ($auto) {
  418. $attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
  419. if ($attachments) {
  420. $attachment = array_shift($attachments);
  421. $img = wp_get_attachment_image_src($attachment->ID, $size);
  422. if (isset($img[0])) {
  423. $result = '<img src="' . $img[0] . '" alt="" width="' . $img[1] . '" height="' . $img[2] . '" title="' . $title . '" class="wp-post-image" />';
  424. }
  425. }
  426. }
  427. if ($result !== '') {
  428. $result = '<div class="alignleft"><a href="' . get_permalink($post->ID) . '" title="' . $title . '">' . $result . '</a></div>';
  429. }
  430. return $result;
  431. }
  432.  
  433. function theme_get_content($args = array()) {
  434. $more_tag = theme_get_array_value($args, 'more_tag', __('Continue reading <span class="meta-nav">&rarr;</span>', THEME_NS));
  435. theme_ob_start();
  436. the_content($more_tag);
  437. $content = theme_ob_get_clean();
  438. return $content . wp_link_pages(array(
  439. 'before' => '<p><span class="page-navi-outer page-navi-caption"><span class="page-navi-inner">' . __('Pages', THEME_NS) . ': </span></span>',
  440. 'after' => '</p>',
  441. 'link_before' => '<span class="page-navi-outer"><span class="page-navi-inner">',
  442. 'link_after' => '</span></span>',
  443. 'echo' => 0
  444. ));
  445. }
  446.  
  447. function theme_get_excerpt($args = array()) {
  448. global $post;
  449. $more_tag = theme_get_array_value($args, 'more_tag', __('Continue reading <span class="meta-nav">&rarr;</span>', THEME_NS));
  450. $auto = theme_get_array_value($args, 'auto', theme_get_option('theme_metadata_excerpt_auto'));
  451. $all_words = theme_get_array_value($args, 'all_words', theme_get_option('theme_metadata_excerpt_words'));
  452. $min_remainder = theme_get_array_value($args, 'min_remainder', theme_get_option('theme_metadata_excerpt_min_remainder'));
  453. $allowed_tags = theme_get_array_value($args, 'allowed_tags',
  454. (theme_get_option('theme_metadata_excerpt_use_tag_filter')
  455. ? explode(',',str_replace(' ', '', theme_get_option('theme_metadata_excerpt_allowed_tags')))
  456. : null));
  457. $perma_link = get_permalink($post->ID);
  458. $more_token = '%%theme_more%%';
  459. $show_more_tag = false;
  460. $tag_disbalance = false;
  461. if (post_password_required($post)) {
  462. return get_the_excerpt();
  463. }
  464. if ($auto && has_excerpt($post->ID)) {
  465. $excerpt = get_the_excerpt();
  466. $show_more_tag = theme_strlen($post->post_content) > 0;
  467. } else {
  468. $excerpt = get_the_content($more_token);
  469. // hack for badly written plugins
  470. theme_ob_start();
  471. echo apply_filters('the_content', $excerpt);
  472. $excerpt = theme_ob_get_clean();
  473. global $multipage;
  474. if ($multipage && theme_strpos($excerpt, $more_token) === false) {
  475. $show_more_tag = true;
  476. }
  477. if (theme_is_empty_html($excerpt))
  478. return $excerpt;
  479. if ($allowed_tags !== null) {
  480. $allowed_tags = '<' . implode('><', $allowed_tags) . '>';
  481. $excerpt = strip_tags($excerpt, $allowed_tags);
  482. }
  483. if (theme_strpos($excerpt, $more_token) !== false) {
  484. $excerpt = str_replace($more_token, $more_tag, $excerpt);
  485. } elseif ($auto && is_numeric($all_words)) {
  486. $token = "%theme_tag_token%";
  487. $content_parts = explode($token, str_replace(array('<', '>'), array($token . '<', '>' . $token), $excerpt));
  488. $content = array();
  489. $word_count = 0;
  490. foreach ($content_parts as $part) {
  491. if (theme_strpos($part, '<') !== false || theme_strpos($part, '>') !== false) {
  492. $content[] = array('type' => 'tag', 'content' => $part);
  493. } else {
  494. $all_chunks = preg_split('/([\s])/u', $part, -1, PREG_SPLIT_DELIM_CAPTURE);
  495. foreach ($all_chunks as $chunk) {
  496. if ('' != trim($chunk)) {
  497. $content[] = array('type' => 'word', 'content' => $chunk);
  498. $word_count += 1;
  499. } elseif ($chunk != '') {
  500. $content[] = array('type' => 'space', 'content' => $chunk);
  501. }
  502. }
  503. }
  504. }
  505.  
  506. if (($all_words < $word_count) && ($all_words + $min_remainder) <= $word_count) {
  507. $show_more_tag = true;
  508. $tag_disbalance = true;
  509. $current_count = 0;
  510. $excerpt = '';
  511. foreach ($content as $node) {
  512. if ($node['type'] == 'word') {
  513. $current_count++;
  514. }
  515. $excerpt .= $node['content'];
  516. if ($current_count == $all_words) {
  517. break;
  518. }
  519. }
  520. $excerpt .= '&hellip;'; // ...
  521. }
  522. }
  523. }
  524. if ($show_more_tag) {
  525. $excerpt = $excerpt . ' <a class="more-link" href="' . $perma_link . '">' . $more_tag . '</a>';
  526. }
  527. if ($tag_disbalance) {
  528. $excerpt = force_balance_tags($excerpt);
  529. }
  530. return $excerpt;
  531. }
  532.  
  533. function theme_get_search() {
  534. theme_ob_start();
  535. get_search_form();
  536. return theme_ob_get_clean();
  537. }
  538.  
  539. function theme_is_home() {
  540. return (is_home() && !is_paged());
  541. }
  542.  
  543. function theme_404_content($args = '') {
  544. $args = wp_parse_args($args, array(
  545. 'error_title' => __('Not Found', THEME_NS),
  546. 'error_message' => __('Apologies, but the page you requested could not be found. Perhaps searching will help.', THEME_NS),
  547. 'focus_script' => '<script type="text/javascript">jQuery(\'div.art-content input[name="s"]\').focus();</script>'
  548. )
  549. );
  550. extract($args);
  551. theme_post_wrapper(
  552. array(
  553. 'title' => $error_title,
  554. 'content' => '<p class="center">' . $error_message . '</p>' . "\n" . theme_get_search() . $focus_script
  555. )
  556. );
  557.  
  558. if (theme_get_option('theme_show_random_posts_on_404_page')) {
  559. theme_ob_start();
  560. echo '<h4 class="box-title">' . theme_get_option('theme_show_random_posts_title_on_404_page') . '</h4>';
  561. ?>
  562. <ul>
  563. <?php
  564. global $post;
  565. $rand_posts = get_posts('numberposts=5&orderby=rand');
  566. foreach ($rand_posts as $post) :
  567. ?>
  568. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
  569. <?php endforeach; ?>
  570. </ul>
  571. <?php
  572. theme_post_wrapper(array('content' => theme_ob_get_clean()));
  573. }
  574. if (theme_get_option('theme_show_tags_on_404_page')) {
  575. theme_ob_start();
  576. echo '<h4 class="box-title">' . theme_get_option('theme_show_tags_title_on_404_page') . '</h4>';
  577. wp_tag_cloud('smallest=9&largest=22&unit=pt&number=200&format=flat&orderby=name&order=ASC');
  578. theme_post_wrapper(array('content' => theme_ob_get_clean()));
  579. }
  580. }
  581.  
  582. function theme_page_navigation() {
  583. global $wp_query;
  584. $total_pages = $wp_query->max_num_pages;
  585. if($total_pages > 1) {
  586. echo theme_stylize_pagination(paginate_links(array(
  587. 'base' => str_replace(PHP_INT_MAX, '%#%', get_pagenum_link(PHP_INT_MAX)),
  588. 'format' => '',
  589. 'current' => max(1, get_query_var('paged')),
  590. 'total' => $total_pages
  591. )));
  592. }
  593. }
  594.  
  595. function theme_post_navigation($args = '') {
  596. $args = wp_parse_args($args, array('wrap' => true, 'prev_link' => false, 'next_link' => false));
  597. $prev_link = $args['prev_link'];
  598. $next_link = $args['next_link'];
  599. $content = '';
  600. $prev_align = 'left';
  601. $next_align = 'right';
  602. if (is_rtl()) {
  603. $prev_align = 'right';
  604. $next_align = 'left';
  605. }
  606. if ($prev_link || $next_link) {
  607. $content = <<<EOL
  608. <div class="navigation">
  609. <div class="align{$prev_align}">{$prev_link}</div>
  610. <div class="align{$next_align}">{$next_link}</div>
  611. </div>
  612. EOL;
  613. }
  614. if ($args['wrap']) {
  615. theme_post_wrapper(array('content' => $content));
  616. } else {
  617. echo $content;
  618. }
  619. }
  620.  
  621. function theme_get_previous_post_link($format = '&laquo; %link', $link = '%title', $in_same_cat = false, $excluded_categories = '') {
  622. return theme_get_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
  623. }
  624.  
  625. function theme_get_next_post_link($format = '%link &raquo;', $link = '%title', $in_same_cat = false, $excluded_categories = '') {
  626. return theme_get_adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
  627. }
  628.  
  629. function theme_get_adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
  630. global $post;
  631. $post = get_post($post);
  632. $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
  633.  
  634. foreach ($attachments as $k => $attachment)
  635. if ($attachment->ID == $post->ID)
  636. break;
  637.  
  638. $k = $prev ? $k - 1 : $k + 1;
  639.  
  640. if (isset($attachments[$k]))
  641. return wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);
  642. }
  643.  
  644. function theme_get_previous_image_link($size = 'thumbnail', $text = false) {
  645. $result = theme_get_adjacent_image_link(true, $size, $text);
  646. if ($result)
  647. $result = '&laquo; ' . $result;
  648. return $result;
  649. }
  650.  
  651. function theme_get_next_image_link($size = 'thumbnail', $text = false) {
  652. $result = theme_get_adjacent_image_link(false, $size, $text);
  653. if ($result)
  654. $result .= ' &raquo;';
  655. return $result;
  656. }
  657.  
  658. function theme_get_adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
  659. if ($previous && is_attachment())
  660. $post = & get_post($GLOBALS['post']->post_parent);
  661. else
  662. $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
  663.  
  664. if (!$post)
  665. return;
  666.  
  667. $title = strip_tags($post->post_title);
  668.  
  669. if (empty($post->post_title))
  670. $title = $previous ? __('Previous Post', THEME_NS) : __('Next Post', THEME_NS);
  671.  
  672. $title = apply_filters('the_title', $title, $post->ID);
  673. $short_title = $title;
  674. if (theme_get_option('theme_single_navigation_trim_title')) {
  675. $short_title = theme_trim_long_str($title, theme_get_option('theme_single_navigation_trim_len'));
  676. }
  677. $date = mysql2date(get_option('date_format'), $post->post_date);
  678. $rel = $previous ? 'prev' : 'next';
  679.  
  680. $string = '<a href="' . get_permalink($post) . '" title="' . esc_attr($title) . '" rel="' . $rel . '">';
  681. $link = str_replace('%title', $short_title, $link);
  682. $link = str_replace('%date', $date, $link);
  683. $link = $string . $link . '</a>';
  684.  
  685. $format = str_replace('%link', $link, $format);
  686.  
  687. $adjacent = $previous ? 'previous' : 'next';
  688. return apply_filters("{$adjacent}_post_link", $format, $link);
  689. }
  690.  
  691.  
  692. function theme_stylize_pagination($pagination) {
  693. if ($pagination) {
  694. $pagination = '<div class="art-pager">' . str_replace(array('current', 'dots'), array('current active', 'dots more'), $pagination) . '</div>';
  695. }
  696. return $pagination;
  697. }
  698.  
  699.  
  700. function theme_comment_reply_link_filter($link) {
  701. return str_replace('class=\'', 'class=\'art-button ', $link);
  702. }
  703.  
  704. add_filter('comment_reply_link', 'theme_comment_reply_link_filter');
  705.  
  706.  
  707. function theme_comment($comment, $args, $depth) {
  708. $GLOBALS['comment'] = $comment;
  709. switch ($comment->comment_type) :
  710. case '' :
  711. ?>
  712. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  713. <div class="art-comment <?php echo $comment->comment_type ?> clearfix" id="comment-<?php comment_ID() ?>">
  714. <div class="art-comment-avatar"><?php echo theme_get_avatar(array('id' => $comment, 'size' => 80)); ?></div>
  715. <div class="art-comment-inner">
  716. <div class="art-comment-header comment-meta commentmetadata"><?php printf(__('%s on ', THEME_NS), get_comment_author_link($comment->comment_ID)); ?>
  717. <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?>"><?php printf(__('%1$s at %2$s', THEME_NS), get_comment_date(), get_comment_time()); ?></a>
  718. <?php edit_comment_link(__('(Edit)', THEME_NS)); ?></div>
  719. <div class="art-comment-content comment-body"><?php if ($comment->comment_approved == '0') : ?>
  720. <em><?php _e('Your comment is awaiting moderation.', THEME_NS); ?></em>
  721. <br />
  722. <?php endif; ?>
  723. <?php comment_text(); ?></div>
  724. <div class="art-comment-footer reply"><?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?></div>
  725. </div>
  726. </div>
  727. <?php
  728. break;
  729. case 'pingback' :
  730. case 'trackback' :
  731. ?>
  732. <li class="post pingback">
  733. <div class="art-comment <?php echo $comment->comment_type ?> clearfix">
  734. <div class="art-comment-content comment-body"><?php _e('Pingback:', THEME_NS); ?> <?php comment_author_link(); ?><?php edit_comment_link(__('(Edit)', THEME_NS), ' '); ?></div>
  735. </div>
  736. <?php
  737. break;
  738. endswitch;
  739. }
  740.  
  741. function theme_get_comments() {
  742. if (!theme_get_option('theme_allow_comments')) return '';
  743. theme_ob_start();
  744. comments_template();
  745. return theme_ob_get_clean();
  746. }
  747.  
  748. function theme_get_avatar_filter($avatar) {
  749. return str_replace('src=', 'onerror=\'this.src="'.get_template_directory_uri().'/images/no-avatar.jpg"\' src=', $avatar);
  750. }
  751. add_filter('get_avatar', 'theme_get_avatar_filter');
  752.  
  753. function theme_get_avatar($args = '') {
  754. $default = get_option('avatar_default');
  755. if (empty($default) || $default === 'mystery') {
  756. $default = get_template_directory_uri() . '/images/no-avatar.jpg';
  757. }
  758. $args = wp_parse_args($args, array('id' => false, 'size' => 96, 'default' => $default, 'alt' => false, 'url' => false));
  759. extract($args);
  760. $result = get_avatar($id, $size, $default, $alt);
  761. if ($result) {
  762. if ($url) {
  763. $result = '<a href="' . esc_url($url) . '">' . $result . '</a>';
  764. }
  765. }
  766. return $result;
  767. }
  768.  
  769. if (!function_exists('get_post_format')) {//for WP 3.0
  770. function get_post_format() {
  771. return null;
  772. }
  773. }
  774.  
  775.  
  776. if (!function_exists('get_queried_object_id')) {//for WP 3.0
  777. function get_queried_object_id() {
  778. global $wp_query;
  779. return $wp_query->get_queried_object_id();
  780. }
  781. }
  782.  
  783. function theme_get_next_post() {
  784. static $ended = false;
  785. if (!$ended) {
  786. if (have_posts()) {
  787. the_post();
  788. get_template_part('content', get_post_format());
  789. } else {
  790. $ended = true;
  791. }
  792. }
  793. }
  794.  
  795. $theme_ob_stack = array();
  796.  
  797. function theme_ob_handler($str) {
  798. global $theme_ob_stack;
  799. end($theme_ob_stack);
  800. $theme_ob_stack[key($theme_ob_stack)] .= $str;
  801. return '';
  802. }
  803.  
  804. function theme_ob_start() {
  805. global $theme_ob_stack;
  806. array_push($theme_ob_stack, '');
  807. ob_start('theme_ob_handler');
  808. }
  809.  
  810. function theme_ob_get_clean() {
  811. global $theme_ob_stack;
  812. ob_end_flush();
  813. return array_pop($theme_ob_stack);
  814. }
Add Comment
Please, Sign In to add comment