diff options
author | Thomas Willingham <founder@kakste.com> | 2014-05-22 19:39:28 +0100 |
---|---|---|
committer | Thomas Willingham <founder@kakste.com> | 2014-05-22 19:39:28 +0100 |
commit | 292601728430469f21b81d7055cd485a0efb491c (patch) | |
tree | 4d35371f101a26b69eb8dc6dc15c3be4a884258e /include | |
parent | b06fd69da84626c1e8c1d8b5dbda6f181027a782 (diff) | |
parent | 8e2771cbd409d56917e7d249d80a2c422609f540 (diff) | |
download | volse-hubzilla-292601728430469f21b81d7055cd485a0efb491c.tar.gz volse-hubzilla-292601728430469f21b81d7055cd485a0efb491c.tar.bz2 volse-hubzilla-292601728430469f21b81d7055cd485a0efb491c.zip |
Merge branch 'master' of https://github.com/friendica/red
Diffstat (limited to 'include')
-rw-r--r-- | include/ItemObject.php | 8 | ||||
-rw-r--r-- | include/apps.php | 203 | ||||
-rw-r--r-- | include/bbcode.php | 14 | ||||
-rwxr-xr-x | include/items.php | 10 | ||||
-rw-r--r-- | include/language.php | 22 | ||||
-rw-r--r-- | include/nav.php | 5 | ||||
-rw-r--r-- | include/widgets.php | 6 |
7 files changed, 235 insertions, 33 deletions
diff --git a/include/ItemObject.php b/include/ItemObject.php index cdb09ecf1..19283c317 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -131,12 +131,12 @@ class Item extends BaseObject { } else { $like_list_part = ''; } - $like_button_label = ((x($alike,$item['mid'])) && ($alike[$item['mid']] < 2 ) ? t('Like') : t('Likes')); + $like_button_label = tt('Like','Likes',$like_count,'noun'); if (feature_enabled($conv->get_profile_owner(),'dislike')) { $dislike_count = ((x($dlike,$item['mid'])) ? $dlike[$item['mid']] : ''); $dislike_list = ((x($dlike,$item['mid'])) ? $dlike[$item['mid'] . '-l'] : ''); - $dislike_button_label = ((x($dlike,$item['mid'])) && ($dlike[$item['mid']] < 2) ? t('Dislike') : t('Dislikes')); + $dislike_button_label = tt('Dislike','Dislikes',$dislike_count,'noun'); if (count($dislike_list) > MAX_LIKERS) { $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS); array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); @@ -276,8 +276,8 @@ class Item extends BaseObject { 'like_list' => $like_list, 'like_list_part' => $like_list_part, 'like_button_label' => $like_button_label, - 'like_modal_title' => t('Likes'), - 'dislike_modal_title' => t('Dislikes'), + 'like_modal_title' => t('Likes','noun'), + 'dislike_modal_title' => t('Dislikes','noun'), 'dislike_count' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_count : ''), 'dislike_list' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_list : ''), 'dislike_list_part' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike_list_part : ''), diff --git a/include/apps.php b/include/apps.php index 09aee0389..9eb54af00 100644 --- a/include/apps.php +++ b/include/apps.php @@ -31,11 +31,14 @@ function get_system_apps() { } } } - + usort($ret,'app_name_compare'); return $ret; } +function app_name_compare($a,$b) { + return strcmp($a['name'],$b['name']); +} function parse_app_description($f) { $ret = array(); @@ -79,6 +82,10 @@ function parse_app_description($f) { if(local_user()) unset($ret); break; + case 'admin': + if(! is_site_admin()) + unset($ret); + break; case 'local_user': if(! local_user()) unset($ret); @@ -93,7 +100,7 @@ function parse_app_description($f) { break; } - logger('require: ' . print_r($ret,true)); +// logger('require: ' . print_r($ret,true)); } if($ret) { translate_system_apps($ret); @@ -104,7 +111,16 @@ function parse_app_description($f) { function translate_system_apps(&$arr) { - $apps = array( 'Matrix' => t('Matrix'), + $apps = array( + 'Site Admin' => t('Site Admin'), + 'Bookmarks' => t('Bookmarks'), + 'Address Book' => t('Address Book'), + 'Login' => t('Login'), + 'Channel Select' => t('Channel Select'), + 'Matrix' => t('Matrix'), + 'Settings' => t('Settings'), + 'Files' => t('Files'), + 'Webpages' => t('Webpages'), 'Channel Home' => t('Channel Home'), 'Profile' => t('Profile'), 'Photos' => t('Photos'), @@ -118,19 +134,71 @@ function translate_system_apps(&$arr) { } -function app_render($app) { + +// papp is a portable app + +function app_render($papp,$mode = 'view') { + + /** + * modes: + * view: normal mode for viewing an app via bbcode from a conversation or page + * provides install/update button if you're logged in locally + * list: normal mode for viewing an app on the app page + * no buttons are shown + * edit: viewing the app page in editing mode provides a delete button + */ + + $installed = false; + + if(! $papp['photo']) + $papp['photo'] = z_root() . '/' . get_default_profile_photo(80); + $papp['papp'] = papp_encode($papp); + foreach($papp as $k => $v) { + if(strpos($v,'http') === 0 && $k != 'papp') + $papp[$k] = zid($v); + if($k === 'desc') + $papp['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$papp['desc']); + } + if(local_user()) { + $installed = app_installed(local_user(),$papp); + } + + $install_action = (($installed) ? t('Update') : t('Install')); + return replace_macros(get_markup_template('app.tpl'),array( + '$app' => $papp, + '$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''), + '$install' => ((local_user() && $mode == 'view') ? $install_action : ''), + '$edit' => ((local_user() && $installed && $mode == 'edit') ? t('Edit') : ''), + '$delete' => ((local_user() && $installed && $mode == 'edit') ? t('Delete') : '') + )); } function app_install($uid,$app) { + $app['uid'] = $uid; + if(app_installed($uid,$app)) + $x = app_update($app); + else + $x = app_store($app); + if($x['success']) + return $x['app_id']; + return false; +} +function app_destroy($uid,$app) { + if($uid && $app['guid']) { + $r = q("delete from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['guid']), + intval($uid) + ); + } } @@ -155,30 +223,41 @@ function app_list($uid) { function app_decode($s) { - $x = base64_decode($s); + $x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s)); return json_decode($x,true); } function app_store($arr) { + // logger('app_store: ' . print_r($arr,true)); + $darray = array(); $ret = array('success' => false); $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); - if((! $darray['url']) || (! $darray['app_channel'])) + if((! $darray['app_url']) || (! $darray['app_channel'])) return $ret; - $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string()); + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_profile_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . get_app()->get_hostname()); $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); - $r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )", + $r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s' )", dbesc($darray['app_id']), dbesc($darray['app_sig']), dbesc($darray['app_author']), @@ -187,18 +266,122 @@ function app_store($arr) { dbesc($darray['app_url']), dbesc($darray['app_photo']), dbesc($darray['app_version']), + intval($darray['app_channel']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']) + ); + if($r) { + $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } + return $ret; +} + + +function app_update($arr) { + + $darray = array(); + $ret = array('success' => false); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); + $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0); + if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id'])) + return $ret; + + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_profile_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); + $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); + $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); + $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); + $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); + $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); + + $r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s' where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_sig']), + dbesc($darray['app_author']), + dbesc($darray['app_name']), + dbesc($darray['app_desc']), + dbesc($darray['app_url']), + dbesc($darray['app_photo']), + dbesc($darray['app_version']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']), + dbesc($darray['app_id']), intval($darray['app_channel']) ); - if($r) + if($r) { $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } return $ret; + } -function app_update($arr) { +function app_encode($app,$embed = false) { + $ret = array(); + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_sig']) + $ret['sig'] = $app['app_sig']; + + if($app['app_author']) + $ret['author'] = $app['app_author']; + + if($app['app_name']) + $ret['name'] = $app['app_name']; + + if($app['app_desc']) + $ret['desc'] = $app['app_desc']; + + if($app['app_url']) + $ret['url'] = $app['app_url']; + + if($app['app_photo']) + $ret['photo'] = $app['app_photo']; + + if($app['app_version']) + $ret['version'] = $app['app_version']; + + if($app['app_addr']) + $ret['addr'] = $app['app_addr']; + + if($app['app_price']) + $ret['price'] = $app['app_price']; + + if($app['app_page']) + $ret['page'] = $app['app_page']; + +// if($app['alt_url']) +// $ret['alt_url'] = $app['alt_url']; + + if(! $embed) + return $ret; + + $j = json_encode($ret); + return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; + +} +function papp_encode($papp) { + return chunk_split(base64_encode(json_encode($papp)),72,"\n"); }
\ No newline at end of file diff --git a/include/bbcode.php b/include/bbcode.php index a4e7560d6..674b5f45a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -166,6 +166,15 @@ function bb_parse_crypt($match) { } +function bb_parse_app($match) { + require_once('include/apps.php'); + + $app = app_decode($match[1]); + if($app) + return app_render($app); + +} + function bb_qr($match) { return '<img class="zrl" src="' . z_root() . '/photo/qr?f=&qr=' . urlencode($match[1]) . '" alt="' . t('QR code') . '" title="' . htmlspecialchars($match[1],ENT_QUOTES,'UTF-8') . '" />'; } @@ -684,6 +693,11 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); } + if(strpos($Text,'[/app]') !== false) { + $Text = preg_replace_callback("/\[app\](.*?)\[\/app\]/ism",'bb_parse_app', $Text); + } + + // html5 video and audio if (strpos($Text,'[/video]') !== false) { $Text = preg_replace_callback("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", 'tryzrlvideo', $Text); diff --git a/include/items.php b/include/items.php index 5aaeb55c0..1c44b7df5 100755 --- a/include/items.php +++ b/include/items.php @@ -2438,7 +2438,7 @@ function tag_deliver($uid,$item_id) { if($terms) { foreach($terms as $term) { - if((strcasecmp($term['term'],$u[0]['channel_name']) == 0) && link_compare($term['url'],$link)) { + if(link_compare($term['url'],$link)) { $mention = true; break; } @@ -2474,11 +2474,11 @@ function tag_deliver($uid,$item_id) { $tagged = false; $plustagged = false; - $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($u[0]['channel_name'],'/') . '\[\/zrl\]/'; + $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/zrl\]/'; if(preg_match($pattern,$body,$matches)) $tagged = true; - $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($u[0]['channel_name'] . '+','/') . '\[\/zrl\]/'; + $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; if(preg_match($pattern,$body,$matches)) $plustagged = true; @@ -2607,7 +2607,7 @@ function tgroup_check($uid,$item) { if($terms) { foreach($terms as $term) { - if(($term['term'] == $u[0]['channel_name']) && link_compare($term['url'],$link)) { + if(link_compare($term['url'],$link)) { $mention = true; break; } @@ -2625,7 +2625,7 @@ function tgroup_check($uid,$item) { $body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']); - $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($u[0]['channel_name'] . '+','/') . '\[\/zrl\]/'; + $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/'; if(! preg_match($pattern,$body,$matches)) { logger('tgroup_check: mention was in a reshare - ignoring'); diff --git a/include/language.php b/include/language.php index b43f5aacc..cfaa855dd 100644 --- a/include/language.php +++ b/include/language.php @@ -145,25 +145,29 @@ function load_translation_table($lang, $install = false) { /** * @brief translate string if translation exists. * - * @param s string that should get translated + * @param $s string that should get translated + * @param $ctx optional context to appear in po file * @return translated string if exsists, otherwise s + * */ -function t($s) { +function t($s,$ctx = '') { global $a; - if(x($a->strings,$s)) { - $t = $a->strings[$s]; + $cs = $ctx?"__ctx:".$ctx."__ ".$s:$s; + if(x($a->strings,$cs)) { + $t = $a->strings[$cs]; return is_array($t) ? $t[0] : $t; } return $s; } -function tt($singular, $plural, $count){ +function tt($singular, $plural, $count, $ctx = ''){ $a = get_app(); - if(x($a->strings,$singular)) { - $t = $a->strings[$singular]; + $cs = $ctx?"__ctx:".$ctx."__ ".$singular:$singular; + if(x($a->strings,$cs)) { + $t = $a->strings[$cs]; $f = 'string_plural_select_' . str_replace('-', '_', $a->language); if(! function_exists($f)) $f = 'string_plural_select_default'; @@ -210,8 +214,10 @@ function detect_language($s) { if($min_confidence === false) $min_confidence = LANGUAGE_DETECT_MIN_CONFIDENCE; + // embedded apps have long base64 strings which will trip up the detector. + $naked_body = preg_replace('/\[app\](.*?)\[\/app\]/','',$s); // strip off bbcode - $naked_body = preg_replace('/\[(.+?)\]/', '', $s); + $naked_body = preg_replace('/\[(.+?)\]/', '', $naked_body); if(mb_strlen($naked_body) < intval($min_length)) { logger('detect language: string length less than ' . intval($min_length), LOGGER_DATA); return ''; diff --git a/include/nav.php b/include/nav.php index a97b434bc..2d0d43d5a 100644 --- a/include/nav.php +++ b/include/nav.php @@ -138,8 +138,8 @@ EOT; if(! get_config('system','hide_help')) $nav['help'] = array($help_url, t('Help'), "", t('Help and documentation')); - if(count($a->get_apps()) > 0) - $nav['apps'] = array('apps', t('Apps'), "", t('Addon applications, utilities, games')); + + $nav['apps'] = array('apps', t('Apps'), "", t('Applications, utilities, links, games')); $nav['search'] = array('search', t('Search'), "", t('Search site content')); @@ -221,7 +221,6 @@ EOT; '$userinfo' => $x['usermenu'], '$localuser' => local_user(), '$sel' => $a->nav_sel, - '$apps' => $a->get_apps(), '$pleasewait' => t('Please wait...') )); diff --git a/include/widgets.php b/include/widgets.php index 37a079bc7..1043acce0 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -76,11 +76,11 @@ function widget_collections($args) { function widget_appselect($arr) { return replace_macros(get_markup_template('app_select.tpl'),array( - '$title' => t('App Category'), + '$title' => t('Apps'), '$system' => t('System'), '$personal' => t('Personal'), - '$featured' => t('Featured'), - '$new' => t('New') + '$new' => t('Create Personal App'), + '$edit' => t('Edit Personal App') )); } |