本文整理汇总了PHP中AjaxResponse类的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse类的具体用法?PHP AjaxResponse怎么用?PHP AjaxResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AjaxResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: performAction
function performAction()
{
global $wgAjaxExportList, $wgOut;
if (empty($this->mode)) {
return;
}
wfProfileIn(__METHOD__);
if (!in_array($this->func_name, $wgAjaxExportList)) {
wfHttpError(400, 'Bad Request', "unknown function " . (string) $this->func_name);
} else {
try {
$result = call_user_func_array($this->func_name, $this->args);
if ($result === false || $result === NULL) {
wfHttpError(500, 'Internal Error', "{$this->func_name} returned no data");
} else {
if (is_string($result)) {
$result = new AjaxResponse($result);
}
$result->sendHeaders();
$result->printText();
}
} catch (Exception $e) {
if (!headers_sent()) {
wfHttpError(500, 'Internal Error', $e->getMessage());
} else {
print $e->getMessage();
}
}
}
wfProfileOut(__METHOD__);
$wgOut = null;
}
示例2: executeUpload
public function executeUpload()
{
$upload_max_filesize = str_replace('M', '', ini_get('upload_max_filesize'));
$res = new \AjaxResponse();
$upload_dir = PUBLIC_DIR . '/media/editor_upload/';
Folder::create($upload_dir, 0777);
$error = array();
$fileUploader = new Uploader($upload_dir, 'file_upload');
$fileUploader->setMaximumFileSize($upload_max_filesize);
$fileUploader->setFilterType('.jpg, .jpeg, .png, .bmp, .gif');
$fileUploader->setIsEncryptFileName(true);
if ($fileUploader->upload('file_upload')) {
$data = $fileUploader->getData();
$file_path = '/media/editor_upload/' . $data['file_name'];
$file_url = rtrim($this->document()->getBaseUrl(), '/') . preg_replace('/(\\/+)/', '/', '/../' . $file_path);
$image = ['file_name' => $data['file_name'], 'url' => $file_url, 'path' => $file_path];
$res->type = \AjaxResponse::SUCCESS;
$res->image = $image;
return $this->renderText($res->toString());
} else {
$error['upload'] = $fileUploader->getError();
}
$res->type = \AjaxResponse::ERROR;
$res->error = $error;
return $this->renderText($res->toString());
}
示例3: saveOrder
function saveOrder($xmlsd)
{
global $reporterOrderTable, $readerOrderTable, $editorOrderTable;
$response = new AjaxResponse();
$response->setContentType('text/plain');
$xmlstr = '' . html_entity_decode($xmlsd);
$dbr =& wfGetDB(DB_WRITE);
$xml = new SimpleXMLElement($xmlstr);
//delete all in table
$result = $dbr->delete($editorOrderTable, "*");
$result = $dbr->delete($readerOrderTable, "*");
$result = $dbr->delete($reporterOrderTable, "*");
foreach ($xml->children() as $child) {
if ($child->getName() == 'Editor') {
$sql = 'INSERT INTO ' . $editorOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')';
$result = $dbr->query($sql);
} elseif ($child->getName() == 'Reader') {
$sql = 'INSERT INTO ' . $readerOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')';
$result = $dbr->query($sql);
} elseif ($child->getName() == 'Reporter') {
$sql = 'INSERT INTO ' . $reporterOrderTable . ' (id, rank) VALUES (' . $child['id'] . ',' . $child['rank'] . ')';
$result = $dbr->query($sql);
}
}
$response->addtext("Changes Saved");
return $response;
}
示例4: performAction
function performAction()
{
global $wgAjaxExportList, $wgOut;
if (empty($this->mode)) {
return;
}
wfProfileIn('AjaxDispatcher::performAction');
if (!in_array($this->func_name, $wgAjaxExportList)) {
header('Status: 400 Bad Request', true, 400);
print "unknown function " . htmlspecialchars((string) $this->func_name);
} else {
try {
$result = call_user_func_array($this->func_name, $this->args);
if ($result === false || $result === NULL) {
header('Status: 500 Internal Error', true, 500);
echo "{$this->func_name} returned no data";
} else {
if (is_string($result)) {
$result = new AjaxResponse($result);
}
$result->sendHeaders();
$result->printText();
}
} catch (Exception $e) {
if (!headers_sent()) {
header('Status: 500 Internal Error', true, 500);
print $e->getMessage();
} else {
print $e->getMessage();
}
}
}
wfProfileOut('AjaxDispatcher::performAction');
$wgOut = null;
}
示例5: wfTalkHereAjaxEditor
function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
global $wgRequest, $wgTitle, $wgOut;
$title = Title::newFromText( $page );
if ( !$title ) {
return false;
}
//fake editor environment
$args = array(
'wpTalkHere' => '1',
'wpReturnTo' => $returnto,
'action' => 'edit',
'section' => $section
);
$wgRequest = new FauxRequest( $args );
$wgTitle = $title;
$article = Article::newFromTitle( $title, RequestContext::getMain() );
$editor = new TalkHereEditPage( $article );
//generate form
$editor->importFormData( $wgRequest );
$editor->showEditForm();
$response = new AjaxResponse();
$response->addText( $wgOut->getHTML() );
$response->setCacheDuration( false ); //don't cache, because of tokens etc
return $response;
}
示例6: getFogbugzServiceResponse
/**
*
* cmd posible values:
* 'getCasesInfo' - in response there will be returned set of cases and subcases info formated in WikiText
* 'getComment' - in response there will be returned comments for particular case
*/
public static function getFogbugzServiceResponse()
{
global $wgRequest, $wgHTTPProxy, $wgFogbugzAPIConfig;
$command = $wgRequest->getText('cmd');
$myFBService = new FogbugzService($wgFogbugzAPIConfig['apiUrl'], $wgFogbugzAPIConfig['username'], $wgFogbugzAPIConfig['password'], $wgHTTPProxy);
// there should be made some kind of protection from setting different value as cmd
if ($command == 'getCasesInfo') {
$outerIDs = $wgRequest->getArray('IDs');
$results = array();
try {
$results = $myFBService->logon()->getCasesBasicInfo($outerIDs);
} catch (Exception $e) {
$results = array();
}
$preparedResults = FogbugzTag::sortAndMakeTickets($results);
$response = new AjaxResponse();
$response->addText(json_encode($preparedResults));
} else {
// this part is not in use now; it will be after adding displaying comments
$outerIDs = $wgRequest->getText('ID');
/* ... */
}
if (!$response) {
$response = new AjaxResponse();
$response->addText(json_encode(array('status' => wfMsg('fbtag-unknown-error'))));
}
return $response;
}
示例7: smwf_ws_callEQIXML
function smwf_ws_callEQIXML($query)
{
global $IP;
require_once $IP . '/extensions/SMWHalo/includes/webservices/SMW_EQI.php';
$result = new AjaxResponse(query($query, "xml"));
$result->setContentType("application/xml");
return $result;
}
示例8: getLinkSuggestImage
function getLinkSuggestImage()
{
global $wgRequest;
wfProfileIn(__METHOD__);
$res = LinkSuggest::getLinkSuggestImage($wgRequest->getText('imageName'));
$ar = new AjaxResponse($res);
$ar->setCacheDuration(60 * 60);
$ar->setContentType('text/plain; charset=utf-8');
wfProfileOut(__METHOD__);
return $ar;
}
示例9: RecipesTemplateAjax
function RecipesTemplateAjax()
{
global $wgRequest;
$method = $wgRequest->getVal('method', false);
if (method_exists('RecipesTemplateAjax', $method)) {
$data = RecipesTemplateAjax::$method();
$json = json_encode($data);
$response = new AjaxResponse($json);
$response->setContentType('application/json; charset=utf-8');
return $response;
}
}
示例10: ajax_tags
/**
* Handles AJAX from /admin/tags
* Used to delete and rename tags
*/
public function ajax_tags($handler_vars)
{
Utils::check_request_method(array('POST'));
$response = new AjaxResponse();
$wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
if ($handler_vars['digest'] != $wsse['digest']) {
$response->message = _t('WSSE authentication failed.');
$response->out();
return;
}
$tag_names = array();
$this->create_theme();
$action = $this->handler_vars['action'];
switch ($action) {
case 'delete':
foreach ($_POST as $id => $delete) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $delete) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
Tags::vocabulary()->delete_term($tag);
}
}
$response->message = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names));
break;
case 'rename':
if (!isset($this->handler_vars['master'])) {
$response->message = _t('Error: New name not specified.');
$response->out();
return;
}
$master = $this->handler_vars['master'];
$tag_names = array();
foreach ($_POST as $id => $rename) {
// skip POST elements which are not tag ids
if (preg_match('/^tag_\\d+/', $id) && $rename) {
$id = substr($id, 4);
$tag = Tags::get_by_id($id);
$tag_names[] = $tag->term_display;
}
}
Tags::vocabulary()->merge($master, $tag_names);
$response->message = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master);
break;
}
$this->theme->tags = Tags::vocabulary()->get_tree('term_display ASC');
$this->theme->max = Tags::vocabulary()->max_count();
$response->data = $this->theme->fetch('tag_collection');
$response->out();
}
示例11: error
protected function error($msg)
{
$this->setNoRender();
$this->_request->setDispatched(true);
if ($this->_request->isXmlHttpRequest()) {
$arp = new AjaxResponse();
$arp->setStatus(AjaxResponse::STATUS_FAILED);
$arp->setMessage($msg);
$this->json($arp);
} else {
$this->view->msg = $msg;
$this->renderScript('common/error.phtml');
}
}
示例12: VET
function VET()
{
global $wgRequest;
$method = $wgRequest->getVal('method');
$vet = new VideoEmbedTool();
$html = $vet->{$method}();
$domain = $wgRequest->getVal('domain', null);
if (!empty($domain)) {
$html .= '<script type="text/javascript">document.domain = "' . $domain . '"</script>';
}
$resp = new AjaxResponse($html);
$resp->setContentType('text/html');
return $resp;
}
示例13: playerAjaxHandler
function playerAjaxHandler($file, $options)
{
$response = new AjaxResponse();
try {
#TODO: caching!
$player = Player::newFromName($file, $options, 'thumbsize');
$html = $player->getPlayerHTML();
$response->addText($html);
} catch (PlayerException $ex) {
$response->setResponseCode($ex->getHTTPCode());
$response->addText($ex->getHTML());
}
return $response;
}
示例14: MyHomeAjax
function MyHomeAjax()
{
global $wgRequest;
$method = $wgRequest->getVal('method', false);
if (method_exists('MyHomeAjax', $method)) {
wfProfileIn(__METHOD__);
$data = MyHomeAjax::$method();
$json = json_encode($data);
$response = new AjaxResponse($json);
$response->setContentType('application/json; charset=utf-8');
wfProfileOut(__METHOD__);
return $response;
}
}
示例15: ajax
/**
* Ajax call. This is called by efCategoryTreeAjaxWrapper, which is used to
* load CategoryTreeFunctions.php on demand.
*/
function ajax($category, $mode)
{
global $wgDBname;
$title = self::makeTitle($category);
if (!$title) {
return false;
}
#TODO: error message?
$this->mIsAjaxRequest = true;
# Retrieve page_touched for the category
$dbkey = $title->getDBkey();
$dbr =& wfGetDB(DB_SLAVE);
$touched = $dbr->selectField('page', 'page_touched', array('page_namespace' => NS_CATEGORY, 'page_title' => $dbkey), __METHOD__);
$mckey = "{$wgDBname}:categorytree({$mode}):{$dbkey}";
//FIXME: would need to add depth parameter.
$response = new AjaxResponse();
if ($response->checkLastModified($touched)) {
return $response;
}
if ($response->loadFromMemcached($mckey, $touched)) {
return $response;
}
$html = $this->renderChildren($title, $mode);
//FIXME: would need to pass depth parameter.
if ($html == '') {
$html = ' ';
}
#HACK: Safari doesn't like empty responses.
#see Bug 7219 and http://bugzilla.opendarwin.org/show_bug.cgi?id=10716
$response->addText($html);
$response->storeInMemcached($mckey, 86400);
return $response;
}