$which_menu, 'container' => false, 'echo' => false, 'items_wrap' => '', 'depth' => 0, ); $menu = wp_nav_menu( $args ); $menu_class = sanitize_html_class( $which_menu ); $label = esc_html__( 'Menu', 'anchorage' ); $out = " "; return $out; } function anchorage_header_menu( $which_menu, $menu_class = '' ) { $menu = anchorage_menu( $which_menu, $menu_class = '' ); $home_href = esc_url(get_bloginfo( 'url' ) ); $blog_title = wp_kses_post( get_bloginfo( 'name' ) ); $home_link = "

$blog_title

"; echo "
$home_link $menu "; if ( is_active_sidebar( 'header-widgets' ) ) { echo ' '; } echo '
'; } function anchorage_arrow( $direction = 'down', $classes = array(), $href = '#' ) { $left = esc_html( '←', 'anchorage' ); $up = esc_html( '↑', 'anchorage' ); $right = esc_html( '→', 'anchorage' ); $down = esc_html( '↓', 'anchorage' ); if ( $direction == 'left' ) { $out = $left; } elseif ( $direction == 'up' ) { $out = $up; } elseif ( $direction == 'right' ) { $out = $right; } else { $out = $down; } $classes = array_map( 'sanitize_html_class', $classes ); $classes = implode( ' ', $classes ); $classes = " class='$classes arrow' "; $out = " $out "; $href = esc_attr( $href ); $out = "$out"; return $out; } /** * Returns a WordPress search form. * * Accepts arguments to inject CSS classes into the form, which this theme uses * in order to comply with SMACCS. Passing dynamic class values for each * instance would not be possible with the normal use of searchform.php. * * @param array $form_class CSS Classes for the form. * @param array $search_input_class CSS Classes for the search input. * @return string A search form. * * @since anchorage 1.0 */ function anchorage_search_form( $form_classes = array(), $search_input_classes = array() ) { // An array of CSS classes for the search form. $form_classes = array_map( 'sanitize_html_class', $form_classes ); $form_classes_string = implode( ' ', $form_classes ); // An array of CSS classes for the search input. $search_input_classes = array_map( 'sanitize_html_class', $search_input_classes ); $search_input_string = implode( ' ', $search_input_classes ); $placeholder = esc_attr__( 'Search', 'anchorage' ); if( isset( $_GET['s'] ) ) { $placeholder = esc_attr( $_GET['s'] ); } $out =" "; return $out; } /** * Return a string to denote the post format, if not standard. * * @return string [description] */ function anchorage_get_post_format(){ global $post; $post_id = absint( $post->ID ); $format = get_post_format( $post_id ); $format = esc_html( $format ); if ( empty( $format ) ) { return false; } $out = "$format →"; return $out; } /** * Return an HTML img tag for the first image in a post content. Used to draw * the content for posts of the "image" format. * * @return string An HTML img tag for the first image in a post content. */ function anchorage_get_first_image() { // Expose information about the current post. global $post; // We'll trap to see if this stays empty later in the function. $src = ''; // Grab all img src's in the post content $output = preg_match_all( '//i', $post->post_content, $matches ); // Grab the first img src returned by our regex. if( ! isset ( $matches[1][0] ) ) { return false; } $src = $matches[1][0]; // Sanitize for output $src = esc_url( $src ); // Make sure there's still something worth outputting after sanitization. if( empty( $src ) ) { return false; } // Grab and sanitize the post title as an alt. $alt = esc_attr( $post->post_title ); $out = "$alt"; // Trap to see if the post has a caption shortcode $caption = ''; if( has_shortcode( $post->post_content, 'caption' ) ) { $output = preg_match_all( '/caption=(.*)\]/smU', $post->post_content, $matches ); if($output){ $caption = $matches[1][0]; $caption = trim($caption, '"'); $caption = trim($caption, "'"); } else { // Grab the content of the first caption preg_match_all( '/\[caption\s?.*\](.*)\[\/caption\]/smU', $post->post_content, $matches ); $caption = strip_tags( $matches[1][0], '

' ); } } // Trap to see if the first image is linked $href = ''; $content_before_first_image = explode( 'post_content ); $content_before_first_image = $content_before_first_image[0]; $href = get_url_in_content( $content_before_first_image ); if( ! empty( $content_before_first_image ) ) { $out = "$out"; } // if the file is on the server, grab the exif $exif = ''; $path = anchorage_file_is_on_server( $src ); if( ! empty( $path ) ) { $path = anchorage_file_is_on_server( $src ); $exif = anchorage_get_media_meta( $path, 'image' ); } // wp_die( var_dump( $src ) ); // If there is a caption, return a figure if( ! empty( $caption ) ) { $out = "

$out
$caption
"; } $out.=$exif; return $out; } function anchorage_uploads_path(){ $dir = wp_upload_dir(); $path = $dir['basedir']; return $path; } function anchorage_uploads_url(){ $dir = wp_upload_dir(); $url = $dir['baseurl']; return $url; } function anchorage_get_first_media( $type ){ global $post; $content = get_media_embedded_in_content( $post->post_content ); if ( get_url_in_content( $content ) ) { $content = get_media_embedded_in_content( $content ); $w = get_url_in_content( $content ); } else { $content = $post->post_content; $w = get_url_in_content( $content ); } $path = anchorage_file_is_on_server( $w ); if( ! $path ) { return false; } if( ( $type == 'audio' ) || ( $type == 'video' ) ) { return anchorage_get_media_meta( $path, $type ); } else { return "$type"; } } function anchorage_get_media_meta( $path, $type ) { $out=''; $fields = false; if( $type == 'audio' ) { require_once( ABSPATH . 'wp-admin/includes/media.php' ); $media = wp_read_audio_metadata( $path ); $fields = array( 'bitrate', 'year', 'artist', 'genre', 'title', 'album', 'length_formatted', ); } elseif( $type == 'video' ) { require_once( ABSPATH . 'wp-admin/includes/media.php' ); $media = wp_read_video_metadata( $path ); $fields = array( 'length_formatted', 'fileformat', 'dataformat', 'mime_type', 'codec', ); } elseif( $type == 'image' ) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); $media = exif_read_data( $path ); $fields = array( 'ExposureTime', array( 'COMPUTED', 'ApertureFNumber' ), 'Model', 'DateTimeOriginal' ); } if( !is_array( $fields ) ) { return false; } $meta = array(); foreach( $fields as $f ) { if( is_string( $f ) ) { if( isset( $media[$f] ) ){ $meta[$f] = $media[$f]; } } elseif( is_array( $f ) ) { $first = $f[0]; $second = $f[1]; if( isset( $media[$first][$second] ) ) { $meta[$second] = $media[$first][$second]; } } } foreach( $meta as $k => $v ) { $k = str_replace( '_', ' ', $k ); if(stristr( $k, 'Date' ) ) { $format = get_option( 'date_format' ); $v = strtotime( $v ); $v = date( $format, $v ); } if( empty( $v ) ) { continue; } $out .= "

$k: $v

"; } if( empty( $out ) ) { return false; } $out="