PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/wp-content/themes/regulus/functions.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 751 lines | 665 code | 75 blank | 11 comment | 46 complexity | 7165bf6ec0b86fd07aed2bf88971ffd3 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $themecolors = array(
  3. 'bg' => 'ffffff',
  4. 'text' => '000000',
  5. 'link' => '333333'
  6. );
  7. $content_width = 460;
  8. add_theme_support( 'automatic-feed-links' );
  9. // Custom background
  10. add_custom_background();
  11. function regulus_custom_background() {
  12. if ( '' != get_background_color() && '' == get_background_image() ) { ?>
  13. <style type="text/css">
  14. body { background-image: none; }
  15. </style>
  16. <?php }
  17. }
  18. add_action( 'wp_head', 'regulus_custom_background' );
  19. // WIDGETS
  20. function regulus_widgets_init() {
  21. register_sidebars(1);
  22. register_sidebar_widget( __('Calendar'), 'bm_calendar', null, 'calendar' );
  23. }
  24. add_action('widgets_init', 'regulus_widgets_init');
  25. function regulus_add_theme_page() {
  26. if ( $_GET['page'] == basename(__FILE__) ) {
  27. // save settings
  28. if ( 'save' == $_REQUEST['action'] ) {
  29. update_option( 'regulus_name', $_REQUEST[ 'r_name' ] );
  30. update_option( 'regulus_email', $_REQUEST[ 'r_email' ] );
  31. update_option( 'regulus_about', $_REQUEST[ 'r_about' ] );
  32. update_option( 'regulus_headerImage', $_REQUEST[ 'r_headerImage' ] );
  33. update_option( 'regulus_colourScheme', $_REQUEST[ 'r_colourScheme' ] );
  34. update_option( 'regulus_headerImageURL', $_REQUEST[ 'r_headerImageURL' ] );
  35. if( isset( $_REQUEST[ 'r_calendar' ] ) ) { update_option( 'regulus_calendar', 1 ); } else { delete_option( 'regulus_calendar' ); }
  36. if( isset( $_REQUEST[ 'r_meta' ] ) ) { update_option( 'regulus_meta', 1 ); } else { delete_option( 'regulus_meta' ); }
  37. if( isset( $_REQUEST[ 'r_admin' ] ) ) { update_option( 'regulus_admin', 1 ); } else { delete_option( 'regulus_admin' ); }
  38. if( isset( $_REQUEST[ 'r_posts' ] ) ) { update_option( 'regulus_posts', 1 ); } else { delete_option( 'regulus_posts' ); }
  39. if( isset( $_REQUEST[ 'r_months' ] ) ) { update_option( 'regulus_months', 1 ); } else { delete_option( 'regulus_months' ); }
  40. if( isset( $_REQUEST[ 'r_excerpt' ] ) ) { update_option( 'regulus_excerpt', 1 ); } else { delete_option( 'regulus_excerpt' ); }
  41. if( isset( $_REQUEST[ 'r_author' ] ) ) { update_option( 'regulus_author', 1 ); } else { delete_option( 'regulus_author' ); }
  42. if( isset( $_REQUEST[ 'r_linkcat' ] ) ) { update_option( 'regulus_linkcat', 1 ); } else { delete_option( 'regulus_linkcat' ); }
  43. if( isset( $_REQUEST[ 'r_sidealign' ] ) ) { update_option( 'regulus_sidealign', 1 ); } else { delete_option( 'regulus_sidealign' ); }
  44. if( isset( $_REQUEST[ 'r_heading' ] ) ) { update_option( 'regulus_heading', 1 ); } else { delete_option( 'regulus_heading' ); }
  45. // goto theme edit page
  46. header("Location: themes.php?page=functions.php&saved=true");
  47. die;
  48. // reset settings
  49. } else if( 'reset' == $_REQUEST['action'] ) {
  50. delete_option( 'regulus_name' );
  51. delete_option( 'regulus_email' );
  52. delete_option( 'regulus_about' );
  53. delete_option( 'regulus_headerImage' );
  54. delete_option( 'regulus_headerImageURL' );
  55. delete_option( 'regulus_colourScheme' );
  56. delete_option( 'regulus_calendar' );
  57. delete_option( 'regulus_meta' );
  58. delete_option( 'regulus_admin' );
  59. delete_option( 'regulus_posts' );
  60. delete_option( 'regulus_months' );
  61. delete_option( 'regulus_excerpt' );
  62. delete_option( 'regulus_author' );
  63. delete_option( 'regulus_linkcat' );
  64. delete_option( 'regulus_sidealign' );
  65. delete_option( 'regulus_heading' );
  66. // goto theme edit page
  67. header("Location: themes.php?page=functions.php&reset=true");
  68. die;
  69. }
  70. }
  71. add_theme_page("Theme Options", "Theme Options", 'edit_theme_options', basename(__FILE__), 'regulus_theme_page');
  72. }
  73. register_nav_menus( array(
  74. 'primary' => __( 'Primary Navigation' ),
  75. ) );
  76. function regulus_page_menu() { // fallback for primary navigation ?>
  77. <ul id="nav">
  78. <li <?php if ( is_front_page() ) { echo "class=\"current_page_item\""; } ?> ><a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Home' ); ?></a></li>
  79. <?php wp_list_pages( 'sort_column=menu_order&depth=1&title_li=' ); ?>
  80. </ul>
  81. <?php }
  82. function regulus_theme_page() {
  83. // --------------------------
  84. // regulus theme page content
  85. // --------------------------
  86. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>Options saved.</strong></p></div>';
  87. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>Options reset.</strong></p></div>';
  88. if ( $_REQUEST['super'] ) $superUser = true; else $superUser = false;
  89. ?>
  90. <div class="wrap">
  91. <h2>Regulus 2.1</h2>
  92. <p>Developed by Ben Gillbanks at Binary Moon. Check the <a href="http://www.binarymoon.co.uk/projects/regulus/">Regulus page for updates</a></p>
  93. <form method="post">
  94. <!-- blog layout options -->
  95. <style type="text/css">
  96. #colourSchemePreview { display:block; width:60%; height:40px; border:1px solid #000; }
  97. .CS_orange { background-color:#fc0; }
  98. .CS_green { background-color:#5f7; }
  99. .CS_blue { background-color:#bbf; }
  100. .CS_pink { background-color:#f9c; }
  101. .CS_white { background-color:#fff; }
  102. .CS_blend { background-color:#eef; }
  103. </style>
  104. <script>
  105. function updateHeaderImage( newpic ) {
  106. newimage = "<?php bloginfo('template_url') ?>/images/bg_" + newpic.value + ".jpg";
  107. document.getElementById( 'placeholder' ).src = newimage;
  108. return true;
  109. }
  110. function updateColour( newcolour ) {
  111. document.getElementById( 'colourSchemePreview' ).className = "CS_" + newcolour.value;
  112. }
  113. function updateHeaderImageSelect( form ) {
  114. text = form.r_headerImageURL.value;
  115. if ( text == "" ) {
  116. newpic = form.r_headerImage.value;
  117. newimage = "<?php bloginfo('template_url') ?>/images/bg_" + newpic + ".jpg";
  118. form.r_headerImage.disabled = 0;
  119. } else {
  120. newimage = form.r_headerImageURL.value;
  121. form.r_headerImage.disabled = 1;
  122. }
  123. document.getElementById( 'placeholder' ).src = newimage;
  124. }
  125. function defaultImage() {
  126. newimage = "<?php bloginfo('template_url') ?>/images/bg_disabled.jpg";
  127. document.getElementById( 'placeholder' ).src = newimage;
  128. }
  129. </script>
  130. <fieldset class="options">
  131. <legend>Header settings</legend>
  132. <p>To use your own header image enter the <strong>complete</strong> url into the Header Image URL box below - eg "http://www.yoursite.com/yourfile.jpg". To fill the header area completely you should make the image <strong>730</strong> pixels wide by <strong>140</strong> pixels high. Any smaller and the image will tile. To use one of the supplied images simply leave this box blank and select the image from the drop down.</p>
  133. <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  134. <?php
  135. regulus_th( "Header Image URL" );
  136. regulus_input( "r_headerImageURL", "text", "", get_settings( 'regulus_headerImageURL' ), "", "updateHeaderImageSelect( this.form )" );
  137. regulus_cth();
  138. $value = get_settings( 'regulus_headerImage' );
  139. if ( get_settings( 'regulus_headerImageURL' ) != "" ) {
  140. $disabled = true;
  141. }
  142. regulus_th( "Header Image" );
  143. if ( $disabled == true ) {
  144. echo "<select name=\"r_headerImage\" style=\"width:60%;\" onchange=\"updateHeaderImage( this )\" disabled=\"true\">";
  145. } else {
  146. echo "<select name=\"r_headerImage\" style=\"width:60%;\" onchange=\"updateHeaderImage( this )\">";
  147. }
  148. regulus_input( "r_headerImage", "option", "Regulus Classic", "1", $value );
  149. regulus_input( "r_headerImage", "option", "Electric Swirl", "2", $value );
  150. regulus_input( "r_headerImage", "option", "Smooth", "3", $value );
  151. regulus_input( "r_headerImage", "option", "Piece of the Puzzle", "4", $value );
  152. regulus_input( "r_headerImage", "option", "Skyline", "5", $value );
  153. regulus_input( "r_headerImage", "option", "Tech Style", "6", $value );
  154. regulus_input( "r_headerImage", "option", "Old and New", "7", $value );
  155. regulus_input( "r_headerImage", "option", "Bloom", "8", $value );
  156. // regulus_input( "r_headerImage", "option", "Random", "random", $value );
  157. echo "</select>";
  158. echo "<img id=\"placeholder\" onError=\"defaultImage();\" src=\"";
  159. bloginfo('template_url');
  160. if ( $disabled == true ) {
  161. echo "/images/bg_disabled.jpg\" width=\"60%\" />";
  162. } else {
  163. echo "/images/bg_$value.jpg\" width=\"60%\" />";
  164. }
  165. regulus_cth();
  166. regulus_th( "Header Text" );
  167. regulus_input( "r_heading", "checkbox", "Hide blog title and description? (Useful if you use the custom header image)", "1", get_settings( 'regulus_heading' ) );
  168. regulus_cth();
  169. ?>
  170. </table>
  171. </fieldset>
  172. <fieldset class="options">
  173. <legend>Blog Options</legend>
  174. <p>Change the way your blog looks and acts with the many blog settings below</p>
  175. <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  176. <?php
  177. $value = get_settings( 'regulus_colourScheme' );
  178. regulus_th( "Colour Scheme" );
  179. echo "<select name=\"r_colourScheme\" style=\"width:60%;\" onchange=\"updateColour( this )\">";
  180. regulus_input( "r_colourScheme", "option", "Orange Spice", "orange", $value );
  181. regulus_input( "r_colourScheme", "option", "Green Peace", "green", $value );
  182. regulus_input( "r_colourScheme", "option", "Calm Blue", "blue", $value );
  183. regulus_input( "r_colourScheme", "option", "Passionate Pink", "pink", $value );
  184. regulus_input( "r_colourScheme", "option", "Whitewash", "white", $value );
  185. regulus_input( "r_colourScheme", "option", "Blend it in", "blend", $value );
  186. echo "</select>";
  187. echo "<div id=\"colourSchemePreview\" class=\"CS_" . $value . "\"></div>";
  188. regulus_cth();
  189. if ( $superUser == true ) {
  190. regulus_th( "Post Options" );
  191. regulus_input( "r_excerpt", "checkbox", "Show Excerpts on the homepage (removes images and some other tags)?", "1", get_settings( 'regulus_excerpt' ) );
  192. // regulus_input( "r_author", "checkbox", "Show Post Author on the homepage?", "1", get_settings( 'regulus_author' ) );
  193. regulus_cth();
  194. }
  195. $display_regulus_sidebar = false;
  196. regulus_th( "Sidebar Options" );
  197. // if plugin installed
  198. if ( !function_exists('is_dynamic_sidebar') ) {
  199. $display_regulus_sidebar = true;
  200. } else {
  201. //plugin installed - is it used?
  202. if ( is_dynamic_sidebar() == false ) { $display_regulus_sidebar = true; }
  203. }
  204. // display regulus sidebar settings
  205. if ( $display_regulus_sidebar == true ) {
  206. regulus_input( "r_calendar", "checkbox", "Show Calendar?", "1", get_settings( 'regulus_calendar' ) );
  207. regulus_input( "r_meta", "checkbox", "Show meta content (login, site admin etc)?", "1", get_settings( 'regulus_meta' ) );
  208. regulus_input( "r_posts", "checkbox", "Show Recent Posts", "1", get_settings( 'regulus_posts' ) );
  209. regulus_input( "r_months", "checkbox", "Show all archive months", "1", get_settings( 'regulus_months' ) );
  210. regulus_input( "r_linkcat", "checkbox", "Use Link categories in blog roll?", "1", get_settings( 'regulus_linkcat' ) );
  211. }
  212. //if ( $superUser == true ) regulus_input( "r_admin", "checkbox", "Display Admin options (only for admin user when logged in)", "1", get_settings( 'regulus_admin' ) );
  213. regulus_input( "r_admin", "checkbox", "Display Admin options (only for admin user when logged in)", "1", get_settings( 'regulus_admin' ) );
  214. regulus_input( "r_sidealign", "checkbox", "Align sidebar to the left?", "1", get_settings( 'regulus_sidealign' ) );
  215. regulus_cth();
  216. ?>
  217. </table>
  218. </fieldset>
  219. <!-- personal options -->
  220. <fieldset class="options">
  221. <legend>Personal Information</legend>
  222. <p>The name and email address are used to highlight the comments you post. The about information will appear at the top of the right hand column (optional)</p>
  223. <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  224. <?php
  225. regulus_th( "Your Name" );
  226. regulus_input( "r_name", "text", "", get_settings( 'regulus_name' ) );
  227. regulus_cth();
  228. regulus_th( "Your Email Address" );
  229. regulus_input( "r_email", "text", "", get_settings( 'regulus_email' ) );
  230. regulus_cth();
  231. regulus_th( "About You" );
  232. regulus_input( "r_about", "textarea", "", get_settings( 'regulus_about' ) );
  233. regulus_cth();
  234. ?>
  235. </table>
  236. </fieldset>
  237. <?php
  238. regulus_input( "save", "submit", "", "Save Options" );
  239. ?>
  240. <input type="hidden" name="action" value="save" />
  241. </form>
  242. <form method="post">
  243. <fieldset class="options">
  244. <legend>Reset</legend>
  245. <p>If for some reason you want to uninstall Regulus then press the reset button to clean things up in the database.</p>
  246. <?php
  247. regulus_input( "reset", "submit", "", "Reset Options" );
  248. ?>
  249. </div>
  250. <input type="hidden" name="action" value="reset" />
  251. </form>
  252. <?php
  253. }
  254. add_action('admin_menu', 'regulus_add_theme_page');
  255. // helper functions
  256. // ----------------
  257. function regulus_input( $var, $type, $description = "", $value = "", $selected="", $onchange="" ) {
  258. // ------------------------
  259. // add a form input control
  260. // ------------------------
  261. echo "\n";
  262. switch( $type ){
  263. case "text":
  264. echo "<input name=\"$var\" id=\"$var\" type=\"$type\" style=\"width: 60%\" class=\"code\" value=\"$value\" onchange=\"$onchange\"/>";
  265. break;
  266. case "submit":
  267. echo "<p class=\"submit\"><input name=\"$var\" type=\"$type\" value=\"$value\" /></p>";
  268. break;
  269. case "option":
  270. if( $selected == $value ) { $extra = "selected=\"true\""; }
  271. echo "<option value=\"$value\" $extra >$description</option>";
  272. break;
  273. case "radio":
  274. if( $selected == $value ) { $extra = "checked=\"true\""; }
  275. echo "<label><input name=\"$var\" id=\"$var\" type=\"$type\" value=\"$value\" $extra /> $description</label><br/>";
  276. break;
  277. case "checkbox":
  278. if( $selected == $value ) { $extra = "checked=\"true\""; }
  279. echo "<label><input name=\"$var\" id=\"$var\" type=\"$type\" value=\"$value\" $extra /> $description</label><br/>";
  280. break;
  281. case "textarea":
  282. echo "<textarea name=\"$var\" id=\"$var\" style=\"width: 60%; height: 10em;\" class=\"code\">" . esc_textarea( $value ) . "</textarea>";
  283. break;
  284. }
  285. }
  286. function regulus_th( $title ) {
  287. // ------------------
  288. // add a table header
  289. // ------------------
  290. echo "<tr valign=\"top\">";
  291. echo "<th width=\"33%\" scope=\"row\">$title :</th>";
  292. echo "<td>";
  293. }
  294. function regulus_cth() {
  295. echo "</td>";
  296. echo "</tr>";
  297. }
  298. function bm_writeAbout() {
  299. $tempVar = get_settings( 'regulus_about' );
  300. // $tempVar = apply_filters( "the_content", $tempVar );
  301. $tempVar = bm_tidy_html( $tempVar );
  302. if( $tempVar != "" && $tempVar != "<br />\n" ) {
  303. echo "\t<li id=\"about\">";
  304. echo "\t\t<h2>About...</h2>\n";
  305. echo "\t\t" . $tempVar . "\n";
  306. echo "\t</li>\n";
  307. }
  308. }
  309. function bm_getProperty( $property ) {
  310. $value = get_settings( "regulus_" . $property );
  311. if( $value == "1" ) {
  312. return 1;
  313. } else {
  314. return 0;
  315. }
  316. }
  317. /*
  318. function bm_calendar() {
  319. echo "<li>";
  320. echo "<div id=\"wp-cal-container\">";
  321. get_calendar( 3 );
  322. echo "</div>";
  323. echo "</li>";
  324. }
  325. */
  326. function bm_calendar() {
  327. $options = get_option('widget_calendar');
  328. $title = $options['title'] ? '<h2>' . $options['title'] . '</h2>' : '';
  329. echo '<li>' . $title;
  330. echo '<div id="wp-cal-container">';
  331. get_calendar( 3 );
  332. echo '</div>';
  333. echo '</li>';
  334. }
  335. // -------------------------------------
  336. // format html for display in a web page
  337. // -------------------------------------
  338. function bm_tidy_html( $data ) {
  339. //remove dodgy characters
  340. $data = htmlspecialchars( $data );
  341. //remove carriage returns
  342. $data = str_replace( "\r", "", $data );
  343. //swap newlines for line breaks
  344. $data = str_replace( "\n", "<br />", $data );
  345. //replace <br>
  346. $data = str_replace( "<br>", "<br />", $data );
  347. //add paragraph tags
  348. $data = "<p>" . str_replace( "<br /><br />", "</p>\n<p>", $data ) . '</p>';
  349. //remove newline at the end of paragraphs
  350. $data = str_replace( "<br /></p>", "</p>", $data);
  351. //remove empty paragraphs
  352. $data = str_replace( "<p></p>", "", $data);
  353. $data = str_replace( "<p><br></p>", "", $data );
  354. $data = stripslashes( $data );
  355. return $data;
  356. }
  357. /*
  358. Plugin Name: WP Admin Bar 2
  359. Version: 2.2
  360. Plugin URI: http://mattread.com/archives/2005/03/wp-admin-bar-20/
  361. Description: Adds a small admin bar to the top of every page.
  362. Author: Matt Read
  363. Author URI: http://www.mattread.com/
  364. modified by Ben Gillbanks for use in Regulus theme
  365. url :http://www.binarymoon.co.uk
  366. */
  367. function bm_admin_bar()
  368. {
  369. global $user_level, $user_ID, $user_nickname, $posts, $author;
  370. $_authordata = get_userdata($posts[0]->post_author);
  371. get_currentuserinfo();
  372. if ( isset($user_level) ) {
  373. ?>
  374. <li>
  375. <h2>Admin Controls</h2>
  376. <ul id="wp-admin-bar">
  377. <?php
  378. // START Special case for write.
  379. $write_level = ( get_settings('new_users_can_blog') ) ? 0 : 1;
  380. //$write_text = ( is_single() OR is_page() ) ? 'Write' : '<strong>Write</strong>';
  381. $write_array = array( '<strong>Write</strong>', $write_level, 'post-new.php' );
  382. // END
  383. // START Special case for edit.
  384. // if (single OR page) AND (user level greater than author level OR is author OR is admin).
  385. $edit_level = ( ( is_single() OR is_page() ) AND ( $user_level > $_authordata->user_level OR $_authordata->ID == $user_ID OR $user_level == 10 ) ) ? 0 : 11;
  386. $edit_array = array('<strong>Edit</strong>',$edit_level,'post.php?action=edit&amp;post=' . $posts[0]->ID );
  387. // END
  388. $menu = array(
  389. array('Dashboard',8,'index.php','dashboard'),
  390. $write_array,
  391. $edit_array,
  392. );
  393. $menu = apply_filters( 'wp_admin_bard', $menu ); // user level 11 to skip
  394. foreach ( $menu as $item ) {
  395. if ($user_level >= $item[1]) {
  396. echo "\n\t<li><a href='".get_settings('siteurl')."/wp-admin/{$item[2]}' title='$item[3]'>{$item[0]}</a></li>";
  397. }
  398. }
  399. // Login and logout link.
  400. echo "\n\t<li>"; wp_loginout(); echo "</li>";
  401. echo "\n</ul>";
  402. echo "</li>";
  403. }
  404. }
  405. /*
  406. Plugin Name: Author Highlight
  407. Plugin URI: http://dev.wp-plugins.org/wiki/AuthorHighlight
  408. Description: Author Highlight is a plugin that prints out a user-specified class attribute if the comment is made by the specified author. It is useful if you would like to apply a different style to comments made by yourself.
  409. Version: 1.0
  410. Author: Jonathan Leighton
  411. Author URI: http://turnipspatch.com/
  412. Licence: This WordPress plugin is licenced under the GNU General Public Licence. For more information see: http://www.gnu.org/copyleft/gpl.html
  413. For documentation, please visit http://dev.wp-plugins.org/wiki/AuthorHighlight
  414. modified by Ben Gillbanks for use in Regulus theme
  415. url :http://www.binarymoon.co.uk
  416. */
  417. $bm_author_highlight = array(
  418. "class_name_highlight" => "highlighted",
  419. "class_name_else" => "",
  420. "email" => get_settings( 'regulus_email' ),
  421. "author" => get_settings( 'regulus_name' )
  422. );
  423. function bm_author_highlight() {
  424. global $comment;
  425. global $bm_author_highlight;
  426. if ( empty( $bm_author_highlight["author"] ) || empty( $bm_author_highlight["email"] ) || empty( $bm_author_highlight["class_name_highlight"] ) )
  427. return;
  428. $author = $comment -> comment_author;
  429. $email = $comment -> comment_author_email;
  430. if ( strcasecmp( $author, $bm_author_highlight[ "author" ] ) == 0 && strcasecmp( $email, $bm_author_highlight["email"]) == 0 ) {
  431. return $bm_author_highlight[ "class_name_highlight" ];
  432. } else {
  433. return $bm_author_highlight[ "class_name_else" ];
  434. }
  435. }
  436. /*
  437. Plugin Name: the_excerpt Reloaded
  438. Plugin URI: http://guff.szub.net/the-excerpt-reloaded
  439. Description: This mod of WordPress' template function the_excerpt() knows there is no spoon.
  440. Version: 0.2
  441. Author: Kaf Oseo
  442. Author URI: http://szub.net
  443. ~Changelog:
  444. 0.2 (16-Dec-2004)
  445. Plugin now attempts to correct *broken* HTML tags (those allowed
  446. through 'allowedtags') by using WP's balanceTags function. This
  447. is controlled through the 'fix_tags' parameter.
  448. Copyright (c) 2004
  449. Released under the GPL license
  450. http://www.gnu.org/licenses/gpl.txt
  451. This is a WordPress plugin (http://wordpress.org).
  452. WordPress is free software; you can redistribute it and/or modify
  453. it under the terms of the GNU General Public License as published
  454. by the Free Software Foundation; either version 2 of the License,
  455. or (at your option) any later version.
  456. This program is distributed in the hope that it will be useful,
  457. but WITHOUT ANY WARRANTY; without even the implied warranty of
  458. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  459. General Public License for more details.
  460. For a copy of the GNU General Public License, write to:
  461. Free Software Foundation, Inc.
  462. 59 Temple Place, Suite 330
  463. Boston, MA 02111-1307
  464. USA
  465. You can also view a copy of the HTML version of the GNU General
  466. Public License at http://www.gnu.org/copyleft/gpl.html
  467. modified by Ben Gillbanks for use in Regulus theme
  468. url :http://www.binarymoon.co.uk
  469. */
  470. function bm_the_excerpt_reloaded($excerpt_length=100, $allowedtags='<a>,<ul>,<li>,<blockquote>', $filter_type='excerpt', $use_more_link=false, $more_link_text="(more...)", $force_more_link=false, $fakeit=1, $fix_tags=true) {
  471. if (preg_match('%^content($|_rss)|^excerpt($|_rss)%', $filter_type)) {
  472. $filter_type = 'the_' . $filter_type;
  473. }
  474. $text = apply_filters($filter_type, bm_get_the_excerpt_reloaded($excerpt_length, $allowedtags, $use_more_link, $more_link_text, $force_more_link, $fakeit));
  475. $text = ($fix_tags) ? balanceTags($text) : $text;
  476. echo $text;
  477. }
  478. function bm_get_the_excerpt_reloaded($excerpt_length, $allowedtags, $use_more_link, $more_link_text, $force_more_link, $fakeit) {
  479. global $id, $post;
  480. $output = '';
  481. $output = $post->post_excerpt;
  482. if ( post_password_required() ) { // if there's a password
  483. $output = __( 'There is no excerpt because this is a protected post.' );
  484. return $output;
  485. }
  486. // If we haven't got an excerpt, make one.
  487. if ((($output == '') && ($fakeit == 1)) || ($fakeit == 2)) {
  488. $output = $post->post_content;
  489. $output = strip_tags($output, $allowedtags);
  490. $blah = explode(' ', $output);
  491. if (count($blah) > $excerpt_length) {
  492. $k = $excerpt_length;
  493. $use_dotdotdot = 1;
  494. } else {
  495. $k = count($blah);
  496. $use_dotdotdot = 0;
  497. }
  498. $excerpt = '';
  499. for ($i=0; $i<$k; $i++) {
  500. $excerpt .= $blah[$i] . ' ';
  501. }
  502. // Display "more" link (use css class 'more-link' to set layout).
  503. if (($use_more_link && $use_dotdotdot) || $force_more_link) {
  504. $excerpt .= "<div class=\"more-link\"> <a href=\"". get_permalink() . "#more-$id\">$more_link_text</a></div>";
  505. } else {
  506. $excerpt .= ($use_dotdotdot) ? '...' : '';
  507. }
  508. $output = $excerpt;
  509. } // end if no excerpt
  510. return $output;
  511. }
  512. ?>