Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fs654 committed Dec 1, 2015
1 parent 25420d1 commit f342cb6
Show file tree
Hide file tree
Showing 26 changed files with 1,016 additions and 1,335 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
1.6.0:
- Added match from suggested friends
- Fixed match page loading (No more waiting for page to load all the images)
- Some design changes
- Match section rebuilt
- Fixed quotes in facebook names
- Improved match system
- Fixed tooltips on disabled buttons
- Optimized load on some scripts
- Vcard & Addressbook classes cleanup (removed unused functions)
- Improved page structure for low resolutions, mobiles and tablets
- Mobiles and tablets compatibility

1.5.0:
- Added "remove all pictures" button
- Added "remove all birthdays" button
Expand Down
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-

## Secondary
- Auto sync (cron)
- Fix user home
- Auto sync (cron)
- Add custom fbid

## Ideas
- Search match among suggested friends and try to get profile picture anyway
-
12 changes: 11 additions & 1 deletion app/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ public function getPhotoUrl($size=false) {
return $photo;
}

/**
* Get photo URL
*/
public function getPhoto($size=40) {
$image = new Image($this->vcard->PHOTO);
$image->resize($size);
// return base64_encode($this->vcard->PHOTO);
return 'data:'.$image->mimeType().';base64,'.$image->__toString();
}

/**
* Set FBID
*/
Expand Down Expand Up @@ -301,7 +311,7 @@ public function getFBID() {
* @NoCSRFRequired
*/
public function Jaro($string) {
return JaroWinkler::Jaro($this->getName(), $string);
return JaroWinkler::Jaro(strtolower($this->getName()), $string);
}

}
Expand Down
39 changes: 36 additions & 3 deletions app/contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ public function delFBID($id) {
* @NoAdminRequired
*/
public function getPhoto($id, $size) {
return $this->getContact($id)->getPhotoUrl($size);
$contact = $this->getContact($id);
if(!$contact) {
return false;
}
return $contact->getPhotoUrl($size);
}

/**
Expand All @@ -184,11 +188,12 @@ public function perfectMatch() {
$edited=0;
// List contacts by Name
foreach ($contacts as $contact) {
$contactsName[$contact->getName()]=$contact;
$contactsName[strtolower($contact->getName())]=$contact;
}
$friends = $this->fbController->getfriends();
// Parse all friends
foreach($friends as $fbid => $friend) {
$friend = strtolower($friend);
// Match exact name
if(isset($contactsName[$friend])) {
if($contactsName[$friend]->getFBID() != $fbid) {
Expand Down Expand Up @@ -222,7 +227,7 @@ public function approxMatch() {
// Only if no FBID set (We do not want to override previous macthes)
if(!in_array($contact->getFBID(), $FBIDs)) {
foreach($friends as $fbid => $friend) {
$jaro = $contact->Jaro($friend)*100;
$jaro = $contact->Jaro(strtolower($friend))*100;
// Only best matches
if($jaro > App::JAROWINKLERMAX && !in_array($fbid, $FBIDs)) {
// Store as integer and big enough so that no results will overwrite another
Expand All @@ -247,4 +252,32 @@ public function approxMatch() {

return $edited;
}

/**
* Match exacts name but use the "People You May Know" list
* @NoAdminRequired
*/
public function suggestMatch() {
$contacts = $this->getList();
$contactsName = Array();
$edited=0;
// List contacts by Name
// Use strtolower to avoid errors based on typo
foreach ($contacts as $contact) {
$contactsName[strtolower($contact->getName())]=$contact;
}
$friends = $this->fbController->getsuggestedFriends();
// Parse all friends
foreach($friends as $fbid => $friend) {
$friend = strtolower($friend);
// Match exact name
if(isset($contactsName[$friend])) {
if($contactsName[$friend]->getFBID() != $fbid) {
$edited++;
$contactsName[$friend]->setFBID($fbid);
}
}
}
return $edited;
}
}
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<description>A Facebook info sync for owncloud contacts</description>
<licence>AGPL</licence>
<author>NOIJN</author>
<version>1.5.0</version>
<version>1.6.0</version>
<namespace>FbSync</namespace>
<category>other</category>
<require>8</require>
Expand Down
3 changes: 2 additions & 1 deletion appinfo/jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private function updateFriends() {
*/
public function run($arguments) {
if( (\OCP\App::isEnabled('contacts') || \OCP\App::isEnabled('contactsplus') ) && \OCP\App::isEnabled('fbsync') ) {
$this->updatePhotos();
$cache = \OC::$server->getCache();
$cache->set("test", "test");
} else {
\OCP\Util::writeLog('fbsync', "App not enabled", \OCP\Util::INFO);
return;
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
['name' => 'facebook#islogged', 'url' => '/facebook/islogged', 'verb' => 'GET'],
['name' => 'contacts#perfectMatch', 'url' => '/perfectmatch', 'verb' => 'GET'],
['name' => 'contacts#approxMatch', 'url' => '/approxmatch', 'verb' => 'GET'],
['name' => 'contacts#suggestMatch', 'url' => '/suggestmatch', 'verb' => 'GET'],
['name' => 'contacts#updateFBID', 'url' => '/contact/fbid/{id}', 'verb' => 'POST'],
['name' => 'contacts#setPhoto', 'url' => '/setphoto/{id}', 'verb' => 'GET'],
['name' => 'contacts#setBirthday', 'url' => '/setbday/{id}', 'verb' => 'GET'],
Expand Down
25 changes: 17 additions & 8 deletions controller/contactscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,44 @@ public function perfectMatch(){
* @NoCSRFRequired
* @return JSONResponse
*/
public function setPhoto($id){
return new JSONResponse($this->app->setPhoto($id));
public function approxMatch(){
return new JSONResponse($this->app->approxMatch());
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @return JSONResponse
*/
public function setBirthday($id){
return new JSONResponse($this->app->setBirthday($id));
public function suggestMatch(){
return new JSONResponse($this->app->suggestMatch());
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @return JSONResponse
*/
public function getPhoto($id, $size){
return new JSONResponse($this->app->getPhoto($id, $size));
public function setPhoto($id){
return new JSONResponse($this->app->setPhoto($id));
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @return JSONResponse
*/
public function approxMatch(){
return new JSONResponse($this->app->approxMatch());
public function setBirthday($id){
return new JSONResponse($this->app->setBirthday($id));
}

/**
* @NoAdminRequired
* @NoCSRFRequired
* @return JSONResponse
*/
public function getPhoto($id, $size){
return new JSONResponse($this->app->getPhoto($id, $size));
}

/**
Expand Down
62 changes: 56 additions & 6 deletions controller/facebookcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private function fblogin($user, $pass) {
}

/**
* Try to log into Facebook and return results and header (for debug)
* Retrieve the facebook friends list
* @var bool Ignore cache and force reload
* @return Array Friends with FBID and Names
*/
Expand Down Expand Up @@ -166,7 +166,7 @@ public function getfriends($ignoreCache=false) {
return false;
}
$main = $html->find('div[id=friends_center_main]', 0);
if (empty($main)) {
if (is_null($main)) {
return false;
}

Expand All @@ -177,29 +177,79 @@ public function getfriends($ignoreCache=false) {
$re = "/uid=([0-9]{1,20})/";
preg_match($re, $friend->href, $matches);
// $friends[fbid]=name
$friends[(int)$matches[1]]=$friend->innertext;
$friends[(int)$matches[1]]=html_entity_decode($friend->innertext, ENT_QUOTES);
}
$page++;

$getdata = $this->dorequest($url.$page);
$html = str_get_html($getdata[1]);
$main = $html->find('div[id=friends_center_main]', 0);
}
\OCP\Util::writeLog('fbsync', count($friends)." friends cached", \OCP\Util::INFO);

// Alphabetical order
asort($friends);

// To cache if defined
if($this->cache)
if($this->cache) {
$this->cache->set($this->cacheKey, json_encode($friends));
\OCP\Util::writeLog('fbsync', count($friends)." friends cached", \OCP\Util::INFO);
}

return $friends;

} else {
return false;
}
}

/**
* Retrieve the 2 first pages of your friends suggestions (24*2 peoples)
* Increasing to 3 or more reduce the suggestion relevance
* @return Array Friends with FBID and Names
*/
public function getsuggestedFriends() {

if($this->islogged()) {

$url = 'https://m.facebook.com/friends/center/suggestions/';
$friends=Array();
$friendLinkFilter = "[href^=/friends/hovercard]";

$getdata = $this->dorequest($url.$page);
$html = str_get_html($getdata[1]);
if (empty($html)) {
return false;
}
$main = $html->find('div[id=friends_center_main]', 0);
if (is_null($main)) {
return false;
}

// 2 first pages
for($count=0; $count < 2; $count++) {
foreach($main->find('a'.$friendLinkFilter) as $friend) {
// FB ID
$re = "/uid=([0-9]{1,20})/";
preg_match($re, $friend->href, $matches);
// $friends[fbid]=name
$friends[(int)$matches[1]]=html_entity_decode($friend->innertext, ENT_QUOTES);
}
// Let's get the next page link
$re = "/<a href=\"(\\/friends\\/center\\/suggestions[0-9a-z\\/\\?=&;_]{0,60})#friends_center_main\">/mi";
preg_match_all($re, html_entity_decode($main->innertext, ENT_QUOTES), $matches);
$url = $matches[1][0];
$getdata = $this->dorequest('https://m.facebook.com'.$url);
$html = str_get_html($getdata[1]);
$main = $html->find('div[id=friends_center_main]', 0);
}

// No sort because we want to keep the suggestion order
return $friends;

} else {
return false;
}
}


/**
Expand Down Expand Up @@ -244,7 +294,7 @@ public function getBirthday($fbid) {
$getdata = $this->dorequest("https://m.facebook.com/profile.php?v=info&id=$fbid");

$html = str_get_html($getdata[1]);
if (empty($html)) {
if (is_null($html)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function index() {
*/
private function error($error) {
$params = ['error' => $error];
return new TemplateResponse('fbsync', 'error', $params); // templates/login.php
return new TemplateResponse('fbsync', 'error', $params); // templates/error.php
}

/**
Expand Down
Loading

0 comments on commit f342cb6

Please sign in to comment.