/**
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_facebook_create($Sender, $RecordType, $ID)
 {
     if (!$this->socialReactions()) {
         throw permissionException();
     }
     $Row = getRecord($RecordType, $ID, true);
     if ($Row) {
         $Message = sliceParagraph(Gdn_Format::plainText($Row['Body'], $Row['Format']), 160);
         if ($this->accessToken() && $Sender->Request->isPostBack()) {
             $R = $this->api('/me/feed', array('link' => $Row['ShareUrl'], 'message' => $Message));
             $Sender->setJson('R', $R);
             $Sender->informMessage(t('Thanks for sharing!'));
         } else {
             $Get = array('app_id' => c('Plugins.Facebook.ApplicationID'), 'link' => $Row['ShareUrl'], 'name' => Gdn_Format::plainText($Row['Name'], 'Text'), 'description' => $Message, 'redirect_uri' => url('/post/shared/facebook', true));
             $Url = 'http://www.facebook.com/dialog/feed?' . http_build_query($Get);
             redirect($Url);
         }
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }
 /**
  *
  *
  * @param PostController $Sender
  * @param type $RecordType
  * @param type $ID
  * @throws type
  */
 public function postController_twitter_create($Sender, $RecordType, $ID)
 {
     if (!$this->socialReactions()) {
         throw permissionException();
     }
     //      if (!Gdn::request()->isPostBack())
     //         throw permissionException('Javascript');
     $Row = GetRecord($RecordType, $ID, true);
     if ($Row) {
         // Grab the tweet message.
         switch (strtolower($RecordType)) {
             case 'discussion':
                 $Message = Gdn_Format::plainText($Row['Name'], 'Text');
                 break;
             case 'comment':
             default:
                 $Message = Gdn_Format::plainText($Row['Body'], $Row['Format']);
         }
         $Elips = '...';
         $Message = preg_replace('`\\s+`', ' ', $Message);
         //         if (function_exists('normalizer_is_normalized')) {
         //            // Slice the string to 119 characters (21 reservered for the url.
         //            if (!normalizer_is_normalized($Message))
         //               $Message = Normalizer::normalize($Message, Normalizer::FORM_D);
         //            $Elips = Normalizer::normalize($Elips, Normalizer::FORM_D);
         //         }
         $Max = 140;
         $LinkLen = 22;
         $Max -= $LinkLen;
         $Message = SliceParagraph($Message, $Max);
         if (strlen($Message) > $Max) {
             $Message = substr($Message, 0, $Max - strlen($Elips)) . $Elips;
         }
         //         echo $Message.strlen($Message);
         if ($this->accessToken()) {
             Gdn::controller()->setData('Message', $Message);
             $Message .= ' ' . $Row['ShareUrl'];
             $R = $this->api('/statuses/update.json', array('status' => $Message), 'POST');
             $Sender->setJson('R', $R);
             $Sender->informMessage(t('Thanks for sharing!'));
         } else {
             $Get = array('text' => $Message, 'url' => $Row['ShareUrl']);
             $Url = "https://twitter.com/share?" . http_build_query($Get);
             redirect($Url);
         }
     }
     $Sender->render('Blank', 'Utility', 'Dashboard');
 }