Add Piratenkleider theme
Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
1171
wp-content/themes/piratenkleider/inc/business-cards.php
Normal file
1171
wp-content/themes/piratenkleider/inc/business-cards.php
Normal file
File diff suppressed because it is too large
Load Diff
2693
wp-content/themes/piratenkleider/inc/constants.php
Normal file
2693
wp-content/themes/piratenkleider/inc/constants.php
Normal file
File diff suppressed because it is too large
Load Diff
207
wp-content/themes/piratenkleider/inc/custom-fields.php
Normal file
207
wp-content/themes/piratenkleider/inc/custom-fields.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Metaboxes and adjustments for generell custom fields
|
||||
*/
|
||||
|
||||
|
||||
add_action( 'load-post.php', 'piratenkleider_metabox_cf_setup' );
|
||||
add_action( 'load-post-new.php', 'piratenkleider_metabox_cf_setup' );
|
||||
|
||||
|
||||
|
||||
/* Meta box setup function. */
|
||||
function piratenkleider_metabox_cf_setup() {
|
||||
|
||||
add_action( 'add_meta_boxes', 'piratenkleider_add_metabox_posts' );
|
||||
add_action( 'add_meta_boxes', 'piratenkleider_add_metabox_pages' );
|
||||
|
||||
/* Save post display option. */
|
||||
add_action( 'save_post', 'piratenkleider_save_metabox_displayoption', 10, 2 );
|
||||
/* Save sidecontent */
|
||||
add_action( 'save_post', 'piratenkleider_save_metabox_pagesidecontent', 10, 2 );
|
||||
/* Save subtitle */
|
||||
add_action( 'save_post', 'piratenkleider_save_metabox_untertitel', 10, 2 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Create one or more meta boxes to be displayed on the post editor screen. */
|
||||
|
||||
function piratenkleider_add_metabox_posts() {
|
||||
/* Displayoptionen */
|
||||
add_meta_box(
|
||||
'piratenkleider_metabox_displayoption',
|
||||
esc_html__( 'Display Option', 'piratenkleider' ),
|
||||
'piratenkleider_do_metabox_displayoption',
|
||||
'post','advanced','high'
|
||||
);
|
||||
|
||||
/* Subtitle */
|
||||
add_meta_box(
|
||||
'piratenkleider_metabox_untertitel',
|
||||
esc_html__( 'Subtitle', 'piratenkleider' ),
|
||||
'piratenkleider_do_metabox_untertitel',
|
||||
'post','normal','high'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
function piratenkleider_add_metabox_pages() {
|
||||
add_meta_box(
|
||||
'piratenkleider_metabox_pagesidecontent',
|
||||
esc_html__( 'Sidebar Text', 'piratenkleider' ),
|
||||
'piratenkleider_do_metabox_pagesidecontent',
|
||||
'page','advanced','default'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Subtitle*/
|
||||
function piratenkleider_do_metabox_untertitel( $object, $box ) {
|
||||
wp_nonce_field( basename( __FILE__ ), 'piratenkleider_metabox_untertitel_nonce' );
|
||||
$post_type = get_post_type( $object->ID);
|
||||
|
||||
|
||||
if ( !current_user_can( 'edit_post', $object->ID) )
|
||||
return;
|
||||
|
||||
$subtitle = get_post_meta( $object->ID, 'piratenkleider_subtitle', true );
|
||||
wphelper_form_text('piratenkleider_subtitle',$subtitle,
|
||||
__('Subtitle','piratenkleider'),
|
||||
__('Optional subtitle for entry, which is displayed below of the main title.','piratenkleider'),
|
||||
'');
|
||||
}
|
||||
|
||||
/* Save subtitles. */
|
||||
function piratenkleider_save_metabox_untertitel( $post_id, $post ) {
|
||||
/* Verify the nonce before proceeding. */
|
||||
if ( !isset( $_POST['piratenkleider_metabox_untertitel_nonce'] ) || !wp_verify_nonce( $_POST['piratenkleider_metabox_untertitel_nonce'], basename( __FILE__ ) ) )
|
||||
return $post_id;
|
||||
|
||||
|
||||
/* Check if the current user has permission to edit the post. */
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
|
||||
wphelper_save_standard('piratenkleider_subtitle', $_POST['piratenkleider_subtitle'], $post_id, 'text');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Display Options for posts and pages */
|
||||
function piratenkleider_do_metabox_displayoption( $object, $box ) {
|
||||
global $options;
|
||||
wp_nonce_field( basename( __FILE__ ), 'piratenkleider_metabox_displayoption_nonce' );
|
||||
|
||||
if ( !current_user_can( 'edit_post',$object->ID ) )
|
||||
return;
|
||||
|
||||
$sliderimage = get_post_meta( $object->ID, 'piratenkleider_slider_image', true );
|
||||
wphelper_form_image('piratenkleider_slider_image', $sliderimage,
|
||||
__('Slider Image','piratenkleider'),
|
||||
__('If you dont want to use the thumbnail (which uses normal formats) '
|
||||
. 'you can add here a special slider image, with proper sizes (1024 x 348 pixel). '
|
||||
. 'If this sizes dont fit, image will be cropped (mostyl from the edges up and down).','piratenkleider'),1024,348);
|
||||
|
||||
|
||||
$show_disclaimer = 0;
|
||||
|
||||
/* also handle field 'piratenkleider-show-post-disclaimer' for
|
||||
posts */
|
||||
$show_disclaimer = get_post_meta( $object->ID, 'piratenkleider-show-post-disclaimer', true );
|
||||
|
||||
if ((isset($options['post_disclaimer'])) && (strlen($options['post_disclaimer'])>0)) {
|
||||
wphelper_form_select('piratenkleider-show-post-disclaimer',
|
||||
array( 0 => __( "Do not show any disclaimer", 'piratenkleider' ),
|
||||
1 => __( "Display disclaimer before article", 'piratenkleider' ),
|
||||
2 => __( "Display disclaimer after article.", 'piratenkleider' ),
|
||||
3 => __( "Display disclaimer before and after article.", 'piratenkleider' ),
|
||||
),
|
||||
$show_disclaimer,
|
||||
__( "Show disclaimer", 'piratenkleider' ), '', 1,'' );
|
||||
|
||||
echo "<p>";
|
||||
_e( "Disclaimer Text", 'piratenkleider' );
|
||||
echo ":<br>";
|
||||
echo "<em>".$options['post_disclaimer']."</em></p>\n";
|
||||
|
||||
} else {
|
||||
echo "<p>";
|
||||
_e( "Notice: No disclaimer text defined. Please define a disclaimer text at first in theme options to use disclaimers.", 'piratenkleider' );
|
||||
echo "</p>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Save the meta box's post/page metadata. */
|
||||
function piratenkleider_save_metabox_displayoption( $post_id, $post ) {
|
||||
|
||||
/* Verify the nonce before proceeding. */
|
||||
if ( !isset( $_POST['piratenkleider_metabox_displayoption_nonce'] ) || !wp_verify_nonce( $_POST['piratenkleider_metabox_displayoption_nonce'], basename( __FILE__ ) ) )
|
||||
return $post_id;
|
||||
|
||||
|
||||
/* Check if the current user has permission to edit the post. */
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
|
||||
|
||||
if ($_POST['post_type'] == 'post') {
|
||||
wphelper_save_standard('piratenkleider-show-post-disclaimer', $_POST['piratenkleider-show-post-disclaimer'], $post_id, 'int');
|
||||
wphelper_save_standard('piratenkleider_slider_image', $_POST['piratenkleider_slider_image'], $post_id, 'int');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Display Options for posts and pages */
|
||||
function piratenkleider_do_metabox_pagesidecontent( $object, $box ) {
|
||||
wp_nonce_field( basename( __FILE__ ), 'piratenkleider_metabox_pagesidecontent_nonce' );
|
||||
$post_type = get_post_type( $object->ID);
|
||||
|
||||
if ( 'page' == $post_type ) {
|
||||
if ( !current_user_can( 'edit_page', $object->ID) )
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = get_post_meta( $object->ID, 'piratenkleider_sidebar-content', true );
|
||||
if ((!isset($text)) || (strlen($text) <2)) {
|
||||
$custom_fields = get_post_custom();
|
||||
if (isset($custom_fields['right_column'])) {
|
||||
$text = $custom_fields['right_column'][0];
|
||||
}
|
||||
}
|
||||
wphelper_form_textarea('piratenkleider_sidebar-content', $text, __( "Optional text for sidebar", 'piratenkleider' ), 60, 5, '');
|
||||
|
||||
}
|
||||
|
||||
/* Save the meta box's post/page metadata. */
|
||||
function piratenkleider_save_metabox_pagesidecontent( $post_id, $post ) {
|
||||
/* Verify the nonce before proceeding. */
|
||||
if ( !isset( $_POST['piratenkleider_metabox_pagesidecontent_nonce'] ) || !wp_verify_nonce( $_POST['piratenkleider_metabox_pagesidecontent_nonce'], basename( __FILE__ ) ) )
|
||||
return $post_id;
|
||||
|
||||
|
||||
/* Check if the current user has permission to edit the post. */
|
||||
if ( 'page' == $_POST['post_type'] ) {
|
||||
if ( !current_user_can( 'edit_page', $post_id ) )
|
||||
return;
|
||||
}
|
||||
|
||||
wphelper_save_standard('piratenkleider_sidebar-content', $_POST['piratenkleider_sidebar-content'], $post_id, 'textarea');
|
||||
|
||||
// Remove old values from version 2
|
||||
$oldval = get_post_meta( $post_id, 'right_column', true );
|
||||
if (isset($oldval)) {
|
||||
delete_post_meta( $post_id, 'right_column', $oldval );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
326
wp-content/themes/piratenkleider/inc/custom-posts.php
Normal file
326
wp-content/themes/piratenkleider/inc/custom-posts.php
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
/*
|
||||
* Custom Post Functionen zu Linktipps
|
||||
*/
|
||||
|
||||
|
||||
function piratenkleider_custom_post_linktipps() {
|
||||
$labels = array(
|
||||
'name' => __( 'Bookmarks', 'piratenkleider' ),
|
||||
'singular_name' => __( 'Bookmark', 'piratenkleider' ),
|
||||
|
||||
);
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'description' => __( 'Add or manage bookmark entries', 'piratenkleider' ),
|
||||
'public' => false,
|
||||
'show_ui' => true,
|
||||
'menu_position' => 8,
|
||||
'supports' => array( 'title' ),
|
||||
'exclude_from_search' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'linktipps','with_front' => FALSE),
|
||||
'capability_type' => 'post',
|
||||
'hierarchical' => false,
|
||||
'menu_icon' => '',
|
||||
);
|
||||
register_post_type( 'linktipps', $args );
|
||||
}
|
||||
add_action( 'init', 'piratenkleider_custom_post_linktipps' );
|
||||
|
||||
|
||||
function piratenkleider_taxonomies_linktipps() {
|
||||
$labels = array();
|
||||
$args = array(
|
||||
'labels' => $labels,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => false,
|
||||
);
|
||||
register_taxonomy( 'linktipp_category', 'linktipps', $args );
|
||||
}
|
||||
add_action( 'init', 'piratenkleider_taxonomies_linktipps' );
|
||||
|
||||
function piratenkleider_linktipp_metabox() {
|
||||
add_meta_box(
|
||||
'linktipp_metabox',
|
||||
__( 'Description and target URL', 'piratenkleider' ),
|
||||
'linktipp_metabox_content',
|
||||
'linktipps',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
function linktipp_metabox_content( $post ) {
|
||||
global $defaultoptions;
|
||||
global $options;
|
||||
global $post;
|
||||
|
||||
wp_nonce_field( plugin_basename( __FILE__ ), 'linktipp_metabox_content_nonce' );
|
||||
?>
|
||||
|
||||
|
||||
<p>
|
||||
<label for="linktipp_url"><?php _e( "Enter target URL", 'piratenkleider' ); ?>:</label>
|
||||
<br />
|
||||
<input class="widefat" type="text" name="linktipp_url"
|
||||
id="linktipp_url" value="<?php echo esc_attr( get_post_meta( $post->ID, 'linktipp_url', true ) ); ?>" size="30" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="linktipp_text"><?php _e( "Enter an optional and short target description", 'piratenkleider' ); ?>:</label>
|
||||
<br />
|
||||
<?php wp_editor( get_post_meta( $post->ID, 'linktipp_text', true ),
|
||||
'linktipp_text',
|
||||
array('media_buttons'=>false)); ?>
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<label for="linktipp_image"><?php _e( "Image for bookmark (either by media library or external URL)", 'piratenkleider' ); ?>:</label>
|
||||
|
||||
|
||||
<?php
|
||||
echo "(".$options['linktipp-thumbnail_width']."px x ".$options['linktipp-thumbnail_height']."px)\n<br>";
|
||||
|
||||
|
||||
$linktipp_imgid = get_post_meta( $post->ID, 'linktipp_imgid', true );
|
||||
$linktipp_image = get_post_meta( $post->ID, 'linktipp_image', true );
|
||||
|
||||
if (isset($linktipp_imgid) && ($linktipp_imgid>0)) {
|
||||
$image_attributes = wp_get_attachment_image_src( $linktipp_imgid, 'linktipp-thumb' );
|
||||
if (is_array($image_attributes)) {
|
||||
echo '<img id="linktipp_image-show" src="'.$image_attributes[0].'" width="'.$image_attributes[1].'" height="'.$image_attributes[2].'">';
|
||||
$linktipp_image = $image_attributes[0];
|
||||
}
|
||||
|
||||
} elseif (filter_var($linktipp_image, FILTER_VALIDATE_URL)) {
|
||||
echo '<img id="linktipp_image-show" src="'.$linktipp_image.'" alt="" style="width: '.$options['linktipp-thumbnail_width'].'px; height: auto;">';
|
||||
} else {
|
||||
echo '<img id="linktipp_image-show" src="'.$options['src-linktipp-thumbnail_default'].'" alt="" style="width: '.$options['linktipp-thumbnail_width'].'px; height: auto;">';
|
||||
}
|
||||
echo '<br /><span class="custom_default_image" style="display:none">'.$defaultoptions['src-linktipp-thumbnail_default'].'</span>';
|
||||
?>
|
||||
<input type="text" name="linktipp_image" size="50" id="linktipp_image"
|
||||
value="<?php echo $linktipp_image; ?>" />
|
||||
<input type="hidden" name="linktipp_imgid" id="linktipp_imgid"
|
||||
value="<?php echo $linktipp_imgid; ?>" />
|
||||
|
||||
|
||||
<input type="button" id="linktipp_image-button" class="button" value="<?php _e( "Select image", 'piratenkleider' ); ?>" />
|
||||
<small> <a href="#" class="custom_clear_image_button"><?php _e( "Remove image", 'piratenkleider' ); ?></a></small>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="linktipp_untertitel"><?php _e( "Optional pretitle", 'piratenkleider' ); ?>:</label>
|
||||
<br />
|
||||
<input class="widefat" type="text" name="linktipp_untertitel"
|
||||
id="linktipp_untertitel" value="<?php echo esc_attr( get_post_meta( $post->ID, 'linktipp_untertitel', true ) ); ?>" size="30" />
|
||||
</p>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
add_action( 'add_meta_boxes', 'piratenkleider_linktipp_metabox' );
|
||||
|
||||
|
||||
function linktipp_metabox_save( $post_id ) {
|
||||
if ( 'linktipps'!= get_post_type() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
||||
return;
|
||||
|
||||
if ( !wp_verify_nonce( $_POST['linktipp_metabox_content_nonce'], plugin_basename( __FILE__ ) ) )
|
||||
return;
|
||||
|
||||
if ( 'page' == $_POST['post_type'] ) {
|
||||
if ( !current_user_can( 'edit_page', $post_id ) )
|
||||
return;
|
||||
} else {
|
||||
if ( !current_user_can( 'edit_post', $post_id ) )
|
||||
return;
|
||||
}
|
||||
|
||||
$url = $_POST['linktipp_url'];
|
||||
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
update_post_meta( $post_id, 'linktipp_url', $url );
|
||||
}
|
||||
|
||||
$imgid = intval($_POST['linktipp_imgid']);
|
||||
if ($imgid) {
|
||||
update_post_meta( $post_id, 'linktipp_imgid', $imgid );
|
||||
} else {
|
||||
$urlimg = $_POST['linktipp_image'];
|
||||
if (filter_var($urlimg, FILTER_VALIDATE_URL)) {
|
||||
update_post_meta( $post_id, 'linktipp_image', $urlimg );
|
||||
} else {
|
||||
delete_post_meta( $post_id, 'linktipp_image' );
|
||||
}
|
||||
delete_post_meta( $post_id, 'linktipp_imgid' );
|
||||
}
|
||||
|
||||
if( isset( $_POST[ 'linktipp_text' ] ) ) {
|
||||
update_post_meta( $post_id, 'linktipp_text', $_POST[ 'linktipp_text' ] );
|
||||
}
|
||||
if( isset( $_POST[ 'linktipp_untertitel' ] ) ) {
|
||||
update_post_meta( $post_id, 'linktipp_untertitel', sanitize_text_field( $_POST[ 'linktipp_untertitel' ] ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
add_action( 'save_post', 'linktipp_metabox_save' );
|
||||
|
||||
|
||||
|
||||
function linktipp_display ($linktipp, $addclass = '') {
|
||||
global $options;
|
||||
if (!isset($linktipp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_id = isset( $linktipp->ID ) ? $linktipp->ID : 0;
|
||||
$title = get_the_title($linktipp);
|
||||
$linktipp_url = get_post_meta( $post_id, 'linktipp_url', true );
|
||||
$linktipp_imgid = get_post_meta( $post_id, 'linktipp_imgid', true );
|
||||
$linktipp_image = get_post_meta( $post_id, 'linktipp_image', true );
|
||||
$linktipp_untertitel = get_post_meta( $post_id, 'linktipp_untertitel', true );
|
||||
$linktipp_text = get_post_meta( $post_id, 'linktipp_text', true );
|
||||
if (isset($linktipp_untertitel) && !isset($title)) {
|
||||
$title = $linktipp_untertitel;
|
||||
$linktipp_untertitel = '';
|
||||
}
|
||||
$out = '';
|
||||
$out .= '<section class="p3-column linktipps '.$addclass.'" id="post-'.$post_id.'" >';
|
||||
$out .= "\n";
|
||||
if ($options['linktipps-titlepos']!=1) {
|
||||
$out .= '<header class="post-title p3-cbox">';
|
||||
if (mb_strlen(trim($linktipp_untertitel))>1) {
|
||||
$out .= '<div class="hgroup">';
|
||||
}
|
||||
if (($options['linktipps-subtitlepos']==0) && (mb_strlen(trim($linktipp_untertitel))>1)) {
|
||||
$out .= '<h3 class="subtitle">'.$linktipp_untertitel.'</h3>';
|
||||
}
|
||||
|
||||
$out .= '<h2>';
|
||||
if (($options['linktipps-linkpos']==0) || ($options['linktipps-linkpos']==3)) {
|
||||
$out .= '<a href="'.$linktipp_url.'" rel="bookmark">';
|
||||
}
|
||||
$out .= $title;
|
||||
if (($options['linktipps-linkpos']==0) || ($options['linktipps-linkpos']==3)) { $out .= '</a>'; }
|
||||
$out .= '</h2>';
|
||||
if (($options['linktipps-subtitlepos']==1) && (mb_strlen(trim($linktipp_untertitel))>1)) {
|
||||
$out .= '<h3 class="subtitle">'.$linktipp_untertitel.'</h3>';
|
||||
|
||||
}
|
||||
if (mb_strlen(trim($linktipp_untertitel))>1) {
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</header>';
|
||||
$out .= "\n";
|
||||
}
|
||||
$out .= '<div class="p3-column">';
|
||||
$out .= "\n";
|
||||
$out .= '<article class="post-entry p3-cbox">';
|
||||
$out .= "\n";
|
||||
if ($options['linktipps-linkpos']==1) {
|
||||
$out .= '<a href="'.$linktipp_url.'">';
|
||||
}
|
||||
|
||||
if (isset($linktipp_imgid) && ($linktipp_imgid>0)) {
|
||||
$image_attributes = wp_get_attachment_image_src( $linktipp_imgid, 'linktipp-thumb' );
|
||||
if (is_array($image_attributes)) {
|
||||
$out .= '<img src="'.$image_attributes[0].'" width="'.$image_attributes[1].'" height="'.$image_attributes[2].'" alt="'.trim(strip_tags($linktipp_text)).'">';
|
||||
}
|
||||
} elseif (isset($linktipp_image)) {
|
||||
$out .= '<img src="'.$linktipp_image.'" alt="">';
|
||||
}
|
||||
if ($options['linktipps-linkpos']==1) {
|
||||
$out .= '</a>';
|
||||
}
|
||||
if (isset($linktipp_text)) {
|
||||
$out .= piratenkleider_make_nice_links($linktipp_text);
|
||||
}
|
||||
$out .= "</article>\n";
|
||||
|
||||
if ($options['linktipps-titlepos']==1) {
|
||||
$out .= '<header class="post-title p3-cbox">';
|
||||
if (str_len(trim($linktipp_untertitel))>1) {
|
||||
$out .= '<div class="hgroup">';
|
||||
}
|
||||
if (($options['linktipps-subtitlepos']==0) && (str_len(trim($linktipp_untertitel))>1)) {
|
||||
$out .= '<h3 class="subtitle">'.$linktipp_untertitel.'</h3>';
|
||||
}
|
||||
$out .= '<h2>';
|
||||
if (($options['linktipps-linkpos']==0) || ($options['linktipps-linkpos']==3)) {
|
||||
$out .= '<a href="'.$linktipp_url.'" rel="bookmark">';
|
||||
}
|
||||
$out .= $title;
|
||||
if (($options['linktipps-linkpos']==0) || ($options['linktipps-linkpos']==3)) { $out .= '</a>'; }
|
||||
$out .= '</h2>';
|
||||
if (($options['linktipps-subtitlepos']==1) && (str_len(trim($linktipp_untertitel))>1)) {
|
||||
$out .= '<h3 class="subtitle">'.$linktipp_untertitel.'</h3>';
|
||||
}
|
||||
if (str_len(trim($linktipp_untertitel))>1) {
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</header>';
|
||||
$out .= "\n";
|
||||
}
|
||||
if (($options['linktipps-linkpos']==2) || ($options['linktipps-linkpos']==3)) {
|
||||
$out .= '<footer class="linktipp-url"><a class="extern" href="'.$linktipp_url.'">'.$linktipp_url.'</a></footer>';
|
||||
|
||||
}
|
||||
|
||||
$out .= "</div>\n";
|
||||
$out .= "</section>\n";
|
||||
return $out;
|
||||
|
||||
}
|
||||
|
||||
function linktipps_shortcode( $atts ) {
|
||||
extract( shortcode_atts( array(
|
||||
'cat' => '',
|
||||
'num' => 5,
|
||||
), $atts ) );
|
||||
$num = sanitize_text_field($num);
|
||||
$cat = sanitize_text_field($cat);
|
||||
if ((isset($cat)) && ( strlen(trim($cat))>0)) {
|
||||
$args = array(
|
||||
'post_type' => 'linktipps',
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'linktipp_category',
|
||||
'field' => 'slug',
|
||||
'terms' => $cat
|
||||
)
|
||||
),
|
||||
'posts_per_page' => $num,
|
||||
);
|
||||
} else {
|
||||
$args = array(
|
||||
'post_type' => 'linktipps',
|
||||
'posts_per_page' => $num,
|
||||
);
|
||||
}
|
||||
|
||||
$links = new WP_Query( $args );
|
||||
if( $links->have_posts() ) {
|
||||
$out = '';
|
||||
while ($links->have_posts() ) {
|
||||
$links->the_post();
|
||||
$out .= linktipp_display($links->post,'shortcode');
|
||||
|
||||
}
|
||||
wp_reset_postdata();
|
||||
|
||||
} else {
|
||||
$out = '<section class="shortcode linktipps"><p>';
|
||||
$out .= __('No bookmarks found.', 'piratenkleider');
|
||||
$out .= "</p></section>\n";
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
add_shortcode( 'linktipps', 'linktipps_shortcode' );
|
||||
|
||||
|
||||
547
wp-content/themes/piratenkleider/inc/forms.php
Normal file
547
wp-content/themes/piratenkleider/inc/forms.php
Normal file
@@ -0,0 +1,547 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Hilfereiche Funktionen für die Custom Fields
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_textarea' ) ) :
|
||||
function wphelper_form_textarea($name= '', $prevalue = '', $labeltext = '', $cols=60, $rows=5, $howtotext = '') {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label></p>\n";
|
||||
echo ' <textarea name="'.$name.'" id="'.$name.'" rows="'.$rows.'" cols="'.$cols.'">'.$prevalue.'</textarea>';
|
||||
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_textarea() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
if ( ! function_exists( 'wphelper_form_wpeditor' ) ) :
|
||||
function wphelper_form_wpeditor($name= '', $prevalue = '', $labeltext = '', $howtotext = '', $small = true) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label></p>\n";
|
||||
if ($small==true) {
|
||||
wp_editor( $prevalue, $name, array('teeny' => true, 'textarea_rows' => 5, 'media_buttons' => false) );
|
||||
} else {
|
||||
wp_editor( $prevalue, $name );
|
||||
}
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_wpeditor() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
if ( ! function_exists( 'wphelper_form_text' ) ) :
|
||||
function wphelper_form_text($name= '', $prevalue = '', $labeltext = '', $howtotext = '', $placeholder='', $size = 0) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label><br />\n";
|
||||
|
||||
echo ' <input type="text" ';
|
||||
if (intval($size)>0) {
|
||||
echo ' size="'.$size.'"';
|
||||
} else {
|
||||
echo ' class="large-text"';
|
||||
}
|
||||
echo ' name="'.$name.'" id="'.$name.'" value="'.$prevalue.'"';
|
||||
if (strlen(trim($placeholder))) {
|
||||
echo ' placeholder="'.$placeholder.'"';
|
||||
}
|
||||
|
||||
echo " />\n";
|
||||
echo "</p>\n";
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_text() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
if ( ! function_exists( 'wphelper_form_email' ) ) :
|
||||
function wphelper_form_email($name= '', $prevalue = '', $labeltext = '', $howtotext = '', $placeholder='', $size = 0) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label><br />\n";
|
||||
|
||||
echo ' <input type="email" ';
|
||||
if (intval($size)>0) {
|
||||
echo ' size="'.$size.'"';
|
||||
} else {
|
||||
echo ' class="large-text"';
|
||||
}
|
||||
echo ' name="'.$name.'" id="'.$name.'" value="'.$prevalue.'"';
|
||||
if (strlen(trim($placeholder))) {
|
||||
echo ' placeholder="'.$placeholder.'"';
|
||||
}
|
||||
|
||||
echo " />\n";
|
||||
echo "</p>\n";
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_email() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
if ( ! function_exists( 'wphelper_form_number' ) ) :
|
||||
function wphelper_form_number($name= '', $prevalue = '', $labeltext = '', $howtotext = '', $min = 0, $max = 0, $step=1) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label><br />\n";
|
||||
|
||||
echo ' <input type="number" ';
|
||||
|
||||
echo 'name="'.$name.'" id="'.$name.'" value="'.$prevalue.'"';
|
||||
if ($min>0) {
|
||||
echo ' min="'.$min.'"';
|
||||
}
|
||||
if ($max>0) {
|
||||
echo ' max="'.$max.'"';
|
||||
}
|
||||
if ($step>1) {
|
||||
echo ' step="'.$step.'"';
|
||||
}
|
||||
|
||||
echo " />\n";
|
||||
echo "</p>\n";
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_number() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_url' ) ) :
|
||||
function wphelper_form_url($name= '', $prevalue = '', $labeltext = '', $howtotext = '', $placeholder='http://', $size = 0) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo "<p>\n";
|
||||
echo ' <label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label><br />\n";
|
||||
echo ' <input type="url" class="large-text" name="'.$name.'" id="'.$name.'" value="'.$prevalue.'"';
|
||||
if (strlen(trim($placeholder))) {
|
||||
echo ' placeholder="'.$placeholder.'"';
|
||||
}
|
||||
if (intval($size)>0) {
|
||||
echo ' length="'.$size.'"';
|
||||
}
|
||||
echo " />\n";
|
||||
echo "</p>\n";
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_url() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_onoff' ) ) :
|
||||
function wphelper_form_onoff($name= '', $prevalue = 0, $labeltext = '', $howtotext = '' ) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) { ?>
|
||||
<div class="schalter">
|
||||
<select class="onoff" name="<?php echo $name; ?>" id="<?php echo $name; ?>">
|
||||
<option value="0" <?php selected(0,$prevalue);?>>Aus</option>
|
||||
<option value="1" <?php selected(1,$prevalue);?>>An</option>
|
||||
</select>
|
||||
<label for="<?php echo $name; ?>">
|
||||
<?php echo $labeltext; ?>
|
||||
</label>
|
||||
</div>
|
||||
<?php
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_onoff() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_select' ) ) :
|
||||
function wphelper_form_select($name= '', $liste = array(), $prevalue = '', $labeltext = '', $howtotext = '', $showempty=1, $emptytext = '' ) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
$emptytext = wphelper_san( $emptytext );
|
||||
|
||||
if (is_array($liste) && !empty($name) && !empty($labeltext)) { ?>
|
||||
<div class="liste">
|
||||
<p><label for="<?php echo $name; ?>">
|
||||
<?php echo $labeltext; ?>
|
||||
</label></p>
|
||||
<select name="<?php echo $name; ?>" id="<?php echo $name; ?>">
|
||||
<?php
|
||||
if ($showempty==1) {
|
||||
echo '<option value="">';
|
||||
if (!empty($emptytext)) {
|
||||
echo $emptytext;
|
||||
} else {
|
||||
_e('No selection','wphelper');
|
||||
}
|
||||
echo '</option>';
|
||||
}
|
||||
|
||||
foreach($liste as $entry => $value){ ?>
|
||||
<option value="<?php echo $entry; ?>" <?php selected($entry,$prevalue);?>><?php echo $value; ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_select() - array, name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_multiselect' ) ) :
|
||||
function wphelper_form_multiselect($name= '', $liste = array(), $prevalues = array(), $labeltext = '', $howtotext = '', $showempty=1, $emptytext = '' ) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
$emptytext = wphelper_san( $emptytext );
|
||||
|
||||
if (is_array($liste) && !empty($name) && !empty($labeltext)) { ?>
|
||||
<div class="liste">
|
||||
<p><label for="<?php echo $name; ?>">
|
||||
<?php echo $labeltext; ?>
|
||||
</label></p>
|
||||
<select size="5" multiple="1" name="<?php echo $name; ?>[]" id="<?php echo $name; ?>">
|
||||
<?php
|
||||
if ($showempty==1) {
|
||||
echo '<option value="">';
|
||||
if (!empty($emptytext)) {
|
||||
echo $emptytext;
|
||||
} else {
|
||||
_e('No selection','wphelper');
|
||||
}
|
||||
echo '</option>';
|
||||
}
|
||||
|
||||
foreach($liste as $entry => $value){
|
||||
echo '<option value="'.$entry.'"';
|
||||
if (is_array($prevalues)) {
|
||||
foreach($prevalues as $pnum){
|
||||
if ($entry==$pnum)
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
}
|
||||
echo '>';
|
||||
echo $value;
|
||||
echo '</option>';
|
||||
|
||||
} ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_multiselect() - array, name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_image' ) ) :
|
||||
function wphelper_form_image($name= '', $preimageid = 0, $labeltext = '', $howtotext = '', $width=300, $height=200 ) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
echo '<p><label for="'.$name.'">';
|
||||
echo $labeltext;
|
||||
echo "</label></p>\n";
|
||||
|
||||
echo '<div class="uploader">';
|
||||
|
||||
$image = '';
|
||||
$imagehtml = '';
|
||||
if (isset($preimageid) && ($preimageid>0)) {
|
||||
$image = wp_get_attachment_image_src($preimageid, 'full');
|
||||
if (isset($image)) {
|
||||
$imagehtml = '<img class="image_show_'.$name.'" src="'.$image[0].'" width="'.$width.'" height="'.$height.'" alt="">';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<div class="previewimage showimg_'.$name.'">';
|
||||
if (!empty($imagehtml)) {
|
||||
echo $imagehtml;
|
||||
}
|
||||
echo "</div>\n"; ?>
|
||||
|
||||
<input type="hidden" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo sanitize_key( $preimageid ) ; ?>" />
|
||||
|
||||
|
||||
<input class="button" name="image_button_<?php echo $name; ?>" id="image_button_<?php echo $name; ?>" value="<?php _e('Select image', 'wphelper'); ?>" />
|
||||
<small><a href="#" class="image_remove_<?php echo $name; ?>"><?php _e( "Remove", 'wphelper' );?></a></small>
|
||||
<br><p class="howto"><?php echo $howtotext; ?>
|
||||
</p><script>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('#image_button_<?php echo $name; ?>').click(function() {
|
||||
wp.media.editor.send.attachment = function(props, attachment) {
|
||||
jQuery('#<?php echo $name; ?>').val(attachment.id);
|
||||
htmlshow = "<img src=\""+attachment.url + "\" width=\"<?php echo $width;?>\" height=\"<?php echo $height;?>\">";
|
||||
jQuery('.showimg_<?php echo $name; ?>').html(htmlshow);
|
||||
|
||||
}
|
||||
wp.media.editor.open(this);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.image_remove_<?php echo $name; ?>').click(function() {
|
||||
jQuery('#<?php echo $name; ?>').val('');
|
||||
jQuery('.showimg_<?php echo $name; ?>').html('<?php _e('No image selected', 'wphelper'); ?>');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_image() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ( ! function_exists( 'wphelper_form_link' ) ) :
|
||||
function wphelper_form_link($name= '', $pretitle ='', $preurl ='' , $labeltext = '', $howtotext = '', $types = '' ) {
|
||||
$name = wphelper_san( $name );
|
||||
$labeltext = wphelper_san( $labeltext );
|
||||
if (!empty($name) && !empty($labeltext)) {
|
||||
wp_enqueue_script( 'wp-link' );
|
||||
echo '<div class="linkeingabe">';
|
||||
$rand = rand();
|
||||
echo '<h2 class="label">'.$labeltext.'</h2>';
|
||||
if (strlen(trim($howtotext))) {
|
||||
echo '<p class="howto">';
|
||||
echo $howtotext;
|
||||
echo "</p>\n";
|
||||
}
|
||||
echo '<div class="linkauswahl" id="container_'.$rand.'">';
|
||||
echo "<p>\n";
|
||||
echo '<label for="title_'.$rand.'_'.$name.'">'.__('Title','wphelper');
|
||||
echo "</label><br />\n";
|
||||
echo '<input type="text" class="large-text" name="'.$name.'_title" id="title_'.$rand.'_'.$name.'" value="'.$pretitle.'" placeholder="'.__('Use title of linked page','wphelper').'">';
|
||||
echo "</p>\n";
|
||||
echo "<p>\n";
|
||||
echo '<label for="url_'.$rand.'_'.$name.'">'.__('URL','wphelper');
|
||||
echo "</label><br />\n";
|
||||
echo '<input type="url" class="large-text" name="'.$name.'_url" id="url_'.$rand.'_'.$name.'" value="'.$preurl.'" placeholder="https://">';
|
||||
echo "</p>";
|
||||
echo '<p><input class="button link_button_'.$name.'" name="link_button_'.$name.'" id="link_button_'.$name.'" type="button" value="'.__('Select link','wphelper').'"></p>';
|
||||
echo "</div>\n";
|
||||
|
||||
?>
|
||||
<script>
|
||||
|
||||
var _link_sideload = false;
|
||||
var link_btn_<?php echo $name?> = (function($){
|
||||
|
||||
var link_sideload = false;
|
||||
var link_val_container = $('#url_<?php echo $rand ?>_<?php echo $name ?>');
|
||||
var title_val_container = $('#title_<?php echo $rand ?>_<?php echo $name ?>');
|
||||
|
||||
function _init() {
|
||||
$('.link_button_<?php echo $name ?>').on('click', function (event) {
|
||||
_addLinkListeners();
|
||||
_link_sideload = false;
|
||||
|
||||
|
||||
if ( typeof wpActiveEditor != 'undefined') {
|
||||
wpLink.open();
|
||||
wpLink.textarea = $(link_val_container);
|
||||
} else {
|
||||
window.wpActiveEditor = true;
|
||||
_link_sideload = true;
|
||||
wpLink.open();
|
||||
wpLink.textarea = $(link_val_container);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
function _addLinkListeners() {
|
||||
$('body').on('click', '#wp-link-submit', function(event) {
|
||||
var linkAtts = wpLink.getAttrs();
|
||||
$('#url_<?php echo $rand?>_<?php echo $name?>').val(linkAtts.href);
|
||||
$('#title_<?php echo $rand?>_<?php echo $name?>').val(linkAtts.title);
|
||||
|
||||
_removeLinkListeners();
|
||||
return false;
|
||||
});
|
||||
$('body').on('click', '#wp-link-cancel', function(event) {
|
||||
_removeLinkListeners();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function _removeLinkListeners() {
|
||||
if(_link_sideload){
|
||||
if ( typeof wpActiveEditor != 'undefined') {
|
||||
wpActiveEditor = undefined;
|
||||
}
|
||||
}
|
||||
wpLink.close();
|
||||
wpLink.textarea = $('html');//focus on document
|
||||
title_val_container.focus();
|
||||
$('body').off('click', '#wp-link-submit');
|
||||
$('body').off('click', '#wp-link-cancel');
|
||||
}
|
||||
return {
|
||||
init: _init,
|
||||
};
|
||||
})(jQuery);
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
|
||||
link_btn_<?php echo $name?>.init();
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
echo "</div>\n";
|
||||
|
||||
add_action( 'admin_footer-post-new.php', 'wphelper_wpLinkUpdate_getAttr', 9999 );
|
||||
add_action( 'admin_footer-post.php', 'wphelper_wpLinkUpdate_getAttr', 9999 );
|
||||
|
||||
} else {
|
||||
echo __('Invalid call to wphelper_form_link() - name or label is missing.', 'wphelper');
|
||||
}
|
||||
}
|
||||
endif;
|
||||
if ( ! function_exists( 'wphelper_wpLinkUpdate_getAttr' ) ) :
|
||||
|
||||
function wphelper_wpLinkUpdate_getAttr() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
( function( $ ) {
|
||||
var inputs = {};
|
||||
|
||||
if ( typeof wpLink == 'undefined' )
|
||||
return;
|
||||
|
||||
// Override the function
|
||||
wpLink.getAttrs= function () {
|
||||
inputs.url = $( '#wp-link-url' );
|
||||
inputs.text = $( '#wp-link-text' );
|
||||
inputs.openInNewTab = $( '#wp-link-target' );
|
||||
return {
|
||||
title: $.trim( inputs.text.val() ),
|
||||
href: $.trim( inputs.url.val() ),
|
||||
target: inputs.openInNewTab.prop( 'checked' ) ? '_blank' : ''
|
||||
};
|
||||
};
|
||||
} )( jQuery );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if ( ! function_exists( 'wphelper_save_standard' ) ) :
|
||||
function wphelper_save_standard($name, &$val, $post_id, $type='text') {
|
||||
if (!empty($name) && !empty($post_id) ) {
|
||||
|
||||
if ($type == 'url') {
|
||||
$newval = ( isset( $val ) ? esc_url( $val ) : 0 );
|
||||
} elseif ($type == 'email') {
|
||||
$newval = ( isset( $val ) ? sanitize_email( $val ) : 0 );
|
||||
} elseif ($type == 'text') {
|
||||
$newval = ( isset( $val ) ? sanitize_text_field( $val ) : 0 );
|
||||
} elseif ($type == 'textnohtml') {
|
||||
$newval = ( isset( $val ) ? wp_strip_all_tags( $val ) : 0 );
|
||||
} elseif (($type == 'intval') || ($type == 'int')) {
|
||||
$newval = ( isset( $val ) ? intval( $val ) : 0 );
|
||||
} elseif ($type == 'textarea') {
|
||||
$newval = ( isset( $val ) ? esc_textarea( $val ) : 0 );
|
||||
} elseif ($type == 'wpeditor') {
|
||||
$newval = $val;
|
||||
} else {
|
||||
$newval = ( isset( $val ) ? sanitize_text_field( $val ) : 0 );
|
||||
}
|
||||
$oldval = get_post_meta( $post_id, $name, true );
|
||||
if (!empty($newval)) {
|
||||
update_post_meta( $post_id, $name, $newval );
|
||||
} elseif ($oldval) {
|
||||
delete_post_meta( $post_id, $name, $oldval );
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ( ! function_exists( 'wphelper_san' ) ) :
|
||||
function wphelper_san($s){
|
||||
return filter_var(trim($s), FILTER_SANITIZE_STRING);
|
||||
}
|
||||
endif;
|
||||
698
wp-content/themes/piratenkleider/inc/theme-options.php
Normal file
698
wp-content/themes/piratenkleider/inc/theme-options.php
Normal file
@@ -0,0 +1,698 @@
|
||||
<?php
|
||||
|
||||
add_action( 'admin_init', 'theme_options_init' );
|
||||
add_action( 'admin_menu', 'theme_options_add_page' );
|
||||
|
||||
/**
|
||||
* Init plugin options to white list our options
|
||||
*/
|
||||
function theme_options_init(){
|
||||
register_setting( 'piratenkleider_options',
|
||||
'piratenkleider_theme_options',
|
||||
'theme_options_validate' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load up the menu page
|
||||
*/
|
||||
function theme_options_add_page() {
|
||||
add_theme_page( __( 'Theme Options', 'piratenkleider' ),
|
||||
__( 'Theme Options', 'piratenkleider' ),
|
||||
'edit_theme_options',
|
||||
'theme_options',
|
||||
'theme_options_do_page' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the options page
|
||||
*/
|
||||
function theme_options_do_page($tab = '') {
|
||||
global $setoptions;
|
||||
global $options;
|
||||
|
||||
if ( ! isset( $_REQUEST['settings-updated'] ) )
|
||||
$_REQUEST['settings-updated'] = false;
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<div class="piratenkleider-optionen"> <!-- begin: .piratenkleider-optionen -->
|
||||
<?php echo "<h2>" . wp_get_theme().': ' . __( 'Change theme options', 'piratenkleider' ) . "</h2>"; ?>
|
||||
|
||||
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
|
||||
<div class="updated fade"><p><strong><?php _e( 'Options saved.', 'piratenkleider' ); ?></strong></p></div>
|
||||
<?php endif;
|
||||
|
||||
if (isset($_GET['tab'])) {
|
||||
$tab = $_GET['tab'];
|
||||
}
|
||||
if ((!isset($tab)) || (empty($tab))) {
|
||||
$tab = $options['optionpage-tab-default'];
|
||||
}
|
||||
if (!isset($setoptions['piratenkleider_theme_options'][$tab])) {
|
||||
echo "Invalid Tab-Option or undefined Option-Field $tab";
|
||||
}
|
||||
|
||||
|
||||
echo "<h3 class=\"nav-tab-wrapper\">\n";
|
||||
foreach($setoptions['piratenkleider_theme_options'] as $i => $value) {
|
||||
$tabtitel = $value['tabtitle'];
|
||||
echo "<a href=\"?page=theme_options&tab=$i\" class=\"nav-tab ";
|
||||
if ($tab==$i) {
|
||||
echo "nav-tab-active";
|
||||
}
|
||||
echo "\">$tabtitel</a>\n";
|
||||
}
|
||||
echo "</h3>\n"; ?>
|
||||
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'piratenkleider_options' ); ?>
|
||||
<input type="hidden" id="piratenkleider_theme_options[tab]" name="piratenkleider_theme_options[tab]" value="<?php echo $tab; ?>">
|
||||
|
||||
|
||||
<div id="einstellungen">
|
||||
<table>
|
||||
<?php
|
||||
if (isset($setoptions['piratenkleider_theme_options'][$tab]['fields'])) {
|
||||
foreach($setoptions['piratenkleider_theme_options'][$tab]['fields'] as $i => $value) {
|
||||
$name = $i;
|
||||
$mark_option =0;
|
||||
if (isset($value['title'])) $title = $value['title'];
|
||||
if (isset($value['type'])) $type = $value['type'];
|
||||
if (isset($value['label'])) $label = $value['label'];
|
||||
if (isset($value['parent'])) $parent = $value['parent'];
|
||||
if (isset($value['liste'])) $liste = $value['liste'];
|
||||
if (isset($value['mark_option']) && $value['mark_option']==1) $mark_option =1;
|
||||
|
||||
|
||||
if ($type == 'section') {
|
||||
if ((isset($setsection)) && ($setsection != "")) {
|
||||
echo "\t\t\t</table>\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
}
|
||||
echo "\t<tr valign=\"top\">\n\t\t<th scope=\"row\">";
|
||||
echo $title;
|
||||
echo "</th>\n\t\t<td>";
|
||||
echo "\t\t\t<table class=\"suboptions\">\n";
|
||||
$setsection = $name;
|
||||
} else {
|
||||
|
||||
echo "\t<tr valign=\"top\" class=\"option-".$name;
|
||||
if ($mark_option==1) {
|
||||
echo " mark-option";
|
||||
}
|
||||
echo "\">\n\t\t<th scope=\"row\">";
|
||||
echo $title;
|
||||
echo "</th>\n\t\t<td>";
|
||||
|
||||
if ((!isset($options[$name])) && (isset($value['default'])) && (!empty($value['default']))) {
|
||||
$options[$name] = $value['default'];
|
||||
}
|
||||
|
||||
if ($type =='bool') {
|
||||
echo "\t\t\t";
|
||||
echo "<input id=\"$name\" name=\"piratenkleider_theme_options[$name]\"
|
||||
type=\"checkbox\" value=\"1\" ";
|
||||
|
||||
if (isset($options[$name])) echo checked( $options[$name],1,false );
|
||||
echo ">\n";
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"$name\">$label</label>\n";
|
||||
} elseif (($type=='text') || ($type=='email')) {
|
||||
echo "\t\t\t";
|
||||
echo "<input class=\"regular-text\" id=\"piratenkleider_theme_options[$name]\"
|
||||
type=\"text\" name=\"piratenkleider_theme_options[$name]\"
|
||||
value=\"";
|
||||
if (isset($options[$name])) echo esc_attr( $options[$name] );
|
||||
|
||||
echo "\"><br>\n";
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
} elseif (($type=='html') ||($type=='url')) {
|
||||
echo "\t\t\t";
|
||||
echo "<input class=\"large-text\" id=\"piratenkleider_theme_options[$name]\"
|
||||
type=\"text\" name=\"piratenkleider_theme_options[$name]\"
|
||||
size=\"120\" value=\"";
|
||||
if (isset($options[$name])) echo esc_attr( $options[$name] );
|
||||
|
||||
echo "\"><br>\n";
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
} elseif ($type=='imgurl') {
|
||||
echo "\t\t\t";
|
||||
echo "<input class=\"large-text\" id=\"piratenkleider_theme_options[$name]\"
|
||||
type=\"text\" name=\"piratenkleider_theme_options[$name]\"
|
||||
size=\"120\" value=\"";
|
||||
if (isset($options[$name])) echo esc_attr( $options[$name] );
|
||||
echo "\"><br>\n";
|
||||
if (isset($options[$name])) {
|
||||
echo "<img class=\"imgurl\" src=\"".esc_attr( $options[$name] )."\" alt=\"\">\n";
|
||||
}
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
|
||||
|
||||
} elseif ($type=='textarea') {
|
||||
echo "\t\t\t";
|
||||
echo "<textarea class=\"large-text\" id=\"piratenkleider_theme_options[$name]\"
|
||||
cols=\"30\" rows=\"10\" name=\"piratenkleider_theme_options[$name]\">";
|
||||
if (isset($options[$name])) echo esc_attr( $options[$name] );
|
||||
echo "</textarea><br>\n";
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
} elseif ($type=='file') {
|
||||
echo "\t\t\t";
|
||||
echo '<div class="uploader">';
|
||||
?>
|
||||
|
||||
<input type="hidden" name="piratenkleider_theme_options[<?php echo $name; ?>]" id="file_<?php echo $name; ?>"
|
||||
value="<?php if (isset($options[$name])) echo sanitize_key( $options[$name]); ?>" />
|
||||
|
||||
<input type="text" name="piratenkleider_theme_options[<?php echo $name; ?>_url]" id="file_<?php echo $name; ?>_url"
|
||||
value="<?php if (isset($options[$name])) echo wp_get_attachment_url( esc_attr( $options[$name]) ); ?>" />
|
||||
<input class="button" name="file_button_<?php echo $name; ?>" id="file_button_<?php echo $name; ?>" value="<?php _e('Add file', 'piratenkleider'); ?>" />
|
||||
<small><a href="#" class="file_remove_<?php echo $name; ?>"><?php _e( "Remove file", 'piratenkleider' );?></a></small>
|
||||
<br><label for="piratenkleider_theme_options[<?php echo $name; ?>]"><?php echo $label; ?></label>
|
||||
</div><script>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('#file_button_<?php echo $name; ?>').click(function() {
|
||||
wp.media.editor.send.attachment = function(props, attachment) {
|
||||
jQuery('#file_<?php echo $name; ?>_url').val(attachment.url);
|
||||
jQuery('#file_<?php echo $name; ?>').val(attachment.id);
|
||||
}
|
||||
wp.media.editor.open(this);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.file_remove_<?php echo $name; ?>').click(function() {
|
||||
jQuery('#file_<?php echo $name; ?>').val('');
|
||||
jQuery('#file_<?php echo $name; ?>_url').val('');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script> <?php
|
||||
|
||||
} elseif (($type=='imageurl') || ($type=='image')) {
|
||||
echo "\t\t\t";
|
||||
echo '<div class="uploader">';
|
||||
echo '<div class="previewimage showimg_'.$name.'">';
|
||||
$addstyle = '';
|
||||
if (isset($value['maxwidth'])) {
|
||||
$addstyle .= 'max-width: '.$value['maxwidth'].'px;';
|
||||
}
|
||||
if (isset($value['maxheight'])) {
|
||||
$addstyle .= 'max-height: '.$value['maxheight'].'px;';
|
||||
}
|
||||
|
||||
if ((isset($options[$name])) && esc_url( $options[$name])) {
|
||||
echo '<img src="'.esc_url( $options[$name]).'" class="image_show_'.$name.'"';
|
||||
if (isset($addstyle) && strlen($addstyle)>1) {
|
||||
echo ' style="'.$addstyle.'"';
|
||||
}
|
||||
echo '/>';
|
||||
} else {
|
||||
_e('No image selected', 'piratenkleider');
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<input type="hidden" name="piratenkleider_theme_options[<?php echo $name; ?>_id]" id="image_<?php echo $name; ?>_id"
|
||||
value="<?php if ( isset( $options[$name."_id"] ) ) echo sanitize_key( $options[$name."_id"] ) ; ?>" />
|
||||
|
||||
<input type="text" name="piratenkleider_theme_options[<?php echo $name; ?>]" id="image_<?php echo $name; ?>" value="<?php if ( isset( $options[$name] ) ) echo esc_attr( $options[$name] ) ; ?>" />
|
||||
<input class="button" name="image_button_<?php echo $name; ?>" id="image_button_<?php echo $name; ?>" value="<?php _e('Add Image', 'piratenkleider'); ?>" />
|
||||
<small><a href="#" class="image_remove_<?php echo $name; ?>"><?php _e( "Remove image", 'piratenkleider' );?></a></small>
|
||||
<?php if (isset($value['default']) && (filter_var($value['default'], FILTER_VALIDATE_URL))) { ?>
|
||||
<small><a href="#" class="image_reset_<?php echo $name; ?>"><?php _e( "Reset to default", 'piratenkleider' );?></a></small>
|
||||
<?php } ?>
|
||||
|
||||
<br><label for="piratenkleider_theme_options[<?php echo $name; ?>]"><?php echo $label; ?></label>
|
||||
</div><script>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('#image_button_<?php echo $name; ?>').click(function() {
|
||||
wp.media.editor.send.attachment = function(props, attachment) {
|
||||
jQuery('#image_<?php echo $name; ?>').val(attachment.url);
|
||||
jQuery('#image_<?php echo $name; ?>_id').val(attachment.id);
|
||||
htmlshow = "<img src=\""+attachment.url + "\">";
|
||||
jQuery('.showimg_<?php echo $name; ?>').html(htmlshow);
|
||||
|
||||
}
|
||||
wp.media.editor.open(this);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.image_remove_<?php echo $name; ?>').click(function() {
|
||||
jQuery('#image_<?php echo $name; ?>').val('');
|
||||
jQuery('#image_<?php echo $name; ?>_id').val('');
|
||||
jQuery('.showimg_<?php echo $name; ?>').html('<?php _e('No image selected', 'piratenkleider'); ?>');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
<?php if (isset($value['default']) && (filter_var($value['default'], FILTER_VALIDATE_URL))) { ?>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.image_reset_<?php echo $name; ?>').click(function() {
|
||||
jQuery('#image_<?php echo $name; ?>').val("<?php echo $value['default']; ?>");
|
||||
jQuery('#image_<?php echo $name; ?>_id').val(0);
|
||||
htmlshow = "<img src=\"<?php echo $value['default']; ?>\">";
|
||||
jQuery('.showimg_<?php echo $name; ?>').html(htmlshow);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
<?php } ?>
|
||||
</script> <?php
|
||||
|
||||
} elseif ($type=='number') {
|
||||
echo "\t\t\t";
|
||||
echo "<input class=\"number\" size=\"5\" id=\"piratenkleider_theme_options[$name]\"
|
||||
type=\"number\" name=\"piratenkleider_theme_options[$name]\"
|
||||
value=\"".esc_attr( $options[$name] )."\"><br>\n";
|
||||
echo "\t\t\t";
|
||||
echo "<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
} elseif ($type=='bildlist') {
|
||||
echo "\t\t\t";
|
||||
foreach($liste as $i => $value) {
|
||||
echo "\t\t\t\t";
|
||||
$src = $value['src'];
|
||||
$label = $value['label'];
|
||||
echo "<label class=\"tile";
|
||||
if ( $src == $options[$name] ) {
|
||||
echo ' checked';
|
||||
}
|
||||
echo "\">\n";
|
||||
echo '<input type="radio" value="'.$src.'"
|
||||
name="piratenkleider_theme_options['.$name.']"';
|
||||
if ( $src == $options[$name] ) {
|
||||
echo ' checked="checked"';
|
||||
}
|
||||
echo '> ';
|
||||
echo $label.'<br><img src="'.$src.'" alt="" style="width: 320px; height: auto;">';
|
||||
echo "</label>\n";
|
||||
}
|
||||
echo "<br style=\"clear: left;\">\n";
|
||||
} elseif ($type=='bildchecklist') {
|
||||
echo "\t\t\t";
|
||||
foreach ( $liste as $option ) {
|
||||
$checked = '';
|
||||
if ((isset($options[$name])) && (is_array($options[$name]))) {
|
||||
foreach ($options[$name] as $current) {
|
||||
if ($current == $option['src']) {
|
||||
$checked = "checked=\"checked\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<label class="plakattile">
|
||||
<div style="height: 40px; width: 100%; margin:0 auto; background-color: #F28900; color: white; display: block;">
|
||||
<input type="checkbox" name="piratenkleider_theme_options[<?php echo $name?>][]"
|
||||
value="<?php echo esc_attr( $option['src'] ); ?>" <?php echo $checked; ?> />
|
||||
<?php echo $option['label']?>
|
||||
</div>
|
||||
<div style="height: 395px; overflow: hidden; margin: 5px auto; width: 280px; padding: 0;">
|
||||
<img src="<?php echo $option['src'] ?>" style="width: 280px; height: auto; ">
|
||||
</div>
|
||||
</label>
|
||||
<?php }
|
||||
echo "<br style=\"clear: left;\">\n";
|
||||
} elseif ($type=='bilddirchecklist') {
|
||||
echo "\t\t\t";
|
||||
$dir = get_template_directory().$value['default'];
|
||||
|
||||
|
||||
if (is_dir($dir)) {
|
||||
$contents = dirToArray($dir);
|
||||
foreach ($contents as $key => $wert) {
|
||||
if (is_array($wert)) {
|
||||
|
||||
echo "<h4>Ordner $key<h4>";
|
||||
foreach ($wert as $sub) {
|
||||
$bildurl = get_template_directory_uri().$value['default'].'/'.$key.'/'.$sub;
|
||||
$checked = '';
|
||||
if ((isset($options[$name])) && (is_array($options[$name]))) {
|
||||
foreach ($options[$name] as $current) {
|
||||
if ($current == $bildurl) {
|
||||
|
||||
$checked = "checked=\"checked\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} ?>
|
||||
|
||||
<label class="plakattile" style="width: 150px; height: 251px">
|
||||
<div style="height: 40px; width: 100%; margin:0 auto; background-color: #F28900; color: white; display: block;">
|
||||
<input type="checkbox" name="piratenkleider_theme_options[<?php echo $name?>][]"
|
||||
value="<?php echo esc_attr( $bildurl ); ?>" <?php echo $checked; ?> />
|
||||
<?php echo $sub ?>
|
||||
</div>
|
||||
<div style="height: 211px; overflow: hidden; margin: 5px auto; width: 150px; padding: 0;">
|
||||
<img src="<?php echo $bildurl ?>" style="width: 150px; height: auto; ">
|
||||
</div>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
echo "<br style=\"clear: left;\">\n";
|
||||
}
|
||||
}
|
||||
// First Dir only
|
||||
|
||||
$found=0;
|
||||
foreach ($contents as $key => $wert) {
|
||||
if (!is_array($wert)) {
|
||||
if ($found==0) {
|
||||
print "<h4>Ordner ".$value['default']."</h4>";
|
||||
$found=1;
|
||||
}
|
||||
$bildurl = get_template_directory_uri().$value['default'].'/'.$wert;
|
||||
$checked = '';
|
||||
if ((isset($options[$name])) && (is_array($options[$name]))) {
|
||||
foreach ($options[$name] as $current) {
|
||||
if ($current == $bildurl) {
|
||||
|
||||
$checked = "checked=\"checked\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} ?>
|
||||
|
||||
<label class="plakattile" style="width: 150px; height: 251px">
|
||||
<div style="height: 40px; width: 100%; margin:0 auto; background-color: #F28900; color: white; display: block;">
|
||||
<input type="checkbox" name="piratenkleider_theme_options[<?php echo $name?>][]"
|
||||
value="<?php echo esc_attr( $bildurl ); ?>" <?php echo $checked; ?> />
|
||||
<?php echo $wert ?>
|
||||
</div>
|
||||
<div style="height: 211px; overflow: hidden; margin: 5px auto; width: 150px; padding: 0;">
|
||||
<img src="<?php echo $bildurl ?>" style="width: 150px; height: auto; ">
|
||||
</div>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
echo "<br style=\"clear: left;\">\n";
|
||||
}
|
||||
|
||||
} elseif ($type=='urlchecklist') {
|
||||
echo "\t\t\t";
|
||||
foreach ( $liste as $entry => $listdata ) {
|
||||
$checked = '';
|
||||
$value = '';
|
||||
$active = 0;
|
||||
if (isset($options[$name][$entry]['content'])) {
|
||||
$value = $options[$name][$entry]['content'];
|
||||
} else {
|
||||
$value = $liste[$entry]['content'];
|
||||
}
|
||||
if (isset($options[$name][$entry]['active'])) {
|
||||
$active = $options[$name][$entry]['active'];
|
||||
}
|
||||
if (($active==1)
|
||||
&& (filter_var($value, FILTER_VALIDATE_URL))) {
|
||||
$checked = "checked=\"checked\"";
|
||||
}
|
||||
?>
|
||||
<div style="display: inline-block; width: 90%;" class="<?php echo $name?>">
|
||||
<label for="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>][active]" class="<?php echo $entry?>" style="width: 120px; display: inline-block;">
|
||||
<input type="checkbox"
|
||||
id="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>][active]"
|
||||
name="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>][active]"
|
||||
value="1" <?php echo $checked; ?>>
|
||||
<?php echo $liste[$entry]['name'] ?>
|
||||
</label>
|
||||
|
||||
<input id="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>][content]"
|
||||
type="text" name="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>][content]"
|
||||
size="80" value="<?php echo $value?>">
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
if (isset($label)) {
|
||||
echo "<p>".$label."</p>\n";
|
||||
}
|
||||
echo "<br style=\"clear: left;\">\n";
|
||||
} elseif ($type=='select') {
|
||||
echo "\t\t\t";
|
||||
echo "<select id=\"$name\" name=\"piratenkleider_theme_options[$name]\">\n";
|
||||
|
||||
foreach($liste as $i => $value) {
|
||||
echo "\t\t\t\t";
|
||||
echo '<option value="'.$i.'"';
|
||||
if ( $i == $options[$name] ) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>';
|
||||
if (!is_array($value)) {
|
||||
echo $value;
|
||||
} else {
|
||||
echo $i;
|
||||
}
|
||||
echo '</option>';
|
||||
echo "\n";
|
||||
}
|
||||
echo "\t\t\t</select><br>\n";
|
||||
echo "\t\t\t<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
} elseif ($type=='multiselectlist') {
|
||||
echo "\t\t\t";
|
||||
foreach ( $liste as $entry => $listdata ) {
|
||||
$checked = '';
|
||||
$value = '';
|
||||
foreach ($options[$name] as $cur) {
|
||||
if ($cur==$entry) {
|
||||
$checked = "checked=\"checked\"";
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<label for="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>]" >
|
||||
<input type="checkbox"
|
||||
id="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>]"
|
||||
name="piratenkleider_theme_options[<?php echo $name?>][<?php echo $entry?>]"
|
||||
value="<?php echo $entry?>" <?php echo $checked; ?>>
|
||||
<?php echo $liste[$entry] ?>
|
||||
</label><br>
|
||||
<?php
|
||||
}
|
||||
if (isset($label)) {
|
||||
echo "<p>".$label."</p>\n";
|
||||
}
|
||||
} elseif ($type=='fontselect') {
|
||||
echo "\t\t\t";
|
||||
echo "<select name=\"piratenkleider_theme_options[$name]\">\n";
|
||||
foreach($liste as $i => $value) {
|
||||
echo "\t\t\t\t";
|
||||
if ((isset($value['webfont']) && $value['webfont']==1)) {
|
||||
echo '<option style="font-size: 1.5em; font-family: '.$i.';" value="'.$i.'"';
|
||||
} elseif ($i == 'none') {
|
||||
echo '<option style="font-size: 1.5em;" value="'.$i.'"';
|
||||
} else {
|
||||
echo '<option style="font-size: 1.5em; font-family: '.$value['family'].';" value="'.$i.'"';
|
||||
}
|
||||
if ( $i == $options[$name] ) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>';
|
||||
echo $value['title'];
|
||||
if ($i != 'none')
|
||||
echo ' (ABCIJL abcijl 1234567890 ÄÖÜäöüß @<>?)';
|
||||
echo '</option>';
|
||||
echo "\n";
|
||||
}
|
||||
echo "\t\t\t</select><br>\n";
|
||||
echo "\t\t\t<label for=\"piratenkleider_theme_options[$name]\">$label</label>\n";
|
||||
|
||||
}
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
}
|
||||
|
||||
if ((isset($setsection)) && ($setsection!="") && ($type != 'section') && (!isset($parent))) {
|
||||
/*
|
||||
* Kein Parent mehr
|
||||
*/
|
||||
echo "\t\t\t</table>\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
$setsection = "";
|
||||
}
|
||||
}
|
||||
if ((isset($setsection)) && ($setsection!="")) {
|
||||
/*
|
||||
* Kein Parent mehr
|
||||
*/
|
||||
echo "\t\t\t</table>\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
$setsection = "";
|
||||
}
|
||||
} else {
|
||||
_e( 'Option not defined', 'piratenkleider' );
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php _e( 'Update', 'piratenkleider' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div> <!-- end: .piratenkleider-optionen -->
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize and validate input. Accepts an array, return a sanitized array.
|
||||
*/
|
||||
function theme_options_validate( $input ) {
|
||||
global $setoptions;
|
||||
global $defaultoptions;
|
||||
$options = get_option( 'piratenkleider_theme_options' );
|
||||
|
||||
$saved = (array) get_option( 'piratenkleider_theme_options' );
|
||||
// $options= $saved;
|
||||
$output = wp_parse_args( $saved, $defaultoptions );
|
||||
$tab = '';
|
||||
if ((isset($_GET['tab'])) && (!empty($_GET['tab']))) {
|
||||
$tab = $_GET['tab'];
|
||||
}
|
||||
if ((empty($tab) && (isset($input['tab'])))) {
|
||||
$tab = $input['tab'];
|
||||
}
|
||||
|
||||
if (!isset($setoptions['piratenkleider_theme_options'][$tab])) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (isset($setoptions['piratenkleider_theme_options'][$tab]['fields'])) {
|
||||
foreach($setoptions['piratenkleider_theme_options'][$tab]['fields'] as $i => $value) {
|
||||
$name = $i;
|
||||
|
||||
$type = $value['type'];
|
||||
$default = '';
|
||||
if (isset($value['default'])) {
|
||||
$default = $value['default'];
|
||||
}
|
||||
if ($type != "section") {
|
||||
if (isset($input[$name])) {
|
||||
if ($type=='bool') {
|
||||
$output[$name] = ( $input[$name] == 1 ? 1 : 0 );
|
||||
} elseif ($type=='text') {
|
||||
$output[$name] = wp_filter_nohtml_kses( $input[$name] );
|
||||
} elseif ($type=='email') {
|
||||
$output[$name] = sanitize_email( $input[$name] );
|
||||
} elseif ($type=='textarea') {
|
||||
$output[$name] = $input[$name] ;
|
||||
} elseif ($type=='html') {;
|
||||
$output[$name] = $input[$name];
|
||||
} elseif (($type=='imageurl') || ($type=='image')) {
|
||||
$output[$name] = esc_url( $input[$name] );
|
||||
if (isset($input[$name."_id"])) {
|
||||
$output[$name."_id"] = sanitize_key( $input[$name."_id"] );
|
||||
}
|
||||
} elseif (($type=='url') || ($type=='imgurl')) {
|
||||
$output[$name] = esc_url( $input[$name] );
|
||||
} elseif ($type=='file') {
|
||||
$output[$name."_url"] = wp_filter_nohtml_kses( $input[$name] );
|
||||
if (isset($input[$name."_id"])) {
|
||||
$output[$name] = sanitize_key( $input[$name."_id"] );
|
||||
}
|
||||
} elseif ($type=='number') {
|
||||
$output[$name] = wp_filter_nohtml_kses( $input[$name] );
|
||||
} elseif (($type=='select') || ($type=='fontselect')) {
|
||||
$output[$name] = wp_filter_nohtml_kses( $input[$name] );
|
||||
} elseif (($type=='bildchecklist') || ($type=='bilddirchecklist')) {
|
||||
$output[$name] = $input[$name];
|
||||
} elseif ($type=='multiselectlist') {
|
||||
$output[$name] = $input[$name];
|
||||
} elseif ($type=='urlchecklist') {
|
||||
$output[$name] = $input[$name];
|
||||
} else {
|
||||
$output[$name] = wp_filter_nohtml_kses( $input[$name] );
|
||||
}
|
||||
} else {
|
||||
if ($type=='bool') {
|
||||
$output[$name] =0;
|
||||
} elseif ($type=='text') {
|
||||
$output[$name] = "";
|
||||
} elseif ($type=='textarea') {
|
||||
$output[$name] = "";
|
||||
} elseif ($type=='html') {
|
||||
$output[$name] = "";
|
||||
} elseif (($type=='imageurl') || ($type=='image')) {
|
||||
$output[$name] = "";
|
||||
$output[$name."_id"] = 0;
|
||||
} elseif (($type=='url') || ($type=='imgurl')) {
|
||||
$output[$name] = "";
|
||||
} elseif ($type=='number') {
|
||||
$output[$name] = 0;
|
||||
} elseif ($type=='file') {
|
||||
$output[$name] = '';
|
||||
$output[$name."_url"] = '';
|
||||
} elseif (($type=='select') || ($type=='fontselect')) {
|
||||
$output[$name] = "";
|
||||
} elseif (($type=='bildchecklist') || ($type=='bilddirchecklist')) {
|
||||
$output[$name] = '';
|
||||
} elseif ($type=='multiselectlist') {
|
||||
$output[$name] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($input['anonymize-user'])) {
|
||||
if ($input['anonymize-user']==1) {
|
||||
$output['aktiv-avatar'] = 0;
|
||||
}
|
||||
|
||||
if (!isset($options['anonymize-user']))
|
||||
$options['anonymize-user'] = $defaultoptions['anonymize-user'];
|
||||
if (($input['anonymize-user']==0) && ($options['anonymize-user']==1)) {
|
||||
update_option('require_name_email',1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($input['reset_options']) && ($input['reset_options'] == 1)) {
|
||||
delete_option('piratenkleider_theme_options');
|
||||
|
||||
}
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reads Directory and contents, ignoring unused files
|
||||
*/
|
||||
|
||||
function dirToArray($dir) {
|
||||
$result = array();
|
||||
$contents = scandir($dir);
|
||||
$bad = array(".", "..", ".DS_Store", "_notes", "Thumbs.db", "Browse.plb");
|
||||
$cdir = array_diff($contents, $bad);
|
||||
|
||||
foreach ($cdir as $key => $value) {
|
||||
if (!in_array($value,array(".","..")))
|
||||
{
|
||||
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
|
||||
{
|
||||
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
405
wp-content/themes/piratenkleider/inc/widgets.php
Normal file
405
wp-content/themes/piratenkleider/inc/widgets.php
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
/*
|
||||
* Piratenkleider Widgets
|
||||
* Proudly made with a lot of coffee
|
||||
*/
|
||||
|
||||
|
||||
function piratenkleider_widgets_init() {
|
||||
global $options;
|
||||
// Sidebar
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Sitebar 1 (Upper)', 'piratenkleider' ),
|
||||
'id' => 'sidebar-widget-area',
|
||||
'description' => __( 'This region is above of optional poster slider.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h2>',
|
||||
'after_title' => '</h2>',
|
||||
) );
|
||||
// Sidebar2
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Sidebar 2 (Lower)', 'piratenkleider' ),
|
||||
'id' => 'sidebar-widget-area-afterplakate',
|
||||
'description' => __( 'This region is below of optional poster slider.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h2>',
|
||||
'after_title' => '</h2>',
|
||||
) );
|
||||
|
||||
|
||||
|
||||
// Widgets for indexpages (categories, tags, authorpage)
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Start page: Intro', 'piratenkleider' ),
|
||||
'id' => 'startpage-intro-area',
|
||||
'description' => __( 'Region below slider on start page.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h2 class="widget-title">',
|
||||
'after_title' => '</h2>',
|
||||
) );
|
||||
|
||||
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Start page: Left footer (content)', 'piratenkleider' ),
|
||||
'id' => 'first-startpage-widget-area',
|
||||
'description' => __( 'On start page: Content footer, left side.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h3>',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Start page: Right footer (content)', 'piratenkleider' ),
|
||||
'id' => 'second-startpage-widget-area',
|
||||
'description' => __( 'On start page: Content footer, right side.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
|
||||
// Linke Seite der Fußzeile
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Page footer: Left', 'piratenkleider' ),
|
||||
'id' => 'first-footer-widget-area',
|
||||
'description' => __( 'Region below main content, left site.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h2>',
|
||||
'after_title' => '</h2>',
|
||||
) );
|
||||
|
||||
// Rechte Seite der Fußzeile
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Page footer: Right', 'piratenkleider' ),
|
||||
'id' => 'second-footer-widget-area',
|
||||
'description' => __( 'Region below main content, right site.', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h2>',
|
||||
'after_title' => '</h2>',
|
||||
) );
|
||||
|
||||
// Widgets for indexpages (categories, tags, authorpage)
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Index pages: Content footer', 'piratenkleider' ),
|
||||
'id' => 'indexpages-widget-area',
|
||||
'description' => __( 'Content footer for index pages (e.g. categoryindex, archive, ...)', 'piratenkleider' ),
|
||||
'before_widget' => '<div class="widget">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h3 class="widget-title">',
|
||||
'after_title' => '</h3>',
|
||||
) );
|
||||
if ($options['artikelstream-show-widget']==1) {
|
||||
// Widgets for indexpages (categories, tags, authorpage)
|
||||
register_sidebar( array(
|
||||
'name' => __( 'Start page: Optional content', 'piratenkleider' ),
|
||||
'id' => 'artikelstream-widget',
|
||||
'description' => __( 'Optional widget for content area; positioned after article stream and can be used to add external feeds in content area.', 'piratenkleider' ),
|
||||
'before_widget' => '<div id="%1$s" class="widget-stream">',
|
||||
'after_widget' => '</div>',
|
||||
'before_title' => '<h1>',
|
||||
'after_title' => '</h1>',
|
||||
) );
|
||||
}
|
||||
|
||||
}
|
||||
add_action( 'widgets_init', 'piratenkleider_widgets_init' );
|
||||
|
||||
|
||||
/**
|
||||
* Adds Newsletter_Widget widget.
|
||||
*/
|
||||
class Newsletter_Widget extends WP_Widget {
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'Newsletter_Widget', // Base ID
|
||||
__( 'Subscribe to newsletter', 'piratenkleider' ),
|
||||
array( 'description' => __( 'Displays a form to subscribe to a mailing list.', 'piratenkleider' ), ) // Args
|
||||
);
|
||||
}
|
||||
|
||||
public function widget( $args, $instance ) {
|
||||
extract( $args );
|
||||
$title = apply_filters( 'widget_title', $instance['title'] );
|
||||
$url = esc_url($instance['url']);
|
||||
|
||||
echo $before_widget;
|
||||
echo '<div class="newsletter">';
|
||||
echo $before_title . $title . $after_title; ?>
|
||||
|
||||
<form method="post" action="<?php echo $url; ?>">
|
||||
<label for="<?php echo $this->get_field_id( 'title' ); ?>">
|
||||
<?php _e("Subscribe to newsletter", 'piratenkleider'); ?>
|
||||
</label>
|
||||
<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>"
|
||||
name="email"
|
||||
value="<?php _e("Enter email address", 'piratenkleider'); ?>"
|
||||
placeholder="<?php _e("Enter email address", 'piratenkleider'); ?>"
|
||||
onfocus="if(this.value=='<?php _e("Enter email address", 'piratenkleider'); ?>')this.value='';"
|
||||
onblur="if(this.value=='')this.value='<?php _e("Enter email address", 'piratenkleider'); ?>';">
|
||||
<input type="submit" name="email-button"
|
||||
value="<?php _e("Subscribe", 'piratenkleider'); ?>" id="newslettersubmit">
|
||||
<?php
|
||||
$site_link = home_url();
|
||||
if ((isset($url))&& (strpos($url, $site_link) !== false)) {
|
||||
echo "<p>";
|
||||
_e("Notice: You will leave this website for further steps.", 'piratenkleider');
|
||||
echo "</p>";
|
||||
} ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = array();
|
||||
$instance['title'] = strip_tags( $new_instance['title'] );
|
||||
$instance['url'] = esc_url($new_instance['newsletter_url']);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function form( $instance ) {
|
||||
global $defaultoptions;
|
||||
|
||||
$defaults = array(
|
||||
'title' => __( 'Newsletter / Mailing list', 'piratenkleider' ),
|
||||
'newsletter_url' => $defaultoptions['url-newsletteranmeldung'],
|
||||
);
|
||||
$instance = wp_parse_args((array)$instance, $defaults);
|
||||
$title = $instance['title'];
|
||||
$url = $instance['newsletter_url'];
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'piratenkleider' ); ?>
|
||||
<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>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id( 'newsletter_url' ); ?>"><?php _e( 'URL for subscribing form (with email attribute)', 'piratenkleider' ); ?>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id( 'newsletter_url' ); ?>" name="<?php echo $this->get_field_name( 'newsletter_url' ); ?>" type="text" value="<?php echo esc_attr( $url ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
} // class Newsletter_Widget
|
||||
// register widget
|
||||
add_action( 'widgets_init', create_function( '', 'register_widget( "Newsletter_Widget" );' ) );
|
||||
|
||||
|
||||
/**
|
||||
* Adds Newsletter_Widget widget.
|
||||
*/
|
||||
class ParteiLinkliste_Widget extends WP_Widget {
|
||||
/**
|
||||
* Register widget with WordPress.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'ParteiLinkliste_Widget', // Base ID
|
||||
__( 'Pirate Links', 'piratenkleider' ),
|
||||
array( 'description' => __( 'List for several pirate party sections worldwide and in some countries', 'piratenkleider' ), ) // Args
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function widget( $args, $instance ) {
|
||||
global $defaultoptions;
|
||||
extract( $args );
|
||||
$bereich = $instance['bereich'] ;
|
||||
if ((!isset($bereich)) || (empty($bereich))) {
|
||||
$bereich = $defaultoptions['default_footerlink_key'];
|
||||
}
|
||||
echo $before_widget;
|
||||
global $default_footerlink_liste;
|
||||
|
||||
$title = $default_footerlink_liste[$bereich]['title'];
|
||||
$url = $default_footerlink_liste[$bereich]['url'];
|
||||
|
||||
if ((isset($url)) && (strlen($url)>5)) {
|
||||
echo $before_title.'<a href="'.$url.'">'.$title.'</a>'.$after_title;
|
||||
} else {
|
||||
echo $before_title.$title.$after_title;
|
||||
}
|
||||
echo '<ul>';
|
||||
|
||||
foreach($default_footerlink_liste[$bereich]['sublist'] as $i => $value) {
|
||||
echo '<li><a href="'.$value.'">';
|
||||
echo $i.'</a></li>';
|
||||
echo "\n";
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = array();
|
||||
$instance['bereich'] = strip_tags( $new_instance['bereich'] );
|
||||
return $instance;
|
||||
}
|
||||
|
||||
|
||||
public function form( $instance ) {
|
||||
global $defaultoptions;
|
||||
if ( isset( $instance[ 'bereich' ] ) ) {
|
||||
$bereich = $instance[ 'bereich' ];
|
||||
} else {
|
||||
$bereich = $defaultoptions['default_footerlink_key'];
|
||||
}
|
||||
|
||||
global $default_footerlink_liste;
|
||||
echo "<label for=\"".$this->get_field_id( 'bereich' )."\">".__( 'Section:', 'piratenkleider' )."</label>\n";
|
||||
echo "<select name=\"".$this->get_field_name( 'bereich' )."\" id=\"".$this->get_field_id( 'bereich' )."\">\n";
|
||||
|
||||
foreach($default_footerlink_liste as $i => $value) {
|
||||
echo "\t\t\t\t";
|
||||
echo '<option value="'.$i.'"';
|
||||
if ( $i == $bereich ) {
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>';
|
||||
if (!is_array($value)) {
|
||||
echo $value;
|
||||
} else {
|
||||
echo $i;
|
||||
}
|
||||
echo '</option>';
|
||||
echo "\n";
|
||||
}
|
||||
echo "</select><br>\n";
|
||||
echo "\t\t\t";
|
||||
}
|
||||
|
||||
} // class Partei Linkliste Widget
|
||||
//
|
||||
// register widget
|
||||
add_action( 'widgets_init', create_function( '', 'register_widget( "ParteiLinkliste_Widget" );' ) );
|
||||
|
||||
|
||||
/**
|
||||
* Adds Bannerlink_Widget widget.
|
||||
*/
|
||||
class Bannerlink_Widget extends WP_Widget {
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'Bannerlink_Widget', // Base ID
|
||||
__( 'Image Link', 'piratenkleider' ),
|
||||
array( 'description' => __( 'Sets an image link for media library', 'piratenkleider' ), ) // Args
|
||||
);
|
||||
}
|
||||
public function form($instance) {
|
||||
$defaults = array(
|
||||
'title' => '',
|
||||
'url' => '',
|
||||
'image_url' => '',
|
||||
'image_id' => 0
|
||||
);
|
||||
$instance = wp_parse_args((array)$instance, $defaults);
|
||||
$title = $instance['title'];
|
||||
$url = $instance['url'];
|
||||
$image_url = $instance['image_url'];
|
||||
$image_id = $instance['image_id'];
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Title:'; ?></label>
|
||||
<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); ?>" />
|
||||
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('url'); ?>"><?php echo 'Target-URL:'; ?></label>
|
||||
<input class="widefat" id="<?php echo $this->get_field_id('url'); ?>"
|
||||
name="<?php echo $this->get_field_name('url'); ?>"
|
||||
type="text" value="<?php echo esc_attr($url); ?>" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('image_url'); ?>"><?php _e('Image:','piratenkleider'); ?>
|
||||
<input class="image_url widefat" id="<?php echo $this->get_field_id('image_url'); ?>"
|
||||
name="<?php echo $this->get_field_name('image_url'); ?>"
|
||||
type="text" value="<?php echo esc_attr($image_url); ?>" />
|
||||
|
||||
<input type="hidden" id="<?php echo $this->get_field_id('image_id'); ?>"
|
||||
class="image_id" name="<?php echo $this->get_field_name('image_id'); ?>" />
|
||||
|
||||
<input class="button upload_image_button" name="upload_image_button" id="<?php echo $this->get_field_id('image_url'); ?>_button" value="<?php _e('Upload', 'piratenkleider'); ?>" />
|
||||
|
||||
|
||||
<br /><?php _e('Select image from media library or enter an URL.', 'piratenkleider'); ?>
|
||||
|
||||
</label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance) {
|
||||
$instance = array();
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['url'] = esc_url($new_instance['url']);
|
||||
$instance['image_url'] = esc_url($new_instance['image_url']);
|
||||
$instance['image_id'] = intval($new_instance['image_id']);
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function widget($args, $instance) {
|
||||
global $defaultoptions;
|
||||
|
||||
extract($args);
|
||||
$title = apply_filters('widget_title', $instance['title']);
|
||||
$url = esc_url($instance['url']);
|
||||
$image_url = esc_url($instance['image_url']);
|
||||
$image_id = intval($instance['image_id']);
|
||||
$image_width = $defaultoptions['bannerlink-width'];
|
||||
$image_height =0;
|
||||
if ($image_id >0) {
|
||||
// Get Thumbnail instead of original
|
||||
$image_attributes = wp_get_attachment_image_src( $image_id, $defaultoptions['bannerlink_name'] );
|
||||
$image_url = $image_attributes[0];
|
||||
$image_width = $image_attributes[1];
|
||||
$image_height = $image_attributes[2];
|
||||
}
|
||||
$site_link = home_url();
|
||||
if ((isset($url))&& (strpos($url, $site_link) !== false)) {
|
||||
$url = wp_make_link_relative($url);
|
||||
}
|
||||
if (($image_id >0) || ((isset($image_url))&& (strpos($image_url, $site_link) !== false))) {
|
||||
$image_url = wp_make_link_relative($image_url);
|
||||
}
|
||||
|
||||
if (!isset($url) && !isset($image_url)) {
|
||||
return;
|
||||
}
|
||||
echo $before_widget;
|
||||
echo '<p class="bannerlink">';
|
||||
if ((isset($url)) && (strlen($url)>0))
|
||||
echo '<a href="'.$url.'">';
|
||||
if ($image_url) {
|
||||
if ($image_height > 0) {
|
||||
echo '<img src="'.$image_url.'" width="'.$image_width.'" height="'.$image_height.'" alt="'.$title.'">';
|
||||
} else {
|
||||
echo '<img src="'.$image_url.'" style="max-width: '.$defaultoptions['bannerlink-width'].'px; height: auto;" alt="'.$title.'">';
|
||||
}
|
||||
} else {
|
||||
echo $title;
|
||||
}
|
||||
if ((isset($url)) && (strlen($url)>0))
|
||||
echo '</a>';
|
||||
echo "</p>\n";
|
||||
echo $after_widget;
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
// register widget
|
||||
add_action( 'widgets_init', create_function( '', 'register_widget( "Bannerlink_Widget" );' ) );
|
||||
|
||||
Reference in New Issue
Block a user