public function plural_label() { $item = $this->item; if ($item) { if (isset($item->labels->name) && $item->labels->name != "" && $item->labels->name != $item->name) { return WOOF_Inflector::titleize($item->labels->name); } else { return WOOF_Inflector::titleize(WOOF_Inflector::pluralize($item->name)); } } return ""; }
public function do_file_from_url($url, $name = "", $dir = null, $assume_extension = "txt", $default_dir, $type) { $exists = false; $info = pathinfo($url); $ext = ""; if (isset($info["extension"])) { $ext = $info["extension"]; } if ($ext == "" || !preg_match("/^[a-z0-9]{1,20}$/", $ext)) { $ext = $assume_extension; } if (is_null($name)) { $file = $info["filename"].".".$ext; } else { if ($name == "") { $file = str_replace("_", "-", WOOF_Inflector::underscore($info["filename"])).".".md5($url).".".$ext; } else { $file = basename($name).".".$ext; } } if (is_null($dir)) { $dir = $default_dir; } if (!is_dir($dir)) { if (!wp_mkdir_p($dir)) { $dir = $default_dir; } } if (file_exists($dir)) { // make sure the base directory exists $file_path = rtrim($dir, WOOF_DIR_SEP).WOOF_DIR_SEP.$file; if (!file_exists($file_path)) { $data = wp_remote_get( $url, array("timeout" => $this->wp_remote_timeout ) ); if (!is_wp_error($data)) { if ($data["response"]["code"] == 200) { // save the file //pr($dir); $handle = fopen ( $file_path , "w" ); fwrite( $handle, $data["body"] ); fclose( $handle ); $exists = true; } } } else { $exists = true; } if ($exists) { $cd = $this->wp_content_dir(); if (strpos($cd, $file_path) === FALSE) { $cd = $this->wp_content_dir(true); } $file_path = str_replace($cd, "", $file_path); if ($type == "image") { $img = $this->content_image( $file_path ); $img->set_external_url($url); return $img; } else { $file = $this->content_file( $file_path ); $file->set_external_url($url); return $file; } } return new WOOF_Silent( sprintf( __("There was no %s at URL %s", WOOF_DOMAIN ), $type, $url ) ); } else { // file_exists $dir return new WOOF_Silent( sprintf( __("Cannot cache %s from URL %s, as the content directory %s does not exist", WOOF_DOMAIN ), $type, $url, $dir ) ); } }
public static function define_term_columns( $columns ) { $tax = self::manage_taxonomy(); $pt = self::manage_post_type(); $posts_label = "Posts"; if ($pt) { $posts_label = $pt->labels["name"]; } if ($tax) { $columns = array(); foreach ($tax->columns() as $column) { $title = ""; if (isset($column["title"])) { $title = $column["title"]; } $key = "custom_".WOOF_Inflector::underscore($title); $disabled = ""; if (isset($column["disabled"])) { $disabled = $column["disabled"]; } if ($disabled != "yes") { if (isset($column["core"])) { $key = $column["core"]; if ($key == "cb") { $title = "<input type=\"checkbox\" />"; } elseif ($key == "posts") { $title = $posts_label; } } $columns[$key] = $title; } } return $columns; } }
public static function model_class($key) { return "MPM_".MPU::title_case(WOOF_Inflector::singularize($key), true); }
public function __get($name) { global $wf; // try to find a taxonomy whose plural name is this $name $singular = WOOF_Inflector::singularize($name); $tax = $wf->taxonomy($singular); if ($tax->exists()) { return $this->terms($singular); } return parent::__get($name); }
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; }
public static function sanitize_filename($filename, $options) { $options = wp_parse_args( $options, array( "filename_sanitize" => "dashes", "filename_case" => "lowercase" ) ); if ($options["filename_sanitize"] != "none") { $filename = sanitize_title_with_dashes($filename); } if ($options["filename_sanitize"] == "underscores") { $filename = str_replace("-", "_", $filename); } if ($options["filename_case"] == "titlecase") { $filename = WOOF_Inflector::titleize($filename); if ($options["filename_sanitize"] == "underscores") { $filename = str_replace(" ", "_", $filename); } else if ($options["filename_sanitize"] == "dashes") { $filename = str_replace(" ", "-", $filename); } } else if ($options["filename_case"] == "uppercase") { $filename = strtoupper($filename); $v = ".V"; } else if ($options["filename_case"] == "lowercase") { $filename = strtolower($filename); } if ($options["filename_sanitize"] == "underscores") { $filename = str_replace("-", "_", $filename); } else if ($options["filename_sanitize"] == "dashes") { $filename = str_replace("_", "-", $filename); } return $filename; }
public function __get($name) { global $wf; // 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; } } // fallback to WOOF_Wrap's get FIRST. $value = $this->get($name); if (is_woof_silent($value)) { $value = $this->set($name); } if (!is_woof_silent($value)) { return $value; } // look for "incoming" post types, so that we can get "incoming_cars" for example if (preg_match("/incoming\_([a-z0-9\_]+)/", $name, $matches)) { $pt_name = $matches[1]; $singular = WOOF_Inflector::singularize($pt_name); foreach ($wf->types() as $type) { if ($type->name == $pt_name) { return $this->incoming("post_type=".$pt_name)->first(); // return the first incoming post } else if ($type->name == $singular) { return $this->incoming("post_type=".$singular); } } // next we'll try taxonomy names foreach ($wf->taxonomies() as $tax) { if ($tax->name == $singular) { return $this->incoming_terms($tax); } } } else { $singular = WOOF_Inflector::singularize($name); foreach ($wf->types() as $type) { if ($type->name == $name) { return $this->posts("post_type=".$name)->first(); // return the first post (ignore the args) } else if ($type->name == $singular) { return $this->posts("post_type=" . $singular); } } } // fallback to the parent method return parent::__get($name); }
public static function help_tab($title, $content) { return array( 'id' => WOOF_Inflector::underscore($title), 'title' => $title, 'content' => self::tab_content( $content ) ); }
public function __get($name) { global $wf; $value = $this->get($name); if (is_woof_silent($value)) { $value = $this->set($name); } if (!is_woof_silent($value)) { return $value; } // look for "incoming" post types, so that we can get "incoming_cars" for example if (preg_match("/incoming\_([a-z0-9\_]+)/", $name, $matches)) { $pt_name = $matches[1]; $singular = WOOF_Inflector::singularize($pt_name); foreach ($wf->types() as $type) { if ($type->name == $singular) { return $this->incoming("post_type=".$singular); } } // next we'll try taxonomy names foreach ($wf->taxonomies() as $tax) { if ($tax->name == $singular) { return $this->incoming_terms($tax->name); } } } return parent::__get($name); }
public function columns_by_key() { if (!isset($this->columns_by_key)) { foreach ($this->columns() as $column) { $title = ""; if (isset($column["title"])) { $title = $column["title"]; } $key = "custom_".WOOF_Inflector::underscore($title); if (isset($column["core"])) { $key = $column["core"]; } $this->columns_by_key[$key] = $column; } } return $this->columns_by_key; }
public function display_label() { if (isset($this->labels["name"]) && $this->labels["name"] != "") { return $this->labels["name"]; } return WOOF_Inflector::titleize($this->name); }
public static function k($class) { return WOOF_Inflector::underscore( WOOF_Inflector::pluralize( str_replace("MPM_", "", $class ) ) ); }
public function model_key() { return WOOF_Inflector::singularize($this->key()); }
public static function define_post_columns($columns) { global $wf; $mode = "list"; $post_type = "post"; if (isset($_GET["mode"])) { $mode = $_GET["mode"]; } if (isset($_GET["post_type"])) { $post_type = $_GET["post_type"]; } $pt = MPM_PostType::find_by_name($post_type); if ($pt) { $columns = array(); foreach ($pt->columns() as $column) { $title = ""; if (isset($column["title"])) { $title = $column["title"]; } $key = "custom_".WOOF_Inflector::underscore($title); $disabled = ""; if (isset($column["disabled"])) { $disabled = $column["disabled"]; } if ($disabled != "yes") { if (isset($column["core"])) { $key = $column["core"]; if ($key == "cb") { $title = "<input type=\"checkbox\" />"; } else if ($key == "comments") { $image = admin_url("images/comment-grey-bubble.png"); $title = <<<HTML <span class="vers"><img alt="Comments" src="{$image}"></span></span> HTML; } } $columns[$key] = $title; } } } return $columns; }
public function __get($name) { global $wf; // try to find a post type with this name, to get posts for this term $singular = WOOF_Inflector::singularize($name); $type = $wf->type($singular); if ($type->exists()) { return $this->posts(array("post_type" => $singular)); } return parent::__call($name, array()); }
/** * Converts a table name to its class name according to rails * naming conventions. * * Converts "people" to "Person" * * @access public * @static * @see tableize * @param string $table_name Table name for getting related ClassName. * @return string SingularClassName */ function classify($table_name) { return WOOF_Inflector::camelize(WOOF_Inflector::singularize($table_name)); }
public function submit() { global $wpdb, $wf; $action = MasterPress::$action; if ($action == "create") { $role_id = $_POST["name"]; if ($role_id == "") { MPV::err(__("A role name must be provided", MASTERPRESS_DOMAIN) ); return false; } // check that there isn't a role of this name already $role = $wf->role($role_id); if ($role && !is_woof_silent($role)) { MPV::err( sprintf( __("Sorry a role named %s already exists. Please choose another name", MASTERPRESS_DOMAIN), $role_id ) ); return false; } // all okay, save the role if (isset($_POST["display_name"]) && trim($_POST["display_name"]) != "") { $display_name = $_POST["display_name"]; } else { $display_name = WOOF_Inflector::titleize($role_id); } $caps = array_keys($_POST["cap"]); foreach ($_POST["new_caps"] as $cap) { if (trim($cap) != "") { $norm = WOOF_Inflector::underscore($cap); if (!in_array($norm, $_POST["all_caps"])) { $caps[] = $norm; } } } add_role($role_id, $display_name, array_fill_keys($caps, true) ); return true; } else if ($action == "edit") { $role_id = MasterPress::$id; $wf_role = $wf->role($role_id); if (!is_woof_silent($wf_role)) { $role = get_role($wf_role->id()); $all_caps = explode(",", $_POST["all_caps"]); $selected_caps = array_keys($_POST["cap"]); $role_caps = array_keys($role->capabilities); $add_caps = array_diff($selected_caps, $role_caps); $remove_caps = array_diff($all_caps, $selected_caps); foreach ($remove_caps as $cap) { if ($role->has_cap($cap)) { $role->remove_cap($cap); } } foreach ($_POST["new_caps"] as $cap) { if (trim($cap) != "") { $norm = WOOF_Inflector::underscore($cap); if (!in_array($norm, $all_caps)) { $add_caps[] = $norm; } } } foreach ($add_caps as $cap) { if (!$role->has_cap($cap)) { $role->add_cap($cap); } } } return true; } else if ($action == "create-field-set" || $action == "edit-field-set") { $field_set = new MPM_RoleFieldSet(); // consume the post data $field_set->name = $_POST["name"]; $field_set->singular_name = $_POST["singular_name"]; $field_set->disabled = isset($_POST["disabled"]); $field_set->labels = $_POST["labels"]; $field_set->visibility = $_POST["visibility"]; $field_set->capabilities = self::handle_capabilities(); $field_set->allow_multiple = isset($_POST["allow_multiple"]); $field_set->type = "r"; // r = role $field_set->icon = self::handle_icon("icon", "icon_select"); $field_set->position = $_POST["position"]; $field_set->expanded = isset($_POST["expanded"]); $field_set->sidebar = false; $field_set->visibility = $this->get_visibility_val("sites,roles"); if (MPC::is_create()) { $field_set->insert(); } else if (MPC::is_edit()) { $field_set->update(MasterPress::$id); } if ($field_set->is_valid()) { if (MPC::is_edit()) { global $meow_provider; $meow_provider->migrate_field_set_meta($field_set, $_POST["name_original"]); } // we don't attach post types to these. they are implicitly linked to the built-in "page" post type // update other menu positions $op = $_POST["other_position"]; if (isset($op) && is_array($op)) { foreach ($op as $id => $position) { $wpdb->update(MPM::table("field-sets"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); } } } return $field_set; } else if ($action == "delete-field-set") { $fg = MPM_FieldSet::find_by_id(MasterPress::$id); if ($fg) { $field_data_action = $_POST["field_data"]; if ($field_data_action == "delete") { $fg->delete_meta(); } } $fg->delete(); return true; } else if ($action == "delete-field") { $f = MPM_Field::find_by_id(MasterPress::$id); if ($f) { $field_data_action = $_POST["field_data"]; if ($field_data_action == "delete") { $f->delete_meta(); } } $f->delete(); return true; } else if ($action == "create-field" || $action == "edit-field") { // FIELD OPERATIONS (NOT FIELD GROUPS!) $field = new MPM_Field(); // consume the post data $field->field_set_id = $_POST["parent"]; $field->name = $_POST["name"]; $field->disabled = isset($_POST["disabled"]); $field->required = isset($_POST["required"]); $field->summary_options = $_POST["summary_options"]; $field->labels = $_POST["labels"]; $field->icon = self::handle_icon("icon", "icon_select"); $field->type = $_POST["type"]; $field->type_options = $_POST["type_options"]; $field->position = $_POST["position"]; $field->visibility = $this->get_visibility_val(); $field->capabilities = self::handle_capabilities(); if (MPC::is_create()) { $field->insert(); } else if (MPC::is_edit()) { $field->update(MasterPress::$id); } if ($field->is_valid()) { if (MPC::is_edit()) { global $meow_provider; $meow_provider->migrate_field_meta($field, $_POST["name_original"]); } // update other menu positions $op = $_POST["other_position"]; if (isset($op) && is_array($op)) { foreach ($op as $id => $position) { $wpdb->update(MPM::table("fields"), array( "position" => $position ), array( "id" => $id ), "%d", "%d" ); } } } return $field; } return false; }
public static function select($options, $value, $blank = false, $editable = true) { global $wf; $control_style = self::option_value($options, "control_style", "drop_down_list"); if ($control_style == "dual_list_box") { // legacy patch for dual list box - it had bad performance for a large number of items $control_style = "list_box_multiple"; } $selected_values = array(); $items = array(); $values_select = ""; $values_options = array_flip($value); $values_options_attr = array_flip($value); $options_attr = array(); $count = -1; $multiple = count($options["user_roles"]) > 1; self::$values_keys = array(); $row_style = self::option_value($options, "row_style", "icon_title"); $result_row_prop = self::option_value($options, "result_row_prop", array()); $grouping = self::option_value($options, "grouping"); $maxwidth = self::option_value($options, "maxwidth"); // build a list of users foreach ($options["user_roles"] as $role_id) { $role = $wf->role($role_id); $users = array("options" => array(), "options_attr" => array()); if ($role && $role->exists()) { $count++; foreach ($role->users() as $user) { $count++; $uid = $user->id(); $title = self::get_row_prop_title($user, $result_row_prop, $role_id); if ($title == "") { $title = $user->full_name(); } // ensure there are no duplicate titles $tcount = 2; while (isset($users["options"][$title])) { $title = $title . " ( ".$tcount." )"; $tcount++; } $users["options"][$title] = $uid; $attr = array( ); // retrieve special properties $attr = array(); if ($row_style == "icon_title_excerpt" || $row_style == "image_title_excerpt") { $attr = array_merge( $attr, self::get_row_prop_role_name($user, $result_row_prop, $role_id) ); } if ($row_style == "image_title_excerpt" || $row_style == "image_title") { $attr = array_merge( $attr, self::get_row_prop_image($user, $result_row_prop, $role_id, $row_style == "image_title" ? 40 : 60) ); } $users["options_attr"][] = $attr; if (in_array($uid, $value)) { $selected_values[] = $uid; $values_options[$uid] = $title; $values_options_attr[$uid] = $attr; } } if (count($users["options"])) { $label = WOOF_Inflector::pluralize($role->name()); $users["optgroup_attr"] = array("label" => $label, "data-selection-prefix" => $role->name().": "); $items[$label] = $users; } } } self::$values_keys = array_values($values_options); $select_style = ""; $select_attr = array("id" => "{{id}}", "name" => "{{name}}"); if (is_numeric($maxwidth)) { $select_style .= "width: 99%; max-width: ".$maxwidth."px;"; } else { $select_style .= "width: 580px;"; } if ($control_style == "list_box_multiple") { $select_attr["multiple"] = "multiple"; $select_attr["name"] = "{{name}}[]"; } if ($select_style != "") { $select_attr["style"] = $select_style; } $basic = self::option_value($options, "basic") == "yes"; if ($control_style == "drop_down_list") { // add a prompting empty label $items = array("" => "") + $items; //array_unshift($options_attr, array()); $select_attr["data-placeholder"] = self::option_value($options, "placeholder", "-- Select a user --"); } else { $select_attr["data-placeholder"] = self::option_value($options, "placeholder", "-- Select users --"); $select_attr["data-value-input"] = "{{id}}-value-input"; if (!$basic) { // ensure the select control does not affect the values posted, the hidden input is responsible for this $select_attr["name"] = "src_".$select_attr["name"]; } } if (!$editable) { $select_attr["data-placeholder"] = __("-- None Selected --", MASTERPRESS_DOMAIN); $select_attr["disabled"] = "disabled"; } return WOOF_HTML::select( $select_attr, $items, $selected_values, $options_attr ); }