diff options
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r-- | Zotlabs/Lib/AConfig.php | 4 | ||||
-rw-r--r-- | Zotlabs/Lib/AbConfig.php | 4 | ||||
-rw-r--r-- | Zotlabs/Lib/Apps.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/Config.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/Enotify.php | 92 | ||||
-rw-r--r-- | Zotlabs/Lib/IConfig.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/PConfig.php | 22 | ||||
-rw-r--r-- | Zotlabs/Lib/PermissionDescription.php | 54 | ||||
-rw-r--r-- | Zotlabs/Lib/System.php | 28 | ||||
-rw-r--r-- | Zotlabs/Lib/Techlevels.php | 21 | ||||
-rw-r--r-- | Zotlabs/Lib/ThreadItem.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/ThreadStream.php | 6 | ||||
-rw-r--r-- | Zotlabs/Lib/XConfig.php | 6 |
13 files changed, 196 insertions, 65 deletions
diff --git a/Zotlabs/Lib/AConfig.php b/Zotlabs/Lib/AConfig.php index ab8648a18..4e7c5483f 100644 --- a/Zotlabs/Lib/AConfig.php +++ b/Zotlabs/Lib/AConfig.php @@ -10,8 +10,8 @@ class AConfig { return XConfig::Load('a_' . $account_id); } - static public function Get($account_id,$family,$key) { - return XConfig::Get('a_' . $account_id,$family,$key); + static public function Get($account_id,$family,$key,$default = false) { + return XConfig::Get('a_' . $account_id,$family,$key, $default); } static public function Set($account_id,$family,$key,$value) { diff --git a/Zotlabs/Lib/AbConfig.php b/Zotlabs/Lib/AbConfig.php index cb5d96951..dfc9efc6c 100644 --- a/Zotlabs/Lib/AbConfig.php +++ b/Zotlabs/Lib/AbConfig.php @@ -16,7 +16,7 @@ class AbConfig { } - static public function Get($chan,$xhash,$family,$key) { + static public function Get($chan,$xhash,$family,$key, $default = false) { $r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1", intval($chan), dbesc($xhash), @@ -26,7 +26,7 @@ class AbConfig { if($r) { return ((preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']); } - return false; + return $default; } diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index a646d8a30..ac03e11e1 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -68,7 +68,7 @@ class Apps { if($id !== true) { // if we already installed this app, but it changed, preserve any categories we created $s = ''; - $r = q("select * from term where otype = %d and oid = d", + $r = q("select * from term where otype = %d and oid = %d", intval(TERM_OBJ_APP), intval($id) ); @@ -203,7 +203,7 @@ class Apps { static public function translate_system_apps(&$arr) { $apps = array( 'Site Admin' => t('Site Admin'), - 'Bug Report' => t('Bug Report'), + 'Report Bug' => t('Report Bug'), 'View Bookmarks' => t('View Bookmarks'), 'My Chatrooms' => t('My Chatrooms'), 'Connections' => t('Connections'), @@ -359,7 +359,7 @@ class Apps { if($r) { if(! $r[0]['app_system']) { if($app['categories'] && (! $app['term'])) { - $r[0]['term'] = q("select * from term where otype = %d and oid = d", + $r[0]['term'] = q("select * from term where otype = %d and oid = %d", intval(TERM_OBJ_APP), intval($r[0]['id']) ); diff --git a/Zotlabs/Lib/Config.php b/Zotlabs/Lib/Config.php index d4ee1aeda..5625a3f79 100644 --- a/Zotlabs/Lib/Config.php +++ b/Zotlabs/Lib/Config.php @@ -98,13 +98,13 @@ class Config { * @return mixed Return value or false on error or if not set */ - static public function Get($family,$key) { + static public function Get($family,$key,$default = false) { if((! array_key_exists($family, \App::$config)) || (! array_key_exists('config_loaded', \App::$config[$family]))) self::Load($family); if(array_key_exists('config_loaded', \App::$config[$family])) { if(! array_key_exists($key, \App::$config[$family])) { - return false; + return $default; } return ((! is_array(\App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$family][$key])) ? unserialize(\App::$config[$family][$key]) @@ -112,7 +112,7 @@ class Config { ); } - return false; + return $default; } /** diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 9a8628968..257687567 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -78,15 +78,12 @@ class Enotify { $sender_email = get_config('system','from_email'); if(! $sender_email) $sender_email = 'Administrator' . '@' . \App::get_hostname(); - $sender_name = get_config('system','from_email_name'); if(! $sender_name) $sender_name = \Zotlabs\Lib\System::get_site_name(); - - $additional_mail_header = ""; if(array_key_exists('item', $params)) { @@ -105,6 +102,10 @@ class Enotify { $title = $params['item']['title']; $body = $params['item']['body']; } + if($params['item']['created'] < datetime_convert('UTC','UTC','now - 1 month')) { + logger('notification invoked for an old item which may have been refetched.',LOGGER_DEBUG,LOG_INFO); + return; + } } else { $title = $body = ''; @@ -216,6 +217,85 @@ class Enotify { $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>'); } + if ($params['type'] == NOTIFY_LIKE) { +// logger("notification: params = " . print_r($params, true), LOGGER_DEBUG); + + $itemlink = $params['link']; + + // ignore like/unlike activity on posts - they probably require a separate notification preference + + if (array_key_exists('item',$params) && (! activity_match($params['item']['verb'],ACTIVITY_LIKE))) { + logger('notification: not a like activity. Ignoring.'); + pop_lang(); + return; + } + + $parent_mid = $params['parent_mid']; + + // Check to see if there was already a notify for this post. + // If so don't create a second notification + + $p = null; + $p = q("select id from notify where link = '%s' and uid = %d limit 1", + dbesc($params['link']), + intval($recip['channel_id']) + ); + if ($p) { + logger('notification: like already notified'); + pop_lang(); + return; + } + + + // if it's a post figure out who's post it is. + + $p = null; + + if($params['otype'] === 'item' && $parent_mid) { + $p = q("select * from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($recip['channel_id']) + ); + } + + xchan_query($p); + + + $item_post_type = item_post_type($p[0]); +// $private = $p[0]['item_private']; + $parent_id = $p[0]['id']; + + $parent_item = $p[0]; + + + // "your post" + if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) + $dest_str = sprintf(t('%1$s, %2$s liked [zrl=%3$s]your %4$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $item_post_type); + else { + pop_lang(); + return; + } + + // Some mail softwares relies on subject field for threading. + // So, we cannot have different subjects for notifications of the same thread. + // Before this we have the name of the replier on the subject rendering + // differents subjects for messages on the same thread. + + $subject = sprintf( t('[$Projectname:Notify] Like received to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s liked an item/conversation you created.'), $recip['channel_name'], $sender['xchan_name']); + $epreamble = $dest_str; + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>'); + } + + + if($params['type'] == NOTIFY_WALL) { $subject = sprintf( t('[$Projectname:Notify] %s posted to your profile wall') , $sender['xchan_name']); @@ -364,7 +444,7 @@ class Enotify { do { $dups = false; $hash = random_string(); - $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", + $r = q("SELECT id FROM notify WHERE hash = '%s' LIMIT 1", dbesc($hash)); if ($r) $dups = true; @@ -633,7 +713,7 @@ class Enotify { call_hooks('email_send', $params); if($params['sent']) { - logger("notification: enotify::send (addon) returns " . $params['result'], LOGGER_DEBUG); + logger("notification: enotify::send (addon) returns " . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG); return $params['result']; } @@ -676,7 +756,7 @@ class Enotify { $multipartMessageBody, // message body $messageHeader // message headers ); - logger("notification: enotify::send returns " . $res, LOGGER_DEBUG); + logger("notification: enotify::send returns " . (($res) ? 'success' : 'failure'), LOGGER_DEBUG); return $res; } diff --git a/Zotlabs/Lib/IConfig.php b/Zotlabs/Lib/IConfig.php index 28c9ab58e..33d94bd49 100644 --- a/Zotlabs/Lib/IConfig.php +++ b/Zotlabs/Lib/IConfig.php @@ -10,7 +10,7 @@ class IConfig { return; } - static public function Get(&$item, $family, $key) { + static public function Get(&$item, $family, $key, $default = false) { $is_item = false; @@ -28,7 +28,7 @@ class IConfig { $iid = $item; if(! $iid) - return false; + return $default; if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) { foreach($item['iconfig'] as $c) { @@ -48,7 +48,7 @@ class IConfig { $item['iconfig'][] = $r[0]; return $r[0]['v']; } - return false; + return $default; } diff --git a/Zotlabs/Lib/PConfig.php b/Zotlabs/Lib/PConfig.php index a481667a5..d70697fbc 100644 --- a/Zotlabs/Lib/PConfig.php +++ b/Zotlabs/Lib/PConfig.php @@ -67,16 +67,16 @@ class PConfig { * @return mixed Stored value or false if it does not exist */ - static public function Get($uid,$family,$key,$instore = false) { + static public function Get($uid,$family,$key,$default = false) { if(is_null($uid) || $uid === false) - return false; + return $default; if(! array_key_exists($uid, \App::$config)) self::Load($uid); if((! array_key_exists($family, \App::$config[$uid])) || (! array_key_exists($key, \App::$config[$uid][$family]))) - return false; + return $default; 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]) @@ -185,13 +185,17 @@ class PConfig { $ret = false; - if(array_key_exists($key, \App::$config[$uid][$family])) + if(array_key_exists($uid,\App::$config) + && is_array(\App::$config['uid']) + && array_key_exists($family,\App::$config['uid']) + && array_key_exists($key, \App::$config[$uid][$family])) 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) - ); + + $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s'", + intval($uid), + dbesc($family), + dbesc($key) + ); return $ret; } diff --git a/Zotlabs/Lib/PermissionDescription.php b/Zotlabs/Lib/PermissionDescription.php index b6c6dd29d..51d5f890d 100644 --- a/Zotlabs/Lib/PermissionDescription.php +++ b/Zotlabs/Lib/PermissionDescription.php @@ -12,22 +12,25 @@ require_once("include/text.php"); * permission settings for an item with an empty ACL. * i.e the caption, icon, and tooltip for the no-ACL option in the ACL dialog. */ -class PermissionDescription { +class PermissionDescription { private $global_perm; private $channel_perm; private $fallback_description; - + /** * Constructor is private. - * Use static methods fromGlobalPermission(), fromStandalonePermission(), or fromDescription() - * to create instances. + * Use static methods fromGlobalPermission(), fromStandalonePermission(), + * or fromDescription() to create instances. + * + * @internal + * @param int $global_perm + * @param int $channel_perm + * @param string $description (optional) default empty */ private function __construct($global_perm, $channel_perm, $description = '') { - $this->global_perm = $global_perm; $this->channel_perm = $channel_perm; - $this->fallback_description = ($description == '') ? t('Visible to your default audience') : $description; } @@ -43,23 +46,22 @@ class PermissionDescription { return new PermissionDescription('', 0x80000, $description); } - /** * Use this method only if the interpretation of an empty ACL doesn't fall back to a global * default permission. You should pass one of the constants from boot.php - PERMS_PUBLIC, * PERMS_NETWORK etc. - * + * * @param integer $perm - a single enumerated constant permission - PERMS_PUBLIC, PERMS_NETWORK etc. * @return a new instance of PermissionDescription */ public static function fromStandalonePermission($perm) { $result = new PermissionDescription('', $perm); - - $checkPerm = $this->get_permission_description(); - if ($checkPerm == $this->fallback_description) { + + $checkPerm = $result->get_permission_description(); + if($checkPerm == $result->fallback_description) { $result = null; - logger('null PermissionDescription from unknown standalone permission: ' . $perm ,LOGGER_DEBUG, LOG_ERROR); + logger('null PermissionDescription from unknown standalone permission: ' . $perm, LOGGER_DEBUG, LOG_ERR); } return $result; @@ -67,9 +69,9 @@ class PermissionDescription { /** * This is the preferred way to create a PermissionDescription, as it provides the most details. - * Use this method if you know an empty ACL will result in one of the global default permissions + * Use this method if you know an empty ACL will result in one of the global default permissions * being used, such as channel_r_stream (for which you would pass 'view_stream'). - * + * * @param string $permname - a key for the global perms array from get_perms() in permissions.php, * e.g. 'view_stream', 'view_profile', etc. * @return a new instance of PermissionDescription @@ -80,19 +82,19 @@ class PermissionDescription { $global_perms = \Zotlabs\Access\Permissions::Perms(); - if (array_key_exists($permname, $global_perms)) { + if(array_key_exists($permname, $global_perms)) { - $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'],$permname); + $channelPerm = \Zotlabs\Access\PermissionLimits::Get(\App::$channel['channel_id'], $permname); $result = new PermissionDescription('', $channelPerm); } else { // The acl dialog can handle null arguments, but it shouldn't happen - logger('null PermissionDescription from unknown global permission: ' . $permname ,LOGGER_DEBUG, LOG_ERROR); + logger('null PermissionDescription from unknown global permission: ' . $permname, LOGGER_DEBUG, LOG_ERR); } + return $result; } - /** * Gets a localized description of the permission, or a generic message if the permission * is unknown. @@ -101,8 +103,7 @@ class PermissionDescription { */ public function get_permission_description() { - switch($this->channel_perm) { - + switch($this->channel_perm) { case 0: return t('Only me'); case PERMS_PUBLIC: return t('Public'); case PERMS_NETWORK: return t('Anybody in the $Projectname network'); @@ -117,19 +118,18 @@ class PermissionDescription { /** * Returns an icon css class name if an appropriate one is available, e.g. "fa-globe" for Public, - * otherwise returns empty string. + * otherwise returns empty string. * * @return string icon css class name (often FontAwesome) */ public function get_permission_icon() { - switch($this->channel_perm) { - + switch($this->channel_perm) { case 0:/* only me */ return 'fa-eye-slash'; case PERMS_PUBLIC: return 'fa-globe'; case PERMS_NETWORK: return 'fa-share-alt-square'; // fa-share-alt-square is very similiar to the hubzilla logo, but we should create our own logo class to use - case PERMS_SITE: return 'fa-sitemap'; - case PERMS_CONTACTS: return 'fa-group'; + case PERMS_SITE: return 'fa-sitemap'; + case PERMS_CONTACTS: return 'fa-group'; case PERMS_SPECIFIC: return 'fa-list'; case PERMS_AUTHED: return ''; case PERMS_PENDING: return ''; @@ -137,7 +137,6 @@ class PermissionDescription { } } - /** * Returns a localized description of where the permission came from, if this is known. * If it's not know, or if the permission is standalone and didn't come from a default @@ -147,8 +146,7 @@ class PermissionDescription { */ public function get_permission_origin_description() { - switch($this->global_perm) { - + switch($this->global_perm) { case PERMS_R_STREAM: return t('This is your default setting for the audience of your normal stream, and posts.'); case PERMS_R_PROFILE: return t('This is your default setting for who can view your default channel profile'); case PERMS_R_ABOOK: return t('This is your default setting for who can view your connections'); diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php index 6ccfd664c..306c90f4a 100644 --- a/Zotlabs/Lib/System.php +++ b/Zotlabs/Lib/System.php @@ -32,16 +32,30 @@ class System { static public function get_notify_icon() { if(is_array(\App::$config) && is_array(\App::$config['system']) && \App::$config['system']['email_notify_icon_url']) return \App::$config['system']['email_notify_icon_url']; - return z_root() . '/images/hz-white-32.png'; + return z_root() . DEFAULT_NOTIFY_ICON; } static public function get_site_icon() { if(is_array(\App::$config) && is_array(\App::$config['system']) && \App::$config['system']['site_icon_url']) return \App::$config['system']['site_icon_url']; - return z_root() . '/images/hz-32.png'; + return z_root() . DEFAULT_PLATFORM_ICON ; } + static public function get_project_link() { + if(is_array(\App::$config) && is_array(\App::$config['system']) && \App::$config['system']['project_link']) + return \App::$config['system']['project_link']; + return 'https://hubzilla.org'; + } + + static public function get_project_srclink() { + if(is_array(\App::$config) && is_array(\App::$config['system']) && \App::$config['system']['project_srclink']) + return \App::$config['system']['project_srclink']; + return 'https://github.com/redmatrix/hubzilla'; + } + + + static public function get_server_role() { if(is_array(\App::$config) && is_array(\App::$config['system']) && \App::$config['system']['server_role']) return \App::$config['system']['server_role']; @@ -54,5 +68,15 @@ class System { return '0.0.0'; } + static public function compatible_project($p) { + if(get_directory_realm() != DIRECTORY_REALM) + return true; + + foreach(['hubzilla','zap'] as $t) { + if(stristr($p,$t)) + return true; + } + return false; + } } diff --git a/Zotlabs/Lib/Techlevels.php b/Zotlabs/Lib/Techlevels.php new file mode 100644 index 000000000..6a8c36fb3 --- /dev/null +++ b/Zotlabs/Lib/Techlevels.php @@ -0,0 +1,21 @@ +<?php + +namespace Zotlabs\Lib; + + +class Techlevels { + + static public function levels() { + $techlevels = [ + '0' => t('Beginner/Basic'), + '1' => t('Novice - not skilled but willing to learn'), + '2' => t('Intermediate - somewhat comfortable'), + '3' => t('Advanced - very comfortable'), + '4' => t('Expert - I can write computer code'), + '5' => t('Wizard - I probably know more than you do') + ]; + return $techlevels; + } + +} + diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index a3e871810..a1666e148 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -44,7 +44,7 @@ class ThreadItem { * Only add those that will be displayed */ - if((! visible_activity($item)) || array_key_exists('author_blocked',$item)) { + if((! visible_activity($item)) || array_key_exists('blocked',$item)) { continue; } @@ -355,6 +355,10 @@ class ThreadItem { 'unverified' => $unverified, 'forged' => $forged, 'location' => $location, + 'attend_label' => t('Attend'), + 'attend_title' => t('Attendance Options'), + 'vote_label' => t('Vote'), + 'vote_title' => t('Voting Options'), 'indent' => $indent, 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php index a6d4f8517..beb626f31 100644 --- a/Zotlabs/Lib/ThreadStream.php +++ b/Zotlabs/Lib/ThreadStream.php @@ -58,7 +58,7 @@ class ThreadStream { case 'display': // in this mode we set profile_owner after initialisation (from conversation()) and then // pull some trickery which allows us to re-invoke this function afterward - // it's an ugly hack so FIXME + // it's an ugly hack so @FIXME $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments'); break; case 'page': @@ -160,9 +160,9 @@ class ThreadStream { } elseif(($this->observer) && (! $item->is_commentable())) { if((array_key_exists('owner',$item->data)) && intval($item->data['owner']['abook_self'])) - $item->set_commentable(perm_is_allowed($this->profile_owner,$this->observer['xchan_hash'],'post_comments')); + $item->set_commentable(perm_is_allowed($this->profile_owner,$ob_hash,'post_comments')); else - $item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data)); + $item->set_commentable(can_comment_on_post($ob_hash,$item->data)); } } require_once('include/channel.php'); diff --git a/Zotlabs/Lib/XConfig.php b/Zotlabs/Lib/XConfig.php index 7f3d0f2cd..bf78c360f 100644 --- a/Zotlabs/Lib/XConfig.php +++ b/Zotlabs/Lib/XConfig.php @@ -59,16 +59,16 @@ class XConfig { * @return mixed Stored $value or false if it does not exist */ - static public function Get($xchan, $family, $key) { + static public function Get($xchan, $family, $key, $default = false) { if(! $xchan) - return false; + return $default; if(! array_key_exists($xchan, \App::$config)) load_xconfig($xchan); if((! array_key_exists($family, \App::$config[$xchan])) || (! array_key_exists($key, \App::$config[$xchan][$family]))) - return false; + return $default; return ((! is_array(\App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$xchan][$family][$key])) ? unserialize(\App::$config[$xchan][$family][$key]) |