The Red Matrix
 All Classes Namespaces Files Functions Variables Pages
attach.php File Reference

File/attach API with the potential for revision control. More...

Functions

 z_mime_content_type ($filename)
 Guess the mimetype from file ending. More...
 
 attach_count_files ($channel_id, $observer, $hash= '', $filename= '', $filetype= '')
 Count files/attachments. More...
 
 attach_list_files ($channel_id, $observer, $hash= '', $filename= '', $filetype= '', $orderby= 'created desc', $start=0, $entries=0)
 Returns a list of files/attachments. More...
 
 attach_by_hash ($hash, $rev=0)
 Find an attachment by hash and revision. More...
 
 attach_by_hash_nodata ($hash, $rev=0)
 Find an attachment by hash and revision. More...
 
 attach_store ($channel, $observer_hash, $options= '', $arr=null)
 
 z_readdir ($channel_id, $observer_hash, $pathname, $parent_hash= '')
 
 attach_mkdir ($channel, $observer_hash, $arr=null)
 Create directory. More...
 
 attach_change_permissions ($channel_id, $resource, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $recurse=false)
 Changes permissions of a file. More...
 
 attach_delete ($channel_id, $resource)
 Delete a file/directory from a channel. More...
 
 get_cloudpath ($arr)
 Returns path to file in cloud/. This function cannot be used with mod/dav as it always returns a path valid under mod/cloud. More...
 
 get_parent_cloudpath ($channel_id, $channel_name, $attachHash)
 Returns path to parent folder in cloud/. This function cannot be used with mod/dav as it always returns a path valid under mod/cloud. More...
 
 find_folder_hash_by_attach_hash ($channel_id, $attachHash)
 Return the hash of an attachment's folder. More...
 
 find_filename_by_hash ($channel_id, $attachHash)
 Returns the filename of an attachment in a given channel. More...
 
 pipe_streams ($in, $out)
 
 file_activity ($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity)
 
 get_file_activity_object ($channel_id, $hash, $cloudpath)
 
 recursive_activity_recipients ($allow_cid, $allow_gid, $deny_cid, $deny_gid, $folder_hash)
 
 in_group ($group_id)
 

Detailed Description

File/attach API with the potential for revision control.

TODO: a filesystem storage abstraction which maintains security (and 'data' contains a system filename which is inaccessible from the web). This could get around PHP storage limits and store videos and larger items, using fread or OS methods or native code to read/write or chunk it through. Also an 'append' option to the storage function might be a useful addition.

Function Documentation

attach_by_hash (   $hash,
  $rev = 0 
)

Find an attachment by hash and revision.

Returns the entire attach structure including data.

This could exhaust memory so most useful only when immediately sending the data.

Parameters
$hash
$rev

Referenced by attach_init().

attach_by_hash_nodata (   $hash,
  $rev = 0 
)

Find an attachment by hash and revision.

Returns the entire attach structure excluding data.

See Also
attach_by_hash()
Parameters
$hash
$ref

Referenced by item_post(), and send_message().

attach_change_permissions (   $channel_id,
  $resource,
  $allow_cid,
  $allow_gid,
  $deny_cid,
  $deny_gid,
  $recurse = false 
)

Changes permissions of a file.

Parameters
$channel_id
$resource
$allow_cid
$allow_gid
$deny_cid
$deny_gid
$recurse

Referenced by filestorage_post().

attach_count_files (   $channel_id,
  $observer,
  $hash = '',
  $filename = '',
  $filetype = '' 
)

Count files/attachments.

Parameters
$channel_id
$observer
$hash(optional)
$filename(optional)
$filetype(optional)
Returns
array $ret['success'] boolean $ret['results'] amount of found results, or false $ret['message'] string with error messages if any
attach_delete (   $channel_id,
  $resource 
)

Delete a file/directory from a channel.

If the provided resource hash is from a directory it will delete everything recursively under this directory.

Parameters
int$channel_idThe id of the channel
string$resourceThe hash to delete
Returns
void

Referenced by RedMatrix\RedDAV\RedDirectory\createFile(), RedMatrix\RedDAV\RedFile\delete(), filestorage_content(), and RedMatrix\RedDAV\RedFile\put().

attach_list_files (   $channel_id,
  $observer,
  $hash = '',
  $filename = '',
  $filetype = '',
  $orderby = 'created desc',
  $start = 0,
  $entries = 0 
)

Returns a list of files/attachments.

Parameters
$channel_id
$observer
$hash(optional)
$filename(optional)
$filetype(optional)
$orderby
$start
$entries
Returns
array $ret['success'] boolean $ret['results'] array with results, or false $ret['message'] string with error messages if any
attach_mkdir (   $channel,
  $observer_hash,
  $arr = null 
)

Create directory.

attach_mkdir($channel,$observer_hash,$arr);

Parameters
array$channelchannel array of owner
string$observer_hashhash of current observer
array$arrparameter array to fulfil request Required: $arr['filename'] $arr['folder'] // hash of parent directory, empty string for root directory Optional: $arr['hash'] // precumputed hash for this node $arr['allow_cid'] $arr['allow_gid'] $arr['deny_cid'] $arr['deny_gid']

Referenced by RedMatrix\RedDAV\RedDirectory\createDirectory().

attach_store (   $channel,
  $observer_hash,
  $options = '',
  $arr = null 
)
Parameters
$channelchannel array of owner
$observer_hashhash of current observer
$options(optional)
$arr(optional)

Referenced by fix_attached_file_permissions(), importelm_post(), send_message(), and wall_attach_post().

file_activity (   $channel_id,
  $object,
  $allow_cid,
  $allow_gid,
  $deny_cid,
  $deny_gid,
  $verb,
  $no_activity 
)

Referenced by attach_delete(), and filestorage_post().

find_filename_by_hash (   $channel_id,
  $attachHash 
)

Returns the filename of an attachment in a given channel.

Parameters
mixed$channel_idThe id of the channel
mixed$attachHashThe hash of the attachment
Returns
string The filename of the attachment

Referenced by get_parent_cloudpath().

find_folder_hash_by_attach_hash (   $channel_id,
  $attachHash 
)

Return the hash of an attachment's folder.

Parameters
int$channel_idThe id of the channel
string$attachHashThe hash of the attachment
Returns
string

Referenced by get_parent_cloudpath().

get_cloudpath (   $arr)

Returns path to file in cloud/. This function cannot be used with mod/dav as it always returns a path valid under mod/cloud.

Parameters
array$arr,[uid]int the channels uid $arr[folder] string $arr[filename]] string
Returns
string path to the file in cloud/

Referenced by filestorage_content().

get_file_activity_object (   $channel_id,
  $hash,
  $cloudpath 
)

Referenced by attach_delete(), and filestorage_post().

get_parent_cloudpath (   $channel_id,
  $channel_name,
  $attachHash 
)

Returns path to parent folder in cloud/. This function cannot be used with mod/dav as it always returns a path valid under mod/cloud.

Parameters
int$channel_idThe id of the channel
string$channel_nameThe name of the channel
string$attachHash
Returns
string with the full folder path

Referenced by attach_delete(), filestorage_content(), and filestorage_post().

in_group (   $group_id)
pipe_streams (   $in,
  $out 
)
Parameters
$in
$out

Referenced by attach_init().

recursive_activity_recipients (   $allow_cid,
  $allow_gid,
  $deny_cid,
  $deny_gid,
  $folder_hash 
)

Referenced by file_activity().

z_mime_content_type (   $filename)

Guess the mimetype from file ending.

This function takes a file name and guess the mimetype from the filename extension.

Parameters
$filenamea string filename
Returns
string The mimetype according to a file ending.

Referenced by attach_store(), and RedMatrix\RedDAV\RedDirectory\createFile().

z_readdir (   $channel_id,
  $observer_hash,
  $pathname,
  $parent_hash = '' 
)

Read a virtual directory and return contents, checking permissions of all parent components. z_readdir

Parameters
integer$channel_id
string$observer_hashhash of current observer
string$pathname
string$parent_hash(optional)
Returns
array $ret $ret['success'] = boolean true or false $ret['message'] = error message if success is false $ret['data'] = array of attach DB entries without data component