lots of work on merging photo and file albums/folders

This commit is contained in:
redmatrix 2015-06-17 17:44:31 -07:00
parent c6c17182e5
commit 6ab20eb1b5
5 changed files with 59 additions and 27 deletions

View File

@ -352,7 +352,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$newalbum = (($arr) ? $arr['newalbum'] : ''); $newalbum = (($arr) ? $arr['newalbum'] : '');
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null); $hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
// logger('arr: ' . print_r($arr,true)); logger('arr: ' . print_r($arr,true));
// This is currently used only in mod/wall_attach // This is currently used only in mod/wall_attach
@ -450,28 +450,44 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$is_photo = 1; $is_photo = 1;
} }
$pathname = '';
if($is_photo) { if($is_photo) {
if($newalbum) { if($newalbum)
$x = z_readdir($channel_id, $observer_hash, filepath_macro($newalbum)); $pathname = filepath_macro($newalbum);
} else
elseif($album) { $pathname = filepath_macro($album);
$x = z_readdir($channel_id, $observer_hash, filepath_macro($album)); }
} else {
if(! $x['success']) { $pathname = filepath_macro($upload_path);
// recursively create the directory path
}
} }
$darr = array('pathname' => $pathname);
if($arr && array_key_exists('allow_cid',$arr))
$darr['allow_cid'] = $arr['allow_cid'];
if($arr && array_key_exists('allow_gid',$arr))
$darr['allow_gid'] = $arr['allow_gid'];
if($arr && array_key_exists('deny_cid',$arr))
$darr['deny_cid'] = $arr['deny_cid'];
if($arr && array_key_exists('deny_gid',$arr))
$darr['deny_gid'] = $arr['deny_gid'];
if($pathname) {
$x = attach_mkdirp($channel_id, $observer_hash, $darr);
$folder_hash = (($x['success']) ? $x['data']['hash'] : '');
}
else {
$folder_hash = '';
}
$created = datetime_convert(); $created = datetime_convert();
if($options === 'replace') { if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d", $r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
dbesc($filename), dbesc($filename),
dbesc($mimetype), dbesc($mimetype),
dbesc($folder_hash),
intval($filesize), intval($filesize),
intval(0), intval(0),
intval($is_photo), intval($is_photo),
@ -482,14 +498,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
elseif($options === 'revise') { elseif($options === 'revise') {
$r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid ) $r = q("insert into attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid, deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($x[0]['aid']), intval($x[0]['aid']),
intval($channel_id), intval($channel_id),
dbesc($x[0]['hash']), dbesc($x[0]['hash']),
dbesc($observer_hash), dbesc($observer_hash),
dbesc($filename), dbesc($filename),
dbesc($mimetype), dbesc($mimetype),
dbesc($folder_hash),
intval($filesize), intval($filesize),
intval($x[0]['revision'] + 1), intval($x[0]['revision'] + 1),
intval(0), intval(0),
@ -504,10 +521,11 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
elseif($options === 'update') { elseif($options === 'update') {
$r = q("update attach set filename = '%s', filetype = '%s', edited = '%s', os_storage = %d, is_photo = %d, $r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', edited = '%s', os_storage = %d, is_photo = %d,
allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where id = %d and uid = %d", allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where id = %d and uid = %d",
dbesc((array_key_exists('filename',$arr)) ? $arr['filename'] : $x[0]['filename']), dbesc((array_key_exists('filename',$arr)) ? $arr['filename'] : $x[0]['filename']),
dbesc((array_key_exists('filetype',$arr)) ? $arr['filetype'] : $x[0]['filetype']), dbesc((array_key_exists('filetype',$arr)) ? $arr['filetype'] : $x[0]['filetype']),
dbesc(($folder_hash) ? $folder_hash : $x[0]['folder']),
dbesc($created), dbesc($created),
dbesc((array_key_exists('os_storage',$arr)) ? $arr['os_storage'] : $x[0]['os_storage']), dbesc((array_key_exists('os_storage',$arr)) ? $arr['os_storage'] : $x[0]['os_storage']),
dbesc((array_key_exists('is_photo',$arr)) ? $arr['is_photo'] : $x[0]['is_photo']), dbesc((array_key_exists('is_photo',$arr)) ? $arr['is_photo'] : $x[0]['is_photo']),
@ -520,14 +538,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
); );
} }
else { else {
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid ) $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']), intval($channel['channel_account_id']),
intval($channel_id), intval($channel_id),
dbesc($hash), dbesc($hash),
dbesc(get_observer_hash()), dbesc(get_observer_hash()),
dbesc($filename), dbesc($filename),
dbesc($mimetype), dbesc($mimetype),
dbesc($folder_hash),
intval($filesize), intval($filesize),
intval(0), intval(0),
intval(0), intval(0),
@ -543,7 +562,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
} }
if($is_photo) { if($is_photo) {
$args = array( 'source' => $source, 'visible' => 0, 'resource_id' => $hash, 'data' => @file_get_contents($src)); $args = array( 'source' => $source, 'visible' => 0, 'resource_id' => $hash, 'album' => basename($pathname), 'data' => @file_get_contents($src));
if($arr['contact_allow']) if($arr['contact_allow'])
$args['contact_allow'] = $arr['contact_allow']; $args['contact_allow'] = $arr['contact_allow'];
$p = photo_upload($channel,get_app()->get_observer(),$args); $p = photo_upload($channel,get_app()->get_observer(),$args);
@ -1510,10 +1529,11 @@ function in_group($group_id) {
function filepath_macro($s) { function filepath_macro($s) {
return str_replace( return str_replace(
array( '%Y', '%M', '%D' ), array( '%Y', '%m', '%d' ),
array( datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'), array( datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'),
datetime_convert('UTC',date_default_timezone_get(),'now', 'm'), datetime_convert('UTC',date_default_timezone_get(),'now', 'm'),
datetime_convert('UTC',date_default_timezone_get(),'now', 'd') datetime_convert('UTC',date_default_timezone_get(),'now', 'd')
), $s); ), $s);
} }

View File

@ -406,6 +406,11 @@ function create_identity($arr) {
} }
} }
if(! $system) {
set_pconfig($ret['channel']['channel_id'],'system','photo_path', '%Y-%m');
set_pconfig($ret['channel']['channel_id'],'system','attach_path','%Y-%m');
}
// auto-follow any of the hub's pre-configured channel choices. // auto-follow any of the hub's pre-configured channel choices.
// Only do this if it's the first channel for this account; // Only do this if it's the first channel for this account;
// otherwise it could get annoying. Don't make this list too big // otherwise it could get annoying. Don't make this list too big

View File

@ -277,9 +277,8 @@ function photos_post(&$a) {
if($p) { if($p) {
$ext = $phototypes[$p[0]['type']]; $ext = $phototypes[$p[0]['type']];
$r = q("UPDATE `photo` SET `description` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", $r = q("UPDATE `photo` SET `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d",
dbesc($desc), dbesc($desc),
dbesc($albname),
dbesc($str_contact_allow), dbesc($str_contact_allow),
dbesc($str_group_allow), dbesc($str_group_allow),
dbesc($str_contact_deny), dbesc($str_contact_deny),
@ -421,7 +420,7 @@ function photos_post(&$a) {
$_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']);
} }
$r = attach_store($a->channel,get_observer_hash(), $_REQUEST); $r = attach_store($a->channel,get_observer_hash(), '', $_REQUEST);
if(! $r['success']) { if(! $r['success']) {
notice($r['message'] . EOL); notice($r['message'] . EOL);

View File

@ -400,6 +400,8 @@ function settings_post(&$a) {
$maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0); $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
$expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0); $expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0);
$evdays = ((x($_POST,'evdays')) ? intval($_POST['evdays']) : 3); $evdays = ((x($_POST,'evdays')) ? intval($_POST['evdays']) : 3);
$photo_path = ((x($_POST,'photo_path')) ? escape_tags(trim($_POST['photo_path'])) : '');
$attach_path = ((x($_POST,'attach_path')) ? escape_tags(trim($_POST['attach_path'])) : '');
$channel_menu = ((x($_POST['channel_menu'])) ? htmlspecialchars_decode(trim($_POST['channel_menu']),ENT_QUOTES) : ''); $channel_menu = ((x($_POST['channel_menu'])) ? htmlspecialchars_decode(trim($_POST['channel_menu']),ENT_QUOTES) : '');
@ -506,6 +508,8 @@ function settings_post(&$a) {
set_pconfig(local_channel(),'system','vnotify',$vnotify); set_pconfig(local_channel(),'system','vnotify',$vnotify);
set_pconfig(local_channel(),'system','always_show_in_notices',$always_show_in_notices); set_pconfig(local_channel(),'system','always_show_in_notices',$always_show_in_notices);
set_pconfig(local_channel(),'system','evdays',$evdays); set_pconfig(local_channel(),'system','evdays',$evdays);
set_pconfig(local_channel(),'system','photo_path',$photo_path);
set_pconfig(local_channel(),'system','attach_path',$attach_path);
$r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d", $r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d",
dbesc($username), dbesc($username),
@ -1011,7 +1015,6 @@ function settings_content(&$a) {
'deny_gid' => $channel['channel_deny_gid'] 'deny_gid' => $channel['channel_deny_gid']
); );
require_once('include/group.php'); require_once('include/group.php');
$group_select = mini_group_select(local_channel(),$channel['channel_default_group']); $group_select = mini_group_select(local_channel(),$channel['channel_default_group']);
@ -1129,7 +1132,9 @@ function settings_content(&$a) {
'$expert' => feature_enabled(local_channel(),'expert'), '$expert' => feature_enabled(local_channel(),'expert'),
'$hint' => t('Please enable expert mode (in <a href="settings/features">Settings > Additional features</a>) to adjust!'), '$hint' => t('Please enable expert mode (in <a href="settings/features">Settings > Additional features</a>) to adjust!'),
'$lbl_misc' => t('Miscellaneous Settings'), '$lbl_misc' => t('Miscellaneous Settings'),
'$menus' => $menu, '$photo_path' => array('photo_path', t('Default photo upload folder'), get_pconfig(local_channel(),'system','photo_path'), '%Y - current year, %m - current month'),
'$attach_path' => array('attach_path', t('Default file upload folder'), get_pconfig(local_channel(),'system','attach_path'), '%Y - current year, %m - current month'),
'$menus' => $menu,
'$menu_desc' => t('Personal menu to display in your channel pages'), '$menu_desc' => t('Personal menu to display in your channel pages'),
'$removeme' => t('Remove Channel'), '$removeme' => t('Remove Channel'),
'$removechannel' => t('Remove this channel.'), '$removechannel' => t('Remove this channel.'),

View File

@ -23,6 +23,9 @@
{{include file="field_input.tpl" field=$defloc}} {{include file="field_input.tpl" field=$defloc}}
{{include file="field_checkbox.tpl" field=$allowloc}} {{include file="field_checkbox.tpl" field=$allowloc}}
{{include file="field_checkbox.tpl" field=$adult}} {{include file="field_checkbox.tpl" field=$adult}}
{{include file="field_input.tpl" field=$photo_path}}
{{include file="field_input.tpl" field=$attach_path}}
<div class="settings-submit-wrapper" > <div class="settings-submit-wrapper" >
<button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button> <button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
</div> </div>