Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Procedural reimplementation #1

Open
wants to merge 3 commits into
from

Conversation

Projects
None yet
1 participant

mostly, i wrote this because my g+ feed was filling up with updates
about this project, i wanted to see what the code looked like. then
i had an unquashable urge to rewrite it. i find OO PHP to be
irritatingly verbose, and it pains me that people use it so much.
in order to keep existing users happy, i also modified the existing
OO code to wrap this procedural codebase. this follows the SPOT
(single point of truth) rule, which also provides for
maintaintability going forward.

requires:

  • php's curl and json extensions enabled
  • write access to a cache directory (if using cache)

changes:

  • better inline and overall documentation
  • upgrade to byte and screen-efficient '#'-based comments ;)
  • cachefile is now based upon the actual google+ ID you grabbed
    data from, which fixes a bug in the original code and enables
    the caching of data from multiple google+ accounts
  • should now be cross platform in that windows-style directory
    separators are honoured.
  • removed expectation of user intelligence (re: remembering to
    include a trailing '/' on will fail) ... ie: bug
  • slight improvement in codepath for cache (time calculation is
    avoided until certainly required)
  • now checks that the length of a supplied g+ id is sane before
    wasting time attempting to scrape a page (eg: if '0' supplied)
  • fixes possible security holes whereby input from the cache
    file is trusted. now validates and performs tag stripping
    through an internal function __gc_fix_tr() that is also used
    before storing to cache and returning non-cached values.
    (also provides safety against weird HTML tidbits when the
    scraper inevitably breaks)
  • removed acceptance of underscores in the number of circles
  • url is no longer cached to disk (cache size reduced)
  • added debugging function and messages
  • changed default cache dir to '.gc_cache' since someone out
    there is going to install this in a web-accessible dir,
    many http servers include or encourage disallowing dotfiles,
    and cache is collision-probable. (might fall back to gc_cache
    on windows - untested ;)
  • code now automatically attempts to create the cache dir if
    it doesn't exist
  • added some configuration options in the source

whinges:

  • 'count' is a really bad choice of identifier since it is far
    too generic and thus ambiguous. however, it has been left in
    place to preserve backwards compatibility.

procedural usage (OO usage remains unchanged):
require_once('gc.php');
$googleplusid = '123456789012345678901';
$info = google_plus_info($googleplusid);
print $info['name'] . ' has ' . $info['count'] . ' followers.';

globalcitizen added some commits Jul 21, 2011

@globalcitizen globalcitizen Procedural re-implementation.
mostly, i wrote this because my g+ feed was filling up with updates
about this project, i wanted to see what the code looked like. then
i had an unquashable urge to rewrite it. i find OO PHP to be
irritatingly verbose, and it pains me that people use it so much.
in order to keep existing users happy, i also modified the existing
OO code to wrap this procedural codebase. this follows the SPOT
(single point of truth) rule, which also provides for
maintaintability going forward.

requires:
 - php's curl and json extensions enabled
 - write access to a cache directory (if using cache)

changes:
 - better inline and overall documentation
 - upgrade to byte and screen-efficient '#'-based comments ;)
 - cachefile is now based upon the actual google+ ID you grabbed
   data from, which fixes a bug in the original code and enables
   the caching of data from multiple google+ accounts
 - should now be cross platform in that windows-style directory
   separators are honoured.
 - removed expectation of user intelligence (re: remembering to
   include a trailing '/' on will fail) ... ie: bug
 - slight improvement in codepath for cache (time calculation is
   avoided until certainly required)
 - now checks that the length of a supplied g+ id is sane before
   wasting time attempting to scrape a page (eg: if '0' supplied)
 - fixes possible security holes whereby input from the cache
   file is trusted. now validates and performs tag stripping
   through an internal function __gc_fix_tr() that is also used
   before storing to cache and returning non-cached values.
   (also provides safety against weird HTML tidbits when the
   scraper inevitably breaks)
 - removed acceptance of underscores in the number of circles
 - url is no longer cached to disk (cache size reduced)
 - added debugging function and messages
 - changed default cache dir to '.gc_cache' since someone out
   there is going to install this in a web-accessible dir,
   many http servers include or encourage disallowing dotfiles,
   and cache is collision-probable. (might fall back to gc_cache
   on windows - untested ;)
 - code now automatically attempts to create the cache dir if
   it doesn't exist
 - added some configuration options in the source

whinges:
 - 'count' is a really bad choice of identifier since it is far
   too generic and thus ambiguous. however, it has been left in
   place to preserve backwards compatibility.

procedural usage (OO usage remains unchanged):
  require_once('gc.php');
  $googleplusid = '123456789012345678901';
  $info = google_plus_info($googleplusid);
  print $info['name'] . ' has ' . $info['count'] . ' followers.';
727b65b
@globalcitizen globalcitizen Modify to wrap gc.php, a newer procedural implementation with many bu…
…gfixes and improvements.
0ab9ec0
@globalcitizen globalcitizen Update documentation. e3b54f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment