Last active
October 10, 2015 13:28
-
-
Save davb/3697459 to your computer and use it in GitHub Desktop.
A skeleton implementation of the FeeligoApi class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Feeligo_Mysite_Api | |
* | |
* this file provides a skeleton implementation of the Api adaptation class. | |
*/ | |
/** | |
* Feeligo configuration settings | |
*/ | |
define("FLG__community_name", "YOUR COMMUNITY'S NAME"); | |
define("FLG__community_api_key", "YOUR COMMUNITY API KEY"); | |
define("FLG__community_secret", "YOUR COMMUNITY SECRET KEY"); | |
/** | |
* enable development mode | |
* WARNING: remove this for production use! | |
*/ | |
define('FLG_ENV', 'development'); | |
/** | |
* require the SDK's built-in FeeligoApi class | |
* | |
* don't forget to modify the path according to your directory structure | |
*/ | |
require_once(str_replace('//','/',dirname(__FILE__).'/').'sdk/lib/api.php'); | |
class Feeligo_Mysite_Api extends FeeligoApi { | |
/** | |
* tells whether a viewer is available in the current context | |
* the viewer is the User which is currently logged in, when applicable | |
* | |
* @return bool | |
*/ | |
public function has_viewer() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* Accessor for the viewer | |
* | |
* @return FeeligoUserAdapter | |
*/ | |
public function viewer() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* tells whether a subject is available in the current context | |
* the subject is the user which is currently being viewed, when applicable | |
* | |
* @return bool | |
*/ | |
public function has_subject() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* Accessor for the subject | |
* | |
* @return FeeligoUserAdapter | |
*/ | |
public function subject() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* Accessor for the website users | |
* | |
* @return FeeligoUsersSelector | |
*/ | |
public function users() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* Accessor for user Actions | |
* | |
* @return FeeligoActionsSelector | |
*/ | |
public function actions() { | |
//TODO: implement this | |
throw new Exception('to be implemented'); | |
} | |
/** | |
* Singleton pattern: gets or creates a single instance of this class | |
* | |
* @return Feeligo_Mysite_Api | |
*/ | |
public static function getInstance() { | |
if( is_null(self::$_instance) ) { | |
self::$_instance = new self(); | |
} | |
return self::$_instance; | |
} | |
/** | |
* Shorthand for getInstance, allows to call Feeligo_Mysite_Api::_() | |
* | |
* @return Feeligo_Mysite_Api | |
*/ | |
public static function _() { | |
return self::getInstance(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* sample implementation of has_viewer and viewer methods | |
* makes the following assumptions: | |
* - $_GET['page'] equals 'users' on all user profile pages | |
* - $_GET['user_id'] gives the ID of the user being shown | |
* - MySQL is used as the RDBMS | |
*/ | |
/** | |
* tells whether a viewer is available in the current context | |
* the viewer is the User which is currently logged in, when applicable | |
* | |
* @return bool | |
*/ | |
public function has_subject() { | |
return $this->subject() !== null; | |
} | |
/** | |
* Accessor for the viewer | |
* | |
* @return bool | |
*/ | |
public function subject() { | |
// check the session cookie | |
if (isset($_GET['page']) && $_GET['page'] == 'users' && isset($_GET['user_id'])) { | |
// fetch a row from the database matching id=$_GET['user_id'] | |
$sql = "SELECT * FROM `users` WHERE id=".mysql_real_escape_string($_GET['user_id'])." LIMIT 1"; | |
$row = mysql_fetch_array(mysql_query($sql)); | |
// return a FeeligoUserAdapter for the row | |
return $row ? new Feeligo_Mysite_UserAdapter($row) : null; | |
} | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
[...] | |
// require the source file containing the implementation of the Feeligo_Mysite_Users_Selector class | |
require_once(str_replace('//','/',dirname(__FILE__).'/').'mysite_users_selector.php'); | |
class Feeligo_Mysite_Api extends FeeligoApi { | |
[...] | |
/** | |
* Accessor for the website users | |
* | |
* @return FeeligoUsersSelector | |
*/ | |
public function users() { | |
return new Feeligo_Mysite_Users_Selector(); | |
} | |
[...] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* sample implementation of has_viewer and viewer methods | |
* makes the following assumptions: | |
* - session information is stored the PHP session cookie | |
* - MySQL is used as the RDBMS | |
*/ | |
/** | |
* tells whether a viewer is available in the current context | |
* the viewer is the User which is currently logged in, when applicable | |
* | |
* @return bool | |
*/ | |
public function has_viewer() { | |
return $this->viewer() !== null; | |
} | |
/** | |
* Accessor for the viewer | |
* | |
* @return bool | |
*/ | |
public function viewer() { | |
// check the session cookie | |
if (isset($_SESSION['current_user_id'])) { | |
// fetch a row from the database matching id=current_user_id | |
$sql = "SELECT * FROM `users` WHERE id=".$_SESSION['current_user_id']." LIMIT 1"; | |
$row = mysql_fetch_array(mysql_query($sql)); | |
// return a FeeligoUserAdapter for the row | |
return $row ? new Feeligo_Mysite_UserAdapter($row) : null; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment