Example #1
0
 /**
  * Check if the user can access to the given URL.
  *
  * @param array $params The params to check.
  *
  * @return bool
  */
 public function check(array $params = [])
 {
     if (!$this->request->session()->read('Auth.User')) {
         return false;
     }
     $params += ['_base' => false];
     $url = Router::url($params);
     $params = Router::parse($url);
     $user = [$this->Authorize->config('userModel') => $this->request->session()->read('Auth.User')];
     $request = new Request();
     $request->addParams($params);
     $action = $this->Authorize->action($request);
     return $this->Acl->check($user, $action);
 }
Example #2
0
 /**
  * Tests that the string template form `Form::field()` can be overridden.
  */
 public function testFieldTemplateOverride()
 {
     $result = $this->form->field('name', array('type' => 'text'));
     $this->form->config(array('templates' => array('field' => '{:label}{:input}{:error}')));
     $result = $this->form->field('name', array('type' => 'text'));
     $this->assertTags($result, array('label' => array('for' => 'Name'), 'Name', '/label', 'input' => array('type' => 'text', 'name' => 'name', 'id' => 'Name')));
 }
Example #3
0
 /**
  * Verifies the expiry and MAC for the cookie
  *
  * @param string $cookie String from the client
  * @return bool
  */
 public function verifySecureCookie($key)
 {
     $cookieFile = glob($this->_app->config('cookies.savepath') . 'cookies.*');
     if (is_array($cookieFile)) {
         foreach ($cookieFile as $file) {
             if (file_exists($file)) {
                 $exp = $this->_app->hook->maybe_unserialize(file_get_contents($file));
             }
         }
     }
     /**
      * If the cookie exists and it is expired, delete it
      * from the server side.
      */
     if (file_exists($file) && $exp['exp'] < time()) {
         unlink($file);
     }
     if ($this->getCookieVars($key, 'exp') === null || $this->getCookieVars($key, 'exp') < time()) {
         // The cookie has expired
         return false;
     }
     $mac = sprintf("exp=%s&data=%s", urlencode($this->getCookieVars($key, 'exp')), urlencode($this->getCookieVars($key, 'data')));
     $hash = hash_hmac($this->_app->config('cookies.crypt'), $mac, $this->_app->config('cookies.secret.key'));
     if (!hash_equals($this->getCookieVars($key, 'digest'), $hash)) {
         // The cookie has been compromised
         return false;
     }
     return true;
 }
 public function testTemplateRemapping()
 {
     $result = $this->form->password('passwd');
     $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'passwd')));
     $this->form->config(array('templates' => array('password' => 'text')));
     $result = $this->form->password('passwd');
     $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'passwd')));
 }
        @access public
        @throws Exception object
        @return string
	*/
    public function auth_user()
    {
        try {
            self::response($this->ApiBC->auth_user($this->Post));
        } catch (Exception $e) {
            throw $e;
        }
Example #6
0
 /**
  * 分析标签属性 正则方式
  * @access public
  * @param string $str 标签属性字符串
  * @param string $name 标签名
  * @param string $alias 别名
  * @return array
  */
 public function parseAttr($str, $name, $alias = '')
 {
     $regex = '/\\s+(?>(?<name>[\\w-]+)\\s*)=(?>\\s*)([\\"\'])(?<value>(?:(?!\\2).)*)\\2/is';
     $result = [];
     if (preg_match_all($regex, $str, $matches)) {
         foreach ($matches['name'] as $key => $val) {
             $result[$val] = $matches['value'][$key];
         }
         if (!isset($this->tags[$name])) {
             // 检测是否存在别名定义
             foreach ($this->tags as $key => $val) {
                 if (isset($val['alias'])) {
                     $array = (array) $val['alias'];
                     if (in_array($name, explode(',', $array[0]))) {
                         $tag = $val;
                         $type = !empty($array[1]) ? $array[1] : 'type';
                         $result[$type] = $name;
                         break;
                     }
                 }
             }
         } else {
             $tag = $this->tags[$name];
             // 设置了标签别名
             if (!empty($alias) && isset($tag['alias'])) {
                 $type = !empty($tag['alias'][1]) ? $tag['alias'][1] : 'type';
                 $result[$type] = $alias;
             }
         }
         if (!empty($tag['must'])) {
             $must = explode(',', $tag['must']);
             foreach ($must as $name) {
                 if (!isset($result[$name])) {
                     throw new Exception('_PARAM_ERROR_:' . $name);
                 }
             }
         }
     } else {
         // 允许直接使用表达式的标签
         if (!empty($this->tags[$name]['expression'])) {
             static $_taglibs;
             if (!isset($_taglibs[$name])) {
                 $_taglibs[$name][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $name);
                 $_taglibs[$name][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\'));
             }
             $result['expression'] = substr($str, $_taglibs[$name][0], -$_taglibs[$name][1]);
             // 清除自闭合标签尾部/
             $result['expression'] = rtrim($result['expression'], '/');
             $result['expression'] = trim($result['expression']);
         } elseif (empty($this->tags[$name]) || !empty($this->tags[$name]['attr'])) {
             throw new Exception('_XML_TAG_ERROR_:' . $name);
         }
     }
     return $result;
 }
Example #7
0
 /**
  * Checks if the given user has permission to perform an action.
  *
  * @param array $params The params to check.
  *
  * @return string
  */
 public function hasPermission(array $params = [])
 {
     $params += ['controller' => 'Permissions', '_base' => false, 'prefix' => 'chat'];
     $url = Router::url($params);
     $params = Router::parse($url);
     $request = new Request();
     $request->addParams($params);
     $action = $this->Authorize->action($request);
     $user = [$this->Authorize->config('userModel') => $this->_session->read('Auth.User')];
     return $this->Acl->check($user, $action);
 }
Example #8
0
 /**
  * 分析标签属性 正则方式
  * @access public
  * @param string $str 标签属性字符串
  * @param string $tag 标签名
  * @return array
  */
 public function parseAttr($str, $tag)
 {
     if (ini_get('magic_quotes_sybase')) {
         $str = str_replace('\\"', '\'', $str);
     }
     $regex = '/\\s+(?>(?<name>\\w+)\\s*)=(?>\\s*)([\\"\'])(?<value>(?:(?!\\2).)*)\\2/is';
     $result = [];
     if (preg_match_all($regex, $str, $matches)) {
         foreach ($matches['name'] as $key => $val) {
             $result[$val] = $matches['value'][$key];
         }
         $tag = strtolower($tag);
         if (!isset($this->tags[$tag])) {
             // 检测是否存在别名定义
             foreach ($this->tags as $key => $val) {
                 if (isset($val['alias']) && in_array($tag, explode(',', $val['alias']))) {
                     $item = $val;
                     break;
                 }
             }
         } else {
             $item = $this->tags[$tag];
         }
         if (!empty($item['must'])) {
             $must = explode(',', $item['must']);
             foreach ($must as $name) {
                 if (!isset($result[$name])) {
                     throw new Exception('_PARAM_ERROR_:' . $name);
                 }
             }
         }
     } else {
         // 允许直接使用表达式的标签
         if (!empty($this->tags[$tag]['expression'])) {
             static $_taglibs;
             if (!isset($_taglibs[$tag])) {
                 $_taglibs[$tag][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $tag);
                 $_taglibs[$tag][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\'));
             }
             $result['expression'] = substr($str, $_taglibs[$tag][0], -$_taglibs[$tag][1]);
             // 清除自闭合标签尾部/
             $result['expression'] = rtrim($result['expression'], '/');
             $result['expression'] = trim($result['expression']);
         } elseif (empty($this->tags[$tag]) || !empty($this->tags[$tag]['attr'])) {
             throw new Exception('_XML_TAG_ERROR_:' . $tag);
         }
     }
     return $result;
 }
Example #9
0
 /**
  * Constructor is private so that another instance isn't created.
  *
  * @since 6.2.0
  */
 private function __construct(\Liten\Liten $liten = null)
 {
     // Make sure the script can handle large folders/files for zip and API calls.
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '1024M');
     if (function_exists('enable_url_ssl')) {
         $protocol = 'https://';
     } else {
         $protocol = 'http://';
     }
     $this->url = $protocol . $this->_baseURL . '/';
     $this->patch_url = $this->getReleaseJsonUrl();
     $this->local_base_dir = BASE_PATH;
     $this->local_backup_dir = '/tmp/';
     $this->app = !empty($liten) ? $liten : \Liten\Liten::getInstance();
     $this->update = new \VisualAppeal\AutoUpdate(rtrim($this->app->config('file.savepath'), '/'), rtrim(BASE_PATH, '/'), 1800);
     $this->current_release = $this->getCurrentRelease();
     $this->current_release_value = $this->current_release['current_release']['current_release_value'];
 }
Example #10
0
 /**
  * Return data on a course view (this will be some form of HTML)
  *
  * @param   object   $course    Current course
  * @param   object   $offering  Name of the component
  * @param   boolean  $describe  Return plugin description only?
  * @return  object
  */
 public function onCourse($course, $offering, $describe = false)
 {
     $response = with(new \Hubzero\Base\Object())->set('name', $this->_name)->set('title', Lang::txt('PLG_COURSES_' . strtoupper($this->_name)))->set('description', JText::_('PLG_COURSES_' . strtoupper($this->_name) . '_BLURB'))->set('default_access', $this->params->get('plugin_access', 'members'))->set('display_menu_tab', true)->set('icon', 'f0ae');
     if ($describe) {
         return $response;
     }
     if (!($active = Request::getVar('active'))) {
         Request::setVar('active', $active = $this->_name);
     }
     // Check to see if user is member and plugin access requires members
     $sparams = new \Hubzero\Config\Registry($course->offering()->section()->get('params'));
     if (!$course->offering()->section()->access('view') && !$sparams->get('preview', 0)) {
         $response->set('html', '<p class="info">' . Lang::txt('COURSES_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>');
         return $response;
     }
     // Determine if we need to return any HTML (meaning this is the active plugin)
     if ($response->get('name') == $active) {
         $this->css();
         // Course and action
         $this->course = $course;
         $action = strtolower(Request::getWord('action', ''));
         $this->view = $this->view('default', 'outline');
         $this->view->option = Request::getCmd('option', 'com_courses');
         $this->view->controller = Request::getWord('controller', 'course');
         $this->view->course = $course;
         $this->view->offering = $offering;
         $this->view->config = $course->config();
         switch ($action) {
             case 'build':
                 $this->_build();
                 break;
             default:
                 $this->js();
                 $this->_display();
                 break;
         }
         $response->set('html', $this->view->loadTemplate());
     }
     // Return the output
     return $response;
 }
Example #11
0
 /**
  * Decide on which Webception configuration file to load
  * based on the 'test' query string parameter.
  *
  * If the test config is not found, it falls back to the default file.
  *
  * @param  object $app Slim's App object.
  * @return array  Array of the application config.
  */
 function get_webception_config($app)
 {
     $config = FALSE;
     $test_type = $app->request()->params('test');
     $webception_config = $app->config('webception');
     // If the test query string parameter is set,
     // a test config will be loaded.
     if ($test_type !== NULL) {
         // Sanitize the test type.
         $test_type = trim(strtolower(remove_file_extension($test_type)));
         // Filter the test type into the test string.
         $test_config = sprintf($webception_config['test'], $test_type);
         // Load the config if it can be found
         if (file_exists($test_config)) {
             $config = (require_once $test_config);
         }
     }
     if ($config == FALSE) {
         $config = (require_once $webception_config['config']);
     }
     return $config;
 }
Example #12
0
 /**
  * Event call to return data for a specific project
  *
  * @param      object  $model           Project model
  * @param      string  $action			Plugin task
  * @param      string  $areas  			Plugins to return data
  * @return     array   Return array of html
  */
 public function onProject($model, $action = 'view', $areas = null)
 {
     $arr = array('html' => '', 'metadata' => '', 'message' => '', 'error' => '');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Check authorization
     if ($model->exists() && !$model->access('member')) {
         return $arr;
     }
     // Model
     $this->model = $model;
     // Load component configs
     $this->_config = $model->config();
     $this->gitpath = $this->_config->get('gitpath', '/opt/local/bin/git');
     // Incoming
     $raw_op = Request::getInt('raw_op', 0);
     $action = $action ? $action : Request::getVar('action', 'list');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return $arr;
         }
     }
     $this->_database = App::get('db');
     $this->_uid = User::get('id');
     // Publishing?
     if ($action == 'browser') {
         return $this->browser();
     }
     if ($action == 'select') {
         return $this->select();
     }
     $act_func = 'act_' . $action;
     if (!method_exists($this, $act_func)) {
         if ($raw_op) {
             print json_encode(array('status' => 'success', 'data' => $table));
             exit;
         } else {
             $act_func = 'act_list';
         }
     }
     // detect CR as new line
     ini_set('auto_detect_line_endings', true);
     if ($raw_op) {
         $this->{$act_func}();
         exit;
     } else {
         Document::addScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
         Document::addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js');
         Document::addStyleSheet('//ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css');
         Document::addScript('/core/plugins/projects/databases/res/main.js');
         Document::addStyleSheet('/core/plugins/projects/databases/res/main.css');
         if (file_exists(__DIR__ . '/res/ds.' . $action . '.js')) {
             Document::addScript('/core/plugins/projects/databases/res/ds.' . $action . '.js');
         }
         if (file_exists(__DIR__ . '/res/ds.' . $action . '.css')) {
             Document::addStyleSheet('/core/plugins/projects/databases/res/ds.' . $action . '.css');
         }
         return $this->{$act_func}();
     }
 }
Example #13
0
 /**
  * Send hub message
  *
  * @param      string 	$option
  * @param      object 	$project    Models\Project
  * @param      array 	$addressees
  * @param      string 	$subject
  * @param      string 	$component
  * @param      string 	$layout
  * @param      string 	$message
  * @param      string 	$reviewer
  * @return     void
  */
 public static function sendHUBMessage($option, $project, $addressees = array(), $subject = '', $component = '', $layout = 'admin', $message = '', $reviewer = '')
 {
     if (!$layout || !$subject || !$component || empty($addressees)) {
         return false;
     }
     // Is messaging turned on?
     if ($project->config()->get('messaging') != 1) {
         return false;
     }
     // Set up email config
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PROJECTS');
     $from['email'] = Config::get('mailfrom');
     // Html email
     $from['multipart'] = md5(date('U'));
     // Message body
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site', 'name' => 'emails', 'layout' => $layout . '_plain'));
     $eview->option = $option;
     $eview->project = $project;
     $eview->message = $message;
     $eview->reviewer = $reviewer;
     $body = array();
     $body['plaintext'] = $eview->loadTemplate(false);
     $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
     // HTML email
     $eview->setLayout($layout . '_html');
     $body['multipart'] = $eview->loadTemplate();
     $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
     // Send HUB message
     Event::trigger('xmessage.onSendMessage', array($component, $subject, $body, $from, $addressees, $option));
 }
 public function __construct(\Liten\Liten $liten = null)
 {
     $this->app = !empty($liten) ? $liten : \Liten\Liten::getInstance();
     if (ETSIS_FILE_CACHE_LOW_RAM && function_exists('memory_get_usage')) {
         $limit = _trim(ini_get('memory_limit'));
         $mod = strtolower($limit[strlen($limit) - 1]);
         switch ($mod) {
             case 'g':
                 $limit *= 1073741824;
                 break;
             case 'm':
                 $limit *= 1048576;
                 break;
             case 'k':
                 $limit *= 1024;
                 break;
         }
         if ($limit <= 0) {
             $limit = 0;
         }
         $this->_memory_limit = $limit;
         $limit = _trim(ETSIS_FILE_CACHE_LOW_RAM);
         $mod = strtolower($limit[strlen($limit) - 1]);
         switch ($mod) {
             case 'g':
                 $limit *= 1073741824;
                 break;
             case 'm':
                 $limit *= 1048576;
                 break;
             case 'k':
                 $limit *= 1024;
                 break;
         }
         $this->_memory_low = $limit;
     } else {
         $this->_memory_limit = 0;
         $this->_memory_low = 0;
     }
     /**
      * Filter sets whether caching is enabled or not.
      *
      * @since 6.2.0
      * @var bool
      */
     $this->enable = $this->app->hook->apply_filter('enable_caching', true);
     $this->persist = $this->enable && true;
     /**
      * File system cache directory.
      */
     $dir = $this->app->config('file.savepath') . 'cache';
     /**
      * Fiter the file cache directory in order to override it
      * in case some systems are having issues.
      *
      * @since 6.2.0
      * @param string $dir
      *            The directory where file system cache files are saved.
      */
     $cacheDir = $this->app->hook->apply_filter('filesystem_cache_dir', $dir);
     /**
      * If the cache directory does not exist, the create it first
      * before trying to call it for use.
      */
     if (!is_dir($cacheDir) || !file_exists($cacheDir)) {
         _mkdir($cacheDir);
     }
     /**
      * If the directory isn't writable, throw an exception.
      */
     if (!etsis_is_writable($cacheDir)) {
         return new \app\src\Core\Exception\Exception(_t('Could not create the file cache directory.'), 'cookie_cache');
     }
     /**
      * Cache directory is set.
      */
     $this->_dir = $cacheDir . DS;
 }
Example #15
0
 /**
  * Send email
  *
  * @param      object 	$publication   Models\Publication
  * @param      array 	$addressees
  * @param      string 	$subject
  * @param      string 	$message
  * @return     void
  */
 public static function notify($publication, $addressees = array(), $subject = NULL, $message = NULL, $hubMessage = false)
 {
     if (!$subject || !$message || empty($addressees)) {
         return false;
     }
     // Is messaging turned on?
     if ($publication->config('email') != 1) {
         return false;
     }
     // Component params
     $params = Component::params('com_publications');
     $address = $params->get('curatorreplyto');
     // Set up email config
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_PUBLICATIONS');
     if (!isset($address) || $address == '') {
         $from['email'] = Config::get('mailfrom');
     } else {
         $from['email'] = $address;
     }
     // Html email
     $from['multipart'] = md5(date('U'));
     // Get message body
     $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'site', 'name' => 'emails', 'layout' => '_plain'));
     $eview->publication = $publication;
     $eview->message = $message;
     $eview->subject = $subject;
     $body = array();
     $body['plaintext'] = $eview->loadTemplate(false);
     $body['plaintext'] = str_replace("\n", "\r\n", $body['plaintext']);
     // HTML email
     $eview->setLayout('_html');
     $body['multipart'] = $eview->loadTemplate();
     $body['multipart'] = str_replace("\n", "\r\n", $body['multipart']);
     $body_plain = is_array($body) && isset($body['plaintext']) ? $body['plaintext'] : $body;
     $body_html = is_array($body) && isset($body['multipart']) ? $body['multipart'] : NULL;
     // Send HUB message
     if ($hubMessage) {
         Event::trigger('xmessage.onSendMessage', array('publication_status_changed', $subject, $body, $from, $addressees, 'com_publications'));
     } else {
         // Send email
         foreach ($addressees as $userid) {
             $user = User::getInstance(trim($userid));
             if (!$user->get('id')) {
                 continue;
             }
             $mail = new \Hubzero\Mail\Message();
             $mail->setSubject($subject)->addTo($user->get('email'), $user->get('name'))->addFrom($from['email'], $from['name'])->setPriority('normal');
             $mail->addPart($body_plain, 'text/plain');
             if ($body_html) {
                 $mail->addPart($body_html, 'text/html');
             }
             $mail->send();
         }
     }
 }
Example #16
0
 /**
  * Return data on a course view (this will be some form of HTML)
  *
  * @param   object   $course    Current course
  * @param   object   $offering  Name of the component
  * @param   boolean  $describe  Return plugin description only?
  * @return  object
  */
 public function onCourse($course, $offering, $describe = false)
 {
     $response = with(new \Hubzero\Base\Object())->set('name', $this->_name)->set('title', Lang::txt('PLG_COURSES_' . strtoupper($this->_name)))->set('description', JText::_('PLG_COURSES_' . strtoupper($this->_name) . '_BLURB'))->set('default_access', $this->params->get('plugin_access', 'members'))->set('display_menu_tab', true)->set('icon', 'f086');
     if ($describe) {
         return $response;
     }
     if (!($active = Request::getVar('active'))) {
         Request::setVar('active', $active = $this->_name);
     }
     $this->config = $course->config();
     $this->course = $course;
     $this->offering = $offering;
     $this->database = App::get('db');
     $this->params->merge(new \Hubzero\Config\Registry($offering->section()->get('params')));
     // Determine if we need to return any HTML (meaning this is the active plugin)
     if ($response->get('name') == $active) {
         $this->_active = $this->_name;
         $this->section = new \Components\Forum\Tables\Section($this->database);
         $this->sections = $this->section->getRecords(array('state' => 1, 'scope' => 'course', 'scope_id' => $this->offering->get('id'), 'sort_Dir' => 'DESC', 'sort' => 'ordering ASC, created ASC, title'));
         //option and paging vars
         $this->option = 'com_courses';
         $this->name = 'courses';
         $this->limitstart = Request::getInt('limitstart', 0);
         $this->limit = Request::getInt('limit', 500);
         $action = '';
         $u = strtolower(Request::getWord('unit', ''));
         if ($u == 'manage') {
             $action = 'sections';
             $b = Request::getVar('group', '');
             if ($b) {
                 Request::setVar('section', $b);
             }
             $c = Request::getVar('asset', '');
             switch ($c) {
                 case 'orderdown':
                     $action = 'orderdown';
                     break;
                 case 'orderup':
                     $action = 'orderup';
                     break;
                 case 'edit':
                     $action = 'editsection';
                     break;
                 case 'delete':
                     $action = 'deletesection';
                     break;
                 case 'new':
                     $action = 'editcategory';
                     break;
                 default:
                     if ($c) {
                         Request::setVar('category', $c);
                         $action = 'editcategory';
                     }
                     $d = Request::getVar('d', '');
                     switch ($d) {
                         case 'edit':
                             $action = 'editcategory';
                             break;
                         case 'delete':
                             $action = 'deletecategory';
                             break;
                         default:
                             //$d = Request::setVar('thread', $c);
                             //$action = 'threads';
                             break;
                     }
                     break;
             }
         }
         if (Request::getVar('file', '')) {
             $action = 'download';
         }
         $action = Request::getVar('action', $action, 'post');
         if (!$action) {
             $action = Request::getVar('action', $action, 'get');
         }
         if ($action == 'edit' && Request::getInt('post', 0)) {
             $action = 'editthread';
         }
         //push the stylesheet to the view
         $this->css();
         $this->base = $this->offering->link() . '&active=' . $this->_name;
         Pathway::append(Lang::txt('PLG_COURSES_' . strtoupper($this->_name)), $this->base);
         switch ($action) {
             case 'sections':
                 $response->set('html', $this->sections());
                 break;
             case 'newsection':
                 $response->set('html', $this->sections());
                 break;
             case 'editsection':
                 $response->set('html', $this->sections());
                 break;
             case 'savesection':
                 $response->set('html', $this->savesection());
                 break;
             case 'deletesection':
                 $response->set('html', $this->deletesection());
                 break;
             case 'categories':
                 $response->set('html', $this->categories());
                 break;
             case 'savecategory':
                 $response->set('html', $this->savecategory());
                 break;
             case 'newcategory':
                 $response->set('html', $this->editcategory());
                 break;
             case 'editcategory':
                 $response->set('html', $this->editcategory());
                 break;
             case 'deletecategory':
                 $response->set('html', $this->deletecategory());
                 break;
             case 'threads':
                 $response->set('html', $this->threads());
                 break;
             case 'savethread':
                 $response->set('html', $this->savethread());
                 break;
             case 'editthread':
                 $response->set('html', $this->editthread());
                 break;
             case 'deletethread':
                 $response->set('html', $this->deletethread());
                 break;
             case 'orderup':
                 $response->set('html', $this->orderup());
                 break;
             case 'orderdown':
                 $response->set('html', $this->orderdown());
                 break;
             case 'download':
                 $response->set('html', $this->download());
                 break;
             case 'search':
                 $response->set('html', $this->panel());
                 break;
             default:
                 $response->set('html', $this->panel());
                 break;
         }
     }
     $tModel = new \Components\Forum\Tables\Post($this->database);
     $response->set('meta_count', $tModel->getCount(array('scope' => 'course', 'scope_id' => $offering->get('id'), 'state' => array(1, 3), 'parent' => 0, 'scope_sub_id' => $this->params->get('discussions_threads', 'all') != 'all' ? $course->offering()->section()->get('id') : null)));
     // Return the output
     return $response;
 }
Example #17
0
 /**
  * Configuration to use when send email
  *
  * @param mixed $config String with configuration name (from email.php), array with config or null to return current config
  * @return mixed
  */
 public function config($config = null)
 {
     if ($config === null) {
         return $this->_config;
     }
     if (is_array($config)) {
         $this->_config = $config;
     } else {
         $this->_config = (string) $config;
     }
     if ($this->_transportClass) {
         $this->_transportClass->config($this->_config);
     }
     return $this;
 }
Example #18
0
 /**
  * Get permissions for a user
  *
  * @param   object  $page
  * @return  boolean
  */
 public function authorise($page)
 {
     // Allow access to all options
     $page->config()->set('access-page-manage', true);
     $page->config()->set('access-page-create', true);
     $page->config()->set('access-page-delete', true);
     $page->config()->set('access-page-edit', true);
     $page->config()->set('access-page-modify', true);
     $page->config()->set('access-comment-view', true);
     $page->config()->set('access-comment-create', true);
     $page->config()->set('access-comment-delete', true);
     $page->config()->set('access-comment-edit', true);
     return true;
 }
Example #19
0
 /**
  * Event call to return data for a specific project
  *
  * @param      object  $model           Project model
  * @param      string  $action			Plugin task
  * @param      string  $areas  			Plugins to return data
  * @return     array   Return array of html
  */
 public function onProject($model, $action = '', $areas = NULL)
 {
     // What's the task?
     $this->_task = $action ? $action : Request::getVar('action');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Model
     $this->model = $model;
     $tasks = array('browser', 'select', 'parseurl', 'parsedoi', 'addcitation', 'deletecitation', 'newcite', 'editcite', 'savecite');
     // Publishing?
     if (in_array($this->_task, $tasks)) {
         // Set vars
         $this->_database = App::get('db');
         $this->_uid = User::get('id');
         // Load component configs
         $this->_config = $model->config();
         $this->_pubconfig = Component::params('com_publications');
         // Actions
         switch ($this->_task) {
             case 'browser':
             default:
                 $html = $this->browser();
                 break;
             case 'parseurl':
                 $html = $this->parseUrl();
                 break;
             case 'parsedoi':
                 $html = $this->parseDoi();
                 break;
             case 'addcitation':
                 $html = $this->addCitation();
                 break;
             case 'deletecitation':
                 $html = $this->deleteCitation();
                 break;
             case 'select':
             case 'newcite':
                 $html = $this->select();
                 break;
             case 'editcite':
                 $html = $this->editcite();
                 break;
             case 'savecite':
                 $html = $this->savecite();
                 break;
         }
         $arr = array('html' => $html, 'metadata' => '');
         return $arr;
     }
     // Nothing to return
     return false;
 }
Example #20
0
 /**
  * Event call to return data for a specific project
  *
  * @param   object  $model   Project model
  * @param   string  $action  Plugin task
  * @param   string  $areas   Plugins to return data
  * @return  array   Return array of html
  */
 public function onProject($model, $action = '', $areas = NULL)
 {
     $returnhtml = true;
     $arr = array('html' => '', 'metadata' => '');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Check that project exists
     if (!$model->exists()) {
         return $arr;
     }
     // Check authorization
     if (!$model->access('member')) {
         return $arr;
     }
     // Model
     $this->model = $model;
     // Are we returning HTML?
     if ($returnhtml) {
         $ajax = Request::getInt('ajax', 0);
         // Record page visit
         if (!$ajax) {
             // First-time visit, record join activity
             $model->recordFirstJoinActivity();
             // Record page visit
             $model->recordVisit();
         }
         // Hide welcome screen?
         $c = Request::getInt('c', 0);
         if ($c) {
             $model->member()->saveParam($model->get('id'), User::get('id'), $param = 'hide_welcome', 1);
             App::redirect(Route::url($model->link()));
             return;
         }
         // Set vars
         $this->_config = $model->config();
         $this->_task = Request::getVar('action', '');
         $this->_database = App::get('db');
         $this->_uid = User::get('id');
         switch ($this->_task) {
             case 'delete':
                 $arr['html'] = $this->_delete();
                 break;
             case 'save':
                 $arr['html'] = $this->_save();
                 break;
             case 'savecomment':
                 $arr['html'] = $this->_saveComment();
                 break;
             case 'deletecomment':
                 $arr['html'] = $this->_deleteComment();
                 break;
             case 'update':
                 $arr['html'] = $this->updateFeed();
                 break;
             case 'page':
             default:
                 $arr['html'] = $this->page();
                 break;
         }
     }
     // Return data
     return $arr;
 }
Example #21
0
 /**
  * Return data on a course view (this will be some form of HTML)
  *
  * @param   object   $course    Current course
  * @param   object   $offering  Name of the component'
  * @param   boolean  $describe  Return plugin description only?
  * @return  object
  */
 public function onCourse($course, $offering, $describe = false)
 {
     $response = with(new \Hubzero\Base\Object())->set('name', $this->_name)->set('title', Lang::txt('PLG_COURSES_' . strtoupper($this->_name)))->set('description', JText::_('PLG_COURSES_' . strtoupper($this->_name) . '_BLURB'))->set('default_access', $this->params->get('plugin_access', 'members'))->set('display_menu_tab', true)->set('icon', 'f05a');
     if ($describe) {
         return $response;
     }
     if (!($active = Request::getVar('active'))) {
         Request::setVar('active', $active = $this->_name);
     }
     // Section specific pages
     $total = $offering->pages(array('count' => true, 'section_id' => $offering->section()->get('id'), 'active' => 1), true);
     // Offering specific pages
     $total += $offering->pages(array('count' => true, 'section_id' => 0, 'active' => 1), true);
     // All course pages
     $total += $offering->pages(array('count' => true, 'course_id' => 0, 'offering_id' => 0, 'active' => 1), true);
     // Determine if we need to return any HTML (meaning this is the active plugin)
     if ($response->get('name') == $active) {
         $action = strtolower(Request::getWord('group', ''));
         if ($action && $action != 'edit' && $action != 'delete') {
             $action = 'download';
         }
         $active = strtolower(Request::getWord('unit', ''));
         if ($active == 'add') {
             $action = 'add';
         }
         if ($active == 'download') {
             $action = 'download';
         }
         if ($act = strtolower(Request::getWord('action', ''))) {
             $action = $act;
         }
         $this->view = $this->view('default', 'pages');
         $this->view->option = Request::getCmd('option', 'com_courses');
         $this->view->controller = Request::getWord('controller', 'course');
         $this->view->course = $course;
         $this->view->offering = $offering;
         $this->view->config = $course->config();
         switch ($action) {
             case 'add':
             case 'edit':
                 $this->_edit();
                 break;
             case 'save':
                 $this->_save();
                 break;
             case 'delete':
                 $this->_delete();
                 break;
             case 'upload':
                 $this->_fileUpload();
                 break;
             case 'download':
                 $this->_fileDownload();
                 break;
             case 'list':
                 $this->_fileList();
                 break;
             case 'remove':
                 $this->_fileDelete();
                 break;
             default:
                 $this->_list();
                 break;
         }
         if (Request::getInt('no_html', 0)) {
             ob_clean();
             header('Content-type: text/plain');
             echo $this->view->loadTemplate();
             exit;
         }
         $response->set('html', $this->view->loadTemplate());
     }
     $response->set('meta_count', $total);
     // Return the output
     return $response;
 }
Example #22
0
 /**
  * Display a page
  *
  * @return  void
  */
 public function displayTask()
 {
     // Set the page's <title> tag
     if ($this->page->get('scope') == 'site') {
         Document::setTitle(Lang::txt('COM_WIKI'));
     }
     Document::setTitle(Document::getTitle() . ': ' . $this->page->title);
     // Set the pathway
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller);
     }
     // Is this a special page?
     if ($this->page->getNamespace() == 'special') {
         // Ensure the special page exists
         if (!in_array(strtolower($this->page->stripNamespace()), $this->book->special())) {
             App::abort(404, Lang::txt('COM_WIKI_WARNING_PAGE_DOES_NOT_EXIST'));
         }
         $this->view->setLayout('special')->set('layout', $this->page->stripNamespace())->set('page', $this->page)->set('book', $this->book)->set('sub', $this->page->get('scope') != 'site')->display();
         return;
     }
     // Does a page exist for the given pagename?
     if ($this->page->isNew() || $this->page->isDeleted()) {
         if (!$this->page->access('create')) {
             App::abort(404, Lang::txt('COM_WIKI_WARNING_PAGE_DOES_NOT_EXIST'));
         }
         $this->view->set('page', $this->page)->set('book', $this->book)->set('sub', $this->page->get('scope') != 'site')->setLayout('doesnotexist')->display();
         return;
     }
     /*if ($this->page->get('scope') != $this->book->get('scope'))
     		{
     			App::redirect(
     				Route::url($this->page->link())
     			);
     		}*/
     // Check if the page is group restricted and the user is authorized
     if (!$this->page->access('view', 'page')) {
         App::abort(403, Lang::txt('COM_WIKI_WARNING_NOT_AUTH'));
     }
     $parents = array();
     if ($this->page->get('parent')) {
         $parents = $this->page->ancestors();
         foreach ($parents as $p) {
             Pathway::append($p->get('title'), $p->link());
         }
     }
     Pathway::append($this->page->title, $this->page->link());
     // Retrieve a specific version if given
     if ($version = Request::getInt('version', 0)) {
         $revision = $this->page->versions()->whereEquals('version', $version)->row();
     } else {
         $revision = $this->page->version;
     }
     if (!$revision->get('id')) {
         $this->view->set('page', $this->page)->set('version', $version ? $version : $this->page->get('version_id'))->set('book', $this->book)->set('sub', $this->page->get('scope') != 'site')->setLayout('nosuchrevision')->display();
         return;
     }
     // Parse the text
     if (intval($this->book->config('cache', 1))) {
         // Caching
         if (!($rendered = Cache::get('wiki.r' . $revision->get('id')))) {
             $rendered = $revision->content($this->page);
             Cache::put('wiki.r' . $revision->get('id'), $rendered, intval($this->book->config('cache_time', 15)));
         }
         $revision->set('pagehtml', $rendered);
     } else {
         $revision->set('pagehtml', $revision->content($this->page));
     }
     //App::get('config')->get('debug') || App::get('config')->get('profile') ? App::get('profiler')->mark('afterWikiParse') : null;
     // Handle display events
     $event = new \stdClass();
     $results = Event::trigger('wiki.onAfterDisplayTitle', array($this->page, &$revision, $this->config));
     $event->afterDisplayTitle = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onBeforeDisplayContent', array(&$this->page, &$revision, $this->config));
     $event->beforeDisplayContent = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onAfterDisplayContent', array(&$this->page, &$revision, $this->config));
     $event->afterDisplayContent = trim(implode("\n", $results));
     $this->page->set('event', $event);
     // Output view
     if (Request::getVar('format') == 'raw') {
         $this->view->setLayout('display_raw');
     }
     $this->view->set('page', $this->page)->set('revision', $revision)->set('parents', $parents)->set('sub', $this->page->get('scope') != 'site')->set('base_path', $this->_base_path)->setErrors($this->getErrors())->display();
 }
Example #23
0
 /**
  * Event call to return data for a specific project
  *
  * @param      object  $model           Project model
  * @param      string  $action			Plugin task
  * @param      string  $areas  			Plugins to return data
  * @return     array   Return array of html
  */
 public function onProject($model, $action = '', $areas = null)
 {
     $returnhtml = true;
     $arr = array('html' => '', 'metadata' => '');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Check that project exists
     if (!$model->exists()) {
         return $arr;
     }
     // Check authorization
     if (!$model->access('member')) {
         return $arr;
     }
     // Model
     $this->model = $model;
     // Are we returning HTML?
     if ($returnhtml) {
         // Set vars
         $this->_task = $action ? $action : Request::getVar('action', '');
         $this->_database = App::get('db');
         $this->_uid = User::get('id');
         $this->_config = $model->config();
         switch ($this->_task) {
             case 'edit':
             case 'setup':
                 $arr['html'] = $this->display(1);
                 break;
             case 'delete':
             case 'deleteit':
                 $arr['html'] = $this->delete();
                 break;
             case 'changerole':
             case 'assignrole':
                 $arr['html'] = $this->_changeRole();
                 break;
             case 'changeowner':
                 $arr['html'] = $this->_changeOwner();
                 break;
             case 'save':
                 $arr['html'] = $this->_save();
                 break;
             case 'quit':
                 $arr['html'] = $this->_quit();
                 break;
             case 'view':
             default:
                 $arr['html'] = $this->display();
                 break;
             case 'select':
             case 'newauthor':
                 $arr['html'] = $this->select();
                 break;
         }
     }
     // Return data
     return $arr;
 }
Example #24
0
 /**
  * Get disk space
  *
  * @param      object  	$model
  *
  * @return     string
  */
 public function pubDiskSpace($model)
 {
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'diskspace'));
     // Include styling and js
     \Hubzero\Document\Assets::addPluginStylesheet('projects', 'files', 'diskspace');
     \Hubzero\Document\Assets::addPluginScript('projects', 'files', 'diskspace');
     $database = App::get('db');
     // Build query
     $filters = array();
     $filters['limit'] = Request::getInt('limit', 25);
     $filters['start'] = Request::getInt('limitstart', 0);
     $filters['sortby'] = Request::getVar('t_sortby', 'title');
     $filters['sortdir'] = Request::getVar('t_sortdir', 'ASC');
     $filters['project'] = $model->get('id');
     $filters['ignore_access'] = 1;
     $filters['dev'] = 1;
     // get dev versions
     // Instantiate project publication
     $objP = new \Components\Publications\Tables\Publication($database);
     // Get all publications
     $view->rows = $objP->getRecords($filters);
     // Get used space
     $view->dirsize = \Components\Publications\Helpers\Html::getDiskUsage($view->rows);
     $view->params = $model->params;
     $view->quota = $view->params->get('pubQuota') ? $view->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b');
     // Get total count
     $view->total = $objP->getCount($filters);
     $view->project = $model;
     $view->option = $this->_option;
     $view->title = isset($this->_area['title']) ? $this->_area['title'] : '';
     return $view->loadTemplate();
 }
Example #25
0
 /**
  * Event call to return data for a specific project
  *
  * @param      object  $model           Project model
  * @param      string  $action			Plugin task
  * @param      string  $areas  			Plugins to return data
  * @return     array   Return array of html
  */
 public function onProject($model, $action = '', $areas = NULL)
 {
     $returnhtml = true;
     $arr = array('html' => '', 'metadata' => '');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Check that project exists
     if (!$model->exists()) {
         return $arr;
     }
     // Check authorization
     if (!$model->access('member')) {
         return $arr;
     }
     // Model
     $this->model = $model;
     // Are we returning HTML?
     if ($returnhtml) {
         // Set vars
         $this->_config = $model->config();
         $this->_task = Request::getVar('action', '');
         $this->_database = App::get('db');
         $this->_uid = User::get('id');
         switch ($this->_task) {
             case 'page':
             default:
                 $arr['html'] = $this->page();
                 break;
             case 'delete':
                 $arr['html'] = $this->_delete();
                 break;
             case 'save':
                 $arr['html'] = $this->_save();
                 break;
             case 'savecomment':
                 $arr['html'] = $this->_saveComment();
                 break;
             case 'deletecomment':
                 $arr['html'] = $this->_deleteComment();
                 break;
             case 'update':
                 $arr['html'] = $this->updateFeed();
                 break;
         }
     }
     // Return data
     return $arr;
 }
Example #26
0
 /**
  * Get permissions for a user
  *
  * @param   object  $page
  * @return  boolean
  */
 public function authorise($page)
 {
     if ($page->config('access-check-done', false)) {
         return true;
     }
     $group = \Hubzero\User\Group::getInstance($this->_scope_id);
     if (!$group) {
         $group = new \Hubzero\User\Group();
         $group->set('gidNumber', $this->_scope_id);
     }
     // Is this a group manager?
     if ($group) {
         // Is this a group manager?
         if ($group->is_member_of('managers', User::get('id'))) {
             // Allow access to all options
             $page->config()->set('access-page-manage', true);
             $page->config()->set('access-page-create', true);
             $page->config()->set('access-page-delete', true);
             $page->config()->set('access-page-edit', true);
             $page->config()->set('access-page-modify', true);
             $page->config()->set('access-comment-view', true);
             $page->config()->set('access-comment-create', true);
             $page->config()->set('access-comment-delete', true);
             $page->config()->set('access-comment-edit', true);
         } else {
             // Check permissions based on the page mode (knol/wiki)
             switch ($page->param('mode')) {
                 // Knowledge article
                 // This means there's a defined set of authors
                 case 'knol':
                     if ($page->get('created_by') == User::get('id') || $page->isAuthor(User::get('id'))) {
                         $page->config()->set('access-page-create', true);
                         $page->config()->set('access-page-delete', true);
                         $page->config()->set('access-page-edit', true);
                         $page->config()->set('access-page-modify', true);
                     } else {
                         if ($page->param('allow_changes')) {
                             $page->config()->set('access-page-modify', true);
                             // This allows users to suggest changes
                         }
                     }
                     if ($page->param('allow_comments')) {
                         $page->config()->set('access-comment-view', true);
                         $page->config()->set('access-comment-create', true);
                     }
                     break;
                     // Standard wiki
                 // Standard wiki
                 default:
                     if ($group->is_member_of('members', User::get('id'))) {
                         $page->config()->set('access-page-create', true);
                         if (!$page->isLocked()) {
                             $page->config()->set('access-page-delete', true);
                             $page->config()->set('access-page-edit', true);
                             $page->config()->set('access-page-modify', true);
                         }
                         $page->config()->set('access-comment-view', true);
                         $page->config()->set('access-comment-create', true);
                     }
                     break;
             }
         }
     }
     return true;
 }
Example #27
0
 /**
  * Event call to return data for a specific project
  *
  * @param      object  $model           Project model
  * @param      string  $action			Plugin task
  * @param      string  $areas  			Plugins to return data
  * @param      string  $tool			Name of tool wiki belongs to
  * @return     array   Return array of html
  */
 public function onProject($model, $action = '', $areas = null, $tool = NULL)
 {
     $returnhtml = true;
     $arr = array('html' => '', 'metadata' => '');
     // Get this area details
     $this->_area = $this->onProjectAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas)) {
         if (empty($this->_area) || !in_array($this->_area['name'], $areas)) {
             return;
         }
     }
     // Check that project exists
     if (!$model->exists()) {
         return $arr;
     }
     // Check authorization
     if (!$model->access('member')) {
         return $arr;
     }
     // Model
     $this->model = $model;
     // Are we returning HTML?
     if ($returnhtml) {
         // Load wiki language file
         Lang::load('com_wiki') || Lang::load('com_wiki', PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'site');
         // Set vars
         $this->_database = App::get('db');
         $this->_uid = User::get('id');
         // Load component configs
         $this->_config = $model->config();
         $this->_group = $this->_config->get('group_prefix', 'pr-') . $this->model->get('alias');
         // Incoming
         $this->_pagename = trim(Request::getVar('pagename', '', 'default', 'none', 2));
         $this->_masterScope = 'projects' . DS . $this->model->get('alias') . DS . 'notes';
         // Get our model
         $this->note = new \Components\Projects\Models\Note($this->_masterScope, $this->_group, $this->model->get('id'));
         // What's the task?
         $this->_task = $action ? $action : Request::getVar('action', 'view');
         // Publishing?
         if ($this->_task == 'browser') {
             return $this->browser();
         }
         // Import some needed libraries
         switch ($this->_task) {
             case 'upload':
             case 'download':
             case 'deletefolder':
             case 'deletefile':
             case 'media':
             case 'list':
                 $this->_controllerName = 'media';
                 break;
             case 'history':
             case 'compare':
             case 'approve':
             case 'deleterevision':
                 $this->_controllerName = 'history';
                 break;
             case 'editcomment':
             case 'addcomment':
             case 'savecomment':
             case 'reportcomment':
             case 'removecomment':
             case 'comments':
                 $this->_controllerName = 'comments';
                 $cid = Request::getVar('cid', 0);
                 if ($cid) {
                     Request::setVar('comment', $cid);
                 }
                 break;
             case 'delete':
             case 'edit':
             case 'save':
             case 'rename':
             case 'saverename':
             default:
                 $this->_controllerName = 'page';
                 break;
         }
         if (substr(strtolower($this->_pagename), 0, strlen('image:')) == 'image:' || substr(strtolower($this->_pagename), 0, strlen('file:')) == 'file:') {
             $this->_controllerName = 'media';
             $this->_task = 'download';
         }
         if (!file_exists(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'site' . DS . 'controllers' . DS . $this->_controllerName . '.php')) {
             $this->_controllerName = 'page';
         }
         // Include controller
         require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'site' . DS . 'controllers' . DS . $this->_controllerName . '.php';
         // Listing/unlisting?
         if ($this->_task == 'publist' || $this->_task == 'unlist') {
             $arr['html'] = $this->_list();
         } elseif ($this->_task == 'share') {
             $arr['html'] = $this->_share();
         } else {
             // Display page
             $arr['html'] = $this->page();
         }
     }
     // Return data
     return $arr;
 }
Example #28
0
 /**
  * Display a page
  *
  * @return  void
  */
 public function displayTask()
 {
     $this->view->book = $this->book;
     $this->view->page = $this->page;
     $this->view->config = $this->config;
     $this->view->base_path = $this->_base_path;
     $this->view->sub = $this->_sub;
     // Prep the pagename for display
     $this->view->title = $this->page->get('title');
     //getTitle();
     // Set the page's <title> tag
     if ($this->_sub) {
         Document::setTitle(Document::getTitle() . ': ' . $this->view->title);
     } else {
         Document::setTitle(($this->_sub ? Lang::txt('COM_GROUPS') . ': ' : '') . Lang::txt('COM_WIKI') . ': ' . $this->view->title);
     }
     // Set the pathway
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller);
     }
     // Is this a special page?
     if ($this->page->get('namespace') == 'special') {
         // Set the layout
         $this->view->setLayout('special');
         $this->view->layout = $this->page->denamespaced();
         $this->view->page->set('scope', Request::getVar('scope', ''));
         $this->view->page->set('group_cn', $this->_group);
         $this->view->message = $this->_message;
         // Ensure the special page exists
         if (!in_array(strtolower($this->view->layout), $this->book->special())) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&scope=' . $this->view->page->get('scope')));
             return;
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     // Does a page exist for the given pagename?
     if (!$this->page->exists() || $this->page->isDeleted()) {
         if (!$this->page->access('create')) {
             App::abort(404, Lang::txt('COM_WIKI_WARNING_PAGE_DOES_NOT_EXIST'));
         }
         // No! Ask if they want to create a new page
         $this->view->setLayout('doesnotexist');
         if ($this->_group) {
             $this->page->set('group_cn', $this->_group);
             $this->page->set('scope', $this->_group . '/wiki');
         }
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->display();
         return;
     }
     if ($this->page->get('group_cn') && !$this->_group) {
         App::redirect(Route::url('index.php?option=com_groups&scope=' . $this->page->get('scope') . '&pagename=' . $this->page->get('pagename')));
         return;
     }
     // Check if the page is group restricted and the user is authorized
     if (!$this->page->access('view', 'page')) {
         throw new Exception(Lang::txt('COM_WIKI_WARNING_NOT_AUTH'), 403);
     }
     if ($scope = $this->page->get('scope')) {
         $s = array();
         if ($cn = $this->page->get('group_cn')) {
             $scope = substr($scope, strlen($cn . '/wiki'));
             $s[] = $cn;
             $s[] = 'wiki';
         }
         $scope = trim($scope, '/');
         if ($scope) {
             $bits = explode('/', $scope);
             foreach ($bits as $bit) {
                 $bit = trim($bit);
                 if ($bit != '/' && $bit != '') {
                     $p = Article::getInstance($bit, implode('/', $s));
                     if ($p->exists()) {
                         Pathway::append($p->get('title'), $p->link());
                     }
                     $s[] = $bit;
                 }
             }
         }
     }
     Pathway::append($this->view->title, $this->page->link());
     // Retrieve a specific version if given
     $this->view->version = Request::getInt('version', 0);
     $this->view->revision = $this->page->revision($this->view->version);
     if (!$this->view->revision->exists()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->setLayout('nosuchrevision')->display();
         return;
     }
     if (Request::getVar('format', '') == 'raw') {
         Request::setVar('no_html', 1);
         echo nl2br($this->view->revision->get('pagetext'));
         return;
     } elseif (Request::getVar('format', '') == 'printable') {
         echo $this->view->revision->get('pagehtml');
         return;
     }
     // Load the wiki parser
     $wikiconfig = array('option' => $this->_option, 'scope' => $this->page->get('scope'), 'pagename' => $this->page->get('pagename'), 'pageid' => $this->page->get('id'), 'filepath' => '', 'domain' => $this->page->get('group_cn'));
     $p = Parser::getInstance();
     // Parse the text
     if (intval($this->book->config('cache', 1))) {
         // Caching
         if (!($rendered = Cache::get('wiki.r' . $this->view->revision->get('id')))) {
             $rendered = $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true);
             Cache::put('wiki.r' . $this->view->revision->get('id'), $rendered, intval($this->book->config('cache_time', 15)));
         }
         $this->view->revision->set('pagehtml', $rendered);
     } else {
         $this->view->revision->set('pagehtml', $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true));
     }
     App::get('config')->get('debug') || App::get('config')->get('profile') ? App::get('profiler')->mark('afterWikiParse') : null;
     // Handle display events
     $this->page->event = new \stdClass();
     $results = Event::trigger('wiki.onAfterDisplayTitle', array($this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayTitle = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onBeforeDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->beforeDisplayContent = trim(implode("\n", $results));
     $results = Event::trigger('wiki.onAfterDisplayContent', array(&$this->page, &$this->view->revision, $this->config));
     $this->page->event->afterDisplayContent = trim(implode("\n", $results));
     $this->view->message = $this->_message;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Example #29
0
 /**
  * Show disk usage
  *
  * @param   object   $model     Project model
  * @param   string   $repoName
  * @param   integer  $by
  * @return  string
  */
 public function diskspace($model, $repoName = 'local', $by = '')
 {
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'diskspace'));
     if (!isset($this->repo)) {
         $this->repo = new \Components\Projects\Models\Repo($model, $repoName);
     }
     $url = Route::url('index.php?option=' . $this->_option . '&alias=' . $model->get('alias') . '&active=files&action=diskspace');
     // Report usage with all history?
     if ($this->params->get('disk_usage') == true || $by == 'admin') {
         $view->dirsize = $this->repo->call('getDiskUsage', $params = array('working' => true, 'history' => true));
         $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => false));
     } else {
         $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => true));
         $view->dirsize = $view->totalspace;
     }
     // Get publication usage
     if (Plugin::isEnabled('projects', 'publications') && $by == 'admin') {
         require_once Component::path('com_publications') . DS . 'helpers' . DS . 'html.php';
         $filters = array();
         $filters['project'] = $model->get('id');
         $filters['ignore_access'] = 1;
         $filters['dev'] = 1;
         $database = \App::get('db');
         $objP = new \Components\Publications\Tables\Publication($database);
         $pubs = $objP->getRecords($filters);
         $view->pubDiskUsage = \Components\Publications\Helpers\Html::getDiskUsage($pubs);
         $view->pubQuota = $model->params->get('pubQuota') ? $model->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b');
     }
     $view->total = $this->repo->count();
     $view->quota = $model->params->get('quota', \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('defaultQuota', '1')), 'GB', 'b'));
     $view->by = $by;
     $view->model = $model;
     $view->option = $this->_option;
     $view->config = $model->config();
     $view->title = isset($this->_area['title']) ? $this->_area['title'] : '';
     $view->params = $this->params;
     return $view->loadTemplate();
 }
Example #30
0
 /**
  * Event call to get side content for main project page
  *
  * @param   object  $model
  * @return  mixed
  */
 public function onProjectMiniList($model)
 {
     if (!$model->exists() || !$model->access('content')) {
         return false;
     }
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'notes', 'name' => 'mini'));
     $group = $model->config()->get('group_prefix', 'pr-') . $model->get('alias');
     $masterScope = 'projects' . DS . $model->get('alias') . DS . 'notes';
     // Get our model
     $note = new \Components\Projects\Models\Note($masterScope, $group, $model->get('id'));
     $view->notes = $note->getNotes();
     $view->model = $model;
     return $view->loadTemplate();
 }