diff options
author | Christian Vogeley <christian.vogeley@hotmail.de> | 2014-03-09 04:15:11 +0100 |
---|---|---|
committer | Christian Vogeley <christian.vogeley@hotmail.de> | 2014-03-09 04:15:11 +0100 |
commit | 76ab9403af3b562531a7eb0831e5a7ecc9aedb38 (patch) | |
tree | c4d74f0cc8aac0fcd5a52520170a64c8d4b01395 /include | |
parent | e8e980c8175be6dae7d642d9707493c465b7137b (diff) | |
parent | 80e381176e1e301782bc56cbb7c6037825eddf2d (diff) | |
download | volse-hubzilla-76ab9403af3b562531a7eb0831e5a7ecc9aedb38.tar.gz volse-hubzilla-76ab9403af3b562531a7eb0831e5a7ecc9aedb38.tar.bz2 volse-hubzilla-76ab9403af3b562531a7eb0831e5a7ecc9aedb38.zip |
merge
Diffstat (limited to 'include')
-rw-r--r-- | include/api.php | 48 | ||||
-rw-r--r-- | include/auth.php | 21 | ||||
-rw-r--r-- | include/bookmarks.php | 50 | ||||
-rw-r--r-- | include/comanche.php | 77 | ||||
-rw-r--r-- | include/contact_widgets.php | 5 | ||||
-rw-r--r-- | include/dir_fns.php | 3 | ||||
-rw-r--r-- | include/enotify.php | 6 | ||||
-rw-r--r-- | include/identity.php | 59 | ||||
-rwxr-xr-x | include/items.php | 56 | ||||
-rw-r--r-- | include/js_strings.php | 28 | ||||
-rw-r--r-- | include/menu.php | 3 | ||||
-rw-r--r-- | include/message.php | 2 | ||||
-rw-r--r-- | include/nav.php | 38 | ||||
-rwxr-xr-x | include/oembed.php | 11 | ||||
-rw-r--r-- | include/onepoll.php | 7 | ||||
-rw-r--r-- | include/poller.php | 18 | ||||
-rw-r--r-- | include/reddav.php | 2 | ||||
-rw-r--r-- | include/security.php | 7 | ||||
-rw-r--r-- | include/socgraph.php | 29 | ||||
-rwxr-xr-x | include/text.php | 12 | ||||
-rw-r--r-- | include/widgets.php | 117 | ||||
-rw-r--r-- | include/zot.php | 48 |
22 files changed, 497 insertions, 150 deletions
diff --git a/include/api.php b/include/api.php index dc270167b..47c78113a 100644 --- a/include/api.php +++ b/include/api.php @@ -533,6 +533,12 @@ require_once('include/items.php'); api_register_func('api/red/channel/export/basic','api_export_basic', true); + + + + + + function api_channel_stream(&$a, $type) { if(api_user() === false) { logger('api_channel_stream: no user'); @@ -691,6 +697,48 @@ require_once('include/items.php'); api_register_func('api/statuses/update','api_statuses_update', true); + function red_item_new(&$a, $type) { + + if (api_user() === false) { + logger('api_statuses_update: no user'); + return false; + } + + logger('api_statuses_update: REQUEST ' . print_r($_REQUEST,true)); + logger('api_statuses_update: FILES ' . print_r($_FILES,true)); + + + // set this so that the item_post() function is quiet and doesn't redirect or emit json + + $_REQUEST['api_source'] = true; + $_REQUEST['profile_uid'] = api_user(); + + if(x($_FILES,'media')) { + $_FILES['userfile'] = $_FILES['media']; + // upload the image if we have one + $_REQUEST['silent']='1'; //tell wall_upload function to return img info instead of echo + require_once('mod/wall_upload.php'); + $media = wall_upload_post($a); + if(strlen($media)>0) + $_REQUEST['body'] .= "\n\n".$media; + } + + require_once('mod/item.php'); + $x = item_post($a); + json_return_and_die($x); + } + + api_register_func('api/red/item/new','red_item_new', true); + + + + + + + + + + function api_status_show(&$a, $type){ $user_info = api_get_user($a); diff --git a/include/auth.php b/include/auth.php index a3b028c73..c21705c99 100644 --- a/include/auth.php +++ b/include/auth.php @@ -58,14 +58,17 @@ function account_verify_password($email,$pass) { } -// login/logout - +/** + * Inline - not a function + * look for auth parameters or re-validate an existing session + * also handles logout + */ +if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) { - -if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) { + // process a logout request if(((x($_POST,'auth-params')) && ($_POST['auth-params'] === 'logout')) || ($a->module === 'logout')) { @@ -77,6 +80,8 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p goaway(z_root()); } + // re-validate a visitor, optionally invoke "su" if permitted to do so + if(x($_SESSION,'visitor_id') && (! x($_SESSION,'uid'))) { // if our authenticated guest is allowed to take control of the admin channel, make it so. $admins = get_config('system','remote_admin'); @@ -106,9 +111,11 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); } + // already logged in user returning + if(x($_SESSION,'uid') || x($_SESSION,'account_id')) { - // already logged in user returning + // first check if we're enforcing that sessions can't change IP address $check = get_config('system','paranoia'); // extra paranoia - if the IP changed, log them out @@ -150,6 +157,8 @@ else { nuke_session(); } + // handle a fresh login request + if((x($_POST,'password')) && strlen($_POST['password'])) $encrypted = hash('whirlpool',trim($_POST['password'])); @@ -188,7 +197,7 @@ else { notice( t('Failed authentication') . EOL); } - logger('authenticate: ' . print_r(get_app()->account,true)); + logger('authenticate: ' . print_r(get_app()->account,true), LOGGER_DEBUG); } diff --git a/include/bookmarks.php b/include/bookmarks.php index 99cb60e64..21a775f9a 100644 --- a/include/bookmarks.php +++ b/include/bookmarks.php @@ -2,7 +2,17 @@ require_once('include/menu.php'); -function bookmark_add($channel,$sender,$taxonomy,$private) { +function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) { + + $menu_id = 0; + $menu_name = ''; + $ischat = false; + + if(is_array($opts)) { + $menu_id = ((x($opts,'menu_id')) ? intval($opt['menu_id']) : 0); + $menu_name = ((x($opts,'menu_name')) ? escape_tags($opts['menu_name']) : ''); + $ischat = ((x($opts,'ischat')) ? intval($opts['ischat']) : 0); + } $iarr = array(); $channel_id = $channel['channel_id']; @@ -11,7 +21,7 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { $iarr['contact_allow'] = array($channel['channel_hash']); $iarr['mitem_link'] = $taxonomy['url']; $iarr['mitem_desc'] = $taxonomy['term']; - $iarr['mitem_flags'] = 0; + $iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0); $m = @parse_url($taxonomy['url']); $zrl = false; @@ -27,16 +37,24 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { $iarr['mitem_flags'] |= MENU_ITEM_ZID; $arr = array(); - $arr['menu_name'] = substr($sender['xchan_hash'],0,16) . ' ' . $sender['xchan_name']; - $arr['menu_desc'] = sprintf( t('%1$s\'s bookmarks'), $sender['xchan_name']); + if(! $menu_name) { + $arr['menu_name'] = substr($sender['xchan_hash'],0,16) . ' ' . $sender['xchan_name']; + $arr['menu_desc'] = sprintf( t('%1$s\'s bookmarks'), $sender['xchan_name']); + } + else { + $arr['menu_name'] = $arr['menu_desc'] = $menu_name; + } $arr['menu_flags'] = (($sender['xchan_hash'] === $channel['channel_hash']) ? MENU_BOOKMARK : MENU_SYSTEM|MENU_BOOKMARK); $arr['menu_channel_id'] = $channel_id; - $x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']); - if($x) - $menu_id = $x[0]['menu_id']; - else - $menu_id = menu_create($arr); + if(! $menu_id) { + $x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']); + if($x) + $menu_id = $x[0]['menu_id']; + else + $menu_id = menu_create($arr); + } + if(! $menu_id) { logger('bookmark_add: unable to create menu ' . $arr['menu_name']); return; @@ -51,5 +69,17 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { logger('add_bookmark: duplicate menu entry', LOGGER_DEBUG); if(! $r) $r = menu_add_item($menu_id,$channel_id,$iarr); + return $r; -}
\ No newline at end of file +} + +function get_bookmark_link($observer) { + + if((! $observer) || ($observer['xchan_network'] !== 'zot')) + return ''; + + $h = @parse_url($observer['xchan_url']); + if($h) + return $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '') . '/rbmark?f='; + return ''; +} diff --git a/include/comanche.php b/include/comanche.php index 7d7e0e70c..13146ded4 100644 --- a/include/comanche.php +++ b/include/comanche.php @@ -57,6 +57,23 @@ function comanche_parser(&$a,$s) { if($cnt) $a->page['template'] = trim($matches[1]); + $cnt = preg_match("/\[template=(.*?)\](.*?)\[\/template\]/ism", $s, $matches); + if($cnt) { + $a->page['template'] = trim($matches[2]); + $a->page['template_style'] = trim($matches[2]) . '_' . $matches[1]; + } + + $cnt = preg_match("/\[template\](.*?)\[\/template\]/ism", $s, $matches); + if($cnt) { + $a->page['template'] = trim($matches[1]); + } + + $cnt = preg_match("/\[theme=(.*?)\](.*?)\[\/theme\]/ism", $s, $matches); + if($cnt) { + $a->layout['schema'] = trim($matches[1]); + $a->layout['theme'] = trim($matches[2]); + } + $cnt = preg_match("/\[theme\](.*?)\[\/theme\]/ism", $s, $matches); if($cnt) $a->layout['theme'] = trim($matches[1]); @@ -79,10 +96,12 @@ function comanche_parser(&$a,$s) { } -function comanche_menu($name) { - $a = get_app(); - $m = menu_fetch($name,$a->profile['profile_uid'],get_observer_hash()); - return menu_render($m); +function comanche_menu($name,$class = '') { + $channel_id = comanche_get_channel_id(); + if($channel_id) { + $m = menu_fetch($name,$channel_id,get_observer_hash()); + return menu_render($m,$class); + } } function comanche_replace_region($match) { @@ -92,20 +111,37 @@ function comanche_replace_region($match) { } } +/** + * @function comanche_get_channel_id() + * Returns the channel_id of the profile owner of the page, or the local_user if there is no profile owner. + * Otherwise returns 0 + */ + +function comanche_get_channel_id() { + $channel_id = ((is_array(get_app()->profile)) ? get_app()->profile['profile_uid'] : 0); + if((! $channel_id) && (local_user())) + $channel_id = local_user(); + return $channel_id; +} + function comanche_block($name) { + + $channel_id = comanche_get_channel_id(); - $o = ''; - $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1", - intval(get_app()->profile['profile_uid']), - dbesc($name) - ); - if($r) { - $o = '<div class="widget bblock">'; - if($r[0]['title']) - $o .= '<h3>' . $r[0]['title'] . '</h3>'; - $o .= prepare_text($r[0]['body'],$r[0]['mimetype']); - $o .= '</div>'; + if($channel_id) { + $o = ''; + $r = q("select * from item inner join item_id on iid = item.id and item_id.uid = item.uid and item.uid = %d and service = 'BUILDBLOCK' and sid = '%s' limit 1", + intval($channel_id), + dbesc($name) + ); + if($r) { + $o = '<div class="widget bblock">'; + if($r[0]['title']) + $o .= '<h3>' . $r[0]['title'] . '</h3>'; + $o .= prepare_text($r[0]['body'],$r[0]['mimetype']); + $o .= '</div>'; + } } return $o; } @@ -152,13 +188,22 @@ function comanche_widget($name,$text) { function comanche_region(&$a,$s) { - $cnt = preg_match_all("/\[menu\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { $s = str_replace($mtch[0],comanche_menu(trim($mtch[1])),$s); } } + + // menu class e.g. [menu=horizontal]my_menu[/menu] or [menu=tabbed]my_menu[/menu] + // allows different menu renderings to be applied + + $cnt = preg_match_all("/\[menu=(.*?)\](.*?)\[\/menu\]/ism", $s, $matches, PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $s = str_replace($mtch[0],comanche_menu(trim($mtch[2]),$mtch[1]),$s); + } + } $cnt = preg_match_all("/\[block\](.*?)\[\/block\]/ism", $s, $matches, PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 482bbed78..758b7291b 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -15,6 +15,8 @@ function findpeople_widget() { . '</div>' . $inv; } } + + $advanced_search = ((local_user() && get_pconfig(local_user(),'feature','expert')) ? t('Advanced') : false); return replace_macros(get_markup_template('peoplefind.tpl'),array( '$findpeople' => t('Find Channels'), @@ -26,6 +28,9 @@ function findpeople_widget() { '$similar' => '', // FIXME and uncomment when mod/match working // t('Similar Interests'), '$random' => t('Random Profile'), '$inv' => t('Invite Friends'), + '$advanced_search' => $advanced_search, + '$advanced_hint' => t('Exammple: name=fred and country=iceland'), + '$find_advanced' => t('Advanced Find'), '$loggedin' => local_user() )); diff --git a/include/dir_fns.php b/include/dir_fns.php index c2e614831..aeee8492f 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -101,6 +101,9 @@ function sync_directories($dirmode) { $ud_flags = 0; if(is_array($t['flags']) && in_array('deleted',$t['flags'])) $ud_flags |= UPDATE_FLAGS_DELETED; + if(is_array($t['flags']) && in_array('forced',$t['flags'])) + $ud_flags |= UPDATE_FLAGS_FORCED; + $z = q("insert into updates ( ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' ) ", dbesc($t['hash']), diff --git a/include/enotify.php b/include/enotify.php index e0991257f..036d5275e 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -384,6 +384,12 @@ function notification($params) { $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id; $msg = str_replace('$itemlink',$itemlink,$epreamble); + + // wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation + + if(($a->language === 'en' || (! $a->language)) && strpos($msg,', ')) + $msg = substr($msg,strpos($msg,', ')+1); + $r = q("update notify set msg = '%s' where id = %d and uid = %d limit 1", dbesc($msg), intval($notify_id), diff --git a/include/identity.php b/include/identity.php index 82fc5fbea..ed6920e67 100644 --- a/include/identity.php +++ b/include/identity.php @@ -486,12 +486,12 @@ function profile_load(&$a, $nickname, $profile = '') { // get the current observer $observer = $a->get_observer(); + $can_view_profile = true; + // Can the observer see our profile? require_once('include/permissions.php'); if(! perm_is_allowed($user[0]['channel_id'],$observer['xchan_hash'],'view_profile')) { - // permission denied - notice( t(' Sorry, you don\'t have the permission to view this profile. ') . EOL); - return; + $can_view_profile = false; } if(! $profile) { @@ -502,10 +502,10 @@ function profile_load(&$a, $nickname, $profile = '') { if($r) $profile = $r[0]['abook_profile']; } - $r = null; + $p = null; if($profile) { - $r = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile + $p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile LEFT JOIN channel ON profile.uid = channel.channel_id WHERE channel.channel_address = '%s' AND profile.profile_guid = '%s' LIMIT 1", dbesc($nickname), @@ -513,8 +513,8 @@ function profile_load(&$a, $nickname, $profile = '') { ); } - if(! $r) { - $r = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile + if(! $p) { + $p = q("SELECT profile.uid AS profile_uid, profile.*, channel.* FROM profile LEFT JOIN channel ON profile.uid = channel.channel_id WHERE channel.channel_address = '%s' and not ( channel_pageflags & %d ) AND profile.is_default = 1 LIMIT 1", @@ -523,7 +523,7 @@ function profile_load(&$a, $nickname, $profile = '') { ); } - if(! $r) { + if(! $p) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -532,37 +532,42 @@ function profile_load(&$a, $nickname, $profile = '') { // fetch user tags if this isn't the default profile - if(! $r[0]['is_default']) { + if(! $p[0]['is_default']) { $x = q("select `keywords` from `profile` where uid = %d and `is_default` = 1 limit 1", intval($profile_uid) ); - if($x) - $r[0]['keywords'] = $x[0]['keywords']; + if($x && $can_view_profile) + $p[0]['keywords'] = $x[0]['keywords']; } - if($r[0]['keywords']) { - $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$r[0]['keywords']); - if(strlen($keywords)) + if($p[0]['keywords']) { + $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$p[0]['keywords']); + if(strlen($keywords) && $can_view_profile) $a->page['htmlhead'] .= '<meta name="keywords" content="' . htmlentities($keywords,ENT_COMPAT,'UTF-8') . '" />' . "\r\n" ; } - $a->profile = $r[0]; - $online = get_online_status($nickname); - $a->profile['online_status'] = $online['result']; + if($can_view_profile) { + $a->profile = $p[0]; + $online = get_online_status($nickname); + $a->profile['online_status'] = $online['result']; - $a->profile_uid = $r[0]['profile_uid']; + $a->profile_uid = $p[0]['profile_uid']; - $a->page['title'] = $a->profile['channel_name'] . " - " . $a->profile['channel_address'] . "@" . $a->get_hostname(); + $a->page['title'] = $a->profile['channel_name'] . " - " . $a->profile['channel_address'] . "@" . $a->get_hostname(); + } - $a->profile['channel_mobile_theme'] = get_pconfig(local_user(),'system', 'mobile_theme'); - $_SESSION['theme'] = $a->profile['channel_theme']; - $_SESSION['mobile_theme'] = $a->profile['channel_mobile_theme']; + if(local_user()) { + $a->profile['channel_mobile_theme'] = get_pconfig(local_user(),'system', 'mobile_theme'); + $_SESSION['mobile_theme'] = $a->profile['channel_mobile_theme']; + } /** * load/reload current theme info */ + $_SESSION['theme'] = $p[0]['channel_theme']; + $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one $theme_info_file = "view/theme/".current_theme()."/php/theme.php"; @@ -570,6 +575,12 @@ function profile_load(&$a, $nickname, $profile = '') { require_once($theme_info_file); } + if(! $can_view_profile) { + // permission denied + notice( t(' Sorry, you don\'t have the permission to view this profile. ') . EOL); + return; + } + return; } @@ -1101,8 +1112,6 @@ function get_theme_uid() { if(local_user()) { if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) return local_user(); - if(! $uid) - return local_user(); } if(! $uid) { $x = get_sys_channel(); @@ -1214,4 +1223,4 @@ function get_channel_by_nick($nick) { ); return(($r) ? $r[0] : false); -}
\ No newline at end of file +} diff --git a/include/items.php b/include/items.php index 1217616d7..70e098415 100755 --- a/include/items.php +++ b/include/items.php @@ -753,7 +753,7 @@ function import_author_rss($x) { values ( '%s', '%s', '%s', '%s' )", dbesc($x['url']), dbesc($x['url']), - dbesc(($name) ? $name : t('Unknown')), + dbesc(($name) ? $name : t('(Unknown)')), dbesc('rss') ); if($r) { @@ -1548,7 +1548,7 @@ function item_store($arr,$allow_exec = false) { $allow_exec = $d['allow_exec']; - $ret = array('result' => false, 'item_id' => 0); + $ret = array('success' => false, 'item_id' => 0); if(! $arr['uid']) { logger('item_store: no uid'); @@ -1933,7 +1933,7 @@ function item_store_update($arr,$allow_exec = false) { - $ret = array('result' => false, 'item_id' => 0); + $ret = array('success' => false, 'item_id' => 0); if(! intval($arr['uid'])) { logger('item_store_update: no uid'); $ret['message'] = 'no uid.'; @@ -3409,8 +3409,11 @@ function item_expire($uid,$days) { // $expire_network_only = save your own wall posts // and just expire conversations started by others + // do not enable this until we can pass bulk delete messages through zot + // $expire_network_only = get_pconfig($uid,'expire','network_only'); + + $expire_network_only = 1; - $expire_network_only = get_pconfig($uid,'expire','network_only'); $sql_extra = ((intval($expire_network_only)) ? " AND not (item_flags & " . intval(ITEM_WALL) . ") " : ""); $r = q("SELECT * FROM `item` @@ -3418,14 +3421,11 @@ function item_expire($uid,$days) { AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `id` = `parent` $sql_extra - AND NOT (item_restrict & %d ) - AND NOT (item_restrict & %d ) - AND NOT (item_restrict & %d ) ", + AND NOT ( item_flags & %d ) + AND (item_restrict = 0 ) ", intval($uid), intval($days), - intval(ITEM_DELETED), - intval(ITEM_WEBPAGE), - intval(ITEM_BUILDBLOCK) + intval(ITEM_RETAINED) ); if(! $r) @@ -3433,44 +3433,40 @@ function item_expire($uid,$days) { $r = fetch_post_tags($r,true); - $expire_items = get_pconfig($uid, 'expire','items'); - $expire_items = (($expire_items===false)?1:intval($expire_items)); // default if not set: 1 - - $expire_notes = get_pconfig($uid, 'expire','notes'); - $expire_notes = (($expire_notes===false)?1:intval($expire_notes)); // default if not set: 1 - - $expire_starred = get_pconfig($uid, 'expire','starred'); - $expire_starred = (($expire_starred===false)?1:intval($expire_starred)); // default if not set: 1 - - $expire_photos = get_pconfig($uid, 'expire','photos'); - $expire_photos = (($expire_photos===false)?0:intval($expire_photos)); // default if not set: 0 - - logger('expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos"); - foreach($r as $item) { - - // don't expire filed items $terms = get_terms_oftype($item['term'],TERM_FILE); - if($terms) + if($terms) { + retain_item($item['id']); continue; + } // Only expire posts, not photos and photo comments - if($expire_photos==0 && ($item['resource_type'] === 'photo')) + if($item['resource_type'] === 'photo') { + retain_item($item['id']); continue; - if($expire_starred==0 && ($item['item_flags'] & ITEM_STARRED)) + } + if($item['item_flags'] & ITEM_STARRED) { + retain_item($item['id']); continue; + } drop_item($item['id'],false); } - proc_run('php',"include/notifier.php","expire","$uid"); +// proc_run('php',"include/notifier.php","expire","$uid"); } +function retain_item($id) { + $r = q("update item set item_flags = (item_flags | %d ) where id = %d limit 1", + intval(ITEM_RETAINED), + intval($id) + ); +} function drop_items($items) { $uid = 0; diff --git a/include/js_strings.php b/include/js_strings.php index afa8f075a..fef84077e 100644 --- a/include/js_strings.php +++ b/include/js_strings.php @@ -2,18 +2,21 @@ function js_strings() { return replace_macros(get_markup_template('js_strings.tpl'), array( - '$delitem' => t('Delete this item?'), - '$comment' => t('Comment'), - '$showmore' => t('show more'), - '$showfewer' => t('show fewer'), - '$pwshort' => t("Password too short"), - '$pwnomatch' => t("Passwords do not match"), - '$everybody' => t('everybody'), - '$passphrase' => t('Secret Passphrase'), - '$passhint' => t('Passphrase hint'), + '$delitem' => t('Delete this item?'), + '$comment' => t('Comment'), + '$showmore' => t('show more'), + '$showfewer' => t('show fewer'), + '$divgrowmore' => t('+ Show More'), + '$divgrowless' => t('- Show Less'), + '$pwshort' => t("Password too short"), + '$pwnomatch' => t("Passwords do not match"), + '$everybody' => t('everybody'), + '$passphrase' => t('Secret Passphrase'), + '$passhint' => t('Passphrase hint'), + '$permschange' => t('Notice: Permissions have changed but have not yet been submitted.'), - '$t01' => ((t('timeago.prefixAgo') != 'timeago.prefixAgo') ? t('timeago.prefixAgo') : 'null'), - '$t02' => ((t('timeago.suffixAgo') != 'timeago.suffixAgo') ? t('timeago.suffixAgo') : 'null'), + '$t01' => ((t('timeago.prefixAgo') != 'timeago.prefixAgo') ? t('timeago.prefixAgo') : ''), + '$t02' => ((t('timeago.prefixFromNow') != 'timeago.prefixFromNow') ? t('timeago.prefixFromNow') : ''), '$t03' => t('ago'), '$t04' => t('from now'), '$t05' => t('less than a minute'), @@ -30,6 +33,5 @@ function js_strings() { '$t16' => t(' '), // wordSeparator '$t17' => ((t('timeago.numbers') != 'timeago.numbers') ? t('timeago.numbers') : '[]') - )); -}
\ No newline at end of file +} diff --git a/include/menu.php b/include/menu.php index 2f1719d0b..4b0a11f10 100644 --- a/include/menu.php +++ b/include/menu.php @@ -24,7 +24,7 @@ function menu_fetch($name,$uid,$observer_xchan) { return null; } -function menu_render($menu, $edit = false) { +function menu_render($menu, $class='', $edit = false) { if(! $menu) return ''; @@ -38,6 +38,7 @@ function menu_render($menu, $edit = false) { return replace_macros(get_markup_template('usermenu.tpl'),array( '$menu' => $menu['menu'], + '$class' => $class, '$edit' => (($edit) ? t("Edit") : ''), '$items' => $menu['items'] )); diff --git a/include/message.php b/include/message.php index a95021583..607166ec9 100644 --- a/include/message.php +++ b/include/message.php @@ -76,7 +76,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' $match = null; $images = null; - if(preg_match_all("/\[img\](.*?)\[\/img\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) + if(preg_match_all("/\[zmg\](.*?)\[\/zmg\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) $images = $match[1]; $match = false; diff --git a/include/nav.php b/include/nav.php index dd15ff411..3aa50226d 100644 --- a/include/nav.php +++ b/include/nav.php @@ -8,12 +8,10 @@ function nav(&$a) { * */ - $ssl_state = ((local_user()) ? true : false); - if(!(x($a->page,'nav'))) $a->page['nav'] = ''; - $base = $a->get_baseurl($ssl_state); + $base = z_root(); $a->page['htmlhead'] .= <<< EOT <script>$(document).ready(function() { @@ -33,18 +31,6 @@ EOT; - /** - * Placeholder div for popup panel - */ - - /** - * - * Our network is distributed, and as you visit friends some of the - * sites look exactly the same - it isn't always easy to know where you are. - * Display the current site location as a navigation aid. - * - */ - if(local_user()) { $channel = $a->get_channel(); $observer = $a->get_observer(); @@ -58,6 +44,25 @@ EOT; $sitelocation = (($myident) ? $myident : $a->get_hostname()); + + /** + * + * Provide a banner/logo/whatever + * + */ + + $banner = get_config('system','banner'); + + if($banner === false) + $banner = get_config('system','sitename'); + + $a->page['header'] .= replace_macros(get_markup_template('hdr.tpl'), array( + '$baseurl' => $a->get_baseurl(), + '$sitelocation' => $sitelocation, + '$banner' => $banner + )); + + // nav links: array of array('href', 'text', 'extra css classes', 'title') $nav = Array(); @@ -128,7 +133,7 @@ EOT; if(($a->config['system']['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user())) $nav['register'] = array('register',t('Register'), "", t('Create an account')); - $help_url = $a->get_baseurl($ssl_state) . '/help'; + $help_url = z_root() . '/help?f=&cmd=' . $a->cmd; if(! get_config('system','hide_help')) $nav['help'] = array($help_url, t('Help'), "", t('Help and documentation')); @@ -209,7 +214,6 @@ EOT; $a->page['nav'] .= replace_macros($tpl, array( '$baseurl' => $a->get_baseurl(), - '$langselector' => ((get_config('system','select_language')) ? lang_selector() : ''), '$sitelocation' => $sitelocation, '$nav' => $x['nav'], '$banner' => $banner, diff --git a/include/oembed.php b/include/oembed.php index d8671a752..57631b051 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -14,6 +14,10 @@ function oembed_fetch_url($embedurl){ $txt = Cache::get($a->videowidth . $embedurl); + if(strstr($txt,'youtu')) { + $txt = str_replace('http:','https:',$txt); + } + // These media files should now be caught in bbcode.php // left here as a fallback in case this is called from another source @@ -99,6 +103,13 @@ function oembed_format_object($j){ $th=120; $tw = $th*$tr; $tpl=get_markup_template('oembed_video.tpl'); + if(strstr($embedurl,'youtu')) { + $embedurl = str_replace('http:','https:',$embedurl); + $j->thumbnail_url = str_replace('http:','https:', $j->thumbnail_url); + $jhtml = str_replace('http:','https:', $jhtml); + $j->html = str_replace('http:','https:', $j->html); + + } $ret.=replace_macros($tpl, array( '$baseurl' => $a->get_baseurl(), '$embedurl'=>$embedurl, diff --git a/include/onepoll.php b/include/onepoll.php index a821b76cf..e81d8bcf7 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -29,19 +29,16 @@ function onepoll_run($argv, $argc){ return; } - $d = datetime_convert(); - $contacts = q("SELECT abook.*, xchan.*, account.* FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan where abook_id = %d - AND (( abook_flags = %d ) OR ( abook_flags = %d ) OR ( abook_flags & %d )) + AND (( abook_flags & %d ) OR ( abook_flags = %d )) AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1", intval($contact_id), - intval(ABOOK_FLAG_HIDDEN), + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED), intval(0), - intval(ABOOK_FLAG_PENDING), intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED) ); diff --git a/include/poller.php b/include/poller.php index 77452cafa..423ee46c1 100644 --- a/include/poller.php +++ b/include/poller.php @@ -96,9 +96,13 @@ function poller_run($argv, $argc){ $dirmode = get_config('system','directory_mode'); + /** + * Cron Daily + * + * Actions in the following block are executed once per day, not on every poller run + * + */ - // Actions in the following block are executed once per day, not on every poller run - if($d2 != intval($d1)) { // expire any read notifications over a month old @@ -121,6 +125,7 @@ function poller_run($argv, $argc){ set_config('system','last_expire_day',$d2); + proc_run('php','include/expire.php'); proc_run('php','include/cli_suggest.php'); } @@ -179,9 +184,7 @@ function poller_run($argv, $argc){ if(! $restart) proc_run('php','include/cronhooks.php'); - // Only poll from those with suitable relationships, - // and which have a polling address and ignore Diaspora since - // we are unable to match those posts with a Diaspora GUID and prevent duplicates. + // Only poll from those with suitable relationships $abandon_sql = (($abandon_days) ? sprintf(" AND account_lastlog > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days)) @@ -192,10 +195,9 @@ function poller_run($argv, $argc){ $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_channel FROM abook LEFT JOIN account on abook_account = account_id where 1 $sql_extra - AND (( abook_flags = %d ) OR ( abook_flags = %d )) + AND (( abook_flags & %d ) OR ( abook_flags = %d )) AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY RAND()", - - intval(ABOOK_FLAG_HIDDEN), + intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED), intval(0), intval(ACCOUNT_OK), intval(ACCOUNT_UNVERIFIED) // FIXME diff --git a/include/reddav.php b/include/reddav.php index 6182aeacd..2a26ac42a 100644 --- a/include/reddav.php +++ b/include/reddav.php @@ -792,6 +792,7 @@ class RedBasicAuth extends Sabre\DAV\Auth\Backend\AbstractBasic { $this->channel_id = $r[0]['channel_id']; $this->channel_hash = $this->observer = $r[0]['channel_hash']; $_SESSION['uid'] = $r[0]['channel_id']; + $_SESSION['account_id'] = $r[0]['channel_account_id']; $_SESSION['authenticated'] = true; return true; } @@ -813,6 +814,7 @@ class RedBasicAuth extends Sabre\DAV\Auth\Backend\AbstractBasic { $this->channel_id = $r[0]['channel_id']; $this->channel_hash = $this->observer = $r[0]['channel_hash']; $_SESSION['uid'] = $r[0]['channel_id']; + $_SESSION['account_id'] = $r[0]['channel_account_id']; $_SESSION['authenticated'] = true; return true; } diff --git a/include/security.php b/include/security.php index 68dd573f7..f52615357 100644 --- a/include/security.php +++ b/include/security.php @@ -32,9 +32,12 @@ function authenticate_success($user_record, $login_initial = false, $interactive } - if($login_initial) + if($login_initial) { + call_hooks('logged_in', $user_record); - + + // might want to log success here + } if($return || x($_SESSION,'workflow')) { unset($_SESSION['workflow']); diff --git a/include/socgraph.php b/include/socgraph.php index 0e91eba60..10d52da66 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -64,6 +64,35 @@ function poco_load($xchan = '',$url = null) { logger('poco_load: ' . print_r($j,true),LOGGER_DATA); + if($xchan) { + if(array_key_exists('chatrooms',$j) && is_array($j['chatrooms'])) { + foreach($j['chatrooms'] as $room) { + $r = q("select * from xchat where xchat_url = '%s' and xchat_xchan = '%s' limit 1", + dbesc($room['url']), + dbesc($xchan) + ); + if($r) { + q("update xchat set xchat_edited = '%s' where xchat_id = %d limit 1", + dbesc(datetime_convert()), + intval($r[0]['xchat_id']) + ); + } + else { + $x = q("insert into xchat ( xchat_url, xchat_desc, xchat_xchan, xchat_edited ) + values ( '%s', '%s', '%s', '%s' ) ", + dbesc(escape_tags($room['url'])), + dbesc(escape_tags($room['desc'])), + dbesc($xchan), + dbesc(datetime_convert()) + ); + } + } + } + q("delete from xchat where xchat_edited < UTC_TIMESTAMP() - INTERVAL 7 DAY and xchat_xchan = '%s' ", + dbesc($xchan) + ); + } + if(! ((x($j,'entry')) && (is_array($j['entry'])))) { logger('poco_load: no entries'); return; diff --git a/include/text.php b/include/text.php index dfd35c769..839e63f5e 100755 --- a/include/text.php +++ b/include/text.php @@ -665,8 +665,11 @@ function contact_block() { if((! is_array($a->profile)) || ($a->profile['hide_friends'])) return $o; - $r = q("SELECT COUNT(abook_id) AS total FROM abook WHERE abook_channel = %d and abook_flags = 0", - intval($a->profile['uid']) + $r = q("SELECT COUNT(abook_id) AS total FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and abook_flags = 0 and not (xchan_flags & %d) and not (xchan_flags & %d) and not (xchan_flags & %d)", + intval($a->profile['uid']), + intval(XCHAN_FLAGS_HIDDEN), + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_DELETED) ); if(count($r)) { $total = intval($r[0]['total']); @@ -677,8 +680,11 @@ function contact_block() { } else { - $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND abook_flags = 0 ORDER BY RAND() LIMIT %d", + $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash WHERE abook_channel = %d AND abook_flags = 0 and not (xchan_flags & %d ) and not (xchan_flags & %d ) and not (xchan_flags & %d ) ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), + intval(XCHAN_FLAGS_HIDDEN), + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_DELETED), intval($shown) ); diff --git a/include/widgets.php b/include/widgets.php index 4a5ae9de7..90586397f 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -589,3 +589,120 @@ function widget_chatroom_list($arr) { )); } +function widget_bookmarkedchats($arr) { + $h = get_observer_hash(); + if(! $h) + return; + $r = q("select * from xchat where xchat_xchan = '%s' group by xchat_url order by xchat_desc", + dbesc($h) + ); + + for($x = 0; $x < count($r); $x ++) + $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); + return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( + '$header' => t('Bookmarked Chatrooms'), + '$rooms' => $r + )); +} + +function widget_suggestedchats($arr) { + + // probably should restrict this to your friends, but then the widget will only work + // if you are logged in locally. + + $h = get_observer_hash(); + if(! $h) + return; + $r = q("select *, count(xchat_url) as total from xchat group by xchat_url order by total desc, xchat_desc limit 24"); + + for($x = 0; $x < count($r); $x ++) + $r[$x]['xchat_url'] = zid($r[$x]['xchat_url']); + return replace_macros(get_markup_template('bookmarkedchats.tpl'),array( + '$header' => t('Suggested Chatrooms'), + '$rooms' => $r + )); +} + +function widget_item($arr) { + $uid = $a->profile['profile_uid']; + if((! $uid) || (! $arr['mid'])) + return ''; + + if(! perm_is_allowed($uid,get_observer_hash(),'view_pages')) + return ''; + + require_once('include/security.php'); + $sql_extra = item_permissions_sql($uid); + + + $r = q("select * from item where mid = '%s' and uid = %d and item_restrict = " . intval(ITEM_WEBPAGE) . " $sql_extra limit 1", + dbesc($arr['mid']), + intval($uid) + ); + + if(! $r) + return ''; + + xchan_query($r); + $r = fetch_post_tags($r,true); + + $o .= prepare_page($r[0]); + return $o; + +} + +function widget_clock($arr) { + + $miltime = 0; + if(isset($arr['military']) && $arr['military']) + $miltime = 1; + +$o = <<< EOT +<div class="widget"> +<h3 class="clockface"></h3> +<script> + +var timerID = null +var timerRunning = false + +function stopclock(){ + if(timerRunning) + clearTimeout(timerID) + timerRunning = false +} + +function startclock(){ + stopclock() + showtime() +} + +function showtime(){ + var now = new Date() + var hours = now.getHours() + var minutes = now.getMinutes() + var seconds = now.getSeconds() + var military = $miltime + var timeValue = "" + if(military) + timeValue = hours + else + timeValue = ((hours > 12) ? hours - 12 : hours) + timeValue += ((minutes < 10) ? ":0" : ":") + minutes +// timeValue += ((seconds < 10) ? ":0" : ":") + seconds + if(! military) + timeValue += (hours >= 12) ? " P.M." : " A.M." + $('.clockface').html(timeValue) + timerID = setTimeout("showtime()",1000) + timerRunning = true +} + +$(document).ready(function() { + startclock(); +}); + +</script> +</div> +EOT; +return $o; + +}
\ No newline at end of file diff --git a/include/zot.php b/include/zot.php index 298abb178..934348d2d 100644 --- a/include/zot.php +++ b/include/zot.php @@ -305,7 +305,7 @@ function zot_refresh($them,$channel = null, $force = false) { return false; } - $x = import_xchan($j,(($force) ? (-1) : 1)); + $x = import_xchan($j,(($force) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED)); if(! $x['success']) return false; @@ -330,8 +330,15 @@ function zot_refresh($them,$channel = null, $force = false) { else $permissions = $j['permissions']; + $connected_set = false; + if($permissions && is_array($permissions)) { foreach($permissions as $k => $v) { + // The connected permission means you are in their address book + if($k === 'connected') { + $connected_set = intval($v); + continue; + } if($v) { $their_perms = $their_perms | intval($global_perms[$k][1]); } @@ -344,7 +351,10 @@ function zot_refresh($them,$channel = null, $force = false) { intval(ABOOK_FLAG_SELF) ); - if($r) { + if($r) { + + $current_abook_connected = (($r[0]['abook_flags'] & ABOOK_FLAG_UNCONNECTED) ? 0 : 1); + $y = q("update abook set abook_their_perms = %d where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) limit 1", @@ -353,6 +363,22 @@ function zot_refresh($them,$channel = null, $force = false) { intval($channel['channel_id']), intval(ABOOK_FLAG_SELF) ); + +// if(($connected_set === 0 || $connected_set === 1) && ($connected_set !== $current_abook_unconnected)) { + + // if they are in your address book but you aren't in theirs, and/or this does not + // match your current connected state setting, toggle it. + +// $y1 = q("update abook set abook_flags = (abook_flags ^ %d) +// where abook_xchan = '%s' and abook_channel = %d +// and not (abook_flags & %d) limit 1", +// intval(ABOOK_FLAG_UNCONNECTED), +// dbesc($x['hash']), +// intval($channel['channel_id']), +// intval(ABOOK_FLAG_SELF) +// ); +// } + if(! $y) logger('abook update failed'); else { @@ -517,14 +543,14 @@ function zot_register_hub($arr) { /** - * @function import_xchan($arr,$ud_flags = 1) + * @function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED) * Takes an associative array of a fetched discovery packet and updates * all internal data structures which need to be updated as a result. * * @param array $arr => json_decoded discovery packet * @param int $ud_flags - * Determines whether to create a directory update record if any changes occur, default 1 or true - * $ud_flags = (-1) indicates a forced refresh where we unconditionally create a directory update record + * Determines whether to create a directory update record if any changes occur, default is UPDATE_FLAGS_UPDATED (true) + * $ud_flags = UPDATE_FLAGS_FORCED indicates a forced refresh where we unconditionally create a directory update record * this typically occurs once a month for each channel as part of a scheduled ping to notify the directory * that the channel still exists * @@ -532,7 +558,7 @@ function zot_register_hub($arr) { * 'message' (optional error string only if success is false) */ -function import_xchan($arr,$ud_flags = 1) { +function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED) { call_hooks('import_xchan', $arr); @@ -891,7 +917,7 @@ function import_xchan($arr,$ud_flags = 1) { } } - if(($changed) || ($ud_flags == (-1))) { + if(($changed) || ($ud_flags == UPDATE_FLAGS_FORCED)) { $guid = random_string() . '@' . get_app()->get_hostname(); update_modtime($xchan_hash,$guid,$arr['address'],$ud_flags); logger('import_xchan: changed: ' . $what,LOGGER_DEBUG); @@ -1370,8 +1396,6 @@ function process_delivery($sender,$arr,$deliveries,$relay) { // remove_community_tag is a no-op if this isn't a community tag activity remove_community_tag($sender,$arr,$channel['channel_id']); - - $item_id = delete_imported_item($sender,$arr,$channel['channel_id']); $result[] = array($d['hash'],(($item_id) ? 'deleted' : 'delete_failed'),$channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); @@ -1414,8 +1438,6 @@ function process_delivery($sender,$arr,$deliveries,$relay) { } } - - $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval($channel['channel_id']) @@ -1627,7 +1649,7 @@ function process_profile_delivery($sender,$arr,$deliveries) { dbesc($sender['hash']) ); if($r) - import_directory_profile($sender['hash'],$arr,$r[0]['xchan_addr'], 1, 0); + import_directory_profile($sender['hash'],$arr,$r[0]['xchan_addr'], UPDATE_FLAGS_UPDATED, 0); } @@ -1638,7 +1660,7 @@ function process_profile_delivery($sender,$arr,$deliveries) { * */ -function import_directory_profile($hash,$profile,$addr,$ud_flags = 1, $suppress_update = 0) { +function import_directory_profile($hash,$profile,$addr,$ud_flags = UPDATE_FLAGS_UPDATED, $suppress_update = 0) { logger('import_directory_profile', LOGGER_DEBUG); if(! $hash) |