<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Vb4_poll extends vB_Api { public function pollvote($pollid, $optionnumber) { $cleaner = vB::getCleaner(); $pollid = $cleaner->clean($pollid, vB_Cleaner::TYPE_UINT); $pollNode = vB_Api::instance('node')->getFullContentforNodes(array($pollid)); if (empty($pollNode) || !empty($pollNode['errors'])) { return vB_Library::instance('vb4_functions')->getErrorResponse($pollNode); } $pollNode = reset($pollNode); $pollTypeid = vB_Types::instance()->getContentTypeId('vBForum_Poll'); if ($pollNode['contenttypeid'] != $pollTypeid) { return array('response' => array('errormessage' => 'invalidid')); } if ($pollNode['content']['voted']) { return array('response' => array('errormessage' => 'useralreadyvote')); } $validPolloptions = array(); foreach ($pollNode['content']['options'] AS $key => $polloption) { $validPolloptions[$polloption['polloptionid']] = $polloption['polloptionid']; } $polloptionids = array(); $multiple = $pollNode['content']['multiple']; if ($multiple) { if (is_array($optionnumber)) { $optionnumber = $cleaner->clean($optionnumber, vB_Cleaner::TYPE_ARRAY_BOOL); foreach ($optionnumber AS $id => $vote) { $id = intval($id); if (!isset($validPolloptions[$id])) { return array('response' => array('errormessage' => 'invalid_poll_option')); } else if ($vote) { $polloptionids[] = $id; } } unset($id); } } else { $id = $cleaner->clean($optionnumber, vB_Cleaner::TYPE_UINT); if (!isset($validPolloptions[$id])) { return array('response' => array('errormessage' => 'invalid_poll_option')); } else { $polloptionids[] = $id; } } unset($optionnumber); if (empty($polloptionids)) { return array('response' => array('errormessage' => 'nopolloptionselected')); } $result = vB_Api::instance('content_poll')->vote($polloptionids); if (empty($result) || !empty($result['errors'])) { return vB_Library::instance('vb4_functions')->getErrorResponse($result); } return array('response' => array('errormessage' => 'redirect_pollvotethanks')); } } 