/**
  * @see AuthorizationPolicy::effect()
  */
 function effect()
 {
     if ($this->_request->getUser()) {
         return AUTHORIZATION_PERMIT;
     } else {
         return AUTHORIZATION_DENY;
     }
 }
 /**
  * @see AuthorizationPolicy::effect()
  */
 function effect()
 {
     $router =& $this->_request->getRouter();
     if (is_object($router->getContext($this->_request))) {
         return AUTHORIZATION_PERMIT;
     } else {
         return AUTHORIZATION_DENY;
     }
 }
 /**
  * @see AuthorizationPolicy::effect()
  */
 function effect()
 {
     if (is_a($this->_router, 'PKPPageRouter')) {
         $page = $this->_router->getRequestedPage($this->_request);
     } else {
         $page = null;
     }
     if (Validation::isLoggedIn() || in_array($page, $this->_getLoginExemptions())) {
         return AUTHORIZATION_PERMIT;
     } else {
         return AUTHORIZATION_DENY;
     }
 }
 /**
  * Cache content as a local file.
  * @param $contents string
  * @return string
  */
 function _cacheContent($contents)
 {
     assert(is_a($this->_router, 'PKPRouter'));
     $filename = $this->_router->getCacheFilename();
     $fp = fopen($filename, 'w');
     if ($fp) {
         fwrite($fp, mktime() . ':' . $contents);
         fclose($fp);
     }
     return $contents;
 }
 public function testDoi()
 {
     // Mock a router.
     $router = new PKPRouter();
     $application = PKPApplication::getApplication();
     $router->setApplication($application);
     // Mock a request.
     $mockRequest = $this->getMock('PKPRequest', array('getRouter', 'getJournal'));
     $mockRequest->expects($this->any())->method('getRouter')->will($this->returnValue($router));
     $mockRequest->expects($this->any())->method('getJournal')->will($this->returnValue(null));
     Registry::set('request', $mockRequest);
     // Retrieve test article from test database.
     $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
     $publishedArticle =& $publishedArticleDao->getPublishedArticleByArticleId(1);
     // Create a SWORD deposit package.
     $deposit = new OJSSwordDeposit($publishedArticle);
     $deposit->setMetadata();
     // Test DOI.
     self::assertEquals('10.1234/t.v1i1.1', $deposit->package->sac_identifier);
     // FIXME: Current requirement is only for a DOI regression test. Test whole package if required.
 }
Exemple #6
0
 /**
  * Cache content as a local file.
  * @param $contents string
  * @return string
  */
 function _cacheContent($contents)
 {
     assert(is_a($this->_router, 'PKPRouter'));
     if ($contents == '') {
         return $contents;
     }
     // Do not cache empties
     $filename = $this->_router->getCacheFilename($this->_requestCallbackHack);
     $fp = fopen($filename, 'w');
     if ($fp) {
         fwrite($fp, mktime() . ':' . $contents);
         fclose($fp);
     }
     return $contents;
 }
Exemple #7
0
 /**
  * Constructor
  */
 function PKPPageRouter()
 {
     parent::PKPRouter();
 }
 /**
  * Constructor
  */
 function PKPComponentRouter()
 {
     parent::PKPRouter();
 }
Exemple #9
0
$pkpBaseDir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
$curDir = dirname(dirname(__FILE__));
// Load system files, initialize
if (basename($_SERVER['SCRIPT_FILENAME'], ".php") == "rfiles") {
    $baseDir = dirname($baseDir);
}
define('INDEX_FILE_LOCATION', $baseDir . '/index.php');
// Load and execute initialization code
chdir($baseDir);
require $baseDir . '/lib/pkp/includes/bootstrap.inc.php';
// Manually set up a context router to get access
// to the application context (required by Locale).
$application =& PKPApplication::getApplication();
$request =& $application->getRequest();
import('core.PKPRouter');
$router = new PKPRouter();
$router->setApplication($application);
$request->setRouter($router);
Locale::initialize();
// Load user variables
$sessionManager =& SessionManager::getManager();
$userSession =& $sessionManager->getUserSession();
$user =& $userSession->getUser();
// Insert system variables into associative array to be used by iBrowser
$init['publicDir'] = Config::getVar('files', 'public_files_dir');
if (isset($user)) {
    // User is logged in
    $init['user'] = $user->getUsername();
    //$init['lang'] = String::substr(Locale::getLocale(), 0, 2);
    $init['lang'] = 'en';
    $init['baseUrl'] = Config::getVar('general', 'base_url');
 /**
  * Constructor
  */
 function __construct()
 {
     parent::__construct();
 }
 /**
  * Mocks the context of an application by manipulating
  * the registered DAOs.
  * @param $contextIds array an array of context IDs to be set up.
  *  Missing IDs will be replaced with null.
  * @param $userId the user id to be returned by the request
  */
 private function mockContext($contextIds, $userId)
 {
     $application = PKPApplication::getApplication();
     // Mock the context
     if (count($contextIds)) {
         $_SERVER['PATH_INFO'] = '/' . implode('/', array_fill(0, count($contextIds), 'context')) . '/';
     } else {
         $_SERVER['PATH_INFO'] = '/';
     }
     foreach ($application->getContextList() as $contextName) {
         // Get a mock DAO for the requested context.
         $contextClass = ucfirst($contextName);
         $daoName = $contextClass . 'DAO';
         $daoMethod = 'get' . $contextClass . 'ByPath';
         $mockContextDao = $this->getMock($daoName, array($daoMethod));
         // Set up the mock context retrieval method
         $mockContextDao->expects($this->any())->method($daoMethod)->will($this->returnValue($this->getMockContext($contextClass, array_shift($contextIds))));
         // Register the mock context DAO
         DAORegistry::registerDAO($daoName, $mockContextDao);
         unset($mockContextDao);
     }
     // Mock the UserDAO and the session with a test user
     if (is_null($userId)) {
         $user = null;
     } else {
         $user = new User();
         $user->setId($userId);
     }
     $mockUserDao = $this->getMock('UserDAO', array('getUser'));
     $mockUserDao->expects($this->any())->method('getUser')->will($this->returnValue($user));
     DAORegistry::registerDAO('UserDAO', $mockUserDao);
     $sessionManager =& SessionManager::getManager();
     $session =& $sessionManager->getUserSession();
     $session->setUserId($userId);
     // Mock the request
     $mockRequest = $this->getMock('Request', array('getRouter', 'getBasePath', 'getRemoteAddr', 'getUserAgent'));
     $router = new PKPRouter();
     $router->setApplication($application);
     $mockRequest->expects($this->any())->method('getRouter')->will($this->returnValue($router));
     $mockRequest->expects($this->any())->method('getBasePath')->will($this->returnValue('/'));
     $mockRequest->expects($this->any())->method('getRemoteAddr')->will($this->returnValue(''));
     $mockRequest->expects($this->any())->method('getUserAgent')->will($this->returnValue(''));
     Registry::set('request', $mockRequest);
 }