From 184e7980d8e32dbf5342a3c382843557d5bce51c Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 6 Jul 2016 16:56:23 -0400 Subject: [PATCH] Updates to shortcodes to clean up display of shortcode options in Management. Added code to fix up canonical page URLs for detail pages in add-ons. Also added code to use the canonical page URL fix up filter to fix member-detail page canonical URL tags. --- controllers/front.php | 1 + models/admin/shortcodes/index.php | 15 +- models/front/members/detail.php | 9 +- models/front/members/detail.php~ | 302 ----------------------------- setup/frontHooks.php | 93 +++++++++ setup/shortcodes.php | 28 +-- views/admin/shortcodes/header.html | 2 +- views/admin/shortcodes/index.html | 26 ++- 8 files changed, 124 insertions(+), 352 deletions(-) delete mode 100644 models/front/members/detail.php~ diff --git a/controllers/front.php b/controllers/front.php index 79cca951..b078c925 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -88,6 +88,7 @@ class glmMembersFront extends GlmPluginSupport // Add filters for use anywhere else (apply_filter). Will have to add this to index.php eventually add_filter('glmMembersFrontScriptsFilter',array($this,'glmMembersFrontScripts')); add_action('glmMembersFrontCSSFilter',array($this,'glmMembersFrontCSS')); + } /** diff --git a/models/admin/shortcodes/index.php b/models/admin/shortcodes/index.php index d3cf79c2..52327354 100644 --- a/models/admin/shortcodes/index.php +++ b/models/admin/shortcodes/index.php @@ -67,26 +67,13 @@ class GlmMembersAdmin_shortcodes_index public function modelAction($actionData = false) { - $shortcodesDescription = ''; - - // For each add-on that's registered - foreach ($this->config['addOns'] as $a) { - - // Add their shortcodes descriptions - if (isset($a['shortcodesDescription'])) { - $shortcodesDescription .= $a['shortcodesDescription']; - } - - } - // Return status, any suggested view, and any data to controller return array( 'status' => true, 'modelRedirect' => false, 'view' => 'admin/shortcodes/index.html', 'data' => array( - 'shortcodesDescription' => $shortcodesDescription, - 'junk' => 'My Junk' + 'addOns' => $this->config['addOns'] ) ); diff --git a/models/front/members/detail.php b/models/front/members/detail.php index e7f0e6f8..65ac6b57 100644 --- a/models/front/members/detail.php +++ b/models/front/members/detail.php @@ -101,9 +101,6 @@ class GlmMembersFront_members_detail extends GlmDataMemberInfo } - public function fancybox_scripts(){ - - } /* * Perform Model Action * @@ -140,6 +137,7 @@ class GlmMembersFront_members_detail extends GlmDataMemberInfo */ public function modelAction ($actionData = false) { + /**** NEED TO REVIEW WHERE THESE STYLES SHOULD BE ENQUEUED - SHOULD NOT BE HERE ****/ wp_enqueue_style('fancyStyle', GLM_MEMBERS_PLUGIN_URL . 'fancybox/source/jquery.fancybox.css?v=2.1.5'); wp_enqueue_style('fancyStyleButtons', GLM_MEMBERS_PLUGIN_URL . 'fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5'); wp_enqueue_style('fancyStyleThumbs', GLM_MEMBERS_PLUGIN_URL . 'fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7'); @@ -314,11 +312,12 @@ class GlmMembersFront_members_detail extends GlmDataMemberInfo } } - + $expanded = htmlspecialchars($_GET['expanded']); - + // Since the ID we recieved with the member data is the pointer to the member info record, replace it with member ID $memberData['id'] = $memberData['member_pointer']; + // Compile template data $templateData = array( 'haveMember' => $haveMember, diff --git a/models/front/members/detail.php~ b/models/front/members/detail.php~ deleted file mode 100644 index 8d773e9d..00000000 --- a/models/front/members/detail.php~ +++ /dev/null @@ -1,302 +0,0 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @version 0.1 - */ - -// Translation table for [glm-member-detail] "show" options to configuration parameters -$GLOBALS['showOpts'] = array( - 'map' => 'detail_show_map', - 'map-logo' => 'detail_map_show_logo', - 'map-description' => 'detail_map_show_descr', - 'map-short-description' => 'detail_map_show_short_descr', - 'map-address' => 'detail_map_show_address', - 'map-street' => 'detail_map_show_street', - 'map-city-state-zip' => 'detail_map_show_citystatezip', - 'map-country' => 'detail_map_show_country', - 'map-region' => 'detail_map_show_region', - 'map-phone' => 'detail_map_show_phone', - 'map-toll-free' => 'detail_map_show_tollfree', - 'map-url' => 'detail_map_show_url', - 'map-url-new-target' => 'detail_map_show_url_newtarget', - 'map-email' => 'detail_map_show_email', - 'map-categories' => 'detail_map_show_categories', - 'map-credit-cards' => 'detail_map_show_creditcards', - 'map-amentities' => 'detail_map_show_amenities', - 'logo' => 'detail_show_logo', - 'address' => 'detail_show_address', - 'street' => 'detail_show_street', - 'city-state-zip' => 'detail_show_citystatezip', - 'country' => 'detail_show_country', - 'region' => 'detail_show_region', - 'description' => 'detail_show_descr', - 'short-description' => 'detail_show_short_descr', - 'phone' => 'detail_show_phone', - 'toll-free' => 'detail_show_tollfree', - 'url' => 'detail_show_url', - 'url-new-target' => 'detail_show_url_newtarget', - 'email' => 'detail_show_email', - 'categories' => 'detail_show_categories', - 'credit-cards' => 'detail_show_creditcards', - 'amentities' => 'detail_show_amenities' -); - -// Load Members data abstract -require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberInfo.php'); - -/* - * This class performs the work for the default action of the "Members" menu - * option, which is to display the members dashboard. - * - */ - -class GlmMembersFront_members_detail extends GlmDataMemberInfo -{ - - /** - * WordPress Database Object - * - * @var $wpdb - * @access public - */ - public $wpdb; - /** - * Plugin Configuration Data - * - * @var $config - * @access public - */ - public $config; - - /* - * Constructor - * - * This contructor sets up this model. At this time that only includes - * storing away the WordPress data object. - * - * @return object Class object - * - */ - public function __construct ($wpdb, $config) - { - - // Save WordPress Database object - $this->wpdb = $wpdb; - - // Save plugin configuration object - $this->config = $config; - - // Run constructor for members data class - parent::__construct(false, false); - - } - - /* - * Perform Model Action - * - * This method does the work for this model and returns any resulting data - * - * @return array Status and data array - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'menuItemRedirect' - * - * If not false, provides a menu item the controller should - * execute after this one. Normally if this is used, there would also be a - * modelRedirect value supplied as well. - * - * 'modelRedirect' - * - * If not false, provides an action the controller should execute after - * this one. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - */ - public function modelAction ($actionData = false) - { - wp_enqueue_style('fancyStyle', GLM_MEMBERS_PLUGIN_URL . 'css/jquery.fancybox.css'); - wp_enqueue_script('fancyScript', GLM_MEMBERS_PLUGIN_URL . 'js/jquery.fancybox.js', array('jquery'), '', true ); -echo GLM_MEMBERS_PLUGIN_URL; - - - $where = ''; - $haveMember = false; - $haveImageGallery = false; - $success = false; - - // Check for "show" shortcode parameter - $settings = array(); - $showList = $actionData['request']['show']; - - if ($showList) { - - // Separate options and see if we have any - $show = explode(',', $showList); - if (count($show) > 0) { - - // For each option - foreach ($show as $s) { - - $s = trim($s); - - // If we're setting all - if ($s == 'all') { - - while (list($key, $val) = each($GLOBALS['showOpts'])) { - $settings[$val] = true; - } - - // Or we're clearing all - } elseif ($s == 'none') { - - while (list($key, $val) = each($GLOBALS['showOpts'])) { - $settings[$val] = false; - } - - // Or it's a single option - } else { - - // Check if we're setting or clearing - $tf = $s[0]; - if ($tf == '+') { - $tf = true; - } elseif ($tf == '-') { - $tf = false; - } else { - $tf = null; - } - - // If we have +/- and we have the key in our showOpts array - $k = substr($s, 1); - if ($tf !== null && isset($GLOBALS['showOpts'][$k])) { - - // Get the name of the configuration option - $c = $GLOBALS['showOpts'][$k]; - - // If the configuration option exists, add to list of modified settings - if (isset($this->config['settings'][$c])) { - $settings[$c] = $tf; - } - } - - } - - } - - } - } - - - // If we have a member slug supplied from a rewrite - get the id - $rrMemberSlug = get_query_var('memberslug', ''); - if ($rrMemberSlug != '') { - - $sql = " - SELECT id - FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX. "members - WHERE member_slug = '$rrMemberSlug' - ;"; - $id = $this->wpdb->get_var($sql); - - // Otherwise if member ID submitted in the URL - } elseif (isset($_REQUEST['id']) && $_REQUEST['id'] > 0) { - - $id = ($_REQUEST['id'] - 0); - - // Otherwise if ID from the short-code - } elseif (isset($actionData['request']) && isset($actionData['request']['id'])) { - - $id = ($actionData['request']['id'] - 0); - - } - - // Check that ID is a positive value - if ($id <= 0) { - - return array( - 'status' => true, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'front/error/index.html', - 'data' => false - ); - - } - - // Default is we didn't find the member info - $memberData = false; - $haveMember = false; - $haveImageGallery = false; - $imageGallery = false; - - // Find the active member info record and get it with main member data - $memberData = $this->getActiveInfoForMember($id); - - if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { - glmMembersFront::addNotice($memberData, 'DataBlock', 'Member Info with Member Data'); - } - - // If we did get member Info - if ($memberData) { - - $success = true; - $haveMember = true; - - // Also get any image gallery images - require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php'); - $Images = new GlmDataImages($this->wpdb, $this->config); - $imageGallery = $Images->getGallery($this->config['ref_type_numb']['MemberInfo'], $memberData['id']); - $haveImageGallery = ($imageGallery != false); - - } - - // Since the ID we recieved with the member data is the pointer to the member info record, replace it with member ID - $memberData['id'] = $memberData['member_pointer']; - - // Compile template data - $templateData = array( - 'haveMember' => $haveMember, - 'member' => $memberData, - 'haveImageGallery' => $haveImageGallery, - 'imageGallery' => $imageGallery - - ); - - // Return status, suggested view, and data to controller - return array( - 'status' => $success, - 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'front/members/detail.html', - 'data' => $templateData, - 'settings' => $settings - ); - - } - - -} - -?> diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 2b2f9794..30ad731a 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -45,6 +45,99 @@ if ( ! isset( $rules['('.$this->config['settings']['canonical_member_page'].')/( } +/* + * Add a filter to correct rel_canonical header entries + * + * This replaces the WordPress wp_head "rel_canonical" action hook and + * includes a new filter that permits other code to link into the filter + * to replace the canonical URL. + * + */ + +// Replace WordPress head tag 'rel_canonical' action with our own to handle +// detail pages that need correct canonical URLs. +add_action('init', function() { + + remove_action( 'wp_head', 'rel_canonical'); + add_action( 'wp_head', function() { + + // Original Code from wp-includes/link-template.php rel_canonical() + if ( ! is_singular() ) { + return; + } + + global $wp_the_query; + if ( ! $id = get_queried_object_id() ) { + return; + } + + $url = get_permalink( $id ); + + // Create a filter that can be used to provide a different canonical URL + // Note that only one add-on linked to this filter may provide the URL at a time! + $newCanonicalSlug = apply_filters( 'glm_rel_canonical_slug', false ); + + // Output our replacement canonical URL and quit. + if ($newCanonicalSlug) { + echo "\n"; + return; + } + + // Remainder of original code from wp-includes/link-template.php rel_canonical() + $page = get_query_var( 'page' ); + if ( $page >= 2 ) { + if ( '' == get_option( 'permalink_structure' ) ) { + $url = add_query_arg( 'page', $page, $url ); + } else { + $url = trailingslashit( $url ) . user_trailingslashit( $page, 'single_paged' ); + } + } + + $cpage = get_query_var( 'cpage' ); + if ( $cpage ) { + $url = get_comments_pagenum_link( $cpage ); + } + echo '\n"; + + }); // add_action wp_head + + return; +}); // do_action 'init' + +/* End of rel_canonical code */ + + +/* + * Member Detail Page Canonical URL Fix + * + * Since the member detail pages are actually all the same page, and since WordPress has a specific + * canonical URL for that page, we need to override the rel='canonical' value in the page header. + * + * The code below checks if we're on a member detail page and if so returns the member slug so that + * can be added to the URL. The matching apply_filters is in the main plugin in setup/frontHooks.php. + */ +add_filter('glm_rel_canonical_slug', function($detailSlug) { + + // If another add-on already supplied the detail slug, then just return that. + if ($detailSlug != false) { + return $detailSlug; + } + + // Check if the page is a member-detail page use the correct + if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, $this->config['settings']['canonical_member_page']) > 0) { + + // Parse out only the member slug and use that + $m = array(); + preg_match('|.*/'.$this->config['settings']['canonical_member_page'].'/([^/]*).*|', GLM_MEMBERS_PLUGIN_CURRENT_URL, $m ); + $detailSlug = $m[1]; + + } + + return $detailSlug; +}); + + + // Add memberslug query var add_filter('query_vars', function($vars) { array_push($vars, 'memberslug'); diff --git a/setup/shortcodes.php b/setup/shortcodes.php index e8481bbd..ba198413 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -168,18 +168,13 @@ $glmMembersShortcodes = array( ); $glmMembersShortcodesDescription = ' - - - @@ -188,12 +183,10 @@ $glmMembersShortcodesDescription = ' category="{ category ID(s) }" @@ -202,19 +195,19 @@ $glmMembersShortcodesDescription = ' category-name="{ category name(s) }" - + @@ -222,14 +215,12 @@ $glmMembersShortcodesDescription = ' blank-start="{True/False}" @@ -238,11 +229,9 @@ $glmMembersShortcodesDescription = ' show="{ content to show }" @@ -321,7 +306,6 @@ $glmMembersShortcodesDescription = ' id="{ member ID }" @@ -338,11 +321,9 @@ $glmMembersShortcodesDescription = ' show="{ content to show }" -
ShortcodeAttributeDescription
[glm-members-list]   -

Displays a list of members and a map with markers for each member. Optionally, the attributes below may used to modify the display of this page. -

-

The "category" attribute is used display only members in a specific category or categories. To select multiple categories, separate the categories with a ",". Categories are specified by ID number. The ID for each category is shown in the Member Categories list. -

-

The "category-name" attribute is used display only members in a specific category or categories by specifying the category names. To select multiple categories, separate the category names with a ",". Category names must match the name of a category exactly to be selected. Category names must be enclosed in quotes. -

amenity-groups="1,2"

The "amenity-groups" attribute is used to display only the amenities that are in specific groups or a group. - Separate the groups with a ","

+ The "amenity-groups" attribute is used to display only the amenities that are in specific groups or a group. + Separate the groups with a "," +
  -

The "blank-start" attribute tells the page whether or not to display the list of members when the user first hits the page. When "blank-start" is "True", the page first displays with the member search form but without any list of members. When the user submits their first search, the page is re-displayed with the member list resuts. Subsequent submissions of the page also display any results found by the search as does selection of the alpha (letter) links. -

-

The "show" attribute is used control what content should be displayed in the member list. The default is to show the content selected in the "Management", "General Settings" page under "Member List Page Options". -

Content to show or not show is specified by a comma separated list of the items listed below. Each item must be preceded by either a "+" or a "-" to @@ -291,9 +280,7 @@ $glmMembersShortcodesDescription = ' view="{ view to use }"

-

Current options available are: bars (default), grid -

The "view" attribute tells the page which view file to use. The "bars" value will display by default, and features a succession of page-wide bars containing an image, member contact @@ -309,10 +296,8 @@ $glmMembersShortcodesDescription = '

[glm-member-detail]   -

Displays details for a specific member along with a map showing their location. The "id" attribute below is required to specify which member to display. -

-

This is an optional attribute for [glm-member-detail] that specifies the ID of the desired member. The ID for a member is displayed both in the left column of the member list and at the top of the Member Dashboard. Only one ID may @@ -329,7 +313,6 @@ $glmMembersShortcodesDescription = ' member name slug as the last part of the path in the URL and try to locate an active member information record with "Name for URLs" set to the same string. -

-

The "show" attribute is used control what content should be displayed in member detail. The default is to show the content selected in the "Management", "General Settings" page under "Member Detail Page Options". -

Content to show or not show is specified by a comma separated list of the items listed below. Each item must be preceded by either a "+" or a "-" to @@ -383,5 +364,4 @@ $glmMembersShortcodesDescription = '

'; diff --git a/views/admin/shortcodes/header.html b/views/admin/shortcodes/header.html index f9fdb916..4aaea61f 100644 --- a/views/admin/shortcodes/header.html +++ b/views/admin/shortcodes/header.html @@ -2,4 +2,4 @@

{$glmPluginName}

- \ No newline at end of file +
\ No newline at end of file diff --git a/views/admin/shortcodes/index.html b/views/admin/shortcodes/index.html index d87855d4..19a2e670 100644 --- a/views/admin/shortcodes/index.html +++ b/views/admin/shortcodes/index.html @@ -21,14 +21,28 @@

 

- {$shortcodesDescription} + {$glmActive = true} + {foreach $addOns as $a} + {if isset($a.shortcodes)} + {if $a.shortcodes|@count gt 0} + + {$a.shortcodesDescription} +
+ {$glmActive = false} + {/if} + {/if} + {/foreach}