예제 #1
0
  function link($args = array()) {
    // get an <a> tag linking to this attachment.
    
    $defaults = array(
      'text' => $this->title(),
      'root_relative' => false
    );
    
    $r = wp_parse_args( $args, $defaults );

    $root_relative = WOOF::is_true_arg($r, "root_relative");
    $tag = '<a href="'.$this->url($root_relative).'"';

    foreach ($r as $key => $value) {
      if ($key != "text" && $key != "href" && $key != "root_relative") {
        $tag .= ' '.$key.'="'.esc_attr($value).'"';
      }
    }
    
	

    $tag .= '>'.$r['text'].'</a>';

    return $tag;
  }
예제 #2
0
  public function send($nocache = false) {
    
    global $wf;
    
    $data = $this->data;
    $r = $this->args;
    $url = $this->url;
    $cache = $r["cache"];
    $cache_invalid = $r["cache_invalid"];
    
    $d = wp_parse_args($data);
    
    if ($nocache) {
      
      $do_request = true;
      
    } else {
    
      $do_request = WOOF::is_false_arg($r, "cache");
    
      $cache_key = $this->cache_key();
    
    
      if (WOOF::is_true_arg($r, "cache")) {
        // check the cache
        $this->item = $wf->cache($cache_key, null, 0, true);
      
        if (is_null($this->item) || false === $this->item) {
          $do_request = true;
        }

      } else {
        
        $wf->uncache($cache_key);
        
      }
    
    }
    
    if ($do_request) {
      
      unset($r["cache"], $r["cache_invalid"]);
      
      if ($r["method"] == "GET") {
        
        $data_qs = http_build_query($data);
        
        if (preg_match("/\?/", $url)) {
          $url = trim($url, "&") . $data_qs;
        } else {
          $url = $url . "?" . $data_qs;
        }

        $this->item = wp_remote_get( $url );
      
      } else {
        
        if (!isset($r["body"])) {
          $r["body"] = $data;
        }
        
        $this->item = wp_remote_post( $url, $r );
     
      }
     
      if ( is_wp_error( $this->item ) ) {
        
        $this->item = new WOOF_Silent( $this->item->get_error_message() );
        
      } else {
        if ($cache_invalid || ( isset($this->item["response"]["code"]) && $this->item["response"]["code"] == 200)) {
          if ($cache && !$nocache) {
            $wf->cache($cache_key, $this->item, $cache, true);
          }
        }
      
      }
    
             
    }
    
  }
예제 #3
0
  public function debug($args = array()) {
    
    $r = array();
    
    $parse = true;
    
    if (is_string($args)) {
      
      $check = explode("&", $args);
      $check_2 = explode("=", $check[0]);
      
      if (count($check_2) == 1) {
        $parse = false;
        // simple label
        $r["l"] = $check_2[0];
        $r["pre"] = true;
      }
    }
    
    if ($parse) {
      
      $r = wp_parse_args( 
        $args, 
        array(
          "pre" => "1"
        )
      );
    
    } 
  
    if (isset($r["l"])) {
      echo '<h2 class="debug-label">'.$r["l"].'</h2>';
    }
    
    if (WOOF::is_true_arg($r, "pre")) {
      echo "<pre>";
    }
  
    print_r( $this->error );

    if (WOOF::is_true_arg($r, "pre")) {
      echo "</pre>";
    }
    
    return false;
    
  }
예제 #4
0
  function link($args = array()) {

    
    $defaults = array(
      'text' => $this->full_name(),
      'root_relative' => true,
      'current_class' => 'current'
    );
    
    $r = wp_parse_args( $args, $defaults );

    if ($r['current_class'] && $this->is_current()) {
      if (isset($r['class'])) {
        $r['class'] .= (' '.$r['current_class']);
      } else {
        $r['class'] = $r['current_class'];
      }
    }
    
    $root_relative = WOOF::is_true_arg($r, "root_relative");
    $tag = '<a href="'.$this->url($root_relative).'"';


    foreach ($r as $key => $value) {
      if ($key != "text" && $key != "href" && $key != "current_class" && $key != "root_relative") {
        $tag .= ' '.$key.'="'.esc_attr($value).'"';
      }
    }
    
    $tag .= '>'.$r['text'].'</a>';

    return $tag;
  }
예제 #5
0
  public function value($args = array()) {
    global $wf;
    
    // overridden value method, to provide the content with filters applied
    $data = $this->data();
    
    global $wp_filter;
    
    $r = wp_parse_args( $args,
      array(
        "unwrap_shortcodes" => false,
        "wpautop" => false
      )
    );

    $wpautop = WOOF::is_true_arg( $r, "wpautop" );
    
    if (isset($data->val)) {
    
      $content = $this->data()->val;
    
      if ( !$wpautop ) {
        $wf->disable_filter("the_content", "wpautop");
      }
      
      if (WOOF::is_true_arg( $r, "unwrap_shortcodes" ) ) {
        $pattern = "/<p>[\s\n]*(\[[^\]]*\])(?:\[\/[^\]]*\])?[\s\n]*<\/p>/";
        $content = preg_replace( $pattern, "$1", $content);
      }
    
      $ret = apply_filters('the_content', $content );

      if ( !$wpautop ) {
        $wf->enable_filter("the_content", "wpautop");
      }

      return $ret;
      
    }
    
    return "";
  }
예제 #6
0
  function mp_thumb($args = "w=60") {
    
		$html = "";

    // updated to always generate a 2x image, for simplicity
    // also now allows more customisation to handle things like overlays
     
    $r = wp_parse_args( $args, array() );
    
    if (isset($r["w"]) && is_numeric($r["w"])) {
      $width = (int) $r["w"];
    } else {
      $width = 60;
    }

    if (isset($r["h"]) && is_numeric($r["h"])) {
      $height = (int) $r["h"];
    } 
            
    $desired_width = $width;
    
    if (isset($height)) {
      $desired_height = $height;
    }
  
    $container_width = $width;
    $my_width = $this->width();
    $my_height = $this->height();
    
    if (isset($height)) {
      $ratio = $width / $height;
    } else {
      $ratio = $my_width / $my_height;
    }
  
    $is_small = false;
    
    $container_class = "";
    
    if ($my_width < $width) {
      $container_width = $my_width;
      
      if ($my_width < $width) {
        $container_class = " small";
        $is_small = true;
      } 
    
    }
    
    if (isset($r["class"])) {
      $container_class .= " " . $r["class"];
    }
    
    if (isset($height)) {
      $container_height = $height;
    } else {
      $container_height = ceil( $container_width / $ratio );
    }
  
    
    if ($this->is_external()) {
      $link_attr = array( "href" => $this->external_url, "class" => "thumbnail" );
    } else {
      $link_attr = array( "href" => $this->url(), "class" => "thumbnail" );
    }
    
    if (isset($r["link_attr"])) {
      $link_attr = wp_parse_args( $r["link_attr"], $link_attr );
    }
    
    if (isset($r["href"])) {
      $link_attr["href"] = $r["href"];
    }
    
    // check the ratio - if the dimensions are between 1x and 2x the desired width and height, we need to crop the image to the same ratio as the desired width and height
    
    $resize_args = array(
      "up" => 0,
      "w" => $width * 2
    );
    
    $tweaked_height = false;
    
    if (isset($height)) {
      
      if ( ( $height > $width ) && ( $my_height > $height && $my_height < $height * 2 ) ) {
        // adjust the height to match
        $desired_ratio = $width / $height;
        $height = round( $my_width / $desired_ratio );
        $resize_args["w"] = $my_width;
        $tweaked_height = true;
        $container_height = $desired_height;
        $resize_args["h"] = $height;
      } else {
        $resize_args["h"] = $height * 2;
      }
      
    }
        
    
    $image = $this->resize( $resize_args );
    
		if ($image->exists()) {
	
	    if (!$tweaked_height) {
	      if ($my_height > $image->height()) { 
	        // adjust the container height to account for rounding differences
	        $container_height = min($container_height, $image->height() / 2);
	      } else {
	        $container_height = min($container_height, $image->height());
	      }
	    } 
    
	    if (isset($r["watermark"])) {
	      $watermark_args = array("at" => "c");
      
	      if (isset($r["watermark_args"])) {
	        $watermark_args = $r["watermark_args"];
	      }
      
	      $image = $image->watermark($r["watermark"], $watermark_args);
      
	    }
    
	    $style_attr = 'width: '.$container_width.'px; height: '.$container_height.'px;';
    
	    $link_attr["style"] = $style_attr;
    
	    $div_attr = array("class" => "mp-thumb".$container_class );

	    $thumb_only = WOOF::is_true_arg($r, "thumb_only");
    
	    if ($thumb_only) {
	      $div_attr["style"] = $style_attr;
	    }
    
	    $html = WOOF_HTML::open("div", $div_attr);
    
	    if (!$thumb_only) {
	      $html .= WOOF_HTML::open("a", $link_attr );
	    }
  
	    $html .= $image->fluid( array("data-thumb_width" => $container_width, "data-thumb_height" => $container_height ) );
    
	    if (!$thumb_only) {
	      $html .= WOOF_HTML::close("a");
	    }

	    if (isset($r["no_image"])) {
	      $html .= WOOF_HTML::tag("span", "class=no-image", $r["no_image"]);
	    }
    
	    $html .= WOOF_HTML::close("div");
			
		} // image exists
		
    return $html;
  }
예제 #7
0
  function prev($args = array()) {

    $r = wp_parse_args( $args, array(
      "mode" => "sibling",
      "loop" => false
    ));
     
    extract($r);
     
    $loop = WOOF::is_true_arg($r, "loop");

    $flatten_args = $r;
    unset($flatten_args["mode"], $flatten_args["loop"], $flatten_args["parent"]);

    if ($mode == "flat") {
      
      $siblings = $this->type->flatten_terms($flatten_args);

    } else if ($mode == "cousin") {
      
      $flatten_args["at"] = count($this->ancestors()) + 1;
      $siblings = $this->type->flatten_terms($flatten_args);
      
    } else {

      $siblings = $this->siblings( true );

    }

    $index = $siblings->index_of($this->id);
     
    if ($index == 0) {
     
      if ($loop) {
        return $siblings->last();
      }

    } else {
       
      return $siblings[ $index - 1 ];
       
    }
    
    return new WOOF_Silent( __("There is no previous term", "WOOF_DOMAIN") );

  }
예제 #8
0
  function flatten_terms( $args = array() ) {
    
    $r = wp_parse_args( 
      $args,
      array(
        "orderby" => "name",
        "order" => "asc",
        "from" => 0,
        "to" => 0
      )
    );
  
    if (isset($r["at"])) {
      $r["from"] = $r["at"];
      $r["to"] = $r["at"];
    } else if (isset($r["depth"])) {
      $r["to"] = $r["depth"];
    } 
    
    if (WOOF::is_true_arg($r, "nocache") || is_null($ret = $this->property_cache_args("flatten_terms", $args))) {
      
      $all = $this->terms($r);

      if ($this->hierarchical()) {
      
        // we need to flatten the structure
      
        // build the structure

        $struct = array();
      
        // first build a structure for all posts
        foreach ($all as $term) {
          $struct[ $term->id ] = array("term" => $term, "children" => array());
        }
      
        // copy the array to allow modification
        $loop = $struct;
      
        // now fill in the children
        foreach ($loop as $node) {

          $parent = $node["term"]->item->parent;
        
          if ($parent != 0) {
            if (isset($struct[$parent])) {
              $struct[$parent]["children"][] = $node;
            }
          } 
        
        }
      
        // now walk the top nodes

        $flat = array();
        
        foreach ($struct as $node) {
          $parent = $node["term"]->item->parent;
        
          if ($parent == 0) {
            self::walk_struct( $node, $struct, $flat, (int) $r["from"], (int) $r["to"] );
          }
        }
      
        $ret = new WOOF_Collection( $flat );
      
      } else {

        $ret = $all;

      }
     
      $this->property_cache_args("flatten_terms", $args, $ret);
     
    } 
    
    return $ret;
    
  }
예제 #9
0
파일: woof.php 프로젝트: verbazend/AWFA
 public function sites($args = array()) {
   
   $r = wp_parse_args( 
     $args,
     array("nocache" => "0")
   );
   
   if (WOOF::is_true_arg($r, "nocache") || is_null($ret = $this->property_cache_args("sites", $args))) {
     
     if (is_multisite()) {
       $ret = $this->wrap_sites( $this->get_sites($args) );
     } else {
       $ret = $this->wrap_sites( $this->site() );
     }
     
     $this->property_cache_args( "sites", $args, $ret );
   }
   
   return $ret;
   
 }
예제 #10
0
파일: mpv-meta.php 프로젝트: verbazend/AWFA
  public static function set_item_template_data(MEOW_FieldSet &$set, $args = array()) {
    
    $r = wp_parse_args(
      $args,
      array("preview" => false, "readonly" => !$set->is_editable(), "id_base" => "mp_meta_", "name_base" => "mp_meta", "order_base" => "mp_meta_order", "summary_preview_base" => "mp_summary_preview_", "summary_base" => "mp_summary_" )
    );
    
    $d = array();
     
    $set_item_classes = array();
    $set_fields_classes = array();
    $set_summary_classes = array();
    
    $d["allow_remove"] = true;
    
    if ($r["preview"]) {
      $d["preview"] = true;
      $d["allow_remove"] = false;
    } 
    
    if ($r["readonly"]) {
      $d["readonly"] = true;
      $d["allow_remove"] = false;
    }

    
    $info = $set->info();
    
    if ($info->expanded) {
      $d["toggle_class"] = "collapse";
      $set_item_classes[] = "expanded";
      $set_summary_classes[] = "hidden";
    } else {
      $d["toggle_class"] = "expand";
      $set_item_classes[] = "collapsed";
      $set_fields_classes[] = "hidden";
    }
    
    if (isset($args["versions_select"])) {
      $d["versions_select"] = $args["versions_select"];
    }
    
    $d["lang_are_you_sure"] = esc_js(__("Are you sure?", MASTERPRESS_DOMAIN));

    $d["label_collapse"] = __("Collapse", MASTERPRESS_DOMAIN);
    

    $d["set_item_classes"] = implode(" ", $set_item_classes);
    $d["set_fields_classes"] = implode(" ", $set_fields_classes);
    
    $d["description"] = trim( $info->label("description") );

    $d["allow_multiple"] = $info->allow_multiple;

    $d["labels_toggle"] = __("Toggle", MASTERPRESS_DOMAIN);
    
    $d["set_labels_remove_plain"] = strip_tags($info->label("remove"));
    $d["set_labels_remove"] = $info->label("remove");
        
    $d["fields"] = array();

    if ( WOOF::is_true_arg($args, "creator") ) {
      $i = "!!set_index!!";
    } else if ($set->creator) {
      // leave a placeholder for Handlebars to render into
      $i = "{{set_index}}";
    } else { 
      $i = $set->index();
    }
    
    
    
    $d["set_index"] = $i;
    
    $set_id = $r["id_base"]."{$info->name}_$i"; 
    $set_name = $r["name_base"]."[{$info->name}][$i]"; 
    
    if (WOOF::is_true_arg($r, "nested")) {
      $d["order_name"] = $r["order_base"]."[$i]"; 
    } else {
      $d["order_name"] = $r["order_base"]."[{$info->name}][$i]"; 
    }
  
    
    
    $d["fields"] = array();
    
    $fields = $info->fields(); 
    $fi = 0; 
    $fc = 0;
    
    foreach ($fields as $field) {
      if ($type_class = MPFT::type_class($field->type)) {
        $fc++;
      }
    }
    
    foreach ($fields as $field) {

      if ($field->current_user_can_see()) {

        $field_id = "{$set_id}_{$field->name}";
        $field_name = "{$set_name}[{$field->name}]";

        if ($r["preview"]) {
          $field_summary_id = $r["summary_preview_base"]."{$info->name}_{$field->name}";
        } else {
          $field_summary_id = $r["summary_base"]."{$info->name}_{$field->name}";
        }
      
      
        $fd = array(); // the field data

        if ($ftc = MPFT::type_class($field->type)) {
          $fi++; 

          $fd["model_id"] = $field->id;
          $fd["readonly"] = false; // reset
    
          $fd["label_is_header"] = call_user_func_array( array($ftc, "label_is_header"), array($field->type_options));
          $fd["type"] = $field->type;
          $fd["type_widget"] = "mpft_".str_replace("-", "_", $field->type);
          $fd["label"] = $field->display_label();
          $fd["esc_label"] = esc_attr($field->display_label());
          $fd["label_suffix"] = call_user_func( array($ftc, "label_suffix") );
        
          $fd["field_path"] = $info->name."-".$field->name;

          $fd["prop_list"] = implode(",", MPFT::type_properties($field->type));
        
          $fd["description"] = trim( $field->label("description") );

          $fd["pos_class"] = WOOF_HTML::pos_class_1($fi, $fc, " mp-field-");

          if ($field->current_user_can_manage()) {
            $mu = $field->manage_url($info);
            
            $mu .= "&mp_redirect=".urlencode($_SERVER["REQUEST_URI"]);
            
            if ($mu) {
              $fd["go"] = '<a href="'.$mu.'" class="mp-go with-mptt" data-tooltip="'.__("Edit Field Definition", MASTERPRESS_DOMAIN).'">'.__("Edit Field Definition").'</a>';
            }


          }
          
          $field_classes = array("mpft-".$field->type);
        
          if ($fi == $fc) {
            $field_classes[] = "mp-field-last";
          }
        
          $field_summary_classes = array();
        
          if ($field->required) {
            $field_classes[] = "required";
            $field_summary_classes[] = "required";
          }
        
          if (isset($field->summary_options["emphasise"])) {
            $field_summary_classes[] = "em";
          }
        
          $fd["name"] = $field->name;
          $fd["template_id"] = "{$info->name}_{$field->name}";
          $fd["summary_id"] = $field_summary_id."_".$i;
          $fd["field_id"] = $field_id;


        
          $fd["id_first"] = $field_id;
        
          $opts = call_user_func( array($ftc, "ui_options") );
        
          $ui = array();
        
          if (count($opts) ) {
            $ui = call_user_func_array( array($ftc, "extract_options"), array($field->type_options, $opts) );
            $ui = call_user_func_array( array($ftc, "normalize_options"), array($ui) );
          }
        
        
        
          $ui_parts = array();
        
          if (count($ui)) {
            foreach( $ui as $key => $value ) {
              $ui_parts[] = "'$key':'".esc_attr(esc_js($value))."'"; 
            } 
          }
        
          // $fd["lang"] = "{".implode(",", $lang_parts)."}";

          $fd["ui"] = "{".implode(",", $ui_parts)."}";
        
          if (isset($field->labels["tooltip_help"])) {
            $tooltip_help = trim($field->label("tooltip_help"));

            if ($tooltip_help != "") {
              $fd["label_tooltip"] = "#mptt_".$info->id."_".$field->id;
            }
          }

          if (!$field->current_user_can_edit($set->is_editable()) && !$r["preview"]) {
            $fd["readonly"] = true;
          }
        
          $strip_whitespace = !call_user_func( array($ftc, "ui_preserve_whitespace") );
        
          $ftd_args = $r;
          
          if ($set->creator) {
            
            $meow_field = new MEOW_FieldCreator($field->name, null, $field);
          
            call_user_func_array( array($ftc, "apply_default"), array($meow_field, $set, $ftc) );
            $field_ui_data = self::field_ui_template_data($set, $meow_field, $ftd_args);
            $field_ui = WOOF::render_template( self::field_ui_template(), $field_ui_data, $strip_whitespace );
          
          } else {

            // here we regard the actual field value, and build the UI from that
            $meow_field = $set->field($field->name); 

            $action = "";
          
            if (isset($_GET["action"])) {
              $action = $_GET["action"];
            }

            if (!$info->allow_multiple && $action != "edit") {
              call_user_func_array( array($ftc, "apply_default"), array($meow_field, $set, $ftc) );
            }

            $field_ui_data = self::field_ui_template_data($set, $meow_field, $ftd_args);
            $field_ui = WOOF::render_template( self::field_ui_template(), $field_ui_data, $strip_whitespace );
        
          }

          
          if ($fi == $fc) {
            if ($meow_field->blank()) {
              $set_summary_classes[] = "last-empty";
            }
        
          }
          
          $fd["field_ui"] = $field_ui;
        
        
          // now build out the summary info
        
        
          $fd["summary_width"] = call_user_func( array($ftc, "summary_width") );
        
          if (isset($field->summary_options["width"])) {
            $sw = (int) $field->summary_options["width"];
          
            if ($sw >= 1 && $sw <= 5) {
              $fd["summary_width"] = $sw;
            }
          
          }
        
        
          $max_length = ( $fd["summary_width"] * 138 ) / 10;
        
          $fd["label_truncated"] = WOOF::truncate_basic( $fd["label"], $max_length, "<span>&hellip;</span>" );
      
          if ($fd["label"] != $fd["label_truncated"]) {
            $fd["label_title"] = strip_tags($fd["label"]);
          }
        
          $label_classes = array();
        
          if (method_exists($ftc, "summary_label_classes")) {
            $label_classes = call_user_func_array( array($ftc, "summary_label_classes"), array($meow_field) );
          } 
          
          $fd["label_classes"] = implode(" ", $label_classes);
        
          $empty = $meow_field->blank();


          $fd["empty_summary"] = call_user_func_array( array($ftc, "empty_summary"), array($meow_field) );
          $fd["summary"] = call_user_func_array( array($ftc, "summary"), array($meow_field) );

          if ($empty) {
            $field_summary_classes[] = "empty";
          } else {
            $fd["is_edit"] = "is-edit";
          }
        
          $fd["classes"] = implode(" ", $field_classes);
          $fd["summary_classes"] = implode(" ", $field_summary_classes);
        
          // add the field data to the main data array
          $d["fields"][] = $fd;  
      
      
        } // endif class_exists($ftc)
    
      } // current user can see
    
    } // endforeach
      
    
    $d["set_summary_classes"] = implode(" ", $set_summary_classes);


    return $d;
    
  }
예제 #11
0
  public function debug($args = array()) {
    
    global $wf;
    
    $r = array();
    
    $parse = true;
    
    if (is_string($args)) {
      
      $check = explode("&", $args);
      $check_2 = explode("=", $check[0]);
      
      if (count($check_2) == 1) {
        $parse = false;
        // simple label
        $r["l"] = $check_2[0];
        $r["pre"] = true;
      }
    }
    
    if ($parse) {
      
      $r = wp_parse_args( 
        $args, 
        array(
          "pre" => "1"
        )
      );
    
    } 
  
    if (isset($r["l"])) {
      echo '<h2 class="debug-label">'.$r["l"].'</h2>';
    }
    
    if (WOOF::is_true_arg($r, "pre")) {
      echo "<pre>";
    }
  
    $data = $this->debug_data();
    
    $class = get_class( $this );
    
		$my_class = $class;
		
    $parents = array();
    
    if (is_object($data)) {
      $data = (array) $data;
    } else if (!is_array($data)) {
      $data = array("value" => $data);
    }
  
    while ($class = get_parent_class($class)) {
      $parents[] = WOOF_HTML::tag("a", "target=_blank&href=" . $wf->woof_docs_base . WOOF_Inflector::dasherize($class), $class);
    }
       
    $data = array(
			"EXTENDS" => implode(", ", $parents),
			"site_id" => $this->_site_id
		) + $data;
    
		// TODO - add support for displaying collection items in this new format
		
		$out = preg_replace("/^Array/", WOOF_HTML::tag("a", "target=_blank&href=" . $wf->woof_docs_base . WOOF_Inflector::dasherize($my_class) , $my_class), print_r($data, true));
		
		echo $out;
    
    if (WOOF::is_true_arg($r, "pre")) {
      echo "</pre>";
    }
    
    return false;
    
  }
예제 #12
0
  public static function attr($attr = array(), $options = array()) {
    
      $a = wp_parse_args(
        $attr,
        array(
          "validate" => true,
          "empty" => false
        )
      );
    
      $o = wp_parse_args($options);
      
      
      $validate_attr = WOOF::is_true_arg($o, "validate");
      $empty_attr = WOOF::is_true_arg($o, "empty");
      
      unset($a["validate"]);
      unset($a["empty"]);
      
      $tag = null;
      
      if (isset($o["tag"])) {
        $tag = $o["tag"];
      }
    
      
      
      $html = '';
    
      foreach ($a as $key => $value) {
      
        $use = true;
      
        if ($validate_attr && !is_null($tag)) {
          $use = self::is_valid_attr($tag, $key);
        }
      
        if ($use) {
      
          $val = $value;
    
          if (is_array($value)) {
            $val = implode(" ", $val);
          }

          if ($key == "itemscope") {
            $html .= ' ' . $key;
          } else {
          
            if (!(trim($val) == "" && !$empty_attr)) {
              $html .= ' '.$key.'="'.esc_attr($val).'"';
            }
      
          }
        
        }
      
      }
    
      return $html;
     
  }
예제 #13
0
  public function posts($args = array(), $noget = array("tax_query")) {
    
    global $wf;
    
    $aa = wp_parse_args($args);
    
    $r = $this->parse_args( 
      $args, 
      array(
        "orderby" => "title",
        "order" => "asc",
        "limit" => $this->post_limit,
        "offset" => 0,
        "type" => "post"
      ),
      "#offset,#limit,#posts_per_page,order_by,orderby,order,type,@before,@after,status,post_status,#author,search,s,tag,category,tax_query,ep",
      array(
        "limit"   => "posts_per_page",
        "order_by" => "orderby",
        "type"    => "post_type",
        "status" => "post_status",
        "search" => "s"
      ),
      $noget
    );

    $ng = $this->to_array($noget);
    
    $type = $r["post_type"];
    
    // set more appropriate ordering defaults if no order was explicitly specified
    if (!isset($args["orderby"]) && !isset($args["order_by"]) && !isset($args["order"])) {
    
      if ($type == "post") {
        $r["orderby"] = "post_date";
        $r["order"] = "desc";
      } else if ($type == "page") {
        $r["orderby"] = "menu_order";
        $r["order"] = "asc";
      }
      
      // ... but also allow developers to override
      
      $r["orderby"] = apply_filters("mp_rest_archive_order_by", $r["orderby"], $type);
      $r["order"] = apply_filters("mp_rest_archive_order", $r["order"], $type);
      
    }
    
    $limit = $this->post_limit;
    
    if (isset($this->post_limits[$type])) {   
      $limit = $this->post_limits[$type];
    }
    
    $post_type = $wf->types($type);
    
    if ($r["posts_per_page"] != -1) {
      $use_limit = max(1, min($limit, $r["posts_per_page"]));
    } else {
      $use_limit = max(1, $limit);
    }
    
    $use_offset = $r["offset"];

    $r["posts_per_page"] = $use_limit;
    
    $page = floor( $use_offset / $use_limit ) + 1;
    
    if (isset($r["ep"])) {
      $ep = $r["ep"];
    } else {
      $ep = $this->endpoint_url( $post_type->rewrite_slug(true) );
    }
  
    unset($r["ep"]);
    
    $pr = $r;
    
    unset($pr["fields"]);
    
    $query = new WP_Query( $pr );

    
    $posts = $wf->wrap( $query->posts );
    
    $found = (int) $query->found_posts;
      
    $mod = floor( $found % $use_limit );

    $final_offset = ( $found ) - $mod;
    
    if ($mod == 0) {
      $final_offset = $final_offset - $use_limit;
    }
    
    $r = $this->remap_args($r, "posts_per_page=limit&post_type=type&post_status=status&s=search");
    
    
    // remove any keys that cannot be overridden with a $_GET
    
    // this is a sub data key
    $sub = WOOF::is_true_arg($aa, "sub");
   

    WOOF::array_remove_keys($r, $ng);
    
    $pages = ceil( $found / $use_limit );
    
    $data = array();
    
    if (!$sub) {
      $data["href"] = $wf->current_url();
    }
    
    $data["found"] = $found;
    $data["limit"] = $use_limit;
    $data["offset"] = $use_offset;
    $data["page"] = $page;
    $data["pages"] = $pages;
    $data["first"] = array( "href" => $ep . "?" . $this->build_query($r, "limit=$use_limit", "offset" ) );
    $data["previous"] = null;
    $data["next"] = null;
    $data["last"] = array( "href" => $ep . "?" . $this->build_query($r, "limit=$use_limit&offset=$final_offset" ) );
    
    if ($page != 1) {
      $data["previous"] = array( "href" => $ep . "?" . $this->build_query($r, "limit=$use_limit&offset=" . ( ( $page - 2 ) * $use_limit ) ) );
    }
    
    if ($found > ($use_offset + $use_limit)) {
      $data["next"] = array( "href" => $ep. "?" . $this->build_query($r, "limit=$use_limit&offset=" . ($page * $use_limit ) ) );
    }
  
    
    $fields = apply_filters( "mp_rest_archive_fields", "", $type );
    
    if ($expand = $wf->has_get("expand")) {
      $expand_fields = $wf->parse_field_list($expand);
      
      if (isset($expand_fields["posts"])) {
        
        $def = MEOW_Post::json_fields();
        
        if (is_array($expand_fields["posts"])) {
          $def = $expand_fields["posts"];
        }
        
        $fields = apply_filters( "mp_rest_single_fields", $def, $type );
      }
      
    }
    
    
    if ($wf->has_get("fields")) {
      $fields = $wf->filter_field_list( apply_filters( "mp_rest_archive_fields_allowed", $fields, $type ) );
    }
  
    // need to allow query params here, and default limits etc

    $data["posts"] = array();

    foreach ( $posts as $post ) {
      $data["posts"][] = apply_filters("mp_rest_archive_json", $post->json($fields), $post );
    }
      
    $json = apply_filters("mp_rest_archive_json", $data, $type );

    return $data;

  }
예제 #14
0
  public function value($args = array()) {

    global $wf;

    $mode = $this->mode();
    
    $r = wp_parse_args(
      $args,
      array(
        "smart_shortcodes" => true,
        "markdown_filtered" => true,
        "filtered" => false
      )
    );
  
    $html = $this->data->val;
    
    if ( in_array($mode, array("markdown", "gfm")) ) {
      $html = $wf->markdown( $html );
      
      if ( WOOF::is_true_arg( $r, "smart_shortcodes" ) ) {
        $html = preg_replace( "/\{(\/?[^\}]*\/?)\}/", "[$1]", $html );
      }

      if (WOOF::is_true_arg( $r, "markdown_filtered" ) ) {
        $html = apply_filters( "the_content", $html );
      }

    } 

    if (WOOF::is_true_arg( $r, "filtered" ) ) {
      $html = apply_filters( "the_content", $html );
    }
      
    return $html;
    
  }