本文整理汇总了PHP中Gdn::discussionModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn::discussionModel方法的具体用法?PHP Gdn::discussionModel怎么用?PHP Gdn::discussionModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn
的用法示例。
在下文中一共展示了Gdn::discussionModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: discussionModel_afterSaveDiscussion_handler
/**
* Check requirements and publish new discussion to Twitter.
*
* @param object $sender DiscussionModel.
* @param array $args EventArguments.
* @return void.
* @package TwitterBot
* @since 0.1
*/
public function discussionModel_afterSaveDiscussion_handler($sender, $args)
{
$discussion = $args['Discussion'];
// Exit if this discussion has already been twittered.
if ($discussion->Attributes['TwitterBot'] == true) {
return;
}
// Exit if discussions from this category shouldn't be twittered
if (!in_array($discussion->CategoryID, Gdn::config('TwitterBot.CategoryIDs'))) {
return;
}
// Exit if the current user hasn't the permission to twitter
$roleIds = array_keys(Gdn::userModel()->getRoles($discussion->InsertUserID));
if (array_intersect($roles, Gdn::config('TwitterBot.RoleIDs'))) {
return;
}
// Exit if only announcements shall be twittered and this is no announcements
if (Gdn::config('TwitterBot.AnnouncementsOnly') && !$discussion->Announce) {
return;
}
// Exit if checkbox is shown and not ticked
if (Gdn::config('TwitterBot.ShowCheckbox') && !$args['FormPostValues']['TwitterBot']) {
return;
}
// Exit if plugin is not configured
$consumerKey = Gdn::config('TwitterBot.ConsumerKey');
$consumerSecret = Gdn::config('TwitterBot.ConsumerSecret');
$oAuthAccessToken = Gdn::config('TwitterBot.OAuthAccessToken');
$oAuthAccessTokenSecret = Gdn::config('TwitterBot.OAuthAccessTokenSecret');
if (!$consumerKey || !$consumerSecret || !$oAuthAccessToken || !$oAuthAccessTokenSecret) {
return;
}
$title = $discussion->Name;
$body = Gdn_Format::to($discussion->Body, $discussion->Format);
$author = $discussion->InsertName;
$date = $discussion->DateInserted;
$category = $discussion->Category;
$url = $discussion->Url;
$tweet = '"' . $title . '" by ' . $author;
require_once __DIR__ . '/library/vendors/twitter-api-php/TwitterAPIExchange.php';
$settings = array('oauth_access_token' => $oAuthAccessToken, 'oauth_access_token_secret' => $oAuthAccessTokenSecret, 'consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret);
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->buildOauth('https://api.twitter.com/1.1/statuses/update.json', 'POST')->setPostfields(array('status' => $tweet))->performRequest();
$response = json_decode($response, true);
if (isset($response['created_at'])) {
// Gdn::controller()->informMessage('This discussion has been published on Twitter', 'Dismissable');
Gdn::discussionModel()->saveToSerializedColumn('Attributes', $discussion->DiscussionID, 'TwitterBot', true);
}
}