/** * * Shortcode parsing method for Membership page listings * @param array $atts * @return string|void */ function membership_page_listings($atts) { extract(shortcode_atts(array('style' => '', 'columns' => 1, 'product' => 0, 'category' => 0, 'subcategory' => 0, 'comments' => 0, 'drip_content' => 0, 'resize_thumb_height' => 0, 'show_children' => '', 'order' => '', 'hide_description' => 'N'), $atts)); $product = intval($product); $category = intval($category); $subcategory = intval($subcategory); $parentId = 0; $page_id = defined('OP_PAGEBUILDER_ID') ? OP_PAGEBUILDER_ID : $post->ID; $title_font = op_asset_font_style($atts); if (!empty($title_font)) { $title_style = "style='" . $title_font . "'"; } else { $title_style = ''; } $content_font = op_asset_font_style($atts, 'content_font_'); if (!empty($content_font)) { $content_style = "style='" . $content_font . "'"; } else { $content_style = ''; } // which children should we take? if (!empty($show_children)) { $parentId = $page_id; } else { if (!empty($product) && empty($category) && empty($subcategory)) { $parentId = $product; } else { if (!empty($product) && !empty($category) && empty($subcategory)) { $parentId = $category; } else { if (!empty($product) && !empty($category) && !empty($subcategory)) { $parentId = $subcategory; } } } } if (!empty($order)) { $temp = explode('|', $order); $order_column = $temp[0]; $order_direction = $temp[1]; } else { $order_column = 'post_title'; $order_direction = 'asc'; } $args = array('posts_per_page' => -1, 'sort_column' => $order_column, 'sort_order' => $order_direction, 'parent' => $parentId, 'hierarchical' => 0, 'post_status' => 'publish'); $pages = get_pages($args); if ($order_column == 'post_title') { if ($order_direction == 'asc') { usort($pages, array("OptimizePress_LiveEditor_Assets", "sortNaturalAsc")); } else { usort($pages, array("OptimizePress_LiveEditor_Assets", "sortNaturalDesc")); } } if (!empty($resize_thumb_height)) { $img_class = ' thumb_resize '; } else { $img_class = ''; } if (empty($pages) || $parentId == 0) { if (is_admin()) { return __('No child membership pages found! Note: Pages will only show in this once they are Published in Wordpress. Draft pages will not show', OP_SN); } } $html = ''; switch ($columns) { case 1: $class = 'page-listing one-col'; break; case 2: $class = 'page-listing two-col'; break; case 3: $class = 'page-listing three-col'; break; case 4: $class = 'page-listing four-col'; break; } foreach ($pages as $page) { /*if (defined("WS_PLUGIN__OPTIMIZEMEMBER_VERSION")) { if (!is_permitted_by_optimizemember($page->ID, "page")) { continue; } }*/ // drip content $dripContentHtml = ''; if (defined("WS_PLUGIN__OPTIMIZEMEMBER_VERSION")) { global $current_user; $hideContent = false; if (isset($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['filter_wp_query']) && 'all' === $GLOBALS['WS_PLUGIN__']['optimizemember']['o']['filter_wp_query'][0]) { $hideContent = true; } if (!is_permitted_by_optimizemember($page->ID, "page") && true === $hideContent) { continue; } $unavailableContent = c_ws_plugin__optimizemember_utils_gets::get_unavailable_singular_ids_with_dripped_content($current_user); // getting content drip days setting $drip_days = get_post_meta($page->ID, "optimizemember_drip_days", true); if ($drip_days) { // if hide links is disabled in OPM general settings, content by this ID is not available to current user and show drip content timer is checked on // membership page listings element if (false === $hideContent && in_array($page->ID, $unavailableContent) && !empty($drip_content) && !current_user_can('level_10')) { //if ($array = is_page_protected_by_optimizemember($page->ID)) { // is it protected? $time = optimizemember_paid_registration_time(); if (!empty($time) && $time > strtotime("-" . $drip_days . " days")) { $daysTo = intval(($time + $drip_days * 86400 - time()) / 86400); if (0 === $daysTo) { $dripContentHtml = '<p class="pagelisting-drip-content">' . __('Less than a day left to be able to access this content', OP_SN) . '</p>'; } else { $dripContentHtml = '<p class="pagelisting-drip-content">' . sprintf(_n('%d day left to be able to access this content', '%d days left to be able to access this content', $daysTo, OP_SN), $daysTo) . '</p>'; } } //} } // if hide links is enabled in OPM general settings, content by this ID is not available to current user and show drip content timer is disabled on // membership page listings element - hide content completely if (true === $hideContent && in_array($page->ID, $unavailableContent) && !current_user_can('level_10')) { continue; } // if user is not logged in if (true === $hideContent && !is_user_logged_in()) { continue; } } } $meta = get_post_meta($page->ID); if (!empty($meta['_' . OP_SN . '_page_thumbnail'])) { $image = $meta['_' . OP_SN . '_page_thumbnail'][0]; $alt = $page->post_title; } if (!empty($comments)) { $comments = wp_count_comments($page->ID); $commentCount = $comments->approved; $commentHtml = '<p class="pagelisting-comment">' . sprintf(__('%d comments', OP_SN), $commentCount) . '</p>'; } else { $commentHtml = ''; } $meta = $meta['_' . OP_SN . '_membership'][0]; $meta = unserialize(unserialize($meta)); $html .= '<div class="' . $class . '">'; $html .= ' <a href="' . get_permalink($page->ID) . '" class="pagelisting-style-' . $style . ' border"> <div class="thumb">'; if ($image != '') { $html .= '<img src="' . $image . '" alt="' . $alt . '" class="scale-with-grid ' . $img_class . '" />'; } else { $html .= '<img src="' . OP_IMG . 'default-page-listings.png" alt="' . $alt . '" class="scale-with-grid ' . $img_class . '" />'; } $html .= '</div> <div class="content"> <h3 ' . $title_style . '>' . $page->post_title . '</h3>' . $commentHtml . $dripContentHtml; if ($hide_description !== 'Y') { $description = stripslashes(base64_decode($meta['description'])); if (strlen($description) > 140) { $html .= '<p ' . $content_style . '>' . substr($description, 0, 140) . '...</p>'; } else { $html .= '<p ' . $content_style . '>' . $description . '</p>'; } } $html .= '</div> </a> '; $html .= '</div>'; } $html .= '<script type="text/javascript">(function($){function resizeWindow(){if($(window).width()>=767)$(".container").each(function(){var e=0;var t=$(this).find("[class*=\'pagelisting-style-\']");t.css({height:"auto"});t.each(function(){var t=$(this).height();if(t>e)e=t});t.height(e)})}$(document).ready(function(){$(window).bind("resize",resizeWindow);$(window).bind("load",resizeWindow)})})(opjq);</script>' . "\n"; return $html; }
/** * * Shortcode parsing method for Membership page listings * @param array $atts */ function membership_page_listings($atts) { extract(shortcode_atts(array('style' => '', 'columns' => 1, 'product' => 0, 'category' => 0, 'subcategory' => 0, 'comments' => 0, 'drip_content' => 0, 'resize_thumb_height' => 0, 'show_children' => '', 'order' => '', 'hide_description' => 'N'), $atts)); $product = intval($product); $category = intval($category); $subcategory = intval($subcategory); $parentId = 0; $page_id = defined('OP_PAGEBUILDER_ID') ? OP_PAGEBUILDER_ID : $post->ID; $title_font = op_asset_font_style($atts); if (!empty($title_font)) { $title_style = "style='" . $title_font . "'"; } else { $title_style = ''; } $content_font = op_asset_font_style($atts, 'content_font_'); if (!empty($content_font)) { $content_style = "style='" . $content_font . "'"; } else { $content_style = ''; } // which children should we take? if (!empty($show_children)) { $parentId = $page_id; } else { if (!empty($product) && empty($category) && empty($subcategory)) { $parentId = $product; } else { if (!empty($product) && !empty($category) && empty($subcategory)) { $parentId = $category; } else { if (!empty($product) && !empty($category) && !empty($subcategory)) { $parentId = $subcategory; } } } } if (!empty($order)) { $temp = explode('|', $order); $order_column = $temp[0]; $order_direction = $temp[1]; } else { $order_column = 'post_title'; $order_direction = 'asc'; } $args = array('posts_per_page' => -1, 'sort_column' => $order_column, 'sort_order' => $order_direction, 'parent' => $parentId, 'hierarchical' => 0, 'post_status' => 'publish'); $pages = get_pages($args); if (!empty($resize_thumb_height)) { $img_class = ' thumb_resize '; } else { $img_class = ''; } if (empty($pages) || $parentId == 0) { if (is_admin()) { return __('No child membership pages found!', OP_SN); } } $html = ''; switch ($columns) { case 1: $class = 'page-listing one-col'; break; case 2: $class = 'page-listing two-col'; break; case 3: $class = 'page-listing three-col'; break; case 4: $class = 'page-listing four-col'; break; } foreach ($pages as $page) { if (defined("WS_PLUGIN__OPTIMIZEMEMBER_VERSION")) { if (!is_permitted_by_optimizemember($page->ID, "page")) { continue; } } // drip content $dripContentHtml = ''; if (!empty($drip_content) && defined("WS_PLUGIN__OPTIMIZEMEMBER_VERSION")) { $drip_days = get_post_meta($page->ID, "optimizemember_drip_days", true); if ($drip_days) { if ($array = is_page_protected_by_optimizemember($page->ID)) { // is it protected? $time = optimizemember_paid_registration_time(); if (!empty($time) && $time > strtotime("-" . $drip_days . " days")) { $daysTo = intval(($time + $drip_days * 86400 - time()) / 86400); $dripContentHtml = '<p class="pagelisting-drip-content">' . $daysTo . ' days to see this content.</p>'; } } } } $meta = get_post_meta($page->ID); if (!empty($meta['_' . OP_SN . '_page_thumbnail'])) { $image = $meta['_' . OP_SN . '_page_thumbnail'][0]; $alt = $page->post_title; } if (!empty($comments)) { $comments = wp_count_comments($page->ID); $commentCount = $comments->approved; $commentHtml = '<p class="pagelisting-comment">' . $commentCount . ' comments</p>'; } else { $commentHtml = ''; } $meta = $meta['_' . OP_SN . '_membership'][0]; $meta = unserialize(unserialize($meta)); $html .= '<div class="' . $class . '">'; $html .= ' <a href="' . get_permalink($page->ID) . '" class="pagelisting-style-' . $style . ' border"> <div class="thumb">'; if ($image != '') { $html .= '<img src="' . $image . '" alt="' . $alt . '" class="scale-with-grid ' . $img_class . '" />'; } else { $html .= '<img src="' . OP_IMG . 'default-page-listings.png" alt="' . $alt . '" class="scale-with-grid ' . $img_class . '" />'; } $html .= '</div> <div class="content"> <h3 ' . $title_style . '>' . $page->post_title . '</h3>' . $commentHtml . $dripContentHtml; if ($hide_description !== 'Y') { $description = stripslashes(base64_decode($meta['description'])); if (strlen($description) > 140) { $html .= '<p ' . $content_style . '>' . substr($description, 0, 140) . '...</p>'; } else { $html .= '<p ' . $content_style . '>' . $description . '</p>'; } } $html .= '</div> </a> '; $html .= '</div>'; } $html .= '<script type="text/javascript"> function resizeWindow(){if(jQuery(window).width()>=767){jQuery(".container").each(function(){var e=0;var t=jQuery(this).find(".border");t.css({height:"auto"});t.each(function(){var t=jQuery(this).height();if(t>e)e=t});t.height(e)})}}jQuery(document).ready(function(){jQuery(window).bind("resize",resizeWindow);jQuery(window).bind("load",resizeWindow)}) </script>' . "\n"; return $html; }