[ Index ]

PHP Cross Reference of Zikula Core 1.3.2

title

Body

[close]

/ -> ajax.php (source)

   1  <?php
   2  /**
   3   * Copyright Zikula Foundation 2009 - Zikula Application Framework
   4   *
   5   * This work is contributed to the Zikula Foundation under one or more
   6   * Contributor Agreements and licensed to You under the following license:
   7   *
   8   * @license GNU/LGPLv3 (or at your option, any later version).
   9   * @package Zikula
  10   *
  11   * Please see the NOTICE file distributed with this source code for further
  12   * information regarding copyright and licensing.
  13   */
  14  include  'lib/bootstrap.php';
  15  $core->init(Zikula_Core::STAGE_ALL | Zikula_Core::STAGE_AJAX & ~Zikula_Core::STAGE_DECODEURLS);
  16  
  17  // Get variables
  18  $module = FormUtil::getPassedValue('module', '', 'GETPOST', FILTER_SANITIZE_STRING);
  19  $type = FormUtil::getPassedValue('type', 'ajax', 'GETPOST', FILTER_SANITIZE_STRING);
  20  $func = FormUtil::getPassedValue('func', '', 'GETPOST', FILTER_SANITIZE_STRING);
  21  
  22  // Check for site closed
  23  if (System::getVar('siteoff') && !SecurityUtil::checkPermission('Settings::', 'SiteOff::', ACCESS_ADMIN) && !($module == 'Users' && $func == 'siteofflogin')) {
  24      if (SecurityUtil::checkPermission('Users::', '::', ACCESS_OVERVIEW) && UserUtil::isLoggedIn()) {
  25          UserUtil::logout();
  26      }
  27      die(new Zikula_Response_Ajax_Unavailable(__('The site is currently off-line.')));
  28  }
  29  
  30  if (empty($func)) {
  31      die(new Zikula_Response_Ajax_NotFound(__f("Missing parameter '%s'", 'func')));
  32  }
  33  
  34  // get module information
  35  $modinfo = ModUtil::getInfoFromName($module);
  36  if ($modinfo == false) {
  37      die(new Zikula_Response_Ajax_NotFound(__f("Error! The '%s' module is unknown.", DataUtil::formatForDisplay($module))));
  38  }
  39  
  40  if (!ModUtil::available($modinfo['name'])) {
  41      die(new Zikula_Response_Ajax_NotFound(__f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($module))));
  42  }
  43  
  44  if (!ModUtil::load($modinfo['name'], $type)) {
  45      die(new Zikula_Response_Ajax_NotFound(__f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($module))));
  46  }
  47  
  48  // Handle database transactions
  49  if (System::getVar('Z_CONFIG_USE_TRANSACTIONS')) {
  50      $dbConn = Doctrine_Manager::getInstance()->getCurrentConnection();
  51      $dbConn->beginTransaction();
  52  }
  53  
  54  // Dispatch controller.
  55  try {
  56      $response = ModUtil::func($modinfo['name'], $type, $func);
  57      if (System::isLegacyMode() && $response == false && LogUtil::hasErrors()) {
  58          throw new Zikula_Exception_Fatal(__('An unknown error occurred in module %s, controller %s, action %s', array($modinfo['name'], $type, $func)));
  59      }
  60  } catch (Zikula_Exception_NotFound $e) {
  61      $response = new Zikula_Response_Ajax_NotFound($e->getMessage());
  62  } catch (Zikula_Exception_Forbidden $e) {
  63      $response = new Zikula_Response_Ajax_Forbidden($e->getMessage());
  64  } catch (Zikula_Exception_Fatal $e) {
  65      $response = new Zikula_Response_Ajax_Fatal($e->getMessage());
  66  } catch (PDOException $e) {
  67      $response = new Zikula_Response_Ajax_Fatal($e->getMessage());
  68  } catch (Exception $e) {
  69      $response = new Zikula_Response_Ajax_Fatal($e->getMessage());
  70  }
  71  
  72  // Handle database transactions
  73  if (System::getVar('Z_CONFIG_USE_TRANSACTIONS')) {
  74      if (isset($e) && $e instanceof Exception) {
  75          $dbConn->rollback();
  76      } else {
  77          $dbConn->commit();
  78      }
  79  }
  80  
  81  // Process final response.
  82  // If response is not instanceof Zikula_Response_Ajax_AbstractBase provide compat solution
  83  if (!$response instanceof Zikula_Response_Ajax_AbstractBase) {
  84      $response = !is_array($response) ? array('data' => $response) : $response;
  85      $response['statusmsg'] = LogUtil::getStatusMessages();
  86      if (System::isLegacyMode()) {
  87          $response['authid'] = SecurityUtil::generateAuthKey(ModUtil::getName());
  88      }
  89      $response = json_encode($response);
  90      header("HTTP/1.1 200 OK");
  91      header('Content-type: application/json');
  92  }
  93  
  94  // Issue response.
  95  echo $response;
  96  System::shutdown();


Generated: Mon Feb 20 12:35:30 2012 Cross-referenced by PHPXref 0.7.1