public function incoming_users($args = array()) { global $meow_provider, $wf; $user_ids = $meow_provider->incoming($this, WOOF::array_arg($args, "for"), "user"); $this->incoming = array(); if (count($user_ids)) { // if there are no matching user ids, don't query, return an empty array $defaults = array( ); $r = wp_parse_args( $args, $defaults ); $r = array_merge( $r , array("include" => $user_ids)); return $wf->users( $r ); } else { return new WOOF_Collection( array() ); } }
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; }
function woof_draw_select_childs($tax_slug, $childs, $level, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos) { $current_request = array(); if (isset($_REQUEST[$tax_slug])) { $current_request = $_REQUEST[$tax_slug]; $current_request = explode(',', $current_request); } ?> <?php foreach ($childs as $term) { ?> <?php $count_string = ""; if ($show_count) { if ($show_count_dynamic) { $count = WOOF::dynamic_count($term, 'select'); } else { $count = $term['count']; } $count_string = '<span class="count">(' . $count . ')</span>'; } //+++ if ($hide_dynamic_empty_pos and $count == 0) { continue; } ?> <option value="<?php echo $term['slug']; ?> " <?php echo selected(in_array($term['slug'], $current_request)); ?> ><?php echo str_repeat(' ', $level); echo $term['name']; ?> <?php echo $count_string; ?> </option> <?php if (!empty($term['childs'])) { woof_draw_select_childs($tax_slug, $term['childs'], $level + 1, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos); } ?> <?php } ?> <?php }
protected function build_package($rep, $filename, $readme = "") { $export_filename = MASTERPRESS_TMP_DIR.$filename; $destination_filename = MASTERPRESS_CONTENT_MASTERPLANS_DIR.$filename; $info["filename"] = $export_filename; // setup PCL Zip to create the package containing a json Masterplan and any referenced menu icons require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php'); $zip = new PclZip($export_filename); // create a file out of the representation $pi = pathinfo($filename); $dir = MASTERPRESS_TMP_DIR.$pi["filename"]; wp_mkdir_p($dir); wp_mkdir_p($dir.WOOF_DIR_SEP."icons"); $handle = fopen( $dir.WOOF_DIR_SEP."masterplan.json", "w"); fwrite($handle, WOOF::json_indent( json_encode($rep) ) ); fclose($handle); if (trim($readme) != "") { $handle = fopen( $dir.WOOF_DIR_SEP."README.markdown", "w"); fwrite($handle, $readme ); fclose($handle); } $file_list = array($dir); $icon_list = array(); $type_list = array(); // grab any referenced icons foreach ($rep["icons"] as $icon_file) { $icon = MASTERPRESS_CONTENT_MENU_ICONS_DIR.$icon_file; if (file_exists($icon)) { $dest = $dir.WOOF_DIR_SEP."icons".WOOF_DIR_SEP.$icon_file; $icon_list[] = array("name" => $icon_file, "url" => MASTERPRESS_CONTENT_MENU_ICONS_URL.$icon_file); copy($icon, $dest); } } // now check if there are any field type extensions we need too $ft_dir = $dir.WOOF_DIR_SEP."field-types"; foreach ($rep["field_types"] as $type) { if (MPU::extension_type_exists($type)) { wp_mkdir_p($ft_dir); $source = MPU::extension_type_dir($type); $dest = $ft_dir.WOOF_DIR_SEP.$type; $type_list[] = array("key" => $type, "icon" => MPU::type_icon_url($type)); MPU::copyr($source, $dest); } } $zip->create( $file_list, PCLZIP_OPT_REMOVE_PATH, MASTERPRESS_TMP_DIR ); copy($export_filename, $destination_filename); unlink($export_filename); MPU::rmdir_r($dir); return array("path" => $destination_filename, "icon_list" => $icon_list, "type_list" => $type_list); }
public static function refresh() { global $wf; $values = json_decode(stripslashes($_REQUEST["values"]), true); $model_id = $_REQUEST["model_id"]; if (!is_array($values)) { $values = array($values); } $field = MPM_Field::find_by_id($model_id); if ($field) { $selects = self::selects($field->type_options, $values); $info["select"] = WOOF::render_template($selects["select"], array("id" => $_REQUEST["id"], "name" => str_replace("[]", "", $_REQUEST["name"]) ) ); self::ajax_success( $info ); } }
function col_summary() { global $wf; $p = $this->term(); if ($this->is_multi_select()) { $terms = $this->terms(); if (count($terms)) { if (count($terms) == 1) { return $terms->first()->edit_link(); } else { $links = array(); $tbt = $terms->group_by("taxonomy_name"); foreach ($tbt as $tax_name => $items) { $ids = $items->flatten("id", "sep=,"); $attr = array( "href" => admin_url("edit-tags.php?taxonomy=".$tax_name."&mp_term__in=".$ids."&mp_view=".urlencode( sprintf( __("Related to '%s'", MASTERPRESS_DOMAIN), $wf->the->title() ) )) ); $tax = $wf->taxonomy($tax_name); $text = WOOF::items_number(count($items), sprintf( __("No %s", MASTERPRESS_DOMAIN), $tax->plural_label()), sprintf( __("1 %s", MASTERPRESS_DOMAIN), $tax->singular_label()), sprintf( __("%d %s", MASTERPRESS_DOMAIN), count($items), $tax->plural_label() ) ); $links[] = WOOF_HTML::tag("a", $attr, $text); } return WOOF_HTML::tag("div", "class=mp-col", implode("<br />", $links)); } } else { return ""; } } else { if ($p->exists()) { return $p->edit_link(); } } }
public function posts($args = array()) { // allows custom field based related terms to be included in queries global $wf, $meow_provider; if ($wf->regard_field_terms()) { $args = wp_parse_args($args); $qr = array(); $qr["posts_per_page"] = $args["posts_per_page"]; $args["posts_per_page"] = -1; $posts = parent::posts($args); $ids = $posts->extract("id"); $incoming = $this->incoming($args); $incoming_ids = $incoming->extract("id"); $r = wp_parse_args($args); $qr["post__in"] = array_merge($ids, $incoming_ids); WOOF::copy_args($r, $qr, "paged,offset,orderby,order"); $posts = $wf->posts( $qr ); } else { $posts = parent::posts($args); } return $posts; }
function woof_draw_checkbox_childs($tax_slug, $childs, $show_count, $show_count_dynamic, $hide_dynamic_empty_pos) { $current_request = array(); if (isset($_REQUEST[$tax_slug])) { $current_request = $_REQUEST[$tax_slug]; $current_request = explode(',', $current_request); } ?> <ul class="woof_childs_list"> <?php foreach ($childs as $term) { $inique_id = uniqid(); ?> <?php $count_string = ""; if ($show_count) { if ($show_count_dynamic) { $count = WOOF::dynamic_count($term, 'checkbox'); } else { $count = $term['count']; } $count_string = '<span class="count">(' . $count . ')</span>'; } //+++ if ($hide_dynamic_empty_pos and $count == 0) { continue; } $thumb = woof_get_tax_thumb($term['term_id'], $tax_slug); ?> <li> <div class="iw"> <label for="<?php echo 'woof_' . $inique_id; ?> "> <?php echo $thumb; ?> <input type="checkbox" id="<?php echo 'woof_' . $inique_id; ?> " class="woof_checkbox_term" data-tax="<?php echo $tax_slug; ?> " name="<?php echo $term['slug']; ?> " value="<?php echo $term['term_id']; ?> " <?php checked(in_array($term['slug'], $current_request)); ?> /> <?php echo $term['name']; ?> <?php echo $count_string; ?> </label> </div> <?php if (!empty($term['childs'])) { woof_draw_checkbox_childs($tax_slug, $term['childs'], $show_count, $show_count_dynamic, $hide_dynamic_empty_pos); } ?> </li> <?php } ?> </ul> <?php }
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; }
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; }
public static function input_checkbox_group( $name, $id, $items, $vals, $item_open = "", $item_close = "", $disabled = false ) { $html = ''; if (!is_array($vals)) { $vals = explode(",", $vals); } // the simplified form where the inner arrays are keyed by their labels foreach ($items as $label => $value) { $id_suffix = WOOF::sanitize($value); $attr = array( "id" => $id."_".$id_suffix, "class" => "checkbox", "type" => "checkbox", "name" => $name, "value" => $value ); if ($disabled) { $attr["disabled"] = "disabled"; } if (in_array($value, $vals)) { $attr["checked"] = "checked"; } if ($item_open != "" && $item_close != "") { $html .= $item_open; } $html .= self::tag("input", $attr ); $html .= self::tag("label", array( "for" => $id."_".$id_suffix, "class" => "checkbox" ), $label ); if ($item_open != "" && $item_close != "") { $html .= $item_close; } } return $html; }
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>…</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; }
public function link($args = array()) { // get an <a> tag linking to the archive page of the post type // by default the text will be the plural label for the post type // if the post type doesn't have an archive, an empty string will be returned. $defaults = array( 'text' => $this->plural_label(), 'root_relative' => true, 'current_class' => 'current' ); $r = wp_parse_args( $args, $defaults ); $post_type_archive_url = $this->archive_url($r["root_relative"]); if (!$post_type_archive_url) { return ''; } if ( $r['current_class'] && trim($_SERVER["REQUEST_URI"], "/") == trim($post_type_archive_url, "/") ) { if (isset($r['class'])) { $r['class'] .= (' '.$r['current_class']); } else { $r['class'] = $r['current_class']; } } if ($r["root_relative"]) { $tag = '<a href="'.WOOF::lpad($post_type_archive_url, "/").'"'; } else { $tag = '<a href="'.get_bloginfo("home").$post_type_archive_url.'"'; } 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; }
public static function term_column_content( $out, $key, $term) { global $taxonomy, $wf; $mode = "list"; if (isset($_GET["mode"])) { $mode = $_GET["mode"]; } $the_term = $wf->term_by_id($term, $taxonomy); $tax = self::manage_taxonomy(); $columns = $tax->columns_by_key(); $column = $columns[$key]; if (!isset($column["core"])) { // we only need to output custom columns if (isset($column["content"])) { $content = stripslashes($column["content"]); MasterPress::$context = "col"; $out = WOOF::eval_expression($content, $the_term); MasterPress::$context = ""; echo $out; } } }
public function tmpl($key, $tmpl = "", $default = null) { $blank = true; $val = $this->get($key); if ($val && !is_woof_silent($val)) { $blank = false; } if (!$blank || !is_null($default)) { if ($blank) { $value = $default; } else { $value = $val; } if (!preg_match("/\{\{.+\}\}/", $tmpl)) { // assume we want the value in the innermost tag WOOF::incl_phpquery(); phpQuery::newDocumentHTML('<div class="context"></div>', $charset = 'utf-8'); pq($tmpl)->appendTo(".context"); pq("*:only-child:last")->append("{{val}}"); $tmpl = pq(".context")->html(); } return WOOF::render_template($tmpl, array("value" => $value, "val" => $value) ); } return ""; }
public static function post_column_content($key) { global $wf; $mode = "list"; $post_type = "post"; if (isset($_GET["mode"])) { $mode = $_GET["mode"]; } $pt = self::manage_post_type(); if ($pt) { $columns = $pt->columns_by_key(); if (isset($columns[$key])) { $column = $columns[$key]; if (!isset($column["core"])) { // we only need to output custom columns if (isset($column["content"])) { $content = stripslashes($column["content"]); MasterPress::$context = "col"; $out = WOOF::eval_expression($content, $wf->the); MasterPress::$context = ""; echo $out; } } } } }
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") ); }
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 ""; }
function col() { global $wf; $p = $this->post(); if ($this->is_multi_select()) { $posts = $this->posts("post_status=any"); if (count($posts)) { if (count($posts) == 1) { return $posts->first()->edit_link(); } else { $links = array(); $pbt = $posts->group_by("type_name"); foreach ($pbt as $type => $items) { $ids = $items->flatten("id", "sep=,"); $attr = array( "href" => admin_url("edit.php?post_type=".$type."&mp_post__in=".$ids."&mp_view=".urlencode( sprintf( __("Related to '%s'", MASTERPRESS_DOMAIN), $wf->the->title() ) )) ); $pt = $wf->type($type); $text = WOOF::items_number(count($items), sprintf( __("No %s", MASTERPRESS_DOMAIN), $pt->plural_label()), sprintf( __("1 %s", MASTERPRESS_DOMAIN), $pt->singular_label()), sprintf( __("%d %s", MASTERPRESS_DOMAIN), count($items), $pt->plural_label() ) ); $links[] = WOOF_HTML::tag("a", $attr, $text); } return WOOF_HTML::tag("div", "class=mp-col", implode("<br />", $links)); } } else { return ""; } } else { if (!is_null($p) && $p->exists()) { return $p->edit_link(); } } }
public static function ui( MEOW_Field $field ) { global $wf; // $field here is a MEOW_Field, which is a class that encapsulates the value of a field AND the info associated with it $options = $field->info->type_options; $readonly = WOOF_HTML::readonly_attr( !$field->is_editable() ); $no_url = __("( no URL entered )", MASTERPRESS_DOMAIN); $url_label = __("URL:", MASTERPRESS_DOMAIN); $button_refresh = __("Refresh Info", MASTERPRESS_DOMAIN); $fetching_info_message = __("Fetching video info… please wait", MASTERPRESS_DOMAIN); $visit_video_title = __("Visit video page", MASTERPRESS_DOMAIN); $watch_video_title = __("Watch video", MASTERPRESS_DOMAIN); $style = ""; if (isset($options["height"]) && is_numeric($options["height"])) { $style .= "height: ".$options["height"]."px;"; } $watch_url = ""; $video_url = ""; $host = ""; $title = ""; $value = ""; $video_id = ""; $empty = "empty"; if (!$field->blank()) { $value = htmlspecialchars($field->value()); $empty = ""; $video_id = $field->prop("video_id"); $host = $field->prop("host"); $title = $field->prop("title"); if ($title == "") { $empty = "empty"; } if ($video_id && $video_id != "") { list($watch_url, $video_url) = self::urls($video_id, $host); } } $prop_inputs = self::prop_inputs($field, self::ui_prop()); $summary_thumb = ""; $thumb = ""; $prop_title = $field->prop("title"); $prop_host = $field->prop("host"); $prop_duration = $field->prop("duration"); $prop_published = self::format_date($field->prop("published")); $prop_updated = self::format_date($field->prop("updated")); $prop_thumbnail = $field->prop_val("thumbnail"); $published_style = ""; $updated_style = ""; if ($field->prop("published") == "") { $published_style = ' style="display:none;" '; } if ($field->prop("updated") == "") { $updated_style = ' style="display:none;" '; } $prop_video_id = $field->prop("video_id"); $display_title = WOOF::truncate_advanced($prop_title, 60, $etc = ' … ', false, true); $summary_display_title = WOOF::truncate_advanced($prop_title, 50, $etc = ' … ', false, true); $host_name = self::host_name($prop_host); list($tw, $th) = array(120, 90); list($stw, $sth) = array(84, 63); $orientation = "square"; $thumb = WOOF_Image::empty_mp_thumb(array("w" => $tw, "h" => $th, "no_image" => $no_url, "class" => "managed thumb") ); $summary_thumb = WOOF_Image::empty_mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_url, "class" => "managed summary-thumb" ) ); if ($prop_thumbnail && $prop_thumbnail != "") { $img = $wf->image_from_url($prop_thumbnail); if ($img && $img->exists()) { $watermark = MPU::type_image("video", "play-overlay.png"); $watermark_args = array("at" => "c", "h" => "60%"); $thumb = $img->mp_thumb(array("w" => $tw, "h" => $th, "no_image" => $no_url, "watermark" => $watermark, "watermark_args" => $watermark_args, "link_attr" => array("class" => "thumb iframe", "href" => $watch_url), "class" => "thumb managed") ); $summary_thumb = $img->mp_thumb(array("w" => $stw, "h" => $sth, "no_image" => $no_url, "class" => "managed summary-thumb", "thumb_only" => true ) ); } } $html = <<<HTML <div class="state {$empty}"> {$prop_inputs} <div class="summary-content"> {$summary_thumb} <div class="summary-info"> <span class="title">{$summary_display_title}</span> <span class="host"><span class="host-type {$prop_host}"><span class="host-name">{$host_name}</span><span class="duration">({$prop_duration})</span></span></span> </div> </div> <div class="ui-content"> {$thumb} <div class="url-info"> <div class="f f-url"> <label for="{{id}}" class="{prop_host}">{$url_label}</label> <input id="{{id}}" name="{{name}}" autocomplete="off" {$readonly} type="text" value="{$value}" class="url text" /> </div> <div class="info"> <span class="error-message"><i></i>error</span> <span class="fetching-info-message progress-message">{$fetching_info_message}</span> <div class="title"> <a href="{$video_url}" target="_blank" title="{$visit_video_title}" class="{$prop_host} title-link">{$display_title}</a> <button class="text refresh with-icon" title="{$button_refresh}" type="button">{$button_refresh}</button> </div> <div class="prop-wrap"> <ul class="prop"> <li class="duration">{$prop_duration}</li> <li class="published" {$published_style}>Published: <span class="val">{$prop_published}</span></li> <li class="updated" {$updated_style}>Updated: <span class="val">{$prop_updated}</span></li> </ul> </div> </div> </div> </div> </div> <!-- /.state --> HTML; return $html; }
function url($root_relative = false) { global $wf; $u = $this->url; if ($root_relative) { return WOOF::root_relative_url($u); } else { return $wf->purl($u); } }
static function combine_type_scripts() { $files = array(); $type_keys = MPFT::type_keys(); // files to merge foreach (MPFT::type_keys() as $type) { $base = WOOF::root_relative_url( MPU::type_file_url($type, "") ); $file = MPU::type_file_path($type, "mpft-$type.js"); if (file_exists($file)) { $files[] = array("base" => $base, "file" => $file); } } $image_base = WOOF::root_relative_url( MASTERPRESS_IMAGES_URL ); // we'll be able to kick this off with an AJAX action in the MasterPress overview // the dev guide for field types must point the "REBUILD" process out to developers! // we can also run this on install and upgrade, so that if field types change, the files would be rebuilt // get code from archive folder if it exists, otherwise grab latest files, merge and save in archive folder if (file_exists(MASTERPRESS_CONTENT_MPFT_CACHE_DIR) && is_writable ( MASTERPRESS_CONTENT_MPFT_CACHE_DIR ) ) { // get and merge code $content = ''; foreach ($files as $file) { $content .= file_get_contents($file["file"]); } MPU::incl_lib("jsminplus.php"); $content = JSMinPlus::minify($content); $handle = fopen(MASTERPRESS_CONTENT_MPFT_CACHE_DIR."mpft-all.js", 'w'); if ($handle) { if (flock($handle, LOCK_EX)) { fwrite($handle, $content); flock($handle, LOCK_UN); } fclose($handle); } } }
public static function ui( MEOW_Field $field ) { global $wf; $prop_inputs = self::prop_inputs($field, "attachment_id"); $prop_source_url = $field->prop("source_url"); $no_file = __("( no file )", MASTERPRESS_DOMAIN); $empty = ""; $filename = ""; $filesize = ""; $filetype = ""; $fileurl = ""; $filetype_class = ""; $filename_trunc = ""; $filetype_trunc = ""; $summary_filename_trunc = ""; $summary_filetype_trunc = ""; if (!$field->blank()) { $file = $field->file(); if ($file && $file->exists()) { $filename = $file->basename(); $filesize = $file->filesize(); $filetype = $file->filetype(); if ($file->is_external()) { $fileurl = $field->value(); } else { $fileurl = $file->permalink(); } $filetype_class = "file-type file-type-".$file->extension(); $filename_trunc = WOOF::truncate_advanced($filename, 37, $etc = ' … ', false, true); $filetype_trunc = WOOF::truncate_advanced($filetype, 36, $etc = ' … ', false, true); $summary_filename_trunc = WOOF::truncate_advanced($filename, 26, $etc = ' … ', false, true); $summary_filetype_trunc = WOOF::truncate_advanced($filetype, 25, $etc = ' … ', false, true); } } else { $empty = "empty"; $filename = $no_file; $filename_trunc = $no_file; } $replace_image_label = __("Replace File:", MASTERPRESS_DOMAIN); $choose_image_label = __("Choose File:", MASTERPRESS_DOMAIN); $url_label = __("Enter File URL:", MASTERPRESS_DOMAIN); $button_view_download_label = __("View / Download", MASTERPRESS_DOMAIN); $button_delete_label = __("Delete", MASTERPRESS_DOMAIN); $button_from_computer_label = __("From Computer…", MASTERPRESS_DOMAIN); $button_from_media_library_label = __("From Media Library…", MASTERPRESS_DOMAIN); $button_from_url_label = __("From URL…", MASTERPRESS_DOMAIN); $button_from_existing_uploads_label = __("From Existing Uploads…", MASTERPRESS_DOMAIN); $button_clear_label = __("Clear", MASTERPRESS_DOMAIN); $button_delete_label = __("Delete", MASTERPRESS_DOMAIN); $button_download_label = __("Download", MASTERPRESS_DOMAIN); $button_cancel_label = __("Cancel", MASTERPRESS_DOMAIN); $button_clear_title = __("Clear field without deleting the file", MASTERPRESS_DOMAIN); $button_delete_title = __("Clear field and delete the file", MASTERPRESS_DOMAIN); $drop_label = __("Drop file here to upload", MASTERPRESS_DOMAIN); $base_url = MASTERPRESS_CONTENT_URL; $dir = 'uploads/'; $media_library_progress_message = __("Fetching URL from Media Library...", MASTERPRESS_DOMAIN); $upload_progress_message = __("Uploading...", MASTERPRESS_DOMAIN); $fetching_info_message = __("Fetching File Information...", MASTERPRESS_DOMAIN); $dowloading_progress_message = __("Downloading File...", MASTERPRESS_DOMAIN); $upload_html = ""; $download_html = ""; $file_controls_html = ""; $labels_html = ""; $controls_html = ""; $drop_html = ""; if ($wf->the_user->can("upload_files") && $field->is_editable()) { $controls_html = <<<HTML <div class="choose-controls"> <h5 class="replace-label">{$replace_image_label}</h5> <h5 class="choose-label">{$choose_image_label}</h5> <div class="buttons"> <div class="file-uploader { input: '#{{id}}', inputName: '{{id}}_file', ids: { drop: '{{id}}_drop_area' }, base_url: '{$base_url}', params: { dir: '{$dir}' }, limit: 1, lang: { buttonChoose: '{$button_from_computer_label}', buttonReplace: '{$button_from_computer_label}' } }"> <input id="{{id}}" name="{{name}}" value="{$fileurl}" type="hidden" class="value" autocomplete="off" /> <div class="uploader-ui"></div> </div> <!-- /.file-uploader --> <button type="button" class="button button-small button-from-url">{$button_from_url_label}</button> <button type="button" class="button button-small button-from-media-library">{$button_from_media_library_label}</button> </div> </div> HTML; $file_controls_html = <<<HTML <div class="file-controls"> <ul> <li><button type="button" type="button" class="text with-icon view">{$button_view_download_label}</button></li> <li><button type="button" type="button" class="text with-icon clear">{$button_clear_label}</button></li> </ul> </div> HTML; $drop_html = <<<HTML <div id="{{id}}_drop_area" class="drop-area">{$drop_label}</div> HTML; } else { $controls_html = <<<HTML <input id="{{id}}" name="{{name}}" value="{$fileurl}" type="hidden" class="value" autocomplete="off" /> HTML; } $html = <<<HTML <div class="summary"> <span class="name" title="{$filename}">{$summary_filename_trunc}</span> <span class="type-size"><span class="type" title="{$filetype}">{$summary_filetype_trunc}</span> <br><span class="size">{$filesize}</span></span> </div> <div class="ui-state {$empty}"> {$prop_inputs} <a href="{$fileurl}" class="file-info" tabindex="-1" target="_blank"> {$drop_html} <h4 class="name"><i class="{$filetype_class}"></i>{$filename_trunc}</h4> <ul class="prop"> <li class="filetype">{$filetype}</li> <li class="filesize">{$filesize}</li> </ul> </a> <!-- /.file-info --> {$file_controls_html} <div class="media-library-progress"> <span class="fetching-message progress-message">{$media_library_progress_message}</span> <span class="fetching-info-message progress-message">{$fetching_info_message}</span> </div> <!-- /.media-library-progress --> <div class="upload-progress"> <div class="upload-progress-well"> <span class="name"><i></i></span> <div class="progress-bar-with-val"> <div class="progress-bar"><div class="border"><div><span class="bar"> </span></div></div></div> <div class="val">0%</div> </div> </div> <span class="uploading-message progress-message">{$upload_progress_message}</span> <span class="fetching-info-message progress-message">{$fetching_info_message}</span> </div> <!-- /.upload-progress --> {$controls_html} <div class="from-url-ui"> <label for="{{id}}-url">{$url_label}</label> <input id="{{prop_id}}-source_url" name="{{prop_name}}[source_url]" type="text" value="{$prop_source_url}" class="text url" /> <div class="buttons"> <button type="button" class="button button-small download">{$button_download_label}</button> <button type="button" class="button button-small cancel">{$button_cancel_label}</button> </div> </div> <!-- /.from-url --> <div class="download-progress"> <span class="downloading-message progress-message">{$dowloading_progress_message}</span> <span class="fetching-info-message progress-message">{$fetching_info_message}</span> </div> <!-- /.download-progress --> </div> <!-- /.ui-state --> HTML; return $html; }
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; }
function terms_by_id($ids, $taxonomy = NULL) { global $wpdb, $wf; if (!is_array($ids)) { $ids = explode(",", $ids); } $results = array(); if (count($ids)) { // check for composite IDs $ids_by_taxonomy = array(); foreach ($ids as $id) { list($term_taxonomy, $term_id) = WOOF::parse_term_composite($id); if (!is_null($taxonomy)) { $term_taxonomy = $taxonomy; } if (!isset($ids_by_taxonomy[$term_taxonomy])) { $ids_by_taxonomy[$term_taxonomy] = array($term_id); } else { $ids_by_taxonomy[$term_taxonomy][] = $term_id; } } // build the where clause $where_parts = array(); foreach ($ids_by_taxonomy as $tax_name => $ids) { $real_ids = array(); foreach ($ids as $id) { if (is_numeric($id)) { $real_ids[] = $id; } } if (count($real_ids)) { $where = " ( t.term_id IN (".implode(",", $real_ids)." ) "; if ($tax_name != "*") { $where .= " AND tt.taxonomy = '".$tax_name."' "; } $where .= " ) "; $where_parts[] = $where; } } if (count($where_parts)) { $sql = "SELECT t.term_id, t.name, t.slug, t.term_group, tt.term_taxonomy_id, tt.count, tt.description, tt.parent, tt.taxonomy FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE ( ".implode(" OR ", $where_parts)." ) "; $results = $wpdb->get_results($sql); } } return $wf->wrap_terms($results); }
public function border($attr) { global $wf; $ic = $wf->get_image_class(); $r = wp_parse_args( $attr, array( "width" => 1, // border width "mode" => "o", // mode - i (inset, same size, original image will shrink inside border), or o (outset, image size will increase for border) "color" => "FFF" // gap between image and reflection )); $color = $r["color"]; $color_hex = $r["color"]; if (!is_array($color)) { $color = WOOF::hex_to_rgb($color); } else { $color_hex = WOOF::rgb_to_hex($color); } if (isset($r["w"])) { $r["width"] = $r["w"]; } $r["suffix"] = ".border.".str_replace("#", "", $color_hex).$r["mode"].$r["width"]; $ci = $this->cacheinfo($r); if (file_exists($ci["path"]) && !isset($r["nocache"])) { return new $ic( $ci["path"], $ci["url"], $this->attr() ); } else { $image = WOOF_Image::load($this->filepath()); if ($r["mode"] == "o") { $output_height = $this->height() + ($r["width"] * 2); // calculate height of output image $output_width = $this->width() + ($r["width"] * 2); // calculate height of output image } else { $output_height = $this->height(); $output_width = $this->width(); } $out = imagecreatetruecolor($output_width, $output_height); imagealphablending($out, false); $bg = imagecolorallocate($out, $color[0], $color[1], $color[2]); imagefill($out, 0, 0, $bg); if ($r["mode"] == "o") { imagecopyresized($out, $image, $r["width"], $r["width"], 0, 0, $this->width(), $this->height(), $this->width(), $this->height()); } else { imagecopyresized($out, $image, $r["width"], $r["width"], 0, 0, $this->width() - ($r["width"] * 2), $this->height() - ($r["width"] * 2), $this->width(), $this->height()); } if ( self::save_image( $ci["path"], $out, $this->infer_content_type($r) ) ) { return new $ic( $ci["path"], $ci["url"], $this->attr() ); } } }
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); } } } } }
function truncate_custom($args = array()) { $str = strip_tags($this->value()); return WOOF::truncate($str, $args); }
public function value_for_set($value) { global $wf; if (WOOF::is_or_extends($value, "WOOF_Image")) { return $value->permalink(); } else if ($att = $wf->attachment($value)->exists()) { return $att->file->permalink(); } return $value; }
function __get($name) { // is we're accessing the set named "content" and it exists, prioritise this first // this allows us to call "content()" to get the standard content FIELD. if ($name == "content") { $set = $this->set("content"); if ($set->exists()) { return $set; } } if ($name == "posts" || $name == "pages") { return parent::__get($name); } // first, look for a property named $name $result = $this->get($name); if (!is_woof_silent($result)) { return $result; } // next, try to get a set named $name $result = $this->s($name); if (!is_woof_silent($result)) { return $result; } // next try the parent, which will get post types, or taxonomies with this name return parent::__get($name); }