| 1 |
<?php namespace FluentForm\App\Modules; |
| 2 |
|
| 3 |
use FluentForm\App; |
| 4 |
use FluentForm\Config; |
| 5 |
use FluentForm\Request; |
| 6 |
use FluentForm\View; |
| 7 |
|
| 8 |
class ProcessExteriorModule |
| 9 |
{ |
| 10 |
public function handleExteriorPages() |
| 11 |
{ |
| 12 |
if(isset($_GET['fluentform_pages']) && $_GET['fluentform_pages'] == 1) { |
| 13 |
if(isset($_GET['preview_id']) && $_GET['preview_id']) { |
| 14 |
$form_id = intval($_GET['preview_id']); |
| 15 |
$this->loadDefaultPageTemplate(); |
| 16 |
$this->renderFormPreview($form_id); |
| 17 |
} |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
public function renderFormPreview($form_id) |
| 22 |
{ |
| 23 |
if(App\Modules\Acl\Acl::hasAnyFormPermission($form_id)) { |
| 24 |
$form = wpFluent()->table('fluentform_forms') |
| 25 |
->find($form_id); |
| 26 |
if($form) { |
| 27 |
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 100, 1 ); |
| 28 |
add_filter( 'post_thumbnail_html', '__return_empty_string' ); |
| 29 |
add_filter( 'get_the_excerpt', function ($content) { |
| 30 |
return ''; |
| 31 |
} ); |
| 32 |
add_filter('the_title', function ($title) use ($form) { |
| 33 |
if(in_the_loop()) { |
| 34 |
return $form->title; |
| 35 |
} |
| 36 |
return $title; |
| 37 |
}, 100, 1); |
| 38 |
add_filter('the_content', function($content) use ($form) { |
| 39 |
if(in_the_loop()) { |
| 40 |
return View::make( 'public.preview_form', array( |
| 41 |
'form' => $form |
| 42 |
) ); |
| 43 |
} |
| 44 |
return $content; |
| 45 |
}); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
private function loadDefaultPageTemplate() |
| 51 |
{ |
| 52 |
add_filter( 'template_include', function ($original) { |
| 53 |
return locate_template( array( 'page.php', 'single.php', 'index.php' ) ); |
| 54 |
} ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Set the posts to one |
| 59 |
* |
| 60 |
* @param WP_Query $query |
| 61 |
* |
| 62 |
* @return void |
| 63 |
*/ |
| 64 |
public function pre_get_posts( $query ) { |
| 65 |
if ( $query->is_main_query() ) { |
| 66 |
$query->set( 'posts_per_page', 1 ); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
} |