soundmap_theme/functions.php
2016-11-29 01:18:17 +01:00

388 lines
14 KiB
PHP

<?php
add_action( 'after_setup_theme', 'soundmap_theme_setup' );
add_action('wp_ajax_soundmap_theme_get_post', 'soundmap_theme_get_post');
add_action('wp_ajax_nopriv_soundmap_theme_get_post', 'soundmap_theme_get_post');
function soundmap_theme_get_post(){
if (!isset($_POST['post_id']))
die();
$args = array(
'include' => $_POST['post_id'],
'post_type' => 'marker'
);
$id = $_POST['post_id'];
$title = get_the_title($id);
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content);
$content = str_replace(']]>', ']]&gt;', $content);
$autor = get_marker_author($id);
$fecha = get_marker_date($id);
$img = "";
if(has_post_thumbnail($id)){
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'large');
$img = '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" class="cboxElement" >';
$attr = array(
'class' => "colorbox-$marker_id",
);
$img .= get_the_post_thumbnail($id, 'thumbnail', $attr);
$img .= '</a>';
$img .= '<script type="text/javascript">colorboxSelector();</script>';
}
$autort = __('Author', 'soundmap');
$fechat = __('Date', 'soundmap');
$ret = "<div id='{$id}'><h2 class='post-title'>{$title}</h2><div>{$img}<p>{$fechat}: {$fecha}</p><p>{$autort}: {$autor}</p><p>{$content}</p></div>";
echo $ret;
die();
}
if ( ! function_exists( 'soundmap_theme_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* To override soundmap_theme_setup() in a child theme, add your own soundmap_theme_setup to your child theme's
* functions.php file.
*
* @uses load_theme_textdomain() For translation/localization support.
* @uses add_editor_style() To style the visual editor.
* @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats.
* @uses register_nav_menus() To add support for navigation menus.
* @uses add_custom_background() To add support for a custom background.
* @uses add_custom_image_header() To add support for a custom header.
* @uses register_default_headers() To register the default custom header images provided with the theme.
* @uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* @since Twenty Eleven 1.0
*/
function soundmap_theme_setup() {
/* Make Twenty Eleven available for translation.
* Translations can be added to the /languages/ directory.
* If you're building a theme based on Twenty Eleven, use a find and replace
* to change 'soundmap_theme' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'soundmap_theme', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
add_theme_support('post-thumbnails');
// Add default posts and comments RSS feed links to <head>.
add_theme_support( 'automatic-feed-links' );
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'primary', __( 'Primary Menu', 'soundmap_theme' ) );
// Add support for a variety of post formats
add_theme_support( 'post-formats', array( 'link' ) );
}
endif; // soundmap_theme_setup
add_filter('wp_get_nav_menu_items','soundmap_theme_menu_modify_upload');
function soundmap_theme_menu_modify_upload( $items){
foreach ($items as $item) {
if ($item->xfn=='addnewfile'){
$item->url = insert_upload_form(__("Upload recording","soundmap_theme"),false);
$item->classes[]='thickbox';
}
}
return $items;
}
/**
* Sets the post excerpt length to 40 words.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*/
function soundmap_theme_excerpt_length( $length ) {
return 40;
}
//add_filter( 'excerpt_length', 'soundmap_theme_excerpt_length' );
/**
* Returns a "Continue Reading" link for excerpts
*/
function soundmap_theme_continue_reading_link() {
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'soundmap_theme' ) . '</a>';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and soundmap_theme_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*/
function soundmap_theme_auto_excerpt_more( $more ) {
return ' &hellip;' . soundmap_theme_continue_reading_link();
}
add_filter( 'excerpt_more', 'soundmap_theme_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*/
function soundmap_theme_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= soundmap_theme_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'soundmap_theme_custom_excerpt_more' );
/**
* Register our sidebars and widgetized areas. Also register the default Epherma widget.
*
* @since Twenty Eleven 1.0
*/
function soundmap_theme_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'soundmap_theme' ),
'id' => 'sidebar-1',
'before_widget' => '<li>',
'after_widget' => "</li>",
'before_title' => '<a href ="#">',
'after_title' => '</a>',
) );
register_sidebar( array(
'name' => __( 'Secondary Sidebar', 'soundmap_theme' ),
'id' => 'sidebar-2',
'description' => __( 'An optional widget area for your site', 'soundmap_theme' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s folding-sidebar">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Footer Area ', 'soundmap_theme' ),
'id' => 'sidebar-footer',
'description' => __( 'An optional widget area for your site footer', 'soundmap_theme' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s folding-sidebar">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Footer Area Three', 'soundmap_theme' ),
'id' => 'sidebar-5',
'description' => __( 'An optional widget area for your site footer', 'soundmap_theme' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_widget('WP_Widget_Extended_Links');
}
add_action( 'widgets_init', 'soundmap_theme_widgets_init' );
//add_filter( 'wp_nav_menu_items', 'soundmap_theme_add_search_box', 10, 2 );
function soundmap_theme_add_search_box ( $items, $args ) {
// only on primary menu
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li class="sbox">' . $searchform . '</li>';
return $items;
}
function soundmap_theme_options_init() {
// If we have no options in the database, let's add them now.
if ( false === soundmap_theme_get_theme_options() )
add_option( 'soundmap_theme_options', soundmap_theme_get_default_theme_options() );
register_setting(
'soundmap_theme', // Options group, see settings_fields() call in theme_options_render_page()
'soundmap_theme_options', // Database option, see soundmap_theme_get_theme_options()
'soundmap_theme_options_validate' // The sanitization callback, see soundmap_theme_theme_options_validate()
);
}
function soundmap_theme_get_theme_options() {
return get_option( 'soundmap_theme_options', soundmap_theme_get_default_theme_options() );
}
function soundmap_theme_get_default_theme_options() {
$default_theme_options = array(
'main-pages' => '0',
);
return $default_theme_options;
}
function soundmap_theme_options_render_page() {
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php printf( __( '%s Theme Options', 'soundmap_theme' ), get_current_theme() ); ?></h2>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<?php
settings_fields( 'soundmap_theme' );
$options = soundmap_theme_get_theme_options();
$default_options = soundmap_theme_get_default_theme_options();
?>
<table class="form-table">
<tr valign="top"><th scope="row"><?php _e( 'Pages:', 'soundmap_theme' ); ?></th>
<td>
<input type="text" name="soundmap_theme_options[main-pages]" id="main-pages" value="<?php echo esc_attr( $options['main-pages'] ); ?>" />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
add_action( 'admin_init', 'soundmap_theme_options_init' );
function soundmap_theme_options_add_page() {
$theme_page = add_theme_page(
__( 'Theme Options', 'soundmap_theme' ), // Name of page
__( 'Theme Options', 'soundmap_theme' ), // Label in menu
'edit_theme_options', // Capability required
'theme_options', // Menu slug, used to uniquely identify the page
'soundmap_theme_options_render_page' // Function that renders the options page
);
if ( ! $theme_page )
return;
}
function soundmap_theme_options_validate( $input ) {
$output = $defaults = soundmap_theme_get_default_theme_options();
$output['main-pages'] = $input['main-pages'];
return $output;
}
add_action( 'admin_menu', 'soundmap_theme_options_add_page' );
/**
* Links widget class
*
* @since 2.8.0
*/
class WP_Widget_Extended_Links extends WP_Widget {
function __construct() {
$widget_ops = array('description' => __( "Your blogroll",'soundmap_theme' ) );
parent::__construct('extended_links', __('Extended Links', 'soundmap_theme'), $widget_ops);
}
function widget( $args, $instance ) {
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$show_description = isset($instance['description']) ? $instance['description'] : false;
$show_name = isset($instance['name']) ? $instance['name'] : false;
$show_rating = isset($instance['rating']) ? $instance['rating'] : false;
$show_images = isset($instance['images']) ? $instance['images'] : true;
$category = isset($instance['category']) ? $instance['category'] : false;
if ( is_admin() && !$category ) {
// Display All Links widget as such in the widgets screen
echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget;
return;
}
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Links' ) : $instance['title'], $instance, $this->id_base);
echo $before_widget . $before_title. $title . $after_title;
echo '<ul>';
$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
wp_list_bookmarks(apply_filters('widget_links_args', array(
'title_before' => $before_title, 'title_after' => $after_title,
'category_before' => $before_widget, 'category_after' => $after_widget,
'show_images' => $show_images, 'show_description' => $show_description,
'show_name' => $show_name, 'show_rating' => $show_rating,
'category' => $category, 'class' => 'linkcat widget'
)));
echo '</ul>' . $after_widget;
}
function update( $new_instance, $old_instance ) {
$new_instance = (array) $new_instance;
$instance = array('title' => '', 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
foreach ( $instance as $field => $val ) {
if ( isset($new_instance[$field]) )
$instance[$field] = 1;
}
$instance['category'] = intval($new_instance['category']);
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function form( $instance ) {
//Defaults
$instance = wp_parse_args( (array) $instance, array( 'title' =>'', 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
$link_cats = get_terms( 'link_category');
$title = esc_attr( $instance['title'] );
?>
<p>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
<label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
<option value=""><?php _e('All Links'); ?></option>
<?php
foreach ( $link_cats as $link_cat ) {
echo '<option value="' . intval($link_cat->term_id) . '"'
. ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
. '>' . $link_cat->name . "</option>\n";
}
?>
</select></p>
<p>
<input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
<label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
<label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
<input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
<label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
</p>
<?php
}
}