Exemplo n.º 1
0
    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 ) );
				
			} 
			
		}
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  public function underscore($property) {
    global $wf;

    $val = $this->get($property);
    
    if (!is_woof_silent($val)) {
      $val = trim($val);
      return WOOF_Inflector::underscore($val);
    }
  
    return "";
  }
Exemplo n.º 4
0
  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;
    
    }
    
  }
Exemplo n.º 5
0
 /**
 * Converts a class name to its table name according to rails
 * naming conventions.
 * 
 * Converts "Person" to "people"
 * 
 * @access public
 * @static
 * @see classify
 * @param    string    $class_name    Class name for getting related table_name.
 * @return string plural_table_name
 */
 function tableize($class_name)
 {
     return WOOF_Inflector::pluralize(WOOF_Inflector::underscore($class_name));
 }
Exemplo n.º 6
0
  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;
  }
Exemplo n.º 7
0
 public static function help_tab($title, $content) {
   return array(
     'id'	=> WOOF_Inflector::underscore($title),
     'title'	=> $title,
     'content'	=> self::tab_content( $content )
   );
 }
Exemplo n.º 8
0
  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;
  }
Exemplo n.º 9
0
 public static function k($class) {
   return WOOF_Inflector::underscore( WOOF_Inflector::pluralize( str_replace("MPM_", "", $class ) ) );
 }