File Objects
The file is a pretty simple object with only a few fields. Each file is linked to a person object representing the person who uploaded the file. In addition, the file may be linked to a content object.
Fields
| id | the unique id of this file |
|---|---|
| contentId | reference to the piece of content the file is attached to |
| groupId | reference to a group the file is attached to |
| userId | reference to the file's uploader |
| file_name | the descriptive name of this file. files uploaded via the edit profile script and default pods name the file 'img' because it is primarily used as an avatar. |
| local_file | pointer to a copy of the original file stored by PeoplePods on the webserver |
| original_name | the original filename of the file |
| description | a description of the file, or a caption for an image |
| extension | 3 character file extension |
| mime_type | the mime type of the file which is autodetected |
| changeDate | date this file was most recently changed |
| date | date this file was uploaded |
| original_file | url of uploaded original file |
| resized | url of resized image, as defined in the PeoplePods admin tool |
| thumbnail | url of the thumbnail image, as defined in the PeoplePods admin tool |
| minutes | minutes since the file was uploaded |
| tmp_name | temporary name of a file that has just been uploaded. this is found in the $_FILES array. |
Relationships
You can access the files of the owner by using the $file->creator() function, which returns a person object.
// access person object member functions
echo "Uploaded by: ";
$file->owner()->permalink();
// output the owner using a special template
$file->owner()->output('avatar');
You can also access the content that the file is attached to, using the handy $file->parent() function.
// access content values
$file->parent()->write('headline');
// is this file by the original poster?
if ($file->get('userId')==$file->parent()->get('userId')) {
// do something
}
Displaying Files
You can use the $file->output() function to output a file using its own templates, or you can access individual fields.
Templates for file objects are found in the files/ sub folder of your theme.
// output a file using the files/download.php template
$file->output('download');
// print an image link using the resized image
<img src="<? $file->write('resized'); ?>" />
// print a link to the original file
< a href="<? $file->write('original_file'); ?>" />
You might also want to send the actual contents of a file instead of just making a link to it. To do this, use the $file->download() function.
Image Files
When an image is uploaded, PeoplePods will automatically resize it into 2 sizes: a resized version, and a thumbnail version. The specifics of how the image is resized can be set using the PeoplePods Command Center tool.
You can tell whether or not a file is an image by using the $file->isImage() function.
PeoplePods can also automatically generate new sizes of an image using the $file->src() function:
// generate a version that is 100 pixels wide <img src="< $img->src(100); ?>" /> // generate a version that is 50 pixels wide and cropped to a square <img src="< $img->src(50,true); ?>" />
Loading Files
The vast majority of the time, you'll probably be displaying the files that are attached to the piece of content you are viewing, or that were uploaded by a specific person. To do this, simply use the $content->files() and $person->files() functions, which returns a list of the files in chronological order.
You can also load a specific file by it's id using the $POD->getFile() function.
If you need to query the file database on any of the file fields or fields in the related tables, use the $POD->getFiles() function.
// output the files from a piece of content
$content->files()->output();
// load a specific file (for editing, etc)
$file = $POD->getFile(array('id'=>1));
// load all files from a user,
// regardless of whether or not it was attached to content
$files = $POD->getFiles(array('userId'=>1));
// load all files from a user NOT attached to contnet
$files = $POD->getFiles(array('userId'=>1,'contentId'=>'null'));
// load all files from any piece of content in a specific group
$group_files = $POD->getFiles(array('d.groupId'=>5));
Adding and Removing File
The best way to add a file is to use the $content->addFile() function or the $person->addFile() function, which handles all the nitty gritty details.
To delete files, call $file->delete().
Relationships
Each file has a set of predefined relationships to people and other pieces of content within the site. These relationships are represented by cleverly named functions that return other objects or stacks of objects.
- $File->author() - returns a person object defined by $File's userId field.
And don't forget, every content object inherits all the functions from the $Obj object. These functions include:
- $File->get()
- $File->set()
- $File->write()
- $File->writeFormatted()
- $File->htmlspecialwrite()
- $File->addMeta()
- $File->removeMeta()
- $File->getMeta()
- $File->addFlag()
- $File->removeFlag()
- $File->toggleFlag()
- $File->hasFlag()
- $File->addTag()
- $File->removeTag()
- $File->hasTag()
- $File->tagsFromString()
- $File->tagsAsString()
- $File->success()
- $File->error()
- $File->errorCode()
- $File->asArray()
More about this function and it's related functions:
Download the latest version of PeoplePods!
0.9
Latest Version:
Release Notes
Recent Posts from Our Blog
Version 0.9 is here!
The latest version of PeoplePods is now available for download! This version features a drastically revamped theme which is now valid HTML5, a completely rewritten JSON-powered API, many...
Ben Brown on how running a community is like throwing a giant, never-ending party
An interview I did with OpenSource.com is now online! Read it here. In it, I discuss how running an online community is like throwing a giant, never-ending party, how open source techniques...
Recently Updated Documentation
Recent Posts from The Forum
Hello PeoplePods forum, we want to add social networking features to our online training software. We are looking to allow users to post comments on...
0 comments | 5 weeks ago
Hello, My firt problem is whith the API, because when I open my site I find : Invalid API Key. Please visit PeoplePods.net to get a valid...
2 comments | 6 weeks ago
hi i just verified my account, its still keep asking for verification code. in this case, i cannot get the api key...
3 comments | 6 weeks ago
What is the proper way to query the database in PeoplePods? I understand there is a function called executeSQL(), but I'm not entirely sure if I'm...
0 comments | 7 weeks ago
Question
1 comment | 7 weeks ago


No comments have been posted yet.