aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/attach.php60
-rw-r--r--include/identity.php5
-rw-r--r--mod/photos.php5
-rw-r--r--mod/settings.php9
-rwxr-xr-xview/tpl/settings.tpl3
5 files changed, 57 insertions, 25 deletions
diff --git a/include/attach.php b/include/attach.php
index 5ad8df502..08aaccb4c 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -352,7 +352,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$newalbum = (($arr) ? $arr['newalbum'] : '');
$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
@@ -450,28 +450,44 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$is_photo = 1;
}
+ $pathname = '';
+
if($is_photo) {
- if($newalbum) {
- $x = z_readdir($channel_id, $observer_hash, filepath_macro($newalbum));
- }
- elseif($album) {
- $x = z_readdir($channel_id, $observer_hash, filepath_macro($album));
- }
- if(! $x['success']) {
- // recursively create the directory path
+ if($newalbum)
+ $pathname = filepath_macro($newalbum);
+ else
+ $pathname = filepath_macro($album);
+ }
+ else {
+ $pathname = filepath_macro($upload_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();
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($mimetype),
+ dbesc($folder_hash),
intval($filesize),
intval(0),
intval($is_photo),
@@ -482,14 +498,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
);
}
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 )
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ $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', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($x[0]['aid']),
intval($channel_id),
dbesc($x[0]['hash']),
dbesc($observer_hash),
dbesc($filename),
dbesc($mimetype),
+ dbesc($folder_hash),
intval($filesize),
intval($x[0]['revision'] + 1),
intval(0),
@@ -504,10 +521,11 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
);
}
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",
dbesc((array_key_exists('filename',$arr)) ? $arr['filename'] : $x[0]['filename']),
dbesc((array_key_exists('filetype',$arr)) ? $arr['filetype'] : $x[0]['filetype']),
+ dbesc(($folder_hash) ? $folder_hash : $x[0]['folder']),
dbesc($created),
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']),
@@ -520,14 +538,15 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
);
}
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 )
- VALUES ( %d, %d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ $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', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']),
intval($channel_id),
dbesc($hash),
dbesc(get_observer_hash()),
dbesc($filename),
dbesc($mimetype),
+ dbesc($folder_hash),
intval($filesize),
intval(0),
intval(0),
@@ -543,7 +562,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
}
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'])
$args['contact_allow'] = $arr['contact_allow'];
$p = photo_upload($channel,get_app()->get_observer(),$args);
@@ -1510,10 +1529,11 @@ function in_group($group_id) {
function filepath_macro($s) {
return str_replace(
- array( '%Y', '%M', '%D' ),
+ array( '%Y', '%m', '%d' ),
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', 'd')
), $s);
-} \ No newline at end of file
+}
+
diff --git a/include/identity.php b/include/identity.php
index 184e9c308..5880e912e 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -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.
// Only do this if it's the first channel for this account;
// otherwise it could get annoying. Don't make this list too big
diff --git a/mod/photos.php b/mod/photos.php
index 786194cd8..dee027cf9 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -277,9 +277,8 @@ function photos_post(&$a) {
if($p) {
$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($albname),
dbesc($str_contact_allow),
dbesc($str_group_allow),
dbesc($str_contact_deny),
@@ -421,7 +420,7 @@ function photos_post(&$a) {
$_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']) {
notice($r['message'] . EOL);
diff --git a/mod/settings.php b/mod/settings.php
index 9284033e6..f26182dc6 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -400,6 +400,8 @@ function settings_post(&$a) {
$maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0);
$expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0);
$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) : '');
@@ -506,6 +508,8 @@ function settings_post(&$a) {
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','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",
dbesc($username),
@@ -1011,7 +1015,6 @@ function settings_content(&$a) {
'deny_gid' => $channel['channel_deny_gid']
);
-
require_once('include/group.php');
$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'),
'$hint' => t('Please enable expert mode (in <a href="settings/features">Settings > Additional features</a>) to adjust!'),
'$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'),
'$removeme' => t('Remove Channel'),
'$removechannel' => t('Remove this channel.'),
diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl
index eb497bbb5..ab62ede45 100755
--- a/view/tpl/settings.tpl
+++ b/view/tpl/settings.tpl
@@ -23,6 +23,9 @@
{{include file="field_input.tpl" field=$defloc}}
{{include file="field_checkbox.tpl" field=$allowloc}}
{{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" >
<button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
</div>