Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final @TODOs added (4 total). #1329

Merged
merged 5 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions inc/post-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

// This function scans the template files of the active theme,
// and returns an array of [Template Name => {file}.php]
if( !function_exists( 'get_post_templates' ) ) {
if( ! function_exists( 'get_post_templates' ) ) {
function get_post_templates() {
$theme = wp_get_theme();
$templates = $theme->get_files( 'php', 1, true );
$post_templates = array();

$base = array(trailingslashit( get_template_directory()), trailingslashit( get_stylesheet_directory() ) );
$base = array( trailingslashit( get_template_directory() ), trailingslashit( get_stylesheet_directory() ) );

foreach ( (array)$templates as $template ) {
$template = WP_CONTENT_DIR . str_replace( WP_CONTENT_DIR, '', $template );
Expand All @@ -27,12 +27,14 @@ function get_post_templates() {
$template_data = implode( '', file( $template ) );

$name = '';
if ( preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name ) )
if ( preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name ) ) {
$name = _cleanup_header_comment( $name[1] );
}

if ( !empty( $name ) ) {
if( basename( $template ) != basename(__FILE__) )
if( basename( $template ) != basename(__FILE__) ) {
$post_templates[trim($name)] = $basename;
}
}
}

Expand All @@ -42,15 +44,15 @@ function get_post_templates() {
}

// build the dropdown items
if( !function_exists( 'post_templates_dropdown' ) ) {
if( ! function_exists( 'post_templates_dropdown' ) ) {
function post_templates_dropdown() {
global $post;
$post_templates = get_post_templates();

foreach ( $post_templates as $template_name => $template_file ) { //loop through templates, make them options
if ( $template_file == get_post_meta( $post->ID, '_wp_post_template', true ) ) {
$selected = ' selected="selected"';
} else {
if ( $template_file == get_post_meta( $post->ID, '_wp_post_template', true ) ) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$opt = '<option value="' . $template_file . '"' . $selected . '>' . $template_name . '</option>';
Expand All @@ -63,17 +65,17 @@ function post_templates_dropdown() {
* Filter the single template value, and replace it with
* the template chosen by the user, if they chose one.
*/
if( !function_exists( 'get_post_template' ) ) {
if( ! function_exists( 'get_post_template' ) ) {
function get_post_template( $template ) {
global $post;
if ( is_object( $post ) ) {
$custom_field = get_post_meta( $post->ID, '_wp_post_template', true );
}
if ( !empty( $custom_field ) ) {
if ( file_exists( get_stylesheet_directory() . "/{$custom_field}") ) {
$template = get_stylesheet_directory() . "/{$custom_field}";
} else if ( file_exists( get_template_directory() . "/{$custom_field}") ) {
$template = get_template_directory() . "/{$custom_field}";
if ( file_exists( get_stylesheet_directory() . '/{$custom_field}' ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschweigert Can we check that this works? I think that switching to single quotes here breaks the curly-braces interpretation: https://secure.php.net/manual/en/language.operators.string.php#110937

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests failed to run because the branch was deleted before tests could be run: https://travis-ci.org/INN/Largo/builds/166745124

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sorry, editing too fast.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why we're using curly braces here but that's for another day, i suppose

$template = get_stylesheet_directory() . '/{$custom_field}';
} else if ( file_exists( get_template_directory() . '/{$custom_field}') ) {
$template = get_template_directory() . '/{$custom_field}';
}
}
return $template;
Expand All @@ -98,15 +100,15 @@ function is_post_template( $template = '' ) {

$post_template = get_post_meta( get_queried_object_id(), '_wp_post_template', true );

if ( empty( $template ) )
if ( empty( $template ) ) {
return (bool) $post_template;

if ( $template == $post_template )
}
if ( $template == $post_template ) {
return true;

if ( 'default' == $template && ! $post_template )
}
if ( 'default' == $template && ! $post_template ) {
return true;

}
return false;
}

Expand All @@ -123,7 +125,7 @@ function is_post_template( $template = '' ) {
*
* This does not remove leading images that are different from the post featured media
*
* The changes to the content in this function should eventually be made
* @TODO The changes to the content in this function should eventually be made
* permanent in the database. (@see https://github.com/INN/Largo/issues/354)
*
* If you would like to disable this function globally or on certain posts,
Expand All @@ -139,7 +141,7 @@ function largo_remove_hero( $content ) {

global $post;
// Abort if there is no global $post
if ( !isset( $post ) ) {
if ( ! isset( $post ) ) {
return $content;
}

Expand Down Expand Up @@ -167,29 +169,26 @@ function largo_remove_hero( $content ) {
*/
$do_run = apply_filters( 'largo_remove_hero', true, $post );

if( !$do_run ) {
if ( ! $do_run ) {
return $content;
}

if( !has_post_thumbnail( $post->ID ) ) {
if ( ! has_post_thumbnail( $post->ID ) ) {
return $content;
}

$options = get_post_custom( $post->ID );

if( isset( $options['featured-image-display'][0] ) ) {
if ( isset( $options['featured-image-display'][0] ) ) {
return $content;
}

if(
of_get_option( 'single_template' ) != 'normal' &&
of_get_option( 'single_template' ) != 'classic'
) {
if ( of_get_option( 'single_template' ) != 'normal' && of_get_option( 'single_template' ) != 'classic' ) {
return $content;
}

$p = explode( "\n", $content );

// 2: Find an image (regex)
//
// Creates the array:
Expand All @@ -201,7 +200,7 @@ function largo_remove_hero( $content ) {

// 3: if there's no image, there's nothing to worry about.

if( !$hasImg ) {
if( ! $hasImg ) {
return $content;
}

Expand All @@ -221,23 +220,24 @@ function largo_remove_hero( $content ) {

$classes = $classes[1];

if( !$pImgId ) {
if ( ! $pImgId ) {
$pattern = '/wp-image-(\d+)/';
preg_match( $pattern, $classes, $imgId);
$pImgId = $imgId[1];
}

if( !($pImgId == $featureImgId) )
if ( ! ( $pImgId == $featureImgId ) ) {
return $content;

}

// 5: Check if it's a full width image, or if the image is not large enough to be a hero.
if( strpos( $classes,'size-small' ) || strpos( $classes,'size-medium' ) )
if ( strpos( $classes,'size-small' ) || strpos( $classes,'size-medium' ) )
return $content;

// 6: Else, shift the first paragraph off the content and return.
array_shift( $p );
$content = implode( "\n", $p );

return $content;

}
Expand All @@ -247,30 +247,30 @@ function largo_remove_hero( $content ) {
/**
* Retrieves the attachment ID from the file URL
* (or that of any thumbnail image)
*
*
* @since 0.4
* @see https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
*
*
* @return Int ID of post attachment (or false if not found)
*/
*/
function largo_url_to_attachmentid( $url ) {

global $wpdb;
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ) );

if( !empty( $attachment ) )
return $attachment[0];
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ) );

// Check if there's a size in the url and remove it.

$url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $url );
$attachment = $wpdb->get_col($wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ) );

if( !empty( $attachment ) )
return $attachment[0];
else
return false;
if ( ! empty( $attachment ) ) {
return $attachment[0];
}

// Check if there's a size in the url and remove it.
$url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $url );
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $url ) );

if ( ! empty( $attachment ) ) {
return $attachment[0];
} else {
return false;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/floating-social-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
*
* Returns an array with the 0th index the offset from top and the 1st index the offset from bottom.
*
* Things to consider:
* @TODO ? Things to consider:
* if there's a hero unit, we need to use the bottom of that
* if there isn't a hero image, then we can use the bottom of `#content > article > header`
* afaik, we don't add hero units after the page loads, so this should be good for now
Expand Down
4 changes: 2 additions & 2 deletions js/tinymce/plugins/largo/tinymce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function init() { //this doesn't seem to actually be getting called, despite what's in window.php?
function init() { // @TODO ? this doesn't seem to actually be getting called, despite what's in window.php?
tinyMCEPopup.resizeToInnerSize();
}

Expand Down Expand Up @@ -80,4 +80,4 @@ jQuery(document).ready(function($) {
}

widthToggle();
});
});
3 changes: 1 addition & 2 deletions lib/lessc.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ protected function compileProp($prop, $block, $out) {

if ($mixins === null) {
// fwrite(STDERR,"failed to find block: ".implode(" > ", $path)."\n");
break; // throw error here??
break; // @TODO ? throw error here??
}

foreach ($mixins as $mixin) {
Expand Down Expand Up @@ -3501,4 +3501,3 @@ class lessc_formatter_lessjs extends lessc_formatter_classic {
public $assignSeparator = ": ";
public $selectorSeparator = ",";
}