popup='page' is set * * This functionality is work in progress and has not been tested. Hence this file is not loaded as a part of Photonic for now. * * @package Photonic_Plugin */ class Photonic_Template { public function __construct() { // Future functionality... will be added in the next version. // add_filter('the_posts', array($this, 'check_and_load_template')); } /** * Internally registers pages we want to fake. Array key is the slug under which it is being available from the frontend * @return mixed */ private static function get_fake_pages() { //http://example.com/fakepage1 $fake_pages['photonic-gallery'] = array( 'title' => __('Photonic Gallery', 'photonic'), 'content' => 'This is dummy content in a fake page' ); return $fake_pages; } /** * Fakes get posts result * * @param $posts * * @return array|null */ public function check_and_load_template($posts) { global $wp, $wp_query, $photonic_gallery_page; $fake_pages = self::get_fake_pages(); $gallery_page = strtolower($photonic_gallery_page); if ($gallery_page === strtolower($wp->request) || (isset($wp->query_vars['page_id']) && strtolower($wp->query_vars['page_id']) === $gallery_page)) { $posts = null; $posts[] = self::create_gallery_page($fake_pages[$gallery_page]); $wp_query->is_page = true; $wp_query->is_singular = true; $wp_query->is_home = false; $wp_query->is_archive = false; $wp_query->is_category = false; $wp_query->photonic_template = $wp->request; //Longer permalink structures may not match the fake post slug and cause a 404 error so we catch the error here unset($wp_query->query["error"]); $wp_query->query_vars["error"] = ""; $wp_query->is_404 = false; } return $posts; } /** * Creates virtual fake page * * @param $page * * @return stdClass */ private static function create_gallery_page($page) { global $photonic_alternative_shortcode, $photonic_gallery_page; $gallery_page = strtolower($photonic_gallery_page); $shortcode_tag = $photonic_alternative_shortcode ?: 'gallery'; $post = new stdClass; $post->post_author = 1; $post->post_name = $gallery_page; $post->guid = get_bloginfo('wpurl') . '/' . $gallery_page; if (isset($_REQUEST['photonic_gallery'])) { $shortcode = $_REQUEST['photonic_gallery']; $shortcode = base64_decode($shortcode); // Input is coming via a URL, so we have to ensure it is safe. // The input is expected to be a Photonic shortcode, so the simplest way is to strip out all instances of the Photonic // shortcode and verify that the input is blank. If it is blank, then all that the input had was a Photonic shortcode. $content_without_shortcodes = strip_shortcodes($shortcode); if (!empty(trim($shortcode)) && has_shortcode($shortcode, $shortcode_tag) && empty(trim($content_without_shortcodes))) { // Looks good. Let's proceed. $post->post_title = $page['title']; $post->post_content = $shortcode; } else { // Input looks funny. Stay safe and exit $post->post_title = esc_html__('Nothing found!', 'photonic'); $post->post_content = esc_html__('You are trying to display a gallery, but no gallery was found corresponding to the input.', 'photonic'); } } else { // Input is blank. Show nothing and exit $post->post_title = esc_html__('Nothing found!', 'photonic'); $post->post_content = esc_html__('You are trying to display a gallery, but no input was provided.', 'photonic'); } $post->ID = -1729; // Arbitrary number; picking Ramanujan's number :-) $post->post_status = 'static'; $post->comment_status = 'closed'; $post->ping_status = 'closed'; $post->comment_count = 0; $post->post_date = current_time('mysql'); $post->post_date_gmt = current_time('mysql', 1); return $post; } } new Photonic_Template();