Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Fixed exception on NULL for get_permalink_light
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Germain committed Aug 20, 2017
1 parent d7fc367 commit d1c05b5
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 344 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ package-lock.json
.DS_Store
ithoughts_tt_gl.log
grunt_localconfig.json
less/*.css
1 change: 1 addition & 0 deletions class/class-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getTermExcerpt( \WP_Post $term ) {
} else {
$content = wp_trim_words( $term->post_content, 25, '...' );
}
$content = strip_shortcodes($content);
return $content;
}

Expand Down
46 changes: 30 additions & 16 deletions class/shortcode/class-glossary.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace ithoughts\tooltip_glossary\shortcode;

if ( ! defined( 'ABSPATH' ) ) {
status_header( 403 );wp_die("Forbidden");// Exit if accessed directly
status_header( 403 );wp_die("Forbidden");// Exit if accessed directly
}


Expand Down Expand Up @@ -157,10 +157,14 @@ public function ithoughts_tt_gl_get_glossary_term_element( $term, $text = null,
}
} else {
if ( is_numeric( $term ) ) {
$term = get_post( $term );
$termRetrieved = get_post( $term );
if(NULL === $termRetrieved){
$backbone->log( \ithoughts\v5_0\LogLevel::WARN, "Term with id \"$term\" and text \"$text\" does not exists.");
}
$term = $termRetrieved;
} else if ( ! ($term instanceof \WP_Post) ) {
// Error
return $text;
$backbone->log( \ithoughts\v5_0\LogLevel::WARN, "Unhandled term descriptor provided:", $term, gettype($term));
$term = NULL;
}
}

Expand Down Expand Up @@ -213,8 +217,12 @@ public function ithoughts_tt_gl_get_glossary_term_element( $term, $text = null,

if ( ! isset( $datas['linkAttrs']['href'] ) ) {
$href = 'javascript::void(0)';
if ( $datas['options']['termlinkopt'] != 'none' ) { // If theere need a link
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term,'glossary' ) );
if ( $datas['options']['termlinkopt'] != 'none' ) { // If there need a link
if ( NULL !== $term ) {
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term,'glossary' ) );
} else {
$backbone->log( \ithoughts\v5_0\LogLevel::WARN, "Tried to call get_permalink_light on NULL term with text \"$text\".");
}
}
$datas['linkAttrs']['href'] = $href;
}
Expand All @@ -231,9 +239,11 @@ public function ithoughts_tt_gl_get_glossary_term_element( $term, $text = null,
$linkElement = '<a ' . $linkArgs . '>' . $text . '</a>';

$datas['attributes']['class'] = 'itg-glossary' . ((isset( $datas['attributes']['class'] ) && $datas['attributes']['class']) ? ' ' . $datas['attributes']['class'] : '');
if(NULL === $term){
$datas['attributes']['class'] .= ' itg-notfound';
}
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $datas['attributes'] );

$backbone = \ithoughts\tooltip_glossary\Backbone::get_instance();
$backbone->add_script( 'qtip' );

return '<span ' . $args . '>' . $linkElement . '</span>';
Expand Down Expand Up @@ -283,8 +293,8 @@ public function save_post_check_for_glossary_usage( $post_id, $post ) {
public function glossary_usage_reset_for_post() {
global $post;
if ( is_singular() && get_post_meta( $post->ID, 'ithoughts_tt_gl_update_term_usage' ) ) :
// Find all glossary terms that have this post noted.
$args = array(
// Find all glossary terms that have this post noted.
$args = array(
'post_type' => 'glossary',
'numberposts' => -1,
'post_status' => 'publish',
Expand All @@ -293,12 +303,12 @@ public function glossary_usage_reset_for_post() {
'value' => $post->ID,
'type' => 'DECIMAL',
),
),
);
$terms = get_posts( $args );
foreach ( $terms as $term ) :
// Delete the meta entry
delete_post_meta( $term->ID, 'ithoughts_tt_gl_term_used', $post->ID );
),
);
$terms = get_posts( $args );
foreach ( $terms as $term ) :
// Delete the meta entry
delete_post_meta( $term->ID, 'ithoughts_tt_gl_term_used', $post->ID );
endforeach;
endif;
}
Expand All @@ -314,9 +324,13 @@ public function glossary_remove_update_marker() {

/** */
public function glossary_shortcode( $atts, $text = '' ) {
/* echo '<hr/>Found shortcode: <pre>';
var_dump(array('atts' => $atts, 'text' => $text));
echo '</pre>';
*/

if ( ! isset( $atts['glossary-id'] ) || ! $atts['glossary-id'] ) {
return $text;
return apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', NULL, $text, $atts );
}
$id = $atts['glossary-id'];
return apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', $id, $text, $atts );
Expand Down
244 changes: 122 additions & 122 deletions class/shortcode/class-termlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace ithoughts\tooltip_glossary\shortcode;

if ( ! defined( 'ABSPATH' ) ) {
status_header( 403 );wp_die("Forbidden");// Exit if accessed directly
status_header( 403 );wp_die("Forbidden");// Exit if accessed directly
}

if ( ! class_exists( __NAMESPACE__ . '\\TermList' ) ) {
Expand Down Expand Up @@ -68,148 +68,148 @@ public function glossary_term_list( $atts, $content = '' ) {
default:{
$mode = self::LIST_MODE_NONE;
}
}

// Sanity check the list of letters (if set by user).
$alphas = $this->filter_alphas_to_array( isset( $data['handled'] ) && isset( $data['handled']['alpha'] ) && $data['handled']['alpha'] ? $data['handled']['alpha'] : null );
// Checks for partial listing options (on first letter, or group)
$group_ids = $this->filter_groupIds_to_array( isset( $data['handled'] ) && isset( $data['handled']['group'] ) ? $data['handled']['group'] : null );

$terms;
$count;

// Define default desc to none. Will generate a simple link
// If no content is required, use microposts. Else, use normal terms
if ( $mode & self::LIST_MODE_MICROPOST ) {
// Add qtip script only if loading tooltips
if ( $mode === self::LIST_MODE_TIP ) {
\ithoughts\tooltip_glossary\Backbone::get_instance()->add_script( 'qtip' );
}

// Sanity check the list of letters (if set by user).
$alphas = $this->filter_alphas_to_array( isset( $data['handled'] ) && isset( $data['handled']['alpha'] ) && $data['handled']['alpha'] ? $data['handled']['alpha'] : null );
// Checks for partial listing options (on first letter, or group)
$group_ids = $this->filter_groupIds_to_array( isset( $data['handled'] ) && isset( $data['handled']['group'] ) ? $data['handled']['group'] : null );

$terms;
$count;

// Define default desc to none. Will generate a simple link
// If no content is required, use microposts. Else, use normal terms
if ( $mode & self::LIST_MODE_MICROPOST ) {
// Add qtip script only if loading tooltips
if ( $mode === self::LIST_MODE_TIP ) {
\ithoughts\tooltip_glossary\Backbone::get_instance()->add_script( 'qtip' );
}

// Fetch microposts
$termsInfos = $this->get_microposts( $group_ids,$alphas );
} else {
// Fetch full posts
$linkdata = apply_filters( 'ithoughts_tt_gl-split-args', $linkdata );
$termsInfos = $this->get_lists_terms( $group_ids,$alphas );
}

$terms = $this->dispatch_per_char( $termsInfos['terms'], 0, 'WP_Post' );
$count = $termsInfos['count'];

// Go through all glossaries, and restrict to alpha list if supplied.
$lists = array();
$countItems = 0;
foreach ( $terms as $char => $terms_char ) {
if ( count( $alphas ) == 0 || in_array( $char, $alphas ) ) {
$lists[] = "<li class=\"glossary-item-header\">$char</li>";
// Fetch microposts
$termsInfos = $this->get_microposts( $group_ids,$alphas );
} else {
// Fetch full posts
$linkdata = apply_filters( 'ithoughts_tt_gl-split-args', $linkdata );
$termsInfos = $this->get_lists_terms( $group_ids,$alphas );
}

$terms = $this->dispatch_per_char( $termsInfos['terms'], 0, 'WP_Post' );
$count = $termsInfos['count'];

// Go through all glossaries, and restrict to alpha list if supplied.
$lists = array();
$countItems = 0;
foreach ( $terms as $char => $terms_char ) {
if ( count( $alphas ) == 0 || in_array( $char, $alphas ) ) {
$lists[] = "<li class=\"glossary-item-header\">$char</li>";
$countItems++;

foreach ( $terms_char as $term ) {
$countItems++;

foreach ( $terms_char as $term ) {
$countItems++;
$term_standardized_post; // If only microposts were retrieved, cast them in WP_Post (usable by standard methods)
if ( $mode & self::LIST_MODE_MICROPOST ) {
$term_standardized_post = $term->to_WP_Post();
} else {
$term_standardized_post = &$term;
}
$linkAttrs = (isset( $linkdata['linkAttrs'] ) && is_array( $linkdata['linkAttrs'] )) ? $linkdata['linkAttrs'] : $linkdata;
$linkAttrs['title'] = esc_attr( $term_standardized_post->post_title );
$linkAttrs['alt'] = esc_attr( $term_standardized_post->post_title );

$link = '';
$content = '';
switch ( $mode ) {
case self::LIST_MODE_NONE:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
}break;

case self::LIST_MODE_TIP:{
$link = apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', $term_standardized_post, null, $linkdata );
} break;

case self::LIST_MODE_EXCERPT:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
$content = '<br>' . '<span class="glossary-item-desc">' . apply_filters( 'ithoughts_tt_gl-term-excerpt', $term_standardized_post ) . '</span>';
} break;

case self::LIST_MODE_FULL:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
$content = '<br>' . '<span class="glossary-item-desc">' . $term->post_content . '</span>';
} break;
}// End switch().

$lists[] = "<li class=\"glossary-item\">$link$content</li>";
}// End foreach().
}// End if().
}// End foreach().
if ( ! isset( $data['handled']['cols'] ) || $data['handled']['cols'] == 0 || $data['handled']['cols'] === false ) {
$data['handled']['cols'] = 1; // set col size to all items
$term_standardized_post; // If only microposts were retrieved, cast them in WP_Post (usable by standard methods)
if ( $mode & self::LIST_MODE_MICROPOST ) {
$term_standardized_post = $term->to_WP_Post();
} else {
$term_standardized_post = &$term;
}
$linkAttrs = (isset( $linkdata['linkAttrs'] ) && is_array( $linkdata['linkAttrs'] )) ? $linkdata['linkAttrs'] : $linkdata;
$linkAttrs['title'] = esc_attr( $term_standardized_post->post_title );
$linkAttrs['alt'] = esc_attr( $term_standardized_post->post_title );

$link = '';
$content = '';
switch ( $mode ) {
case self::LIST_MODE_NONE:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
}break;

case self::LIST_MODE_TIP:{
$link = apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', $term_standardized_post, null, $linkdata );
} break;

case self::LIST_MODE_EXCERPT:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
$content = '<br>' . '<span class="glossary-item-desc">' . apply_filters( 'ithoughts_tt_gl-term-excerpt', $term_standardized_post ) . '</span>';
} break;

case self::LIST_MODE_FULL:{
$href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) );
$target = '';
if ( $data['options']['termlinkopt'] != 'none' ) {
$linkAttrs['target'] = '_blank';
}
$linkAttrs['href'] = &$href;
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs );
$link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>';
$content = '<br>' . '<span class="glossary-item-desc">' . do_shortcode($term->post_content) . '</span>';
} break;
}// End switch().

$lists[] = "<li class=\"glossary-item\">$link$content</li>";
}// End foreach().
}// End if().
}// End foreach().
if ( ! isset( $data['handled']['cols'] ) || $data['handled']['cols'] == 0 || $data['handled']['cols'] === false ) {
$data['handled']['cols'] = 1; // set col size to all items
}
$chunked;
if ( $data['handled']['cols'] != 1 ) {
$termsPerChunkFloat = $countItems / $data['handled']['cols'];
$termsPerChunk = intval( $termsPerChunkFloat );
if ( $termsPerChunkFloat != $termsPerChunk ) {
$termsPerChunk++;
}
$chunked;
if ( $data['handled']['cols'] != 1 ) {
$termsPerChunkFloat = $countItems / $data['handled']['cols'];
$termsPerChunk = intval( $termsPerChunkFloat );
if ( $termsPerChunkFloat != $termsPerChunk ) {
$termsPerChunk++;
}

if ( $termsPerChunk < 1 ) {
$termsPerChunk = 1;
}
$chunked = array_chunk( $lists, $termsPerChunk );
} else {
$chunked = array( &$lists );
if ( $termsPerChunk < 1 ) {
$termsPerChunk = 1;
}
$chunked = array_chunk( $lists, $termsPerChunk );
} else {
$chunked = array( &$lists );
}

$data['attributes']['class'] = 'glossary-list-details' . ((isset( $data['attributes']['class'] ) && $data['attributes']['class']) ? ' ' . $data['attributes']['class'] : '');
/*
$data['attributes']['class'] = 'glossary-list-details' . ((isset( $data['attributes']['class'] ) && $data['attributes']['class']) ? ' ' . $data['attributes']['class'] : '');
/*
if(isset($data["handled"]["masonry"])){
$data["attributes"]["class"] .= " masonry";
$data["attributes"]["class"] = trim($data["attributes"]["class"]);
$data["attributes"]["data-cols"] = $data["handled"]["cols"];
}*/
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $data['attributes'] );
$args = \ithoughts\v5_0\Toolbox::concat_attrs( $data['attributes'] );

$return = '<div ' . $args . '>';
if ( isset( $data['handled']['masonry'] ) ) {/*
$return = '<div ' . $args . '>';
if ( isset( $data['handled']['masonry'] ) ) {/*
\ithoughts\tooltip_glossary\Backbone::get_instance()->add_script('list');
$return .= '<ul class="glossary-list">';
foreach( $chunked as $col => $items ){
$return .= implode( '', $items );
}
$return .= '</ul>';*/
} else {
foreach ( $chunked as $col => $items ) {
$return .= '<ul class="glossary-list">';
$return .= implode( '', $items );
$return .= '</ul>';
}
} else {
foreach ( $chunked as $col => $items ) {
$return .= '<ul class="glossary-list">';
$return .= implode( '', $items );
$return .= '</ul>';
}
$return .= '</div>';
}
$return .= '</div>';

return $return;
return $return;
} // glossary_term_list
} // termlist
}// End if().
Loading

0 comments on commit d1c05b5

Please sign in to comment.