Guest User

Functions post http://br.forums.wordpress.org/topic/redirecionando-home?replies=4#post-8873

a guest
Aug 18th, 2010
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 53.41 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Core functions file for the theme. Includes other key files.
  4.  *
  5.  * @package Suffusion
  6.  * @subpackage Functions
  7.  */
  8.  
  9. //load_theme_textdomain("suf_theme", TEMPLATEPATH. "/translation");
  10. $locale = get_locale();
  11. load_textdomain('suf_theme', locate_template(array("translation/{$locale}.mo", "{$locale}.mo")));
  12.  
  13. if (!isset($content_width)) $content_width = 725;
  14. $themename = "Suffusion";
  15. $shortname = "suf";
  16.  
  17. // Option names
  18. $color_scheme = $shortname."_color_scheme";
  19. $sidebar_header = $shortname."_sidebar_header";
  20. $show_shadows = $shortname."_show_shadows";
  21. $body_style_setting = $shortname."_body_style_setting";
  22. $body_font_style_setting = $shortname."_body_font_style_setting";
  23. $header_style_setting = $shortname."_header_style_setting";
  24.  
  25. $font_faces = array (
  26.     "Arial, Helvetica, sans-serif" => "<font face=\"Arial, Helvetica, sans-serif\">Arial, <span class='mac'>Arial, Helvetica,</span> <i>sans-serif</i></font>",
  27.     "'Arial Black', Gadget, sans-serif" => "<font face=\"'Arial Black', Gadget, sans-serif\">Arial Black, <span class='mac'>Arial Black, Gadget,</span> <i>sans-serif</i></font>",
  28.     "'Comic Sans MS', cursive" => "<font face=\"'Comic Sans MS', cursive\">Comic Sans MS, <span class='mac'>Comic Sans MS,</span> <i>cursive</i></font>",
  29.     "'Courier New', Courier, monospace " => "<font face=\"'Courier New', Courier, monospace\">Courier New, <span class='mac'>Courier New, Courier,</span> <i>monospace</i></font>",
  30.     "Georgia, serif" => "<font face=\"Georgia, serif\">Georgia, <span class='mac'>Georgia,</span> <i>serif</i></font>",
  31.     "Impact, Charcoal, sans-serif" => "<font face=\"Impact, Charcoal, sans-serif\">Impact, <span class='mac'>Impact, Charcoal,</span> <i>sans-serif</i></font>",
  32.     "'Lucida Console', Monaco, monospace" => "<font face=\"'Lucida Console', Monaco, monospace\">Lucida Console, <span class='mac'>Monaco,</span> <i>monospace</i></font>",
  33.     "'Lucida Sans Unicode', 'Lucida Grande', sans-serif" => "<font face=\"'Lucida Sans Unicode', 'Lucida Grande', sans-serif\">Lucida Sans Unicode, <span class='mac'>Lucida Grande,</span> <i>sans-serif</i></font>",
  34.     "'Palatino Linotype', 'Book Antiqua', Palatino, serif" => "<font face=\"'Palatino Linotype', 'Book Antiqua', Palatino, serif\">Palatino Linotype, Book Antiqua, <span class='mac'>Palatino,</span> <i>serif</i></font>",
  35.     "Tahoma, Geneva, sans-serif" => "<font face=\"Tahoma, Geneva, sans-serif\">Tahoma, <span class='mac'>Geneva,</span> <i>sans-serif</i></font>",
  36.     "'Times New Roman', Times, serif" => "<font face=\"'Times New Roman', Times, serif\">Times New Roman, <span class='mac'>Times,</span> <i>serif</i></font>",
  37.     "'Trebuchet MS', Helvetica, sans-serif" => "<font face=\"'Trebuchet MS', Helvetica, sans-serif\">Trebuchet MS, <span class='mac'>Helvetica,</span> <i>sans-serif</i></font>",
  38.     "Verdana, Geneva, sans-serif" => "<font face=\"Verdana, Geneva, sans-serif\">Verdana, <span class='mac'>Verdana, Geneva,</span> <i>sans-serif</i></font>",
  39.     "Symbol" => "<font face=\"Symbol\">Symbol, <span class='mac'>Symbol</span></font> (\"Symbol\" works in IE and Chrome on Windows and in Safari on Mac)",
  40.     "Webdings" => "<font face=\"Webdings\">Webdings, <span class='mac'>Webdings</span></font> (\"Webdings\" works in IE and Chrome on Windows and in Safari on Mac)",
  41.     "Wingdings, 'Zapf Dingbats'" => "<font face=\"Wingdings, 'Zapf Dingbats'\">Wingdings, <span class='mac'>Zapf Dingbats</span></font> (\"Wingdings\" works in IE and Chrome on Windows and in Safari on Mac)",
  42.     "'MS Sans Serif', Geneva, sans-serif" => "<font face=\"'MS Sans Serif', Geneva, sans-serif\">MS Sans Serif, <span class='mac'>Geneva,</span> <i>sans-serif</i></font>",
  43.     "'MS Serif', 'New York', serif" => "<font face=\"'MS Serif', 'New York', serif\">MS Serif, <span class='mac'>New York,</span> <i>serif</i></font>",
  44. );
  45.  
  46. $suffusion_options = get_option('suffusion_options');
  47. if (!isset($suffusion_options[$color_scheme]) || $suffusion_options[$color_scheme] === FALSE || $suffusion_options[$color_scheme] == null || !isset($suffusion_options[$color_scheme])) {
  48.     $theme_name = 'root';
  49. }
  50. else {
  51.     $theme_name = $suffusion_options[$color_scheme];
  52. }
  53. $default_theme_name = "dark-theme-green";
  54. $suffusion_rtl_layout = false;
  55.  
  56. //Essential for multi-selects. Do not delete!!! And do not move it below the next statement!!!
  57. $spawned_options = array();
  58. $page_array = null;
  59. $category_array = null;
  60.  
  61. // Global variables
  62. $SUFFUSION_COMMENT_TYPES = array('comment' => __('Comments', 'suf_theme'), 'trackback' => __('Trackbacks', 'suf_theme'), 'pingback' => __('Pingbacks', 'suf_theme'));
  63.  
  64. $sidebar_tabs = array(
  65.     'archives' => array('title' => __('Archives', 'suf_theme')),
  66.     'categories' => array('title' => __('Categories', 'suf_theme')),
  67.     'links' => array('title' => __('Links', 'suf_theme')),
  68.     'meta' => array('title' => __('Meta', 'suf_theme')),
  69.     'pages' => array('title' => __('Pages', 'suf_theme')),
  70.     'recent_comments' => array('title' => __('Recent Comments', 'suf_theme')),
  71.     'recent_posts' => array('title' => __('Recent Posts', 'suf_theme')),
  72.     'search' => array('title' => __('Search', 'suf_theme')),
  73.     'tag_cloud' => array('title' => __('Tag Cloud', 'suf_theme')),
  74.     'custom_tab_1' => array('title' => __('Custom Tab 1', 'suf_theme')),
  75.     'custom_tab_2' => array('title' => __('Custom Tab 2', 'suf_theme')),
  76.     'custom_tab_3' => array('title' => __('Custom Tab 3', 'suf_theme')),
  77.     'custom_tab_4' => array('title' => __('Custom Tab 4', 'suf_theme')),
  78.     'custom_tab_5' => array('title' => __('Custom Tab 5', 'suf_theme')),
  79.     'custom_tab_6' => array('title' => __('Custom Tab 6', 'suf_theme')),
  80.     'custom_tab_7' => array('title' => __('Custom Tab 7', 'suf_theme')),
  81.     'custom_tab_8' => array('title' => __('Custom Tab 8', 'suf_theme')),
  82.     'custom_tab_9' => array('title' => __('Custom Tab 9', 'suf_theme')),
  83.     'custom_tab_10' => array('title' => __('Custom Tab 10', 'suf_theme')),
  84. );
  85.  
  86. $suffusion_404_title =  __("Error 404 - Not Found", "suf_theme");
  87. $suffusion_404_content = __("Sorry, the page that you are looking for does not exist.", "suf_theme");
  88.  
  89. $suffusion_comment_label_name = __('Name', "suf_theme");
  90. $suffusion_comment_label_req = __('(required)', "suf_theme");
  91. $suffusion_comment_label_email = __('E-mail', "suf_theme");
  92. $suffusion_comment_label_uri = __('URI', "suf_theme");
  93. $suffusion_comment_label_your_comment = __('Your Comment', "suf_theme");
  94.  
  95. $social_networks = array('twitter' => 'Twitter',
  96.                 'facebook' => 'Facebook',
  97.                 'technorati' => 'Technorati',
  98.                 'linkedin' => "LinkedIn",
  99.                 'flickr' => 'Flickr',
  100.                 'delicious' => 'Delicious',
  101.                 'digg' => 'Digg',
  102.                 'stumbleupon' => 'StumbleUpon',
  103.                 'reddit' => "Reddit");
  104.  
  105. include_once (TEMPLATEPATH . "/admin/theme-definitions.php");
  106. include_once (TEMPLATEPATH . "/admin/theme-options.php");
  107. $suffusion_unified_options = suffusion_get_unified_options();
  108.  
  109. include_once (TEMPLATEPATH . "/admin/suffusion-options-page.php");
  110.  
  111. // WEF 5th August 2010 (version 3.6.0 of Suffusion) support for comments on older versions of WP (< 2.7) has been removed)
  112. // Begin legacy comments support
  113. /*
  114. add_filter( 'comments_template', 'legacy_comments' );
  115. function legacy_comments( $file ) {
  116.     if ( !function_exists('wp_list_comments') )
  117.         $file = TEMPLATEPATH . '/legacy-comments.php';
  118.     return $file;
  119. }
  120. */
  121. //End legacy comments support
  122.  
  123. function suf_get_formatted_page_array($prefix) {
  124.     global $spawned_options, $page_array;
  125.     $ret = array();
  126.     $pages = get_pages('sort_column=menu_order');
  127.     if ($pages != null) {
  128.         foreach ($pages as $page) {
  129.             if (is_null($page_array)) {
  130.                 $ret[$page->ID] = array ("title" => $page->post_title, "depth" => count(get_post_ancestors($page)));
  131.             }
  132.             $spawned_options[count($spawned_options)] = array(  "id" => $prefix."_".$page->ID,
  133.                 "type" => "checkbox",
  134.                 "parent" => $prefix, "std" => "false");
  135.         }
  136.     }
  137.     if ($page_array == null) {
  138.         $page_array = $ret;
  139.         return $ret;
  140.     }
  141.     else {
  142.         return $page_array;
  143.     }
  144. }
  145.  
  146. function suf_get_formatted_category_array($prefix, $spawn = true) {
  147.     global $spawned_options, $category_array;
  148.     $ret = array();
  149.     $args = array("type" => "post",
  150.         "orderby" => "name",
  151.         "hide_empty" => false,
  152.     );
  153.     $categories = get_categories($args);
  154.     if ($categories == null) { $categories = array(); }
  155.     foreach ($categories as $category) {
  156.         if ($category_array == null) {
  157.             $ret[$category->cat_ID] = array("title" => $category->cat_name);
  158.         }
  159.         if ($spawn) {
  160.             $spawned_options[count($spawned_options)] = array(  "id" => $prefix."_".$category->cat_ID,
  161.                                                                 "type" => "checkbox",
  162.                                                                 "parent" => $prefix,
  163.                                                                 "std" => "false");
  164.         }
  165.     }
  166.     if ($category_array == null) {
  167.         $category_array = $ret;
  168.         return $category_array;
  169.     }
  170.     else {
  171.         return $category_array;
  172.     }
  173. }
  174.  
  175. function suf_get_allowed_categories($prefix) {
  176.     global $suffusion_options;
  177.     $allowed = array();
  178.     if (isset($suffusion_options[$prefix])) {
  179.         $selected = $suffusion_options[$prefix];
  180.         if ($selected && trim($selected) != '') { $selected_categories = explode(',', $selected); } else { $selected_categories = array(); }
  181.         if ($selected_categories && is_array($selected_categories)) {
  182.             foreach ($selected_categories as $category) {
  183.                 $allowed[count($allowed)] = get_category($category);
  184.             }
  185.         }
  186.     }
  187.     return $allowed;
  188. }
  189.  
  190. if (class_exists("WP_Widget")) {
  191.     include_once (TEMPLATEPATH . '/suffusion-widgets.php');
  192. }
  193. include_once (TEMPLATEPATH . '/suffusion-classes.php');
  194.  
  195. add_action('admin_menu', 'suffusion_add_page_fields');
  196.  
  197. function suffusion_add_page_fields() {
  198.     if (function_exists('add_meta_box')) {
  199.         add_meta_box('suffusion-page-box', 'Additional Options for Suffusion', 'suffusion_page_extras', 'page', 'normal', 'high');
  200.         add_meta_box('suffusion-post-box', 'Additional Options for Suffusion', 'suffusion_post_extras', 'post', 'normal', 'high');
  201.     }
  202. }
  203.  
  204. function suffusion_page_extras() {
  205.     global $post;
  206. ?>
  207.     <p>
  208.         <label for="suf_alt_page_title"><?php _e("Page Title in Dropdown Menu", "suf_theme"); ?></label><br/>
  209.         <input type="text" id="suf_alt_page_title" name="suf_alt_page_title"
  210.         value="<?php echo get_post_meta($post->ID, "suf_alt_page_title", true); ?>" /> <?php _e("This text will be shown in the drop-down menus in the navigation bar. If left blank, the title of the page is used.", 'suf_theme'); ?>
  211.     </p>
  212.     <p>
  213.         <label for="suf_nav_unlinked"><?php _e("Do not link to this page in the navigation bars", "suf_theme"); ?></label><br/>
  214.         <input type="checkbox" id="suf_nav_unlinked" name="suf_nav_unlinked"
  215.             <?php if (get_post_meta($post->ID, 'suf_nav_unlinked', true)) { echo " checked='checked' ";} ?> />
  216.             <?php _e('If this box is checked, clicking on this page in the navigation bar will not take you anywhere.', 'suf_theme'); ?>
  217.     </p>
  218.     <p>
  219.         <label for="thumbnail"><?php _e("Thumbnail", "suf_theme"); ?></label><br/>
  220.         <input type="text" id="thumbnail" name="thumbnail"
  221.             value="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" /> <?php _e("Enter the full URL of the thumbnail image that you would like to use, including http://", "suf_theme"); ?>
  222.     </p>
  223.     <p>
  224.         <label for="featured_image"><?php _e("Featured Image", "suf_theme"); ?></label><br/>
  225.         <input type="text" id="featured_image" name="featured_image"
  226.             value="<?php echo get_post_meta($post->ID, "featured_image", true); ?>" /> <?php _e("Enter the full URL of the featured image that you would like to use, including http://", "suf_theme"); ?>
  227.     </p>
  228.     <p>
  229.         <label for="meta_description"><?php _e("Meta Description", "suf_theme"); ?></label><br/>
  230.         <textarea id="meta_description" name="meta_description" cols='80' rows='5'><?php echo get_post_meta($post->ID, "meta_description", true); ?></textarea>
  231.     </p>
  232.     <p>
  233.         <label for="meta_keywords"><?php _e("Meta Keywords", "suf_theme"); ?></label><br/>
  234.         <input type="text" id="meta_keywords" name="meta_keywords" style='width: 500px;'
  235.             value="<?php echo get_post_meta($post->ID, "meta_keywords", true); ?>" /> <?php _e("Enter a comma-separated list of keywords for this post. This list will be included in the meta tags for this post.", "suf_theme"); ?>
  236.     </p>
  237.     <input type='hidden' id='suffusion_post_meta' name='suffusion_post_meta' value='suffusion_post_meta'/>
  238. <?php
  239. }
  240.  
  241. function suffusion_post_extras() {
  242.     global $post;
  243. ?>
  244.     <p>
  245.         <label for="thumbnail"><?php _e("Thumbnail", "suf_theme"); ?></label><br/>
  246.         <input type="text" id="thumbnail" name="thumbnail"
  247.             value="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" /> <?php _e("Enter the full URL of the thumbnail image that you would like to use, including http://", "suf_theme"); ?>
  248.     </p>
  249.     <p>
  250.         <label for="featured_image"><?php _e("Featured Image", "suf_theme"); ?></label><br/>
  251.         <input type="text" id="featured_image" name="featured_image"
  252.             value="<?php echo get_post_meta($post->ID, "featured_image", true); ?>" /> <?php _e("Enter the full URL of the featured image that you would like to use, including http://", "suf_theme"); ?>
  253.     </p>
  254.     <p>
  255.         <label for="suf_magazine_headline"><?php _e("Make this post a headline", "suf_theme"); ?></label><br/>
  256.         <input type="checkbox" id="suf_magazine_headline" name="suf_magazine_headline"
  257.             <?php if (get_post_meta($post->ID, 'suf_magazine_headline', true)) { echo " checked='checked' ";} ?> />
  258.             <?php _e('If this box is checked, this post will show up as a headline in the magazine template.', 'suf_theme'); ?>
  259.     </p>
  260.     <p>
  261.         <label for="suf_magazine_excerpt"><?php _e("Make this post an excerpt in the magazine layout", "suf_theme"); ?></label><br/>
  262.         <input type="checkbox" id="suf_magazine_excerpt" name="suf_magazine_excerpt"
  263.             <?php if (get_post_meta($post->ID, 'suf_magazine_excerpt', true)) { echo " checked='checked' ";} ?> />
  264.             <?php _e('If this box is checked, this post will show up as an excerpt in the magazine template.', 'suf_theme'); ?>
  265.     </p>
  266.     <p>
  267.         <label for="meta_description"><?php _e("Meta Description", "suf_theme"); ?></label><br/>
  268.         <textarea id="meta_description" name="meta_description" cols='80' rows='5'><?php echo get_post_meta($post->ID, "meta_description", true); ?></textarea>
  269.     </p>
  270.     <p>
  271.         <label for="meta_keywords"><?php _e("Meta Keywords", "suf_theme"); ?></label><br/>
  272.         <input type="text" id="meta_keywords" name="meta_keywords" style='width: 500px;'
  273.             value="<?php echo get_post_meta($post->ID, "meta_keywords", true); ?>" /> <?php _e("Enter a comma-separated list of keywords for this post. This list will be included in the meta tags for this post.", "suf_theme"); ?>
  274.     </p>
  275.     <input type='hidden' id='suffusion_post_meta' name='suffusion_post_meta' value='suffusion_post_meta'/>
  276. <?php
  277. }
  278.  
  279. function suffusion_save_post_fields($post_id) {
  280.     $suffusion_post_fields = array('thumbnail', 'featured_image', 'suf_magazine_headline', 'suf_magazine_excerpt', 'suf_alt_page_title', 'meta_description', 'meta_keywords', 'suf_nav_unlinked');
  281.     if (isset($_POST['suffusion_post_meta'])) {
  282.         foreach ($suffusion_post_fields as $post_field) {
  283.             $data = stripslashes($_POST[$post_field]);
  284.             if (get_post_meta($post_id, $post_field) == '') {
  285.                 add_post_meta($post_id, $post_field, $data, true);
  286.             }
  287.             else if ($data != get_post_meta($post_id, $post_field, true)) {
  288.                 update_post_meta($post_id, $post_field, $data);
  289.             }
  290.             else if ($data == '') {
  291.                 delete_post_meta($post_id, $post_field, get_post_meta($post_id, $post_field, true));
  292.             }
  293.         }
  294.     }
  295. }
  296.  
  297. add_action("save_post", "suffusion_save_post_fields");
  298. add_action("publish_post", "suffusion_save_post_fields");
  299.  
  300. function suffusion_export_settings() {
  301.     global $options, $suffusion_options;
  302.     $export = array();
  303.     foreach ($options as $value) {
  304.         if ((isset($value['export']) && $value['export'] == 'ne') || !isset($value['id']) || $value['type'] == 'button') {
  305.             continue;
  306.         }
  307.         if (!isset($suffusion_options[$value['id']]) && isset($value['std'])) {
  308.             $export[$value['id']] = $value['std'];
  309.         }
  310.         else {
  311.             $export[$value['id']] = $suffusion_options[$value['id']];
  312.         }
  313.     }
  314.     header('Content-Type: text/plain');
  315.     header('Content-Disposition: attachment; filename="suffusion-options.php"');
  316.     echo "<?php \n";
  317.     echo "/* Suffusion settings exported on ".date('Y-m-d H:i')." */ \n";
  318.     echo '$suffusion_exported_options = ';
  319.     var_export($export);
  320.     echo ";\n ?>";
  321.     die;
  322. }
  323.  
  324. add_action('wp_head', 'suf_add_header_contents');
  325. function suf_add_header_contents() {
  326.     suf_create_openid_links();
  327.     suf_create_additional_feeds();
  328. }
  329.  
  330. add_action('wp_footer', 'suf_add_footer_contents');
  331. function suf_add_footer_contents() {
  332.     suf_create_analytics_contents();
  333. }
  334.  
  335. // OpenID stuff...
  336. function suf_create_openid_links() {
  337.     global $suf_openid_enabled, $suf_openid_server, $suf_openid_delegate;
  338.     if ($suf_openid_enabled == "enabled") {
  339.         echo "<!-- Start OpenID settings -->\n";
  340.         echo "<link rel=\"openid.server\" href=\"".$suf_openid_server."\" />\n";
  341.         echo "<link rel=\"openid.delegate\" href=\"".$suf_openid_delegate."\" />\n";
  342.         echo "<!-- End OpenID settings -->\n";
  343.     }
  344. }
  345. // ... End OpenID stuff
  346.  
  347. // Analytics ...
  348. function suf_create_analytics_contents() {
  349.     global $suf_analytics_enabled, $suf_custom_analytics_code;
  350.     if ($suf_analytics_enabled == "enabled") {
  351.         if (trim($suf_custom_analytics_code) != "") {
  352.             echo "<!-- Start Google Analytics -->\n";
  353.             echo stripslashes($suf_custom_analytics_code)."\n";
  354.             echo "<!-- End Google Analytics -->\n";
  355.         }
  356.     }
  357. }
  358. // ... End Analytics
  359.  
  360. // Additional Feeds ...
  361. function suf_create_additional_feeds() {
  362.     global $suffusion_options;
  363.     echo "<!-- Start Additional Feeds -->\n";
  364.     if (isset($suffusion_options['suf_custom_rss_feed_1']) && trim($suffusion_options['suf_custom_rss_feed_1']) != "") {
  365.         echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".esc_attr($suffusion_options['suf_custom_rss_title_1'])."\" href=\"".$suffusion_options['suf_custom_rss_feed_1']."\" />\n";
  366.     }
  367.     if (isset($suffusion_options['suf_custom_rss_feed_2']) && trim($suffusion_options['suf_custom_rss_feed_2']) != "") {
  368.         echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".esc_attr($suffusion_options['suf_custom_rss_title_2'])."\" href=\"".$suffusion_options['suf_custom_rss_feed_2']."\" />\n";
  369.     }
  370.     if (isset($suffusion_options['suf_custom_rss_feed_3']) && trim($suffusion_options['suf_custom_rss_feed_3']) != "") {
  371.         echo "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"".esc_attr($suffusion_options['suf_custom_rss_title_3'])."\" href=\"".$suffusion_options['suf_custom_rss_feed_3']."\" />\n";
  372.     }
  373.     if (isset($suffusion_options['suf_custom_atom_feed_1']) && trim($suffusion_options['suf_custom_atom_feed_1']) != "") {
  374.         echo "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"".esc_attr($suffusion_options['suf_custom_atom_title_1'])."\" href=\"".$suffusion_options['suf_custom_atom_feed_1']."\" />\n";
  375.     }
  376.     if (isset($suffusion_options['suf_custom_atom_feed_2']) && trim($suffusion_options['suf_custom_atom_feed_2']) != "") {
  377.         echo "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"".esc_attr($suffusion_options['suf_custom_atom_title_2'])."\" href=\"".$suffusion_options['suf_custom_atom_feed_2']."\" />\n";
  378.     }
  379.     if (isset($suffusion_options['suf_custom_atom_feed_3']) && trim($suffusion_options['suf_custom_atom_feed_3']) != "") {
  380.         echo "<link rel=\"alternate\" type=\"application/atom+xml\" title=\"".esc_attr($suffusion_options['suf_custom_atom_title_3'])."\" href=\"".$suffusion_options['suf_custom_atom_feed_3']."\" />\n";
  381.     }
  382.     echo "<!-- End Additional Feeds -->\n";
  383. }
  384. // ... End Additional Feeds
  385.  
  386. function get_excluded_pages($prefix) {
  387.     global $$prefix;
  388.     $inclusions = $$prefix;
  389.     $all_pages = get_pages('sort_column=menu_order');
  390.     if ($all_pages == null) {
  391.         $all_pages = array();
  392.     }
  393.  
  394.     if ($inclusions && trim($inclusions) != '') {
  395.         $include = explode(',', $inclusions);
  396.         $translations = wpml_lang_object_ids($include, 'post');
  397.         foreach ($translations as $translation) {
  398.             $include[count($include)] = $translation;
  399.         }
  400.     }
  401.     else {
  402.         $include = array();
  403.     }
  404.  
  405.     // First we figure out which pages have to be excluded
  406.     $exclude = array();
  407.     foreach ($all_pages as $page) {
  408.         if (!in_array($page->ID, $include)) {
  409.             $exclude[count($exclude)] = $page->ID;
  410.         }
  411.     }
  412.     // Now we need to figure out if these excluded pages are ancestors of any pages on the list. If so, we remove the descendants
  413.     foreach ($all_pages as $page) {
  414.         $ancestors = get_post_ancestors($page);
  415.         foreach ($ancestors as $ancestor) {
  416.             if (in_array($ancestor, $exclude)) {
  417.                 $exclude[count($exclude)] = $page->ID;
  418.             }
  419.         }
  420.     }
  421.  
  422.     $exclusion_list = implode(",", $exclude);
  423.     return $exclusion_list;
  424. }
  425.  
  426. function suffusion_get_page_structure($id, $title, $link, $depth, $exclusion_list) {
  427.     $page_structure = new Suf_Navigation_Structure($id, $title, $link, $depth, 'page');
  428.     $page_structure->children = array();
  429.     $child_pages = get_pages('sort_column=menu_order&parent='.$id.'&child_of='.$id.'&exclude='.$exclusion_list);
  430.     if ($child_pages == null) { $child_pages = array(); }
  431.     $child_depth = $depth + 1;
  432.     foreach ($child_pages as $child_page) {
  433.         $link_disabled = get_post_meta($child_page->ID, 'suf_nav_unlinked', true);
  434.         if ($link_disabled) {
  435.             $child_page_link = "";
  436.         }
  437.         else {
  438.             $child_page_link = get_page_link($child_page->ID);
  439.         }
  440.         $child = suffusion_get_page_structure($child_page->ID, $child_page->post_title, $child_page_link, $child_depth, $exclusion_list);
  441.         $page_structure->children[count($page_structure->children)] = $child;
  442.     }
  443.     return $page_structure;
  444. }
  445.  
  446. function suffusion_get_home_link_html($position) {
  447.     global $suffusion_options;
  448.     $retStr = "";
  449.     $suf_show_home = "";
  450.     $option_name = $position == 'top' ? 'suf_navt_show_home' : 'suf_show_home';
  451.     if (!isset($suffusion_options[$option_name])) {
  452.         $suf_show_home = "none";
  453.     }
  454.     else {
  455.         $suf_show_home = $suffusion_options[$option_name];
  456.     }
  457.  
  458.     $show_on_front = get_option('show_on_front');
  459.     $class = "";
  460.     if (is_front_page()) {
  461.         $class = " class='highlighted' ";
  462.     }
  463.     else if (is_home() && $show_on_front == 'posts') {
  464.         $class = " class='highlighted' ";
  465.     }
  466.  
  467.     $option_name = $position == 'top' ? 'suf_navt_home_text' : 'suf_home_text';
  468.     $home_link = get_option("home");
  469.     if (function_exists('icl_get_home_url')) {
  470.         $home_link = icl_get_home_url();
  471.     }
  472.     if ($suf_show_home == "text") {
  473.         if ($suffusion_options[$option_name] === FALSE || $suffusion_options[$option_name] == null) {
  474.             $suf_home_text = "Home";
  475.         }
  476.         else if (trim($suffusion_options[$option_name]) == "") {
  477.             $suf_home_text = "Home";
  478.         }
  479.         else {
  480.             $suf_home_text = trim($suffusion_options[$option_name]);
  481.         }
  482.         $retStr .= "\n\t\t\t\t\t"."<li><a $class href='".$home_link."'>".$suf_home_text."</a></li>";
  483.     }
  484.     else if ($suf_show_home == "icon") {
  485.         $retStr .= "\n\t\t\t\t\t"."<li><a $class href='".$home_link."'><img src='".get_bloginfo("template_directory")."/images/home-light.png' alt='Home' class='home-icon'/></a></li>";
  486.     }
  487.     return $retStr;
  488. }
  489.  
  490. /**
  491.  * This method takes a Suffusion_Nav_Structure object and parses it out to build the navigation menu.
  492.  * The menu is based on Stu Nicholls' famous CSS-only navigation menu: http://www.cssplay.co.uk/menus/final_drop.html. I have made minor modifications to it.
  493.  */
  494. function suffusion_parse_nav_structure($nav_structure, $position = 'main') {
  495.     global $post;
  496.     $retStr = "";
  497.     if ($nav_structure->depth == 0) {
  498.         $home_link = suffusion_get_home_link_html($position);
  499.         if (($nav_structure->children != null && is_array($nav_structure->children) && count($nav_structure->children) > 0) || $home_link) {
  500.             $retStr .= "\n\t\t\t\t\t"."<ul class='sf-menu'>";
  501.             $retStr .= $home_link;
  502.             foreach ($nav_structure->children as $child_page) {
  503.                 $retStr .= suffusion_parse_nav_structure($child_page, $position);
  504.             }
  505.             $retStr .= "\n\t\t\t\t\t"."</ul>";
  506.         }
  507.     }
  508.     else if ($nav_structure->depth == 1) {
  509.         $show_on_front = get_option('show_on_front');
  510.         $page_for_posts = get_option('page_for_posts');
  511.         $ancestors = get_post_ancestors($post);
  512.         if (!is_array($ancestors)) {
  513.             $ancestors = array();
  514.         }
  515.  
  516.         $href = trim($nav_structure->link) == "" ? " href='#' onclick='return false;' " : " href='$nav_structure->link' ";
  517.         if (is_page() && ($post->ID == $nav_structure->ID || in_array($nav_structure->ID, $ancestors)) && $nav_structure->type == 'page' ||
  518.                 (($nav_structure->ID == $page_for_posts) && $show_on_front == 'page' && is_home())) {
  519.             $retStr .= "\n\t\t\t\t\t"."<li><a $href class='highlighted'>".$nav_structure->title."</a>";
  520.         }
  521.         else if (is_category() && (single_cat_title('', false) == $nav_structure->title)&& $nav_structure->type == 'cat') {
  522.             $retStr .= "\n\t\t\t\t\t"."<li><a $href class='highlighted'>".$nav_structure->title."</a>";
  523.         }
  524.         else {
  525.             $target = $nav_structure->target ? " target='".$nav_structure->target."' " : ' ';
  526.             $retStr .= "\n\t\t\t\t\t"."<li><a $href $target>".$nav_structure->title."</a>";
  527.         }
  528.         if ($nav_structure->children != null && count($nav_structure->children) != 0) {
  529.             $retStr .= "\n\t\t\t"."<ul>";
  530.             foreach ($nav_structure->children as $child_page) {
  531.                 $target = $child_page->target ? " target='".$child_page->target."' " : ' ';
  532.                 $child_href = trim($child_page->link) == "" ? " href='#' onclick='return false;' " : " href='$child_page->link' ";
  533.                 //$retStr .= "\n\t\t\t\t"."<li><a href='$child_page->link' $target";
  534.                 $retStr .= "\n\t\t\t\t"."<li><a $child_href $target";
  535.                 $retStr .= suffusion_parse_nav_structure($child_page, $position);
  536.             }
  537.             $retStr .= "\n\t\t\t\t"."</ul>";
  538.         }
  539.         $retStr .= "\n\t\t\t\t"."</li>";
  540.     }
  541.     else {
  542.         if ($nav_structure->children != null && count($nav_structure->children) != 0) {
  543.             $retStr .= " class='drop' title=\"$nav_structure->title\"><!--[if !IE]>--><span class='float-ptr'>&gt;</span><!--<![endif]-->$nav_structure->title<!--[if lte IE 7]>&nbsp;&nbsp;&gt;<![endif]--> <!--[if (!IE)|(gt IE 7)]><span class='float-ptr'>&gt;</span><![endif]--></a>";
  544.             $retStr .= "\n\t\t\t"."<ul>";
  545.  
  546.             foreach ($nav_structure->children as $child_page) {
  547.                 $target = $child_page->target ? " target='".$child_page->target."' " : ' ';
  548.                 $child_href = trim($child_page->link) == "" ? " href='#' onclick='return false;' " : " href='$child_page->link' ";
  549.                 //$retStr .= "\n\t\t\t\t"."<li><a href='$child_page->link' $target";
  550.                 $retStr .= "\n\t\t\t\t"."<li><a $child_href $target";
  551.                 $retStr .= suffusion_parse_nav_structure($child_page, $position);
  552.             }
  553.             $retStr .= "\n\t\t\t\t"."</ul>";
  554.             $retStr .= "\n\t\t\t\t"."</li>";
  555.         }
  556.         else {
  557.             $retStr .= " title=\"$nav_structure->title\">$nav_structure->title</a></li>";
  558.         }
  559.     }
  560.     return $retStr;
  561. }
  562.  
  563. function suf_get_excluded_categories($prefix) {
  564.     global $$prefix;
  565.     $inclusions = $$prefix;
  566.     $inclusions_array = explode(',', $inclusions);
  567.  
  568.     if (is_array($inclusions_array)) {
  569.         $translations_array = wpml_lang_object_ids($inclusions_array, 'category');
  570.     }
  571.     if (is_array($translations_array)) {
  572.         foreach ($translations_array as $translation) {
  573.             if (!in_array($translation, $inclusions_array)) {
  574.                 $inclusions_array[count($inclusions_array)] = $translation;
  575.             }
  576.         }
  577.     }
  578.     if (is_array($inclusions_array)) {
  579.         $inclusions = implode(',', $inclusions_array);
  580.     }
  581.  
  582.     $args = array(
  583.         "type" => "post",
  584.         "orderby" => "name",
  585.         "exclude" => $inclusions,
  586.     );
  587.  
  588.     $excluded = get_categories($args);
  589.     return $excluded;
  590. }
  591.  
  592. function suf_get_included_bookmarks($prefix, $all = false) {
  593.     global $$prefix;
  594.     $inclusions = $$prefix;
  595.     if (function_exists('mylinkorder')) {
  596.         $order_by = 'order';
  597.     }
  598.     else {
  599.         $order_by = 'name';
  600.     }
  601.     $args = array(
  602.         "order" => "ASC",
  603.         "orderby" => $order_by,
  604.     );
  605.     $links = get_bookmarks($args);
  606.     if ($all) {
  607.         return $links;
  608.     }
  609.     $included = array();
  610.     $inclusions_array = explode(',',$inclusions);
  611.     if ($inclusions_array && count($inclusions_array) > 0) {
  612.         foreach ($links as $bookmark) {
  613.             if (in_array($bookmark->link_id, $inclusions_array)) {
  614.                 $included[count($included)] = $bookmark;
  615.             }
  616.         }
  617.     }
  618.     return $included;
  619. }
  620.  
  621. /**
  622.  * Returns the list of included menus. It uses the following logic:
  623.  *   1. Checks the options set in the navigation bar setup screens
  624.  *   2. Checks if the menu is assigned to a "location" through the menu administration screens in WP (Apparently this is needed for theme approvals!!)
  625.  * If a menu is assigned to a location, that takes precedence over the theme's options.
  626.  *
  627.  * @param  $prefix This is the option name in the theme options
  628.  * @param bool $all
  629.  * @param string $position
  630.  * @return array
  631.  */
  632. function suf_get_included_menus($prefix, $all = false, $position = 'main') {
  633.     global $$prefix;
  634.     $inclusions = $$prefix;
  635.     $args = array(
  636.         'sort_column' => 'menu_order'
  637.     );
  638.     if (!function_exists('wp_get_nav_menus')) {
  639.         return array();
  640.     }
  641.  
  642.     $menus = wp_get_nav_menus($args);
  643.     if ($all) {
  644.         return $menus;
  645.     }
  646.     $included = array();
  647.     $inclusions_array = explode(',',$inclusions);
  648.  
  649.     $menu_locations = array();
  650.     if (function_exists('get_nav_menu_locations')) {
  651.         $menu_locations = get_nav_menu_locations();
  652.     }
  653.     if (isset($menu_locations[$position])) {
  654.         $menu_in_location = $menu_locations[$position];
  655.     }
  656.  
  657.     $all_ids = array();
  658.     if ($inclusions_array && count($inclusions_array) > 0) {
  659.         foreach ($menus as $menu) {
  660.             $all_ids[] = $menu->term_id;
  661.             if (in_array($menu->term_id, $inclusions_array)) {
  662.                 $included[] = $menu;
  663.             }
  664.             else if (isset($menu_in_location) && $menu_in_location == $menu->term_id) {
  665.                 $included[] = $menu;
  666.             }
  667.         }
  668.     }
  669.     return $included;
  670. }
  671.  
  672. function create_nav_for_all($position = 'main', $page_option = 'suf_nav_pages', $cats_option = 'suf_nav_cats', $links_option = 'suf_nav_links', $menus_option = 'suf_nav_menus') {
  673.     global $post, $suf_nav_pages_style, $suf_nav_page_tab_title, $suf_nav_page_tab_link, $suf_navt_pages_style, $suf_navt_page_tab_title, $suf_navt_page_tab_link;
  674.     global $suf_nav_cat_style, $suf_nav_cat_tab_title, $suf_nav_cat_tab_link, $suf_navt_cat_style, $suf_navt_cat_tab_title, $suf_navt_cat_tab_link;
  675.     global $suf_nav_links_style, $suf_nav_links_tab_title, $suf_nav_links_tab_link, $suf_navt_links_style, $suf_navt_links_tab_title, $suf_navt_links_tab_link;
  676.     global $suf_nav_entity_order, $suf_navt_entity_order, $suf_nav_pages_all_sel, $suf_nav_cats_all_sel, $suf_nav_links_all_sel, $suf_navt_pages_all_sel, $suf_navt_cats_all_sel, $suf_navt_links_all_sel;
  677.     global $suf_nav_menus_all_sel, $suf_navt_menus_all_sel, $suf_navt_menus_style, $suf_nav_menus_style;
  678.  
  679.     switch ($position) {
  680.         case 'top':
  681.             $pages_style = $suf_navt_pages_style;
  682.             $page_tab_title = stripslashes($suf_navt_page_tab_title);
  683.             $page_tab_link = $suf_navt_page_tab_link;
  684.             $page_all_sel = $suf_navt_pages_all_sel;
  685.             $cat_style = $suf_navt_cat_style;
  686.             $cat_tab_title = stripslashes($suf_navt_cat_tab_title);
  687.             $cat_tab_link = $suf_navt_cat_tab_link;
  688.             $cat_all_sel = $suf_navt_cats_all_sel;
  689.             $links_style = $suf_navt_links_style;
  690.             $links_tab_title = stripslashes($suf_navt_links_tab_title);
  691.             $links_tab_link = $suf_navt_links_tab_link;
  692.             $link_all_sel = $suf_navt_links_all_sel;
  693.             $menus_all_sel = $suf_navt_menus_all_sel;
  694.             $menus_style = $suf_navt_menus_style;
  695.             $entity_order = $suf_navt_entity_order;
  696.             break;
  697.         default:
  698.             $pages_style = $suf_nav_pages_style;
  699.             $page_tab_title = stripslashes($suf_nav_page_tab_title);
  700.             $page_tab_link = $suf_nav_page_tab_link;
  701.             $page_all_sel = $suf_nav_pages_all_sel;
  702.             $cat_style = $suf_nav_cat_style;
  703.             $cat_tab_title = stripslashes($suf_nav_cat_tab_title);
  704.             $cat_tab_link = $suf_nav_cat_tab_link;
  705.             $cat_all_sel = $suf_nav_cats_all_sel;
  706.             $links_style = $suf_nav_links_style;
  707.             $links_tab_title = stripslashes($suf_nav_links_tab_title);
  708.             $links_tab_link = $suf_nav_links_tab_link;
  709.             $link_all_sel = $suf_nav_links_all_sel;
  710.             $menus_all_sel = $suf_nav_menus_all_sel;
  711.             $menus_style = $suf_nav_menus_style;
  712.             $entity_order = $suf_nav_entity_order;
  713.             break;
  714.     }
  715.  
  716.     if ($page_all_sel == 'selected') {
  717.         $pages_excluded = get_excluded_pages($page_option);
  718.     }
  719.     else {
  720.         $pages_excluded = array();
  721.     }
  722.  
  723.     if ($cat_all_sel == 'selected') {
  724.         $categories_excluded = suf_get_excluded_categories($cats_option);
  725.     }
  726.     else {
  727.         $categories_excluded = array();
  728.     }
  729.  
  730.     if ($link_all_sel == 'selected') {
  731.         $bookmarks_included = suf_get_included_bookmarks($links_option, false);
  732.     }
  733.     else {
  734.         $bookmarks_included = suf_get_included_bookmarks($links_option, true);
  735.     }
  736.  
  737.     if (function_exists('wp_nav_menu')) {
  738.         if ($menus_all_sel == 'selected') {
  739.             $menus_included = suf_get_included_menus($menus_option, false, $position);
  740.         }
  741.         else {
  742.             $menus_included = suf_get_included_menus($menus_option, true, $position);
  743.         }
  744.     }
  745.  
  746.     $nav_structure = new Suf_Navigation_Structure(0, 'Root', '', 0);
  747.     $nav_structure->children = array();
  748.     $entity_order = suf_get_entity_order($entity_order, 'nav');
  749.     $entity_order = explode(',', $entity_order);
  750.     $processed_menus = array();
  751.     foreach ($entity_order as $entity) {
  752.         if ($entity == 'pages') {
  753.             if ($pages_style == 'rolled-up') {
  754.                 $page_structure = suffusion_get_page_structure(0, $page_tab_title, $page_tab_link, 1, $pages_excluded);
  755.                 if ($page_structure->children != null && count($page_structure->children) > 0) {
  756.                     $nav_structure->children[count($nav_structure->children)] = $page_structure;
  757.                 }
  758.             }
  759.             else if ($pages_style == 'flattened') {
  760.                 $page_structure = suffusion_get_page_structure(0, $page_tab_title,  $page_tab_link, 0, $pages_excluded);
  761.                 if ($page_structure->children != null && count($page_structure->children) > 0) {
  762.                     foreach ($page_structure->children as $child_structure) {
  763.                         $nav_structure->children[count($nav_structure->children)] = $child_structure;
  764.                     }
  765.                 }
  766.             }
  767.         }
  768.         else if ($entity == 'categories') {
  769.             if ($cat_style == 'rolled-up') {
  770.                 $category_structure = suffusion_get_category_structure(0, $cat_tab_title, $cat_tab_link, 1, $categories_excluded, 'page');
  771.                 if ($category_structure->children != null && count($category_structure->children) > 0) {
  772.                     $nav_structure->children[count($nav_structure->children)] = $category_structure;
  773.                 }
  774.             }
  775.             else if ($cat_style == 'flattened') {
  776.                 $category_structure = suffusion_get_category_structure(0, $cat_tab_title, $cat_tab_link, 0, $categories_excluded, 'cat');
  777.                 foreach ($category_structure->children as $child_structure) {
  778.                     $nav_structure->children[count($nav_structure->children)] = $child_structure;
  779.                 }
  780.             }
  781.         }
  782.         else if ($entity == 'links') {
  783.             if ($links_style == 'rolled-up') {
  784.                 $bookmark_structure = suffusion_get_bookmark_structure(0, $links_tab_title, $links_tab_link, 1, $bookmarks_included, 'page');
  785.                 if ($bookmark_structure->children != null && count($bookmark_structure->children) > 0) {
  786.                     $nav_structure->children[count($nav_structure->children)] = $bookmark_structure;
  787.                 }
  788.             }
  789.             else if ($links_style == 'flattened') {
  790.                 $bookmark_structure = suffusion_get_bookmark_structure(0, $links_tab_title, $links_tab_link, 0, $bookmarks_included, 'link');
  791.                 foreach ($bookmark_structure->children as $child_structure) {
  792.                     $nav_structure->children[count($nav_structure->children)] = $child_structure;
  793.                 }
  794.             }
  795.         }
  796.         else if ((strlen($entity) >= 5 && substr($entity, 0, 5) == 'menu-')) {
  797.             if (function_exists('wp_nav_menu')) {
  798.                 if ($menus_style == 'rolled-up') {
  799.                     foreach ($menus_included as $menu) {
  800.                         if ($menu->term_id == intval(substr($entity, 5)) && !in_array($menu->term_id, $processed_menus)) {
  801.                             $processed_menus[] = $menu->term_id;
  802.                             $menu_items = wp_get_nav_menu_items($menu->term_id);
  803.                             $menu_structure = suffusion_get_menu_structure(0, $menu->name, null, 1, $menu_items, 'menu');
  804.                             $nav_structure->children[] = $menu_structure;
  805.                         }
  806.                     }
  807.                 }
  808.                 else if ($menus_style == 'flattened') {
  809.                     foreach ($menus_included as $menu) {
  810.                         if ($menu->term_id == intval(substr($entity, 5)) && !in_array($menu->term_id, $processed_menus)) {
  811.                             $processed_menus[] = $menu->term_id;
  812.                             $menu_items = wp_get_nav_menu_items($menu->term_id);
  813.                             foreach ($menu_items as $menu_item) {
  814.                                 if ($menu_item->menu_item_parent == 0) {
  815.                                     $title = $menu_item->attr_title ? $menu_item->attr_title : $menu_item->title;
  816.                                     $child = suffusion_get_menu_structure($menu_item->ID, esc_html($title), $menu_item->url, 1, $menu_items, 'menu', $menu_item->target);
  817.                                     $nav_structure->children[] = $child;
  818.                                 }
  819.                             }
  820.                         }
  821.                     }
  822.                 }
  823.             }
  824.         }
  825.     }
  826.     $retStr = suffusion_parse_nav_structure($nav_structure, $position);
  827.     return $retStr;
  828. }
  829.  
  830. function create_nav($echo = true, $type = "pages", $position = 'main', $page_option = 'suf_nav_pages', $cats_option = 'suf_nav_cats', $links_option = 'suf_nav_links', $menus_option = 'suf_nav_menus') {
  831.     $retStr = "";
  832.     if ($type == "pages") {
  833.         $retStr = create_nav_for_all($position, $page_option, $cats_option, $links_option, $menus_option);
  834.     }
  835.     if ($echo) {
  836.         echo $retStr;
  837.     }
  838.     return $retStr;
  839. }
  840.  
  841. /**
  842.  * If more than one page exists, return TRUE.
  843.  */
  844. function show_page_nav() {
  845.     global $wp_query;
  846.     return ($wp_query->max_num_pages > 1);
  847. }
  848. /**
  849.  * If more than one post exists, return TRUE.
  850.  */
  851. function suffusion_post_count() {
  852.     $post_type = get_query_var('post_type');
  853.     if (!isset($post_type) || $post_type == null || $post_type == '') {
  854.         $post_type = 'post';
  855.     }
  856.     $post_count = wp_count_posts($post_type);
  857.     return $post_count->publish;
  858. }
  859.  
  860. function check_integer($val) {
  861.     return ($val !== true) && ((string)abs((int) $val)) === ((string) ltrim($val, '-0'));
  862. }
  863.  
  864. function get_size_from_field($val, $default) {
  865.     $ret = $default;
  866.     if (substr(trim($val), -2) == "px") {
  867.         $test_str = trim(substr(trim($val), 0, strlen(trim($val)) - 2));
  868.         if (check_integer($test_str)) {
  869.             $ret = $test_str."px";
  870.         }
  871.     }
  872.     else if (check_integer(trim($val))) {
  873.         $ret = trim($val)."px";
  874.     }
  875.     return $ret;
  876. }
  877.  
  878. function get_numeric_size_from_field($val, $default) {
  879.     $ret = $default;
  880.     if (substr(trim($val), -2) == "px") {
  881.         $test_str = trim(substr(trim($val), 0, strlen(trim($val)) - 2));
  882.         if (check_integer($test_str)) {
  883.             $ret = (int)$test_str;
  884.         }
  885.     }
  886.     else if (check_integer(trim($val))) {
  887.         $ret = (int)(trim($val));
  888.     }
  889.     return $ret;
  890. }
  891.  
  892. function suffusion_get_formatted_sbtab_array($prefix, $spawn = true) {
  893.     global $sidebar_tabs, $spawned_options;
  894.  
  895.     foreach ($sidebar_tabs as $tab => $tab_options) {
  896.         $spawned_options[count($spawned_options)] = array('id' => $prefix.'_'.$tab, 'type' => 'checkbox', 'parent' => $prefix, 'std' => 'false');
  897.     }
  898.     return $sidebar_tabs;
  899. }
  900.  
  901. function suffusion_get_category_structure($id, $title, $link, $depth, $exclusion_list = array(), $type = 'cat') {
  902.     $category_structure = new Suf_Navigation_Structure($id, $title, $link, $depth, $type);
  903.     $category_structure->children = array();
  904.     $exclude_categories = array();
  905.     foreach ($exclusion_list as $category) {
  906.         $exclude_categories[count($exclude_categories)] = $category->cat_ID;
  907.     }
  908.     $exclude = implode(',', $exclude_categories);
  909.     $child_cats = get_categories(array('type' => 'post', 'child_of' => $id, 'parent' => $id, 'exclude' => $exclude));
  910.     $child_cat_ids = array();
  911.     if ($child_cats) {
  912.         foreach ($child_cats as $child_cat) {
  913.             $child_cat_ids[count($child_cat_ids)] = $child_cat->cat_ID;
  914.         }
  915.     }
  916.     $lang_specific_cat_ids = wpml_lang_object_ids($child_cat_ids, 'category');
  917.     if (count($lang_specific_cat_ids) != 0) {
  918.         $include = implode(',',$lang_specific_cat_ids);
  919.         if (function_exists('mycategoryorder')) {
  920.             $order_by = 'order';
  921.         }
  922.         else {
  923.             $order_by = 'name';
  924.         }
  925.         $child_cats = get_categories(array('type' => 'post', 'include' => $include, 'orderby' => $order_by));
  926.         if ($child_cats == null) { $child_cats = array(); }
  927.         $child_depth = $depth + 1;
  928.         foreach ($child_cats as $child_cat) {
  929.             $child_cat_link = get_category_link($child_cat->cat_ID);
  930.             $child = suffusion_get_category_structure($child_cat->cat_ID, $child_cat->cat_name, $child_cat_link, $child_depth, $exclusion_list);
  931.             $category_structure->children[count($category_structure->children)] = $child;
  932.         }
  933.     }
  934.     return $category_structure;
  935. }
  936.  
  937. function suffusion_get_category_ancestor_count($cat, $counter) {
  938.     if ($cat == null || !$cat) {
  939.         return $counter;
  940.     }
  941.     $count = $counter;
  942.     if ($cat->category_parent) {
  943.         $parent = get_category($cat->category_parent);
  944.         $count = suffusion_get_category_ancestor_count($parent, $count + 1);
  945.     }
  946.     return $count;
  947. }
  948.  
  949. function suffusion_get_bookmark_structure($id, $title, $link, $depth, $inclusion_list = array(), $type = 'link', $target = false) {
  950.     $bookmark_structure = new Suf_Navigation_Structure($id, $title, $link, $depth, $type, $target);
  951.     $bookmark_structure->children = array();
  952.     $child_depth = $depth + 1;
  953.     foreach ($inclusion_list as $bookmark) {
  954.         $child = suffusion_get_bookmark_structure($bookmark->link_id, $bookmark->link_name, $bookmark->link_url, $child_depth, array(), 'link', $bookmark->link_target);
  955.         $bookmark_structure->children[count($bookmark_structure->children)] = $child;
  956.     }
  957.     return $bookmark_structure;
  958. }
  959.  
  960. function suffusion_get_menu_structure($id, $title, $link, $depth, $inclusions, $type = 'menu', $target = false) {
  961.     $menu_structure = new Suf_Navigation_Structure($id, $title, $link, $depth, $type, $target);
  962.     $menu_structure->children = array();
  963.     $child_depth = $depth + 1;
  964.     foreach ($inclusions as $menu_item) {
  965.         if ($menu_item->menu_item_parent == $id) {
  966.             $title = $menu_item->attr_title ? $menu_item->attr_title : $menu_item->title;
  967.             $child = suffusion_get_menu_structure($menu_item->ID, esc_html($title), $menu_item->url, $child_depth, $inclusions, 'menu-item', $menu_item->target);
  968.             $menu_structure->children[] = $child;
  969.         }
  970.     }
  971.     return $menu_structure;
  972. }
  973.  
  974. function suf_get_allowed_pages($prefix) {
  975.     global $suffusion_options;
  976.     $allowed = array();
  977.     if (isset($suffusion_options[$prefix])) {
  978.         $selected = $suffusion_options[$prefix];
  979.         if (!empty($selected)) {
  980.             $selected_pages = explode(',', $selected);
  981.             if (is_array($selected_pages) && count($selected_pages) > 0) {
  982.                 foreach ($selected_pages as $page_id) {
  983.                     $page = get_page($page_id);
  984.                     $allowed[count($allowed)] = $page;
  985.                 }
  986.             }
  987.         }
  988.     }
  989.     return $allowed;
  990. }
  991.  
  992. function suf_get_formatted_link_array($prefix, $spawn = true) {
  993.     global $spawned_options, $link_array;
  994.     $ret = array();
  995.     $args = array(
  996.         "order" => "ASC",
  997.         "orderby" => 'name',
  998.     );
  999.     $links = get_bookmarks($args);
  1000.     if ($links == null) {
  1001.         $links = array();
  1002.     }
  1003.     foreach ($links as $link) {
  1004.         if ($link_array == null) {
  1005.             $ret[$link->link_id] = array("title" => $link->link_name);
  1006.         }
  1007.         if ($spawn) {
  1008.             $spawned_options[count($spawned_options)] = array(  "id" => $prefix."_".$link->link_id,
  1009.                                                                 "type" => "checkbox",
  1010.                                                                 "parent" => $prefix,
  1011.                                                                 "std" => "false");
  1012.         }
  1013.     }
  1014.     if ($link_array == null) {
  1015.         $link_array = $ret;
  1016.         return $link_array;
  1017.     }
  1018.     else {
  1019.         return $link_array;
  1020.     }
  1021. }
  1022.  
  1023. function suf_get_formatted_wp_menu_array($prefix, $spawn = true) {
  1024.     global $spawned_options, $menu_array;
  1025.     $ret = array();
  1026.     if (!function_exists('wp_nav_menu')) {
  1027.         return $ret;
  1028.     }
  1029.  
  1030.     $menus = wp_get_nav_menus();
  1031.     if ($menus == null) {
  1032.         $menus = array();
  1033.     }
  1034.  
  1035.     foreach ($menus as $menu) {
  1036.         if ($menu_array == null) {
  1037.             $ret[$menu->term_id] = array("title" => $menu->name);
  1038.         }
  1039.         if ($spawn) {
  1040.             $spawned_options[count($spawned_options)] = array(  "id" => $prefix."_".$menu->term_id,
  1041.                                                                 "type" => "checkbox",
  1042.                                                                 "parent" => $prefix,
  1043.                                                                 "std" => "false");
  1044.         }
  1045.     }
  1046.  
  1047.     if ($menu_array == null) {
  1048.         $menu_array = $ret;
  1049.         return $menu_array;
  1050.     }
  1051.     else {
  1052.         return $menu_array;
  1053.     }
  1054. }
  1055.  
  1056. /* Functions for WPML compatibility */
  1057. function wpml_lang_object_id($id, $type){
  1058.     if(function_exists('icl_object_id')) {
  1059.         return icl_object_id($id, $type, true);
  1060.     } else {
  1061.         return $id;
  1062.     }
  1063. }
  1064.  
  1065. function wpml_lang_object_ids($ids_array, $type) {
  1066.     if(function_exists('icl_object_id')) {
  1067.         $res = array();
  1068.         foreach ($ids_array as $id) {
  1069.             $xlat = icl_object_id($id, $type, false);
  1070.             if (!is_null($xlat) && !in_array($xlat, $res)) {
  1071.                 $res[] = $xlat;
  1072.             }
  1073.         }
  1074.         return $res;
  1075.     }
  1076.     else {
  1077.         return $ids_array;
  1078.     }
  1079. }
  1080. /* End functions for WPML compatibility */
  1081.  
  1082. function suffusion_tab_array_prepositions() {
  1083.     global $sidebar_tabs;
  1084.     $ret = array();
  1085.     foreach ($sidebar_tabs as $key => $value) {
  1086.         $ret[count($ret)] = array('key' => $key, 'value' => $value['title']);
  1087.     }
  1088.     return $ret;
  1089. }
  1090.  
  1091. function suffusion_nav_entity_prepositions() {
  1092.     $ret = array(array('key' => 'pages', 'value' => 'Pages'), array('key' => 'categories', 'value' => 'Categories'), array('key' => 'links', 'value' => 'Links'));
  1093.     return $ret;
  1094. }
  1095.  
  1096. function suf_get_formatted_options_array($prefix, $options_array) {
  1097.     global $spawned_options;
  1098.     $ret = array();
  1099.     foreach ($options_array as $option_key => $option_value) {
  1100.         $ret[$option_key] = array('title' => $option_value, 'depth' => 1);
  1101.         $spawned_options[] = array('id' => $prefix.'_'.$option_key, 'type' => 'checkbox', 'parent' => $prefix, 'std' => 'false');
  1102.     }
  1103.     return $ret;
  1104. }
  1105.  
  1106. function suf_get_entity_order($entity_order, $entity_type='nav') {
  1107.     $ret = array();
  1108.     if (is_array($entity_order)) {
  1109.         foreach ($entity_order as $element) {
  1110.             $ret[] = $element['key'];
  1111.         }
  1112.         $ret = implode(',',$ret);
  1113.     }
  1114.     else {
  1115.         $defaults = suffusion_entity_prepositions($entity_type);
  1116.         $ret = explode(',', $entity_order);
  1117.         $default_array = array();
  1118.         foreach ($defaults as $default) {
  1119.             $default_array[] = $default['key'];
  1120.             if (!in_array($default['key'], $ret)) {
  1121.                 $ret[] = $default['key'];
  1122.             }
  1123.         }
  1124.         $ret_array = array();
  1125.         foreach ($ret as $ret_entry) {
  1126.             if (in_array($ret_entry, $default_array)) {
  1127.                 $ret_array[] = $ret_entry;
  1128.             }
  1129.         }
  1130.         $ret = implode(',', $ret_array);
  1131.     }
  1132.     return $ret;
  1133. }
  1134.  
  1135. function suffusion_update_available($theme) {
  1136.     static $themes_update;
  1137.     if ( !isset($themes_update) )
  1138.         $themes_update = get_transient('update_themes');
  1139.  
  1140.     if ( is_object($theme) && isset($theme->stylesheet) )
  1141.         $stylesheet = $theme->stylesheet;
  1142.     elseif ( is_array($theme) && isset($theme['Stylesheet']) )
  1143.         $stylesheet = $theme['Stylesheet'];
  1144.     else
  1145.         return false; //No valid info passed.
  1146.  
  1147.     if (isset($themes_update->response[ $stylesheet ])) {
  1148.         return true;
  1149.     }
  1150.     return false;
  1151. }
  1152.  
  1153. function suffusion_get_full_content_count() {
  1154.     global $suffusion, $suf_category_fc_number, $suf_author_fc_number, $suf_tag_fc_number, $suf_search_fc_number, $suf_archive_fc_number, $suf_index_fc_number, $suf_pop_fc_number;
  1155.     $context = $suffusion->get_context();
  1156.     $full_post_count = 0;
  1157.     if (in_array('category', $context)) {
  1158.         $full_post_count = (int)$suf_category_fc_number;
  1159.     }
  1160.     else if (in_array('author', $context)) {
  1161.         $full_post_count = (int)$suf_author_fc_number;
  1162.     }
  1163.     else if (in_array('tag', $context)) {
  1164.         $full_post_count = (int)$suf_tag_fc_number;
  1165.     }
  1166.     else if (in_array('search', $context)) {
  1167.         $full_post_count = (int)$suf_search_fc_number;
  1168.     }
  1169.     else if (in_array('date', $context)) {
  1170.         $full_post_count = (int)$suf_archive_fc_number;
  1171.     }
  1172.     else if (in_array('home', $context) || in_array('blog', $context)) {
  1173.         $full_post_count = (int)$suf_index_fc_number;
  1174.     }
  1175.     else if (in_array('page', $context)) {
  1176.         if (in_array('posts.php', $context)) {
  1177.             $full_post_count = (int)$suf_pop_fc_number;
  1178.         }
  1179.     }
  1180.     return $full_post_count;
  1181. }
  1182.  
  1183. function suffusion_nr_entity_prepositions() {
  1184.     $ret = array(array('key' => 'current', 'value' => 'Currently Reading'), array('key' => 'unread', 'value' => 'Not Yet Read'), array('key' => 'completed', 'value' => 'Completed'));
  1185.     return $ret;
  1186. }
  1187.  
  1188. function suffusion_entity_prepositions($entity_type = 'nav') {
  1189.     if ($entity_type == 'nav') {
  1190.         $ret = array(array('key' => 'pages', 'value' => 'Pages'), array('key' => 'categories', 'value' => 'Categories'), array('key' => 'links', 'value' => 'Links'));
  1191.         if (function_exists('wp_get_nav_menus')) {
  1192.             $menus = wp_get_nav_menus();
  1193.             if ($menus == null) {
  1194.                 $menus = array();
  1195.             }
  1196.  
  1197.             foreach ($menus as $menu) {
  1198.                 $ret[] = array('key' => "menu-".$menu->term_id, "value" => $menu->name);
  1199.             }
  1200.         }
  1201.     }
  1202.     else if ($entity_type == 'nr') {
  1203.         $ret = array(array('key' => 'current', 'value' => 'Currently Reading'), array('key' => 'unread', 'value' => 'Not Yet Read'), array('key' => 'completed', 'value' => 'Completed'));
  1204.     }
  1205.     return $ret;
  1206. }
  1207.  
  1208. function suffusion_get_unified_options() {
  1209.     global $options, $suffusion_options, $skin_settings, $theme_name, $default_theme_name;
  1210.     if ($theme_name == 'root') {
  1211.         $skin = $default_theme_name;
  1212.     }
  1213.     else {
  1214.         $skin = $theme_name;
  1215.     }
  1216.  
  1217.     if (file_exists(STYLESHEETPATH."/skins/$skin/settings.php")) {
  1218.         include_once(STYLESHEETPATH."/skins/$skin/settings.php");
  1219.     }
  1220.     else if (file_exists(TEMPLATEPATH."/skins/$skin/settings.php")) {
  1221.         include_once(TEMPLATEPATH."/skins/$skin/settings.php");
  1222.     }
  1223.     $unified_options_array = array();
  1224.     foreach ($options as $value) {
  1225.         if (isset($value['id'])) {
  1226.             if (!isset($suffusion_options[$value['id']])) {
  1227.                 if (is_array($skin_settings) && isset($skin_settings[$value['id']])) {
  1228.                     $unified_options_array[$value['id']] = $skin_settings[$value['id']];
  1229.                 }
  1230.                 else if (isset($value['std'])) {
  1231.                     $unified_options_array[$value['id']] = $value['std'];
  1232.                 }
  1233.             }
  1234.             else if (isset($value['std']) && $suffusion_options[$value['id']] == $value['std']) {
  1235.                 if (is_array($skin_settings) && isset($skin_settings[$value['id']])) {
  1236.                     $unified_options_array[$value['id']] = $skin_settings[$value['id']];
  1237.                 }
  1238.                 else {
  1239.                     $unified_options_array[$value['id']] = $suffusion_options[$value['id']];
  1240.                 }
  1241.             }
  1242.             else {
  1243.                 $unified_options_array[$value['id']] = $suffusion_options[$value['id']];
  1244.             }
  1245.         }
  1246.     }
  1247.     return $unified_options_array;
  1248. }
  1249.  
  1250. if (function_exists('add_theme_support')) {
  1251.     add_theme_support('post-thumbnails');
  1252.     add_theme_support('nav-menus'); // For Beta and RC versions of WP 3.0
  1253.     add_theme_support('menus'); // For the final release version of WP 3.0
  1254.     add_theme_support('automatic-feed-links');
  1255. }
  1256.  
  1257. require_once (TEMPLATEPATH . "/suffusion.php");
  1258. include_once (TEMPLATEPATH . "/widget-areas.php");
  1259. include_once (TEMPLATEPATH . "/functions/actions.php");
  1260. include_once (TEMPLATEPATH . "/functions/filters.php");
  1261. include_once (TEMPLATEPATH . "/functions/shortcodes.php");
  1262.  
  1263. if (isset($suffusion_options['suf_custom_php_file'])) {
  1264.     $custom_php_file = $suffusion_options['suf_custom_php_file'];
  1265.     $custom_php_file = stripslashes($custom_php_file);
  1266.     if (substr($custom_php_file, 0, 1) == "/") {
  1267.         $custom_php_file = substr($custom_php_file, 1);
  1268.     }
  1269.     if (trim($custom_php_file) != "" && file_exists(WP_CONTENT_DIR."/".$custom_php_file)) {
  1270.         include_once(WP_CONTENT_DIR."/".$custom_php_file);
  1271.     }
  1272. }
  1273.  
  1274. $suffusion_theme_hierarchy = array(
  1275.     'light-theme-gray-1' => array('style.css', 'skins/light-theme-gray-1/style.css'),
  1276.     'light-theme-gray-2' => array('style.css', 'skins/light-theme-gray-2/style.css'),
  1277.     'light-theme-green' => array('style.css', 'skins/light-theme-green/style.css'),
  1278.     'light-theme-orange' => array('style.css', 'skins/light-theme-orange/style.css'),
  1279.     'light-theme-pale-blue' => array('style.css', 'skins/light-theme-pale-blue/style.css'),
  1280.     'light-theme-purple' => array('style.css', 'skins/light-theme-purple/style.css'),
  1281.     'light-theme-red' => array('style.css', 'skins/light-theme-red/style.css'),
  1282.     'light-theme-royal-blue' => array('style.css', 'skins/light-theme-royal-blue/style.css'),
  1283.     'dark-theme-gray-1' => array('style.css', 'skins/light-theme-gray-1/style.css', 'dark-style.css', 'skins/dark-theme-gray-1/style.css'),
  1284.     'dark-theme-gray-2' => array('style.css', 'skins/light-theme-gray-2/style.css', 'dark-style.css', 'skins/dark-theme-gray-2/style.css'),
  1285.     'dark-theme-green' => array('style.css', 'skins/light-theme-green/style.css', 'dark-style.css', 'skins/dark-theme-green/style.css'),
  1286.     'dark-theme-orange' => array('style.css', 'skins/light-theme-orange/style.css', 'dark-style.css', 'skins/dark-theme-orange/style.css'),
  1287.     'dark-theme-pale-blue' => array('style.css', 'skins/light-theme-pale-blue/style.css', 'dark-style.css', 'skins/dark-theme-pale-blue/style.css'),
  1288.     'dark-theme-purple' => array('style.css', 'skins/light-theme-purple/style.css', 'dark-style.css', 'skins/dark-theme-purple/style.css'),
  1289.     'dark-theme-red' => array('style.css', 'skins/light-theme-red/style.css', 'dark-style.css', 'skins/dark-theme-red/style.css'),
  1290.     'dark-theme-royal-blue' => array('style.css', 'skins/light-theme-royal-blue/style.css', 'dark-style.css', 'skins/dark-theme-royal-blue/style.css'),
  1291.     'minima' => array('style.css', 'skins/minima/style.css'),
  1292. );
  1293.  
  1294. $suffusion = new Suffusion();
  1295. $suffusion->init();
  1296. ?>
Advertisement
Add Comment
Please, Sign In to add comment