本文整理汇总了PHP中content::get_tweets方法的典型用法代码示例。如果您正苦于以下问题:PHP content::get_tweets方法的具体用法?PHP content::get_tweets怎么用?PHP content::get_tweets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类content
的用法示例。
在下文中一共展示了content::get_tweets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_tweets
/**
* gets tweets from the db for a given campaign
* @param string $campaign_hash the hash value for the campaign
*/
function get_tweets($campaign_hash)
{
$params = array('total' => 'int', 'page' => 'int', 'lang' => array('regex', '/^[a-z]{2}$/'), 'screen_name' => 'string', 'since' => 'datetime', 'before' => 'datetime', 'reply' => array('regex', '/^(show|hide|only)$/'), 'retweet' => array('regex', '/^(show|hide|only)$/'), 'approved' => array('regex', '/^(yes|no)$/'), 'format' => array('regex', '/^(json|html)$/'));
// normalise requested filter parameters to safe values - prevents attacks from input
foreach ($params as $param => $constraint) {
$extra = null;
if (is_array($constraint)) {
$extra = $constraint[1];
$constraint = $constraint[0];
}
switch ($constraint) {
case 'int':
${$param} = !empty($_REQUEST[$param]) && intval($_REQUEST[$param]) ? intval($_REQUEST[$param]) : null;
break;
case 'regex':
${$param} = !empty($_REQUEST[$param]) && preg_match($extra, $_REQUEST[$param]) ? $_REQUEST[$param] : null;
break;
case 'string':
${$param} = !empty($_REQUEST[$param]) ? $_REQUEST[$param] : null;
break;
case 'bool':
${$param} = isset($_REQUEST[$param]);
break;
case 'datetime':
${$param} = !empty($_REQUEST[$param]) && strtotime($_REQUEST[$param]) > -1 ? strtotime($_REQUEST[$param]) : null;
// the comparison with -1 instead of false is to allow compatibility with php 5.1.0
break;
}
}
$tweets = content::get_tweets($campaign_hash, $total, $page, $lang, $screen_name, $since, $before, $reply, $retweet, $approved);
// throw an error if there are no tweets for some reason
if (!is_array($tweets)) {
$headers = array('content-type' => 'text/plain', 'status' => 400);
view::make('errors/plain_error')->with('message', $tweets)->headers($headers)->render(true, true);
}
switch ($format) {
case 'html':
// todo: pull in templates here that each tweet would be wrapped in - this is unspecced right now
break;
default:
// json
$headers = array('content-type' => 'application/json');
view::make('output/json')->with('tweets', json_encode($tweets))->headers($headers)->render(true, true);
break;
}
}
示例2: admin
//.........这里部分代码省略.........
$campaign = content::get_campaign($params[2]);
$campaign_html = '';
foreach ($campaign as $q) {
$campaign_html .= $q['html'];
}
// build up the extra elements specifically for the campaign details - not the queries
$campaign_details = \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/label_wrap.php', array('label' => 'Campaign Name', 'element' => \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_text.php', array('value' => "value=\"{$campaign[0]['name']}\"", 'placeholder' => "placeholder=\"campaign name\"", 'name' => 'name'))));
$campaign_details .= \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/label_wrap.php', array('label' => 'URL', 'element' => \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_text.php', array('value' => "value=\"{$campaign[0]['url']}\"", 'placeholder' => "placeholder=\"campaign url\"", 'name' => 'url'))));
$campaign_details .= \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/label_wrap.php', array('label' => 'Start', 'element' => \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_date.php', array('value' => "value=\"{$campaign[0]['start']}\"", 'placeholder' => "placeholder=\"start date\"", 'name' => 'start'))));
$campaign_details .= \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/label_wrap.php', array('label' => 'End', 'element' => \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_date.php', array('value' => "value=\"{$campaign[0]['end']}\"", 'placeholder' => "placeholder=\"end date\"", 'name' => 'end'))));
$deactivated = array();
foreach (array('yes', 'no') as $d) {
$deactivated[] = \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_option.php', array('selected' => $d == $campaign[0]['force_deactivated'] ? 'selected="selected"' : '', 'value' => $d, 'display_value' => $d));
}
$campaign_details .= \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/label_wrap.php', array('label' => 'Force Deactivated?', 'element' => \helpers\html\html::load_snippet(MAVERICK_BASEDIR . 'vendor/helpers/html/snippets/input_select.php', array('values' => implode('', $deactivated), 'name' => 'force_deactivated'))));
$view_params = array('campaign_fields' => $campaign_html, 'campaign_buttons' => $campaign_buttons, 'campaign_details' => $campaign_details, 'scripts' => array('/js/campaigns.js' => 10, 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js' => 5));
if ($errors) {
$view_params['errors'] = $errors;
}
$this->load_view('campaign_edit', $view_params);
} else {
return false;
}
// just bomb out if people are fucking with the URL
break;
case 'new_campaign':
$campaign_id = content::create_new_campaign();
view::redirect('/' . $this->app->get_config('tweed.admin_path') . "/campaign/edit/{$campaign_id}");
break;
case 'deactivate':
case 'reactivate':
// just bomb out if people are fucking with the URL
if (empty($params[2]) || !intval($params[2])) {
return false;
}
content::set_campaign_status($params[2], $params[1]);
view::redirect('/' . $this->app->get_config('tweed.admin_path'));
break;
}
break;
case 'tweets':
$errors = false;
// todo: generate fetch parameters based on the passed in filter options
$pagination_filter = array();
foreach (array('campaign', 'lang', 'user', 'after') as $filter) {
if (!empty($_REQUEST[$filter])) {
${$filter} = $_REQUEST[$filter];
$pagination_filter[] = "{$filter}=" . filter_var($_REQUEST[$filter], FILTER_SANITIZE_SPECIAL_CHARS);
} else {
${$filter} = null;
}
}
$current_page = !empty($_REQUEST['page']) && intval($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
// get the tweets (with any specified filter parameters if available)
$tweets = content::get_tweets(null, $this->app->get_config('twitter.total'), $current_page, $lang, $user, null, null, null, null, null);
$tweets_count = content::get_tweets_count(null, $lang, $user, null, null, null, null, null);
// get the pagination string
$pagination_links = $this->get_pagination('/' . $this->app->get_config('tweed.admin_path') . '/tweets', $current_page, $tweets_count, $pagination_filter);
// create the table
$headers = '["ID #","Campaign","Lang","User","Sent At","Retweet?","Reply?","Approved?","Content","Actions"]';
$data = array();
if (is_array($tweets)) {
foreach ($tweets as $tweet) {
$tweet_actions = array($tweet['approved'] == 'no' ? 'approve' : 'unapprove');
$data[] = array($tweet['id'], $tweet['campaign_name'], $tweet['iso_lang'], $tweet['user_screen_name'], date("l, jS M, Y", strtotime($tweet['created_at'])), intval($tweet['retweet_count']) ? 'yes' : 'no', intval($tweet['in_reply_to_id']) ? 'yes' : 'no', $tweet['approved'], $tweet['content'], content::generate_actions('tweets', $tweet['id'], $tweet_actions));
}
} else {
$errors = "<span class=\"error\">{$tweets}</span>";
}
$tweets_table = new \helpers\html\tables('forms', 'layout', $data, $headers);
$tweets_table->class = 'item_table tweets';
// create the filter form
// campaign list
$campaign_list = content::get_all_campaigns();
foreach ($campaign_list as &$c) {
$c = "\"{$c['name']}\"";
}
// language list
$languages = content::get_languages();
foreach ($languages as &$l) {
$l = "\"{$l['iso_lang']}\"";
}
$filter_form_elements = '{
"campaign":{"type":"select","label":"Campaign","values":["",' . implode(',', $campaign_list) . ']},
"lang":{"type":"select","label":"Language","values":["",' . implode(',', $languages) . ']},
"user":{"type":"text","label":"User"},
"after":{"type":"date","placeholder":"' . date("Y-m-d H:i:s") . '","label":"Sent after"},
"submit":{"type":"submit","value":"Filter","class":"action filter full"}
}';
$filter_form = new \helpers\html\form('filter_form', $filter_form_elements);
// set up the view
$view_params = array('tweets_table' => $tweets_table->render(), 'filter_form' => $filter_form->render(), 'pagination' => $pagination_links, 'scripts' => array('/js/tweets.js' => 10));
// add in any errors that might have been generated which should be shown to the user
if ($errors) {
$view_params['errors'] = $errors;
}
$this->load_view('tweets', $view_params);
break;
}
}