Example #1
0
/**
 * Get property value from the database.
 *
 * @param  int    $term_id
 * @param  string $slug
 * @param  mixed  $default
 *
 * @return mixed
 */
function papi_get_term_field($term_id = null, $slug = null, $default = null)
{
    if (!is_numeric($term_id) && is_string($term_id)) {
        $default = $slug;
        $slug = $term_id;
        $term_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return $default;
    }
    return papi_get_field(papi_get_term_id($term_id), $slug, $default, 'term');
}
Example #2
0
 static function render_modules($property_slug)
 {
     $relations = papi_get_field($property_slug);
     if ($relations) {
         foreach ($relations as $key => $relation) {
             $blade_template = rtrim(papi_get_page_type_template($relation->ID), '.php');
             $view = view($blade_template, ['module' => papi_get_page($relation->ID)]);
             $pathToCompiled = $view->path;
             include $pathToCompiled;
         }
     }
 }
 /**
  * Update value.
  *
  * @param  Papi_Core_Property $property
  * @param  mixed  $value
  * @param  string $slug
  * @param  int    $post_id
  *
  * @return array
  */
 protected function update_value($property, $value, $slug, $post_id)
 {
     if (!is_array($value) || !$this->should_update_array($slug)) {
         return $property->import_value($value, $slug, $post_id);
     }
     $old = papi_get_field($post_id, $slug, []);
     $value = array_merge($old, $value);
     $value = $property->import_value($value, $slug, $post_id);
     if ($property->import_setting('property_array_slugs')) {
         return papi_from_property_array_slugs($value, $slug);
     }
     return $property->update_value($value, $slug, $post_id);
 }
Example #4
0
 /**
  * Get value.
  *
  * @return mixed
  */
 public function get_value()
 {
     $value = $this->get_option('value');
     if (papi_is_empty($value)) {
         $type = papi_get_meta_type();
         $slug = $this->get_slug(true);
         $value = papi_get_field($slug, null, $type);
         $post_status = get_post_status($this->get_post_id());
         if (papi_is_empty($value) && ($post_status === false || $post_status === 'auto-draft')) {
             $value = $this->get_option('default');
         }
     }
     if (papi_is_empty($value)) {
         return $this->default_value;
     }
     if ($this->convert_type === 'string') {
         $value = papi_convert_to_string($value);
     }
     return papi_santize_data($value);
 }
Example #5
0
 * Try to get start page sidebar modules
 */
if (!sizeof($sidebar_modules)) {
    if ($frontpage_id = get_option('page_on_front')) {
        if ($frontpage_modules = papi_get_field($frontpage_id, 'sidebar')) {
            $sidebar_modules = $frontpage_modules;
        }
    }
}
?>

@if(sizeof($sidebar_modules))
	@foreach($sidebar_modules as $module)
        @if(Groups_Post_Access::user_can_read_post($module->ID))
            <?php 
if (papi_get_field($module->ID, 'anonymous_only') && is_user_logged_in()) {
    continue;
}
?>
    		<div class="row">
    			<?php 
$post = get_post($module->ID);
setup_postdata($GLOBALS['post'] =& $post);
bladerunner(rtrim(papi_get_page_type_template($module->ID), '.php'));
?>
                <p>&nbsp;</p>
    	    </div>
        @endif
	@endforeach
	<?php 
wp_reset_postdata();
Example #6
0
 /**
  * Export data from Papi. With or without all property options.
  *
  * @param  mixed $post_id
  * @param  bool  $only_values
  *
  * @return array
  */
 public function export($post_id, $only_values = false)
 {
     $post_id = papi_get_post_id($post_id);
     if (empty($post_id)) {
         return [];
     }
     $slugs = papi_get_slugs($post_id);
     foreach ($slugs as $key => $box) {
         foreach ($box as $index => $slug) {
             unset($slugs[$key][$index]);
             $value = papi_get_field($post_id, $slug, null);
             if ($only_values === true) {
                 $slugs[$key][$slug] = $value;
             } else {
                 $store = papi_get_meta_store($post_id);
                 // @codeCoverageIgnoreStart
                 if (is_null($store)) {
                     continue;
                 }
                 // @codeCoverageIgnoreEnd
                 $property = $store->get_property($slug);
                 // @codeCoverageIgnoreStart
                 if (!papi_is_property($property)) {
                     continue;
                 }
                 // @codeCoverageIgnoreEnd
                 $options = clone $property->get_options();
                 $options->value = $value;
                 $slugs[$key][$slug] = $options;
             }
         }
     }
     return $slugs;
 }
Example #7
0
          <div class="startpageheaderend">{!! $module->thirdliner !!}</div>
          <p class="startpageherop">{{ $module->sellpoint }}</p>
          <div class="w-row startpageherorow">
            <div class="w-col w-col-6 w-col-small-6 w-clearfix">
              <?php 
$link = papi_get_field($module->id, 'link1');
?>
              @if( $link )
                <a href="{{ $link->url }}" class="w-inline-block startpageherobtn1">
                  <div class="startpageherobtn1text">{{ $link->title }}</div>
                </a>
              @endif
            </div>
            <div class="w-col w-col-6 w-col-small-6">
              <?php 
$link = papi_get_field($module->id, 'link2');
?>
              @if( $link )
                <a href="{{ $link->url }}" class="w-inline-block startpageherobtn2">
                  <div class="startpageherobtn1text startpageherobtn2text">{{ $link->title }}</div>
                </a>
              @endif
            </div>
          </div>
        </div>
        <div data-ix="scrollfingerback" class="startpageherofingerdiv"></div>
      </div>
    </div>
  </div>
  @include('views.parts.pointers.blue_right')
Example #8
0
<?php

$image_field = papi_get_field('image');
$image = null;
$image = isset($image_field->sizes['small']) ? $image_field->sizes['small']['url'] : $image;
$image = isset($image_field->sizes['medium']) ? $image_field->sizes['medium']['url'] : $image;
$image = isset($image_field->sizes['large']) ? $image_field->sizes['large']['url'] : $image;
?>

  <div class="card">
<a href="<?php 
the_permalink();
?>
">
    <div class="card-image">
      <img src="<?php 
echo $image;
?>
" alt="<?php 
echo get_the_title();
?>
">
    </div>
    <div class="card-header">
      <?php 
echo get_the_title();
?>
    </div>
    <div class="card-copy">
      <p>
      <?php 
Example #9
0
<?php

get_header();
while (have_posts()) {
    the_post();
    ?>

<div class="entry">
	<?php 
    the_title('<h1 class="entry-title">', '</h1>');
    ?>

	<?php 
    $hero = papi_get_field('hero_image');
    if ($hero) {
        ?>
			<div class="entry-hero">
				<img src="<?php 
        echo $hero->url;
        ?>
" />
			</div>
			<?php 
    }
    ?>

	<div class="entry-text">
		<?php 
    the_papi_field('editor');
    ?>
	</div>
 /**
  * Restore to post revision.
  *
  * @param int $post_id
  * @param int $revision_id
  */
 public function restore_post_revision($post_id, $revision_id)
 {
     $slugs = papi_get_slugs($revision_id, true);
     foreach ($slugs as $slug) {
         $value = papi_get_field($revision_id, $slug);
         if (papi_is_empty($value)) {
             papi_delete_field($post_id, $slug);
         } else {
             papi_update_field($post_id, $slug, $value);
         }
     }
 }
    /**
     * Render property html.
     */
    public function html()
    {
        $post_id = papi_get_post_id();
        $settings = $this->get_settings();
        // Create query array for every page type.
        $page_types = array_map(function ($page_type) {
            return ['key' => papi_get_page_type_key(), 'value' => $page_type, 'compare' => 'LIKE'];
        }, papi_to_array($settings->page_type));
        // Add relation.
        $page_types['relation'] = 'OR';
        // Prepare arguments for WP_Query.
        $args = ['post_type' => 'any', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'meta_query' => $page_types];
        $query = new WP_Query($args);
        $posts = $query->get_posts();
        $values = [];
        foreach (papi_to_array($settings->slug) as $slug) {
            foreach ($posts as $post) {
                $val = papi_get_field($post->ID, $slug);
                $val = array_filter(papi_to_array($val), function ($item) use($post_id) {
                    return is_object($item) && $item->ID === $post_id;
                });
                if (empty($val)) {
                    continue;
                }
                $page_type = papi_get_entry_type_by_meta_id($post->ID);
                if (empty($page_type)) {
                    continue;
                }
                // Create the array
                if (!isset($values[$post->post_type])) {
                    $values[$post->post_type] = [];
                }
                if (!isset($values[$post->post_type][$page_type->name])) {
                    $values[$post->post_type][$page_type->name] = [];
                }
                // Add the post
                if (!isset($values[$post->post_type][$page_type->name][$post->ID]) && !empty($val)) {
                    $values[$post->post_type][$page_type->name][$post->ID] = $post;
                }
            }
        }
        ?>
		<ul class="papi-property-reference" data-papi-rule="<?php 
        echo esc_attr($this->html_name());
        ?>
">
			<?php 
        if (empty($values)) {
            ?>
				<p>
					<?php 
            esc_html_e('No references exists', 'papi');
            ?>
				</p>
			<?php 
        }
        ksort($values);
        foreach ($values as $title => $val) {
            $post_type = get_post_type_object($title);
            ?>
				<li>
					<h3><?php 
            echo esc_html($post_type->labels->name);
            ?>
</h3>
					<div class="handlediv" title="Click to toggle"><br></div>
				</li>
				<li>
					<div class="page-types">
						<ul>
							<?php 
            ksort($val);
            foreach ($val as $name => $posts) {
                ?>
								<li class="heading-border">
									<h4><?php 
                echo esc_html($name);
                ?>
</h4>
									<div class="handlediv" title="Click to toggle"><br></div>
								</li>
								<li>
									<div class="box">
										<?php 
                $i = 0;
                foreach ($posts as $post) {
                    ?>
											<a href="<?php 
                    echo esc_attr(get_edit_post_link($post->ID));
                    ?>
"><?php 
                    echo esc_html($post->post_title);
                    ?>
</a>
										<?php 
                    $i++;
                }
                ?>
										<div class="clear"></div>
									</div>
								</li>
							<?php 
            }
            ?>
						</ul>
						<div class="clear"></div>
					</div>
				</li>
			<?php 
        }
        ?>
		</ul>
		<?php 
    }
Example #12
0
/**
 * Get property value for property on a option page.
 *
 * @param  string $slug
 * @param  mixed  $default
 *
 * @return mixed
 */
function papi_get_option($slug, $default = null)
{
    return papi_get_field(0, $slug, $default, Papi_Option_Page::TYPE);
}
<div class="wrap">
	<div id="primary" class="content-home">
		<main id="main" class="site-main" role="main">

			<?php 
while (have_posts()) {
    the_post();
    ?>

				<?php 
    get_template_part('template-parts/content', 'home');
    ?>

                <?php 
    $products = papi_get_field('products');
    if ($products) {
        ?>
					<div class="cards">
                	<?php 
        foreach ($products as $key => $product) {
            $post = get_post($product->ID);
            setup_postdata($post);
            get_template_part('templates/parts/product-card');
        }
        ?>
					</div>
                	<?php 
    }
    wp_reset_postdata();
    ?>
Example #14
0
/**
 * Get property value for property on a option page.
 *
 * @param  string $slug
 * @param  mixed  $default
 *
 * @return mixed
 */
function papi_get_option($slug, $default = null)
{
    return papi_get_field(0, $slug, $default, 'option');
}
Example #15
0
/**
 * Get property value for property on a option page.
 *
 * @param  string $slug
 * @param  mixed  $default
 *
 * @return mixed
 */
function papi_get_option($slug, $default = null)
{
    return papi_get_field(0, $slug, $default, Papi_Core_Page::TYPE_OPTION);
}
Example #16
0
            <div class="blogpuffright">
              <div class="w-clearfix blogpuffheaderdiv">
                <div class="blogpuffheaderleft">

                  @if( papi_get_page_type_id() == 'blog-post' )
                        <div class="blogpuffdate">{{ __('BLOGGPOST','AEKAB' ) }}</div>
                  @elseif( papi_get_page_type_id() == 'portfolio-post' )
                        <div class="blogpuffdate">{{ __('UPPDRAG','AEKAB' ) }}</div>
                  @else
                        <div class="blogpuffdate">{{ __('NYHET','AEKAB' ) }}</div>
                  @endif

                </div>
                <div class="blogpuffheaderright">
                  <?php 
$main_cat = papi_get_field('main_category');
?>
                  @if( $main_cat && property_exists( $main_cat, 'name' ) )
                    <div class="blogpuffheadertxt">{{ $main_cat->name }}</div>
                  @endif
                </div>
              </div>
              <a href="{{ get_the_permalink() }}" class="w-inline-block blogpuffclickarea"><h3 class="blogpuffheadline">{{the_title()}}</h3>
                <p class="blogpuffbody">
                  {!! get_post_excerpt() !!}                
                </p>
              </a>
            </div>
          </div> 

Example #17
0
            @endforeach
          @endif

          <?php 
wp_reset_postdata();
?>
            

        </div>
      </div>
    </div>
  </div>
  <div class="w-section sectionpuffsmorenews">
    <div class="w-container">
      <?php 
$more = papi_get_field($module->id, 'more');
?>
      @if( $more )
      <a href="{{ $more->url }}" class="w-inline-block startpagelinkblockmorenews">
        <div>{{ $more->title }}</div>
      </a>
      @endif
    </div>
  </div>
  @include('views.parts.swisch')

@include('views.parts.admin-edit')


Example #18
0
<?php

$type = 1;
$payoff = 'Ledord för oss är respons, nyfikenhet, affärsförståelse och kvalitetsinsatser.';
if (isset($module)) {
    $type = $module->type;
    $payoff = $module->words;
} else {
    $post_payoff = papi_get_field('payoff');
    if ($post_payoff) {
        $payoff = $post_payoff;
    }
    $type = 2;
}
?>


@if( $type == 2 )
	<div class="w-section sectiongreypayoff">
		<div class="w-container">
			<h2 class="startpagepayoff1 payoff2">{{ $payoff }}</h2>
		</div>
	</div>
	@include('views.parts.pointers.gray_right')
@else
	<div class="w-section startpagesectionpayoff1">
		<div class="w-container">
			<h1 class="startpagepayoff1">{{ $payoff }}</h1>
		</div>
	</div>
@endif
$matches = papi_get_field($module->id, 'matches');
if ($matches) {
    foreach ($matches as $match) {
        if (!$cat_list == '') {
            $cat_list .= ',';
        }
        $cat_list .= $match['term']->term_id;
    }
}
?>
<div class="row">

	<div class="col-md-12">

		<?php 
$length = (int) papi_get_field($module->id, 'excerpt_length');
$args = ['post_type' => 'post'];
if ($cat_list != '') {
    $args['cat'] = $cat_list;
}
$the_query = new WP_Query($args);
?>
		@if( $the_query->have_posts() )
			@if( $title=papi_get_field( $module->id, 'title' ) )
				<h2>{{ $title }}</h2>
			@endif
			@while ( $the_query->have_posts() )
				{{ $the_query->the_post() }}
					<h3>{{ the_title() }}</h3>
					{!! get_post_excerpt( get_the_ID(), $length, false) !!}
					<br/>
 /**
  * Get property value.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 private function get_value(Papi_Core_Conditional_Rule $rule)
 {
     if (papi_doing_ajax()) {
         $source = $rule->get_source();
         $meta_id = papi_get_meta_id();
         $entry_type = papi_get_entry_type_by_meta_id($meta_id);
         if (!papi_is_empty($source) && $entry_type instanceof Papi_Entry_Type !== false) {
             if (papi_is_property($entry_type->get_property($rule->slug))) {
                 return $this->get_deep_value($rule->slug, $source);
             }
         }
     }
     if (!papi_is_empty($rule->get_source())) {
         return $this->get_deep_value($rule->slug, $rule->get_source());
     }
     $slug = $rule->get_field_slug();
     $type = papi_get_meta_type();
     $value = papi_get_field($slug, null, $type);
     return $this->get_deep_value($slug, $value);
 }
Example #21
0
<?php

$link = papi_get_field($module->ID, 'link');
?>

<div class="panel panel-default">
	<div class="panel-heading">
		<h3 class="panel-title">{{ get_the_title( $module->ID ) }}</h3>
	</div>
	<div class="panel-body">
		@if( has_post_thumbnail( $module->ID ) )
			<div class="thumbnail">
			    <?php 
$feat_image_url = wp_get_attachment_url(get_post_thumbnail_id($module->ID));
?>
				<img src="{{ $feat_image_url }}" class="img-responsive" />
			</div>
		@endif
		<p>{!! papi_get_field( $module->ID, 'text' ) !!}</p>
		@if( $link )
			<div class="caption text-center">
					<p>
						<a href="{{ $link->url }}" class="btn btn-warning">{{ $link->title }}</a>
					</p>
			</div>
		@endif
	</div>
</div>


Example #22
0
/**
 * Get value for a property on a page.
 *
 * You should use papi_get_field() instead.
 *
 * @param int    $post_id
 * @param string $slug
 * @param mixed  $default
 * @param string $type
 *
 * @deprecated deprecated since version 2.0.0.
 *
 * @return mixed
 */
function papi_field($post_id = null, $slug = null, $default = null, $type = 'post')
{
    _deprecated_function(__FUNCTION__, '2.0.0', 'papi_get_field');
    return papi_get_field($post_id, $slug, $default, $type);
}
Example #23
0
/**
 * Echo the value for property.
 *
 * @param int    $id
 * @param string $slug
 * @param mixed  $default
 */
function the_papi_field($id = null, $slug = null, $default = null)
{
    $value = papi_get_field($id, $slug, $default);
    if (is_array($value)) {
        $value = implode(', ', $value);
    }
    if (is_object($value)) {
        $value = papi_convert_to_string($value);
    }
    echo esc_html($value);
}
 /**
  * Get value.
  *
  * @return mixed
  */
 public function get_value()
 {
     $value = $this->get_option('value');
     if (papi_is_empty($value)) {
         $slug = $this->get_slug(true);
         if ($this->is_option_page()) {
             $value = papi_get_option($slug);
         } else {
             $value = papi_get_field($this->get_post_id(), $slug);
         }
         $post_status = get_post_status($this->get_post_id());
         if (papi_is_empty($value) && ($post_status === false || $post_status === 'auto-draft')) {
             $value = $this->get_option('default');
         }
     }
     return $this->prepare_value($value);
 }
Example #25
0
@extends('views.layouts.master')

@section('main')

	<?php 
$modules = papi_get_field(get_the_ID(), 'page_modules');
?>
	
	@if( $modules )
		@foreach( $modules as $module )
			@include( rtrim( papi_get_page_type_template($module->ID), '.php' ), [ 'module' => papi_get_page($module->ID) ] )
		@endforeach
	@endif

@endsection
Example #26
0
/**
 * Echo the value for property on a page.
 *
 * @param int    $post_id
 * @param string $slug
 * @param mixed  $default
 */
function the_papi_field($post_id = null, $slug = null, $default = null)
{
    $value = papi_get_field($post_id, $slug, $default);
    if (is_array($value)) {
        $value = implode(', ', $value);
    }
    echo $value;
}
 /**
  * Get property value.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 private function get_value(Papi_Core_Conditional_Rule $rule)
 {
     if (papi_doing_ajax()) {
         $source = $rule->get_source();
         $post_id = papi_get_post_id();
         $page_type = papi_get_page_type_by_post_id($post_id);
         if (!papi_is_empty($source) && $page_type instanceof Papi_Page_Type !== false) {
             if (papi_is_property($page_type->get_property($rule->slug))) {
                 return $this->get_deep_value($rule->slug, $source);
             }
         }
     }
     if (!papi_is_empty($rule->get_source())) {
         return $this->get_deep_value($rule->slug, $rule->get_source());
     }
     $slug = $rule->get_field_slug();
     if (papi_is_option_page()) {
         $value = papi_get_option($slug);
     } else {
         $value = papi_get_field($slug);
     }
     return $this->get_deep_value($slug, $value);
 }