diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-06-07 20:43:49 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-06-07 20:43:49 -0400 |
commit | cf180f614207e6cdae44d1e3649a469b8982ade0 (patch) | |
tree | e2ffae5bbc7f12577dce0a0b9a7a638df142dd18 /include | |
parent | 2af8105b460d300ba41928734c960f5f70613952 (diff) | |
parent | 67665a8b9d8ff1dbcc26a46837447544d8968784 (diff) | |
download | volse-hubzilla-cf180f614207e6cdae44d1e3649a469b8982ade0.tar.gz volse-hubzilla-cf180f614207e6cdae44d1e3649a469b8982ade0.tar.bz2 volse-hubzilla-cf180f614207e6cdae44d1e3649a469b8982ade0.zip |
Merge remote-tracking branch 'upstream/dev' into wiki
Diffstat (limited to 'include')
-rw-r--r-- | include/config.php | 180 | ||||
-rw-r--r-- | include/photos.php | 28 | ||||
-rw-r--r-- | include/widgets.php | 6 |
3 files changed, 23 insertions, 191 deletions
diff --git a/include/config.php b/include/config.php index fe7cbead6..d0ae4af39 100644 --- a/include/config.php +++ b/include/config.php @@ -60,201 +60,33 @@ function del_config($family, $key) { } - - - -/** - * @brief Loads all configuration values of a channel into a cached storage. - * - * All configuration values of the given channel are stored in global cache - * which is available under the global variable App::$config[$uid]. - * - * @param string $uid - * The channel_id - * @return void|false Nothing or false if $uid is false - */ - function load_pconfig($uid) { - if($uid === false) - return false; - - if(! array_key_exists($uid, App::$config)) - App::$config[$uid] = array(); + Zlib\PConfig::Load($uid); - $r = q("SELECT * FROM pconfig WHERE uid = %d", - intval($uid) - ); - - if($r) { - foreach($r as $rr) { - $k = $rr['k']; - $c = $rr['cat']; - if(! array_key_exists($c, App::$config[$uid])) { - App::$config[$uid][$c] = array(); - App::$config[$uid][$c]['config_loaded'] = true; - } - App::$config[$uid][$c][$k] = $rr['v']; - } - } } -/** - * @brief Get a particular channel's config variable given the category name - * ($family) and a key. - * - * Get a particular channel's config value from the given category ($family) - * and the $key from a cached storage in App::$config[$uid]. - * - * Returns false if not set. - * - * @param string $uid - * The channel_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to query - * @param boolean $instore (deprecated, without function) - * @return mixed Stored value or false if it does not exist - */ function get_pconfig($uid, $family, $key, $instore = false) { -// logger('include/config.php: get_pconfig() deprecated instore param used', LOGGER_DEBUG); - - if($uid === false) - return false; - if(! array_key_exists($uid, App::$config)) - load_pconfig($uid); + return Zlib\PConfig::Get($uid,$family,$key,$instore = false); - if((! array_key_exists($family, App::$config[$uid])) || (! array_key_exists($key, App::$config[$uid][$family]))) - return false; - - return ((! is_array(App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', App::$config[$uid][$family][$key])) - ? unserialize(App::$config[$uid][$family][$key]) - : App::$config[$uid][$family][$key] - ); } -/** - * @brief Sets a configuration value for a channel. - * - * Stores a config value ($value) in the category ($family) under the key ($key) - * for the channel_id $uid. - * - * @note Please do not store booleans - convert to 0/1 integer values! - * - * @param string $uid - * The channel_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to set - * @param string $value - * The value to store - * @return mixed Stored $value or false - */ -function set_pconfig($uid, $family, $key, $value) { - - // this catches subtle errors where this function has been called - // with local_channel() when not logged in (which returns false) - // and throws an error in array_key_exists below. - // we provide a function backtrace in the logs so that we can find - // and fix the calling function. - - if($uid === false) { - btlogger('UID is FALSE!', LOGGER_NORMAL, LOG_ERR); - return; - } - - // manage array value - $dbvalue = ((is_array($value)) ? serialize($value) : $value); - $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); - if(get_pconfig($uid, $family, $key) === false) { - if(! array_key_exists($uid, App::$config)) - App::$config[$uid] = array(); - if(! array_key_exists($family, App::$config[$uid])) - App::$config[$uid][$family] = array(); - - // keep a separate copy for all variables which were - // set in the life of this page. We need this to - // synchronise channel clones. - - if(! array_key_exists('transient', App::$config[$uid])) - App::$config[$uid]['transient'] = array(); - if(! array_key_exists($family, App::$config[$uid]['transient'])) - App::$config[$uid]['transient'][$family] = array(); - - App::$config[$uid][$family][$key] = $value; - App::$config[$uid]['transient'][$family][$key] = $value; - - $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ", - intval($uid), - dbesc($family), - dbesc($key), - dbesc($dbvalue) - ); - if($ret) - return $value; - - return $ret; - } - - $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s'", - dbesc($dbvalue), - intval($uid), - dbesc($family), - dbesc($key) - ); - - // keep a separate copy for all variables which were - // set in the life of this page. We need this to - // synchronise channel clones. - - if(! array_key_exists('transient', App::$config[$uid])) - App::$config[$uid]['transient'] = array(); - if(! array_key_exists($family, App::$config[$uid]['transient'])) - App::$config[$uid]['transient'][$family] = array(); - - App::$config[$uid][$family][$key] = $value; - App::$config[$uid]['transient'][$family][$key] = $value; +function set_pconfig($uid, $family, $key, $value) { - if($ret) - return $value; + return Zlib\PConfig::Set($uid,$family,$key,$value); - return $ret; } -/** - * @brief Deletes the given key from the channel's configuration. - * - * Removes the configured value from the stored cache in App::$config[$uid] - * and removes it from the database. - * - * @param string $uid - * The channel_id - * @param string $family - * The category of the configuration value - * @param string $key - * The configuration key to delete - * @return mixed - */ function del_pconfig($uid, $family, $key) { - $ret = false; - - if (x(App::$config[$uid][$family], $key)) - unset(App::$config[$uid][$family][$key]); - $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'", - intval($uid), - dbesc($family), - dbesc($key) - ); + return Zlib\PConfig::Delete($uid,$family,$key); - return $ret; } + /** * @brief Loads a full xchan's configuration into a cached storage. * diff --git a/include/photos.php b/include/photos.php index 1cc64f6fa..c64d662ea 100644 --- a/include/photos.php +++ b/include/photos.php @@ -443,7 +443,7 @@ function photo_upload($channel, $observer, $args) { * * success (bool) * * albums (array) */ -function photos_albums_list($channel, $observer) { +function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') { $channel_id = $channel['channel_id']; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); @@ -451,11 +451,15 @@ function photos_albums_list($channel, $observer) { if(! perm_is_allowed($channel_id, $observer_xchan, 'view_storage')) return false; - /** @FIXME create a permissions SQL which works on arbitrary observers and channels, regardless of login or web status */ - $sql_extra = permissions_sql($channel_id); + $sql_extra = permissions_sql($channel_id,$observer_xchan); + + $sort_key = dbesc($sort_key); + $direction = dbesc($direction); + + - $albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by max(created) desc", + $albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by $sort_key $direction", intval($channel_id), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE) @@ -483,20 +487,14 @@ function photos_albums_list($channel, $observer) { return $ret; } -function photos_album_widget($channelx,$observer,$albums = null) { +function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = 'asc') { $o = ''; - // If we weren't passed an album list, see if the photos module - // dropped one for us to find in App::$data['albums']. - // If all else fails, load it. - - if(! $albums) { - if(array_key_exists('albums', App::$data)) - $albums = App::$data['albums']; - else - $albums = photos_albums_list($channelx,$observer); - } + if(array_key_exists('albums', App::$data)) + $albums = App::$data['albums']; + else + $albums = photos_albums_list($channelx,$observer,$sortkey,$direction); if($albums['success']) { $o = replace_macros(get_markup_template('photo_albums.tpl'),array( diff --git a/include/widgets.php b/include/widgets.php index 5237b1a30..3ca189af0 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -799,8 +799,10 @@ function widget_photo_albums($arr) { if((! $channelx) || (! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_storage'))) return ''; require_once('include/photos.php'); + $sortkey = ((array_key_exists('sortkey',$arr)) ? $arr['sortkey'] : 'album'); + $direction = ((array_key_exists('direction',$arr)) ? $arr['direction'] : 'asc'); - return photos_album_widget($channelx, App::get_observer()); + return photos_album_widget($channelx, App::get_observer(),$sortkey,$direction); } @@ -1450,7 +1452,7 @@ function widget_admin($arr) { $aside = array( 'site' => array(z_root() . '/admin/site/', t('Site'), 'site'), - 'users' => array(z_root() . '/admin/users/', t('Accounts'), 'users', 'pending-update', t('Member registrations waiting for confirmation')), + 'accounts' => array(z_root() . '/admin/accounts/', t('Accounts'), 'accounts', 'pending-update', t('Member registrations waiting for confirmation')), 'channels' => array(z_root() . '/admin/channels/', t('Channels'), 'channels'), 'security' => array(z_root() . '/admin/security/', t('Security'), 'security'), 'features' => array(z_root() . '/admin/features/', t('Features'), 'features'), |