pages/rtadmin/RTAdminHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('rt.ocs.ConferenceRTAdmin');
00020 import('handler.Handler');
00021 
00022 class RTAdminHandler extends Handler {
00026    function RTAdminHandler() {
00027       parent::Handler();
00028 
00029       $this->addCheck(new HandlerValidatorConference($this));     
00030       $this->addCheck(new HandlerValidatorRoles($this, true, null, null, array(ROLE_ID_SITE_ADMIN, ROLE_ID_CONFERENCE_MANAGER)));      
00031    }
00032 
00037    function index() {
00038       $this->validate();
00039       $conference = Request::getConference();
00040       $user = Request::getUser();
00041       if ($conference) {
00042          $rtDao =& DAORegistry::getDAO('RTDAO');
00043          $rt = $rtDao->getConferenceRTByConference($conference);
00044          if (isset($rt)) {
00045             $version = $rtDao->getVersion($rt->getVersion(), $conference->getId());
00046          }
00047 
00048          // Display the administration menu for this conference.
00049 
00050          $this->setupTemplate();
00051          $templateMgr =& TemplateManager::getManager();
00052          $templateMgr->assign('helpTopicId', 'conference.generalManagement.readingTools');
00053          $templateMgr->assign('versionTitle', isset($version)?$version->getTitle():null);
00054          $templateMgr->assign('enabled', $rt->getEnabled());
00055 
00056          $templateMgr->display('rtadmin/index.tpl');
00057       } elseif ($user) {
00058          // Display a list of conferences.
00059          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00060          $roleDao =& DAORegistry::getDAO('RoleDAO');
00061 
00062          $conferences = array();
00063 
00064          $allConferences =& $conferenceDao->getConferences();
00065          $allConferences =& $allConferences->toArray();
00066 
00067          foreach ($allConferences as $conference) {
00068             if ($roleDao->roleExists($conference->getId(), 0, $user->getId(), ROLE_ID_CONFERENCE_MANAGER)) {
00069                $conferences[] = $conference;
00070             }
00071          }
00072 
00073          $this->setupTemplate();
00074          $templateMgr =& TemplateManager::getManager();
00075          $templateMgr->assign_by_ref('conferences', $conferences);
00076          $templateMgr->assign('helpTopicId', 'conference.generalManagement.readingTools');
00077          $templateMgr->display('rtadmin/conferences.tpl');
00078       } else {
00079          // Not logged in.
00080          Validation::redirectLogin();
00081       }
00082    }
00083 
00084    function validateUrls($args) {
00085       $this->validate();
00086 
00087       $rtDao =& DAORegistry::getDAO('RTDAO');
00088       $conference = Request::getConference();
00089 
00090       if (!$conference) {
00091          Request::redirect(null, null, Request::getRequestedPage());
00092          return;
00093       }
00094 
00095       $versionId = isset($args[0])?$args[0]:0;
00096       $conferenceId = $conference->getId();
00097 
00098       $version = $rtDao->getVersion($versionId, $conferenceId);
00099 
00100       if ($version) {
00101          // Validate the URLs for a single version
00102          $versions = array(&$version);
00103          import('core.ArrayItemIterator');
00104          $versions = new ArrayItemIterator($versions, 1, 1);
00105       } else {
00106          // Validate all URLs for this conference
00107          $versions = $rtDao->getVersions($conferenceId);
00108       }
00109 
00110       $this->setupTemplate(true, $version);
00111       $templateMgr =& TemplateManager::getManager();
00112       $templateMgr->register_modifier('validate_url', 'smarty_rtadmin_validate_url');
00113       $templateMgr->assign_by_ref('versions', $versions);
00114       $templateMgr->assign('helpTopicId', 'conference.generalManagement.readingTools');
00115       $templateMgr->display('rtadmin/validate.tpl');
00116    }
00117 
00125    function setupTemplate($subclass = false, $version = null, $context = null, $search = null) {
00126       parent::setupTemplate();
00127       AppLocale::requireComponents(array(LOCALE_COMPONENT_PKP_READER, LOCALE_COMPONENT_OCS_MANAGER));
00128 
00129       $conference =& Request::getConference();
00130       $schedConf =& Request::getSchedConf();
00131       $templateMgr =& TemplateManager::getManager();
00132 
00133       $pageHierarchy = array();
00134 
00135       if ($schedConf) {
00136          $pageHierarchy[] = array(Request::url(null, null, 'index'), $schedConf->getFullTitle(), true);
00137       } elseif ($conference) {
00138          $pageHierarchy[] = array(Request::url(null, 'index', 'index'), $conference->getConferenceTitle(), true);
00139       }
00140 
00141       $pageHierarchy[] = array(Request::url(null, null, 'user'), 'navigation.user');
00142       $pageHierarchy[] = array(Request::url(null, null, 'manager'), 'manager.conferenceSiteManagement');
00143 
00144       if ($subclass) $pageHierarchy[] = array(Request::url(null, null, 'rtadmin'), 'rt.readingTools');
00145 
00146       if ($version) {
00147          $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'versions'), 'rt.versions');
00148          $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'editVersion', $version->getVersionId()), $version->getTitle(), true);
00149          if ($context) {
00150             $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'contexts', $version->getVersionId()), 'rt.contexts');
00151             $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'editContext', array($version->getVersionId(), $context->getContextId())), $context->getAbbrev(), true);
00152             if ($search) {
00153                $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'searches', array($version->getVersionId(), $context->getContextId())), 'rt.searches');
00154                $pageHierarchy[] = array(Request::url(null, null, 'rtadmin', 'editSearch', array($version->getVersionId(), $context->getContextId(), $search->getSearchId())), $search->getTitle(), true);
00155             }
00156          }
00157       }
00158       $templateMgr->assign('pageHierarchy', $pageHierarchy);
00159    }
00160 }
00161 
00162 function rtadmin_validate_url($url, $useGet = false, $redirectsAllowed = 5) {
00163    $data = parse_url($url);
00164    if(!isset($data['host'])) {
00165       return false;
00166    }
00167 
00168    $fp = @ fsockopen($data['host'], isset($data['port']) && !empty($data['port']) ? $data['port'] : 80, $errno, $errstr, 10);
00169    if (!$fp) {
00170       return false;
00171    }
00172 
00173    $req = sprintf("%s %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516\r\n\r\n", ($useGet ? 'GET' : 'HEAD'), (isset($data['path']) && $data['path'] !== '' ? $data['path'] : '/') .  (isset($data['query']) && $data['query'] !== '' ? '?' .  $data['query'] : ''), $data['host']);
00174 
00175    fputs($fp, $req);
00176 
00177    for($res = '', $time = time(); !feof($fp) && $time >= time() - 15; ) {
00178       $res .= fgets($fp, 128);
00179    }
00180 
00181    fclose($fp);
00182 
00183    // Check result for HTTP status code.
00184    if(!preg_match('!^HTTP/(\d\.?\d*) (\d+)\s*(.+)[\n\r]!m', $res, $matches)) {
00185       return false;
00186    }
00187    list($match, $http_version, $http_status_no, $http_status_str) = $matches;
00188 
00189    // If HTTP status code 2XX (Success)
00190    if(preg_match('!^2\d\d$!', $http_status_no)) return true;
00191 
00192    // If HTTP status code 3XX (Moved)
00193    if(preg_match('!^(?:(?:Location)|(?:URI)|(?:location)): ([^\s]+)[\r\n]!m', $res, $matches)) {
00194       // Recursively validate the URL if an additional redirect is allowed..
00195       if ($redirectsAllowed >= 1) return rtadmin_validate_url(preg_match('!^https?:
00196       return false;
00197    }
00198 
00199    // If it's not found or there is an error condition
00200    if(($http_status_no == 403 || $http_status_no == 404 || $http_status_no == 405 || $http_status_no == 500 || strstr($res, 'Bad Request') || strstr($res, 'Bad HTTP Request') || trim($res) == '') && !$useGet) {
00201       return rtadmin_validate_url($url, true, $redirectsAllowed-1);
00202    }
00203 
00204    return false;
00205 }
00206 
00207 function smarty_rtadmin_validate_url ($search, $errors) {
00208    // Make sure any prior content is flushed to the user's browser.
00209    flush();
00210    ob_flush();
00211 
00212    if (!is_array($errors)) $errors = array();
00213 
00214    if (!rtadmin_validate_url($search->getUrl())) $errors[] = array('url' => $search->getUrl(), 'id' => $search->getSearchId());
00215    if ($search->getSearchUrl() && !rtadmin_validate_url($search->getSearchUrl())) $errors[] = array('url' => $search->getSearchUrl(), 'id' => $search->getSearchId());
00216 
00217    return $errors;
00218 }
00219 
00220 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7