本文整理汇总了PHP中Poll::getPoll方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::getPoll方法的具体用法?PHP Poll::getPoll怎么用?PHP Poll::getPoll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::getPoll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* Called on every poll page view.
*/
public function view()
{
global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgScriptPath, $wgUploadPath, $wgLang;
global $wgSupressPageTitle, $wgNameSpacesWithEditMenu;
// Perform no custom handling if the poll in question has been deleted
if (!$this->getID()) {
parent::view();
}
$wgSupressPageTitle = true;
$wgOut->setHTMLTitle($wgTitle->getText());
$wgOut->setPageTitle($wgTitle->getText());
$wgNameSpacesWithEditMenu[] = NS_POLL;
$wgOut->addScript("<script type=\"text/javascript\">\n\t\t\t\$( function() { LightBox.init(); PollNY.show(); } );\n\t\t</script>\n");
$createPollObj = SpecialPage::getTitleFor('CreatePoll');
$wgOut->addHTML("<script type=\"text/javascript\">\n\t\t\tvar _POLL_OPEN_MESSAGE = \"" . addslashes(wfMsg('poll-open-message')) . "\";\n\t\t\tvar _POLL_CLOSE_MESSAGE = \"" . addslashes(wfMsg('poll-close-message')) . "\";\n\t\t\tvar _POLL_FLAGGED_MESSAGE = \"" . addslashes(wfMsg('poll-flagged-message')) . "\";\n\t\t\tvar _POLL_FINISHED = \"" . addslashes(wfMsg('poll-finished', $createPollObj->getFullURL(), $wgTitle->getFullURL())) . "\";\n\t\t</script>");
// Get total polls count so we can tell the user how many they have
// voted for out of total
$dbr = wfGetDB(DB_MASTER);
$total_polls = 0;
$s = $dbr->selectRow('poll_question', array('COUNT(*) AS count'), array(), __METHOD__);
if ($s !== false) {
$total_polls = number_format($s->count);
}
$stats = new UserStats($wgUser->getID(), $wgUser->getName());
$stats_current_user = $stats->getUserStats();
$sk = $wgUser->getSkin();
$p = new Poll();
$poll_info = $p->getPoll($wgTitle->getArticleID());
if (!isset($poll_info['id'])) {
return '';
}
// Set up submitter data
$user_title = Title::makeTitle(NS_USER, $poll_info['user_name']);
$avatar = new wAvatar($poll_info['user_id'], 'l');
$avatarID = $avatar->getAvatarImage();
$stats = new UserStats($poll_info['user_id'], $poll_info['user_name']);
$stats_data = $stats->getUserStats();
$user_name_short = $wgLang->truncate($poll_info['user_name'], 27);
$output = '<div class="poll-right">';
// Show the "create a poll" link to registered users
if ($wgUser->isLoggedIn()) {
$output .= '<div class="create-link">
<a href="' . $createPollObj->escapeFullURL() . '">
<img src="' . $wgScriptPath . '/extensions/PollNY/images/addIcon.gif" alt="" />' . wfMsg('poll-create') . '</a>
</div>';
}
$output .= '<div class="credit-box">
<h1>' . wfMsg('poll-submitted-by') . "</h1>\n\t\t\t\t\t<div class=\"submitted-by-image\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">\n\t\t\t\t\t\t\t<img src=\"{$wgUploadPath}/avatars/{$avatarID}\" style=\"border:1px solid #d7dee8; width:50px; height:50px;\"/>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"submitted-by-user\">\n\t\t\t\t\t\t<a href=\"{$user_title->getFullURL()}\">{$user_name_short}</a>\n\t\t\t\t\t\t<ul>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/voteIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['votes']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/pencilIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['edits']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t<li>\n\t\t\t\t\t\t\t\t<img src=\"{$wgScriptPath}/extensions/PollNY/images/commentsIcon.gif\" alt=\"\" />\n\t\t\t\t\t\t\t\t{$stats_data['comments']}\n\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t</ul>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"cleared\"></div>\n\n\t\t\t\t\t<a href=\"" . SpecialPage::getTitleFor('ViewPoll')->escapeFullURL('user=' . $poll_info['user_name']) . '">' . wfMsgExt('poll-view-all-by', 'parsemag', $user_name_short) . '</a>
</div>';
$output .= '<div class="poll-stats">';
if ($wgUser->isLoggedIn()) {
$output .= wfMsgExt('poll-voted-for', 'parsemag', '<b>' . $stats_current_user['poll_votes'] . '</b>', $total_polls, number_format($stats_current_user['poll_votes'] * 5));
} else {
$output .= wfMsgExt('poll-would-have-earned', 'parse', number_format($total_polls * 5));
}
$output .= '</div>' . "\n";
$toggle_flag_label = $poll_info['status'] == 1 ? wfMsg('poll-flag-poll') : wfMsg('poll-unflag-poll');
$toggle_flag_status = $poll_info['status'] == 1 ? 2 : 1;
if ($poll_info['status'] == 1) {
// Creator and admins can change the status of a poll
$toggle_label = $poll_info['status'] == 1 ? wfMsg('poll-close-poll') : wfMsg('poll-open-poll');
$toggle_status = $poll_info['status'] == 1 ? 0 : 1;
}
$output .= '<div class="poll-links">' . "\n";
// Poll administrators can access the poll admin panel
if ($wgUser->isAllowed('polladmin')) {
$output .= '<a href="' . SpecialPage::getTitleFor('AdminPoll')->escapeFullURL() . '">' . wfMsg('poll-admin-panel') . '</a> | ';
}
if ($poll_info['status'] == 1 && ($poll_info['user_id'] == $wgUser->getID() || $wgUser->isAllowed('polladmin'))) {
$output .= "<a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_status});\">{$toggle_label}</a> |";
}
if ($poll_info['status'] == 1 || $wgUser->isAllowed('polladmin')) {
$output .= " <a href=\"javascript:void(0)\" onclick=\"PollNY.toggleStatus({$toggle_flag_status});\">{$toggle_flag_label}</a>";
}
$output .= "\n" . '</div>' . "\n";
// .poll-links
$output .= '</div>' . "\n";
// .poll-right
$output .= '<div class="poll">' . "\n";
$output .= "<h1 class=\"pagetitle\">{$wgTitle->getText()}</h1>\n";
if ($poll_info['image']) {
$poll_image_width = 150;
$poll_image = wfFindFile($poll_info['image']);
$poll_image_url = $width = '';
if (is_object($poll_image)) {
$poll_image_url = $poll_image->createThumb($poll_image_width);
if ($poll_image->getWidth() >= $poll_image_width) {
$width = $poll_image_width;
} else {
$width = $poll_image->getWidth();
}
}
$poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '"/>';
$output .= "<div class=\"poll-image\">{$poll_image_tag}</div>";
}
// Display question and let user vote
//.........这里部分代码省略.........
示例2: wfGetPollResults
function wfGetPollResults( $pageID ) {
global $wgScriptPath;
$p = new Poll();
$poll_info = $p->getPoll( $pageID );
$x = 1;
$output = '';
foreach( $poll_info['choices'] as $choice ) {
//$percent = round( $choice['votes'] / $poll_info['votes'] * 100 );
if( $poll_info['votes'] > 0 ) {
$bar_width = floor( 480 * ( $choice['votes'] / $poll_info['votes'] ) );
}
$bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" border=\"0\" class=\"image-choice-{$x}\" style=\"width:{$choice['percent']}%;height:12px;\"/>";
$output .= "<div class=\"poll-choice\">
<div class=\"poll-choice-left\">{$choice['choice']} ({$choice['percent']}%)</div>";
$output .= "<div class=\"poll-choice-right\">{$bar_img} <span class=\"poll-choice-votes\">"
. wfMsgExt( 'poll-votes', 'parsemag', $choice['votes'] ) .
'</span></div>';
$output .= '</div>';
$x++;
}
return $output;
}
示例3: renderEmbedPoll
/**
* Callback function for the <pollembed> tag.
*
* @param $input Mixed: user input
* @param $args Array: arguments supplied to the pollembed tag
* @param $parser Object: instance of Parser class
* @return HTML or nothing
*/
public static function renderEmbedPoll($input, $args, $parser)
{
$poll_name = $args['title'];
if ($poll_name) {
global $wgOut, $wgUser, $wgScriptPath;
// Load CSS for non-Monaco skins - Monaco's ny.css already contains
// PollNY's styles (and more)
if (get_class($wgUser->getSkin()) !== 'SkinMonaco') {
$wgOut->addExtensionStyle($wgScriptPath . '/extensions/PollNY/Poll.css');
}
// Disable caching; this is important so that we don't cause subtle
// bugs that are a bitch to fix.
$wgOut->enableClientCache(false);
$parser->disableCache();
$poll_title = Title::newFromText($poll_name, NS_POLL);
$poll_title = PollNYHooks::followPollID($poll_title);
$poll_page_id = $poll_title->getArticleID();
if ($poll_page_id > 0) {
$p = new Poll();
$poll_info = $p->getPoll($poll_page_id);
$output = "\t\t" . '<div class="poll-embed-title">' . $poll_info['question'] . '</div>' . "\n";
if ($poll_info['image']) {
$poll_image_width = 100;
$poll_image = wfFindFile($poll_info['image']);
$width = $poll_image_url = '';
if (is_object($poll_image)) {
$poll_image_url = $poll_image->createThumb($poll_image_width);
if ($poll_image->getWidth() >= $poll_image_width) {
$width = $poll_image_width;
} else {
$width = $poll_image->getWidth();
}
}
$poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '" />';
$output .= "\t\t<div class=\"poll-image\">{$poll_image_tag}</div>\n";
}
// If the user hasn't voted for this poll yet and the poll is open
// for votes, display the question and let the user vote
if (!$p->userVoted($wgUser->getName(), $poll_info['id']) && $poll_info['status'] == 1) {
$wgOut->addScriptFile($wgScriptPath . '/extensions/PollNY/Poll.js');
$wgOut->addScript("<script type=\"text/javascript\">\$( function() { PollNY.showEmbedPoll({$poll_info['id']}); } );</script>\n");
$output .= "<div id=\"loading-poll_{$poll_info['id']}\">" . wfMsg('poll-js-loading') . '</div>';
$output .= "<div id=\"poll-display_{$poll_info['id']}\" style=\"display:none;\">";
$output .= "<form name=\"poll_{$poll_info['id']}\"><input type=\"hidden\" id=\"poll_id_{$poll_info['id']}\" name=\"poll_id_{$poll_info['id']}\" value=\"{$poll_info['id']}\"/>";
foreach ($poll_info['choices'] as $choice) {
$output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<input type=\"radio\" name=\"poll_choice\" onclick=\"PollNY.pollEmbedVote({$poll_info['id']}, {$poll_page_id})\" id=\"poll_choice\" value=\"{$choice['id']}\">{$choice['choice']}\n\t\t\t\t\t\t</div>";
}
$output .= '</div>
</form>';
} else {
// Display message if poll has been closed for voting
if ($poll_info['status'] == 0) {
$output .= '<div class="poll-closed">' . wfMsg('poll-closed') . '</div>';
}
$x = 1;
foreach ($poll_info['choices'] as $choice) {
//$percent = round( $choice['votes'] / $poll_info['votes'] * 100 );
if ($poll_info['votes'] > 0) {
$bar_width = floor(480 * ($choice['votes'] / $poll_info['votes']));
}
$bar_img = "<img src=\"{$wgScriptPath}/extensions/PollNY/images/vote-bar-{$x}.gif\" border=\"0\" class=\"image-choice-{$x}\" style=\"width:{$choice['percent']}%;height:12px;\" alt=\"\" />";
$output .= "<div class=\"poll-choice\">\n\t\t\t\t\t\t<div class=\"poll-choice-left\">{$choice['choice']} ({$choice['percent']}%)</div>";
// If the amount of votes is not set, set it to 0
// This fixes an odd bug where "votes" would be shown
// instead of "0 votes" when using the pollembed tag.
if (empty($choice['votes'])) {
$choice['votes'] = 0;
}
$output .= "<div class=\"poll-choice-right\">{$bar_img} <span class=\"poll-choice-votes\">" . wfMsgExt('poll-votes', 'parsemag', $choice['votes']) . '</span></div>';
$output .= '</div>';
$x++;
}
$output .= '<div class="poll-total-votes">(' . wfMsgExt('poll-based-on-votes', 'parsemag', $poll_info['votes']) . ')</div>';
$output .= '<div><a href="' . $poll_title->escapeFullURL() . '">' . wfMsg('poll-discuss') . '</a></div>';
$output .= '<div class="poll-timestamp">' . wfMsg('poll-createdago', Poll::getTimeAgo($poll_info['timestamp'])) . '</div>';
}
return $output;
} else {
// Poll doesn't exist or is unavailable for some other reason
$output = '<div class="poll-embed-title">' . wfMsg('poll-unavailable') . '</div>';
return $output;
}
}
return '';
}
示例4: displayForm
/**
* Display the form for updating a given poll (via the id parameter in the
* URL).
* @return String: HTML
*/
function displayForm() {
global $wgUser, $wgOut, $wgRequest, $wgScriptPath, $wgHooks;
$p = new Poll();
$poll_info = $p->getPoll( $wgRequest->getInt( 'id' ) );
if(
!$poll_info['id'] ||
!( $wgUser->isAllowed( 'polladmin' ) || $wgUser->getID() == $poll_info['user_id'] )
) {
$wgOut->setPageTitle( wfMsgHtml( 'poll-woops' ) );
$wgOut->addHTML( wfMsg( 'poll-edit-invalid-access' ) );
return false;
}
$poll_image_tag = '';
if( $poll_info['image'] ) {
$poll_image_width = 150;
$poll_image = wfFindFile( $poll_info['image'] );
$poll_image_url = $width = '';
if ( is_object( $poll_image ) ) {
$poll_image_url = $poll_image->createThumb( $poll_image_width );
if ( $poll_image->getWidth() >= $poll_image_width ) {
$width = $poll_image_width;
} else {
$width = $poll_image->getWidth();
}
}
$poll_image_tag = '<img width="' . $width . '" alt="" src="' . $poll_image_url . '"/>';
}
$poll_page = Title::newFromID( $wgRequest->getInt( 'id' ) );
$prev_qs = '';
if( $wgRequest->getInt( 'prev_poll_id' ) ) {
$prev_qs = 'prev_id=' . $wgRequest->getInt( 'prev_poll_id' );
}
// i18n for JS (by SpecialCreatePoll.php, to reduce code duplication)
$wgHooks['MakeGlobalVariablesScript'][] = 'CreatePoll::addJSGlobals';
$wgOut->setPageTitle( wfMsg( 'poll-edit-title', $poll_info['question'] ) );
$form = "<div class=\"update-poll-left\">
<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"form1\">
<input type=\"hidden\" name=\"poll_id\" value=\"{$poll_info['id']}\" />
<input type=\"hidden\" name=\"prev_poll_id\" value=\"" . $wgRequest->getInt( 'prev_id' ) . '" />
<input type="hidden" name="poll_image_name" id="poll_image_name" />
<h1>' . wfMsg( 'poll-edit-answers' ) . '</h1>';
$x = 1;
foreach( $poll_info['choices'] as $choice ) {
$form .= "<div class=\"update-poll-answer\">
<span class=\"update-poll-answer-number\">{$x}.</span>
<input type=\"text\" tabindex=\"{$x}\" id=\"poll_answer_{$x}\" name=\"poll_answer_{$x}\" value=\"" .
htmlspecialchars( $choice['choice'], ENT_QUOTES ) . '" />
</div>';
$x++;
}
global $wgRightsText;
if ( $wgRightsText ) {
$copywarnMsg = 'copyrightwarning';
$copywarnMsgParams = array(
'[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
$wgRightsText
);
} else {
$copywarnMsg = 'copyrightwarning2';
$copywarnMsgParams = array(
'[[' . wfMsgForContent( 'copyrightpage' ) . ']]'
);
}
$form .= '</div>
<div class="update-poll-right">
<h1>' . wfMsg( 'poll-edit-image' ) . "</h1>
<div id=\"poll_image\" class=\"update-poll-image\">{$poll_image_tag}</div>
<!--
<div id=\"fake-form\" style=\"display:block;height:70px;\">
<input type=\"file\" size=\"40\" disabled=\"disabled\" />
<div style=\"margin:9px 0px 0px 0px;\">
<input type=\"button\" value=\"Upload\"/>
</div>
</div>
-->
<div id=\"real-form\" style=\"display:block;height:90px;\">
<iframe id=\"imageUpload-frame\" class=\"imageUpload-frame\" width=\"610\"
scrolling=\"no\" frameborder=\"0\" src=\"" .
SpecialPage::getTitleFor( 'PollAjaxUpload' )->escapeFullURL( 'wpThumbWidth=75' ) . '">
</iframe>
</div>
//.........这里部分代码省略.........