diff --git a/include/config/config.xml b/include/config/config.xml
index abb5dfafa..1823b6f66 100755
--- a/include/config/config.xml
+++ b/include/config/config.xml
@@ -52,21 +52,34 @@
- ***REMOVED***
- ***REMOVED***
-
-
- _KEY_
- _KEY_
-
-
- _KEY_
- _KEY_
-
-
- _KEY_
- _KEY_
-
+ ***REMOVED***
+ ***REMOVED***
+
+
+ _KEY_
+ _KEY_
+
+
+ _KEY_
+ _KEY_
+
+
+ _KEY_
+ _KEY_
+
+
+ user_status,publish_stream
+
+ I just ordered awsome food!
+ CrunchButton
+ Curated Online Food Ordering.
+ http://_DOMAIN_/
+ Some awesome call to action message here!
+ http://_DOMAIN_/assets/images/appicon.png
+ CrunchButton
+ http://_DOMAIN_/
+
+
800-242-1444
diff --git a/include/controllers/default/crunchbutton/api/facebook/index.php b/include/controllers/default/crunchbutton/api/facebook/index.php
new file mode 100644
index 000000000..8a1a4465e
--- /dev/null
+++ b/include/controllers/default/crunchbutton/api/facebook/index.php
@@ -0,0 +1,70 @@
+method()) {
+ case 'get':
+
+ switch ( c::getPagePiece( 2 ) ) {
+
+ case 'publish_permission':
+
+ $facebook = new Crunchbutton_Facebook();
+
+ if( $facebook->hasPublishPermission() ){
+ echo json_encode(['success' => 'has permission']);
+
+ } else {
+ echo json_encode(['error' => 'not allowed', 'url' => $facebook->getLoginURL() ]);
+ }
+
+ break;
+ // publish
+ case 'publish':
+
+ $facebook = new Crunchbutton_Facebook();
+
+ if( $facebook->hasPublishPermission() ){
+
+ switch ( c::getPagePiece( 3 ) ) {
+
+ // publish/order/x
+ case 'order':
+
+ $order_id = c::getPagePiece( 4 );
+
+ if( $order_id ){
+
+ $facebook->postOrderStatus( $order_id );
+ echo json_encode(['success' => 'status posted']);
+
+ } else {
+
+ echo json_encode(['error' => 'invalid resource']);
+ }
+
+ break;
+
+ default:
+ echo json_encode(['error' => 'invalid resource']);
+ break;
+ }
+
+ } else {
+ echo json_encode(['error' => 'not allowed', 'url' => $facebook->getLoginURL() ]);
+ }
+
+ break;
+ }
+
+ break;
+
+ default:
+ echo json_encode(['error' => 'invalid resource']);
+ break;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/include/library/Crunchbutton/Facebook.php b/include/library/Crunchbutton/Facebook.php
new file mode 100644
index 000000000..ff8358ede
--- /dev/null
+++ b/include/library/Crunchbutton/Facebook.php
@@ -0,0 +1,128 @@
+restaurant();
+
+ $restaurantName = $restaurant->name;
+ $restaurantURL = 'http://'.$_SERVER['__HTTP_HOST']. '/food-delivery/' . $restaurant->permalink;
+ $restaurantDescription = $restaurant->short_description;
+ if( $restaurant->thumb() ){
+ $restaurantImage = $restaurant->thumb()->getFileName();
+ }
+
+ $status = array(
+ 'name' => $restaurantName,
+ 'caption' => $restaurantDescription,
+ 'link' => $restaurantURL,
+ 'picture' => $restaurantImage
+ );
+ return $this->postStatus( $status );
+ }
+
+ public function facebook(){
+ if( !$this->_facebook ){
+ $this->_facebook = new Cana_Facebook( [
+ 'appId' => Cana::config()->facebook->app,
+ 'secret' => Cana::config()->facebook->secret
+ ] );
+ }
+ return $this->_facebook;
+ }
+
+ public function hasPublishPermission(){
+ return $this->hasPermission( 'publish_actions' );
+ }
+
+ public function postStatus( $status ){
+
+ if( $this->hasPublishPermission() ){
+
+ $status[ 'message' ] = ( $status[ 'message' ] && $status[ 'message' ] != '' ) ? $status[ 'message' ] : c::config()->facebook->default->poststatus->message;
+ $status[ 'name' ] = ( $status[ 'name' ] && $status[ 'name' ] != '' ) ? $status[ 'name' ] : c::config()->facebook->default->poststatus->name;
+ $status[ 'caption' ] = ( $status[ 'caption' ] && $status[ 'caption' ] != '' ) ? $status[ 'caption' ] : c::config()->facebook->default->poststatus->caption;
+ $status[ 'linklink' ] = ( $status[ 'link' ] && $status[ 'link' ] != '' ) ? $status[ 'link' ] : c::config()->facebook->default->poststatus->link;
+ $status[ 'description' ] = ( $status[ 'description' ] && $status[ 'description' ] != '' ) ? $status[ 'description' ] : c::config()->facebook->default->poststatus->description;
+ $status[ 'picture' ] = ( $status[ 'picture' ] && $status[ 'picture' ] != '' ) ? $status[ 'picture' ] : c::config()->facebook->default->poststatus->picture;
+ $status[ 'site_name' ] = ( $status[ 'site_name' ] && $status[ 'site_name' ] != '' ) ? $status[ 'site_name' ] : c::config()->facebook->default->poststatus->site_name;
+ $status[ 'site_url' ] = ( $status[ 'site_url' ] && $status[ 'site_url' ] != '' ) ? $status[ 'site_url' ] : c::config()->facebook->default->poststatus->site_url;
+
+ $mural = array(
+ 'message' => $status[ 'message' ],
+ 'name' => $status[ 'name' ],
+ 'caption' => $status[ 'caption' ],
+ 'link' => $status[ 'link' ],
+ 'description' => $status[ 'description' ],
+ 'picture' =>$status[ 'picture' ],
+ 'actions' => array(
+ array(
+ 'name' => $status[ 'site_name' ],
+ 'link' => $status[ 'site_url' ],
+ )
+ )
+ );
+
+ try {
+ $endpoint = $this->userID() . '/feed';
+ $this->facebook()->api( $endpoint, 'POST', $mural );
+ return true;
+ } catch ( Cana_Facebook_Exception $e ) {
+ $error = [
+ 'type' => 'facebook',
+ 'level' => 'error',
+ 'params' => $mural,
+ ];
+ Crunchbutton_Log::error( $error );
+ return false;
+ }
+ }
+ }
+
+ public function hasPermission( $permission ){
+ if( isset( $this->permissions()[ 'data' ] ) && isset( $this->permissions()[ 'data' ][0][ $permission ] ) ){
+ return true;
+ }
+ return false;
+ }
+
+ public function user(){
+ if( !$this->_user ){
+ $this->_user = $this->facebook()->getUser();
+ if ( $this->_user ) {
+ try {
+ $user = $this->facebook()->api( '/' . $this->_user );
+ } catch ( Cana_Facebook_Exception $e ) {
+ $user = null;
+ }
+ $this->_user = $user;
+ }
+ }
+ return $this->_user;
+ }
+
+ public function userID(){
+ return $this->user()[ 'id' ];
+ }
+
+ public function getLoginURL(){
+ $params = array(
+ 'scope' => c::config()->facebook->default->scope,
+ );
+ return $this->facebook()->getLoginURL( $params );
+ }
+
+ public function permissions(){
+ if( !$this->_permissions ){
+ $this->_permissions = $this->facebook()->api( '/me/permissions' );
+ }
+ return $this->_permissions;
+ }
+
+}
\ No newline at end of file