Skip to content

Commit

Permalink
FacebookPublicUpdater did not parse a count of 'one'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Cole committed Apr 29, 2015
1 parent de9575f commit 466edf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/data-sources/FacebookPublicUpdater.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@ public function get_total() {
// Safety check
if (!is_string($this->updater->data)) return 0;

// Strings to search for in the result
// If there is only 1 share
if (strpos($this->updater->data, '<span id="u_0_2"><span>One person likes this.</span>') !== false) return 1;

// Strings to search for in the result if there is more than one share
$wrapper_start = '<span id="u_0_2"><span>';
$wrapper_end = ' people like this.</span>';

$start = strpos($this->updater->data, $wrapper_start);
$end = strpos($this->updater->data, $wrapper_end, $start);

// Safety check
// If the data was not found in the result
if ($start === false || $end === false) return 0;

// Perform substring matching
$match = substr($this->updater->data, $start+strlen($wrapper_start), $end - $start - strlen($wrapper_start));

// Safety check
// If the substring task failed
if ($match === false) return 0;

// Convert the string with commas to an integer
Expand Down
1 change: 1 addition & 0 deletions src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ This plugin was created by Ben Cole, as a member of the Chapman University web m

= 1.5.2 =
* Fixed an issue where Facebook stats were not collected for some websites in languages other than English
* Fixed an issue where a Facebook count of one was reported as zero

= 1.5.1 =
* Updated the Facebook Graph API to version 2.3 (latest)
Expand Down

0 comments on commit 466edf8

Please sign in to comment.