merged multipart email changes

This commit is contained in:
Chris Case 2011-05-21 21:40:16 -07:00
commit 4cff911939
361 changed files with 35970 additions and 10729 deletions

2
.gitignore vendored
View File

@ -1,3 +1,4 @@
favicon.*
.htconfig.php
\#*
wip/*
@ -6,4 +7,5 @@ include/jquery-1.4.2.min.js
*.out
*.version*
push*
langup
home.html

View File

@ -1,4 +1,3 @@
Options -Indexes
AddType application/x-java-archive .jar
AddType audio/ogg .oga

190
README
View File

@ -1,132 +1,74 @@
*********
Friendika
*********
*************
* Friendika *
*************
Distributed Social Network
Friendika Communications Server
http://friendika.com
Since the dawn of the world-wide-web, the internet has been a battleground
between the "big boys" with all their resources, and a bunch of upstarts whose
goal is to topple the status quo - and bring the same powers of global reach
to anybody with a computer and an internet connection.
The latest battleground is social networking. Many of your friends would
have you believe that the world (and all the information in it) belongs to
Facebook.
Friendika is here to rock that boat.
Granted, all your friends aren't here - yet. The people who made fun of you
in high school (yet curiously wanted to be friends with you now) are still
"poking" each other and managing their virtual farms and telling you all about
their virtual gang wars. Would you miss them?
I wouldn't.
You probably have a handful of friends that are truly special. Tell those
friends that the world has changed - because it has. It's time to move on. A
year ago, if you had left Facebook, there was no place to go - at least a
place which offered the same kind of social interaction (and wasn't just
another huge company trying to make money off of all of your private
information).
Today you have options.
What if there was a social network which provided some of the same
interaction you've grown to love, *and* was free to use, *and* was open source,
*and* where your privacy is always under your control?
And what if this social network could scale to encompass the entire
internet, and *not* require a central organisation to provide servers?
(In exchange for peddling your private information behind your back.)
Look no further.
Friendika is a social network without boundaries, and without ownership.
Friendika installations can link together into a global social network which
is free from central control. Besides the Friendika network (which is privacy
enhanced); you can also connect with and communicate with friends on identi.ca,
Status.Net and many other sites and social networks *today*.
Welcome to the federated social web. If you choose not to use Friendika
(though we think you'd be foolish not to), you can choose any of 20-30 other
providers of federated social networking software and still be a part of this
vast new social network. This is going to be bigger than Facebook.
Much bigger.
We are currently developing connectors to seamlessly communicate with many
other open social networks and providers - like Diaspora, GNU-Social,
OneSocialWeb, and even some of the larger closed services such as Facebook and
Twitter.
Over the coming months, the boundaries between these networks will start
to become indistinguishable as they all become part of your social circle.
Our core belief is that your personal thoughts and conversations belong to
you - and are only meant to be shared with those you wish to share them with.
Period.
Friendika is secure, and as private as you wish it to be. Our privacy
settings are straight-forward and simple, because we know that relationships
rarely are (straight-forward and simple). Whether you're communicating with
drinking buddies or potential employers, you can rest assured that each is
only able to see the side of you that you wish to present. If you send a
private message to your aunt Mary, we will encrypt it with military grade
encryption.
Other distributed social network projects talk about privacy and offering
a feature-rich social networking alternative, but all they can deliver is
vapour and vague promises. Things like "Private mail will be in the next
release".
Friendika delivers. We've got an incredibly rich social communications
interface you can make use of *right now*.
And lest you think we're just trying to copy Facebook feature-for-feature,
you couldn't be further from the truth. We like the conversational style
because it feels natural, and that's why Facebook grew to be what it is today.
But we're creating something completely different.
Something better.
A single instance of Friendika can easily support hundreds of (and up to
several thousand) people using commodity hosting hardware. You could even run
Friendika on an old PC in your closet or garage. Each of these people are able
to connect with potentially hundreds or thousands of friends and associates
on any other supported network anywhere in the world and share photos, links,
status updates, etc.
But maybe you don't want to be connected to the world... and that's OK
too. Friendika may be closed off from the global community and used to support
social networking amongst corporate, educational, religious, and other private
communities. This makes it an excellent choice for the social networking needs
of young teenagers and especially k-12 organisations.
Every person on Friendika has unlimited profiles available to them. There
is a "public profile" which can be seen by anybody. Additional profiles may be
tailored to specific groups or individuals. Try doing that on Twitter.
Groups may be created and used for closed conversations. In this way your
conversations with one group of friends is completely isolated from other
friends or groups of friends.
You may also create interactive band/celebrity pages, special interest
groups, and even organisational 'soapboxes' - for social communications that
require the ability to scale to global levels. Friendika provides for automatic
relationship management in these extreme cases so that you can concentrate on
your message and public persona - and not worry about being swamped by friend
requests. You can even maintain private social contact with your closest
friends and public updates to your hordes of fans - using the same interface.
No other social network offers this ability.
http://project.friendika.com
Join us.
Friendika is a web application for managing social communications. Some
would call it a "social network" or "distributed social network". We think
both terms have been over-used, and don't adequately describe Friendika's
capabilities - though Friendika can also fill those roles.
At its essence, Friendika is a web application which can monitor various
information and social activity streams, and which also lets you participate
in online conversations with friends and associates, using a variety of network
protocols. These are combined into an overview of your various communications
and activities - regardless of network origin.
Friendika also manages your personal profiles and photo albums and lets
you securely present each of these to specific audiences. Your communications
can be either open and public, or closed and private. You can easily create
"groups" of contacts with which you can partition your conversations into
private social circles, and which cannot be seen outside the circle.
Friendika is decentralised. Any account on any Friendika server can connect
with any account on any other Friendika server. You can also connect to and
interact directly with friends on Status.Net and other federated social web
services (e.g. identi.ca, GNU-Social, etc.).
Outgoing communications can be directed at these networks and also
existing accounts on Facebook and Twitter - or even delivered to email
contacts.
Incoming data streams aren't limited to traditional social networks.
They may include most any service which provides a syndication feed (both RSS
and Atom). This allows you to view communications from friends in other
diverse social networks - such as Diaspora, Google Buzz, and millions of
blogs, news services, and other websites. You can also import
contacts from (and write to) anybody that is accessible from your email
INBOX and view them in your social stream. Over time we will try to
build two-way bridges to other services so that you can freely
interact in both directions with anybody on an accessible network that
allows it.
Communications between Friendika servers are private and encrypted,
using military grade encryption - and require mutual identity provenance
before any data is exchanged. These same crypto mechanisms provide remote
password-less authentication; allowing you to post to profiles and view private
photo collections on other servers - without encountering any login and/or
authorisation dialogues when visiting these sites.
Friendika has no boundaries and no central ownership of the data generated
within the network. Anybody with a commodity PHP/MySQL web server or hosting
account can provide a server, and each individual server can then support
up to several thousand participating members - each with their own unique
communication and privacy needs. This allows Friendika to scale to global
levels and mimics the decentralised architecture of the web itself.
If you are creating a website which requires social interaction, Friendika
can also take the place of blog software, forum software and feed readers, and
also provide individualised communications and content management - or
simply be used as an alternative to traditional "monolithic" social networks.
Friendika is also free - in every sense of the word.
Choose freedom - join us.
Find out more about the project at http://project.friendika.com
*******************
Friendika Demo Site

View File

@ -1,17 +1,13 @@
<?php
/**
* This module still needs a lot of work, but is functional today.
* Please review this section if you upgrade because things will change.
* If you have issues upgrading, remove facebook from the addon list,
* view a page on your site, then add it back to the list. This will reset
* all of the plugin 'hooks'.
* Installing the Friendika/Facebook connector
*
* 1. register an API key for your site from developer.facebook.com
* a. We'd be very happy if you include "Friendika" in the application name
* to increase name recognition. The Friendika icons are also present
* in the images directory and may be uploaded as a Facebook app icon.
* Use images/ff-16.jpg for the Icon and images/ff-128.jpg for the Logo.
* Use images/friendika-16.jpg for the Icon and images/friendika-128.jpg for the Logo.
* b. The url should be your site URL with a trailing slash.
* You may use http://portal.friendika.com/privacy as the privacy policy
* URL unless your site has different requirements, and
@ -24,20 +20,20 @@
* Replace with the settings Facebook gives you.
* 2. Enable the facebook plugin by including it in .htconfig.php - e.g.
* $a->config['system']['addon'] = 'plugin1,plugin2,facebook';
* 3. Visit your site url + '/facebook' (e.g. http://example.com/facebook)
* and click 'Install Facebook posting'.
* 3. Visit the Facebook Settings section of the "Settings->Plugin Settings" page.
* and click 'Install Facebook Connector'.
* 4. This will ask you to login to Facebook and grant permission to the
* plugin to do its stuff. Allow it to do so.
* 5. You're done. To turn it off visit your site's /facebook page again and
* 5. You're done. To turn it off visit the Plugin Settings page again and
* 'Remove Facebook posting'.
*
* Turn logging on (see the github Friendika wiki page 'Settings') and
* repeat these steps if you have trouble.
* Vidoes and embeds will not be posted if there is no other content. Links
* and images will be converted to text and long posts truncated - with a link
* to view the full post. Posts with permission settings and comments will
* not be posted to Facebook.
* and images will be converted to a format suitable for the Facebook API and
* long posts truncated - with a link to view the full post.
*
* Facebook contacts will not be able to view private photos, as they are not able to
* authenticate to your site to establish identity. We will address this
* in a future release.
*/
define('FACEBOOK_MAXPOSTLEN', 420);
@ -88,6 +84,10 @@ function facebook_init(&$a) {
$token = substr($token,0,strpos($token,'&'));
set_pconfig($uid,'facebook','access_token',$token);
set_pconfig($uid,'facebook','post','1');
fb_get_self($uid);
fb_get_friends($uid);
fb_consume_all($uid);
}
// todo: is this a browser session or a server session? where do we go?
@ -95,6 +95,138 @@ function facebook_init(&$a) {
}
function fb_get_self($uid) {
$access_token = get_pconfig($uid,'facebook','access_token');
if(! $access_token)
return;
$s = fetch_url('https://graph.facebook.com/me/?access_token=' . $access_token);
if($s) {
$j = json_decode($s);
set_pconfig($uid,'facebook','self_id',(string) $j->id);
}
}
function fb_get_friends($uid) {
$access_token = get_pconfig($uid,'facebook','access_token');
if(! $access_token)
return;
$s = fetch_url('https://graph.facebook.com/me/friends?access_token=' . $access_token);
if($s) {
logger('facebook: fb_get_friends: ' . $s, LOGGER_DATA);
$j = json_decode($s);
logger('facebook: fb_get_friends: json: ' . print_r($j,true), LOGGER_DATA);
foreach($j->data as $person) {
$s = fetch_url('https://graph.facebook.com/' . $person->id . '?access_token=' . $access_token);
if($s) {
$jp = json_decode($s);
logger('fb_get_friends: info: ' . print_r($jp,true), LOGGER_DATA);
// always use numeric link for consistency
$jp->link = 'http://facebook.com/profile.php?id=' . $person->id;
// check if we already have a contact
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1",
intval($uid),
dbesc($jp->link)
);
if(count($r)) {
// check that we have all the photos, this has been known to fail on occasion
if((! $r[0]['photo']) || (! $r[0]['thumb']) || (! $r[0]['micro'])) {
require_once("Photo.php");
$photos = import_profile_photo('https://graph.facebook.com/' . $jp->id . '/picture', $uid, $r[0]['id']);
$r = q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d LIMIT 1
",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($r[0]['id'])
);
}
continue;
}
else {
// create contact record
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`,
`name`, `nick`, `photo`, `network`, `rel`, `priority`,
`writable`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
intval($uid),
dbesc(datetime_convert()),
dbesc($jp->link),
dbesc(''),
dbesc(''),
dbesc($jp->id),
dbesc('facebook ' . $jp->id),
dbesc($jp->name),
dbesc(($jp->nickname) ? $jp->nickname : strtolower($jp->first_name)),
dbesc('https://graph.facebook.com/' . $jp->id . '/picture'),
dbesc(NETWORK_FACEBOOK),
intval(REL_BUD),
intval(1),
intval(1)
);
}
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($jp->link),
intval($uid)
);
if(! count($r)) {
continue;
}
$contact = $r[0];
$contact_id = $r[0]['id'];
require_once("Photo.php");
$photos = import_profile_photo($r[0]['photo'],$uid,$contact_id);
$r = q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d LIMIT 1
",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_id)
);
}
}
}
}
function facebook_post(&$a) {
if(local_user()){
@ -116,6 +248,12 @@ function facebook_content(&$a) {
notice( t('Facebook disabled') . EOL);
}
if($a->argc > 1 && $a->argv[1] === 'friends') {
fb_get_friends(local_user());
notice( t('Updating contacts') . EOL);
}
$fb_installed = get_pconfig(local_user(),'facebook','post');
$appid = get_config('facebook','appid');
@ -134,14 +272,14 @@ function facebook_content(&$a) {
$o .= '<div id="facebook-enable-wrapper">';
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri='
. $a->get_baseurl() . '/facebook/' . $a->user['nickname'] . '&scope=publish_stream,read_stream,offline_access">' . t('Install Facebook post connector') . '</a>';
. $a->get_baseurl() . '/facebook/' . $a->user['nickname'] . '&scope=publish_stream,read_stream,offline_access">' . t('Install Facebook connector for this account.') . '</a>';
$o .= '</div>';
}
if($fb_installed) {
$o .= '<div id="facebook-disable-wrapper">';
$o .= '<a href="' . $a->get_baseurl() . '/facebook/remove' . '">' . t('Remove Facebook post connector') . '</a></div>';
$o .= '<a href="' . $a->get_baseurl() . '/facebook/remove' . '">' . t('Remove Facebook connector') . '</a></div>';
$o .= '<div id="facebook-post-default-form">';
$o .= '<form action="facebook" method="post" >';
@ -158,6 +296,7 @@ function facebook_install() {
register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
}
@ -165,9 +304,46 @@ function facebook_uninstall() {
unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
}
function facebook_cron($a,$b) {
$last = get_config('facebook','last_poll');
$poll_interval = intval(get_config('facebook','poll_interval'));
if(! $poll_interval)
$poll_interval = 3600;
if($last) {
$next = $last + $poll_interval;
if($next > time())
return;
}
logger('facebook_cron');
set_config('facebook','last_poll', time());
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'facebook' AND `k` = 'post' AND `v` = '1' ");
if(count($r)) {
foreach($r as $rr) {
// check for new friends once a day
$last_friend_check = get_pconfig($rr['uid'],'facebook','friend_check');
if($last_friend_check)
$next_friend_check = $last_friend_check + 86400;
if($next_friend_check <= time()) {
fb_get_friends($rr['uid']);
set_pconfig($rr['uid'],'facebook','friend_check',time());
}
fb_consume_all($rr['uid']);
}
}
}
function facebook_plugin_settings(&$a,&$b) {
$b .= '<div class="settings-block">';
@ -197,9 +373,77 @@ function facebook_post_hook(&$a,&$b) {
* Post to Facebook stream
*/
require_once('include/group.php');
logger('Facebook post');
if((local_user()) && (local_user() == $b['uid']) && (! $b['private']) && (! $b['parent'])) {
$reply = false;
$likes = false;
if((local_user()) && (local_user() == $b['uid'])) {
if($b['parent']) {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($b['parent']),
intval(local_user())
);
if(count($r) && substr($r[0]['uri'],0,4) === 'fb::')
$reply = substr($r[0]['uri'],4);
elseif(count($r) && substr($r[0]['extid'],0,4) === 'fb::')
$reply = substr($r[0]['extid'],4);
else
return;
logger('facebook reply id=' . $reply);
}
if($b['private'] && $reply == false) {
$allow_people = expand_acl($b['allow_cid']);
$allow_groups = expand_groups(expand_acl($b['allow_gid']));
$deny_people = expand_acl($b['deny_cid']);
$deny_groups = expand_groups(expand_acl($b['deny_gid']));
$recipients = array_unique(array_merge($allow_people,$allow_groups));
$deny = array_unique(array_merge($deny_people,$deny_groups));
$allow_str = dbesc(implode(', ',$recipients));
if($allow_str) {
$r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'");
$allow_arr = array();
if(count($r))
foreach($r as $rr)
$allow_arr[] = $rr['notify'];
}
$deny_str = dbesc(implode(', ',$deny));
if($deny_str) {
$r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $deny_str ) AND `network` = 'face'");
$deny_arr = array();
if(count($r))
foreach($r as $rr)
$deny_arr[] = $rr['notify'];
}
if(count($deny_arr) && (! count($allow_arr))) {
// One or more FB folks were denied access but nobody on FB was specifically allowed access.
// This might cause the post to be open to public on Facebook, but only to selected members
// on another network. Since this could potentially leak a post to somebody who was denied,
// we will skip posting it to Facebook with a slightly vague but relevant message that will
// hopefully lead somebody to this code comment for a better explanation of what went wrong.
notice( t('Post to Facebook cancelled because of multi-network access permission conflict.') . EOL);
return;
}
// if it's a private message but no Facebook members are allowed or denied, skip Facebook post
if((! count($allow_arr)) && (! count($deny_arr)))
return;
}
if($b['verb'] == ACTIVITY_LIKE)
$likes = true;
$appid = get_config('facebook', 'appid' );
@ -214,7 +458,12 @@ function facebook_post_hook(&$a,&$b) {
$fb_token = get_pconfig(local_user(),'facebook','access_token');
logger('facebook: $fb_post: ' . $fb_post . ' $fb_enable: ' . $fb_enable . ' $fb_token: ' . $fb_token,LOGGER_DEBUG);
if($fb_post && $fb_token && $fb_enable) {
// post to facebook if it's a public post and we've ticked the 'post to Facebook' box,
// or it's a private message with facebook participants
// or it's a reply or likes action to an existing facebook post
if($fb_post && $fb_token && ($fb_enable || $b['private'] || $reply)) {
logger('facebook: able to post');
require_once('library/facebook.php');
require_once('include/bbcode.php');
@ -225,9 +474,32 @@ function facebook_post_hook(&$a,&$b) {
// make links readable before we strip the code
$msg = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is",'$2 [$1]',$msg);
// unless it's a dislike - just send the text as a comment
if($b['verb'] == ACTIVITY_DISLIKE)
$msg = trim(strip_tags(bbcode($msg)));
$search_str = $a->get_baseurl() . '/search';
if(preg_match("/\[url=(.+?)\](.+?)\[\/url\]/is",$msg,$matches)) {
// don't use hashtags for message link
if(strpos($matches[2],$search_str) === false) {
$link = $matches[1];
if(substr($matches[2],0,5) != '[img]')
$linkname = $matches[2];
}
}
$msg = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is",'$2 $1',$msg);
if(preg_match("/\[img\](.+?)\[\/img\]/is",$msg,$matches))
$image = $matches[1];
$msg = preg_replace("/\[img\](.+?)\[\/img\]/is", t('Image: ') . '$1', $msg);
$msg = preg_replace("/\[img\](.+?)\[\/img\]/is", t('Image: ') . '$1',$msg);
$msg = trim(strip_tags(bbcode($msg)));
$msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
@ -237,7 +509,7 @@ function facebook_post_hook(&$a,&$b) {
require_once('library/slinky.php');
$display_url = $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $b['id'];
$slinky = new Slinky( $posturl );
$slinky = new Slinky( $display_url );
// setup a cascade of shortening services
// try to get a short link from these services
// in the order ur1.ca, trim, id.gd, tinyurl
@ -253,9 +525,57 @@ function facebook_post_hook(&$a,&$b) {
logger('Facebook post: msg=' . $msg, LOGGER_DATA);
$postvars = array('access_token' => $fb_token, 'message' => $msg);
if($likes) {
$postvars = array('access_token' => $fb_token);
}
else {
$postvars = array(
'access_token' => $fb_token,
'message' => $msg
);
if(isset($image))
$postvars['picture'] = $image;
if(isset($link))
$postvars['link'] = $link;
if(isset($linkname))
$postvars['name'] = $linkname;
}
$x = post_url('https://graph.facebook.com/me/feed', $postvars);
if(($b['private']) && (! $b['parent'])) {
$postvars['privacy'] = '{"value": "CUSTOM", "friends": "SOME_FRIENDS"';
if(count($allow_arr))
$postvars['privacy'] .= ',"allow": "' . implode(',',$allow_arr) . '"';
if(count($deny_arr))
$postvars['privacy'] .= ',"deny": "' . implode(',',$deny_arr) . '"';
$postvars['privacy'] .= '}';
}
if($reply) {
$url = 'https://graph.facebook.com/' . $reply . '/' . (($likes) ? 'likes' : 'comments');
}
else {
$url = 'https://graph.facebook.com/me/feed';
if($b['plink'])
$postvars['actions'] = '{"name": "' . t('View on Friendika') . '", "link": "' . $b['plink'] . '"}';
}
logger('facebook: post to ' . $url);
logger('facebook: postvars: ' . print_r($postvars,true));
// "test_mode" prevents anything from actually being posted.
// Otherwise, let's do it.
if(! get_config('facebook','test_mode'))
$x = post_url($url, $postvars);
$retj = json_decode($x);
if($retj->id) {
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1",
dbesc('fb::' . $retj->id),
intval($b['id'])
);
}
logger('Facebook post returns: ' . $x, LOGGER_DEBUG);
@ -264,3 +584,234 @@ function facebook_post_hook(&$a,&$b) {
}
}
function fb_consume_all($uid) {
require_once('include/items.php');
$access_token = get_pconfig($uid,'facebook','access_token');
if(! $access_token)
return;
$s = fetch_url('https://graph.facebook.com/me/feed?access_token=' . $access_token);
if($s) {
$j = json_decode($s);
logger('fb_consume_stream: wall: ' . print_r($j,true), LOGGER_DATA);
fb_consume_stream($uid,$j,true);
}
$s = fetch_url('https://graph.facebook.com/me/home?access_token=' . $access_token);
if($s) {
$j = json_decode($s);
logger('fb_consume_stream: feed: ' . print_r($j,true), LOGGER_DATA);
fb_consume_stream($uid,$j,false);
}
}
function fb_consume_stream($uid,$j,$wall = false) {
$a = get_app();
$self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid)
);
$user = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if(count($user))
$my_local_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
$self_id = get_pconfig($uid,'facebook','self_id');
if(! count($j->data) || (! strlen($self_id)))
return;
foreach($j->data as $entry) {
logger('fb_consume: entry: ' . print_r($entry,true), LOGGER_DATA);
$datarray = array();
$we_posted = false;
$app = $entry->application;
if($app->id == get_config('facebook','appid') && $wall)
$we_posted = true;
$r = q("SELECT * FROM `item` WHERE ( `uri` = '%s' OR `extid` = '%s') AND `uid` = %d LIMIT 1",
dbesc('fb::' . $entry->id),
dbesc('fb::' . $entry->id),
intval($uid)
);
if(count($r)) {
$post_exists = true;
$orig_post = $r[0];
$top_item = $r[0]['id'];
}
else {
$post_exists = false;
$orig_post = null;
}
if(! $orig_post) {
$datarray['gravity'] = 0;
$datarray['uid'] = $uid;
$datarray['wall'] = (($wall) ? 1 : 0);
$datarray['uri'] = $datarray['parent-uri'] = 'fb::' . $entry->id;
$from = $entry->from;
if($from->id == $self_id)
$datarray['contact-id'] = $self[0]['id'];
else {
$r = q("SELECT * FROM `contact` WHERE `notify` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($from->id),
intval($uid)
);
if(count($r))
$datarray['contact-id'] = $r[0]['id'];
}
// don't store post if we don't have a contact
if(! x($datarray,'contact-id'))
continue;
$datarray['verb'] = ACTIVITY_POST;
if($wall) {
$datarray['owner-name'] = $self[0]['name'];
$datarray['owner-link'] = $self[0]['url'];
$datarray['owner-avatar'] = $self[0]['thumb'];
}
$datarray['author-name'] = $from->name;
$datarray['author-link'] = 'http://facebook.com/profile.php?id=' . $from->id;
$datarray['author-avatar'] = 'https://graph.facebook.com/' . $from->id . '/picture';
$datarray['plink'] = $datarray['author-link'] . '&v=wall&story_fbid=' . substr($entry->id,strpos($entry->id,'_') + 1);
$datarray['body'] = $entry->message;
if($entry->picture)
$datarray['body'] .= "\n\n" . '[img]' . $entry->picture . '[/img]';
if($entry->link)
$datarray['body'] .= "\n" . linkify($entry->link);
if($entry->name)
$datarray['body'] .= "\n" . $entry->name;
if($entry->caption)
$datarray['body'] .= "\n" . $entry->caption;
if($entry->description)
$datarray['body'] .= "\n" . $entry->description;
$datarray['created'] = datetime_convert('UTC','UTC',$entry->created_time);
$datarray['edited'] = datetime_convert('UTC','UTC',$entry->updated_time);
if($entry->privacy && $entry->privacy->value !== 'EVERYONE')
$datarray['private'] = 1;
$top_item = item_store($datarray);
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($top_item),
intval($uid)
);
if(count($r))
$orig_post = $r[0];
}
$likers = $entry->likes->data;
$comments = $entry->comments->data;
if(is_array($likers)) {
foreach($likers as $likes) {
if(! $orig_post)
continue;
$r = q("SELECT * FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `verb` = '%s' AND `author-link` = '%s' LIMIT 1",
dbesc($orig_post['uri']),
intval($uid),
dbesc(ACTIVITY_LIKE),
dbesc('http://facebook.com/profile.php?id=' . $likes->id)
);
if(count($r))
continue;
$likedata = array();
$likedata['parent'] = $top_item;
$likedata['verb'] = ACTIVITY_LIKE;
$likedata['gravity'] = 3;
$likedata['uid'] = $uid;
$likedata['wall'] = (($wall) ? 1 : 0);
$likedata['uri'] = item_new_uri($a->get_baseurl(), $uid);
$likedata['parent-uri'] = $orig_post['uri'];
if($likes->id == $self_id)
$likedata['contact-id'] = $self[0]['id'];
else {
$r = q("SELECT * FROM `contact` WHERE `notify` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($likes->id),
intval($uid)
);
if(count($r))
$likedata['contact-id'] = $r[0]['id'];
}
if(! x($likedata,'contact-id'))
$likedata['contact-id'] = $orig_post['contact-id'];
$likedata['verb'] = ACTIVITY_LIKE;
$likedata['author-name'] = $likes->name;
$likedata['author-link'] = 'http://facebook.com/profile.php?id=' . $likes->id;
$likedata['author-avatar'] = 'https://graph.facebook.com/' . $likes->id . '/picture';
$author = '[url=' . $likedata['author-link'] . ']' . $likedata['author-name'] . '[/url]';
$objauthor = '[url=' . $orig_post['author-link'] . ']' . $orig_post['author-name'] . '[/url]';
$post_type = t('status');
$plink = '[url=' . $orig_post['plink'] . ']' . $post_type . '[/url]';
$likedata['object-type'] = ACTIVITY_OBJ_NOTE;
$likedata['body'] = sprintf( t('%1$s likes %2$s\'s %3$s'), $author, $objauthor, $plink);
$likedata['object'] = '<object><type>' . ACTIVITY_OBJ_NOTE . '</type><local>1</local>' .
'<id>' . $orig_post['uri'] . '</id><link>' . xmlify('<link rel="alternate" type="text/html" href="' . $orig_post['plink'] . '">') . '</link><title>' . $orig_post['title'] . '</title><content>' . $orig_post['body'] . '</content></object>';
$item = item_store($likedata);
}
}
if(is_array($comments)) {
foreach($comments as $cmnt) {
if(! $orig_post)
continue;
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND ( `uri` = '%s' OR `extid` = '%s' ) LIMIT 1",
intval($uid),
dbesc('fb::' . $cmnt->id),
dbesc('fb::' . $cmnt->id)
);
if(count($r))
continue;
$cmntdata = array();
$cmntdata['parent'] = $top_item;
$cmntdata['verb'] = ACTIVITY_POST;
$cmntdata['gravity'] = 6;
$cmntdata['uid'] = $uid;
$cmntdata['wall'] = (($wall) ? 1 : 0);
$cmntdata['uri'] = 'fb::' . $cmnt->id;
$cmntdata['parent-uri'] = $orig_post['uri'];
if($cmnt->from->id == $self_id) {
$cmntdata['contact-id'] = $self[0]['id'];
}
else {
$r = q("SELECT * FROM `contact` WHERE `notify` = '%s' AND `uid` = %d LIMIT 1",
dbesc($cmnt->from->id),
intval($uid)
);
if(count($r)) {
$cmntdata['contact-id'] = $r[0]['id'];
if($r[0]['blocked'] || $r[0]['readonly'])
continue;
}
}
if(! x($cmntdata,'contact-id'))
$cmntdata['contact-id'] = $orig_post['contact-id'];
$cmntdata['created'] = datetime_convert('UTC','UTC',$cmnt->created_time);
$cmntdata['edited'] = datetime_convert('UTC','UTC',$cmnt->created_time);
$cmntdata['verb'] = ACTIVITY_POST;
$cmntdata['author-name'] = $cmnt->from->name;
$cmntdata['author-link'] = 'http://facebook.com/profile.php?id=' . $cmnt->from->id;
$cmntdata['author-avatar'] = 'https://graph.facebook.com/' . $cmnt->from->id . '/picture';
$cmntdata['body'] = $cmnt->message;
$item = item_store($cmntdata);
}
}
}
}

View File

@ -18,6 +18,10 @@ function oembed_uninstall() {
}
function oembed_hook_page_header($a, &$b){
if(($a->module !== 'network') && ($a->module !== 'profile'))
return;
$b .= '<script src="addon/oembed/oembed.js"></script>
<style>#oembed.hide { display: none }
#oembed {
@ -33,11 +37,11 @@ function oembed_hook_page_header($a, &$b){
<div id="oembed" class="hide"><input id="oembed_url">&nbsp;
<input type="button" value="Embed" onclick="oembed_do()" style="float:left;">
<a onclick="oembed(); return false;" style="float:right;"><img onmouseout="imgdull(this);" onmouseover="imgbright(this);" class="wall-item-delete-icon" src="images/b_drophide.gif" style="width: 16px; height: 16px;"></a>
<p style="clear:both">Paste a link from 5min.com, Amazon Product Image, blip.tv, Clikthrough, CollegeHumor Video,
<div style="clear:both">Paste a link from 5min.com, Amazon Product Image, blip.tv, Clikthrough, CollegeHumor Video,
Daily Show with Jon Stewart, Dailymotion, dotSUB.com, Flickr Photos, Funny or Die Video,
Google Video, Hulu, Kinomap, LiveJournal UserPic, Metacafe, National Film Board of Canada,
Phodroid Photos, Photobucket, Qik Video, Revision3, Scribd, SlideShare, TwitPic, Twitter Status,
Viddler Video, Vimeo, Wikipedia, Wordpress.com, XKCD Comic, YFrog, YouTube</p>
Viddler Video, Vimeo, Wikipedia, Wordpress.com, XKCD Comic, YFrog, YouTube</div>
</div>
';
}

View File

@ -12,25 +12,32 @@
}
#statusnet-disconnect-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 25px;
}
#statusnet-default-label {
float: left;
width: 250px;
margin-bottom: 25px;
}
#statusnet-disconnect {
float: left;
}
#statusnet-enable-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 5px;
}
#statusnet-checkbox {
float: left;
}
#statusnet-pin-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 25px;
}
#statusnet-pin {
@ -40,7 +47,7 @@
#statusnet-consumerkey-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 8px;
}
#statusnet-consumerkey {
@ -49,7 +56,7 @@
}
#statusnet-consumersecret-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 8px;
}
#statusnet-consumersecret {
@ -58,7 +65,7 @@
}
#statusnet-baseapi-label {
float: left;
width: 200px;
width: 250px;
margin-bottom: 25px;
}
#statusnet-baseapi {

View File

@ -90,18 +90,40 @@ function statusnet_settings_post ($a,$post) {
* if the statusnet-disconnect checkbox is set, clear the statusnet configuration
* TODO can we revoke the access tokens at Twitter and do we need to do so?
*/
del_pconfig( local_user(), 'statusnet', 'consumerkey' );
del_pconfig( local_user(), 'statusnet', 'consumersecret' );
del_pconfig( local_user(), 'statusnet', 'post' );
del_pconfig( local_user(), 'statusnet', 'oauthtoken' );
del_pconfig( local_user(), 'statusnet', 'consumerkey' );
del_pconfig( local_user(), 'statusnet', 'consumersecret' );
del_pconfig( local_user(), 'statusnet', 'post' );
del_pconfig( local_user(), 'statusnet', 'post_by_default' );
del_pconfig( local_user(), 'statusnet', 'oauthtoken' );
del_pconfig( local_user(), 'statusnet', 'oauthsecret' );
del_pconfig( local_user(), 'statusnet', 'baseapi' );
} else {
if (isset($_POST['statusnet-consumersecret'])) {
set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
set_pconfig(local_user(), 'statusnet', 'baseapi', $_POST['statusnet-baseapi']);
header('Location: '.$a->get_baseurl().'/settings/addon');
// check if we can reach the API of the StatusNet server
// we'll check the API Version for that, if we don't get one we'll try to fix the path but will
// resign quickly after this one try to fix the path ;-)
$apibase = $_POST['statusnet-baseapi'];
$c = fetch_url( $apibase . 'statusnet/version.xml' );
if (strlen($c) > 0) {
// ok the API path is correct, let's save the settings
set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase );
} else {
// the API path is not correct, maybe missing trailing / ?
$apibase = $apibase . '/';
$c = fetch_url( $apibase . 'statusnet/version.xml' );
if (strlen($c) > 0) {
// ok the API path is now correct, let's save the settings
set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase );
} else {
// still not the correct API base, let's do noting
notice( t('We could not contact the StatusNet API with the Path you entered.').EOL );
}
}
goaway($a->get_baseurl().'/settings/addon');
} else {
if (isset($_POST['statusnet-pin'])) {
// if the user supplied us with a PIN from Twitter, let the magic of OAuth happen
@ -119,11 +141,13 @@ function statusnet_settings_post ($a,$post) {
set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']);
set_pconfig(local_user(),'statusnet', 'post', 1);
// reload the Addon Settings page, if we don't do it see Bug #42
header('Location: '.$a->get_baseurl().'/settings/addon');
goaway($a->get_baseurl().'/settings/addon');
} else {
// if no PIN is supplied in the POST variables, the user has changed the setting
// to post a tweet for every new __public__ posting to the wall
set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable']));
set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default']));
notice( t('StatusNet settings updated.') . EOL);
}}}
}
function statusnet_settings(&$a,&$s) {
@ -133,6 +157,7 @@ function statusnet_settings(&$a,&$s) {
/***
* 1) Check that we have a base api url and a consumer key & secret
* 2) If no OAuthtoken & stuff is present, generate button to get some
* allow the user to cancel the connection process at this step
* 3) Checkbox for "Send public notices (respect size limitation)
*/
$api = get_pconfig(local_user(), 'statusnet', 'baseapi');
@ -140,8 +165,10 @@ function statusnet_settings(&$a,&$s) {
$csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' );
$otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken' );
$osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret' );
$enabled = get_pconfig(local_user(), 'statusnet', 'post');
$enabled = get_pconfig(local_user(), 'statusnet', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$defenabled = get_pconfig(local_user(),'statusnet','post_by_default');
$defchecked = (($defenabled) ? ' checked="checked" ' : '');
$s .= '<div class="settings-block">';
$s .= '<h3>'. t('StatusNet Posting Settings').'</h3>';
@ -187,6 +214,13 @@ function statusnet_settings(&$a,&$s) {
$s .= '<input id="statusnet-token2" type="hidden" name="statusnet-token2" value="'.$request_token['oauth_token_secret'].'" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
$s .= '<h4>'.t('Cancel Connection Process').'</h4>';
$s .= '<div id="statusnet-cancel-wrapper">';
$s .= '<p>'.t('Current StatusNet API is').': '.$api.'</p>';
$s .= '<label id="statusnet-cancel-label" for="statusnet-cancel">'. t('Cancel StatusNet Connection') . '</label>';
$s .= '<input id="statusnet-cancel" type="checkbox" name="statusnet-disconnect" value="1" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
} else {
/***
* we have an OAuth key / secret pair for the user
@ -195,11 +229,15 @@ function statusnet_settings(&$a,&$s) {
$connection = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret);
$details = $connection->get('account/verify_credentials');
$s .= '<div id="statusnet-info" ><img id="statusnet-avatar" src="'.$details->profile_image_url.'" /><p id="statusnet-info-block">'. t('Currently connected to: ') .'<a href="'.$details->statusnet_profile_url.'" target="_statusnet">'.$details->screen_name.'</a><br /><em>'.$details->description.'</em></p></div>';
$s .= '<p>'. t('If enabled all your <strong>public</strong> postings will be posted to the associated StatusNet account as well.') .'</p>';
$s .= '<p>'. t('If enabled all your <strong>public</strong> postings will be posted to the associated StatusNet account.') .'</p>';
$s .= '<div id="statusnet-enable-wrapper">';
$s .= '<label id="statusnet-enable-label" for="statusnet-checkbox">'. t('Send public postings to StatusNet') .'</label>';
$s .= '<label id="statusnet-enable-label" for="statusnet-checkbox">'. t('Allow posting to StatusNet') .'</label>';
$s .= '<input id="statusnet-checkbox" type="checkbox" name="statusnet-enable" value="1" ' . $checked . '/>';
$s .= '<div class="clear"></div>';
$s .= '<label id="statusnet-default-label" for="statusnet-default">'. t('Send public postings to StatusNet by default') .'</label>';
$s .= '<input id="statusnet-default" type="checkbox" name="statusnet-default" value="1" ' . $defchecked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="statusnet-disconnect-wrapper">';
$s .= '<label id="statusnet-disconnect-label" for="statusnet-disconnect">'. t('Clear OAuth configuration') .'</label>';
$s .= '<input id="statusnet-disconnect" type="checkbox" name="statusnet-disconnect" value="1" />';

View File

@ -138,7 +138,7 @@ function twitter_settings(&$a,&$s) {
* which the user can request a PIN to connect the account to a
* account at Twitter.
*/
require_once('library/twitteroauth.php');
require_once('library/twitteroauth.php');
$connection = new TwitterOAuth($ckey, $csecret);
$request_token = $connection->getRequestToken();
$token = $request_token['oauth_token'];

View File

@ -0,0 +1,32 @@
<?php
function friends_widget_name() {
return "Shows profile contacts";
}
function friends_widget_help() {
return "";
}
function friends_widget_args(){
return Array();
}
function friends_widget_content(&$a, $conf){
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
WHERE `user`.`uid` = %s AND `profile`.`is-default` = 1 LIMIT 1",
intval($conf['uid'])
);
if(!count($r)) return;
$a->profile = $r[0];
$o = "";
$o .= "<style>
.f9k_widget .contact-block-div { display: block !important; float: left!important; width: 50px!important; height: 50px!important; margin: 2px!important;}
.f9k_widget #contact-block-end { clear: left; }
</style>";
$o .= _abs_url(contact_block());
$o .= "<a href='".$a->get_baseurl().'/profile/'.$a->profile['nickname']."'>". t('Connect on Friendika!') ."</a>";
return $o;
}

View File

@ -0,0 +1,22 @@
<?php
function like_widget_name() {
return "Shows likes";
}
function like_widget_help() {
return "Search first item wich contains <em>KEY</em> and print like/dislike count";
}
function like_widget_args(){
return Array("KEY");
}
function like_widget_content(&$a, $conf){
$args = explode(",",$_GET['a']);
if ($args[0]!=""){
return " #TODO like/dislike count for item with <em>" .$args[0]. "</em> # ";
} else {
return " #TODO# ";
}
}

64
addon/widgets/widgets.js Normal file
View File

@ -0,0 +1,64 @@
/**
* @author Fabio Comuni
*/
var f9a_widget_$widget_id = {
entrypoint : "$entrypoint",
key : "$key",
widgetid: "$widget_id",
argstr: "$args",
xmlhttp : null,
getXHRObj : function(){
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
this.xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
},
dorequest : function(args, cb) {
if (args===null) args = new Array();
args['k']=this.key;
args['s']=window.location;
args['a']=this.argstr;
var urlencodedargs = new Array();
for(k in args){ urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) ); }
var url = this.entrypoint + "?"+ urlencodedargs.join("&");
this.xmlhttp.open("GET", url ,true);
this.xmlhttp.send();
this.xmlhttp.obj = this;
this.xmlhttp.onreadystatechange=function(){
if (this.readyState==4){
if (this.status==200) {
cb(this.obj, this.responseText);
} else {
document.getElementById(this.obj.widgetid).innerHTML="Error loading widget.";
}
}
}
},
requestcb: function(obj, responseText) {
document.getElementById(obj.widgetid).innerHTML=responseText;
},
load : function (){
this.getXHRObj();
this.dorequest(null, this.requestcb);
}
};
(function() {
f9a_widget_$widget_id.load();
})();
document.writeln("<div id='$widget_id' class='f9k_widget'>");
document.writeln("<img id='$widget_id_ld' src='$loader'>");
document.writeln("</div>");

168
addon/widgets/widgets.php Normal file
View File

@ -0,0 +1,168 @@
<?php
/**
* widgets from friendika
*
* allow to embed info from friendika into another site
*/
function widgets_install() {
// we need some hooks, for the configuration and for sending tweets
register_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
register_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
logger("installed widgets");
}
function widgets_settings_post(){
if (isset($_POST['widgets-submit'])){
del_pconfig(local_user(), 'widgets', 'key');
}
}
function widgets_settings(&$a,&$o) {
if(! local_user())
return;
$key = get_pconfig(local_user(), 'widgets', 'key' );
if ($key=='') { $key = mt_rand(); set_pconfig(local_user(), 'widgets', 'key', $key); }
$o .='<h3 class="settings-heading">Widgets</h3>';
$o.='
<div id="settings-username-wrapper">
'. t('Widgets key: ') .'<strong>'.$key.'</strong>
</div>
<div id="settings-username-end"></div>
<div class="settings-submit-wrapper">
<input type="submit" value="'.t('Generate new key').'" class="settings-submit" name="widgets-submit">
</div>';
$o.='<h4>Widgets:</h4>';
$o .= '<ul>';
$d = dir(dirname(__file__));
while(false !== ($f = $d->read())) {
if(substr($f,0,7)=="widget_") {
preg_match("|widget_([^.]+).php|", $f, $m);
$w=$m[1];
require_once($f);
$o.='<li><a href="'.$a->get_baseurl().'/widgets/'.$w.'/?k='.$key.'&p=1">'. call_user_func($w."_widget_name") .'</a></li>';
}
}
$o .= '</ul>';
}
function widgets_module() {
return;
}
function _abs_url($s){
$a = get_app();
return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->get_baseurl()."/\$2", $s);
}
function widgets_content(&$a) {
if (!isset($_GET['k'])) {
if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
return;
}
$r = q("SELECT * FROM pconfig WHERE uid IN (SELECT uid FROM pconfig WHERE v='%s')AND cat='widgets'",
dbesc($_GET['k'])
);
if (!count($r)){
if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
return;
}
$conf = array();
$conf['uid'] = $r[0]['uid'];
foreach($r as $e) { $conf[$e['k']]=$e['v']; }
$o = "";
$widgetfile =dirname(__file__)."/widget_".$a->argv[1].".php";
if (file_exists($widgetfile)){
require_once($widgetfile);
} else {
if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
return;
}
//echo "<pre>"; var_dump($a->argv); die();
if ($a->argv[2]=="cb"){
/*if (!local_user()){
if (!isset($_GET['s']))
{header('HTTP/1.0 400 Bad Request'); killme();}
if (substr($_GET['s'],0,strlen($conf['site'])) !== $conf['site'])
{header('HTTP/1.0 400 Bad Request'); killme();}
} */
$o .= call_user_func($a->argv[1].'_widget_content',$a, $conf);
} else {
if (isset($_GET['p']) && local_user()==$conf['uid'] ) {
$o .= "<style>.f9k_widget { float: left;border:1px solid black; }</style>";
$o .= "<h1>Preview Widget</h1>";
$o .= '<a href="'.$a->get_baseurl().'/settings/addon">'. t("Plugin Settings") .'</a>';
$o .= "<h4>".call_user_func($a->argv[1].'_widget_name')."</h4>";
$o .= call_user_func($a->argv[1].'_widget_help');
$o .= "<br style='clear:left'/><br/>";
$o .= "<script>";
} else {
header("content-type: application/x-javascript");
}
$script = file_get_contents(dirname(__file__)."/widgets.js");
$o .= replace_macros($script, array(
'$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
'$key' => $conf['key'],
'$widget_id' => 'f9k_'.$a->argv[1]."_".time(),
'$loader' => $a->get_baseurl()."/images/rotator.gif",
'$args' => (isset($_GET['a'])?$_GET['a']:''),
));
if (isset($_GET['p'])) {
$jsargs = implode("</em>,<em>", call_user_func($a->argv[1].'_widget_args'));
if ($jsargs!='') $jsargs = "&a=<em>".$jsargs."</em>";
$o .= "</script>
<br style='clear:left'/><br/>
<h4>Copy and paste this code</h4>
<code>"
.htmlspecialchars('<script src="'.$a->get_baseurl().'/widgets/'.$a->argv[1].'?k='.$conf['key'])
.$jsargs
.htmlspecialchars('"></script>')
."</code>";
return $o;
}
}
echo $o;
killme();
}
?>

475
boot.php
View File

@ -1,15 +1,27 @@
<?php
set_time_limit(0);
ini_set('pcre.backtrack_limit', 250000);
define ( 'FRIENDIKA_VERSION', '2.1.915' );
define ( 'DFRN_PROTOCOL_VERSION', '2.1' );
define ( 'DB_UPDATE_VERSION', 1040 );
define ( 'FRIENDIKA_VERSION', '2.2.987' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
define ( 'DB_UPDATE_VERSION', 1054 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
define ( 'DOWN_ARROW', '&#x21e9;' );
/**
*
* Image storage quality. Lower numbers save space at cost of image detail.
* For ease of upgrade, please do not change here. Change jpeg quality with
* set_config('system','jpeg_quality',n) in .htconfig.php
* where n is netween 1 and 100, and with very poor results below about 50
*
*/
define ( 'JPEG_QUALITY', 100 );
/**
* SSL redirection policies
@ -73,6 +85,18 @@ define ( 'PAGE_SOAPBOX', 1 );
define ( 'PAGE_COMMUNITY', 2 );
define ( 'PAGE_FREELOVE', 3 );
/**
* Network and protocol family types
*/
define ( 'NETWORK_DFRN', 'dfrn'); // Friendika, Mistpark, other DFRN implementations
define ( 'NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations
define ( 'NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol
define ( 'NETWORK_DIASPORA', 'dspr'); // Diaspora
define ( 'NETWORK_MAIL', 'mail'); // IMAP/POP
define ( 'NETWORK_FACEBOOK', 'face'); // Facebook API
/**
* Maximum number of "people who like (or don't like) this" that we will list by name
*/
@ -159,6 +183,11 @@ if (get_magic_quotes_gpc()) {
unset($process);
}
/*
* translation system
*/
require_once("include/pgettext.php");
/**
*
@ -184,6 +213,8 @@ class App {
public $user;
public $cid;
public $contact;
public $contacts;
public $page_contact;
public $content;
public $data;
public $error = false;
@ -259,7 +290,7 @@ class App {
$this->argv = explode('/',$this->cmd);
$this->argc = count($this->argv);
if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
$this->module = $this->argv[0];
$this->module = str_replace(".", "_", $this->argv[0]);
}
else {
$this->module = 'home';
@ -272,7 +303,7 @@ class App {
if($this->cmd === '.well-known/host-meta') {
require_once('include/hostxrd.php');
hostxrd($this->hostname);
hostxrd($this->get_baseurl());
// NOTREACHED
}
@ -347,10 +378,12 @@ class App {
function init_pagehead() {
$this->page['title'] = $this->config['sitename'];
$tpl = load_view_file("view/head.tpl");
$tpl = file_get_contents('view/head.tpl');
$this->page['htmlhead'] = replace_macros($tpl,array(
'$baseurl' => $this->get_baseurl() . '/',
'$generator' => 'Friendika' . ' ' . FRIENDIKA_VERSION
'$baseurl' => $this->get_baseurl(),
'$generator' => 'Friendika' . ' ' . FRIENDIKA_VERSION,
'$delitem' => t('Delete this item?'),
'$comment' => t('Comment')
));
}
@ -430,15 +463,18 @@ function check_config(&$a) {
load_config('system');
if(! x($_SERVER,'SERVER_NAME'))
return;
$build = get_config('system','build');
if(! x($build))
$build = set_config('system','build',DB_UPDATE_VERSION);
$url = get_config('system','url');
if(! x($url))
// if the url isn't set or the stored url is radically different
// than the currently visited url, store the current value accordingly.
// "Radically different" ignores common variations such as http vs https
// and www.example.com vs example.com.
if((! x($url)) || (! link_compare($url,$a->get_baseurl())))
$url = set_config('system','url',$a->get_baseurl());
if($build != DB_UPDATE_VERSION) {
@ -585,44 +621,17 @@ function reload_plugins() {
// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
// depending on the order in which they were declared in the array.
require_once("include/template_processor.php");
if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
global $t;
return $t->replace($s,$r);
$search = array();
$replace = array();
if(is_array($r) && count($r)) {
foreach ($r as $k => $v ) {
$search[] = $k;
$replace[] = $v;
}
}
return str_replace($search,$replace,$s);
}}
// load string translation table for alternate language
if(! function_exists('load_translation_table')) {
function load_translation_table($lang) {
global $a;
if(file_exists("view/$lang/strings.php"))
include("view/$lang/strings.php");
}}
// translate string if translation exists
if(! function_exists('t')) {
function t($s) {
$a = get_app();
if(x($a->strings,$s))
return $a->strings[$s];
return $s;
}}
// curl wrapper. If binary flag is true, return binary
// results.
@ -819,7 +828,7 @@ function escape_tags($string) {
if(! function_exists('login')) {
function login($register = false) {
$o = "";
$register_tpl = (($register) ? load_view_file("view/register-link.tpl") : "");
$register_tpl = (($register) ? get_markup_template("register-link.tpl") : "");
$register_html = replace_macros($register_tpl,array(
'$title' => t('Create a New Account'),
@ -843,14 +852,16 @@ function login($register = false) {
$lostlink = t('Password Reset');
if(local_user()) {
$tpl = load_view_file("view/logout.tpl");
$tpl = get_markup_template("logout.tpl");
}
else {
$tpl = load_view_file("view/login.tpl");
$tpl = get_markup_template("login.tpl");
}
$o = replace_macros($tpl,array(
$o = '<script type="text/javascript"> $(document).ready(function() { $("#login-name").focus();} );</script>';
$o .= replace_macros($tpl,array(
'$logout' => t('Logout'),
'$register_html' => $register_html,
'$classname' => $classname,
@ -1085,6 +1096,7 @@ function paginate(&$a) {
$stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string);
$stripped = str_replace('q=','',$stripped);
$stripped = trim($stripped,'/');
$pagenum = $a->pager['page'];
$url = $a->get_baseurl() . '/' . $stripped;
@ -1097,7 +1109,7 @@ function paginate(&$a) {
$numpages = $a->pager['total'] / $a->pager['itemspage'];
$numstart = 1;
$numstart = 1;
$numstop = $numpages;
if($numpages > 14) {
@ -1221,6 +1233,7 @@ function set_config($family,$key,$value) {
global $a;
if(get_config($family,$key,true) === false) {
$a->config[$family][$key] = $value;
$ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
dbesc($family),
dbesc($key),
@ -1315,6 +1328,7 @@ function set_pconfig($uid,$family,$key,$value) {
global $a;
if(get_pconfig($uid,$family,$key,true) === false) {
$a->config[$uid][$family][$key] = $value;
$ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' ) ",
intval($uid),
dbesc($family),
@ -1492,7 +1506,9 @@ function lrdd($uri) {
return array();
logger('lrdd: host_meta: ' . $xml, LOGGER_DATA);
$h = simplexml_load_string($xml);
$h = parse_xml_string($xml);
$arr = convert_xml_element_to_array($h);
if(isset($arr['xrd']['property'])) {
@ -1564,16 +1580,19 @@ function lrdd($uri) {
$headers = $a->get_curl_headers();
logger('lrdd: headers=' . $headers, LOGGER_DEBUG);
require_once('library/HTML5/Parser.php');
$dom = @HTML5_Parser::parse($html);
// don't try and parse raw xml as html
if(! strstr($html,'<?xml')) {
require_once('library/HTML5/Parser.php');
$dom = @HTML5_Parser::parse($html);
if($dom) {
$items = $dom->getElementsByTagName('link');
foreach($items as $item) {
$x = $item->getAttribute('rel');
if($x == "lrdd") {
$pagelink = $item->getAttribute('href');
break;
if($dom) {
$items = $dom->getElementsByTagName('link');
foreach($items as $item) {
$x = $item->getAttribute('rel');
if($x == "lrdd") {
$pagelink = $item->getAttribute('href');
break;
}
}
}
}
@ -1620,9 +1639,15 @@ function lrdd($uri) {
if(! function_exists('fetch_lrdd_template')) {
function fetch_lrdd_template($host) {
$tpl = '';
$url = 'http://' . $host . '/.well-known/host-meta' ;
$links = fetch_xrd_links($url);
logger('template: ' . print_r($links,true));
$url1 = 'https://' . $host . '/.well-known/host-meta' ;
$url2 = 'http://' . $host . '/.well-known/host-meta' ;
$links = fetch_xrd_links($url1);
logger('template (https): ' . print_r($links,true));
if(! count($links)) {
$links = fetch_xrd_links($url2);
logger('template (http): ' . print_r($links,true));
}
if(count($links)) {
foreach($links as $link)
if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd')
@ -1646,7 +1671,7 @@ function fetch_xrd_links($url) {
return array();
logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
$h = simplexml_load_string($xml);
$h = parse_xml_string($xml);
$arr = convert_xml_element_to_array($h);
$links = array();
@ -1834,51 +1859,62 @@ function allowed_email($email) {
return $found;
}}
// Format the like/dislike text for a profile item
// $cnt = number of people who like/dislike the item
// $arr = array of pre-linked names of likers/dislikers
// $type = one of 'like, 'dislike'
// $id = item id
// returns formatted text
if(! function_exists('format_like')) {
function format_like($cnt,$arr,$type,$id) {
$o = '';
if($cnt == 1)
$o .= $arr[0] . (($type === 'like') ? t(' likes this.') : t(' doesn\'t like this.')) . EOL ;
else {
$o .= '<span class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');" >'
. $cnt . ' ' . t('people') . '</span> ' . (($type === 'like') ? t('like this.') : t('don\'t like this.')) . EOL ;
$total = count($arr);
if($total >= MAX_LIKERS)
$arr = array_slice($arr, 0, MAX_LIKERS - 1);
if($total < MAX_LIKERS)
$arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
$str = implode(', ', $arr);
if($total >= MAX_LIKERS)
$str .= t(', and ') . $total - MAX_LIKERS . t(' other people');
$str .= (($type === 'like') ? t(' like this.') : t(' don\'t like this.'));
$o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
}
return $o;
}}
// wrapper to load a view template, checking for alternate
// languages before falling back to the default
// obsolete, deprecated.
if(! function_exists('load_view_file')) {
function load_view_file($s) {
global $lang, $a;
if(! isset($lang))
$lang = 'en';
$b = basename($s);
$d = dirname($s);
$lang = get_config('system','language');
if($lang === false)
$lang = 'en';
if(file_exists("$d/$lang/$b"))
return file_get_contents("$d/$lang/$b");
$theme = current_theme();
if(file_exists("$d/theme/$theme/$b"))
return file_get_contents("$d/theme/$theme/$b");
return file_get_contents($s);
}}
if(! function_exists('get_intltext_template')) {
function get_intltext_template($s) {
global $lang;
if(! isset($lang))
$lang = 'en';
if(file_exists("view/$lang/$s"))
return file_get_contents("view/$lang/$s");
elseif(file_exists("view/en/$s"))
return file_get_contents("view/en/$s");
else
return file_get_contents("view/$s");
}}
if(! function_exists('get_markup_template')) {
function get_markup_template($s) {
$theme = current_theme();
if(file_exists("view/theme/$theme/$s"))
return file_get_contents("view/theme/$theme/$s");
else
return file_get_contents("view/$s");
}}
// for html,xml parsing - let's say you've got
// an attribute foobar="class1 class2 class3"
// and you want to find out if it contains 'class3'.
@ -1959,29 +1995,6 @@ return str_replace ("%","=",rawurlencode($s));
}}
if(! function_exists('like_puller')) {
function like_puller($a,$item,&$arr,$mode) {
$url = '';
$sparkle = '';
$verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
$url = $item['author-link'];
if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
$url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
$sparkle = ' class="sparkle" ';
}
if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
$arr[$item['parent'] . '-l'] = array();
if(! isset($arr[$item['parent']]))
$arr[$item['parent']] = 1;
else
$arr[$item['parent']] ++;
$arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
}
return;
}}
if(! function_exists('get_mentions')) {
function get_mentions($item) {
@ -2026,20 +2039,9 @@ function contact_block() {
intval($shown)
);
if(count($r)) {
$o .= '<h4 class="contact-h4">' . $total . ' ' . t('Contacts') . '</h4><div id="contact-block">';
$o .= '<h4 class="contact-h4">' . sprintf( tt('%d Contact','%d Contacts', $total),$total) . '</h4><div id="contact-block">';
foreach($r as $rr) {
$redirect_url = $a->get_baseurl() . '/redir/' . $rr['id'];
if(local_user() && ($rr['uid'] == local_user())
&& ($rr['network'] === 'dfrn')) {
$url = $redirect_url;
$sparkle = ' sparkle';
}
else {
$url = $rr['url'];
$sparkle = '';
}
$o .= '<div class="contact-block-div"><a class="contact-block-link' . $sparkle . '" href="' . $url . '" ><img class="contact-block-img' . $sparkle . '" src="' . $rr['micro'] . '" title="' . $rr['name'] . ' [' . $rr['url'] . ']" alt="' . $rr['name'] . '" /></a></div>' . "\r\n";
$o .= micropro($rr,true,'mpfriend');
}
$o .= '</div><div id="contact-block-end"></div>';
$o .= '<div id="viewcontacts"><a id="viewcontacts-link" href="viewcontacts/' . $a->profile['nickname'] . '">' . t('View Contacts') . '</a></div>';
@ -2053,6 +2055,44 @@ function contact_block() {
}}
if(! function_exists('micropro')) {
function micropro($contact, $redirect = false, $class = '', $textmode = false) {
if($class)
$class = ' ' . $class;
$url = $contact['url'];
$sparkle = '';
if($redirect) {
$a = get_app();
$redirect_url = $a->get_baseurl() . '/redir/' . $contact['id'];
if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) {
$url = $redirect_url;
$sparkle = ' sparkle';
}
}
$click = ((x($contact,'click')) ? ' onclick="' . $contact['click'] . '" ' : '');
if($click)
$url = '';
if($textmode) {
return '<div class="contact-block-textdiv' . $class . '"><a class="contact-block-link' . $class . $sparkle
. (($click) ? ' fakelink' : '') . '" '
. (($url) ? ' href="' . $url . '"' : '') . $click
. '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
. '" >'. $contact['name'] . '</a></div>' . "\r\n";
}
else {
return '<div class="contact-block-div' . $class . '"><a class="contact-block-link' . $class . $sparkle
. (($click) ? ' fakelink' : '') . '" '
. (($url) ? ' href="' . $url . '"' : '') . $click . ' ><img class="contact-block-img' . $class . $sparkle . '" src="'
. $contact['micro'] . '" title="' . $contact['name'] . ' [' . $contact['url'] . ']" alt="' . $contact['name']
. '" /></a></div>' . "\r\n";
}
}}
if(! function_exists('search')) {
function search($s) {
$a = get_app();
@ -2144,7 +2184,7 @@ function smilies($s) {
$a = get_app();
return str_replace(
array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O'),
array(
'<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
@ -2154,6 +2194,7 @@ function smilies($s) {
'<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
@ -2271,8 +2312,15 @@ function profile_sidebar($profile) {
$photo = '<div id="profile-photo-wrapper"><img class="photo" src="' . $profile['photo'] . '" alt="' . $profile['name'] . '" /></div>';
// don't show connect link to yourself
$connect = (($profile['uid'] != local_user()) ? '<li><a id="dfrn-request-link" href="dfrn_request/' . $profile['nickname'] . '">' . t('Connect') . '</a></li>' : '');
// don't show connect link to authenticated visitors either
if((remote_user()) && ($_SESSION['visitor_visiting'] == $profile['uid']))
$connect = '';
if((x($profile,'address') == 1)
|| (x($profile,'locality') == 1)
|| (x($profile,'region') == 1)
@ -2297,11 +2345,11 @@ function profile_sidebar($profile) {
$pubkey = ((x($profile,'pubkey') == 1) ? '<div class="key" style="display:none;">' . $profile['pubkey'] . '</div>' : '');
$marital = ((x($profile,'marital') == 1) ? '<div class="marital"><span class="marital-label"><span class="heart">&hearts;</span> ' . t('Status:') . ' </span><span class="marital-text">' . $profile['marital'] . '</span></div></div><div class="profile-clear"></div>' : '');
$marital = ((x($profile,'marital') == 1) ? '<div class="marital"><span class="marital-label"><span class="heart">&hearts;</span> ' . t('Status:') . ' </span><span class="marital-text">' . $profile['marital'] . '</span></div><div class="profile-clear"></div>' : '');
$homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div></div><div class="profile-clear"></div>' : '');
$homepage = ((x($profile,'homepage') == 1) ? '<div class="homepage"><span class="homepage-label">' . t('Homepage:') . ' </span><span class="homepage-url">' . linkify($profile['homepage']) . '</span></div><div class="profile-clear"></div>' : '');
$tpl = load_view_file('view/profile_vcard.tpl');
$tpl = get_markup_template('profile_vcard.tpl');
$o .= replace_macros($tpl, array(
'$fullname' => $fullname,
@ -2409,9 +2457,7 @@ function get_birthdays() {
if(! local_user())
return $o;
$bd_format = get_config('system','birthday_format');
if(! $bd_format)
$bd_format = 'g A l F d' ; // 8 AM Friday January 18
$bd_format = t('g A l F d') ; // 8 AM Friday January 18
$r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid`
@ -2423,25 +2469,39 @@ function get_birthdays() {
);
if($r && count($r)) {
$o .= '<div id="birthday-wrapper"><div id="birthday-title">' . t('Birthdays this week:') . '</div>';
$o .= '<div id="birthday-adjust">' . t("\x28Adjusted for local time\x29") . '</div>';
$o .= '<div id="birthday-title-end"></div>';
$total = 0;
foreach($r as $rr)
if(strlen($rr['name']))
$total ++;
foreach($r as $rr) {
$now = strtotime('now');
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
if($total) {
$o .= '<div id="birthday-notice" class="birthday-notice fakelink" onclick=openClose(\'birthday-wrapper\'); >' . t('Birthday Reminders') . ' ' . '(' . $total . ')' . '</div>';
$o .= '<div id="birthday-wrapper" style="display: none;" ><div id="birthday-title">' . t('Birthdays this week:') . '</div>';
$o .= '<div id="birthday-adjust">' . t("\x28Adjusted for local time\x29") . '</div>';
$o .= '<div id="birthday-title-end"></div>';
$o .= '<div class="birthday-list" id="birthday-' . $rr['eid'] . '"><a class="sparkle" href="'
. $a->get_baseurl() . '/redir/' . $rr['cid'] . '">' . $rr['name'] . '</a> '
. day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '')
. '</div>' ;
foreach($r as $rr) {
if(! strlen($rr['name']))
continue;
$now = strtotime('now');
$today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false);
$o .= '<div class="birthday-list" id="birthday-' . $rr['eid'] . '"><a class="sparkle" href="'
. $a->get_baseurl() . '/redir/' . $rr['cid'] . '">' . $rr['name'] . '</a> '
. day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '')
. '</div>' ;
}
$o .= '</div></div>';
}
$o .= '</div>';
}
return $o;
}}
return $o;
if(! function_exists('normalise_link')) {
function normalise_link($url) {
$ret = str_replace(array('https:','//www.'), array('http:','//'), $url);
return(rtrim($ret,'/'));
}}
/**
@ -2457,9 +2517,7 @@ function get_birthdays() {
if(! function_exists('link_compare')) {
function link_compare($a,$b) {
$a1 = str_replace(array('https:','//www.'), array('http:','//'), $a);
$b1 = str_replace(array('https:','//www.'), array('http:','//'), $b);
if(strcasecmp($a1,$b1) === 0)
if(strcasecmp(normalise_link($a),normalise_link($b)) === 0)
return true;
return false;
}}
@ -2512,34 +2570,38 @@ function proc_run($cmd){
proc_close(proc_open($cmdline." &",array(),$foo));
}}
/*
* Return full URL to theme which is currently in effect.
* Provide a sane default if nothing is chosen or the specified theme does not exist.
*/
if(! function_exists('current_theme_url')) {
function current_theme_url() {
if(! function_exists('current_theme')) {
function current_theme(){
$app_base_themes = array('duepuntozero', 'loozah');
$a = get_app();
$system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
$theme_name = ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
$theme_name = ((is_array($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
if($theme_name && file_exists('view/theme/' . $theme_name . '/style.css'))
return($a->get_baseurl() . '/view/theme/' . $theme_name . '/style.css');
return($theme_name);
foreach($app_base_themes as $t) {
if(file_exists('view/theme/' . $t . '/style.css'))
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
}
return($t);
}
$fallback = glob('view/theme/*/style.css');
if(count($fallback))
return($a->get_baseurl() . $fallback[0]);
return (str_replace('view/theme/','', str_replace("/style.css","",$fallback[0])));
}}
/*
* Return full URL to theme which is currently in effect.
* Provide a sane default if nothing is chosen or the specified theme does not exist.
*/
if(! function_exists('current_theme_url')) {
function current_theme_url() {
global $a;
$t = current_theme();
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
}}
if(! function_exists('feed_birthday')) {
@ -2630,7 +2692,7 @@ if(! function_exists('get_plink')) {
function get_plink($item) {
$a = get_app();
$plink = (((x($item,'plink')) && (! $item['private'])) ? '<div class="wall-item-links-wrapper"><a href="'
. $item['plink'] . '" title="' . t('link to source') . '" target="external-link" ><img src="' . $a->get_baseurl() . '/images/remote-link.gif" alt="' . t('link to source') . '" /></a></div>' : '');
. $item['plink'] . '" title="' . t('link to source') . '" target="external-link" class="icon remote-link"></a></div>' : '');
return $plink;
}}
@ -2639,29 +2701,46 @@ function unamp($s) {
return str_replace('&amp;', '&', $s);
}}
if(! function_exists('extract_item_authors')) {
function extract_item_authors($arr,$uid) {
if((! $uid) || (! is_array($arr)) || (! count($arr)))
return array();
$urls = array();
foreach($arr as $rr) {
if(! in_array("'" . dbesc($rr['author-link']) . "'",$urls))
$urls[] = "'" . dbesc($rr['author-link']) . "'";
}
// pre-quoted, don't put quotes on %s
if(count($urls)) {
$r = q("SELECT `id`,`url` FROM `contact` WHERE `uid` = %d AND `url` IN ( %s ) AND `network` = 'dfrn' AND `self` = 0 AND `blocked` = 0 ",
intval($uid),
implode(',',$urls)
);
if(count($r)) {
$ret = array();
foreach($r as $rr)
$ret[$rr['url']] = $rr['id'];
return $ret;
if(! function_exists('lang_selector')) {
function lang_selector() {
global $lang;
$o .= '<div id="language-selector" style="display: none;" >';
$o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
$langs = glob('view/*/strings.php');
if(is_array($langs) && count($langs)) {
if(! in_array('view/en/strings.php',$langs))
$langs[] = 'view/en/';
foreach($langs as $l) {
$ll = substr($l,5);
$ll = substr($ll,0,strrpos($ll,'/'));
$selected = (($ll === $lang) ? ' selected="selected" ' : '');
$o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
}
}
return array();
$o .= '</select></form></div>';
return $o;
}}
if(! function_exists('parse_xml_string')) {
function parse_xml_string($s) {
if(! strstr($s,'<?xml'))
return false;
$s2 = substr($s,strpos($s,'<?xml'));
libxml_use_internal_errors(true);
$x = @simplexml_load_string($s2);
if(count(libxml_get_errors()))
foreach(libxml_get_errors() as $err)
logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
libxml_clear_errors();
return $x;
}}
if(! function_exists('is_site_admin')) {
function is_site_admin() {
$a = get_app();
if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
return true;
return false;
}}

View File

@ -64,6 +64,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
`issued-id` char(255) NOT NULL,
`dfrn-id` char(255) NOT NULL,
`url` char(255) NOT NULL,
`addr` char(255) NOT NULL,
`alias` char(255) NOT NULL,
`pubkey` text NOT NULL,
`prvkey` text NOT NULL,
@ -85,6 +86,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
`priority` tinyint(3) NOT NULL,
`blocked` tinyint(1) NOT NULL DEFAULT '1',
`readonly` tinyint(1) NOT NULL DEFAULT '0',
`writable` tinyint(1) NOT NULL DEFAULT '0',
`pending` tinyint(1) NOT NULL DEFAULT '1',
`rating` tinyint(1) NOT NULL DEFAULT '0',
`reason` text NOT NULL,
@ -164,6 +166,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`gravity` tinyint(1) NOT NULL DEFAULT '0',
`parent` int(10) unsigned NOT NULL DEFAULT '0',
`parent-uri` char(255) NOT NULL,
`extid` char(255) NOT NULL,
`thr-parent` char(255) NOT NULL,
`created` datetime NOT NULL,
`edited` datetime NOT NULL,
@ -184,6 +187,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`plink` char(255) NOT NULL,
`resource-id` char(255) NOT NULL,
`tag` mediumtext NOT NULL,
`attach` mediumtext NOT NULL,
`inform` mediumtext NOT NULL,
`location` char(255) NOT NULL,
`coord` char(255) NOT NULL,
@ -192,6 +196,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
`private` tinyint(1) NOT NULL DEFAULT '0',
`pubmail` tinyint(1) NOT NULL DEFAULT '0',
`visible` tinyint(1) NOT NULL DEFAULT '0',
`unseen` tinyint(1) NOT NULL DEFAULT '1',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
@ -204,6 +209,7 @@ CREATE TABLE IF NOT EXISTS `item` (
KEY `wall` (`wall`),
KEY `parent` (`parent`),
KEY `parent-uri` (`parent-uri`),
KEY `extid` (`extid`),
KEY `created` (`created`),
KEY `edited` (`edited`),
KEY `visible` (`visible`),
@ -297,7 +303,8 @@ CREATE TABLE IF NOT EXISTS `profile` (
`sexual` char(255) NOT NULL,
`politic` char(255) NOT NULL,
`religion` char(255) NOT NULL,
`keywords` text NOT NULL,
`pub_keywords` text NOT NULL,
`prv_keywords` text NOT NULL,
`about` text NOT NULL,
`summary` char(255) NOT NULL,
`music` text NOT NULL,
@ -314,7 +321,9 @@ CREATE TABLE IF NOT EXISTS `profile` (
`thumb` char(255) NOT NULL,
`publish` tinyint(1) NOT NULL DEFAULT '0',
`net-publish` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
FULLTEXT KEY `pub_keywords` (`pub_keywords`),
FULLTEXT KEY `prv_keywords` (`prv_keywords`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@ -363,6 +372,7 @@ CREATE TABLE IF NOT EXISTS `user` (
`email` char(255) NOT NULL,
`openid` char(255) NOT NULL,
`timezone` char(128) NOT NULL,
`language` char(32) NOT NULL DEFAULT 'en',
`register_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`login_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`default-location` char(255) NOT NULL,
@ -374,10 +384,12 @@ CREATE TABLE IF NOT EXISTS `user` (
`sprvkey` text NOT NULL,
`verified` tinyint(1) unsigned NOT NULL DEFAULT '0',
`blocked` tinyint(1) unsigned NOT NULL DEFAULT '0',
`blockwall` tinyint(1) unsigned NOT NULL DEFAULT '0',
`notify-flags` int(11) unsigned NOT NULL DEFAULT '65535',
`page-flags` int(11) unsigned NOT NULL DEFAULT '0',
`pwdreset` char(255) NOT NULL,
`maxreq` int(11) NOT NULL DEFAULT '10',
`expire` int(11) unsigned NOT NULL DEFAULT '0',
`allow_cid` mediumtext NOT NULL,
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
@ -479,3 +491,48 @@ CREATE TABLE IF NOT EXISTS `cache` (
`v` TEXT NOT NULL,
`updated` DATETIME NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `fcontact` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`url` CHAR( 255 ) NOT NULL ,
`name` CHAR( 255 ) NOT NULL ,
`photo` CHAR( 255 ) NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `ffinder` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`uid` INT UNSIGNED NOT NULL ,
`cid` INT UNSIGNED NOT NULL ,
`fid` INT UNSIGNED NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `mailacct` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`uid` INT NOT NULL,
`server` CHAR( 255 ) NOT NULL ,
`port` INT NOT NULL,
`ssltype` CHAR( 16 ) NOT NULL,
`mailbox` CHAR( 255 ) NOT NULL,
`user` CHAR( 255 ) NOT NULL ,
`pass` TEXT NOT NULL ,
`reply_to` CHAR( 255 ) NOT NULL ,
`pubmail` TINYINT(1) NOT NULL DEFAULT '0',
`last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MYISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `attach` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`uid` INT NOT NULL ,
`filetype` CHAR( 64 ) NOT NULL ,
`filesize` INT NOT NULL ,
`data` LONGBLOB NOT NULL ,
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`allow_cid` MEDIUMTEXT NOT NULL ,
`allow_gid` MEDIUMTEXT NOT NULL ,
`deny_cid` MEDIUMTEXT NOT NULL ,
`deny_gid` MEDIUMTEXT NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8;

66
doc/Account-Basics.md Normal file
View File

@ -0,0 +1,66 @@
Account Basics
==============
* [Home](help)
**Registration**
Not all Friendika sites allow open registration. If registration is allowed, you will see a "Register" link immediately below the login prompts on the site home page. Following this link will take you to the site Registration page.
*OpenID*
The first field on the Registration page is for an OpenID address. If you do not have an OpenID address or do not wish to use OpenID, leave this field blank. If you have an OpenID account elsewhere and wish to use it, enter the address into this field and click 'Register'. Friendika will attempt to extract as much information as possible from your OpenID provider and return to this page with those items already filled in.
*Your Full Name*
Please provide your full name as you would like it to be displayed on this system.
*Email Address*
Please provide a valid email address. Your email address is **never** published. We need this to send you account information and your login details. You may also occasionally receive notifications of incoming messages or items requiring your attention, but you have the ability to completely disable these once from your Settings page once you have logged in.
*Nickname*
A nickname is used to generate web addresses for many of your personal pages, and is also treated like an email address when establishing communications with others. Due to the way that the nickname is used, it has some limitations. It must contain only US-ASCII text characters and numbers, and must also start with a text character. It also must be unique on this system. This is used in many places to identify your account, and once set - cannot be changed.
*Directory Publishing*
The Registration form also allows you to choose whether or not to list your account in the online directory. This is like a "phone book" and you may choose to be unlisted. We recommend that you select 'Yes' so that other people (friends, family, etc.) will be able to find you. If you choose 'No', you will essentially be invisible and have few opportunities for interaction. Whichever you choose, this can be changed any time from your Settings page after you login.
*Register*
Once you have provided the necessary details, click the 'Register' button. An email will be sent to you providing your account login details. Some sites may require administrator approval before the registration is processed, and you will be alerted if this is the case. Please watch your email (including spam folders) for your registration approval.
**Login Page**
On the 'Login' page, please enter your login information that was provided during registration. You may use either your nickname or email address as a Login Name.
If you use your account to manage multiple '[Pages](help/Pages)' and these all have the same email address, please enter the nickname for the account you wish to manage.
*If* your account has been OpenID enabled, you may use your OpenID address as a login name and leave the password blank. You will be redirected to your OpenID provider to complete your authorisation.
Otherwise, enter your password. This will have been initially provided in your registration email message. Your password is case-sensitive, so please check your 'Caps Lock' key if you are having difficulty logging in.
**Changing Your Password**
After your first login, please visit the 'Settings' page from the top menu bar and change your password to something that you will remember.
**See Also**
* [Profiles](help/Profiles)
* [Groups and Privacy](help/Groups-and-Privacy)
* [Remove Account](help/Remove-Account)

30
doc/Bugs-and-Issues.md Normal file
View File

@ -0,0 +1,30 @@
Bugs and Issues
===============
* [Home](help)
Please report any bugs/issues you encounter using our bug tracker at [[http://bugs.friendika.com]]
Try to provide as much information as you can about the bug (including the full text of any error messages or notices), and if possible your Friendika version.
Your Friendika version may be found in newer releases by visiting http://YOURFRIENDIKASITE/friendika
For older versions, view the HTML source of your profile page. The Friendika version is in the HTML header, 5-10 lines from the top of the page.
For really old versions which don't have a version number in the HTML header - please upgrade. Your bug was probably fixed a long time ago.
**Bug Sponsorship**
The bug/issue database allows you to sponsor issues. This provides an incentive for developers to work on your issue. This isn't necessary - we don't like bugs and will try to fix them. This has more importance for future development projects and feature requests.
Bug sponsorship works on the honour system. If you agree to pay $10 to fix a bug, when the fix has been checked in and verified you should send a paypal payment to the developer assigned to the bug. Don't ever think you can get away with not paying a developer for work performed. Some of these guys could hack into your credit card account if you make them mad.
At the present time, one has to be approved as a "developer" to be able to assign themselves to a sponsored bug. This requires the developer to have some history fixing Friendika bugs. This is for everybody's assurance that the bug fix will work well with Friendika. If you wish to become approved as a developer, work on and check in some non-sponsored issues or your own projects and we will move you up the ladder.
If you truly feel you have the solution to a sponsored bug but aren't an approved developer, you risk a sponsored developer assigning the bug to themselves before you check it in, but if they haven't done so - include a short note with your pull request. Assuming that it meets our code standards, we'll see that you get credit.
If you sponsor a project at greater than a $50 level, you may be requested by the developer for payment up front before work has begun (typically half). Again this is on the honour system - and is mostly to avoid payment issues and disagreements later. You should also expect to see some progress updates or demonstrations if the work takes more than a week or two. If the work is not completed within a reasonable time (as decided by those involved), you are entitled to get your money back.
Friendika is not involved in these transactions. It is purely a personal agreement between sponsors and developers. If there are any issues, the parties will need to work it out between themselves. We're just providing some guidelines to help avoid potential problems.

63
doc/Connectors.md Normal file
View File

@ -0,0 +1,63 @@
Connectors
==========
* [Home](help)
Connectors allow you to connect with external social networks and services. Connectors are only required for posting to existing accounts on Facebook, Twitter, and StatusNet. There is also a connector for accessing your email INBOX.
If the following network connectors are installed on your system, select the following links to visit the appropriate settings page and configure them for your account:
* [Facebook](/settings/addon)
* [Twitter](/settings/addon)
* [StatusNet](/settings/addon)
* [Email](/settings)
Instructions For Connecting To People On Specific Services
==========================================================
**Friendika**
You may connect by providing your Identity Address on the 'Connect' page of any Friendika member. You may also put their Identity Address into the Connect box on your [Contacts](contacts) page.
**Identi.ca/StatusNet/GNU-Social**
These are described as the "federated social web" or OStatus contacts.
Please note that there are **no** privacy provisions on the OStatus network. Any message which is delivered to **any** OStatus member is visible to anybody in the world and will negate any privacy settings that you have in effect. These messages will also turn up in public searches.
To connect with an OStatus member insert their profile URL or Identity address into the Connect box on your [Contacts](contacts) page.
The StatusNet connector may be used if you wish posts to appear on an OStatus site using an existing OStatus account.
It is not necessary to do this, as you may 'follow' OStatus members from Friendika and they may follow you (by placing their own Identity Address into your 'Connect' page).
**Blogger, Wordpress, RSS feeds, arbitrary web pages**
Put the URL into the Connect box on your [Contacts](contacts) page. You will not be able to reply to these contacts.
This will allow you to _connect_ with millions of pages on the internet. All that we require to do this is that the page use a discoverable feed using either the RSS or Atom syndication format, and which provides an author name and a site image in a form which we can extract.
**Twitter**
To follow a Twitter member, put the URL of the Twitter member's main page into the Connect box on your [Contacts](contacts) page. To reply, you must have the Twitter connector installed, and reply using your own status editor. Begin the message with @twitterperson replacing with the Twitter username.
**Diaspora**
To follow a Diaspora member, put either the URL or the pod address (Identity Address) of the Diaspora member into the Connect box on your [Contacts](contacts) page. It is not currently possible to reply to Diaspora members. This will be provided in a future release (once the Diaspora communication protocols stabilise and are published).
**Email**
Configure the email connector from your [Settings](settings) page. Once this has been done, you may enter an email addres to connect with using the Connect box on your [Contacts](contacts) page. They must be the sender of a message which is currently in your INBOX for the connect to succeed. You may include email contacts in private conversations.
**Facebook**
The Facebook connector is a plugin/addon which allows you to interact with friends on Facebook from within Friendika. If enabled, your Facebook friend list will be imported, and you will see and be able to respond to Facebook posts. Facebook members may also be added to private conversation groups. You will not be able to connect with individual Facebook accounts - but will have your entire friend list imported and updated if new friends are added.
Assuming the Facebook plugin/addon has been installed on your system, it can be enabled by going to your [Plugin Settings](settings/addon) page, and then select "Facebook Connector Settings" on that page. This will only appear if the Facebook plugin/addon has been installed. Follow the instruction to install or remove the Facebook connector.
You may also choose whether your public postings are posted to Facebook by default. You may toggle this setting at any time from the Permissions settings of the status post editor (click the lock icon). This setting has no effect on private conversations - which will always be delivered to Facebook friends who are included in the permissions.
(Note: At this time, Facebook contacts will not be able to view any private photos. This will be resolved in a future release. Facebook contacts may however see any public photos you have uploaded.)

22
doc/Developers.md Normal file
View File

@ -0,0 +1,22 @@
Friendika Developer Guide
Here is how you can join us.
First, get yourself a working git package on the system where you will be
doing development.
Create your own github account.
You may fork/clone the Friendika repository from [https://github.com/friendika/friendika.git](https://github.com/friendika/friendika.git).
Follow the instructions provided here: [http://help.github.com/fork-a-repo/](http://help.github.com/fork-a-repo/)
to create and use your own tracking fork on github
Then go to your github page and create a "Pull request" when you are ready
to notify us to merge your work.
**Important**
Please pull in any changes from the project repository and merge them with your work **before** issuing a pull request. We reserve the right to reject any patch which results in a large number of merge conflicts. This is especially true in the case of language translations - where we may not be able to understand the subtle differences between conflicting versions.
Also - **test your changes**. Don't assume that a simple fix won't break something else. If possible get an experienced Friendika developer to review the code.

36
doc/Groups-and-Privacy.md Normal file
View File

@ -0,0 +1,36 @@
Groups and Privacy
==================
* [Home](help)
Groups are merely collections of friends. But Friendika uses these to unlock some very powerful features.
To create a group, visit your Friendika "Contacts" page and select "Create a new group". Give the group a name.
This brings you to a page where you can select the group members.
You will have two boxes on this page. The top box is the roster of current group members. Below that is another box containing all of your friends who are *not* members of the group.
If you click on a photo of a person who isn't in the group, they will be put into the group. If you click on a photo of a person who is in the group, they will be removed from it.
Once you have created a group, you may use it in any access control list. This is the little lock icon beneath the status update box on your home page. If you click this you can select who can see and who can *not* see the post you are about to make. These can be individual people or groups.
On your "Network" page you will find posts and conversation from everybody in your network. You may select an individual group on this page to show conversations pertaining only to members of that group.
But wait, there's more...
If you look carefully when visiting a group from your Network page, the lock icon under the status update box has an exclamation mark next to it. This is meant to draw attention to that lock. Click the lock. You will see that since you are only viewing a certain group of people, your status updates while on that screen default to only being seen by that same group of people. This is how you keep your future employers from seeing what you write to your drinking buddies. You can over-ride this setting, but this makes it easy to separate your conversations into different friend circles.
These private conversations work best when your friends are Freindika members. We know who else can see the conversations - nobody, *unless* your friends cut and paste the messages and send them to others.
This is a trust issue you need to be aware of. No software in the world can prevent your friends from leaking your confidential and trusted communications. Only a wise choice of friends.
But it isn't as clear cut when dealing with status.net, identi.ca and other network providers. You are encouraged to be **very** cautious when other network members are in a group because it's entirely possible for your private messages to end up in a public newsfeed. If you look at the Contact Edit page for any person, we will tell you whether or not they are members of an insecure network where you should exercise caution.
On your "Settings" page, you may create a set of default permissions which apply to every post that you create.
Once you have created a post, you can not change the permissions assigned. Within seconds it has been delivered to lots of people - and perhaps everybody it was addressed to. If you mistakenly created a message and wish you could take it back, the best you can do is to delete it. We will send out a delete notification to everybody who received the message - and this should wipe out the message with the same speed it was initially propagated. In most cases it will be completely wiped from the Internet - in under a minute. Again, this applies to Friendika networks. Once a message spreads to other networks, it may not be removed quickly and in some cases it may not be removed at all.
In case you haven't yet figured this out, we are encouraging you to encourage your friends to use Friendika - because all these privacy features work much better within a privacy-aware network. Many of the other social networks Friendika can connect to have no privacy controls.

36
doc/Home.md Normal file
View File

@ -0,0 +1,36 @@
Friendika Documentation and Resources
=====================================
**Contents**
* [Account Basics](help/Account-Basics)
* [Profiles](help/Profiles)
* [Connectors](help/Connectors)
* [Making Friends](help/Making-Friends)
* [Groups and Privacy](help/Groups-and-Privacy)
* [Tags and Mentions](help/Tags-and-Mentions)
* [Pages](help/Pages)
* [Remove Account](help/Remove-Account)
* [Bugs and Issues](help/Bugs-and-Issues)
**Technical Documentation**
* [Install](help/Install)
* [Settings](help/Settings)
* [Plugins](help/Plugins)
* [Installing Connectors (Facebook/Twitter/StatusNet)](help/Installing-Connectors)
* [Message Flow](help/Message-Flow)
* [Developers](help/Developers)
**External Resources**
* [Main Website](http://friendika.com)
* [Forums](http://groups.google.com/group/friendika)
* [Developer Forums](http://groups.google.com/group/friendika-dev)
**About**
* [Site/Version Info](friendika)

97
doc/Install.md Normal file
View File

@ -0,0 +1,97 @@
Friendika Installation
We've tried very hard to ensure that Friendika will run on commodity hosting platforms - such as those used to host Wordpress blogs and Drupal websites. But be aware that Friendika is more than a simple web application. It is a complex communications system which more closely resembles an email server than a web server. For reliability and performance, messages are delivered in the background and are queued for later delivery when sites are down. This kind of functionality requires a bit more of the host system than the typical blog. Not every PHP/MySQL hosting provider will be able to support Friendika. Many will. But **please** review the requirements and confirm these with your hosting provider prior to installation.
Also if you encounter installation issues, please let us know via the forums at http://groups.google.com/group/friendika or file an issue at http://bugs.friendika.com . Please be as clear as you can about your operating environment and provide as much detail as possible about any error messages you may see, so that we can prevent it from happening in the future. Due to the large variety of operating systems and PHP platforms in existence we may have only limited ability to debug your PHP installation or acquire any missing modules - but we will do our best to solve any general code issues.
Before you begin: Choose a domain name or subdomain name for your server. Put some thought into this - because changing it after installation is currently not-supported. Things will break, and some of your friends may have difficulty communicating with you. We plan to address this limitation in a future release.
1. Requirements
- Apache with mod-rewrite enabled and "Options All" so you can use a
local .htaccess file
- PHP 5.2+. The later the better. You'll need 5.3 for encryption of key exchange conversations. On a Windows environment, 5.2+ might not work as the function dns_get_record() is only available with version 5.3.
- PHP *command line* access with register_argc_argv set to true in the
php.ini file
- curl, gd, mysql, and openssl extensions
- some form of email server or email gateway such that PHP mail() works
- mcrypt (optional; used for server-to-server message encryption)
- Mysql 5.x
- ability to schedule jobs with cron (Linux/Mac) or Scheduled Tasks
(Windows) [Note: other options are presented in Section 7 of this document]
- Installation into a top-level domain or sub-domain (without a
directory/path component in the URL) is preferred. Directory paths will
not be as convenient to use and have not been thoroughly tested.
[Dreamhost.com offers all of the necessary hosting features at a
reasonable price. If your hosting provider doesn't allow Unix shell access,
you might have trouble getting everything to work.]
2. Unpack the Friendika files into the root of your web server document area.
- If you are able to do so, we recommend using git to clone the source repository rather than to use a packaged tar or zip file. This makes the software much easier to update. The Linux command to clone the repository into a directory "mywebsite" would be
`git clone http://github.com/friendika/friendika.git mywebsite`
and then you can pick up the latest changes at any time with
`git pull`
- If you copy the directory tree to your webserver, make sure
that you also copy .htaccess - as "dot" files are often hidden
and aren't normally copied.
3. Create an empty database and note the access details (hostname, username, password, database name).
4. Visit your website with a web browser and follow the instructions. Please note any error messages and correct these before continuing.
5. *If* the automated installation fails for any reason, check the following:
- ".htconfig.php" exists ... If not, edit htconfig.php and change system settings. Rename
to .htconfig.php
- Database is populated. ... If not, import the contents of "database.sql" with phpmyadmin
or mysql command line
6. At this point visit your website again, and register your personal account.
Registration errors should all be recoverable automatically.
If you get any *critical* failure at this point, it generally indicates the
database was not installed correctly. You might wish to move/rename
.htconfig.php to another name and empty (called 'dropping') the database
tables, so that you can start fresh.
7. Set up a cron job or scheduled task to run the poller once every 5-10
minutes in order to perform background processing. Example:
`cd /base/directory; /path/to/php include/poller.php`
Change "/base/directory", and "/path/to/php" as appropriate for your situation.
If you are using a Linux server, run "crontab -e" and add a line like the
one shown, substituting for your unique paths and settings:
`*/10 * * * * cd /home/myname/mywebsite; /usr/bin/php include/poller.php`
You can generally find the location of PHP by executing "which php". If you
have troubles with this section please contact your hosting provider for
assistance. Friendika will not work correctly if you cannot perform this step.
Alternative: You may be able to use the 'poormancron' plugin to perform this step
if you are using a recent Friendika release. To do this, edit the file ".htconfig.php"
and look for a line describing your plugins. On a fresh installation, it will look like
`$a->config['system']['addon'] = 'js_upload';`
This indicates the "js_upload" addon module is enabled. You may add additional
addons/plugins using this same line in the configuration file. Change it to read
`$a->config['system']['addon'] = 'js_upload,poormancron';`
and save your changes.

View File

@ -0,0 +1,154 @@
Installing Connectors (Facebook/Twitter/StatusNet)
==================================================
* [Home](help)
Friendika uses plugins to provide connectivity to some networks, such as Facebook and Twitter.
There is also a plugin to post through to an existing account on a Status.Net service. You do not require this to communicate with Status.Net members from Friendika - only if you wish to post to an existing account.
All three of these plugins require an account on the target network. In addition you (or typically the server administrator) will need to obtain an API key to provide authenticated access to your Friendika server.
**Site Configuration**
Plugins must be installed by the site administrator before they can be use. This is accomplished through the site
configuration file ".htconfig.php".
The configuration directive looks like:
```
$a->config['system']['addon'] = ' ... list of plugins separated by commas ... ';
```
Example:
To install all of the connector addons in addition to the default Javascript photo uploader this line would look like:
```
$a->config['system']['addon'] = 'js_upload,facebook,twitter,statusnet';
```
You may also add other plugins/addons as your needs require.
Each of the connectors also requires an "API key" from the service you wish to connect with. This is also installed in the
configuration file. The method for obtaining these keys varies greatly - but almost always requires an existing account on the target service. Once installed, these API keys can usually be shared by all site members.
The details of configuring each service follows (much of this information comes directly from the plugin source files):
**Twitter Plugin for Friendika**
* Author: Tobias Diekershoff
* tobias.diekershoff@gmx.net
* License:3-clause BSD license (same as Friendika)
Configuration:
To use this plugin you need a OAuth Consumer key pair (key & secret)
you can get it from Twitter at https://twitter.com/apps
Register your Friendika site as "Client" application with "Read & Write" access.
We do not need "Twitter as login". When you've registered the app you get the
OAuth Consumer key and secret pair for your application/site.
Add this key pair to your global .htconfig.php
```
$a->config['twitter']['consumerkey'] = 'your consumer_key here';
$a->config['twitter']['consumersecret'] = 'your consumer_secret here';
```
After this, your user can configure their Twitter account settings
from "Settings -> Plugin Settings".
Documentation: http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/Twitter_Plugin
**StatusNet Plugin for Friendika**
* Author: Tobias Diekershoff
* tobias.diekershoff@gmx.net
* License:3-clause BSD license (same as Friendika)
Configuration
When the addon is activated the user has to aquire the following in order to connect to the StatusNet account of choice.
* The base URL for the StatusNet API, for identi.ca this is https://identi.ca/api/
* OAuth Consumer key & secret
To get the OAuth Consumer key pair the user has to
(a) ask her Friendika admin if a pair already exists or
(b) has to register the Friendika server as a client application on the StatusNet server.
This can be done from the account settings under "Settings -> Connections -> Register an OAuth client application -> Register new application".
During the registration of the OAuth client remember the following:
* Application names must be unique on the StatusNet site, so we recommend a Name of 'friendika-nnnn', replace 'nnnn' with a random number or your website name.
* there is no callback url
* register a desktop client
* with read & write access
* the Source URL should be the URL of your Friendika server
After the required credentials for the application are stored in the configuration you have to actually connect your Friendika account with StatusNet. This is done from the Settings -> Plugin Settings page. Follow the Sign in with StatusNet button, allow access and then copy the security code into the box provided. Friendika will then try to acquire the final OAuth credentials from the API.
If successful the addon settings will allow you to select to post your public messages to your StatusNet account (have a look behind the little lock symbol beneath the status "editor" on your Home or Network pages).
Documentation: http://diekershoff.homeunix.net/redmine/wiki/friendikaplugin/StatusNet_Plugin
**Installing the Friendika/Facebook connector**
* register an API key for your site from developer.facebook.com
This requires a Facebook account, and may require additional authentication in the form of credit card or mobile phone verification.
a. We'd be very happy if you include "Friendika" in the application name
to increase name recognition. The Friendika icons are also present
in the images directory and may be uploaded as a Facebook app icon.
Use images/friendika-16.jpg for the Icon and images/friendika-128.jpg for the Logo.
b. The url should be your site URL with a trailing slash.
You may use http://portal.friendika.com/privacy as the privacy policy
URL unless your site has different requirements, and
http://portal.friendika.com as the Terms of Service URL unless
you have different requirements. (Friendika is a software application
and does not require Terms of Service, though your installation of it might).
c. Set the following values in your .htconfig.php file
```
$a->config['facebook']['appid'] = 'xxxxxxxxxxx';
$a->config['facebook']['appsecret'] = 'xxxxxxxxxxxxxxx';
```
Replace with the settings Facebook gives you.
Visit the Facebook Settings section of the "Settings->Plugin Settings" page.
and click 'Install Facebook Connector'.
This will ask you to login to Facebook and grant permission to the
plugin to do its stuff. Allow it to do so.
You're done. To turn it off visit the Plugin Settings page again and
'Remove Facebook posting'.
Videos and embeds will not be posted if there is no other content. Links
and images will be converted to a format suitable for the Facebook API and
long posts truncated - with a link to view the full post.
Facebook contacts will also not be able to view "private" photos, as they are not able to
authenticate to your site to establish identity. We will address this
in a future release.

50
doc/Making-Friends.md Normal file
View File

@ -0,0 +1,50 @@
Making Friends
==============
* [Home](help)
Friendship in Friendika can take on a great many different meanings. But let's keep it simple, you want to be friends with somebody. How do you do it?
The first thing you can do is look at the Directory for somebody you would like to connect with. Visit their profile. Just beneath their profile picture will be the word 'Connect' (we're assuming this is an English language profile).
Click that. It will take you to a "Connect" form.
This is going to ask you for your Identity Address. This is necessary so that this person's website can find yours.
What do you put in the box?
If your Friendika site is called "demo.friendika.com" and your username/nickname on that site is "bob", you would put in "bob@demo.friendika.com".
Notice this looks just like an email address. It was meant to be that way. It's easy for people to remember.
You *could* also put in the URL of your "home" page, such as "http://demo.friendika.com/profile/bob", but the email-style address is certainly easier.
When you've submitted the connection page, it will take you back to your own site where you must then login (if necessary) and verify the connection request on *your* site. Once you've done this, the two websites can communicate with each other to complete the process (after your new friend has approved the request).
If you already know somebody's Identity Address, you can enter it in the "connect" box on your "Contacts" page. This will take you through a similar process.
**Alternate Networks**
You can also use your Identity Address or other people's Identity Addresses to become friends across networks. The list of possible networks is growing all the time. If you know (for instance) "bob" on identi.ca (a Status.Net site) you could put bob@identi.ca into your Contact page and become friends across networks. (Or you can put in the URL to Bob's identi.ca page if you wish). You can also be "partial" friends with somebody on Google Buzz by putting in their gmail address. Google Buzz does not yet support all the protocols we need for direct messaging, but you should be able to follow status updates from within Friendika. You can do the same for Twitter accounts and Diaspora accounts. In fact you can "follow" most anybody or any website that produces a syndication feed (RSS/Atom,etc.). If we can find an information stream and a name to attach to the contact, we'll try to connect with them.
If you have supplied your mailbox connection information on your Settings page, you can enter the email address of anybody that has sent you a message recently and have their email messages show up in your social stream. You can also reply to them from within Friendika.
People can also become friends with you from other networks. If a friend of yours has an identi.ca account, they can become friends with you by putting your Friendika Identity Address into their identi.ca subscription dialog box.
If this happens you will receive a notification. You will need to approve this before the friendship is complete.
Some networks allow people to send you messages without being friends and without your approval. Friendika does not allow this by default, as it would open a gateway for spam. So when you've approved a friend request from one of these networks, look at your contact page for that person (this will be displayed as soon as you approve the relationship). They might be marked as an "Ignored" contact.
This means they can see some of your posts (your public posts), but they aren't permitted to send you anything. You can "Un-ignore" them if you desire to allow them to contact you directly and to have their status updates appear in your Network feed.
When you receive a friendship notification from another Friendika member, you will have the option of allowing them as a "fan" or as a "friend". If they are a fan, they can see what you have to say, including private communications that you send to them, but not vice versa. As a friend, you can both communicate with each other.
Once you have become friends, if you find the person constantly sends you spam or worthless information, you can "Ignore" them - without breaking off the friendship or even alerting them to the fact that you aren't interested in anything they are saying. In many ways they are like a "fan" - but they don't know this. They think they are a friend.
You can also "block" a person. This completely blocks communications with that person. They may still be able to see your public posts, as can anybody in the world, but they cannot communicate with you directly in any way. They will know or be able to discover that they have been blocked but there's nothing they can do about it.
You can also delete a friend no matter what the friendship status - which complete removes everything relating to that person from your website.

54
doc/Message-Flow.md Normal file
View File

@ -0,0 +1,54 @@
Friendika Message Flow
This page attempts to document some of the details of how messages get from one person to another in the Friendika network. There are multiple paths, using multiple protocols and message formats.
Those attempting to understand these message flows should become familiar with (at the minimum) the DFRN protocol document (http://dfrn.org/dfrn.pdf) and the message passing elements of the OStatus stack (salmon and Pubsubhubbub).
Most message passing involves the file include/items.php, which has functions for several feed-related import/export activities.
When a message is posted, all immediate deliveries to all networks are made using include/notifier.php, which chooses how (and to whom) to deliver the message. This file also invokes the local side of all deliveries including DFRN-notify.
mod/dfrn_notify.php handles the remote side of DFRN-notify.
Local feeds are generated by mod/dfrn_poll.php - which also handles the remote side of DFRN-poll protocol.
Salmon notifications arrive via mod/salmon.php.
Push (pubsubhubbub) feeds arrive via mod/pubsub.php
DFRN-poll feed imports arrive via include/poller.php as a scheduled task, this implements the local side of the DFRN-poll protocol.
Scenario #1. Bob posts a public status message
This is a public message with no conversation members so no private transport is used. There are two paths it can take - as a bbcode path to DFRN clients, and converted to HTML with the server's PuSH (pubsubhubbub) hubs notified. When a PuSH hub is operational, dfrn-poll clients prefer to receive their information through the PuSH channel. They will fall back on a daily poll in case the hub has delivery issues (this is quite common when using the default Google reference hub). If there is no specified hub or hubs, DFRN clients will poll at a configurable (per-contact) rate at up to 5-minute intervals. Feeds retrieved via dfrn-poll are bbcode and may also contain private conversations which the poller has permissions to see.
Scenario #2. Jack replies to Bob's public message. Jack is on the Friendika/DFRN network.
Jack uses dfrn-notify to send a direct reply to Bob. Bob then creates a feed of the conversation and sends it to everybody involved in the conversation using dfrn-notify. PuSH hubs are notified that new content is available. The hub or hubs will then retrieve the latest feed and transmit it to all hub subscribers (which may be on different networks).
Scenario #3. Mary replies to Bob's public message. Mary is on the Friendika/DFRN network.
Mary uses dfrn-notify to send a direct reply to Bob. Bob then creates a feed of the conversation and sends it to everybody involved in the conversation (excluding himself, the conversation is now sent to both Jack and Mary). Messages are sent using dfrn-notify. Push hubs are also notified that new content is available. The hub or hubs will then retrieve the latest feed and transmit it to all hub subscribers (which may be on different networks).
Scenario #4. William replies to Bob's public message. William is on the OStatus network.
William uses salmon to notify Bob of the reply. Content is html embedded in salmon magic envelope. Bob then creates a feed of the conversation and sends it to all Friendika participants involved in the conversation using dfrn-notify (excluding himself, the conversation is sent to both Jack and Mary). Push hubs are notified that new content is available. The hub or hubs will then retrieve the latest feed and transmit it to all hub subscribers (which may be on different networks).
Scenario #5. Bob posts a private message to Mary and Jack.
Message is delivered immediately to Mary and Jack using dfrn_notify. Public hubs are not notified. Requeueing is attempted in case of timeout. Replies follow the same flow as the public replies except that hubs are not notified and message is never made available in the public feed. The entire conversation is also made available to Mary and Jack (and nobody else) through their dfrn-poll personalised feed.

28
doc/Pages.md Normal file
View File

@ -0,0 +1,28 @@
Pages
=====
* [Home](help)
Friendika also lets you create group and/or celebrity pages.
Every page in Friendika has a nickname and these must all be unique. This applies to all pages, whether they are normal profiles or group pages.
Therefore the first thing you need to do to create a new page is to register a new account for the page. Please note that the site administrator can restrict and/or regulate the registration of new accounts.
If you create a second account on a system and use the same email address or OpenID account, you will no longer be able to use the email address (or OpenID) to login to the account. You should login using the account nickname instead.
On the new account, visit the 'Settings' page. Towards the end of the page are "Advanced Page Settings". Typically you would use "Normal Account" for a normal personal account. This is the default selection. Group pages provide the ability for people to become friends/fans of the page without requiring approval.
The exact setting you would use depends on how you wish to interact with people who join the page. The "Soapbox" setting let's the page owner control all communications. Everything you post will go out to the page members, but there will be no opportunity for interaction. This setting would typically be used for announcements or corporate communications.
The most common setting is the "Community Account". This creates a group page where all members can freely interact.
The "Automatic Friend Account" is typically used for personal profile pages where you wish to automatically approve any friendship/connection requests.
**Managing Multiple Pages**
We recommend that you create group pages with the same email address and password as your normal account. If you do this, you will find a new "Manage" tab on the menu bar which lets you toggle identities easily and manage your pages. You are not required to do this, but the alternative is to logout and log back into the other account to manage alternate pages - and this could get cumbersome if you manage several different pages/identities.

289
doc/Plugins.md Normal file
View File

@ -0,0 +1,289 @@
**Friendika Addon/Plugin development**
This is an early specification and hook details may be subject to change.
Please see the sample addon 'randplace' for a working example of using some of these features. The facebook addon provides an example of integrating both "addon" and "module" functionality. Addons work by intercepting event hooks - which must be registered. Modules work by intercepting specific page requests (by URL path).
You must register all addons/plugins with the system in the .htconfig.php file.
$a->config['system']['addon'] = 'plugin1name, plugin2name, another_name';
Plugin names cannot contain spaces and are used as filenames. Each addon must contain both an install and an uninstall function based on the addon/plugin name. For instance "plugin1name_install()". These two functions take no arguments and are usually responsible for registering (and unregistering) event hooks that your plugin will require. The install and uninstall functions will also be called (i.e. re-installed) if the plugin changes after installation - therefore your uninstall should not destroy data and install should consider that data may already exist. Future extensions may provide for "setup" amd "remove".
Register your plugin hooks during installation.
register_hook($hookname, $file, $function);
$hookname is a string and corresponds to a known Friendika hook.
$file is a pathname relative to the top-level Friendika directory. This *should* be 'addon/plugin_name/plugin_name.php' in most cases.
$function is a string and is the name of the function which will be executed when the hook is called.
Your hook callback functions will be called with at least one and possibly two arguments
function myhook_function(&$a, &$b) {
}
If you wish to make changes to the calling data, you must declare them as
reference variables (with '&') during function declaration.
$a is the Friendika 'App' class - which contains a wealth of information
about the current state of Friendika, such as which module has been called,
configuration info, the page contents at the point the hook was invoked, profile
and user information, etc. It is recommeded you call this '$a' to match its usage
elsewhere.
$b can be called anything you like. This is information which is specific to the hook
currently being processed, and generally contains information that is being immediately
processed or acted on that you can use, display, or alter. Remember to declare it with
'&' if you wish to alter it.
**Modules**
Plugins/addons may also act as "modules" and intercept all page requests for a given URL path. In order for a plugin to act as a module it needs to define a function "plugin_name_module()" which takes no arguments and need not do anything.
If this function exists, you will now receive all page requests for "http://my.web.site/plugin_name" - with any number of URL components as additional arguments. These are parsed into an array $a->argv, with a corresponding $a->argc indicating the number of URL components. So http://my.web.site/plugin/arg1/arg2 would look for a module named "plugin" and pass its module functions the $a App structure (which is available to many components). This will include:
$a->argc = 3
$a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
Your module functions will often contain the function plugin_name_content(&$a), which defines and returns the page body content. They may also contain plugin_name_post(&$a) which is called before the _content function and typically handles the results of POST forms. You may also have plugin_name_init(&$a) which is called very early on and often does module initialisation.
**Current hooks:**
**'authenticate'** - called when a user attempts to login.
$b is an array
'username' => the supplied username
'password' => the supplied password
'authenticated' => set this to non-zero to authenticate the user.
'user_record' => successful authentication must also return a valid user record from the database
**'logged_in'** - called after a user has successfully logged in.
$b contains the $a->user array
**'display_item'** - called when formatting a post for display.
$b is an array
'item' => The item (array) details pulled from the database
'output' => the (string) HTML representation of this item prior to adding it to the page
**'post_local'** - called when a status post or comment is entered on the local system
$b is the item array of the information to be stored in the database
{Please note: body contents are bbcode - not HTML)
**'post_local_end'** - called when a local status post or comment has been stored on the local system
$b is the item array of the information which has just been stored in the database
{Please note: body contents are bbcode - not HTML)
**'post_remote'** - called when receiving a post from another source. This may also be used to post local activity or system generated messages.
$b is the item array of information to be stored in the database and the item
body is bbcode.
**'settings_form'** - called when generating the HTML for the user Settings page
$b is the (string) HTML of the settings page before the final '</form>' tag.
**'settings_post'** - called when the Settings pages are submitted.
$b is the $_POST array
**'plugin_settings'** - called when generating the HTML for the addon settings page
$b is the (string) HTML of the addon settings page before the final '</form>' tag.
**'plugin_settings_post'** - called when the Addon Settings pages are submitted.
$b is the $_POST array
**'profile_post'** - called when posting a profile page.
$b is the $_POST array
**'profile_edit'** - called prior to output of profile edit page
$b is array
'profile' => profile (array) record from the database
'entry' => the (string) HTML of the generated entry
**'profile_advanced'** - called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page.
$b is the (string) HTML representation of the generated profile
(The profile array details are in $a->profile)
**'directory_item'** - called from the Directory page when formatting an item for display
$b is an array
'contact' => contact (array) record for the person from the database
'entry' => the (string) HTML of the generated entry
**'profile_sidebar_enter'** - called prior to generating the sidebar "short" profile for a page
$b is (array) the person's profile array
**'profile_sidebar'** - called when generating the sidebar "short" profile for a page
$b is an array
'profile' => profile (array) record for the person from the database
'entry' => the (string) HTML of the generated entry
**'contact_block_end'** - called when formatting the block of contacts/friends on a profile sidebar has completed
$b is an array
'contacts' => array of contacts
'output' => the (string) generated HTML of the contact block
**'bbcode'** - called during conversion of bbcode to html
$b is (string) converted text
**'html2bbcode'** - called during conversion of html to bbcode (e.g. remote message posting)
$b is (string) converted text
**'page_header'** - called after building the page navigation section
$b is (string) HTML of nav region
**'personal_xrd'** - called prior to output of personal XRD file.
$b is an array
'user' => the user record for the person
'xml' => the complete XML to be output
**'home_content'** - called prior to output home page content, shown to unlogged users
$b is (string) HTML of section region
**'contact_edit'** - called when editing contact details on an individual from the Contacts page
$b is (array)
'contact' => contact record (array) of target contact
'output' => the (string) generated HTML of the contact edit page
**'contact_edit_post'** - called when posting the contact edit page
$b is the $_POST array
**'init_1'** - called just after DB has been opened and before session start
$b is not used or passed
**'page_end'** - called after HTML content functions have completed
$b is (string) HTML of content div
*** = subject to change
Not yet documented (you may view these within the source code):
**'atom_feed'** ***
**'atom_feed_end'** ***
**'parse_atom'** ***
**'atom_author'** ***
**'atom_entry'** ***
A complete list of all hook callbacks with file locations (generated 22-Feb-2011): Please see the source for details of any hooks not documented above.
boot.php: call_hooks('contact_block_end', $arr);
boot.php: call_hooks('profile_sidebar_enter', $profile);
boot.php: call_hooks('profile_sidebar', $arr);
boot.php: call_hooks("proc_run", $args);
include/nav.php: call_hooks('page_header', $a->page['nav']);
include/auth.php: call_hooks('authenticate', $addon_auth);
include/auth.php: call_hooks('logged_in', $a->user);
include/bbcode.php: call_hooks('bbcode',$Text);
include/acl_selectors.php: call_hooks($a->module . '_pre_' . $selname, $arr);
include/acl_selectors.php: call_hooks($a->module . '_post_' . $selname, $o);
include/acl_selectors.php: call_hooks($a->module . '_pre_' . $selname, $arr);
include/acl_selectors.php: call_hooks($a->module . '_post_' . $selname, $o);
include/items.php: call_hooks('atom_feed', $atom);
include/items.php: call_hooks('atom_feed_end', $atom);
include/items.php: call_hooks('atom_feed_end', $atom);
include/items.php: call_hooks('parse_atom', $arr);
include/items.php: call_hooks('post_remote',$arr);
include/items.php: call_hooks('atom_author', $o);
include/items.php: call_hooks('atom_entry', $o);
include/html2bbcode.php: call_hooks('html2bbcode', $text);
index.php: call_hooks('init_1');
index.php:call_hooks('app_menu', $arr);
index.php:call_hooks('page_end', $a->page['content']);
mod/photos.php: call_hooks('photo_post_init', $_POST);
mod/photos.php: call_hooks('photo_post_file',$ret);
mod/photos.php: call_hooks('photo_post_end',intval($item_id));
mod/photos.php: call_hooks('photo_upload_form',$ret);
mod/parse_url.php: call_hooks('parse_link', $arr);
mod/home.php: call_hooks("home_content",$o);
mod/contacts.php: call_hooks('contact_edit_post', $_POST);
mod/contacts.php: call_hooks('contact_edit', $arr);
mod/settings.php: call_hooks('plugin_settings_post', $_POST);
mod/settings.php: call_hooks('settings_post', $_POST);
mod/settings.php: call_hooks('plugin_settings', $o);
mod/settings.php: call_hooks('settings_form',$o);
mod/network.php: call_hooks('jot_tool', $jotplugins);
mod/network.php: call_hooks('jot_networks', $jotnets);
mod/network.php: call_hooks('display_item', $arr);
mod/xrd.php: call_hooks('personal_xrd', $arr);
mod/item.php: call_hooks('post_local_start', $_POST);
mod/item.php: call_hooks('post_local',$datarray);
mod/item.php: call_hooks('post_local_end', $datarray);
mod/profile.php: call_hooks('profile_advanced',$o);
mod/profile.php: call_hooks('jot_tool', $jotplugins);
mod/profile.php: call_hooks('jot_networks', $jotnets);
mod/profile.php: call_hooks('display_item', $arr);
mod/display.php: call_hooks('display_item', $arr);
mod/profiles.php: call_hooks('profile_post', $_POST);
mod/profiles.php: call_hooks('profile_edit', $arr);
mod/cb.php: call_hooks('cb_init');
mod/cb.php: call_hooks('cb_post', $_POST);
mod/cb.php: call_hooks('cb_afterpost');
mod/cb.php: call_hooks('cb_content', $o);
mod/directory.php: call_hooks('directory_item', $arr);

51
doc/Profiles.md Normal file
View File

@ -0,0 +1,51 @@
Profiles
========
* [Home](help)
Friendika has unlimited profiles. You may use different profiles to show different "sides of yourself" to different audiences.
You always have a profile known as your "default" or "public" profile. This profile is always available to the general public and cannot be hidden (there may be rare exceptions on privately run or disconnected sites). You may, and probably should restrict the information you make available on your public profile.
That said, if you want other friends to be able to find you, it helps to have the following information in your public profile...
* Your real name
* A photo of **you**
* Your location on the planet, at least to a country level.
Without this basic information, you could get very lonely here. Most people (even your best friends) will not try and connect with somebody that has a fake name or doesn't contain a real photo.
In addition, if you'd like to meet people that share some general interests with you, please take a moment and add some "Public Keywords" to your profile. Such as "music, linux, photography" or whatever. You can add as many keywords as you like.
Your default or public profile is also shown to contacts on other networks, since they do not have the ability to view your private profiles. Only members of the Friendika network can see alternate/private profiles.
To create an alternate profile, select "Profiles" from the menu of your Friendika site. You may edit an existing profile, change the profile photo, or create a new profile. You may also create a "clone" of an existing profile if you only wish to change a few items but don't wish to enter all the information again.
To assign a profile to specific persons, select the person from your "Contacts" page and click the pencil "Edit" icon. You will find a dropdown box listing the various profiles available. If this box is not selectable, the person is not in a supported network and cannot be assigned a specific profile.
Once a profile has been selected, when the person views your profile from one of the "magic profile links" on their site, they will see the private profile you have assigned. If they are not logged into their site or view your profile from elsewhere, they will see your public profile.
A magic profile link is indicated by a special cursor when hovering over a contact's name or photo. Currently this cursor is a hand next to a small padlock. These magic cursors indicate that by following the link, you are able to access special areas of the other person's pages which are only available to friends and may not be available to the general public.
You may also discover that (assuming you have the proper permissions) you may be able to post directly on the other person's profile (often called a "wall-to-wall" post). You may also be able to comment directly on posts from while visiting the other person's profile page.
There are two settings which allow you to publish your profile to a directory and ensure that it can be found by others. You can change these through settings on the "Settings" page. One setting allows you to publish your profile in the site directory of this Friendika server. Another option (this may have been disabled by the site creator) allows you to publish your profile in the "Global Directory". This is a mega directory which contains people from many other Friendika installations world-wide.
If you do not wish to be visible to any of these sites, you may leave your profile unpublished.
Although you may have multiple profiles, you only have one profile photo. This is intentional. In early tests we experimented with different photos for each profile and found it was very confusing for people. They might see a different picture depending on what website they visited or what conversation they were in, and often alerted them to the fact that other people might be able to see different profiles of you than they could see.
(But you can use the rich-text information boxes within a profile such as "Tell us about yourself" and link other photos onto the page.)
**Keywords and Directory Search**
On the site Directory page, you may search for people with published profiles who are on this site. The search is typically for your nickname or part of your full name. However this search will also match against other profile fields - such as gender, location, "about", work, and education. You may also include "Keywords" in your default profile - which may be used to search for common interests with other members. You have two sets of keywords available - public and private. Private keywords are *not* visible to anybody. You could use these keywords to locate people who share membership in secret societies, or that share a love of fishing (for example) - without making this information visible on your public profile. Public keywords are used in the friend suggestion tool and although they aren't readily visible, they may be seen by viewing the HTML of your profile page.
Directory searches are also able to use "boolean" logic so that you can search for "+lesbian +Florida" and find those who's sexual preference (or keywords) contain the world "lesbian" and that live in Florida. See the section on "Topical Tags" on the [[Tags-and-Mentions]] page for more information on performing boolean searches.
On your Contacts page is a link to "Find People with Shared Interests" (unless your site administrator has disabled the global directory). This will combine both your public and private keywords, and find people in the global directory who have matching and/or similar keywords. (Your private keywords are not identified or stored on the global directory). The more keywords you provide, the more relevant the search results that are returned. These are sorted by relevance. You may discover that you are the first person on the list - because you are very likely the most relevant match for your keywords in the directory.

13
doc/Remove-Account.md Normal file
View File

@ -0,0 +1,13 @@
Remove Account
==============
* [Home](help)
We don't like to see people leave Friendika, but if you need to remove your account, you should visit the URL
http://friendika-site/removeme
with your web browser. You will need to be logged in at the time. (Replace "friendika-site" with the hostname of your Friendika server)
You will be asked for your password to confirm the request. If this matches your stored password, your account will immediately be removed. Unlike some social networks we do **not** hold onto it for a grace period in case you change your mind. Your user details, your conversations, your photos, your friends - everything; will be removed immediately and you will be logged out.

237
doc/Settings.md Normal file
View File

@ -0,0 +1,237 @@
Here are some of the built-in features which don't have an exposed interface or are otherwise undocumented. Configuration settings are stored in the file ".htconfig.php". Edit this file with a text editor to make the desired changes. Several system settings are already documented in that file and will not be covered here.
**Hot Keys**
Friendika traps the following keyboard events:
* [Pause] - Pauses "Ajax" update activity. This is the process that provides updates without reloading the page. You may wish to pause it to reduce network usage and/or as a debugging aid for javascript developers. A pause indicator will appear at the lower right hand corner of the page. Hit the [pause] key once again to resume.
* [F8] - Displays a language selector
**Birthday Notifications**
Birthday events are published on your Home page for any friends having a birthday in the coming 6 days. In order for your birthday to be discoverable by all of your friends, you must set your birthday (at least the month and day) in your default profile. You are not required to provide the year.
**Configuration settings**
**Language**
System Setting
Please see util/README for information on creating language translations.
Config:
```
$a->config['system']['language'] = 'name';
```
**System Theme**
System Setting
Choose a named theme to be the default system theme (which may be over-ridden by user profiles). Default theme is "default".
Config:
```
$a->config['system']['theme'] = 'theme-name';
```
**Verify SSL Certitificates**
Security setting
By default Friendika allows SSL communication between websites that have "self-signed" SSL certificates. For the widest compatibility with browsers and other networks we do not recommend using self-signed certificates, but we will not prevent you from using them. SSL encrypts all the data transmitted between sites (and to your browser) and this allows you to have completely encrypted communications, and also protect your login session from hijacking. Self-signed certificates can be generated for free, without paying top-dollar for a website SSL certificate - however these aren't looked upon favourably in the security community because they can be subject to so-called "man-in-the-middle" attacks. If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites.
Config:
```
$a->config['system']['verifyssl'] = true;
```
**Allowed Friend Domains**
Corporate/Edu enhancement
Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. (Wildcard support on Windows platforms requires PHP5.3). By default, any (valid) domain may establish friendships with this site.
Config:
```
$a->config['system']['allowed_sites'] = "sitea.com, *siteb.com";
```
**Allowed Email Domains**
Corporate/Edu enhancement
Comma separated list of domains which are allowed in email addresses for registrations to this site. This can lockout those who are not part of this organisation from registering here. Wildcards are accepted. (Wildcard support on Windows platforms requires PHP5.3). By default, any (valid) email address is allowed in registrations.
Config:
```
$a->config['system']['allowed_email'] = "sitea.com, *siteb.com";
```
**Block Public**
Corporate/Edu enhancement
Set to true to block public access to all otherwise public personal pages on this site unless you are currently logged in. This blocks the viewing of profiles, friends, photos, the site directory and search pages to unauthorised persons. A side effect is that entries from this site will not appear in the global directory. We recommend specifically disabling that also (setting is described elsewhere on this page). Note: this is specifically for sites that desire to be "standalone" and do not wish to be connected to any other Friendika sites. Unauthorised persons will also not be able to request friendship with site members. Default is false. Available in version 2.2 or greater.
Config:
```
$a->config['system']['block_public'] = true;
```
**Force Publish**
Corporate/Edu enhancement
By default, each user can choose on their Settings page whether or not to have their profile published in the site directory. This setting forces all
profiles on this site to be listed in the site directory and there is no option provided to the user to change it. Default is false.
Config:
```
$a->config['system']['publish_all'] = true;
```
**Global Directory**
Corporate/Edu enhancement
This configures the URL to update the global directory, and is supplied in the default configuration. The undocumented part is that if this is not set, the global directory is completely unavailable to the application. This allows a private community to be completely isolated from the global mistpark network.
```
$a->config['system']['directory_submit_url'] = 'http://dir.friendika.com/submit';
```
**Proxy Configuration Settings**
If your site uses a proxy to connect to the internet, you may use these settings to communicate with the outside world (the outside world still needs to be able to see your website, or this will not be very useful).
Config:
```
$a->config['system']['proxy'] = "http://proxyserver.domain:port";
$a->config['system']['proxyuser'] = "username:password";
```
**Network Timeout**
How long to wait on a network communication before timing out. Value is in seconds. Default is 60 seconds. Set to 0 for unlimited (not recommended).
Config:
```
$a->config['system']['curl_timeout'] = 60;
```
**Banner/Logo**
Set the content for the site banner. Default is the Friendika logo and name. You may wish to provide HTML/CSS to style and/or position this content, as it may not be themed by default.
Config:
```
$a->config['system']['banner'] = '<span id="logo-text">My Great Website</span>';
```
**Maximum Image Size**
Maximum size in bytes of uploaded images. Default is 0, which means no limits.
Config:
```
$a->config['system']['maximagesize'] = 1000000;
```
**UTF-8 Regular Expressions**
During registrations, full names are checked using UTF-8 regular expressions. This requires PHP to have been compiled with a special setting to allow UTF-8 expressions. If you are completely unable to register accounts, set no_utf to true. Default is false (meaning UTF8 regular expressions are supported and working).
Config:
```
$a->config['system']['no_utf'] = true;
```
**Check Full Names**
You may find a lot of spammers trying to register on your site. During testing we discovered that since these registrations were automatic, the "Full Name" field was often set to just an account name with no space between first and last name. If you would like to support people with only one name as their full name, you may change this setting to true. Default is false.
Config:
```
$a->config['system']['no_regfullname'] = true;
```
**Gravatars**
During registration, we will try to automatically find a user photo for you on the web using the gravatar service. You may turn this off by setting 'no_gravatar' to true. Default is false.
Config:
```
$a->config['system']['no_gravatar'] = true;
```
**OpenID**
By default, OpenID may be used for both registration and logins. If you do not wish to make OpenID facilities available on your system (at all), set 'no_openid' to true. Default is false.
Config:
```
$a->config['system']['no_openid'] = true;
```
**Multiple Registrations**
The ability to create "Pages" requires a person to register more than once. Your site configuration can block registration (or require approval to register). By default logged in users can register additional accounts for use as pages. These will still require approval if REGISTER_APPROVE is selected. You may prohibit logged in users from creating additional accounts by setting 'block_extended_register' to true. Default is false.
Config:
```
$a->config['system']['block_extended_register'] = true;
```
**Developer Settings**
Most useful when debugging protocol exchanges and tracking down other communications issues.
Config:
```
$a->config['system']['debugging'] = true;
$a->config['system']['logfile'] = 'logfile.out';
$a->config['system']['loglevel'] = LOGGER_DEBUG;
```
Turns on detailed debugging logs which will be stored in 'logfile.out' (which must be writeable by the webserver). LOGGER_DEBUG will show a good deal of information about system activity but will not include detailed data. You may also select LOGGER_ALL but due to the volume of information we recommend only enabling this when you are tracking down a specific problem. Other log levels are possible but are not being used at the present time.
**PHP error logging**
Use the following settings to redirect PHP errors to a file.
Config:
```
error_reporting(E_ERROR | E_WARNING | E_PARSE );
ini_set('error_log','php.out');
ini_set('log_errors','1');
ini_set('display_errors', '0');
```
This will put all PHP errors in the file php.out (which must be writeable by the webserver). Undeclared variables are occasionally referenced in the program and therefore we do not recommend using E_NOTICE or E_ALL. The vast majority of issues reported at these levels are completely harmless. Please report to the developers any errors you encounter in the logs using the recommended settings above. They generally indicate issues which need to be resolved.
If you encounter a blank (white) page when using the application, view the PHP logs - as this almost always indicates an error has occurred.

View File

@ -0,0 +1,7 @@
Here is a list of Friendika installations free for everybody to join:
* [friendika.com](http://demo.friendika.com)
* [friendika.net](http://www.friendika.net)
* [aphasi.cc](https://friendika.aphasi.cc)
* [openmindspace.org](http://friendika.openmindspace.org)
* [dfrn.net](http://dfrn.net/)

37
doc/Tags-and-Mentions.md Normal file
View File

@ -0,0 +1,37 @@
Tags and Mentions
=================
* [Home](help)
Like many other modern social networks, Friendika uses a special notation inside messages to indicate "tags" or contextual links to other entities.
**Mentions**
People are tagged by preceding their name with the @ character.
The following are various ways of indicating a person:
* @mike - indicates a known contact in your social circle whose nickname is "mike"
* @mike_macgirvin - indicates a known contact in your social circle whose full name is "Mike Macgirvin". Note that spaces cannot be used inside tags.
* @mike@macgirvin.com - indicates the Identity Address of a person on a different network, or one that is *not* in your social circle. This can only be an email-style locator, not a web URL.
Unless their system blocks unsolicited "mentions", the person tagged will likely receive a "Mention" post/activity or become a direct participant in the conversation in the case of public posts. Please note that Friendika often blocks incoming "mentions" from other networks and especially from people with no relationship to you. This is a spam prevention measure.
Friendika makes no distinction between people and groups for the purpose of tagging. (Some other networks use !group to indicate a group.)
**Topical Tags**
Topical tags are indicated by preceding the tag name with the # character. This will create a link in the post to a generalised site search for the term provided. For example, #cars will provide a search link for all posts mentioning 'cars' on your site. Topical tags are generally a minimum of three characters in length. Shorter search terms are not likely to yield any search results, although this depends on the database configuration. The same rules apply as with names that spaces within tags are represented by the underscore character. It is therefore not possible to create a tag whose target contains an underscore.
Tag searches may also use "boolean" logic.
* \#bike - creates a search for "bike"
* \#bike_red - creates a search for posts that contain either the word "bike" OR the word "red".
* \#+bike_+red - creates a search for posts that contain both the word "bike" AND the word "red"
* \#+bike_-blue - creates a search for posts that contain the word "bike" but do *not* contain the word "blue"

18
doc/developer Normal file
View File

@ -0,0 +1,18 @@
Friendika Developer Guide
Here is how you can join us.
First, get yourself a working git package on the system where you will be
doing development.
Create your own github account.
Follow the instructions provided here: [[http://help.github.com/fork-a-repo/]]
to create and use your own tracking fork on github
Then go to your github page and create a "Pull request" when you are ready
to notify us to merge your work.
**Important**
Please pull in any changes from the project repository and merge them with your work **before** issuing a pull request. We reserve the right to reject any patch which results in a large number of merge conflicts. This is especially true in the case of language translations - where we may not be able to understand the subtle differences between conflicting versions.

View File

@ -38,7 +38,7 @@ $a->config['admin_email'] = '';
// Maximum size of an imported message, 0 is unlimited
$a->config['max_import_size'] = 10000;
$a->config['max_import_size'] = 200000;
// maximum size of uploaded photos

BIN
images/article.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
images/audio.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

BIN
images/friendika-1600.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

BIN
images/icons.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
images/pencil.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

BIN
images/recycle.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 B

After

Width:  |  Height:  |  Size: 237 B

BIN
images/share.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
images/spencil.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

BIN
images/tools.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

BIN
images/video.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

View File

@ -14,11 +14,13 @@ function user_remove($uid) {
q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `intro` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `event` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `item` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `mail` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `photo` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `profile_check` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `pconfig` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `user` WHERE `uid` = %d", intval($uid));
if($uid == local_user()) {
unset($_SESSION['authenticated']);
@ -41,6 +43,9 @@ function contact_remove($id) {
q("DELETE FROM `mail` WHERE `contact-id` = %d ",
intval($id)
);
q("DELETE FROM `event` WHERE `cid` = %d ",
intval($id)
);
}

View File

@ -162,12 +162,20 @@ class Photo {
}
public function saveImage($path) {
imagejpeg($this->image,$path,100);
$quality = get_config('system','jpeg_quality');
if((! $quality) || ($quality > 100))
$quality = JPEG_QUALITY;
imagejpeg($this->image,$path,$quality);
}
public function imageString() {
ob_start();
imagejpeg($this->image,NULL,100);
$quality = get_config('system','jpeg_quality');
if((! $quality) || ($quality > 100))
$quality = JPEG_QUALITY;
imagejpeg($this->image,NULL,$quality);
$s = ob_get_contents();
ob_end_clean();
return $s;

View File

@ -216,7 +216,7 @@ function scrape_feed($url) {
}
if(stristr($line,'application/rss+xml') || stristr($s,'<rss')) {
$ret['feed_rss'] = $url;
return ret;
return $ret;
}
}
}
@ -227,17 +227,287 @@ function scrape_feed($url) {
if(! $dom)
return $ret;
$items = $dom->getElementsByTagName('link');
// get Atom link elements
$items = $dom->getElementsByTagName('img');
foreach($items as $item) {
$x = $item->getAttribute('rel');
if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
$ret['feed_atom'] = $item->getAttribute('href');
if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml'))
$ret['feed_rss'] = $item->getAttribute('href');
// get img elements (twitter)
if($items) {
foreach($items as $item) {
$x = $item->getAttribute('id');
if($x === 'profile-image') {
$ret['photo'] = $item->getAttribute('src');
}
}
}
$head = $dom->getElementsByTagName('base');
if($head) {
foreach($head as $head0) {
$basename = $head0->getAttribute('href');
break;
}
}
if(! $basename)
$basename = substr($url,0,strrpos($url,'/')) . '/';
$items = $dom->getElementsByTagName('link');
// get Atom/RSS link elements, take the first one of either.
if($items) {
foreach($items as $item) {
$x = $item->getAttribute('rel');
if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml')) {
if(! x($ret,'feed_atom'))
$ret['feed_atom'] = $item->getAttribute('href');
}
if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml')) {
if(! x($ret,'feed_rss'))
$ret['feed_rss'] = $item->getAttribute('href');
}
}
}
// Drupal and perhaps others only provide relative URL's. Turn them into absolute.
if(x($ret,'feed_atom') && (! strstr($ret['feed_atom'],'://')))
$ret['feed_atom'] = $basename . $ret['feed_atom'];
if(x($ret,'feed_rss') && (! strstr($ret['feed_rss'],'://')))
$ret['feed_rss'] = $basename . $ret['feed_rss'];
return $ret;
}}
}}
function probe_url($url) {
require_once('include/email.php');
$result = array();
if(! $url)
return $result;
$diaspora = false;
$email_conversant = false;
if($url) {
$links = lrdd($url);
if(count($links)) {
logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA);
foreach($links as $link) {
if($link['@attributes']['rel'] === NAMESPACE_DFRN)
$dfrn = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'salmon')
$notify = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === NAMESPACE_FEED)
$poll = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
$hcard = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location')
$diaspora = true;
}
// Status.Net can have more than one profile URL. We need to match the profile URL
// to a contact on incoming messages to prevent spam, and we won't know which one
// to match. So in case of two, one of them is stored as an alias. Only store URL's
// and not webfinger user@host aliases. If they've got more than two non-email style
// aliases, let's hope we're lucky and get one that matches the feed author-uri because
// otherwise we're screwed.
foreach($links as $link) {
if($link['@attributes']['rel'] === 'alias') {
if(strpos($link['@attributes']['href'],'@') === false) {
if(isset($profile)) {
if($link['@attributes']['href'] !== $profile)
$alias = unamp($link['@attributes']['href']);
}
else
$profile = unamp($link['@attributes']['href']);
}
}
}
}
else {
// Check email
$orig_url = $url;
if((strpos($orig_url,'@')) && validate_email($orig_url)) {
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
intval(local_user())
);
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($x) && count($r)) {
$mailbox = construct_mailbox_name($r[0]);
$password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']),$password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$r[0]['user'],$password);
unset($password);
}
if($mbox) {
$msgs = email_poll($mbox,$orig_url);
if(count($msgs)) {
$addr = $orig_url;
$network = NETWORK_MAIL;
$name = substr($url,0,strpos($url,'@'));
$profile = 'http://' . substr($url,strpos($url,'@')+1);
// fix nick character range
$vcard = array('fn' => $name, 'nick' => $name, 'photo' => gravatar_img($url));
$notify = 'smtp ' . random_string();
$poll = 'email ' . random_string();
$priority = 0;
$x = email_msg_meta($mbox,$msgs[0]);
if(stristr($x->from,$orig_url))
$adr = imap_rfc822_parse_adrlist($x->from,'');
elseif(stristr($x->to,$orig_url))
$adr = imap_rfc822_parse_adrlist($x->to,'');
if(isset($adr) && strlen($adr[0]->personal))
$vcard['fn'] = notags($adr[0]->personal);
}
imap_close($mbox);
}
}
}
}
if(strlen($dfrn)) {
$ret = scrape_dfrn($dfrn);
if(is_array($ret) && x($ret,'dfrn-request')) {
$network = NETWORK_DFRN;
$request = $ret['dfrn-request'];
$confirm = $ret['dfrn-confirm'];
$notify = $ret['dfrn-notify'];
$poll = $ret['dfrn-poll'];
}
}
if($network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
$network = NETWORK_OSTATUS;
$priority = 0;
if($hcard) {
$vcard = scrape_vcard($hcard);
// Google doesn't use absolute url in profile photos
if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
$h = @parse_url($hcard);
if($h)
$vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
}
logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA);
}
if(! $profile) {
if($diaspora)
$profile = $hcard;
else
$profile = $url;
}
if(! x($vcard,'fn'))
if(x($vcard,'nick'))
$vcard['fn'] = $vcard['nick'];
if((! isset($vcard)) && (! $poll)) {
$ret = scrape_feed($url);
logger('probe_url: scrape_feed returns: ' . print_r($ret,true), LOGGER_DATA);
if(count($ret) && ($ret['feed_atom'] || $ret['feed_rss'])) {
$poll = ((x($ret,'feed_atom')) ? unamp($ret['feed_atom']) : unamp($ret['feed_rss']));
$vcard = array();
if(x($ret,'photo'))
$vcard['photo'] = $ret['photo'];
require_once('simplepie/simplepie.inc');
$feed = new SimplePie();
$xml = fetch_url($poll);
$feed->set_raw_data($xml);
$feed->init();
if(! x($vcard,'photo'))
$vcard['photo'] = $feed->get_image_url();
$author = $feed->get_author();
if($author) {
$vcard['fn'] = unxmlify(trim($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
if(strpos($vcard['fn'],'@') !== false)
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
$vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
$email = unxmlify($author->get_email());
}
else {
$item = $feed->get_item(0);
if($item) {
$author = $item->get_author();
if($author) {
$vcard['fn'] = trim(unxmlify($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
if(strpos($vcard['fn'],'@') !== false)
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
$vcard['nick'] = strtolower(unxmlify($vcard['fn']));
if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
$email = unxmlify($author->get_email());
}
if(! $vcard['photo']) {
$rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
if($rawmedia && $rawmedia[0]['attribs']['']['url'])
$vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
}
}
}
if((! $vcard['photo']) && strlen($email))
$vcard['photo'] = gravatar_img($email);
if($poll === $profile)
$lnk = $feed->get_permalink();
if(isset($lnk) && strlen($lnk))
$profile = $lnk;
if(! (x($vcard,'fn')))
$vcard['fn'] = notags($feed->get_title());
if(! (x($vcard,'fn')))
$vcard['fn'] = notags($feed->get_description());
$network = 'feed';
$priority = 2;
}
}
}
if(! x($vcard,'photo')) {
$a = get_app();
$vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ;
}
$vcard['fn'] = notags($vcard['fn']);
$vcard['nick'] = notags($vcard['nick']);
$result['name'] = $vcard['fn'];
$result['nick'] = $vcard['nick'];
$result['url'] = $profile;
$result['addr'] = $addr;
$result['notify'] = $notify;
$result['poll'] = $poll;
$result['request'] = $request;
$result['confirm'] = $confirm;
$result['photo'] = $vcard['photo'];
$result['priority'] = $priority;
$result['network'] = $network;
$result['alias'] = $alias;
logger('probe_url: ' . print_r($result,true), LOGGER_DEBUG);
return $result;
}

View File

@ -48,7 +48,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$o = '';
// When used for private messages, we limit correspondence to mutual friends and the selector
// When used for private messages, we limit correspondence to mutual DFRN/Friendika friends and the selector
// to one recipient. By default our selector allows multiple selects amongst all contacts.
$sql_extra = '';
@ -57,9 +57,12 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$sql_extra .= sprintf(" AND `rel` = %d ", intval(REL_BUD));
}
if($privmail || $privatenet) {
if($privmail) {
$sql_extra .= " AND `network` IN ( 'dfrn' ) ";
}
}
elseif($privatenet) {
$sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face' ) ";
}
if($privmail)
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
@ -80,8 +83,6 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
call_hooks($a->module . '_pre_' . $selname, $arr);
if(count($r)) {
foreach($r as $rr) {
if((is_array($preselected)) && in_array($rr['id'], $preselected))
@ -129,7 +130,7 @@ function populate_acl($user = null,$celeb = false) {
$o = '';
$o .= '<div id="acl-wrapper">';
$o .= '<div id="acl-permit-outer-wrapper">';
$o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div>';
$o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
$o .= '<div id="acl-permit-text-end"></div>';
$o .= '<div id="acl-permit-wrapper">';
$o .= '<div id="group_allow_wrapper">';

431
include/api.php Normal file
View File

@ -0,0 +1,431 @@
<?php
require_once("bbcode.php");
require_once("datetime.php");
/*
* Twitter-Like API
*
*/
$API = Array();
function api_date($str){
//Wed May 23 06:01:13 +0000 2007
return datetime_convert('UTC', 'UTC', $str, "D M d h:i:s +0000 Y" );
}
function api_register_func($path, $func, $auth=false){
global $API;
$API[$path] = array('func'=>$func,
'auth'=>$auth);
}
/**
* Simple HTTP Login
*/
function api_login(&$a){
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Friendika"');
header('HTTP/1.0 401 Unauthorized');
die('This api require login');
}
$user = $_SERVER['PHP_AUTH_USER'];
$encrypted = hash('whirlpool',trim($_SERVER['PHP_AUTH_PW']));
/**
* next code from mod/auth.php. needs better solution
*/
// process normal login request
$r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
AND `password` = '%s' AND `blocked` = 0 AND `verified` = 1 LIMIT 1",
dbesc(trim($user)),
dbesc(trim($user)),
dbesc($encrypted)
);
if(count($r)){
$record = $r[0];
} else {
header('WWW-Authenticate: Basic realm="Friendika"');
header('HTTP/1.0 401 Unauthorized');
die('This api require login');
}
$_SESSION['uid'] = $record['uid'];
$_SESSION['theme'] = $record['theme'];
$_SESSION['authenticated'] = 1;
$_SESSION['page_flags'] = $record['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname'];
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
//notice( t("Welcome back ") . $record['username'] . EOL);
$a->user = $record;
if(strlen($a->user['timezone'])) {
date_default_timezone_set($a->user['timezone']);
$a->timezone = $a->user['timezone'];
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
intval($_SESSION['uid']));
if(count($r)) {
$a->contact = $r[0];
$a->cid = $r[0]['id'];
$_SESSION['cid'] = $a->cid;
}
q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($_SESSION['uid'])
);
call_hooks('logged_in', $a->user);
header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
}
/**************************
* MAIN API ENTRY POINT *
**************************/
function api_call(&$a){
GLOBAL $API;
foreach ($API as $p=>$info){
if (strpos($a->query_string, $p)===0){
#unset($_SERVER['PHP_AUTH_USER']);
if ($info['auth']===true && local_user()===false) {
api_login($a);
}
$type="json";
if (strpos($a->query_string, ".xml")>0) $type="xml";
if (strpos($a->query_string, ".json")>0) $type="json";
if (strpos($a->query_string, ".rss")>0) $type="rss";
if (strpos($a->query_string, ".atom")>0) $type="atom";
$r = call_user_func($info['func'], $a, $type);
if ($r===false) return;
switch($type){
case "xml":
$r = mb_convert_encoding($r, "UTF-8",mb_detect_encoding($r));
header ("Content-Type: text/xml");
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break;
case "json":
header ("Content-Type: application/json");
return json_encode($r);
break;
case "rss":
header ("Content-Type: application/rss+xml");
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break;
case "atom":
#header ("Content-Type: application/atom+xml");
return '<?xml version="1.0" encoding="UTF-8"?>'."\n".$r;
break;
}
//echo "<pre>"; var_dump($r); die();
}
}
return false;
}
/**
* RSS extra info
*/
function api_rss_extra(&$a, $arr, $user_info){
if (is_null($user_info)) $user_info = api_get_user($a);
$arr['$rss'] = array(
'alternate' => $user_info['url'],
'self' => $a->get_baseurl(). "/". $a->query_string,
'updated' => api_date(null),
'language' => $user_info['language'],
'logo' => $a->get_baseurl()."/images/friendika-32.png",
);
return $arr;
}
/**
* Returns user info array.
*/
function api_get_user(&$a){
$user = null;
$extra_query = "";
if(x($_GET, 'user_id')) {
$user = intval($_GET['user_id']);
$extra_query = "AND `contact`.`id` = %d ";
}
if(x($_GET, 'screen_name')) {
$user = dbesc($_GET['screen_name']);
$extra_query = "AND `contact`.`nick` = '%s' ";
}
if ($user===null){
list($user, $null) = explode(".",$a->argv[3]);
if(is_numeric($user)){
$user = intval($user);
$extra_query = "AND `contact`.`id` = %d ";
} else {
$user = dbesc($user);
$extra_query = "AND `contact`.`nick` = '%s' ";
}
}
if ($user==='') {
if (local_user()===false) {
api_login($a); return False;
} else {
$user = $_SESSION['uid'];
$extra_query = "AND `user`.`uid` = %d ";
}
}
// user info
$uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `user`, `contact`
WHERE `user`.`uid`=`contact`.`uid` AND `contact`.`self`=1
$extra_query",
$user
);
if (count($uinfo)==0) {
return False;
}
// count public wall messages
$r = q("SELECT COUNT(`id`) as `count` FROM `item`
WHERE `uid` = %d
AND `type`='wall'
AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
intval($uinfo[0]['uid'])
);
$countitms = $r[0]['count'];
// count friends
$r = q("SELECT COUNT(`id`) as `count` FROM `contact`
WHERE `uid` = %d
AND `self`=0 AND `blocked`=0",
intval($uinfo[0]['uid'])
);
$countfriends = $r[0]['count'];
$ret = Array(
'id' => $uinfo[0]['cid'],
'name' => $uinfo[0]['username'],
'screen_name' => $uinfo[0]['nickname'],
'location' => $uinfo[0]['default-location'],
'profile_image_url' => $uinfo[0]['micro'],
'url' => $uinfo[0]['url'],
'protected' => false, #
'friends_count' => $countfriends,
'created_at' => api_date($uinfo[0]['created']),
'utc_offset' => 0, #XXX: fix me
'time_zone' => $uinfo[0]['timezone'],
'geo_enabled' => false,
'statuses_count' => $countitms, #XXX: fix me
'lang' => 'en', #XXX: fix me
'description' => '',
'followers_count' => $countfriends, #XXX: fix me
'lang' => 'en', #XXX: fix me
'favourites_count' => 0,
'contributors_enabled' => false,
'follow_request_sent' => false,
'profile_background_color' => 'cfe8f6',
'profile_text_color' => '000000',
'profile_link_color' => 'FF8500',
'profile_sidebar_fill_color' =>'AD0066',
'profile_sidebar_border_color' => 'AD0066',
'profile_background_image_url' => '',
'profile_background_tile' => false,
'profile_use_background_image' => false,
'notifications' => false,
'verified' => true, #XXX: fix me
'followers' => '', #XXX: fix me
#'status' => null
);
return $ret;
}
/**
* apply xmlify() to all values of array $val, recursively
*/
function api_xmlify($val){
if (is_bool($val)) return $val?"true":"false";
if (is_array($val)) return array_map('api_xmlify', $val);
return xmlify($val);
}
/**
* load api $templatename for $type and replace $data array
*/
function api_apply_template($templatename, $type, $data){
switch($type){
case "rss":
case "atom":
case "xml":
$data = api_xmlify($data);
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
$ret = replace_macros($tpl, $data);
break;
case "json":
$ret = $data;
break;
}
return $ret;
}
/**
** TWITTER API
*/
/**
* Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful;
* returns a 401 status code and an error message if not.
* http://developer.twitter.com/doc/get/account/verify_credentials
*/
function api_account_verify_credentials(&$a, $type){
if (local_user()===false) return false;
$user_info = api_get_user($a);
return api_apply_template("user", $type, array('$user' => $user_info));
}
api_register_func('api/account/verify_credentials','api_account_verify_credentials', true);
/**
* Returns extended information of a given user, specified by ID or screen name as per the required id parameter.
* The author's most recent status will be returned inline.
* http://developer.twitter.com/doc/get/users/show
*/
function api_users_show(&$a, $type){
$user_info = api_get_user($a);
// get last public wall message
$lastwall = q("SELECT `item`.*, `i`.`contact-id` as `reply_uid`, `i`.`nick` as `reply_author`
FROM `item`, `contact`,
(SELECT `item`.`id`, `item`.`contact-id`, `contact`.`nick` FROM `item`,`contact` WHERE `contact`.`id`=`item`.`contact-id`) as `i`
WHERE `item`.`contact-id` = %d
AND `i`.`id` = `item`.`parent`
AND `contact`.`id`=`item`.`contact-id` AND `contact`.`self`=1
AND `type`!='activity'
AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
ORDER BY `created` DESC
LIMIT 1",
intval($user_info['id'])
);
if (count($lastwall)>0){
$lastwall = $lastwall[0];
$in_reply_to_status_id = '';
$in_reply_to_user_id = '';
$in_reply_to_screen_name = '';
if ($lastwall['parent']!=$lastwall['id']) {
$in_reply_to_status_id=$lastwall['parent'];
$in_reply_to_user_id = $lastwall['reply_uid'];
$in_reply_to_screen_name = $lastwall['reply_author'];
}
$user_info['status'] = array(
'created_at' => api_date($lastwall['created']),
'id' => $lastwall['contact-id'],
'text' => strip_tags(bbcode($lastwall['body'])),
'source' => 'web',
'truncated' => false,
'in_reply_to_status_id' => $in_reply_to_status_id,
'in_reply_to_user_id' => $in_reply_to_user_id,
'favorited' => false,
'in_reply_to_screen_name' => $in_reply_to_screen_name,
'geo' => '',
'coordinates' => $lastwall['coord'],
'place' => $lastwall['location'],
'contributors' => ''
);
}
return api_apply_template("user", $type, array('$user' => $user_info));
}
api_register_func('api/users/show','api_users_show');
/**
*
* http://developer.twitter.com/doc/get/statuses/home_timeline
*
* TODO: Optional parameters
* TODO: Add reply info
*/
function api_statuses_home_timeline(&$a, $type){
if (local_user()===false) return false;
$user_info = api_get_user($a);
// get last newtork messages
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`, `user`
WHERE `item`.`contact-id` = %d AND `user`.`uid` = `item`.`uid`
AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
intval($user_info['id']),
0,20
);
$ret = Array();
foreach($r as $item) {
$status = array(
'created_at'=> api_date($item['created']),
'id' => $item['id'],
'text' => strip_tags(bbcode($item['body'])),
'html' => bbcode($item['body']),
'source' => 'web',
'url' => ($item['plink']!=''?$item['plink']:$item['author-link']),
'truncated' => False,
'in_reply_to_status_id' => ($item['parent']!=$item['id']?$item['id']:''),
'in_reply_to_user_id' => '',
'favorited' => false,
'in_reply_to_screen_name' => '',
'geo' => '',
'coordinates' => $item['coord'],
'place' => $item['location'],
'contributors' => '',
'annotations' => '',
'entities' => '',
'user' => $user_info,
'objecttype' => $item['object-type'],
'verb' => $item['verb'],
'self' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,
'edit' => $a->get_baseurl()."/api/statuses/show/".$ite['id'].".".$type,
);
$ret[]=$status;
};
$data = array('$statuses' => $ret);
switch($type){
case "atom":
case "rss":
$data = api_rss_extra($a, $data, $user_info);
}
return api_apply_template("timeline", $type, $data);
}
api_register_func('api/statuses/home_timeline','api_statuses_home_timeline', true);
api_register_func('api/statuses/friends_timeline','api_statuses_home_timeline', true);
api_register_func('api/statuses/user_timeline','api_statuses_home_timeline', true);
# TODO: user_timeline should be profile view

View File

@ -28,6 +28,15 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
goaway($a->get_baseurl());
}
if(x($_SESSION,'visitor_id') && (! x($_SESSION,'uid'))) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($_SESSION['visitor_id'])
);
if(count($r)) {
$a->contact = $r[0];
}
}
if(x($_SESSION,'uid')) {
// already logged in user returning
@ -191,9 +200,17 @@ else {
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname'];
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
notice( t("Welcome back ") . $record['username'] . EOL);
$a->user = $record;
if($a->user['login_date'] === '0000-00-00 00:00:00') {
$_SESSION['return_url'] = 'profile_photo/new';
$a->module = 'profile_photo';
notice( t("Welcome ") . $a->user['username'] . EOL);
notice( t('Please upload a profile photo.') . EOL);
}
else
notice( t("Welcome back ") . $a->user['username'] . EOL);
if(strlen($a->user['timezone'])) {
date_default_timezone_set($a->user['timezone']);
$a->timezone = $a->user['timezone'];
@ -214,6 +231,8 @@ else {
$a->cid = $r[0]['id'];
$_SESSION['cid'] = $a->cid;
}
q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($_SESSION['uid'])

View File

@ -3,7 +3,7 @@ require_once("include/oembed.php");
// BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendika - Mike Macgirvin
function bbcode($Text) {
function bbcode($Text,$preserve_nl = false) {
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
@ -12,7 +12,10 @@ function bbcode($Text) {
$Text = str_replace(">", "&gt;", $Text);
// Convert new line chars to html <br /> tags
$Text = nl2br($Text);
if($preserve_nl)
$Text = str_replace(array("\n","\r"), array('',''),$Text);
// Set up the parameters for a URL search string
$URLSearchString = "^\[\]";
@ -22,7 +25,7 @@ function bbcode($Text) {
// Perform URL Search
$Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+]+)/", ' <a href="$2" target="external-link">$2</a>', $Text);
$Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+\,]+)/", ' <a href="$2" target="external-link">$2</a>', $Text);
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="external-link">$1</a>', $Text);
$Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="external-link">$2</a>', $Text);
@ -77,7 +80,7 @@ function bbcode($Text) {
// Images
// [img]pathtoimage[/img]
$Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);
$Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
// html5 video and audio
@ -90,8 +93,12 @@ function bbcode($Text) {
$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);
// Youtube extensions
$Text = preg_replace("/\[youtube\]http:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<iframe width="425" height="349" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $Text);
// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
// oembed tag
$Text = oembed_bbcode2html($Text);

755
include/conversation.php Normal file
View File

@ -0,0 +1,755 @@
<?php
/**
* Render actions localized
*/
function localize_item(&$item){
if ($item['verb']=="http://activitystrea.ms/schema/1.0/like" ||
$item['verb']=="http://activitystrea.ms/schema/1.0/dislike"){
$r = q("SELECT * from `item`,`contact` WHERE
`item`.`contact-id`=`contact`.`id` AND `item`.`uri`='%s';",
dbesc($item['parent-uri']));
if(count($r)==0) return;
$obj=$r[0];
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
$post_type = (($obj['resource-id']) ? t('photo') : t('status'));
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
switch($item['verb']){
case "http://activitystrea.ms/schema/1.0/like":
$bodyverb = t('%1$s likes %2$s\'s %3$s');
break;
case "http://activitystrea.ms/schema/1.0/dislike":
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
break;
}
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
}
if ($item['verb']=='http://activitystrea.ms/schema/1.0/make-friend'){
if ($item['object-type']=="" || $item['object-type']!='http://activitystrea.ms/schema/1.0/person') return;
$Aname = $item['author-name'];
$Alink = $item['author-link'];
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$obj = parse_xml_string($xmlhead.$item['object']);
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title;
$Blink = ""; $Bphoto = "";
foreach ($links->link as $l){
$atts = $l->attributes();
switch($atts['rel']){
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
}
}
$A = '[url=' . $Alink . ']' . $Aname . '[/url]';
$B = '[url=' . $Blink . ']' . $Bname . '[/url]';
if ($Bphoto!="") $Bphoto = '[url=' . $Blink . '][img]' . $Bphoto . '[/img][/url]';
$item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
}
}
/**
* "Render" a conversation or list of items for HTML display.
* There are two major forms of display:
* - Sequential or unthreaded ("New Item View" or search results)
* - conversation view
* The $mode parameter decides between the various renderings and also
* figures out how to determine page owner and other contextual items
* that are based on unique features of the calling module.
*
*/
function conversation(&$a, $items, $mode, $update) {
require_once('bbcode.php');
$profile_owner = 0;
$page_writeable = false;
if($mode === 'network') {
$profile_owner = local_user();
$page_writeable = true;
}
if($mode === 'profile') {
$profile_owner = $a->profile['profile_uid'];
$page_writeable = can_write_wall($a,$profile_owner);
}
if($mode === 'notes') {
$profile_owner = $a->profile['profile_uid'];
$page_writeable = true;
}
if($mode === 'display') {
$profile_owner = $a->profile['uid'];
$page_writeable = can_write_wall($a,$profile_owner);
}
if($update)
$return_url = $_SESSION['return_url'];
else
$return_url = $_SESSION['return_url'] = $a->cmd;
load_contact_links(local_user());
$cmnt_tpl = get_markup_template('comment_item.tpl');
$like_tpl = get_markup_template('like.tpl');
$noshare_tpl = get_markup_template('like_noshare.tpl');
$tpl = get_markup_template('wall_item.tpl');
$wallwall = get_markup_template('wallwall_item.tpl');
$alike = array();
$dlike = array();
if(count($items)) {
if($mode === 'network-new' || $mode === 'search') {
// "New Item View" on network page or search page results
// - just loop through the items and format them minimally for display
$tpl = get_markup_template('search_item.tpl');
$droptpl = get_markup_template('wall_fake_drop.tpl');
foreach($items as $item) {
$comment = '';
$owner_url = '';
$owner_photo = '';
$owner_name = '';
$sparkle = '';
if($mode === 'search') {
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
$nickname = $item['nickname'];
}
else
$nickname = $a->user['nickname'];
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
$sp = false;
$profile_link = best_link_url($item,$sp);
if($sp)
$sparkle = ' sparkle';
if($profile_link === 'mailbox')
$profile_link = '';
$normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
$profile_avatar = $a->contacts[$normalised]['thumb'];
else
$profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
$location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
$coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
if($coord) {
if($location)
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
else
$location = '<span class="smalltext">' . $coord . '</span>';
}
$drop = '';
$dropping = false;
if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
$dropping = true;
$drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
//
localize_item($item);
$drop = replace_macros($droptpl,array('$id' => $item['id']));
$lock = '<div class="wall-item-lock"></div>';
$o .= replace_macros($tpl,array(
'$id' => $item['item_id'],
'$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
'$profile_url' => $profile_link,
'$item_photo_menu' => item_photo_menu($item),
'$name' => $profile_name,
'$sparkle' => $sparkle,
'$lock' => $lock,
'$thumb' => $profile_avatar,
'$title' => $item['title'],
'$body' => smilies(bbcode($item['body'])),
'$ago' => relative_date($item['created']),
'$location' => $location,
'$indent' => '',
'$owner_url' => $owner_url,
'$owner_photo' => $owner_photo,
'$owner_name' => $owner_name,
'$drop' => $drop,
'$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'] . '">' . t('View in context') . '</a>'
));
}
return $o;
}
// Normal View
// Figure out how many comments each parent has
// (Comments all have gravity of 6)
// Store the result in the $comments array
$comments = array();
foreach($items as $item) {
if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) {
if(! x($comments,$item['parent']))
$comments[$item['parent']] = 1;
else
$comments[$item['parent']] += 1;
}
}
// map all the like/dislike activities for each parent item
// Store these in the $alike and $dlike arrays
foreach($items as $item) {
like_puller($a,$item,$alike,'like');
like_puller($a,$item,$dlike,'dislike');
}
$comments_collapsed = false;
$blowhard = 0;
$blowhard_count = 0;
foreach($items as $item) {
$comment = '';
$template = $tpl;
$commentww = '';
$sparkle = '';
$owner_url = $owner_photo = $owner_name = '';
// We've already parsed out like/dislike for special treatment. We can ignore them now
if(((activity_match($item['verb'],ACTIVITY_LIKE))
|| (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
$toplevelpost = (($item['id'] == $item['parent']) ? true : false);
// Take care of author collapsing and comment collapsing
// If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
// If there are more than two comments, squash all but the last 2.
if($toplevelpost) {
$item_writeable = (($item['writable'] || $item['self']) ? true : false);
if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
$blowhard_count ++;
if($blowhard_count == 3) {
$o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent']
. '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >'
. t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-'
. $item['parent'] . '" style="display: none;" >';
}
}
else {
$blowhard = $item['cid'];
if($blowhard_count >= 3)
$o .= '</div>';
$blowhard_count = 0;
}
$comments_seen = 0;
$comments_collapsed = false;
}
else
$comments_seen ++;
$override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false);
$show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false);
if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
if(! $comments_collapsed) {
$o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent']
. '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\'); $(\'#ccollapse-wrapper-' . $item['parent'] . '\').hide();" >'
. sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>'
. '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
$comments_collapsed = true;
}
}
if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
$o .= '</div>';
}
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
$lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
: '<div class="wall-item-lock"></div>');
// Top-level wall post not written by the wall owner (wall-to-wall)
// First figure out who owns it.
$osparkle = '';
if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) {
if($item['type'] === 'wall') {
// On the network page, I am the owner. On the display page it will be the profile owner.
// This will have been stored in $a->page_contact by our calling page.
// Put this person on the left of the wall-to-wall notice.
$owner_url = $a->page_contact['url'];
$owner_photo = $a->page_contact['thumb'];
$owner_name = $a->page_contact['name'];
$template = $wallwall;
$commentww = 'ww';
}
if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
// Could be anybody.
$owner_url = $item['owner-link'];
$owner_photo = $item['owner-avatar'];
$owner_name = $item['owner-name'];
$template = $wallwall;
$commentww = 'ww';
// If it is our contact, use a friendly redirect link
if((link_compare($item['owner-link'],$item['url']))
&& ($item['network'] === 'dfrn')) {
$owner_url = $redirect_url;
$osparkle = ' sparkle';
}
}
}
$likebuttons = '';
if($page_writeable) {
if($toplevelpost) {
$likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
'$id' => $item['id'],
'$likethis' => t("I like this \x28toggle\x29"),
'$nolike' => t("I don't like this \x28toggle\x29"),
'$share' => t('Share'),
'$wait' => t('Please wait')
));
}
if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
'$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
'$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'),
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $profile_owner,
'$mylink' => $a->contact['url'],
'$mytitle' => t('This is you'),
'$myphoto' => $a->contact['thumb'],
'$comment' => t('Comment'),
'$submit' => t('Submit'),
'$ww' => (($mode === 'network') ? $commentww : '')
));
}
}
$edpost = (((($profile_owner == local_user()) && ($toplevelpost) && (intval($item['wall']) == 1)) || ($mode === 'notes'))
? '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id']
. '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>'
: '');
$drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
$photo = $item['photo'];
$thumb = $item['thumb'];
// Post was remotely authored.
$diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
$profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
$sp = false;
$profile_link = best_link_url($item,$sp);
if($sp)
$sparkle = ' sparkle';
if($profile_link === 'mailbox')
$profile_link = '';
$normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
$profile_avatar = $a->contacts[$normalised]['thumb'];
else
$profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
$like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
$dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
$location = (($item['location']) ? '<a target="map" title="' . $item['location']
. '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
$coord = (($item['coord']) ? '<a target="map" title="' . $item['coord']
. '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
if($coord) {
if($location)
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
else
$location = '<span class="smalltext">' . $coord . '</span>';
}
$indent = (($toplevelpost) ? '' : ' comment');
if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
$indent .= ' shiny';
//
localize_item($item);
// Build the HTML
$tmp_item = replace_macros($template,array(
'$id' => $item['item_id'],
'$linktitle' => sprintf( t('View %s\'s profile'), $profile_name),
'$olinktitle' => sprintf( t('View %s\'s profile'), $owner_name),
'$to' => t('to'),
'$wall' => t('Wall-to-Wall'),
'$vwall' => t('via Wall-To-Wall:'),
'$profile_url' => $profile_link,
'$item_photo_menu' => item_photo_menu($item),
'$name' => $profile_name,
'$thumb' => $profile_avatar,
'$osparkle' => $osparkle,
'$sparkle' => $sparkle,
'$title' => $item['title'],
'$body' => smilies(bbcode($item['body'])),
'$ago' => relative_date($item['created']),
'$lock' => $lock,
'$location' => $location,
'$indent' => $indent,
'$owner_url' => $owner_url,
'$owner_photo' => $owner_photo,
'$owner_name' => $owner_name,
'$plink' => get_plink($item),
'$edpost' => $edpost,
'$drop' => $drop,
'$vote' => $likebuttons,
'$like' => $like,
'$dislike' => $dislike,
'$comment' => $comment
));
$arr = array('item' => $item, 'output' => $tmp_item);
call_hooks('display_item', $arr);
$o .= $arr['output'];
}
}
// if author collapsing is in force but didn't get closed, close it off now.
if($blowhard_count >= 3)
$o .= '</div>';
return $o;
}
if(! function_exists('load_contact_links')) {
function load_contact_links($uid) {
$a = get_app();
$ret = array();
if(! $uid || x($a->contacts,'empty'))
return;
$r = q("SELECT `id`,`network`,`url`,`thumb` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
intval($uid)
);
if(count($r)) {
foreach($r as $rr){
$url = normalise_link($rr['url']);
$ret[$url] = $rr;
}
}
else
$ret['empty'] = true;
$a->contacts = $ret;
return;
}}
function best_link_url($item,&$sparkle) {
$a = get_app();
$best_url = '';
$sparkle = false;
$clean_url = normalise_link($item['author-link']);
if((local_user()) && (local_user() == $item['uid'])) {
if(isset($a->contacts) && x($a->contacts,$clean_url)) {
if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
$best_url = $a->get_baseurl() . '/redir/' . $a->contacts[$clean_url]['id'];
$sparkle = true;
}
else
$best_url = $a->contacts[$clean_url]['url'];
}
}
if(! $best_url) {
if(strlen($item['author-link']))
$best_url = $item['author-link'];
else
$best_url = $item['url'];
}
return $best_url;
}
if(! function_exists('item_photo_menu')){
function item_photo_menu($item){
$a = get_app();
if (local_user() && (! count($a->contacts)))
load_contact_links(local_user());
$contact_url="";
$pm_url="";
$status_link="";
$photos_link="";
$posts_link="";
$sparkle = false;
$profile_link = best_link_url($item,$sparkle);
if($profile_link === 'mailbox')
$profile_link = '';
if($sparkle) {
$cid = intval(basename($profile_link));
$status_link = $profile_link . "?url=status";
$photos_link = $profile_link . "?url=photos";
$profile_link = $profile_link . "?url=profile";
$pm_url = $a->get_baseurl() . '/message/new/' . $cid;
}
else {
if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
$cid = $item['contact-id'];
}
else {
$cid = 0;
}
}
if(($cid) && (! $item['self'])) {
$contact_url = $a->get_baseurl() . '/contacts/' . $cid;
$posts_link = $a->get_baseurl() . '/network/?cid=' . $cid;
}
$menu = Array(
t("View status") => $status_link,
t("View profile") => $profile_link,
t("View photos") => $photos_link,
t("View recent") => $posts_link,
t("Edit contact") => $contact_url,
t("Send PM") => $pm_url,
);
$args = array($item, &$menu);
call_hooks('item_photo_menu', $args);
$o = "";
foreach($menu as $k=>$v){
if ($v!="") $o .= "<li><a href='$v'>$k</a></li>\n";
}
return $o;
}}
if(! function_exists('like_puller')) {
function like_puller($a,$item,&$arr,$mode) {
$url = '';
$sparkle = '';
$verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE);
if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
$url = $item['author-link'];
if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === 'dfrn') && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
$url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
$sparkle = ' class="sparkle" ';
}
if(! ((isset($arr[$item['parent'] . '-l'])) && (is_array($arr[$item['parent'] . '-l']))))
$arr[$item['parent'] . '-l'] = array();
if(! isset($arr[$item['parent']]))
$arr[$item['parent']] = 1;
else
$arr[$item['parent']] ++;
$arr[$item['parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
}
return;
}}
// Format the like/dislike text for a profile item
// $cnt = number of people who like/dislike the item
// $arr = array of pre-linked names of likers/dislikers
// $type = one of 'like, 'dislike'
// $id = item id
// returns formatted text
if(! function_exists('format_like')) {
function format_like($cnt,$arr,$type,$id) {
$o = '';
if($cnt == 1)
$o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
else {
$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
$o .= (($type === 'like') ?
sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
:
sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
$o .= EOL ;
$total = count($arr);
if($total >= MAX_LIKERS)
$arr = array_slice($arr, 0, MAX_LIKERS - 1);
if($total < MAX_LIKERS)
$arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
$str = implode(', ', $arr);
if($total >= MAX_LIKERS)
$str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
$str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
$o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
}
return $o;
}}
function status_editor($a,$x, $notes_cid = 0) {
$o = '';
$geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
$tpl = get_markup_template('jot-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$geotag' => $geotag,
'$nickname' => $x['nickname'],
'$ispublic' => t('Visible to <strong>everybody</strong>'),
'$linkurl' => t('Please enter a link URL:'),
'$utubeurl' => t('Please enter a YouTube link:'),
'$vidurl' => t("Please enter a video\x28.ogg\x29 link/URL:"),
'$audurl' => t("Please enter an audio\x28.ogg\x29 link/URL:"),
'$whereareu' => t('Where are you right now?'),
'$title' => t('Enter a title for this item')
));
$tpl = get_markup_template("jot.tpl");
$jotplugins = '';
$jotnets = '';
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
$mail_enabled = false;
$pubmail_enabled = false;
if(($x['is_owner']) && (! $mail_disabled)) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
$mail_enabled = true;
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
}
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
. t("Post to Email") . '</div>';
}
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);
if($notes_cid)
$jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$o .= replace_macros($tpl,array(
'$return_path' => $a->cmd,
'$action' => 'item',
'$share' => (($x['button']) ? $x['button'] : t('Share')),
'$upload' => t('Upload photo'),
'$weblink' => t('Insert web link'),
'$youtube' => t('Insert YouTube video'),
'$video' => t('Insert Vorbis [.ogg] video'),
'$audio' => t('Insert Vorbis [.ogg] audio'),
'$setloc' => t('Set your location'),
'$noloc' => t('Clear browser location'),
'$title' => t('Set title'),
'$wait' => t('Please wait'),
'$permset' => t('Permission settings'),
'$ptyp' => (($notes_cid) ? 'note' : 'wall'),
'$content' => '',
'$post_id' => '',
'$baseurl' => $a->get_baseurl(),
'$defloc' => $x['default_location'],
'$visitor' => $x['visitor'],
'$pvisit' => (($notes_cid) ? 'none' : $x['visitor']),
'$emailcc' => t('CC: email addresses'),
'$public' => t('Public post'),
'$jotnets' => $jotnets,
'$emtitle' => t('Example: bob@example.com, mary@example.com'),
'$lockstate' => $x['lockstate'],
'$acl' => $x['acl'],
'$bang' => $x['bang'],
'$profile_uid' => $x['profile_uid'],
));
return $o;
}

View File

@ -19,6 +19,23 @@ class dba {
public $connected = false;
function __construct($server,$user,$pass,$db,$install = false) {
$server = trim($server);
$user = trim($user);
$pass = trim($pass);
$db = trim($db);
if($install) {
if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
notice( sprintf( t('Cannot locate DNS info for database server \'%s\''), $server));
$this->connected = false;
$this->db = null;
return;
}
}
}
$this->db = @new mysqli($server,$user,$pass,$db);
if(! mysqli_connect_errno()) {
$this->connected = true;
@ -61,7 +78,7 @@ class dba {
}
else {
/*
/**
* If dbfail.out exists, we will write any failed calls directly to it,
* regardless of any logging that may or may nor be in effect.
* These usually indicate SQL syntax errors that need to be resolved.

201
include/email.php Normal file
View File

@ -0,0 +1,201 @@
<?php
function email_connect($mailbox,$username,$password) {
if(! function_exists('imap_open'))
return false;
$mbox = imap_open($mailbox,$username,$password);
return $mbox;
}
function email_poll($mbox,$email_addr) {
if(! ($mbox && $email_addr))
return array();;
$search = imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID);
$search2 = imap_search($mbox,'TO "' . $email_addr . '"', SE_UID);
if($search && $search2)
$res = array_merge($search,$search2);
elseif($search)
$res = $search;
else
$res = $search2;
return (($res) ? $res : array());
}
function construct_mailbox_name($mailacct) {
$ret = '{' . $mailacct['server'] . ((intval($mailacct['port'])) ? ':' . $mailacct['port'] : '');
$ret .= (($mailacct['ssltype']) ? '/' . $mailacct['ssltype'] . '/novalidate-cert' : '');
$ret .= '}' . $mailacct['mailbox'];
return $ret;
}
function email_msg_meta($mbox,$uid) {
$ret = (($mbox && $uid) ? imap_fetch_overview($mbox,$uid,FT_UID) : array(array()));
return ((count($ret)) ? $ret[0] : array());
}
function email_msg_headers($mbox,$uid) {
$raw_header = (($mbox && $uid) ? imap_fetchheader($mbox,$uid,FT_UID) : '');
$raw_header = str_replace("\r",'',$raw_header);
$ret = array();
$h = split("\n",$raw_header);
if(count($h))
foreach($h as $line ) {
if (preg_match("/^[a-zA-Z]/", $line)) {
$key = substr($line,0,strpos($line,':'));
$value = substr($line,strpos($line,':')+1);
$last_entry = strtolower($key);
$ret[$last_entry] = trim($value);
}
else {
$ret[$last_entry] .= ' ' . trim($line);
}
}
return $ret;
}
function email_get_msg($mbox,$uid) {
$ret = array();
$struc = (($mbox && $uid) ? imap_fetchstructure($mbox,$uid,FT_UID) : null);
if(! $struc)
return $ret;
if(! $struc->parts) {
$ret['body'] = email_get_part($mbox,$uid,$struc,0);
}
else {
foreach($struc->parts as $ptop => $p) {
$x = email_get_part($mbox,$uid,$p,$ptop + 1);
if($x)
$ret['body'] = $x;
}
}
return $ret;
}
// At the moment - only return plain/text.
// Later we'll repackage inline images as data url's and make the HTML safe
function email_get_part($mbox,$uid,$p,$partno) {
// $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
global $htmlmsg,$plainmsg,$charset,$attachments;
echo $partno;
// DECODE DATA
$data = ($partno)
? imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK)
: imap_body($mbox,$uid,FT_UID|FT_PEEK);
// Any part may be encoded, even plain text messages, so check everything.
if ($p->encoding==4)
$data = quoted_printable_decode($data);
elseif ($p->encoding==3)
$data = base64_decode($data);
// PARAMETERS
// get all parameters, like charset, filenames of attachments, etc.
$params = array();
if ($p->parameters)
foreach ($p->parameters as $x)
$params[strtolower($x->attribute)] = $x->value;
if ($p->dparameters)
foreach ($p->dparameters as $x)
$params[strtolower($x->attribute)] = $x->value;
// ATTACHMENT
// Any part with a filename is an attachment,
// so an attached text file (type 0) is not mistaken as the message.
if ($params['filename'] || $params['name']) {
// filename may be given as 'Filename' or 'Name' or both
$filename = ($params['filename'])? $params['filename'] : $params['name'];
// filename may be encoded, so see imap_mime_header_decode()
$attachments[$filename] = $data; // this is a problem if two files have same name
}
// TEXT
if ($p->type == 0 && $data) {
// Messages may be split in different parts because of inline attachments,
// so append parts together with blank row.
if (strtolower($p->subtype)=='plain')
return (trim($data) ."\n\n");
else
$data = '';
// $htmlmsg .= $data ."<br><br>";
$charset = $params['charset']; // assume all parts are same charset
}
// EMBEDDED MESSAGE
// Many bounce notifications embed the original message as type 2,
// but AOL uses type 1 (multipart), which is not handled here.
// There are no PHP functions to parse embedded messages,
// so this just appends the raw source to the main message.
// elseif ($p->type==2 && $data) {
// $plainmsg .= $data."\n\n";
// }
// SUBPART RECURSION
if ($p->parts) {
foreach ($p->parts as $partno0=>$p2) {
$x = email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1)); // 1.2, 1.2.1, etc.
if($x)
return $x;
}
}
}
function email_header_encode($in_str, $charset) {
$out_str = $in_str;
if ($out_str && $charset) {
// define start delimimter, end delimiter and spacer
$end = "?=";
$start = "=?" . $charset . "?B?";
$spacer = $end . "\r\n " . $start;
// determine length of encoded text within chunks
// and ensure length is even
$length = 75 - strlen($start) - strlen($end);
/*
[EDIT BY danbrown AT php DOT net: The following
is a bugfix provided by (gardan AT gmx DOT de)
on 31-MAR-2005 with the following note:
"This means: $length should not be even,
but divisible by 4. The reason is that in
base64-encoding 3 8-bit-chars are represented
by 4 6-bit-chars. These 4 chars must not be
split between two encoded words, according
to RFC-2047.
*/
$length = $length - ($length % 4);
// encode the string and split it into chunks
// with spacers after each chunk
$out_str = base64_encode($out_str);
$out_str = chunk_split($out_str, $length, $spacer);
// remove trailing spacer and
// add start and end delimiters
$spacer = preg_quote($spacer);
$out_str = preg_replace("/" . $spacer . "$/", "", $out_str);
$out_str = $start . $out_str . $end;
}
return $out_str;
}

44
include/expire.php Normal file
View File

@ -0,0 +1,44 @@
<?php
require_once("boot.php");
function expire_run($argv, $argc){
global $a, $db;
if(is_null($a)) {
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once('session.php');
require_once('datetime.php');
require_once('simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');
$a->set_baseurl(get_config('system','url'));
logger('expire: start');
$r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0");
if(count($r)) {
foreach($r as $rr) {
logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG);
item_expire($rr['uid'],$rr['expire']);
}
}
return;
}
if (array_search(__file__,get_included_files())===0){
expire_run($argv,$argc);
killme();
}

41
include/fcontact.php Normal file
View File

@ -0,0 +1,41 @@
<?php
function fcontact_store($url,$name,$photo) {
$nurl = str_replace(array('https:','//www.'), array('http:','//'), $url);
$r = q("SELECT `id` FROM `fcontact` WHERE `url` = '%s' LIMIT 1",
dbesc($nurl)
);
if(count($r))
return $r[0]['id'];
$r = q("INSERT INTO `fcontact` ( `url`, `name`, `photo` ) VALUES ( '%s', '%s', '%s' ) ",
dbesc($nurl),
dbesc($name),
dbesc($photo)
);
if($r) {
$r = q("SELECT `id` FROM `fcontact` WHERE `url` = '%s' LIMIT 1",
dbesc($nurl)
);
if(count($r))
return $r[0]['id'];
}
return 0;
}
function ffinder_store($uid,$cid,$fid) {
$r = q("INSERT INTO `ffinder` ( `uid`, `cid`, `fid` ) VALUES ( %d, %d, %d ) ",
intval($uid),
intval($cid),
intval($fid)
);
return $r;
}

View File

@ -108,9 +108,9 @@ function group_get_members($gid) {
if(intval($gid)) {
$r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member`
LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
WHERE `gid` = %d AND `group_member`.`uid` = %d",
WHERE `gid` = %d AND `group_member`.`uid` = %d ORDER BY `contact`.`name` ASC ",
intval($gid),
intval($_SESSION['uid'])
intval(local_user())
);
if(count($r))
$ret = $r;
@ -118,9 +118,25 @@ function group_get_members($gid) {
return $ret;
}
function group_public_members($gid) {
$ret = 0;
if(intval($gid)) {
$r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
LEFT JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
WHERE `gid` = %d AND `group_member`.`uid` = %d
AND `contact`.`network` != 'dfrn' AND `contact`.`network` != 'mail' AND `contact`.`network` != 'face' ",
intval($gid),
intval(local_user())
);
if(count($r))
$ret = count($r);
}
return $ret;
}
function group_side($every="contacts",$each="group") {
function group_side($every="contacts",$each="group",$edit = false) {
$o = '';
@ -150,7 +166,7 @@ EOT;
);
if(count($r)) {
foreach($r as $rr)
$o .= " <li class=\"sidebar-group-li\"><a href=\"$each/{$rr['id']}\">{$rr['name']}</a></li>\r\n";
$o .= ' <li class="sidebar-group-li">' . (($edit) ? "<a href=\"group/{$rr['id']}\" title=\"" . t('Edit') . "\" ><img src=\"images/spencil.gif\" alt=\"" . t('Edit') . "\"></a> " : "") . "<a href=\"$each/{$rr['id']}\">{$rr['name']}</a></li>\r\n";
}
$o .= " </ul>\r\n </div>\r\n</div>";

View File

@ -1,10 +1,10 @@
<?php
function hostxrd($hostname) {
function hostxrd($baseurl) {
header("Content-type: text/xml");
$tpl = file_get_contents('view/xrd_host.tpl');
echo str_replace('$domain',$hostname,$tpl);
echo str_replace('$domain',$baseurl,$tpl);
session_write_close();
exit();

View File

@ -113,7 +113,7 @@ function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0)
$items = $r;
$feed_template = load_view_file('view/atom_feed.tpl');
$feed_template = get_markup_template('atom_feed.tpl');
$atom = '';
@ -180,7 +180,7 @@ function construct_activity_object($item) {
if($item['object']) {
$o = '<as:object>' . "\r\n";
$r = @simplexml_load_string($item['object']);
$r = parse_xml_string($item['object']);
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
@ -206,7 +206,7 @@ function construct_activity_target($item) {
if($item['target']) {
$o = '<as:target>' . "\r\n";
$r = @simplexml_load_string($item['target']);
$r = parse_xml_string($item['target']);
if($r->type)
$o .= '<as:object-type>' . xmlify($r->type) . '</as:object-type>' . "\r\n";
if($r->id)
@ -241,8 +241,14 @@ function get_atom_elements($feed,$item) {
$res = array();
$author = $item->get_author();
$res['author-name'] = unxmlify($author->get_name());
$res['author-link'] = unxmlify($author->get_link());
if($author) {
$res['author-name'] = unxmlify($author->get_name());
$res['author-link'] = unxmlify($author->get_link());
}
else {
$res['author-name'] = unxmlify($feed->get_title());
$res['author-link'] = unxmlify($feed->get_permalink());
}
$res['uri'] = unxmlify($item->get_id());
$res['title'] = unxmlify($item->get_title());
$res['body'] = unxmlify($item->get_content());
@ -343,12 +349,14 @@ function get_atom_elements($feed,$item) {
// the wild, by sanitising it and converting supported tags to bbcode before we rip out any remaining
// html.
if((strpos($res['body'],'<') !== false) || (strpos($res['body'],'>') !== false)) {
$res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $res['body']);
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
$res['body'] = oembed_html2bbcode($res['body']);
$config = HTMLPurifier_Config::createDefault();
@ -401,6 +409,17 @@ function get_atom_elements($feed,$item) {
$res['edited'] = $item->get_date('c');
// Disallow time travelling posts
$d1 = strtotime($res['created']);
$d2 = strtotime($res['edited']);
$d3 = strtotime('now');
if($d1 > $d3)
$res['created'] = datetime_convert();
if($d2 > $d3)
$res['edited'] = datetime_convert();
$rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
$res['owner-name'] = unxmlify($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']);
@ -440,7 +459,45 @@ function get_atom_elements($feed,$item) {
if((x($res,'verb')) && ($res['verb'] === 'http://ostatus.org/schema/1.0/unfollow'))
$res['verb'] = ACTIVITY_UNFOLLOW;
$cats = $item->get_categories();
if($cats) {
$tag_arr = array();
foreach($cats as $cat) {
$term = $cat->get_term();
if(! $term)
$term = $cat->get_label();
$scheme = $cat->get_scheme();
if($scheme && $term && stristr($scheme,'X-DFRN:'))
$tag_arr[] = substr($scheme,7,1) . '[url=' . unxmlify(substr($scheme,9)) . ']' . unxmlify($term) . '[/url]';
elseif($term)
$tag_arr[] = notags(trim($term));
}
$res['tag'] = implode(',', $tag_arr);
}
$attach = $item->get_enclosures();
if($attach) {
$att_arr = array();
foreach($attach as $att) {
$len = intval($att->get_length());
$link = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_link()))));
$title = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_title()))));
$type = str_replace(array(',','"'),array('%2D','%22'),notags(trim(unxmlify($att->get_type()))));
if(strpos($type,';'))
$type = substr($type,0,strpos($type,';'));
if((! $link) || (strpos($link,'http') !== 0))
continue;
if(! $title)
$title = ' ';
if(! $type)
$type = 'application/octet-stream';
$att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]';
}
$res['attach'] = implode(',', $att_arr);
}
$rawobj = $item->get_item_tags(NAMESPACE_ACTIVITY, 'object');
@ -467,6 +524,10 @@ function get_atom_elements($feed,$item) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
@ -506,6 +567,9 @@ function get_atom_elements($feed,$item) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
$res['body'] = preg_replace('#<iframe[^>].+?' . 'http://www.youtube.com/embed/([A-Za-z0-9\-_=]+).+?</iframe>#s',
'[youtube]$1[/youtube]', $res['body']);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
@ -598,6 +662,8 @@ function item_store($arr,$force_parent = false) {
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
$arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
$arr['tag'] = ((x($arr,'tag')) ? notags(trim($arr['tag'])) : '');
$arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
@ -645,6 +711,7 @@ function item_store($arr,$force_parent = false) {
$parent_id = 0;
$arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $arr['uri'];
$arr['gravity'] = 0;
}
else {
logger('item_store: item parent was not found - ignoring item');
@ -702,6 +769,18 @@ function item_store($arr,$force_parent = false) {
intval($current_post)
);
/**
* If this is now the last-child, force all _other_ children of this parent to *not* be last-child
*/
if($arr['last-child']) {
$r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
dbesc($arr['uri']),
intval($arr['uid']),
intval($current_post)
);
}
return $current_post;
}
@ -739,7 +818,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
if(! $rino_enable)
$rino = 0;
$url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
$url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
logger('dfrn_deliver: ' . $url);
@ -760,7 +839,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
return 3;
}
$res = simplexml_load_string($xml);
$res = parse_xml_string($xml);
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
return (($res->status) ? $res->status : 3);
@ -799,14 +878,14 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
if($dissolve)
$postvars['dissolve'] = '1';
if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
$postvars['data'] = $atom;
}
elseif($owner['page-flags'] == PAGE_COMMUNITY) {
if((($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
$postvars['data'] = $atom;
$postvars['perm'] = 'rw';
}
else {
$postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
$postvars['perm'] = 'r';
}
if($rino && $rino_allowed && (! $dissolve)) {
@ -848,17 +927,15 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
if((! $curl_stat) || (! strlen($xml)))
return(-1); // timed out
if(strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: phase 2: no valid XML returned');
logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
return 3;
}
$res = simplexml_load_string($xml);
$res = parse_xml_string($xml);
return $res->status;
return $res->status;
}
@ -878,7 +955,7 @@ function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
*
*/
function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $secure_feed = false) {
require_once('simplepie/simplepie.inc');
@ -893,6 +970,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
if($feed->error())
logger('consume_feed: Error parsing XML: ' . $feed->error());
$permalink = $feed->get_permalink();
// Check at the feed level for updated contact name and/or photo
@ -1137,6 +1215,13 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
if(! x($datarray,'author-name'))
$datarray['author-name'] = $contact['name'];
if(! x($datarray,'author-link'))
$datarray['author-link'] = $contact['url'];
if(! x($datarray,'author-avatar'))
$datarray['author-avatar'] = $contact['thumb'];
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
@ -1207,8 +1292,18 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
// Head post of a conversation. Have we seen it? If not, import it.
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
if(is_array($contact)) {
if(! x($datarray,'author-name'))
$datarray['author-name'] = $contact['name'];
if(! x($datarray,'author-link'))
$datarray['author-link'] = $contact['url'];
if(! x($datarray,'author-avatar'))
$datarray['author-avatar'] = $contact['thumb'];
}
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
@ -1252,7 +1347,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
if(! is_array($contact))
return;
if($contact['network'] === 'stat') {
if($contact['network'] === 'stat' || stristr($permalink,'twitter.com')) {
if(strlen($datarray['title']))
unset($datarray['title']);
$datarray['last-child'] = 1;
@ -1299,8 +1394,8 @@ function new_follower($importer,$contact,$datarray,$item) {
// create contact record - set to readonly
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
`blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1 ) ",
`blocked`, `readonly`, `pending`, `writable` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 1, 1, 1 ) ",
intval($importer['uid']),
dbesc(datetime_convert()),
dbesc($url),
@ -1336,7 +1431,7 @@ function new_follower($importer,$contact,$datarray,$item) {
$a = get_app();
if(count($r)) {
if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
$email_tpl = load_view_file('view/follow_notify_eml.tpl');
$email_tpl = get_intltext_template('follow_notify_eml.tpl');
$email = replace_macros($email_tpl, array(
'$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),
'$url' => $url,
@ -1347,7 +1442,9 @@ function new_follower($importer,$contact,$datarray,$item) {
$res = mail($r[0]['email'],
t("You have a new follower at ") . $a->config['sitename'],
$email,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
}
}
@ -1426,17 +1523,24 @@ function atom_author($tag,$name,$uri,$h,$w,$photo) {
function atom_entry($item,$type,$author,$owner,$comment = false) {
$a = get_app();
if($item['deleted'])
return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '" />' . "\r\n";
$a = get_app();
if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid'])
$body = fix_private_photos($item['body'],$owner['uid']);
else
$body = $item['body'];
$o = "\r\n\r\n<entry>\r\n";
if(is_array($author))
$o .= atom_author('author',$author['name'],$author['url'],80,80,$author['thumb']);
else
$o .= atom_author('author',$item['name'],$item['url'],80,80,$item['thumb']);
$o .= atom_author('author',(($item['author-name']) ? $item['author-name'] : $item['name']),(($item['author-link']) ? $item['author-link'] : $item['url']),80,80,(($item['author-avatar']) ? $item['author-avatar'] : $item['thumb']));
if(strlen($item['owner-name']))
$o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
@ -1447,8 +1551,8 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
$o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
$o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
$o .= '<dfrn:env>' . base64url_encode($item['body'], true) . '</dfrn:env>' . "\r\n";
$o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
$o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
$o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($body) : $body) . '</content>' . "\r\n";
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
if($comment)
$o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
@ -1473,6 +1577,15 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
if(strlen($actarg))
$o .= $actarg;
$tags = item_getfeedtags($item);
if(count($tags)) {
foreach($tags as $t) {
$o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
}
}
$o .= item_getfeedattach($item);
$mentioned = get_mentions($item);
if($mentioned)
$o .= $mentioned;
@ -1483,4 +1596,125 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
return $o;
}
function fix_private_photos($s,$uid) {
$a = get_app();
logger('fix_private_photos');
if(preg_match("/\[img\](.+?)\[\/img\]/is",$s,$matches)) {
$image = $matches[1];
logger('fix_private_photos: found photo ' . $image);
if(stristr($image ,$a->get_baseurl() . '/photo/')) {
$i = basename($image);
$i = str_replace('.jpg','',$i);
$x = strpos($i,'-');
if($x) {
$res = substr($i,$x+1);
$i = substr($i,0,$x);
$r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `scale` = %d AND `uid` = %d",
dbesc($i),
intval($res),
intval($uid)
);
if(count($r)) {
logger('replacing photo');
$s = str_replace($image, 'data:image/jpg;base64,' . base64_encode($r[0]['data']), $s);
}
}
logger('fix_private_photos: replaced: ' . $s, LOGGER_DATA);
}
}
return($s);
}
function item_getfeedtags($item) {
$ret = array();
$matches = false;
$cnt = preg_match_all('|\#\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches);
if($cnt) {
for($x = 0; $x < count($matches); $x ++) {
if($matches[1][$x])
$ret[] = array('#',$matches[1][$x], $matches[2][$x]);
}
}
$matches = false;
$cnt = preg_match_all('|\@\[url\=(.+?)\](.+?)\[\/url\]|',$item['tag'],$matches);
if($cnt) {
for($x = 0; $x < count($matches); $x ++) {
if($matches[1][$x])
$ret[] = array('#',$matches[1][$x], $matches[2][$x]);
}
}
return $ret;
}
function item_getfeedattach($item) {
$ret = '';
$arr = explode(',',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.+?)\" size=\"(.+?)\" type=\"(.+?)\" title=\"(.+?)\"\[\/attach\]|',$r,$matches);
if($cnt) {
$ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
if(intval($matches[2]))
$ret .= 'size="' . intval($matches[2]) . '" ';
if($matches[4] !== ' ')
$ret .= 'title="' . xmlify(trim($matches[4])) . '" ';
$ret .= ' />' . "\r\n";
}
}
}
return $ret;
}
function item_expire($uid,$days) {
if((! $uid) || (! $days))
return;
$r = q("SELECT * FROM `item`
WHERE `uid` = %d
AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY
AND `id` = `parent`
AND `deleted` = 0",
intval($uid),
intval($days)
);
if(! count($r))
return;
logger('expire: # items=' . count($r) );
foreach($r as $item) {
// Only expire posts, not photos and photo comments
if(strlen($item['resource-id']))
continue;
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($item['id'])
);
// kill the kids
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($item['parent-uri']),
intval($item['uid'])
);
}
proc_run('php',"include/notifier.php","expire","$uid");
}

View File

@ -26,6 +26,8 @@
var pr = 0;
var liking = 0;
var in_progress = false;
var langSelect = false;
var commentBusy = false;
$(document).ready(function() {
$.ajaxSetup({cache: false});
@ -45,6 +47,18 @@
$('#pause').html('');
}
}
// F8 - show/hide language selector
if(event.keyCode == '119') {
if(langSelect) {
langSelect = false;
$('#language-selector').hide();
}
else {
langSelect = true;
$('#language-selector').show();
}
}
// this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
// update: incompatible usage of onKeyDown vs onKeyPress
// if(event.keyCode == '36' && event.shiftKey == true) {
@ -77,26 +91,26 @@
$.get("ping",function(data) {
$(data).find('result').each(function() {
var net = $(this).find('net').text();
if(net == 0) { net = ''; }
if(net == 0) { net = ''; $('#net-update').hide() } else { $('#net-update').show() }
$('#net-update').html(net);
var home = $(this).find('home').text();
if(home == 0) { home = ''; }
if(home == 0) { home = ''; $('#home-update').hide() } else { $('#home-update').show() }
$('#home-update').html(home);
var mail = $(this).find('mail').text();
if(mail == 0) { mail = ''; }
if(mail == 0) { mail = ''; $('#mail-update').hide() } else { $('#mail-update').show() }
$('#mail-update').html(mail);
var intro = $(this).find('intro').text();
var register = $(this).find('register').text();
if(intro == 0) { intro = ''; }
if(register != 0 && intro != '') { intro = intro+'/'+register; }
if(register != 0 && intro == '') { intro = '0/'+register; }
if (intro == '') { $('#notify-update').hide() } else { $('#notify-update').show() }
$('#notify-update').html(intro);
});
}) ;
}
timer = setTimeout(NavUpdate,30000);
}
function liveUpdate() {
@ -113,12 +127,21 @@
$.get(update_url,function(data) {
in_progress = false;
$('.ccollapse-wrapper',data).each(function() {
var ident = $(this).attr('id');
var is_hidden = $('#' + ident).is(':hidden');
if($('#' + ident).length) {
$('#' + ident).replaceWith($(this));
if(is_hidden)
$('#' + ident).hide();
}
});
$('.wall-item-outside-wrapper',data).each(function() {
var ident = $(this).attr('id');
if($('#' + ident).length == 0) {
$('img',this).each(function() {
$(this).attr('src',$(this).attr('dst'));
});
if($('#' + ident).length == 0) {
$('img',this).each(function() {
$(this).attr('src',$(this).attr('dst'));
});
$('#' + prev).after($(this));
}
else {
@ -127,29 +150,26 @@
$('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
$('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like'));
$('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike'));
$('#' + ident + ' ' + '.my-comment-photo').each(function() {
$(this).attr('src',$(this).attr('dst'));
});
$('#' + ident + ' ' + '.my-comment-photo').each(function() {
$(this).attr('src',$(this).attr('dst'));
});
}
prev = ident;
});
$('.like-rotator').hide();
if(commentBusy) {
commentBusy = false;
$('body').css('cursor', 'auto');
}
});
}
function imgbright(node) {
$(node).attr("src",$(node).attr("src").replace('hide','show'));
$(node).css('width',24);
$(node).css('height',24);
$(node).removeClass("drophide").addClass("drop");
}
function imgdull(node) {
$(node).attr("src",$(node).attr("src").replace('show','hide'));
$(node).css('width',16);
$(node).css('height',16);
$(node).removeClass("drop").addClass("drophide");
}
// Since our ajax calls are asynchronous, we will give a few
@ -215,6 +235,8 @@
}
function post_comment(id) {
commentBusy = true;
$('body').css('cursor', 'wait');
$.post(
"item",
$("#comment-edit-form-" + id).serialize(),
@ -231,10 +253,49 @@
if(data.reload) {
window.location.href=data.reload;
}
},
"json"
);
return false;
}
function bin2hex(s){
// Converts the binary representation of data to hex
//
// version: 812.316
// discuss at: http://phpjs.org/functions/bin2hex
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Linuxworld
// * example 1: bin2hex('Kev');
// * returns 1: '4b6576'
// * example 2: bin2hex(String.fromCharCode(0x00));
// * returns 2: '00'
var v,i, f = 0, a = [];
s += '';
f = s.length;
for (i = 0; i<f; i++) {
a[i] = s.charCodeAt(i).toString(16).replace(/^([\da-f])$/,"0$1");
}
return a.join('');
}
function groupChangeMember(gid,cid) {
$('body .fakelink').css('cursor', 'wait');
$.get('group/' + gid + '/' + cid, function(data) {
$('#group-update-wrapper').html(data);
$('body .fakelink').css('cursor', 'auto');
});
}
function profChangeMember(gid,cid) {
$('body .fakelink').css('cursor', 'wait');
$.get('profperm/' + gid + '/' + cid, function(data) {
$('#prof-update-wrapper').html(data);
$('body .fakelink').css('cursor', 'auto');
});
}

View File

@ -27,24 +27,23 @@ function nav(&$a) {
$myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
$a->page['nav'] .= '<div id="site-location">' . $myident . substr($a->get_baseurl(),strpos($a->get_baseurl(),'//') + 2 ) . '</div>';
$sitelocation = $myident . substr($a->get_baseurl(),strpos($a->get_baseurl(),'//') + 2 );
// nav links: array of array('href', 'text', 'extra css classes')
$nav = Array();
/**
* Display login or logout
*/
if(local_user()) {
$a->page['nav'] .= '<a id="nav-logout-link" class="nav-link" href="logout">' . t('Logout') . "</a>\r\n";
$nav['logout'] = Array('logout',t('Logout'), "");
}
else {
$a->page['nav'] .= '<a id="nav-login-link" class="nav-login-link';
if ($a->module == 'login') { $a->page['nav'] .= ' nav-selected'; }
$a->page['nav'] .= '" href="login">' . t('Login') . "</a>\r\n";
$nav['login'] = Array('login',t('Login'), ($a->module == 'login'?'nav-selected':''));
}
$a->page['nav'] .= "<span id=\"nav-link-wrapper\" >\r\n";
/**
* "Home" should also take you home from an authenticated remote profile connection
@ -53,18 +52,22 @@ function nav(&$a) {
$homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
if(($a->module != 'home') && (! (local_user())))
$a->page['nav'] .= '<a id="nav-home-link" class="nav-commlink" href="' . $homelink . '">' . t('Home') . "</a>\r\n";
$nav['home'] = array($homelink, t('Home'), "");
if(($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user()))
$a->page['nav'] .= '<a id="nav-register-link" class="nav-commlink" href="register" >'
. t('Register') . "</a>\r\n";
$nav['register'] = array('register',t('Register'), "");
if(strlen($a->apps)) {
$a->page['nav'] .= '<a id="nav-apps-link" class="nav-link" href="apps">' . t('Apps') . "</a>\r\n";
}
$help_url = $a->get_baseurl() . '/help';
$a->page['nav'] .= '<a id="nav-search-link" class="nav-link" href="search">' . t('Search') . "</a>\r\n";
if(! get_config('system','hide-help'))
$nav['help'] = array($help_url, t('Help'), "");
$nav['apps'] = array('apps', t('Apps'), "");
$nav['search'] = array('search', t('Search'), "");
$gdirpath = 'directory';
@ -74,7 +77,7 @@ function nav(&$a) {
$gdirpath = $gdir;
}
$a->page['nav'] .= '<a id="nav-directory-link" class="nav-link" href="' . $gdirpath . '">' . t('Directory') . "</a>\r\n";
$nav['directory'] = array($gdirpath, t('Directory'), "");
/**
*
@ -84,36 +87,30 @@ function nav(&$a) {
if(local_user()) {
$a->page['nav'] .= '<a id="nav-network-link" class="nav-commlink" href="network">' . t('Network')
. '</a><span id="net-update" class="nav-ajax-left"></span>' . "\r\n";
$nav['network'] = array('network', t('Network'), "");
$nav['home'] = array('profile/' . $a->user['nickname'], t('Home'), "");
$a->page['nav'] .= '<a id="nav-home-link" class="nav-commlink" href="profile/' . $a->user['nickname'] . '">'
. t('Home') . '</a><span id="home-update" class="nav-ajax-left"></span>' . "\r\n";
/* only show friend requests for normal pages. Other page types have automatic friendship. */
if($_SESSION['page_flags'] == PAGE_NORMAL) {
$a->page['nav'] .= '<a id="nav-notify-link" class="nav-commlink" href="notifications">' . t('Notifications')
. '</a><span id="notify-update" class="nav-ajax-left"></span>' . "\r\n";
$nav['notifications'] = array('notifications', t('Notifications'), "");
}
$a->page['nav'] .= '<a id="nav-messages-link" class="nav-commlink" href="message">' . t('Messages')
. '</a><span id="mail-update" class="nav-ajax-left"></span>' . "\r\n";
$nav['messages'] = array('message', t('Messages'), "");
if(is_array($a->identities) && count($a->identities) > 1) {
$a->page['nav'] .= '<a id="nav-manage-link" class="nav-commlink" href="manage">' . t('Manage') . '</a>' . "\r\n";
$nav['manage'] = array('manage', t('Manage'), "");
}
$a->page['nav'] .= '<a id="nav-settings-link" class="nav-link" href="settings">' . t('Settings') . "</a>\r\n";
$a->page['nav'] .= '<a id="nav-profiles-link" class="nav-link" href="profiles">' . t('Profiles') . "</a>\r\n";
$a->page['nav'] .= '<a id="nav-contacts-link" class="nav-link" href="contacts">' . t('Contacts') . "</a>\r\n";
$nav['settings'] = array('settings', t('Settings'),"");
$nav['profiles'] = array('profiles', t('Profiles'),"");
$nav['contacts'] = array('contacts', t('Contacts'),"");
}
$a->page['nav'] .= "</span>\r\n<span id=\"nav-end\"></span>\r\n";
/**
*
@ -124,10 +121,17 @@ function nav(&$a) {
$banner = get_config('system','banner');
if($banner === false)
$banner .= '<a href="http://friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendika.com">Friendika</a></span>';
$banner .= '<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>';
$a->page['nav'] .= '<span id="banner">' . $banner . '</span>';
$tpl = get_markup_template('nav.tpl');
$a->page['nav'] .= replace_macros($tpl, array(
'$langselector' => lang_selector(),
'$sitelocation' => $sitelocation,
'$nav' => $nav,
'$banner' => $banner,
));
call_hooks('page_header', $a->page['nav']);

View File

@ -20,6 +20,8 @@ function notifier_run($argv, $argc){
require_once('include/items.php');
require_once('include/bbcode.php');
load_hooks();
if($argc < 3)
return;
@ -40,6 +42,7 @@ function notifier_run($argv, $argc){
break;
}
$expire = false;
$top_level = false;
$recipients = array();
$url_recipients = array();
@ -57,10 +60,21 @@ function notifier_run($argv, $argc){
$item = $message[0];
}
elseif($cmd === 'expire') {
$expire = true;
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP - INTERVAL 10 MINUTE",
intval($item_id)
);
$uid = $item_id;
$item_id = 0;
if(! count($items))
return;
}
else {
// find ancestors
$r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
intval($item_id)
);
@ -68,6 +82,7 @@ function notifier_run($argv, $argc){
return;
}
$parent_item = $r[0];
$parent_id = intval($r[0]['parent']);
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
@ -76,11 +91,10 @@ function notifier_run($argv, $argc){
intval($parent_id)
);
if(! count($items)){
if(! count($items)) {
return;
}
// avoid race condition with deleting entries
if($items[0]['deleted']) {
@ -98,11 +112,11 @@ function notifier_run($argv, $argc){
intval($uid)
);
if(count($r))
$owner = $r[0];
else {
if(! count($r))
return;
}
$owner = $r[0];
$hub = get_config('system','huburl');
// If this is a public conversation, notify the feed hub
@ -117,7 +131,7 @@ function notifier_run($argv, $argc){
$parent = $items[0];
if($parent['type'] === 'remote') {
if($parent['type'] === 'remote' && (! $expire)) {
// local followup to remote post
$followup = true;
$notify_hub = false; // not public
@ -177,8 +191,8 @@ function notifier_run($argv, $argc){
$contacts = $r;
}
$feed_template = load_view_file('view/atom_feed.tpl');
$mail_template = load_view_file('view/atom_mail.tpl');
$feed_template = get_markup_template('atom_feed.tpl');
$mail_template = get_markup_template('atom_mail.tpl');
$atom = '';
$slaps = array();
@ -235,6 +249,7 @@ function notifier_run($argv, $argc){
}
else {
foreach($items as $item) {
if(! $item['parent'])
continue;
@ -242,9 +257,9 @@ function notifier_run($argv, $argc){
if(! $contact)
continue;
$atom .= atom_entry($item,'text',$contact,$owner,true);
$atom .= atom_entry($item,'text',$contact,$owner,true);
if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link']))
if(($top_level) && ($notify_hub) && ($item['author-link'] === $item['owner-link']) && (! $expire))
$slaps[] = atom_entry($item,'html',$contact,$owner,true);
}
}
@ -255,12 +270,30 @@ function notifier_run($argv, $argc){
logger('notifier: slaps: ' . print_r($slaps,true), LOGGER_DATA);
// If this is a public message and pubmail is set on the parent, include all your email contacts
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
if(! $mail_disabled) {
if((! strlen($parent_item['allow_cid'])) && (! strlen($parent_item['allow_gid']))
&& (! strlen($parent_item['deny_cid'])) && (! strlen($parent_item['deny_gid']))
&& (intval($parent_item['pubmail']))) {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `network` = '%s'",
intval($uid),
dbesc(NETWORK_MAIL)
);
if(count($r)) {
foreach($r as $rr)
$recipients[] = $rr['id'];
}
}
}
if($followup)
$recip_str = $parent['contact-id'];
else
$recip_str = implode(', ', $recipients);
$r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
dbesc($recip_str)
);
@ -319,7 +352,7 @@ function notifier_run($argv, $argc){
// only send salmon if public - e.g. if it's ok to notify
// a public hub, it's ok to send a salmon
if(count($slaps) && $notify_hub) {
if((count($slaps)) && ($notify_hub) && (! $expire)) {
logger('notifier: slapdelivery: ' . $contact['name']);
foreach($slaps as $slappy) {
if($contact['notify']) {
@ -340,8 +373,82 @@ function notifier_run($argv, $argc){
}
break;
case 'mail':
// WARNING: does not currently convert to RFC2047 header encodings, etc.
$addr = $contact['addr'];
if(! strlen($addr))
break;
if($cmd === 'wall-new' || $cmd === 'comment-new') {
$it = null;
if($cmd === 'wall-new')
$it = $items[0];
else {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($argv[2]),
intval($uid)
);
if(count($r))
$it = $r[0];
}
if(! $it)
break;
$local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if(! count($local_user))
break;
$reply_to = '';
$r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
if($r1 && $r1[0]['reply_to'])
$reply_to = $r1[0]['reply_to'];
$subject = (($it['title']) ? $it['title'] : t("\x28no subject\x29")) ;
$headers = 'From: ' . $local_user[0]['username'] . ' <' . $local_user[0]['email'] . '>' . "\n";
if($reply_to)
$headers .= 'Reply-to: ' . $reply_to . "\n";
$headers .= 'Message-id: <' . $it['uri'] . '>' . "\n";
if($it['uri'] !== $it['parent-uri']) {
$header .= 'References: <' . $it['parent-uri'] . '>' . "\n";
if(! strlen($it['title'])) {
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' LIMIT 1",
dbesc($it['parent-uri'])
);
if(count($r)) {
$subtitle = $r[0]['title'];
if($subtitle) {
if(strncasecmp($subtitle,'RE:',3))
$subject = $subtitle;
else
$subject = 'Re: ' . $subtitle;
}
}
}
}
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
$html = prepare_body($it);
$message = '<html><body>' . $html . '</body></html>';
logger('notifier: email delivery to ' . $addr);
mail($addr, $subject, $message, $headers);
}
break;
case 'dspr':
case 'feed':
case 'face':
default:
break;
}
@ -350,7 +457,7 @@ function notifier_run($argv, $argc){
// send additional slaps to mentioned remote tags (@foo@example.com)
if($slap && count($url_recipients) && $followup && $notify_hub) {
if($slap && count($url_recipients) && $followup && $notify_hub && (! $expire)) {
foreach($url_recipients as $url) {
if($url) {
logger('notifier: urldelivery: ' . $url);

46
include/pgettext.php Normal file
View File

@ -0,0 +1,46 @@
<?php
/**
* translation support
*/
// load string translation table for alternate language
if(! function_exists('load_translation_table')) {
function load_translation_table($lang) {
global $a;
if(file_exists("view/$lang/strings.php"))
include("view/$lang/strings.php");
}}
// translate string if translation exists
if(! function_exists('t')) {
function t($s) {
$a = get_app();
if(x($a->strings,$s)) {
$t = $a->strings[$s];
return is_array($t)?$t[0]:$t;
}
return $s;
}}
if(! function_exists('tt')){
function tt($singular, $plural, $count){
$a = get_app();
if(x($a->strings,$singular)) {
$t = $a->strings[$singular];
$k = string_plural_select($count);
return is_array($t)?$t[$k]:$t;
}
if ($count!=1){
return $plural;
} else {
return $singular;
}
}}

View File

@ -1,4 +1,5 @@
<?php
require_once("boot.php");
function poller_run($argv, $argc){
@ -15,20 +16,35 @@ function poller_run($argv, $argc){
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once('session.php');
require_once('datetime.php');
require_once('simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/email.php');
$a->set_baseurl(get_config('system','url'));
load_hooks();
logger('poller: start');
// run queue delivery process in the background
proc_run('php',"include/queue.php");
// once daily run expire in background
$d1 = get_config('system','last_expire_day');
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
if($d2 != intval($d1)) {
set_config('system','last_expire_day',$d2);
proc_run('php','include/expire.php');
}
// clear old cache
q("DELETE FROM `cache` WHERE `updated` < '%s'",
dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
@ -47,10 +63,12 @@ function poller_run($argv, $argc){
$sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
reload_plugins();
$d = datetime_convert();
call_hooks('cron', $d);
reload_plugins();
$contacts = q("SELECT `id` FROM `contact`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
@ -74,6 +92,9 @@ function poller_run($argv, $argc){
continue;
foreach($res as $contact) {
$xml = false;
if($manual_id)
$contact['last-update'] = '0000-00-00 00:00:00';
@ -147,25 +168,29 @@ function poller_run($argv, $argc){
: datetime_convert('UTC','UTC',$contact['last-update'], ATOM_TIME)
);
if($contact['network'] === 'dfrn') {
if($contact['network'] === NETWORK_DFRN) {
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
if(intval($contact['duplex']) && $contact['dfrn-id'])
$idtosend = '0:' . $orig_id;
if(intval($contact['duplex']) && $contact['issued-id'])
$idtosend = '1:' . $orig_id;
$idtosend = '1:' . $orig_id;
// they have permission to write to us. We already filtered this in the contact query.
$perm = 'rw';
$url = $contact['poll'] . '?dfrn_id=' . $idtosend
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
. '&type=data&last_update=' . $last_update ;
. '&type=data&last_update=' . $last_update
. '&perm=' . $perm ;
$xml = fetch_url($url);
$handshake_xml = fetch_url($url);
logger('poller: handshake with url ' . $url . ' returns xml: ' . $xml, LOGGER_DATA);
logger('poller: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA);
if(! $xml) {
if(! $handshake_xml) {
logger("poller: $url appears to be dead - marking for death ");
// dead connection - might be a transient event, or this might
// mean the software was uninstalled or the domain expired.
@ -182,7 +207,7 @@ function poller_run($argv, $argc){
continue;
}
if(! strstr($xml,'<?xml')) {
if(! strstr($handshake_xml,'<?xml')) {
logger('poller: response from ' . $url . ' did not contain XML.');
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
@ -192,7 +217,7 @@ function poller_run($argv, $argc){
}
$res = simplexml_load_string($xml);
$res = parse_xml_string($handshake_xml);
if(intval($res->status) == 1) {
logger("poller: $url replied status 1 - marking for death ");
@ -239,56 +264,181 @@ function poller_run($argv, $argc){
$final_dfrn_id = substr($final_dfrn_id,2);
if($final_dfrn_id != $orig_id) {
logger('poller: ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
// did not decode properly - cannot trust this site
continue;
}
$postvars['dfrn_id'] = $idtosend;
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
$postvars['perm'] = 'rw';
$xml = post_url($contact['poll'],$postvars);
}
else {
elseif(($contact['network'] === NETWORK_OSTATUS)
|| ($contact['network'] === NETWORK_DIASPORA)
|| ($contact['network'] === NETWORK_FEED) ) {
// $contact['network'] !== 'dfrn'
// Upgrading DB fields from an older Friendika version
// Will only do this once per notify-enabled OStatus contact
if(($contact['notify']) && (! $contact['writable'])) {
q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d LIMIT 1",
intval($contact['id'])
);
}
$xml = fetch_url($contact['poll']);
}
elseif($contact['network'] === NETWORK_MAIL) {
logger('poller: received xml : ' . $xml, LOGGER_DATA);
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
if($mail_disabled)
continue;
if(! strstr($xml,'<?xml')) {
logger('poller: post_handshake: response from ' . $url . ' did not contain XML.');
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($contact['id'])
$mbox = null;
$x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
intval($importer_uid)
);
continue;
$mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($x) && count($mailconf)) {
$mailbox = construct_mailbox_name($mailconf[0]);
$password = '';
openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$mailconf[0]['user'],$password);
unset($password);
if($mbox) {
q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($mailconf[0]['id']),
intval($importer_uid)
);
}
}
if($mbox) {
$msgs = email_poll($mbox,$contact['addr']);
if(count($msgs)) {
foreach($msgs as $msg_uid) {
$datarray = array();
$meta = email_msg_meta($mbox,$msg_uid);
$headers = email_msg_headers($mbox,$msg_uid);
// look for a 'references' header and try and match with a parent item we have locally.
$raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
$datarray['uri'] = trim($meta->message_id,'<>');
if($raw_refs) {
$refs_arr = explode(' ', $raw_refs);
if(count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++)
$refs_arr[$x] = "'" . str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x])) . "'";
}
$qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
intval($importer_uid)
);
if(count($r))
$datarray['parent-uri'] = $r[0]['uri'];
}
if(! x($datarray,'parent-uri'))
$datarray['parent-uri'] = $datarray['uri'];
// Have we seen it before?
$r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
intval($importer_uid),
dbesc($datarray['uri'])
);
if(count($r)) {
if($meta->deleted && ! $r[0]['deleted']) {
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($r[0]['id'])
);
}
continue;
}
$datarray['title'] = notags(trim($meta->subject));
$datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
$r = email_get_msg($mbox,$msg_uid);
if(! $r)
continue;
$datarray['body'] = escape_tags($r['body']);
// some mailing lists have the original author as 'from' - add this sender info to msg body.
// todo: adding a gravatar for the original author would be cool
if(! stristr($meta->from,$contact['addr']))
$datarray['body'] = t('From: ') . escape_tags($meta->from) . "\n\n" . $datarray['body'];
$datarray['uid'] = $importer_uid;
$datarray['contact-id'] = $contact['id'];
if($datarray['parent-uri'] === $datarray['uri'])
$datarray['private'] = 1;
$datarray['author-name'] = $contact['name'];
$datarray['author-link'] = 'mailbox';
$datarray['author-avatar'] = $contact['photo'];
$stored_item = item_store($datarray);
q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d",
dbesc($datarray['parent-uri']),
intval($importer_uid)
);
q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
intval($stored_item)
);
}
}
imap_close($mbox);
}
}
elseif($contact['network'] === NETWORK_FACEBOOK) {
// TODO: work in progress
}
consume_feed($xml,$importer,$contact,$hub,1);
if($xml) {
logger('poller: received xml : ' . $xml, LOGGER_DATA);
// do it twice. Ensures that children of parents which may be later in the stream aren't tossed
consume_feed($xml,$importer,$contact,$hub,1);
if(! strstr($xml,'<?xml')) {
logger('poller: post_handshake: response from ' . $url . ' did not contain XML.');
$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($contact['id'])
);
continue;
}
if((strlen($hub)) && ($hub_update)
&& (($contact['rel'] == REL_BUD) || (($contact['network'] === 'stat') && (! $contact['readonly'])))) {
logger('poller: subscribing to hub(s) : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
subscribe_to_hub($h,$importer,$contact);
consume_feed($xml,$importer,$contact,$hub,1, true);
// do it twice. Ensures that children of parents which may be later in the stream aren't tossed
consume_feed($xml,$importer,$contact,$hub,1);
if((strlen($hub)) && ($hub_update) && (($contact['rel'] == REL_BUD) || (($contact['network'] === NETWORK_OSTATUS) && (! $contact['readonly'])))) {
logger('poller: subscribing to hub(s) : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
subscribe_to_hub($h,$importer,$contact);
}
}
}
}
$updated = datetime_convert();
$r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d LIMIT 1",
@ -300,6 +450,7 @@ function poller_run($argv, $argc){
// loop - next contact
}
}
return;
}

View File

@ -1,46 +1,54 @@
<?php
function advanced_profile(&$a) {
$o .= '';
$o .= <<< EOT
<h2>Profilo</h2>
EOT;
$o .= '<h2>' . t('Profile') . '</h2>';
if($a->profile['name']) {
$lbl_fullname = t('Full Name:');
$fullname = $a->profile['name'];
$o .= <<< EOT
<div id="advanced-profile-name-wrapper" >
<div id="advanced-profile-name-text">Nome Completo:</div>
<div id="advanced-profile-name">{$a->profile['name']}</div>
<div id="advanced-profile-name-text">$lbl_fullname</div>
<div id="advanced-profile-name">$fullname</div>
</div>
<div id="advanced-profile-name-end"></div>
EOT;
}
if($a->profile['gender']) {
$lbl_gender = t('Gender:');
$gender = $a->profile['gender'];
$o .= <<< EOT
<div id="advanced-profile-gender-wrapper" >
<div id="advanced-profile-gender-text">Genere:</div>
<div id="advanced-profile-gender">{$a->profile['gender']}</div>
<div id="advanced-profile-gender-text">$lbl_gender</div>
<div id="advanced-profile-gender">$gender</div>
</div>
<div id="advanced-profile-gender-end"></div>
EOT;
}
if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) {
$lbl_birthday = t('Birthday:');
$o .= <<< EOT
<div id="advanced-profile-dob-wrapper" >
<div id="advanced-profile-dob-text">Compleanno:</div>
<div id="advanced-profile-dob-text">$lbl_birthday</div>
EOT;
// If no year, add an arbitrary one so just we can parse the month and day.
$year_bd_format = t('j F, Y');
$short_bd_format = t('j F');
$o .= '<div id="advanced-profile-dob">'
. ((intval($a->profile['dob']))
? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00','j F, Y'))
: day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],6) . ' 00:00 +00:00','j F')))
? day_translate(datetime_convert('UTC','UTC',$a->profile['dob'] . ' 00:00 +00:00',$year_bd_format))
: day_translate(datetime_convert('UTC','UTC','2001-' . substr($a->profile['dob'],6) . ' 00:00 +00:00',$short_bd_format)))
. "</div>\r\n</div>";
$o .= '<div id="advanced-profile-dob-end"></div>';
@ -48,9 +56,10 @@ $o .= '<div id="advanced-profile-dob-end"></div>';
}
if($age = age($a->profile['dob'],$a->profile['timezone'],'')) {
$lbl_age = t('Age:');
$o .= <<< EOT
<div id="advanced-profile-age-wrapper" >
<div id="advanced-profile-age-text">Et&agrave;:</div>
<div id="advanced-profile-age-text">$lbl_age</div>
<div id="advanced-profile-age">$age</div>
</div>
<div id="advanced-profile-age-end"></div>
@ -58,14 +67,19 @@ EOT;
}
if($a->profile['marital']) {
$lbl_marital = t('<span class="heart">&hearts;</span> Status:');
$marital = $a->profile['marital'];
$o .= <<< EOT
<div id="advanced-profile-marital-wrapper" >
<div id="advanced-profile-marital-text"><span class="heart">&hearts;</span> Stato:</div>
<div id="advanced-profile-marital">{$a->profile['marital']}</div>
<div id="advanced-profile-marital-text">$lbl_marital</div>
<div id="advanced-profile-marital">$marital</div>
EOT;
if($a->profile['with'])
$o .= "<div id=\"advanced-profile-with\">({$a->profile['with']})</div>";
if($a->profile['with']) {
$with = $a->profile['with'];
$o .= "<div id=\"advanced-profile-with\">($with)</div>";
}
$o .= <<< EOT
</div>
<div id="advanced-profile-marital-end"></div>
@ -73,20 +87,24 @@ EOT;
}
if($a->profile['sexual']) {
$lbl_sexual = t('Sexual Preference:');
$sexual = $a->profile['sexual'];
$o .= <<< EOT
<div id="advanced-profile-sexual-wrapper" >
<div id="advanced-profile-sexual-text">Preferenze sessuali:</div>
<div id="advanced-profile-sexual">{$a->profile['sexual']}</div>
<div id="advanced-profile-sexual-text">$lbl_sexual</div>
<div id="advanced-profile-sexual">$sexual</div>
</div>
<div id="advanced-profile-sexual-end"></div>
EOT;
}
if($a->profile['homepage']) {
$lbl_homepage = t('Homepage:');
$homepage = linkify($a->profile['homepage']);
$o .= <<< EOT
<div id="advanced-profile-homepage-wrapper" >
<div id="advanced-profile-homepage-text">Homepage:</div>
<div id="advanced-profile-homepage-text">$lbl_homepage</div>
<div id="advanced-profile-homepage">$homepage</div>
</div>
<div id="advanced-profile-homepage-end"></div>
@ -94,29 +112,33 @@ EOT;
}
if($a->profile['politic']) {
$lbl_politic = t('Political Views:');
$politic = $a->profile['politic'];
$o .= <<< EOT
<div id="advanced-profile-politic-wrapper" >
<div id="advanced-profile-politic-text">Orientamento politico:</div>
<div id="advanced-profile-politic">{$a->profile['politic']}</div>
<div id="advanced-profile-politic-text">$lbl_politic</div>
<div id="advanced-profile-politic">$politic</div>
</div>
<div id="advanced-profile-politic-end"></div>
EOT;
}
if($a->profile['religion']) {
$lbl_religion = t('Religion:');
$religion = $a->profile['religion'];
$o .= <<< EOT
<div id="advanced-profile-religion-wrapper" >
<div id="advanced-profile-religion-text">Religione:</div>
<div id="advanced-profile-religion">{$a->profile['religion']}</div>
<div id="advanced-profile-religion-text">$lbl_religion</div>
<div id="advanced-profile-religion">$religion</div>
</div>
<div id="advanced-profile-religion-end"></div>
EOT;
}
if($txt = prepare_text($a->profile['about'])) {
$lbl_about = t('About:');
$o .= <<< EOT
<div id="advanced-profile-about-wrapper" >
<div id="advanced-profile-about-text">Informazioni varie:</div>
<div id="advanced-profile-about-text">$lbl_about</div>
<br />
<div id="advanced-profile-about">$txt</div>
</div>
@ -125,9 +147,10 @@ EOT;
}
if($txt = prepare_text($a->profile['interest'])) {
$lbl_interests = t('Hobbies/Interests:');
$o .= <<< EOT
<div id="advanced-profile-interest-wrapper" >
<div id="advanced-profile-interest-text">Hobbie/Interessi:</div>
<div id="advanced-profile-interest-text">$lbl_interests</div>
<br />
<div id="advanced-profile-interest">$txt</div>
</div>
@ -136,9 +159,10 @@ EOT;
}
if($txt = prepare_text($a->profile['contact'])) {
$lbl_contact = t('Contact information and Social Networks:');
$o .= <<< EOT
<div id="advanced-profile-contact-wrapper" >
<div id="advanced-profile-contact-text">Informazioni su contatti e Social Networks:</div>
<div id="advanced-profile-contact-text">$lbl_contact</div>
<br />
<div id="advanced-profile-contact">$txt</div>
</div>
@ -147,9 +171,10 @@ EOT;
}
if($txt = prepare_text($a->profile['music'])) {
$lbl_music = t('Musical interests:');
$o .= <<< EOT
<div id="advanced-profile-music-wrapper" >
<div id="advanced-profile-music-text">Interessi musicali:</div>
<div id="advanced-profile-music-text">$lbl_music</div>
<br />
<div id="advanced-profile-music">$txt</div>
</div>
@ -158,9 +183,10 @@ EOT;
}
if($txt = prepare_text($a->profile['book'])) {
$lbl_book = t('Books, literature:');
$o .= <<< EOT
<div id="advanced-profile-book-wrapper" >
<div id="advanced-profile-book-text">Libri, letteratura:</div>
<div id="advanced-profile-book-text">$lbl_book</div>
<br />
<div id="advanced-profile-book">$txt</div>
</div>
@ -169,9 +195,10 @@ EOT;
}
if($txt = prepare_text($a->profile['tv'])) {
$lbl_tv = t('Television:');
$o .= <<< EOT
<div id="advanced-profile-tv-wrapper" >
<div id="advanced-profile-tv-text">Televisione:</div>
<div id="advanced-profile-tv-text">$lbl_tv</div>
<br />
<div id="advanced-profile-tv">$txt</div>
</div>
@ -180,9 +207,10 @@ EOT;
}
if($txt = prepare_text($a->profile['film'])) {
$lbl_film = t('Film/dance/culture/entertainment:');
$o .= <<< EOT
<div id="advanced-profile-film-wrapper" >
<div id="advanced-profile-film-text">Film/danza/cultura/intrattenimento:</div>
<div id="advanced-profile-film-text">$lbl_film</div>
<br />
<div id="advanced-profile-film">$txt</div>
</div>
@ -191,9 +219,10 @@ EOT;
}
if($txt = prepare_text($a->profile['romance'])) {
$lbl_romance = t('Love/Romance:');
$o .= <<< EOT
<div id="advanced-profile-romance-wrapper" >
<div id="advanced-profile-romance-text">Amore/romanticismo:</div>
<div id="advanced-profile-romance-text">$lbl_romance</div>
<br />
<div id="advanced-profile-romance">$txt</div>
</div>
@ -202,9 +231,10 @@ EOT;
}
if($txt = prepare_text($a->profile['work'])) {
$lbl_work = t('Work/employment:');
$o .= <<< EOT
<div id="advanced-profile-work-wrapper" >
<div id="advanced-profile-work-text">Lavoro/impiego:</div>
<div id="advanced-profile-work-text">$lbl_work</div>
<br />
<div id="advanced-profile-work">$txt</div>
</div>
@ -213,9 +243,10 @@ EOT;
}
if($txt = prepare_text($a->profile['education'])) {
$lbl_education = t('School/education:');
$o .= <<< EOT
<div id="advanced-profile-education-wrapper" >
<div id="advanced-profile-education-text">Scuola/educazione:</div>
<div id="advanced-profile-education-text">$lbl_education</div>
<br />
<div id="advanced-profile-education">$txt</div>
</div>
@ -223,4 +254,5 @@ $o .= <<< EOT
EOT;
}
return $o;
}

View File

@ -161,7 +161,7 @@ EOT;
$signature2 = base64url_encode($rsa->sign($data));
$salmon_tpl = load_view_file('view/magicsig.tpl');
$salmon_tpl = get_markup_template('magicsig.tpl');
$salmon = replace_macros($salmon_tpl,array(
'$data' => $data,
'$encoding' => $encoding,

View File

@ -25,7 +25,7 @@ function can_write_wall(&$a,$owner) {
else {
$r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` LEFT JOIN `user` on `user`.`uid` = `contact`.`uid`
WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1",
intval($owner),
intval(remote_user()),
intval(REL_VIP),

View File

@ -0,0 +1,137 @@
<?php
class Template {
var $r;
var $search;
var $replace;
var $stack = array();
var $nodes = array();
var $done = false;
private function _build_replace($r, $prefix){
if(is_array($r) && count($r)) {
foreach ($r as $k => $v ) {
if (is_array($v))
$this->_build_replace($v, "$prefix$k.");
$this->search[] = $prefix . $k;
$this->replace[] = $v;
}
}
}
private function _push_stack(){
$this->stack[] = array($this->r, $this->search, $this->replace, $this->nodes);
}
private function _pop_stack(){
list($this->r, $this->search, $this->replace, $this->nodes) = array_pop($this->stack);
}
private function _get_var($name){
$keys = array_map('trim',explode(".",$name));
$val = $this->r;
foreach($keys as $k) {
$val = $val[$k];
}
return $val;
}
/**
* IF node
*
* {{ if <$var> }}...{{ endif }}
*/
private function _replcb_if($args){
$val = $this->_get_var($args[2]);
return ($val?$args[3]:"");
}
/**
* FOR node
*
* {{ for <$var> as $name }}...{{ endfor }}
* {{ for <$var> as $key=>$name }}...{{ endfor }}
*/
private function _replcb_for($args){
$m = array_map('trim', explode(" as ", $args[2]));
list($keyname, $varname) = explode("=>",$m[1]);
if (is_null($varname)) { $varname=$keyname; $keyname=""; }
if ($m[0]=="" || $varname=="" || is_null($varname)) die("template error: 'for ".$m[0]." as ".$varname."'") ;
$vals = $this->r[$m[0]];
$ret="";
if (!is_array($vals)) return $ret;
foreach ($vals as $k=>$v){
$this->_push_stack();
$r = $this->r;
$r[$varname] = $v;
if ($keyname!='') $r[$keyname] = $k;
$ret .= $this->replace($args[3], $r);
$this->_pop_stack();
}
return $ret;
}
/**
* INC node
*
* {{ inc <templatefile> [with $var1=$var2] }}{{ endinc }}
*/
private function _replcb_inc($args){
list($tplfile, $newctx) = array_map('trim', explode("with",$args[2]));
$this->_push_stack();
$r = $this->r;
if (!is_null($newctx)) {
list($a,$b) = array_map('trim', explode("=",$newctx));
$r[$a] = $this->_get_var($b);
}
$this->nodes = Array();
$tpl = get_markup_template($tplfile);
$ret = $this->replace($tpl, $r);
$this->_pop_stack();
return $ret;
}
private function _replcb_node($m) {
$node = $this->nodes[$m[1]];
if (method_exists($this, "_replcb_".$node[1])){
return call_user_func(array($this, "_replcb_".$node[1]), $node);
} else {
return "";
}
}
private function _replcb($m){
$this->done = false;
$this->nodes[] = (array) $m;
return "||". (count($this->nodes)-1) ."||";
}
private function _build_nodes($s){
$this->done = false;
while (!$this->done){
$this->done=true;
$s = preg_replace_callback('|{{ *([a-z]*) *([^}]*)}}([^{]*){{ *end\1 *}}|', array($this, "_replcb"), $s);
}
krsort($this->nodes);
return $s;
}
public function replace($s, $r) {
$this->r = $r;
$this->search = array();
$this->replace = array();
$this->_build_replace($r, "");
#$s = str_replace(array("\n","\r"),array("§n§","§r§"),$s);
$s = $this->_build_nodes($s);
$s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
$s = str_replace($this->search,$this->replace, (string) $s);
return $s;
}
}
$t = new Template;

View File

@ -1,5 +1,7 @@
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
/**
*
* Friendika
@ -31,10 +33,18 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false
*
* Get the language setting directly from system variables, bypassing get_config()
* as database may not yet be configured.
*
* If possible, we use the value from the browser.
*
*/
$lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs = preg_split("/[,-]/",$_SERVER['HTTP_ACCEPT_LANGUAGE'],2);
$lang = $langs[0];
} else {
$lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en');
}
load_translation_table($lang);
@ -79,6 +89,19 @@ $a->init_pagehead();
session_start();
/**
* Language was set earlier, but we can over-ride it in the session.
* We have to do it here because the session was just now opened.
*/
if(x($_POST,'system_language'))
$_SESSION['language'] = $_POST['system_language'];
if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
$lang = $_SESSION['language'];
load_translation_table($lang);
}
/**
*
* For Mozilla auth manager - still needs sorting, and this might conflict with LRDD header.

3042
library/markdown.php Normal file

File diff suppressed because it is too large Load Diff

11
mod/api.php Normal file
View File

@ -0,0 +1,11 @@
<?php
require_once('include/api.php');
function api_content(&$a) {
echo api_call($a);
killme();
}

View File

@ -5,10 +5,11 @@ function apps_content(&$a) {
$o .= '<h3>' . t('Applications') . '</h3>';
$o .= '<div class="app-title"><a href="notes">' . t('Private Notes') . '</a></div>';
if($a->apps)
$o .= $a->apps;
return $o;
}

View File

@ -9,15 +9,20 @@ function contacts_init(&$a) {
$a->page['aside'] .= group_side();
if($a->config['register_policy'] != REGISTER_CLOSED)
$a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
$a->page['aside'] .= '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
$tpl = load_view_file('view/follow.tpl');
if(strlen(get_config('system','directory_submit_url')))
$a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >' . t('Find People With Shared Interests') . '</a></div>';
$tpl = get_markup_template('follow.tpl');
$a->page['aside'] .= replace_macros($tpl,array(
'$label' => t('Connect/Follow'),
'$hint' => t('Example: bob@example.com, http://example.com/barbara'),
'$follow' => t('Follow')
));
}
function contacts_post(&$a) {
@ -137,7 +142,8 @@ function contacts_content(&$a) {
intval(local_user())
);
if($r) {
notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
//notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
notice( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
}
goaway($a->get_baseurl() . '/contacts/' . $contact_id);
return; // NOTREACHED
@ -151,7 +157,7 @@ function contacts_content(&$a) {
intval(local_user())
);
if($r) {
notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
notice( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
}
goaway($a->get_baseurl() . '/contacts/' . $contact_id);
return; // NOTREACHED
@ -162,7 +168,7 @@ function contacts_content(&$a) {
// create an unfollow slap
if($orig_record[0]['network'] === 'stat') {
$tpl = load_view_file('view/follow_slap.tpl');
$tpl = get_markup_template('follow_slap.tpl');
$slap = replace_macros($tpl, array(
'$name' => $a->user['username'],
'$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
@ -174,8 +180,8 @@ function contacts_content(&$a) {
'$type' => 'text',
'$content' => t('stopped following'),
'$nick' => $a->user['nickname'],
'$verb' => ACTIVITY_UNFOLLOW,
'$ostat_follow' => '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
'$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
'$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
));
if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
@ -209,12 +215,12 @@ function contacts_content(&$a) {
return;
}
$tpl = load_view_file('view/contact_head.tpl');
$tpl = get_markup_template('contact_head.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
require_once('include/contact_selectors.php');
$tpl = load_view_file("view/contact_edit.tpl");
$tpl = get_markup_template("contact_edit.tpl");
switch($r[0]['rel']) {
case REL_BUD:
@ -243,6 +249,9 @@ function contacts_content(&$a) {
$sparkle = '';
}
$insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" />&nbsp;'
. t('Private communications are not available for this contact.') . '</p></div>';
$last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
? t('Never')
: datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
@ -252,9 +261,20 @@ function contacts_content(&$a) {
$o .= replace_macros($tpl,array(
'$header' => t('Contact Editor'),
'$submit' => t('Submit'),
'$lbl_vis1' => t('Profile Visibility'),
'$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
'$lbl_info1' => t('Contact Information / Notes'),
'$lbl_rep1' => t('Online Reputation'),
'$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
'$lbl_rep3' => t('You may help them choose whether or not to interact with this person by providing a <em>reputation</em> to guide them.'),
'$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
'$visit' => t('Visit $name\'s profile'),
'$blockunblock' => t('Block/Unblock contact'),
'$ignorecont' => t('Ignore contact'),
'$altcrepair' => t('Repair contact URL settings'),
'$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
'$lblrecent' => t('View conversations'),
'$delete' => t('Delete contact'),
'$poll_interval' => contact_poll_interval($r[0]['priority']),
'$lastupdtext' => t('Last updated: '),
@ -265,7 +285,7 @@ function contacts_content(&$a) {
'$contact_id' => $r[0]['id'],
'$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
'$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
'$insecure' => (($r[0]['network'] === 'stat') ? load_view_file('view/insecure_net.tpl') : ''),
'$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK) ? $insecure : ''),
'$info' => $r[0]['info'],
'$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
'$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
@ -297,7 +317,7 @@ function contacts_content(&$a) {
$search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
$tpl = load_view_file("view/contacts-top.tpl");
$tpl = get_markup_template("contacts-top.tpl");
$o .= replace_macros($tpl,array(
'$header' => t('Contacts'),
'$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
@ -331,7 +351,7 @@ function contacts_content(&$a) {
if(count($r)) {
$tpl = load_view_file("view/contact_template.tpl");
$tpl = get_markup_template("contact_template.tpl");
foreach($r as $rr) {
if($rr['self'])
@ -364,13 +384,14 @@ function contacts_content(&$a) {
$o .= replace_macros($tpl, array(
'$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
'$img_hover' => t('Visit $username\'s profile'),
'$edit_hover' => t('Edit contact'),
'$id' => $rr['id'],
'$alt_text' => $alt_text,
'$dir_icon' => $dir_icon,
'$thumb' => $rr['thumb'],
'$name' => substr($rr['name'],0,20),
'$username' => $rr['name'],
'$sparkle' => $sparkle,
'$url' => $url
));

105
mod/crepair.php Normal file
View File

@ -0,0 +1,105 @@
<?php
function crepair_post(&$a) {
if(! local_user())
return;
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
if(! count($r))
return;
$contact = $r[0];
$nick = ((x($_POST,'nick')) ? $_POST['nick'] : null);
$url = ((x($_POST,'url')) ? $_POST['url'] : null);
$request = ((x($_POST,'request')) ? $_POST['request'] : null);
$confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : null);
$notify = ((x($_POST,'notify')) ? $_POST['notify'] : null);
$poll = ((x($_POST,'poll')) ? $_POST['poll'] : null);
$r = q("UPDATE `contact` SET `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s'
WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc($nick),
dbesc($url),
dbesc($request),
dbesc($confirm),
dbesc($notify),
dbesc($poll),
intval($contact['id']),
local_user()
);
if($r)
notice( t('Contact settings applied.') . EOL);
else
notice( t('Contact update failed.') . EOL);
return;
}
function crepair_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
if(! count($r)) {
notice( t('Contact not found.') . EOL);
return;
}
$contact = $r[0];
$msg1 = t('Repair Contact Settings');
$msg2 = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact will stop working.');
$msg3 = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
$o .= '<h2>' . $msg1 . '</h2>';
$o .= '<div class="error-message">' . $msg2 . EOL . EOL. $msg3 . '</div>';
$tpl = get_markup_template('crepair.tpl');
$o .= replace_macros($tpl, array(
'$label_name' => t('Name'),
'$label_nick' => t('Account Nickname'),
'$label_url' => t('Account URL'),
'$label_request' => t('Friend Request URL'),
'$label_confirm' => t('Friend Confirm URL'),
'$label_notify' => t('Notification Endpoint URL'),
'$label_poll' => t('Poll/Feed URL'),
'$contact_name' => $contact['name'],
'$contact_nick' => $contact['nick'],
'$contact_id' => $contact['id'],
'$contact_url' => $contact['url'],
'$request' => $contact['request'],
'$confirm' => $contact['confirm'],
'$notify' => $contact['notify'],
'$poll' => $contact['poll'],
'$lbl_submit' => t('Submit')
));
return $o;
}

View File

@ -240,7 +240,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
notice( t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL );
}
$xml = simplexml_load_string($res);
$xml = parse_xml_string($res);
$status = (int) $xml->status;
$message = unxmlify($xml->message); // human readable text of what may have gone wrong.
switch($status) {
@ -423,9 +423,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
$arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
$arr['verb'] = ACTIVITY_FRIEND;
$arr['object-type'] = ACTIVITY_OBJ_PERSON;
$arr['body'] = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url] ' . t('is now friends with')
. ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . "\n\n\n"
. ' [url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
$A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
$B = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$BPhoto = '[url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
$arr['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
$arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $contact['name'] . '</title>'
. '<id>' . $contact['url'] . '/' . $contact['name'] . '</id>';
@ -434,6 +436,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
$arr['object'] .= '</link></object>' . "\n";
$arr['last-child'] = 1;
$arr['allow_cid'] = $user[0]['allow_cid'];
$arr['allow_gid'] = $user[0]['allow_gid'];
$arr['deny_cid'] = $user[0]['deny_cid'];
$arr['deny_gid'] = $user[0]['deny_gid'];
$i = item_store($arr);
if($i)
proc_run('php',"include/notifier.php","activity","$i");
@ -491,7 +498,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
dbesc($node));
if(! count($r)) {
$message = t('No user record found for ') . '\'' . $node . '\'';
$message = sprintf(t('No user record found for \'%s\' '), $node);
xml_status(3,$message); // failure
// NOTREACHED
}
@ -632,8 +639,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if((count($r)) && ($r[0]['notify-flags'] & NOTIFY_CONFIRM)) {
$tpl = (($new_relation == REL_BUD)
? load_view_file('view/friend_complete_eml.tpl')
: load_view_file('view/intro_complete_eml.tpl'));
? get_intltext_template('friend_complete_eml.tpl')
: get_intltext_template('intro_complete_eml.tpl'));
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
@ -645,8 +652,12 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
'$uid' => $newuid )
);
$res = mail($r[0]['email'], t("Connection accepted at ") . $a->config['sitename'],
$email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
$res = mail($r[0]['email'], sprintf( t("Connection accepted at %s") , $a->config['sitename']),
$email_tpl,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
if(!$res) {
// pointless throwing an error here and confusing the person at the other end of the wire.
}

View File

@ -10,6 +10,12 @@ function dfrn_notify_post(&$a) {
$data = ((x($_POST,'data')) ? $_POST['data'] : '');
$key = ((x($_POST,'key')) ? $_POST['key'] : '');
$dissolve = ((x($_POST,'dissolve')) ? intval($_POST['dissolve']) : 0);
$perm = ((x($_POST,'perm')) ? notags(trim($_POST['perm'])) : 'r');
$writable = (-1);
if($dfrn_version >= 2.21) {
$writable = (($perm === 'rw') ? 1 : 0);
}
$direction = (-1);
if(strpos($dfrn_id,':') == 1) {
@ -74,6 +80,14 @@ function dfrn_notify_post(&$a) {
$importer = $r[0];
if(($writable != (-1)) && ($writable != $importer['writable'])) {
q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
intval($writable),
intval($importer['id'])
);
$importer['writable'] = $writable;
}
logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']);
logger('dfrn_notify: data: ' . $data, LOGGER_DATA);
@ -118,8 +132,6 @@ function dfrn_notify_post(&$a) {
}
if($importer['readonly']) {
// We aren't receiving stuff from this person. But we will quietly ignore them
// rather than a blatant "go away" message.
@ -198,7 +210,7 @@ function dfrn_notify_post(&$a) {
= html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$msg['body']))));
// load the template for private message notifications
$tpl = load_view_file('view/mail_received_html_body_eml.tpl');
$tpl = get_intltext_template('mail_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
'$siteName' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -213,7 +225,7 @@ function dfrn_notify_post(&$a) {
));
// load the template for private message notifications
$tpl = load_view_file('view/mail_received_text_body_eml.tpl');
$tpl = get_intltext_template('mail_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl,array(
'$siteName' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -262,10 +274,13 @@ function dfrn_notify_post(&$a) {
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
}
if($deleted) {
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
dbesc($uri),
intval($importer['importer_uid'])
intval($importer['importer_uid']),
intval($importer['id'])
);
if(count($r)) {
$item = $r[0];
@ -374,21 +389,7 @@ function dfrn_notify_post(&$a) {
if((! $is_like) && ($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {
require_once('bbcode.php');
$from = stripslashes($datarray['author-name']);
/*
$tpl = load_view_file('view/cmnt_received_eml.tpl');
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
'$username' => $importer['username'],
'$email' => $importer['email'],
'$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
'$from' => $from,
'$body' => html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8')
));
$res = mail($importer['email'], $from . t(' commented on an item at ') . $a->config['sitename'],
$email_tpl, "From: " . t('Administrator') . '@' . $a->get_hostname() );
*/
// name of the automated email sender
$msg['notificationfromname'] = stripslashes($datarray['author-name']);;
// noreply address to send from
@ -405,7 +406,7 @@ function dfrn_notify_post(&$a) {
= html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_html_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -418,7 +419,7 @@ function dfrn_notify_post(&$a) {
));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_text_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -515,24 +516,6 @@ function dfrn_notify_post(&$a) {
continue;
require_once('bbcode.php');
$from = stripslashes($datarray['author-name']);
/*
$tpl = load_view_file('view/cmnt_received_eml.tpl');
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
'$username' => $importer['username'],
'$email' => $importer['email'],
'$from' => $from,
'$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $r,
'$body' => html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8')
));
$res = mail($importer['email'], $from . t(" commented on an item at ")
. $a->config['sitename'],
$email_tpl,t("From: Administrator@") . $a->get_hostname() );
*/
// name of the automated email sender
$msg['notificationfromname'] = stripslashes($datarray['author-name']);;
@ -550,7 +533,7 @@ function dfrn_notify_post(&$a) {
= html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_html_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -562,7 +545,7 @@ function dfrn_notify_post(&$a) {
));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_text_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site

View File

@ -16,6 +16,7 @@ function dfrn_poll_init(&$a) {
$challenge = ((x($_GET,'challenge')) ? $_GET['challenge'] : '');
$sec = ((x($_GET,'sec')) ? $_GET['sec'] : '');
$dfrn_version = ((x($_GET,'dfrn_version')) ? (float) $_GET['dfrn_version'] : 2.0);
$perm = ((x($_GET,'perm')) ? $_GET['perm'] : 'r');
$direction = (-1);
@ -26,6 +27,10 @@ function dfrn_poll_init(&$a) {
}
if(($dfrn_id === '') && (! x($_POST,'dfrn_id')) && ($a->argc > 1)) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
killme();
}
logger('dfrn_poll: public feed request from ' . $_SERVER['REMOTE_ADDR'] );
header("Content-type: application/atom+xml");
$o = get_feed_for($a, '', $a->argv[1],$last_update);
@ -69,13 +74,14 @@ function dfrn_poll_init(&$a) {
if(strlen($s)) {
$xml = simplexml_load_string($s);
$xml = parse_xml_string($s);
if((int) $xml->status == 1) {
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url'];
notice( $r[0]['username'] . t(' welcomes ') . $r[0]['name'] . EOL);
$_SESSION['visitor_visiting'] = $r[0]['uid'];
notice( sprintf(t('%s welcomes %s'), $r[0]['username'] , $r[0]['name']) . EOL);
// Visitors get 1 day session.
$session_id = session_id();
$expire = time() + 86400;
@ -92,7 +98,7 @@ function dfrn_poll_init(&$a) {
}
if($type === 'profile-check') {
if($type === 'profile-check' && $dfrn_version < 2.2 ) {
if((strlen($challenge)) && (strlen($sec))) {
@ -182,7 +188,69 @@ function dfrn_poll_post(&$a) {
$dfrn_id = ((x($_POST,'dfrn_id')) ? $_POST['dfrn_id'] : '');
$challenge = ((x($_POST,'challenge')) ? $_POST['challenge'] : '');
$url = ((x($_POST,'url')) ? $_POST['url'] : '');
$sec = ((x($_POST,'sec')) ? $_POST['sec'] : '');
$ptype = ((x($_POST,'type')) ? $_POST['type'] : '');
$dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0);
$perm = ((x($_POST,'perm')) ? $_POST['perm'] : 'r');
if($ptype === 'profile-check') {
if((strlen($challenge)) && (strlen($sec))) {
logger('dfrn_poll: POST: profile-check');
q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time()));
$r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1",
dbesc($sec)
);
if(! count($r)) {
xml_status(3, 'No ticket');
// NOTREACHED
}
$orig_id = $r[0]['dfrn_id'];
if(strpos($orig_id, ':'))
$orig_id = substr($orig_id,2);
$c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
intval($r[0]['cid'])
);
if(! count($c)) {
xml_status(3, 'No profile');
}
$contact = $c[0];
$sent_dfrn_id = hex2bin($dfrn_id);
$challenge = hex2bin($challenge);
$final_dfrn_id = '';
if(($contact['duplex']) && strlen($contact['prvkey'])) {
openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']);
}
else {
openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
openssl_public_decrypt($challenge,$decoded_challenge,$contact['pubkey']);
}
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
if(strpos($final_dfrn_id,':') == 1)
$final_dfrn_id = substr($final_dfrn_id,2);
if($final_dfrn_id != $orig_id) {
logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
// did not decode properly - cannot trust this site
xml_status(3, 'Bad decryption');
}
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dfrn_poll><status>0</status><challenge>$decoded_challenge</challenge><sec>$sec</sec></dfrn_poll>";
killme();
// NOTREACHED
}
}
$direction = (-1);
if(strpos($dfrn_id,':') == 1) {
@ -234,6 +302,7 @@ function dfrn_poll_post(&$a) {
if(! count($r))
killme();
$contact = $r[0];
$owner_uid = $r[0]['uid'];
$contact_id = $r[0]['id'];
@ -267,6 +336,23 @@ function dfrn_poll_post(&$a) {
// NOTREACHED
}
else {
// Update the writable flag if it changed
logger('dfrn_poll: post request feed: ' . print_r($_POST,true),LOGGER_DATA);
if($dfrn_version >= 2.21) {
if($perm === 'rw')
$writable = 1;
else
$writable = 0;
if($writable != $contact['writable']) {
q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
intval($writable),
intval($contact_id)
);
}
}
header("Content-type: application/atom+xml");
$o = get_feed_for($a,$dfrn_id, $a->argv[1], $last_update, $direction);
echo $o;
@ -283,6 +369,7 @@ function dfrn_poll_content(&$a) {
$destination_url = ((x($_GET,'destination_url')) ? $_GET['destination_url'] : '');
$sec = ((x($_GET,'sec')) ? $_GET['sec'] : '');
$dfrn_version = ((x($_GET,'dfrn_version')) ? (float) $_GET['dfrn_version'] : 2.0);
$perm = ((x($_GET,'perm')) ? $_GET['perm'] : 'r');
$direction = (-1);
if(strpos($dfrn_id,':') == 1) {
@ -363,21 +450,51 @@ function dfrn_poll_content(&$a) {
}
if(($type === 'profile') && (strlen($sec))) {
// URL reply
$s = fetch_url($r[0]['poll']
. '?dfrn_id=' . $encrypted_id
. '&type=profile-check'
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
. '&challenge=' . $challenge
. '&sec=' . $sec
);
if($dfrn_version < 2.2) {
$s = fetch_url($r[0]['poll']
. '?dfrn_id=' . $encrypted_id
. '&type=profile-check'
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
. '&challenge=' . $challenge
. '&sec=' . $sec
);
}
else {
$s = post_url($r[0]['poll'], array(
'dfrn_id' => $encrypted_id,
'type' => 'profile-check',
'dfrn_version' => DFRN_PROTOCOL_VERSION,
'challenge' => $challenge,
'sec' => $sec
));
}
$profile = $r[0]['nickname'];
switch($destination_url) {
case 'profile':
$dest = $a->get_baseurl() . '/profile/' . $profile . '?tab=profile';
break;
case 'photos':
$dest = $a->get_baseurl() . '/photos/' . $profile;
break;
case 'status':
case '':
$dest = $a->get_baseurl() . '/profile/' . $profile;
break;
default:
$dest = $destination_url;
break;
}
logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
if(strlen($s) && strstr($s,'<?xml')) {
$xml = simplexml_load_string($s);
$xml = parse_xml_string($s);
logger('dfrn_poll: profile: parsed xml: ' . print_r($xml,true), LOGGER_DATA);
@ -389,7 +506,8 @@ function dfrn_poll_content(&$a) {
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['visitor_home'] = $r[0]['url'];
notice( $r[0]['username'] . t(' welcomes ') . $r[0]['name'] . EOL);
$_SESSION['visitor_visiting'] = $r[0]['uid'];
notice( sprintf(t('%s welcomes %s'), $r[0]['username'] , $r[0]['name']) . EOL);
// Visitors get 1 day session.
$session_id = session_id();
$expire = time() + 86400;
@ -398,10 +516,10 @@ function dfrn_poll_content(&$a) {
dbesc($session_id)
);
}
$profile = $r[0]['nickname'];
goaway((strlen($destination_url)) ? $destination_url : $a->get_baseurl() . '/profile/' . $profile);
goaway($dest);
}
goaway($a->get_baseurl());
goaway($dest);
// NOTREACHED
}

View File

@ -12,6 +12,10 @@
if(! function_exists('dfrn_request_init')) {
function dfrn_request_init(&$a) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
return;
}
if($a->argc > 1)
$which = $a->argv[1];
@ -123,9 +127,9 @@ function dfrn_request_post(&$a) {
notice( t('Warning: profile location has no profile photo.') . EOL );
$invalid = validate_dfrn($parms);
if($invalid) {
notice( $invalid . t(' required parameter')
. (($invalid == 1) ? t(" was ") : t("s were ") )
. t("not found at the given location.") . EOL ) ;
notice( sprintf( tt("%d required parameter was not found at the given location",
"%d required parameters were not found at the given location",
$invalid), $invalid) . EOL );
return;
}
}
@ -238,7 +242,7 @@ function dfrn_request_post(&$a) {
intval($uid)
);
if(count($r) > $maxreq) {
notice( $a->profile['name'] . t(' has received too many connection requests today.') . EOL);
notice( sprintf( t('%s has received too many connection requests today.'), $a->profile['name']) . EOL);
notice( t('Spam protection measures have been invoked.') . EOL);
notice( t('Friends are advised to please try again in 24 hours.') . EOL);
return;
@ -306,7 +310,7 @@ function dfrn_request_post(&$a) {
return;
}
elseif($ret[0]['rel'] == REL_BUD) {
notice( t('Apparently you are already friends with .') . $a->profile['name'] . EOL);
notice( sprintf( t('Apparently you are already friends with %s.'), $a->profile['name']) . EOL);
return;
}
else {
@ -354,9 +358,9 @@ function dfrn_request_post(&$a) {
notice( t('Warning: profile location has no profile photo.') . EOL );
$invalid = validate_dfrn($parms);
if($invalid) {
notice( $invalid . t(' required parameter')
. (($invalid == 1) ? t(" was ") : t("s were ") )
. t("not found at the given location.") . EOL ) ;
notice( sprintf( tt("%d required parameter was not found at the given location",
"%d required parameters were not found at the given location",
$invalid), $invalid) . EOL );
return;
}
@ -495,12 +499,14 @@ function dfrn_request_content(&$a) {
$dfrn_url = notags(trim(hex2bin($_GET['dfrn_url'])));
$aes_allow = (((x($_GET,'aes_allow')) && ($_GET['aes_allow'] == 1)) ? 1 : 0);
$confirm_key = (x($_GET,'confirm_key') ? $_GET['confirm_key'] : "");
$o .= load_view_file("view/dfrn_req_confirm.tpl");
$o = replace_macros($o,array(
$tpl = get_markup_template("dfrn_req_confirm.tpl");
$o = replace_macros($tpl,array(
'$dfrn_url' => $dfrn_url,
'$aes_allow' => (($aes_allow) ? '<input type="hidden" name="aes_allow" value="1" />' : "" ),
'$confirm_key' => $confirm_key,
'$username' => $a->user['username'],
'$welcome' => sprintf( t('Welcome home %s.'), $a->user['username']),
'$please' => sprintf( t('Please confirm your introduction/connection request to %s.'), $dfrn_url),
'$submit' => t('Confirm'),
'$uid' => $_SESSION['uid'],
'$nickname' => $a->user['nickname'],
'dfrn_rawurl' => $_GET['dfrn_url']
@ -531,7 +537,7 @@ function dfrn_request_content(&$a) {
if($r[0]['page-flags'] != PAGE_NORMAL)
$auto_confirm = true;
if(($r[0]['notify-flags'] & NOTIFY_INTRO) && (! $auto_confirm)) {
$email_tpl = load_view_file('view/request_notify_eml.tpl');
$email_tpl = get_intltext_template('request_notify_eml.tpl');
$email = replace_macros($email_tpl, array(
'$requestor' => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : t('[Name Withheld]')),
'$url' => stripslashes($r[0]['url']),
@ -540,9 +546,12 @@ function dfrn_request_content(&$a) {
'$sitename' => $a->config['sitename']
));
$res = mail($r[0]['email'],
t("Introduction received at ") . $a->config['sitename'],
t("Introduction received at ") . $a->config['sitename'],
$email,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] );
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
// This is a redundant notification - no point throwing errors if it fails.
}
if($auto_confirm) {
@ -578,6 +587,12 @@ function dfrn_request_content(&$a) {
* Normal web request. Display our user's introduction form.
*/
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL);
return;
}
/**
* Try to auto-fill the profile address
*/
@ -607,23 +622,24 @@ function dfrn_request_content(&$a) {
*/
if($a->profile['page-flags'] == PAGE_NORMAL)
$tpl = load_view_file('view/dfrn_request.tpl');
$tpl = get_markup_template('dfrn_request.tpl');
else
$tpl = load_view_file('view/auto_request.tpl');
$tpl = get_markup_template('auto_request.tpl');
$o .= replace_macros($tpl,array(
'$header' => t('Friend/Connection Request'),
'$desc' => t('Examples: jojo@demo.friendika.com, http://demo.friendika.com/profile/jojo, testuser@identi.ca'),
'$pls_answer' => t('Please answer the following:'),
'$does_know' => t('Does $name know you?'),
'$yes' => t('Yes'),
'$no' => t('No'),
'$add_note' => t('Add a personal note:'),
'$page_desc' => t('Please enter your profile address from one of the following supported social networks:'),
'$page_desc' => t("Please enter your 'Identity Address' from one of the following supported social networks:"),
'$friendika' => t('Friendika'),
'$statusnet' => t('StatusNet/Federated Social Web'),
'$private_net' => t("Private \x28secure\x29 network"),
'$public_net' => t("Public \x28insecure\x29 network"),
'$your_address' => t('Your profile address:'),
'$your_address' => t('Your Identity Address:'),
'$submit' => t('Submit Request'),
'$cancel' => t('Cancel'),
'$nickname' => $a->argv[1],

View File

@ -13,6 +13,14 @@ function directory_post(&$a) {
function directory_content(&$a) {
$everything = (($a->argc > 1 && $a->argv[1] === 'all' && is_site_admin()) ? true : false);
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL);
return;
}
$o = '';
$o .= '<script> $(document).ready(function() { $(\'#nav-directory-link\').addClass(\'nav-selected\'); });</script>';
if(x($_SESSION,'theme'))
@ -23,7 +31,7 @@ function directory_content(&$a) {
else
$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
$tpl = load_view_file('view/directory_header.tpl');
$tpl = get_markup_template('directory_header.tpl');
$globaldir = '';
$gdirpath = dirname(get_config('system','directory_submit_url'));
@ -32,32 +40,47 @@ function directory_content(&$a) {
. $gdirpath . '">' . t('Global Directory') . '</a></div></li></ul>';
}
$admin = '';
if(is_site_admin()) {
if($everything)
$admin = '<ul><li><div id="directory-admin-link"><a href="' . $a->get_baseurl() . '/directory' . '">' . t('Normal site view') . '</a></div></li></ul>';
else
$admin = '<ul><li><div id="directory-admin-link"><a href="' . $a->get_baseurl() . '/directory/all' . '">' . t('View all site entries') . '</a></div></li></ul>';
}
$o .= replace_macros($tpl, array(
'$search' => $search,
'$globaldir' => $globaldir,
'$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "")
'$admin' => $admin,
'$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
'$sitedir' => t('Site Directory'),
'$submit' => t('Find')
));
if($search)
$search = dbesc($search);
$sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
$sql_extra = ((strlen($search)) ? " AND MATCH (`profile`.`name`, `user`.`nickname`, `pdesc`, `locality`,`region`,`country-name`,`gender`,`marital`,`sexual`,`about`,`romance`,`work`,`education`,`pub_keywords`,`prv_keywords` ) AGAINST ('$search' IN BOOLEAN MODE) " : "");
$publish = ((get_config('system','publish_all')) ? '' : " AND `publish` = 1 " );
$publish = ((get_config('system','publish_all') || $everything) ? '' : " AND `publish` = 1 " );
$r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ");
if(count($r))
$a->set_pager_total($r[0]['total']);
if($everything)
$order = " ORDER BY `register_date` DESC ";
else
$order = " ORDER BY `name` ASC ";
$r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra ORDER BY `name` ASC LIMIT %d , %d ",
$r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ",
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
if(count($r)) {
$tpl = load_view_file('view/directory_item.tpl');
$tpl = get_markup_template('directory_item.tpl');
if(in_array('small', $a->argv))
$photo = 'thumb';
@ -86,10 +109,10 @@ function directory_content(&$a) {
}
if(strlen($rr['dob'])) {
if(($years = age($rr['dob'],$rr['timezone'],'')) != 0)
$details .= "<br />Age: $years" ;
$details .= '<br />' . t('Age: ') . $years ;
}
if(strlen($rr['gender']))
$details .= '<br />Gender: ' . $rr['gender'];
$details .= '<br />' . t('Gender: ') . $rr['gender'];
$entry = replace_macros($tpl,array(
'$id' => $rr['id'],
@ -115,7 +138,7 @@ function directory_content(&$a) {
}
else
notice("No entries (some entries may be hidden).");
notice( t("No entries \x28some entries may be hidden\x29.") . EOL);
return $o;
}

View File

@ -3,6 +3,16 @@
function display_content(&$a) {
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
notice( t('Public access denied.') . EOL);
return;
}
require_once("include/bbcode.php");
require_once('include/security.php');
require_once('include/conversation.php');
$o = '<div id="live-display"></div>' . "\r\n";
$nick = (($a->argc > 1) ? $a->argv[1] : '');
@ -16,15 +26,10 @@ function display_content(&$a) {
return;
}
require_once("include/bbcode.php");
require_once('include/security.php');
$groups = array();
$tab = 'posts';
$contact = null;
$remote_contact = false;
@ -48,6 +53,11 @@ function display_content(&$a) {
}
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($a->profile['uid'])
);
if(count($r))
$a->page_contact = $r[0];
$sql_extra = "
AND `allow_cid` = ''
@ -88,7 +98,7 @@ function display_content(&$a) {
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`,
`contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
@ -102,17 +112,6 @@ function display_content(&$a) {
);
$cmnt_tpl = load_view_file('view/comment_item.tpl');
$like_tpl = load_view_file('view/like.tpl');
$tpl = load_view_file('view/wall_item.tpl');
$wallwall = load_view_file('view/wallwall_item.tpl');
$return_url = $_SESSION['return_url'] = $a->cmd;
$alike = array();
$dlike = array();
if(count($r)) {
if((local_user()) && (local_user() == $a->profile['uid'])) {
@ -122,173 +121,9 @@ function display_content(&$a) {
);
}
foreach($r as $item) {
like_puller($a,$item,$alike,'like');
like_puller($a,$item,$dlike,'dislike');
}
$author_contacts = extract_item_authors($r,$a->profile['uid']);
$o .= conversation($a,$r,'display', false);
foreach($r as $item) {
$template = $tpl;
$comment = '';
$owner_url = '';
$owner_photo = '';
$owner_name = '';
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
$lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
: '<div class="wall-item-lock"></div>');
if(can_write_wall($a,$a->profile['uid'])) {
if($item['id'] == $item['parent']) {
$likebuttons = replace_macros($like_tpl,array(
'$id' => $item['id'],
'$likethis' => t("I like this \x28toggle\x29"),
'$nolike' => t("I don't like this \x28toggle\x29"),
'$wait' => t('Please wait')
));
}
if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
'$jsreload' => $_SESSION['return_url'],
'$type' => 'wall-comment',
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $a->profile['uid'],
'$mylink' => $contact['url'],
'$mytitle' => t('This is you'),
'$myphoto' => $contact['thumb'],
'$ww' => ''
));
}
}
$profile_url = $item['url'];
$sparkle = '';
// Top-level wall post not written by the wall owner (wall-to-wall)
// First figure out who owns it.
$osparkle = '';
if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
if($item['type'] === 'wall') {
// I do. Put me on the left of the wall-to-wall notice.
$owner_url = $a->contact['url'];
$owner_photo = $a->contact['thumb'];
$owner_name = $a->contact['name'];
$template = $wallwall;
$commentww = 'ww';
}
if($item['type'] === 'remote' && ($item['owner-link'] != $item['author-link'])) {
// Could be anybody.
$owner_url = $item['owner-link'];
$owner_photo = $item['owner-avatar'];
$owner_name = $item['owner-name'];
$template = $wallwall;
$commentww = 'ww';
// If it is our contact, use a friendly redirect link
if((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === 'dfrn')) {
$owner_url = $redirect_url;
$osparkle = ' sparkle';
}
}
}
$diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
$profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
$profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
// Can we use our special contact URL for this author?
if(strlen($item['author-link'])) {
$profile_link = $item['author-link'];
if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
$profile_link = $redirect_url;
$sparkle = ' sparkle';
}
elseif(isset($author_contacts[$item['author-link']])) {
$profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
$sparkle = ' sparkle';
}
}
if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
$drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
else
$drop = replace_macros(load_view_file('view/wall_fake_drop.tpl'), array('$id' => $item['id']));
$like = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
$dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
$location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
$coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
if($coord) {
if($location)
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
else
$location = '<span class="smalltext">' . $coord . '</span>';
}
$indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
$indent .= ' shiny';
$tmp_item = replace_macros($template,array(
'$id' => $item['item_id'],
'$linktitle' => t('View $name\'s profile'),
'$olinktitle' => t('View $owner_name\'s profile'),
'$to' => t('to'),
'$wall' => t('Wall-to-Wall'),
'$vwall' => t('via Wall-To-Wall:'),
'$profile_url' => $profile_link,
'$name' => $profile_name,
'$sparkle' => $sparkle,
'$osparkle' => $osparkle,
'$thumb' => $profile_avatar,
'$title' => $item['title'],
'$body' => smilies(bbcode($item['body'])),
'$ago' => relative_date($item['created']),
'$lock' => $lock,
'$location' => $location,
'$indent' => $indent,
'$owner_url' => $owner_url,
'$owner_photo' => $owner_photo,
'$owner_name' => $owner_name,
'$plink' => get_plink($item),
'$drop' => $drop,
'$vote' => $likebuttons,
'$like' => $like,
'$dislike' => $dislike,
'$comment' => $comment
));
$arr = array('item' => $item, 'output' => $tmp_item);
call_hooks('display_item', $arr);
$o .= $arr['output'];
}
}
else {
$r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",

120
mod/editpost.php Normal file
View File

@ -0,0 +1,120 @@
<?php
require_once('acl_selectors.php');
function editpost_content(&$a) {
$o = '';
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
$post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if(! $post_id) {
notice( t('Item not found') . EOL);
return;
}
$itm = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($post_id),
intval(local_user())
);
if(! count($itm)) {
notice( t('Item not found') . EOL);
return;
}
$o .= '<h2>' . t('Edit post') . '</h2>';
$tpl = get_markup_template('jot-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$ispublic' => '&nbsp;', // t('Visible to <strong>everybody</strong>'),
'$geotag' => $geotag,
'$nickname' => $a->user['nickname']
));
$tpl = get_markup_template("jot.tpl");
if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
$lockstate = 'lock';
else
$lockstate = 'unlock';
$celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
$jotplugins = '';
$jotnets = '';
$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
$mail_enabled = false;
$pubmail_enabled = false;
if(! $mail_disabled) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
$mail_enabled = true;
if(intval($r[0]['pubmail']))
$pubmail_enabled = true;
}
}
if($mail_enabled) {
$selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
$jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . 'value="1" /> '
. t("Post to Email") . '</div>';
}
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$o .= replace_macros($tpl,array(
'$return_path' => $_SESSION['return_url'],
'$action' => 'item',
'$share' => t('Edit'),
'$upload' => t('Upload photo'),
'$weblink' => t('Insert web link'),
'$youtube' => t('Insert YouTube video'),
'$video' => t('Insert Vorbis [.ogg] video'),
'$audio' => t('Insert Vorbis [.ogg] audio'),
'$setloc' => t('Set your location'),
'$noloc' => t('Clear browser location'),
'$wait' => t('Please wait'),
'$permset' => t('Permission settings'),
'$ptyp' => $itm[0]['type'],
'$content' => $itm[0]['body'],
'$post_id' => $post_id,
'$baseurl' => $a->get_baseurl(),
'$defloc' => $a->user['default-location'],
'$visitor' => 'none',
'$pvisit' => 'none',
'$emailcc' => t('CC: email addresses'),
'$public' => t('Public post'),
'$jotnets' => $jotnets,
'$emtitle' => t('Example: bob@example.com, mary@example.com'),
'$lockstate' => $lockstate,
'$acl' => '', // populate_acl((($group) ? $group_acl : $a->user), $celeb),
'$bang' => (($group) ? '!' : ''),
'$profile_uid' => $_SESSION['uid']
));
return $o;
}

View File

@ -11,178 +11,56 @@ function follow_post(&$a) {
}
$url = $orig_url = notags(trim($_POST['url']));
$email_conversant = false;
if($url) {
$links = @lrdd($url);
if(count($links)) {
foreach($links as $link) {
if($link['@attributes']['rel'] === NAMESPACE_DFRN)
$dfrn = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'salmon')
$notify = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === NAMESPACE_FEED)
$poll = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard')
$hcard = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = unamp($link['@attributes']['href']);
// remove ajax junk
}
$url = str_replace('/#!/','/',$url);
// Status.Net can have more than one profile URL. We need to match the profile URL
// to a contact on incoming messages to prevent spam, and we won't know which one
// to match. So in case of two, one of them is stored as an alias. Only store URL's
// and not webfinger user@host aliases. If they've got more than two non-email style
// aliases, let's hope we're lucky and get one that matches the feed author-uri because
// otherwise we're screwed.
if(! allowed_url($url)) {
notice( t('Disallowed profile URL.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
foreach($links as $link) {
if($link['@attributes']['rel'] === 'alias') {
if(strpos($link['@attributes']['href'],'@') === false) {
if(isset($profile)) {
if($link['@attributes']['href'] !== $profile)
$alias = unamp($link['@attributes']['href']);
}
else
$profile = unamp($link['@attributes']['href']);
}
}
}
}
else {
if((strpos($orig_url,'@')) && validate_email($orig_url)) {
$email_conversant = true;
}
}
}
// If we find a DFRN site, send our subscriber to the other person's
// dfrn_request page and all the other details will get sorted.
$ret = probe_url($url);
if(strlen($dfrn)) {
$ret = scrape_dfrn($dfrn);
if(is_array($ret) && x($ret,'dfrn-request')) {
if(strlen($a->path))
$myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
else
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
if($ret['network'] === NETWORK_DFRN) {
if(strlen($a->path))
$myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
else
$myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
goaway($ret['dfrn-request'] . "&addr=$myaddr");
goaway($ret['request'] . "&addr=$myaddr");
// NOTREACHED
}
// NOTREACHED
}
$network = 'stat';
$priority = 0;
if($hcard) {
$vcard = scrape_vcard($hcard);
// Google doesn't use absolute url in profile photos
if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') {
$h = @parse_url($hcard);
if($h)
$vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
}
}
if(! $profile)
$profile = $url;
if(! x($vcard,'fn'))
if(x($vcard,'nick'))
$vcard['fn'] = $vcard['nick'];
if((! isset($vcard)) && (! $poll)) {
$ret = scrape_feed($url);
if(count($ret) && ($ret['feed_atom'] || $ret['feed_rss'])) {
$poll = ((x($ret,'feed_atom')) ? unamp($ret['feed_atom']) : unamp($ret['feed_rss']));
$vcard = array();
require_once('simplepie/simplepie.inc');
$feed = new SimplePie();
$xml = fetch_url($poll);
$feed->set_raw_data($xml);
$feed->init();
$vcard['photo'] = $feed->get_image_url();
$author = $feed->get_author();
if($author) {
$vcard['fn'] = unxmlify(trim($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
if(strpos($vcard['fn'],'@') !== false)
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
$vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
$email = unxmlify($author->get_email());
}
else {
$item = $feed->get_item(0);
if($item) {
$author = $item->get_author();
if($author) {
$vcard['fn'] = trim(unxmlify($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
if(strpos($vcard['fn'],'@') !== false)
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
$vcard['nick'] = strtolower(unxmlify($vcard['fn']));
if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
$email = unxmlify($author->get_email());
}
if(! $vcard['photo']) {
$rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
if($rawmedia && $rawmedia[0]['attribs']['']['url'])
$vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
}
}
}
if((! $vcard['photo']) && strlen($email))
$vcard['photo'] = gravatar_img($email);
$network = 'feed';
$priority = 2;
}
}
logger('follow: poll=' . $poll . ' notify=' . $notify . ' profile=' . $profile . ' vcard=' . print_r($vcard,true));
$vcard['fn'] = notags($vcard['fn']);
$vcard['nick'] = notags($vcard['nick']);
// do we have enough information?
if(! ((x($vcard['fn'])) && ($poll) && ($profile))) {
if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
notice( t('The profile address specified does not provide adequate information.') . EOL);
goaway($_SESSION['return_url']);
}
if(! $notify) {
if(! $ret['notify']) {
notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
}
if(! x($vcard,'photo'))
$vcard['photo'] = $a->get_baseurl() . '/images/default-profile.jpg' ;
$writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
if($ret['network'] === NETWORK_MAIL) {
$writeable = 1;
}
// check if we already have a contact
// the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
intval(local_user()),
dbesc($poll)
dbesc($ret['poll'])
);
if(count($r)) {
@ -197,26 +75,28 @@ function follow_post(&$a) {
}
else {
// create contact record
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
`blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 0, 0, 0 ) ",
$r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
`writable`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
intval(local_user()),
dbesc(datetime_convert()),
dbesc($profile),
dbesc($alias),
dbesc($notify),
dbesc($poll),
dbesc($vcard['fn']),
dbesc($vcard['nick']),
dbesc($vcard['photo']),
dbesc($network),
intval(REL_FAN),
intval($priority)
dbesc($ret['url']),
dbesc($ret['addr']),
dbesc($ret['alias']),
dbesc($ret['notify']),
dbesc($ret['poll']),
dbesc($ret['name']),
dbesc($ret['nick']),
dbesc($ret['photo']),
dbesc($ret['network']),
intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
intval($ret['priority']),
intval($writeable)
);
}
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($profile),
dbesc($ret['url']),
intval(local_user())
);
@ -231,7 +111,7 @@ function follow_post(&$a) {
require_once("Photo.php");
$photos = import_profile_photo($vcard['photo'],local_user(),$contact_id);
$photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
$r = q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
@ -257,7 +137,7 @@ function follow_post(&$a) {
// create a follow slap
$tpl = load_view_file('view/follow_slap.tpl');
$tpl = get_markup_template('follow_slap.tpl');
$slap = replace_macros($tpl, array(
'$name' => $a->user['username'],
'$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],

68
mod/friendika.php Normal file
View File

@ -0,0 +1,68 @@
<?php
function friendika_init(&$a) {
if ($a->argv[1]=="json"){
$register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
if (isset($a->config['admin_email']) && $a->config['admin_email']!=''){
$r = q("SELECT username, nickname FROM user WHERE email='%s'", $a->config['admin_email']);
$admin = array(
'name' => $r[0]['username'],
'profile'=> $a->get_baseurl().'/profile/'.$r[0]['nickname'],
);
} else {
$admin = false;
}
$data = Array(
'version' => FRIENDIKA_VERSION,
'url' => $a->get_baseurl(),
'plugins' => $a->plugins,
'register_policy' => $register_policy[$a->config['register_policy']],
'admin' => $admin,
'site_name' => $a->config['sitename'],
);
echo str_replace('\\/','/',json_encode($data));
killme();
}
}
function friendika_content(&$a) {
$o = '';
$o .= '<h3>Friendika</h3>';
$o .= '<p></p><p>';
$o .= 'View <a href="LICENSE">License</a>' . '<br /><br />';
$o .= t('This is Friendika version') . ' ' . FRIENDIKA_VERSION . ' ';
$o .= t('running at web location') . ' ' . $a->get_baseurl() . '</p><p>';
$o .= t('Shared content within the Friendika network is provided under the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 license</a>') . '</p><p>';
$o .= t('Please visit <a href="http://project.friendika.com">Project.Friendika.com</a> to learn more about the Friendika project.') . '</p><p>';
$o .= t('Bug reports and issues: please visit') . ' ' . '<a href="http://bugs.friendika.com">Bugs.Friendika.com</a></p><p>';
$o .= t('Suggestions, praise, donations, etc. - please email "Info" at Friendika - dot com') . '</p>';
$o .= '<p></p>';
if(count($a->plugins)) {
$o .= '<p>' . t('Installed plugins/addons/apps') . '</p>';
$o .= '<ul>';
foreach($a->plugins as $p)
if(strlen($p))
$o .= '<li>' . $p . '</li>';
$o .= '</ul>';
}
else
$o .= '<p>' . t('No installed plugins/addons/apps');
return $o;
}

View File

@ -55,28 +55,7 @@ function group_post(&$a) {
if($r)
notice( t('Group name changed.') . EOL );
}
$members = $_POST['group_members_select'];
if(is_array($members))
array_walk($members,'validate_members');
$r = q("DELETE FROM `group_member` WHERE `gid` = %d AND `uid` = %d",
intval($a->argv[1]),
intval(local_user())
);
$result = true;
if(is_array($members) && count($members)) {
foreach($members as $member) {
$r = q("INSERT INTO `group_member` ( `uid`, `gid`, `contact-id`)
VALUES ( %d, %d, %d )",
intval(local_user()),
intval($group['id']),
intval($member)
);
if(! $r)
$result = false;
}
}
if($result)
notice( t('Membership list updated.') . EOL);
$a->page['aside'] = group_side();
}
return;
@ -90,8 +69,12 @@ function group_content(&$a) {
}
if(($a->argc == 2) && ($a->argv[1] === 'new')) {
$tpl = load_view_file('view/group_new.tpl');
$o .= replace_macros($tpl,array());
$tpl = get_markup_template('group_new.tpl');
$o .= replace_macros($tpl,array(
'$desc' => t('Create a group of contacts/friends.'),
'$name' => t('Group Name: '),
'$submit' => t('Submit')
));
return $o;
}
@ -109,13 +92,22 @@ function group_content(&$a) {
notice( t('Unable to remove group.') . EOL);
}
goaway($a->get_baseurl() . '/group');
return; // NOTREACHED
// NOTREACHED
}
if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
$r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
intval($a->argv[2]),
intval(local_user())
);
if(count($r))
$change = intval($a->argv[2]);
}
if(($a->argc > 1) && (intval($a->argv[1]))) {
if(($a->argc == 2) && (intval($a->argv[1]))) {
require_once('include/acl_selectors.php');
$r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
$r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
intval($a->argv[1]),
intval(local_user())
);
@ -124,14 +116,31 @@ function group_content(&$a) {
goaway($a->get_baseurl() . '/contacts');
}
$group = $r[0];
$ret = group_get_members($group['id']);
$members = group_get_members($group['id']);
$preselected = array();
if(count($ret)) {
foreach($ret as $p)
$preselected[] = $p['id'];
if(count($members)) {
foreach($members as $member)
$preselected[] = $member['id'];
}
$drop_tpl = load_view_file('view/group_drop.tpl');
if($change) {
if(in_array($change,$preselected)) {
group_rmv_member(local_user(),$group['name'],$change);
}
else {
group_add_member(local_user(),$group['name'],$change);
}
$members = group_get_members($group['id']);
$preselected = array();
if(count($members)) {
foreach($members as $member)
$preselected[] = $member['id'];
}
}
$drop_tpl = get_markup_template('group_drop.tpl');
$drop_txt = replace_macros($drop_tpl, array(
'$id' => $group['id'],
'$delete' => t('Delete')
@ -139,15 +148,63 @@ function group_content(&$a) {
$celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
$tpl = load_view_file('view/group_edit.tpl');
$tpl = get_markup_template('group_edit.tpl');
$o .= replace_macros($tpl, array(
'$gid' => $group['id'],
'$name' => $group['name'],
'$drop' => $drop_txt,
'$selector' => contact_select('group_members_select','group_members_select',$preselected,25,false,$celeb)
'$desc' => t('Click on a contact to add or remove.'),
'$title' => t('Group Editor'),
'$gname' => t('Group Name: '),
'$submit' => t('Submit')
));
}
if(! isset($group))
return;
$o .= '<div id="group-update-wrapper">';
if($change)
$o = '';
$o .= '<div id="group-members">';
$o .= '<h3>' . t('Members') . '</h3>';
foreach($members as $member) {
if($member['url']) {
$member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
$o .= micropro($member,true,'mpgroup');
}
else
group_rmv_member(local_user(),$group['name'],$member['id']);
}
$o .= '</div><div id="group-members-end"></div>';
$o .= '<hr id="group-separator" />';
$o .= '<div id="group-all-contacts">';
$o .= '<h3>' . t('All Contacts') . '</h3>';
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
intval(local_user())
);
if(count($r)) {
foreach($r as $member) {
if(! in_array($member['id'],$preselected)) {
$member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . '); return true;';
$o .= micropro($member,true,'mpall');
}
}
}
$o .= '</div><div id="group-all-contacts-end"></div>';
if($change) {
echo $o;
killme();
}
$o .= '</div>';
return $o;
}
}

37
mod/help.php Normal file
View File

@ -0,0 +1,37 @@
<?php
if(! function_exists('load_doc_file')) {
function load_doc_file($s) {
global $lang;
if(! isset($lang))
$lang = 'en';
$b = basename($s);
$d = dirname($s);
if(file_exists("$d/$lang/$b"))
return file_get_contents("$d/$lang/$b");
return file_get_contents($s);
}}
function help_content(&$a) {
global $lang;
require_once('library/markdown.php');
$text = '';
if($a->argc > 1) {
$text = load_doc_file('doc/' . $a->argv[1] . '.md');
$a->page['title'] = t('Help:') . ' ' . str_replace('-',' ',notags($a->argv[1]));
}
if(! $text) {
$text = load_doc_file('doc/Home.md');
$a->page['title'] = t('Help');
}
return Markdown($text);
}

View File

@ -20,7 +20,7 @@ function home_content(&$a) {
if(x($_SESSION,'theme'))
unset($_SESSION['theme']);
$o .= '<h1>' . ((x($a->config,'sitename')) ? t("Welcome to ").$a->config['sitename'] : "" ) . '</h1>';
$o .= '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
if(file_exists('home.html'))
$o .= file_get_contents('home.html');

View File

@ -14,17 +14,20 @@ function install_post(&$a) {
$phpath = notags(trim($_POST['phpath']));
require_once("dba.php");
unset($db);
$db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
if(mysqli_connect_errno()) {
unset($db);
$db = new dba($dbhost, $dbuser, $dbpass, '', true);
if(! mysqli_connect_errno()) {
$r = q("CREATE DATABASE '%s'",
dbesc($dbdata)
);
if($r)
if($r) {
unset($db);
$db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
}
}
if(mysqli_connect_errno()) {
notice( t('Could not create/connect to database.') . EOL);
@ -34,7 +37,7 @@ function install_post(&$a) {
notice( t('Connected to database.') . EOL);
$tpl = load_view_file('view/htconfig.tpl');
$tpl = get_intltext_template('htconfig.tpl');
$txt = replace_macros($tpl,array(
'$dbhost' => $dbhost,
'$dbuser' => $dbuser,
@ -50,36 +53,47 @@ function install_post(&$a) {
}
$errors = load_database($db);
if(! $errors) {
// Our sessions normally are stored in the database. But as we have only managed
// to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
// that you'll see the following important notice (which is stored in the session).
session_write_close();
if($errors)
$a->data['db_failed'] = true;
else
$a->data['db_installed'] = true;
require_once('session.php');
session_start();
session_regenerate_id();
$_SESSION['sysmsg'] = '';
notice( t('Database import succeeded.') . EOL
. t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL
. t('Please see the file "INSTALL.txt".') . EOL );
goaway($a->get_baseurl() . '/register' );
}
else {
$db = null; // start fresh
notice( t('Database import failed.') . EOL
. t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
. t('Please see the file "INSTALL.txt".') . EOL );
}
return;
}
function install_content(&$a) {
global $db;
$o = '';
if(x($a->data,'db_installed')) {
$o .= '<h2>' . t('Proceed with Installation') . '</h2>';
$o .= '<p style="font-size: 130%;">';
$o .= t('Your Friendika site database has been installed.') . EOL;
$o .= t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL ;
$o .= t('Please see the file "INSTALL.txt".') . EOL ;
$o .= '<br />';
$o .= '<a href="' . $a->get_baseurl() . '/register' . '">' . t('Proceed to registration') . '</a>' ;
$o .= '</p>';
return $o;
}
if(x($a->data,'db_failed')) {
$o .= t('Database import failed.') . EOL;
$o .= t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
$o .= t('Please see the file "INSTALL.txt".') . EOL ;
return $o;
}
if($db && $db->connected) {
$r = q("SELECT COUNT(*) as `total` FROM `user`");
if($r && count($r) && $r[0]['total']) {
notice( t('Permission denied.') . EOL);
return '';
}
}
notice( t('Welcome to Friendika.') . EOL);
@ -102,8 +116,18 @@ function install_content(&$a) {
require_once('datetime.php');
$tpl = load_view_file('view/install_db.tpl');
$tpl = get_markup_template('install_db.tpl');
$o .= replace_macros($tpl, array(
'$lbl_01' => t('Friendika Social Network'),
'$lbl_02' => t('Installation'),
'$lbl_03' => t('In order to install Friendika we need to know how to contact your database.'),
'$lbl_04' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
'$lbl_05' => t('The database you specify below must already exist. If it does not, please create it before continuing.'),
'$lbl_06' => t('Database Server Name'),
'$lbl_07' => t('Database Login Name'),
'$lbl_08' => t('Database Login Password'),
'$lbl_09' => t('Database Name'),
'$lbl_10' => t('Please select a default timezone for your website'),
'$baseurl' => $a->get_baseurl(),
'$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
'$submit' => t('Submit'),

View File

@ -25,21 +25,25 @@ function invite_post(&$a) {
$recip = trim($recip);
if(! valid_email($recip)) {
notice( $recip . t(' : ') . t('Not a valid email address.') . EOL);
notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL);
continue;
}
$res = mail($recip, t('Please join my network on ') . $a->config['sitename'],
$message, "From: " . $a->user['email']);
$res = mail($recip, sprintf(t('Please join my network on %s'), $a->config['sitename']),
$message,
"From: " . $a->user['email'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
if($res) {
$total ++;
}
else {
notice( $recip . t(' : ') . t('Message delivery failed.') . EOL);
notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL);
}
}
notice( $total . t(' messages sent.') . EOL);
notice( sprintf( tt("%d message sent.", "%d messages sent.", $total) , $total) . EOL);
return;
}
@ -51,13 +55,13 @@ function invite_content(&$a) {
return;
}
$tpl = load_view_file('view/invite.tpl');
$tpl = get_markup_template('invite.tpl');
$o = replace_macros($tpl, array(
'$invite' => t('Send invitations'),
'$addr_text' => t('Enter email addresses, one per line:'),
'$msg_text' => t('Your message:'),
'$default_message' => t('Please join my social network on ') . $a->config['sitename'] . "\r\n" . "\r\n"
'$default_message' => sprintf(t('Please join my social network on %s'), $a->config['sitename']) . "\r\n" . "\r\n"
. t('To accept this invitation, please visit:') . "\r\n" . "\r\n" . $a->get_baseurl()
. "\r\n" . "\r\n" . t('Once you have registered, please connect with me via my profile page at:')
. "\r\n" . "\r\n" . $a->get_baseurl() . '/profile/' . $a->user['nickname'] ,

View File

@ -51,7 +51,7 @@ function item_post(&$a) {
}
$profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
$post_id = ((x($_POST['post_id'])) ? intval($_POST['post_id']) : 0);
if(! can_write_wall($a,$profile_uid)) {
notice( t('Permission denied.') . EOL) ;
@ -60,6 +60,21 @@ function item_post(&$a) {
killme();
}
// is this an edited post?
$orig_post = null;
if($post_id) {
$i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
intval($profile_uid),
intval($post_id)
);
if(! count($i))
killme();
$orig_post = $i[0];
}
$user = null;
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
@ -68,37 +83,53 @@ function item_post(&$a) {
if(count($r))
$user = $r[0];
if($orig_post) {
$str_group_allow = $orig_post['allow_gid'];
$str_contact_allow = $orig_post['allow_cid'];
$str_group_deny = $orig_post['deny_gid'];
$str_contact_deny = $orig_post['deny_cid'];
$title = $orig_post['title'];
$location = $orig_post['location'];
$coord = $orig_post['coord'];
$verb = $orig_post['verb'];
$emailcc = $orig_post['emailcc'];
$str_group_allow = perms2str($_POST['group_allow']);
$str_contact_allow = perms2str($_POST['contact_allow']);
$str_group_deny = perms2str($_POST['group_deny']);
$str_contact_deny = perms2str($_POST['contact_deny']);
$private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
if(($parent_item) &&
(($parent_item['private'])
|| strlen($parent_item['allow_cid'])
|| strlen($parent_item['allow_gid'])
|| strlen($parent_item['deny_cid'])
|| strlen($parent_item['deny_gid'])
)
) {
$private = 1;
$body = escape_tags(trim($_POST['body']));
$private = $orig_post['private'];
$pubmail_enable = $orig_post['pubmail'];
}
else {
$str_group_allow = perms2str($_POST['group_allow']);
$str_contact_allow = perms2str($_POST['contact_allow']);
$str_group_deny = perms2str($_POST['group_deny']);
$str_contact_deny = perms2str($_POST['contact_deny']);
$title = notags(trim($_POST['title']));
$location = notags(trim($_POST['location']));
$coord = notags(trim($_POST['coord']));
$verb = notags(trim($_POST['verb']));
$emailcc = notags(trim($_POST['emailcc']));
$title = notags(trim($_POST['title']));
$body = escape_tags(trim($_POST['body']));
$location = notags(trim($_POST['location']));
$coord = notags(trim($_POST['coord']));
$verb = notags(trim($_POST['verb']));
$emailcc = notags(trim($_POST['emailcc']));
$body = escape_tags(trim($_POST['body']));
$private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
if(! strlen($body)) {
notice( t('Empty post discarded.') . EOL );
if(x($_POST,'return'))
goaway($a->get_baseurl() . "/" . $_POST['return'] );
killme();
if(($parent_item) &&
(($parent_item['private'])
|| strlen($parent_item['allow_cid'])
|| strlen($parent_item['allow_gid'])
|| strlen($parent_item['deny_cid'])
|| strlen($parent_item['deny_gid'])
)) {
$private = 1;
}
$pubmail_enable = ((x($_POST,'pubmail_enable') && intval($_POST['pubmail_enable']) && (! $private)) ? 1 : 0);
if(! strlen($body)) {
notice( t('Empty post discarded.') . EOL );
if(x($_POST,'return'))
goaway($a->get_baseurl() . "/" . $_POST['return'] );
killme();
}
}
// get contact info for poster
@ -151,7 +182,6 @@ function item_post(&$a) {
}
}
/**
*
* When a photo was uploaded into the message using the (profile wall) ajax
@ -212,6 +242,8 @@ function item_post(&$a) {
if(count($tags)) {
foreach($tags as $tag) {
if(strpos($tag,'#') === 0) {
if(strpos($tag,'[url='))
continue;
$basetag = str_replace('_',' ',substr($tag,1));
$body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
if(strlen($str_tags))
@ -220,6 +252,8 @@ function item_post(&$a) {
continue;
}
if(strpos($tag,'@') === 0) {
if(strpos($tag,'[url='))
continue;
$stat = false;
$name = substr($tag,1);
if((strpos($name,'@')) || (strpos($name,'http://'))) {
@ -283,15 +317,13 @@ function item_post(&$a) {
$str_tags .= ',';
$str_tags .= '@[url=' . $alias . ']' . $newname . '[/url]';
}
}
}
}
}
$wall = 0;
if($post_type === 'wall' || $post_type === 'wall-comment')
$wall = 1;
@ -332,6 +364,7 @@ function item_post(&$a) {
$datarray['deny_cid'] = $str_contact_deny;
$datarray['deny_gid'] = $str_group_deny;
$datarray['private'] = $private;
$datarray['pubmail'] = $pubmail_enable;
/**
* These fields are for the convenience of plugins...
@ -342,13 +375,35 @@ function item_post(&$a) {
$datarray['parent'] = $parent;
$datarray['self'] = $self;
if($orig_post)
$datarray['edit'] = true;
call_hooks('post_local',$datarray);
if($orig_post) {
$r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
dbesc($body),
dbesc(datetime_convert()),
intval($post_id),
intval($profile_uid)
);
proc_run('php', "include/notifier.php", 'edit_post', "$post_id");
if((x($_POST,'return')) && strlen($_POST['return'])) {
logger('return: ' . $_POST['return']);
goaway($a->get_baseurl() . "/" . $_POST['return'] );
}
killme();
}
else
$post_id = 0;
$r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `changed`, `uri`, `title`, `body`, `location`, `coord`,
`tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private` )
VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
`tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail` )
VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )",
intval($datarray['uid']),
dbesc($datarray['type']),
intval($datarray['wall']),
@ -375,7 +430,8 @@ function item_post(&$a) {
dbesc($datarray['allow_gid']),
dbesc($datarray['deny_cid']),
dbesc($datarray['deny_gid']),
intval($datarray['private'])
intval($datarray['private']),
intval($datarray['pubmail'])
);
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
@ -408,21 +464,7 @@ function item_post(&$a) {
if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
require_once('bbcode.php');
$from = $author['name'];
/*
$tpl = load_view_file('view/cmnt_received_eml.tpl');
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
'$username' => $user['username'],
'$email' => $user['email'],
'$from' => $from,
'$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
'$body' => strip_tags(bbcode($datarray['body']))
));
$res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
$email_tpl,t("From: Administrator@") . $a->get_hostname() );
*/
// name of the automated email sender
$msg['notificationfromname'] = stripslashes($datarray['author-name']);;
// noreply address to send from
@ -439,7 +481,7 @@ function item_post(&$a) {
= html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), "<br />\n",$datarray['body']))));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_html_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -452,7 +494,7 @@ function item_post(&$a) {
));
// load the template for private message notifications
$tpl = load_view_file('view/cmnt_received_text_body_eml.tpl');
$tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl,array(
'$sitename' => $a->config['sitename'], // name of this site
'$siteurl' => $a->get_baseurl(), // descriptive url of this site
@ -485,22 +527,6 @@ function item_post(&$a) {
if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
require_once('bbcode.php');
$from = $author['name'];
/*
$tpl = load_view_file('view/wall_received_eml.tpl');
$email_tpl = replace_macros($tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
'$username' => $user['username'],
'$email' => $user['email'],
'$from' => $from,
'$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id,
'$body' => strip_tags(bbcode($datarray['body']))
));
$res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
$email_tpl,t("From: Administrator@") . $a->get_hostname() );
*/
// name of the automated email sender
$msg['notificationfromname'] = $from;
@ -583,7 +609,8 @@ function item_post(&$a) {
proc_run('php', "include/notifier.php", $notify_type, "$post_id");
$datarray['id'] = $post_id;
$datarray['id'] = $post_id;
$datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
call_hooks('post_local_end', $datarray);
@ -594,13 +621,12 @@ function item_post(&$a) {
$addr = trim($recip);
if(! strlen($addr))
continue;
$disclaimer = '<hr />' . t('This message was sent to you by ') . $a->user['username']
. t(', a member of the Friendika social network.') . '<br />';
$disclaimer .= t('You may visit them online at') . ' '
. $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '<br />';
$disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . '<br />';
$disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username'])
. '<br />';
$disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
$disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
$subject = '[Friendika]' . ' ' . $a->user['username'] . ' ' . t('posted an update.');
$subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
$headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
@ -640,7 +666,7 @@ function item_content(&$a) {
require_once('include/security.php');
$uid = $_SESSION['uid'];
$uid = local_user();
if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
@ -716,7 +742,8 @@ function item_content(&$a) {
// send the notification upstream/downstream as the case may be
proc_run('php',"include/notifier.php","drop","$drop_id");
// We seem to lose the return url occasionally. Have not been able to reliably duplicate
// logger('drop_return_url: ' . $_SESSION['return_url']);
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
//NOTREACHED
}
@ -726,4 +753,4 @@ function item_content(&$a) {
//NOTREACHED
}
}
}
}

View File

@ -124,9 +124,9 @@ function like_content(&$a) {
</object>
EOT;
if($verb === 'like')
$bodyverb = t('likes');
$bodyverb = t('%1$s likes %2$s\'s %3$s');
if($verb === 'dislike')
$bodyverb = t('doesn\'t like');
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
if(! isset($bodyverb))
return;
@ -147,9 +147,11 @@ EOT;
$arr['author-name'] = $contact['name'];
$arr['author-link'] = $contact['url'];
$arr['author-avatar'] = $contact['thumb'];
$arr['body'] = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . ' ' . $bodyverb . ' '
. '[url=' . $item['author-link'] . ']' . $item['author-name'] . t('\'s') . '[/url]' . ' '
. '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]' ;
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
$arr['verb'] = $activity;
$arr['object-type'] = $objtype;
@ -171,6 +173,10 @@ EOT;
);
}
$arr['id'] = $post_id;
call_hooks('post_local_end', $arr);
proc_run('php',"include/notifier.php","like","$post_id");
return; // NOTREACHED

View File

@ -24,9 +24,9 @@ function lostpass_post(&$a) {
intval($uid)
);
if($r)
notice("Password reset request issued. Check your email.");
notice( t('Password reset request issued. Check your email.') . EOL);
$email_tpl = load_view_file("view/lostpass_eml.tpl");
$email_tpl = get_intltext_template("lostpass_eml.tpl");
$email_tpl = replace_macros($email_tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
@ -35,8 +35,12 @@ function lostpass_post(&$a) {
'$reset_link' => $a->get_baseurl() . '/lostpass?verify=' . $new_password
));
$res = mail($email, t('Password reset requested at ') . $a->config['sitename'],
$email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER[SERVER_NAME]);
$res = mail($email, sprintf( t('Password reset requested at %s'),$a->config['sitename']),
$email_tpl,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
goaway($a->get_baseurl());
}
@ -53,7 +57,7 @@ function lostpass_content(&$a) {
dbesc($hash)
);
if(! count($r)) {
notice("Request could not be verified. (You may have previously submitted it.) Password reset failed." . EOL);
notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
goaway($a->get_baseurl());
return;
}
@ -69,16 +73,23 @@ function lostpass_content(&$a) {
intval($uid)
);
if($r) {
$tpl = load_view_file('view/pwdreset.tpl');
$tpl = get_markup_template('pwdreset.tpl');
$o .= replace_macros($tpl,array(
'$lbl1' => t('Password Reset'),
'$lbl2' => t('Your password has been reset as requested.'),
'$lbl3' => t('Your new password is'),
'$lbl4' => t('Save or copy your new password - and then'),
'$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
'$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
'$newpass' => $new_password,
'$baseurl' => $a->get_baseurl()
));
notice("Your password has been reset." . EOL);
$email_tpl = load_view_file("view/passchanged_eml.tpl");
$email_tpl = get_intltext_template("passchanged_eml.tpl");
$email_tpl = replace_macros($email_tpl, array(
'$sitename' => $a->config['sitename'],
'$siteurl' => $a->get_baseurl(),
@ -87,16 +98,24 @@ function lostpass_content(&$a) {
'$new_password' => $new_password,
'$uid' => $newuid ));
$res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,"From: Administrator@{$_SERVER[SERVER_NAME]}");
$res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
return $o;
}
}
else {
$tpl = load_view_file('view/lostpass.tpl');
$tpl = get_markup_template('lostpass.tpl');
$o .= $tpl;
$o .= replace_macros($tpl,array(
'$title' => t('Forgot your Password?'),
'$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
'$name' => t('Nickname or Email: '),
'$submit' => t('Reset')
));
return $o;
}

View File

@ -34,7 +34,7 @@ function manage_post(&$a) {
$_SESSION['page_flags'] = $r[0]['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
notice( t("Welcome back ") . $r[0]['username'] . EOL);
notice( sprintf( t("Welcome back %s") , $r[0]['username']) . EOL);
$a->user = $r[0];
if(strlen($a->user['timezone'])) {

57
mod/match.php Normal file
View File

@ -0,0 +1,57 @@
<?php
function match_content(&$a) {
$o = '';
if(! local_user())
return;
$o .= '<h2>' . t('Profile Match') . '</h2>';
$r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
intval(local_user())
);
if(! count($r))
return;
if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) {
notice('No keywords to match. Please add keywords to your default profile.');
return;
}
$params = array();
$tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
if($tags) {
$params['s'] = $tags;
if($a->pager['page'] != 1)
$params['p'] = $a->pager['page'];
$x = post_url('http://dir.friendika.com/msearch', $params);
$j = json_decode($x);
if($j->total) {
$a->set_pager_total($j->total);
$a->set_pager_itemspage($j->items_page);
}
if(count($j->results)) {
foreach($j->results as $jj) {
$o .= '<div class="profile-match-wrapper"><div class="profile-match-photo">';
$o .= '<a href="' . $jj->url . '">' . '<img src="' . $jj->photo . '" alt="' . $jj->name . '" title="' . $jj->name . '[' . $jj->url . ']' . '" /></a></div>';
$o .= '<div class="profile-match-break"></div>';
$o .= '<div class="profile-match-name"><a href="' . $jj->url . '" title="' . $jj->name . '[' . $jj->url .']' . '">' . $jj->name . '</a></div>';
$o .= '<div class="profile-match-end"></div></div>';
}
$o .= '<div id="profile-match-wrapper-end"></div>';
}
else {
notice( t('No matches') . EOL);
}
}
$o .= paginate($a);
return $o;
}

View File

@ -120,7 +120,7 @@ function message_content(&$a) {
$myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
$tpl = load_view_file('view/mail_head.tpl');
$tpl = get_markup_template('mail_head.tpl');
$header = replace_macros($tpl, array(
'$messages' => t('Messages'),
'$inbox' => t('Inbox'),
@ -164,15 +164,18 @@ function message_content(&$a) {
if(($a->argc > 1) && ($a->argv[1] === 'new')) {
$tpl = load_view_file('view/msg-header.tpl');
$tpl = get_markup_template('msg-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$nickname' => $a->user['nickname']
'$nickname' => $a->user['nickname'],
'$linkurl' => t('Please enter a link URL:')
));
$select = contact_select('messageto','message-to-select', false, 4, true);
$tpl = load_view_file('view/prv_message.tpl');
$preselect = (isset($a->argv[2])?array($a->argv[2]):false);
$select = contact_select('messageto','message-to-select', $preselect, 4, true);
$tpl = get_markup_template('prv_message.tpl');
$o .= replace_macros($tpl,array(
'$header' => t('Send Private Message'),
'$to' => t('To:'),
@ -222,7 +225,7 @@ function message_content(&$a) {
return $o;
}
$tpl = load_view_file('view/mail_list.tpl');
$tpl = get_markup_template('mail_list.tpl');
foreach($r as $rr) {
$o .= replace_macros($tpl, array(
'$id' => $rr['id'],
@ -234,7 +237,7 @@ function message_content(&$a) {
'$delete' => t('Delete conversation'),
'$body' => $rr['body'],
'$to_name' => $rr['name'],
'$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'],'D, d M Y - g:i A')
'$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
));
}
$o .= paginate($a);
@ -272,7 +275,7 @@ function message_content(&$a) {
require_once("include/bbcode.php");
$tpl = load_view_file('view/msg-header.tpl');
$tpl = get_markup_template('msg-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$nickname' => $a->user['nickname'],
@ -280,7 +283,7 @@ function message_content(&$a) {
));
$tpl = load_view_file('view/mail_conv.tpl');
$tpl = get_markup_template('mail_conv.tpl');
foreach($messages as $message) {
if($message['from-url'] == $myprofile) {
$from_url = $myprofile;
@ -306,7 +309,7 @@ function message_content(&$a) {
}
$select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
$parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
$tpl = load_view_file('view/prv_message.tpl');
$tpl = get_markup_template('prv_message.tpl');
$o .= replace_macros($tpl,array(
'$header' => t('Send Reply'),
'$to' => t('To:'),

View File

@ -15,25 +15,25 @@ function network_init(&$a) {
$a->page['aside'] .= '<div id="network-new-link">';
if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
$a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '">' . t('Normal View') . '</a>';
$a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('Normal View') . '</a>';
else
$a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
$a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('New Item View') . '</a>';
$a->page['aside'] .= '</div>';
$a->page['aside'] .= group_side('network','network');
$a->page['aside'] .= group_side('network','network',true);
}
function network_content(&$a, $update = 0) {
require_once('include/conversation.php');
if(! local_user())
return login(false);
$o = '';
require_once("include/bbcode.php");
$contact_id = $a->cid;
$group = 0;
@ -41,6 +41,8 @@ function network_content(&$a, $update = 0) {
$nouveau = false;
require_once('include/acl_selectors.php');
$cid = ((x($_GET['cid'])) ? intval($_GET['cid']) : 0);
if(($a->argc > 2) && $a->argv[2] === 'new')
$nouveau = true;
@ -49,67 +51,41 @@ function network_content(&$a, $update = 0) {
$nouveau = true;
else {
$group = intval($a->argv[1]);
$group_acl = array('allow_gid' => '<' . $group . '>');
$def_acl = array('allow_gid' => '<' . $group . '>');
}
}
if($cid)
$def_acl = array('allow_cid' => '<' . intval($cid) . '>');
if(! $update) {
if(group) {
if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
$plural_form = sprintf( tt('%d member', '%d members', $t), $t);
notice( sprintf( t('Warning: This group contains %s from an insecure network.'), $plural_form ) . EOL);
notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
}
}
$o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
$_SESSION['return_url'] = $a->cmd;
$geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
$tpl = load_view_file('view/jot-header.tpl');
$a->page['htmlhead'] .= replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$geotag' => $geotag,
'$nickname' => $a->user['nickname']
));
$tpl = load_view_file("view/jot.tpl");
if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
$lockstate = 'lock';
else
$lockstate = 'unlock';
$celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
$jotplugins = '';
$jotnets = '';
call_hooks('jot_tool', $jotplugins);
call_hooks('jot_networks', $jotnets);
$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
$o .= replace_macros($tpl,array(
'$return_path' => $a->cmd,
'$action' => 'item',
'$share' => t('Share'),
'$upload' => t('Upload photo'),
'$weblink' => t('Insert web link'),
'$youtube' => t('Insert YouTube video'),
'$setloc' => t('Set your location'),
'$noloc' => t('Clear browser location'),
'$wait' => t('Please wait'),
'$permset' => t('Permission settings'),
'$content' => '',
'$post_id' => '',
'$baseurl' => $a->get_baseurl(),
'$defloc' => $a->user['default-location'],
'$visitor' => 'block',
'$emailcc' => t('CC: email addresses'),
'$jotnets' => $jotnets,
'$emtitle' => t('Example: bob@example.com, mary@example.com'),
'$lockstate' => $lockstate,
'$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
'$bang' => (($group) ? '!' : ''),
'$profile_uid' => $_SESSION['uid']
));
$x = array(
'is_owner' => true,
'allow_location' => $a->user['allow_location'],
'default_location' => $a->user['default_location'],
'nickname' => $a->user['nickname'],
'lockstate' => ((($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
'bang' => (($group || $cid) ? '!' : ''),
'visitor' => 'block',
'profile_uid' => local_user()
);
$o .= status_editor($a,$x);
// The special div is needed for liveUpdate to kick in for this page.
// We only launch liveUpdate if you are on the front page, you aren't
@ -119,18 +95,21 @@ function network_content(&$a, $update = 0) {
$o .= '<div id="live-network"></div>' . "\r\n";
$o .= "<script> var profile_uid = " . $_SESSION['uid']
. "; var netargs = '" . substr($a->cmd,8)
. ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '')
. "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
}
// We aren't going to try and figure out at the item, group, and page level
// which items you've seen and which you haven't. You're looking at some
// subset of items, so just mark everything seen.
// We aren't going to try and figure out at the item, group, and page
// level which items you've seen and which you haven't. If you're looking
// at the top level network page just mark everything seen.
$r = q("UPDATE `item` SET `unseen` = 0
WHERE `unseen` = 1 AND `uid` = %d",
intval($_SESSION['uid'])
);
if((! $group) && (! $cid)) {
$r = q("UPDATE `item` SET `unseen` = 0
WHERE `unseen` = 1 AND `uid` = %d",
intval($_SESSION['uid'])
);
}
// We don't have to deal with ACL's on this page. You're looking at everything
// that belongs to you, hence you can see all of it. We will filter by group if
@ -148,7 +127,7 @@ function network_content(&$a, $update = 0) {
killme();
notice( t('No such group') . EOL );
goaway($a->get_baseurl() . '/network');
return; // NOTREACHED
// NOTREACHED
}
$contacts = expand_groups(array($group));
@ -160,28 +139,56 @@ function network_content(&$a, $update = 0) {
notice( t('Group is empty'));
}
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
$o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
}
elseif($cid) {
if((! $group) && (! $update))
$r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d
AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
intval($cid)
);
if(count($r)) {
$sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( " . intval($cid) . " )) ";
$o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
}
}
else {
notice( t('Invalid contact.') . EOL);
goaway($a->get_baseurl() . '/network');
// NOTREACHED
}
}
if((! $group) && (! $cid) && (! $update))
$o .= get_birthdays();
$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
$r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$sql_extra2
$sql_extra ",
intval($_SESSION['uid'])
);
if(count($r))
if(count($r)) {
$a->set_pager_total($r[0]['total']);
$a->set_pager_itemspage(40);
}
if($nouveau) {
// "New Item View" - show all items unthreaded in reverse created date order
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, `contact`
@ -194,282 +201,65 @@ function network_content(&$a, $update = 0) {
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
}
else {
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
// Normal conversation view
// First fetch a known number of parent items
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = `parentitem`.`id`
AND `item`.`parent` = `item`.`id`
$sql_extra
ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC LIMIT %d ,%d ",
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
intval(local_user()),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
}
$author_contacts = extract_item_authors($r,local_user());
$cmnt_tpl = load_view_file('view/comment_item.tpl');
$like_tpl = load_view_file('view/like.tpl');
$tpl = load_view_file('view/wall_item.tpl');
$wallwall = load_view_file('view/wallwall_item.tpl');
$alike = array();
$dlike = array();
if(count($r)) {
if($nouveau) {
$tpl = load_view_file('view/search_item.tpl');
$droptpl = load_view_file('view/wall_fake_drop.tpl');
foreach($r as $item) {
$comment = '';
$owner_url = '';
$owner_photo = '';
$owner_name = '';
$sparkle = '';
$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
$profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
$profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
if(strlen($item['author-link'])) {
if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
$profile_link = $redirect_url;
$sparkle = ' sparkle';
}
elseif(isset($author_contacts[$item['author-link']])) {
$profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
$sparkle = ' sparkle';
}
}
$location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
$coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
if($coord) {
if($location)
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
else
$location = '<span class="smalltext">' . $coord . '</span>';
}
$drop = replace_macros($droptpl,array('$id' => $item['id']));
$lock = '<div class="wall-item-lock"></div>';
$o .= replace_macros($tpl,array(
'$id' => $item['item_id'],
'$linktitle' => t('View $name\'s profile'),
'$profile_url' => $profile_link,
'$name' => $profile_name,
'$sparkle' => $sparkle,
'$lock' => $lock,
'$thumb' => $profile_avatar,
'$title' => $item['title'],
'$body' => smilies(bbcode($item['body'])),
'$ago' => relative_date($item['created']),
'$location' => $location,
'$indent' => '',
'$owner_url' => $owner_url,
'$owner_photo' => $owner_photo,
'$owner_name' => $owner_name,
'$drop' => $drop,
'$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
));
}
$o .= paginate($a);
return $o;
}
// Then fetch all the children of the parents that are on this page
foreach($r as $item) {
like_puller($a,$item,$alike,'like');
like_puller($a,$item,$dlike,'dislike');
}
$parents_arr = array();
$parents_str = '';
foreach($r as $item) {
$comment = '';
$template = $tpl;
$commentww = '';
$sparkle = '';
$owner_url = $owner_photo = $owner_name = '';
if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
continue;
$redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
$lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
: '<div class="wall-item-lock"></div>');
// Top-level wall post not written by the wall owner (wall-to-wall)
// First figure out who owns it.
$osparkle = '';
if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
if($item['type'] === 'wall') {
// I do. Put me on the left of the wall-to-wall notice.
$owner_url = $a->contact['url'];
$owner_photo = $a->contact['thumb'];
$owner_name = $a->contact['name'];
$template = $wallwall;
$commentww = 'ww';
}
if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
// Could be anybody.
$owner_url = $item['owner-link'];
$owner_photo = $item['owner-avatar'];
$owner_name = $item['owner-name'];
$template = $wallwall;
$commentww = 'ww';
// If it is our contact, use a friendly redirect link
if((link_compare($item['owner-link'],$item['url']))
&& ($item['network'] === 'dfrn')) {
$owner_url = $redirect_url;
$osparkle = ' sparkle';
}
}
}
if($update)
$return_url = $_SESSION['return_url'];
else
$return_url = $_SESSION['return_url'] = $a->cmd;
$likebuttons = '';
if($item['id'] == $item['parent']) {
$likebuttons = replace_macros($like_tpl,array(
'$id' => $item['id'],
'$likethis' => t("I like this \x28toggle\x29"),
'$nolike' => t("I don't like this \x28toggle\x29"),
'$wait' => t('Please wait')
));
}
if($item['last-child']) {
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
'$jsreload' => '', // $_SESSION['return_url'],
'$type' => 'net-comment',
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $_SESSION['uid'],
'$mylink' => $a->contact['url'],
'$mytitle' => t('This is you'),
'$myphoto' => $a->contact['thumb'],
'$ww' => $commentww
));
}
$drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
$photo = $item['photo'];
$thumb = $item['thumb'];
// Post was remotely authored.
$diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
$profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
$profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
if(strlen($item['author-link'])) {
$profile_link = $item['author-link'];
if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
$profile_link = $redirect_url;
$sparkle = ' sparkle';
}
elseif(isset($author_contacts[$item['author-link']])) {
$profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
$sparkle = ' sparkle';
}
}
else
$profile_link = $item['url'];
$like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
$dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
$location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
$coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
if($coord) {
if($location)
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
else
$location = '<span class="smalltext">' . $coord . '</span>';
}
$indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
$indent .= ' shiny';
// Build the HTML
$tmp_item = replace_macros($template,array(
'$id' => $item['item_id'],
'$linktitle' => t('View $name\'s profile'),
'$olinktitle' => t('View $owner_name\'s profile'),
'$to' => t('to'),
'$wall' => t('Wall-to-Wall'),
'$vwall' => t('via Wall-To-Wall:'),
'$profile_url' => $profile_link,
'$name' => $profile_name,
'$thumb' => $profile_avatar,
'$osparkle' => $osparkle,
'$sparkle' => $sparkle,
'$title' => $item['title'],
'$body' => smilies(bbcode($item['body'])),
'$ago' => relative_date($item['created']),
'$lock' => $lock,
'$location' => $location,
'$indent' => $indent,
'$owner_url' => $owner_url,
'$owner_photo' => $owner_photo,
'$owner_name' => $owner_name,
'$plink' => get_plink($item),
'$drop' => $drop,
'$vote' => $likebuttons,
'$like' => $like,
'$dislike' => $dislike,
'$comment' => $comment
));
$arr = array('item' => $item, 'output' => $tmp_item);
call_hooks('display_item', $arr);
$o .= $arr['output'];
if(count($r)) {
foreach($r as $rr)
$parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr);
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
$sql_extra
ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
intval(local_user()),
dbesc($parents_str)
);
}
}
// Set this so that the conversation function can find out contact info for our wall-wall items
$a->page_contact = $a->contact;
$mode = (($nouveau) ? 'network-new' : 'network');
$o .= conversation($a,$r,$mode,$update);
if(! $update) {
$o .= paginate($a);
$o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
}
return $o;
}
}

129
mod/notes.php Normal file
View File

@ -0,0 +1,129 @@
<?php
function notes_init(&$a) {
if(! local_user())
return;
$profile = 0;
$which = $a->user['nickname'];
// profile_load($a,$which,$profile);
}
function notes_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
require_once("include/bbcode.php");
require_once('include/security.php');
require_once('include/conversation.php');
require_once('include/acl_selectors.php');
$groups = array();
$o = '';
$remote_contact = false;
$contact_id = $_SESSION['cid'];
$contact = $a->contact;
$is_owner = true;
$o .= '<h3>' . t('Private Notes') . '</h3>';
$commpage = false;
$commvisitor = false;
$celeb = false;
$x = array(
'is_owner' => $is_owner,
'allow_location' => (($a->user['allow_location']) ? true : false),
'default_location' => $a->user['default-location'],
'nickname' => $a->user['nickname'],
'lockstate' => 'lock',
'acl' => '',
'bang' => '',
'visitor' => 'block',
'profile_uid' => local_user(),
'button' => t('Save')
);
$o .= status_editor($a,$x,$a->contact['id']);
// Construct permissions
// default permissions - anonymous user
$sql_extra = " AND `allow_cid` = '<" . $a->contact['id'] . ">' ";
$r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
$sql_extra ",
intval(local_user())
);
if(count($r)) {
$a->set_pager_total($r[0]['total']);
$a->set_pager_itemspage(40);
}
$r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`id` = `item`.`parent` AND `item`.`wall` = 0
$sql_extra
ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
intval(local_user()),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
$parents_arr = array();
$parents_str = '';
if(count($r)) {
foreach($r as $rr)
$parents_arr[] = $rr['item_id'];
$parents_str = implode(', ', $parents_arr);
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`,
`contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND `item`.`parent` IN ( %s )
$sql_extra
ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
intval(local_user()),
dbesc($parents_str)
);
}
$o .= conversation($a,$r,'notes',$update);
$o .= paginate($a);
return $o;
}

View File

@ -65,12 +65,11 @@ function notifications_content(&$a) {
else
$sql_extra = " AND `ignore` = 0 ";
$tpl = load_view_file('view/intros-top.tpl');
$o .= replace_macros($tpl,array(
'$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
'$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
));
$o .= '<h1>' . t('Pending Friend/Connect Notifications') . '</h1>' . "\r\n";
$o .= '<div id="notification-show-hide-wrapper" >';
$o .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ) . '" id="notifications-show-hide-link" >'
. ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
$r = q("SELECT COUNT(*) AS `total` FROM `intro`
@ -90,13 +89,13 @@ function notifications_content(&$a) {
if(($r !== false) && (count($r))) {
$tpl = load_view_file("view/intros.tpl");
$tpl = get_markup_template("intros.tpl");
foreach($r as $rr) {
$friend_selected = (($rr['network'] !== 'stat') ? ' checked="checked" ' : ' disabled ');
$fan_selected = (($rr['network'] === 'stat') ? ' checked="checked" disabled ' : '');
$dfrn_tpl = load_view_file('view/netfriend.tpl');
$dfrn_tpl = get_markup_template('netfriend.tpl');
$knowyou = '';
$dfrn_text = '';
@ -141,24 +140,20 @@ function notifications_content(&$a) {
if ($a->config['register_policy'] == REGISTER_APPROVE &&
$a->config['admin_email'] === $a->user['email']){
$o .= load_view_file('view/registrations-top.tpl');
$o .= '<h1>' . t('User registrations waiting for confirm') . '</h1>' . "\r\n";
$r = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
FROM `register`
LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
if(($r !== false) && (count($r))) {
$tpl = load_view_file("view/registrations.tpl");
$o .= '<ul>';
foreach($r as $rr) {
$o .= "<ul>";
$o .= replace_macros($tpl, array(
'$fullname' => $rr['name'],
'$email' => $rr['email'],
'$approvelink' => "regmod/allow/".$rr['hash'],
'$denylink' => "regmod/deny/".$rr['hash'],
));
$o .= "</ul>";
$o .= '<li>' . sprintf('%s (%s) : ', $rr['name'],$rr['email'])
. '<a href="regmod/allow/' . $rr['hash'] .'">' . t('Approve')
. '</a> - <a href="regmod/deny/' . $rr['hash'] . '">' . t('Deny') . '</a></li>' . "\r\n";
}
$o .= "</ul>";
}
else
notice( t('No registrations.') . EOL);

53
mod/oexchange.php Normal file
View File

@ -0,0 +1,53 @@
<?php
function oexchange_init(&$a) {
if(($a->argc > 1) && ($a->argv[1] === 'xrd')) {
$tpl = get_markup_template('oexchange_xrd.tpl');
$o = replace_macros($tpl, array('$base' => $a->get_baseurl()));
echo $o;
killme();
}
}
function oexchange_content(&$a) {
if(! local_user()) {
$o = login(false);
return $o;
}
if(($a->argc > 1) && $a->argv[1] === 'done') {
notice( t('Post successful.') . EOL);
return;
}
$url = (((x($_GET,'url')) && strlen($_GET['url'])) ? notags(trim($_GET['url'])) : '');
$s = fetch_url($a->get_baseurl() . '/parse_url&url=' . $url);
if(! strlen($s))
return;
require_once('include/html2bbcode.php');
$post = array();
$post['profile_uid'] = local_user();
$post['return'] = '/oexchange/done' ;
$post['body'] = html2bbcode($s);
$post['type'] = 'wall';
$_POST = $post;
require_once('mod/item.php');
item_post($a);
}

View File

@ -70,9 +70,18 @@ function openid_content(&$a) {
$_SESSION['page_flags'] = $r[0]['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
notice( t("Welcome back ") . $r[0]['username'] . EOL);
$a->user = $r[0];
if($a->user['login_date'] === '0000-00-00 00:00:00') {
$_SESSION['return_url'] = 'profile_photo/new';
$a->module = 'profile_photo';
notice( t("Welcome ") . $a->user['username'] . EOL);
notice( t('Please upload a profile photo.') . EOL);
}
else
notice( t("Welcome back ") . $a->user['username'] . EOL);
if(strlen($a->user['timezone'])) {
date_default_timezone_set($a->user['timezone']);
$a->timezone = $a->user['timezone'];

18
mod/opensearch.php Normal file
View File

@ -0,0 +1,18 @@
<?php
function opensearch_content(&$a) {
$tpl = get_markup_template('opensearch.tpl');
header("Content-type: application/opensearchdescription+xml");
$o = replace_macros($tpl, array(
'$baseurl' => $a->get_baseurl(),
'$nodename' => $a->get_hostname(),
));
echo $o;
killme();
}
?>

Some files were not shown because too many files have changed in this diff Show More