Esempio n. 1
0
 /**
  * Method to handle an error condition.
  *
  * @param   Exception  &$error  The Exception object to be handled.
  * @return  void
  */
 public static function handleError(&$error)
 {
     $renderer = new \Hubzero\Error\Renderer\Page(App::get('document'), App::get('template.loader'), App::get('config')->get('debug'));
     // Make sure the error is a 404 and we are not in the administrator.
     if (!App::isSite() || $error->getCode() != 404) {
         // Render the error page.
         return $renderer->render($error);
     }
     // Get the full current URI.
     $uri = Hubzero\Utility\Uri::getInstance();
     $current = $uri->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'));
     // Attempt to ignore idiots.
     if (strpos($current, 'mosConfig_') !== false || strpos($current, '=http://') !== false) {
         // Render the error page.
         return $renderer->render($error);
     }
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_redirect' . DS . 'models' . DS . 'link.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_redirect' . DS . 'models' . DS . 'link.php';
         // See if the current url exists in the database as a redirect.
         $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $current)->row();
         // If no published redirect was found try with the server-relative URL
         if (!$link->get('id') || $link->get('published') != 1) {
             $currRel = $uri->toString(array('path', 'query', 'fragment'));
             $link = \Components\Redirect\Models\Link::all()->whereEquals('old_url', $currRel)->row();
         }
         // If a redirect exists and is published, permanently redirect.
         if ($link->get('id') && $link->get('published') == 1) {
             App::redirect($link->new_url, null, null, true, false);
         }
         $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
         $row = \Components\Redirect\Models\Link::all()->whereEquals('old_url', substr($current, 0, 255))->row();
         if (!$row->get('id')) {
             $row->set(['old_url' => $current, 'new_url' => '', 'referer' => $referer, 'comment' => '', 'hits' => 1, 'published' => 0, 'created_date' => Date::toSql()]);
         } else {
             $row->set('hits', intval($row->get('hits', 0)) + 1);
         }
         try {
             $row->save();
         } catch (Exception $e) {
             // Do nothing for now.
             // @TODO  Log this?
         }
     }
     // Render the error page.
     $renderer->render($error);
 }
Esempio n. 2
0
});
/*
| Match by redirection rule
|
| Match the first segment of the URI by component name. If a match is 
| found, the component's router will be loaded to continue parsing any
| further segments.
*/
$router->rules('parse')->append('redirect', function ($uri) {
    // Use an alturi in case any previous rule altered
    // the $uri by adding/removing vars
    $alturi = new \Hubzero\Utility\Uri($uri->uri());
    $db = \App::get('db');
    $db->setQuery("SELECT *\n\t\tFROM `#__redirect_links`\n\t\tWHERE `published`=1\n\t\tAND (`old_url`=" . $db->quote($alturi->toString(array('scheme', 'host', 'port', 'path', 'query', 'fragment'))) . "\n\t\tOR `old_url`=" . $db->quote($alturi->toString(array('path', 'query', 'fragment'))) . ")\n\t\tLIMIT 1");
    if ($row = $db->loadObject()) {
        $myuri = new \Hubzero\Utility\Uri($row->new_url);
        $vars = $myuri->getQuery(true);
        foreach ($vars as $key => $var) {
            $uri->setVar($key, $var);
        }
        if (isset($vars['Itemid'])) {
            $menu->setActive($vars['Itemid']);
        }
        return true;
    }
});
/*
| Match by posted data
|
| Look for the option var in POST data
*/
Esempio n. 3
0
defined('_HZEXEC_') or die;
$hash = App::hash(App::get('client')->name . ':authenticator');
if (($cookie = \Hubzero\Utility\Cookie::eat('authenticator')) && !Request::getInt('reset', false)) {
    $primary = $cookie->authenticator;
    $user = User::getInstance($cookie->user_id);
    $user_img = $cookie->user_img;
    Request::setVar('primary', $primary);
}
$usersConfig = Component::params('com_members');
$primary = Request::getWord('primary', false);
// use some reflections to inspect plugins for special behavior (added for shibboleth)
$refl = array();
foreach ($authenticators as $a) {
    $refl[$a['name']] = new \ReflectionClass("plgAuthentication{$a['name']}");
}
$current = Hubzero\Utility\Uri::getInstance()->toString();
$current .= strstr($current, '?') ? '&' : '?';
?>
<div class="hz_user">

<?php 
if ($primary && $primary != 'hubzero') {
    ?>
	<a class="primary" href="<?php 
    echo Route::url('index.php?option=com_users&view=login&authenticator=' . $primary . $returnQueryString);
    ?>
">
		<div class="<?php 
    echo $primary;
    ?>
 upper"></div>
Esempio n. 4
0
 /**
  * Method to save the form data.
  *
  * @param	array	$data	The form data.
  *
  * @return	boolean	True on success.
  * @since	1.6
  */
 public function save($data)
 {
     // Initialise variables.
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('item.id');
     $isNew = true;
     $db = $this->getDbo();
     $table = $this->getTable();
     // Load the row if saving an existing item.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     if (!$isNew && $table->menutype == $data['menutype']) {
         if ($table->parent_id == $data['parent_id']) {
             // If first is chosen make the item the first child of the selected parent.
             if ($data['menuordering'] == -1) {
                 $table->setLocation($data['parent_id'], 'first-child');
             } elseif ($data['menuordering'] == -2) {
                 $table->setLocation($data['parent_id'], 'last-child');
             } elseif ($data['menuordering'] && $table->id != $data['menuordering'] || empty($data['id'])) {
                 $table->setLocation($data['menuordering'], 'after');
             } elseif ($data['menuordering'] && $table->id == $data['menuordering']) {
                 unset($data['menuordering']);
             }
         } else {
             $table->setLocation($data['parent_id'], 'last-child');
         }
     } elseif ($isNew) {
         $table->setLocation($data['parent_id'], 'last-child');
     } else {
         $table->setLocation(1, 'last-child');
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Alter the title & alias for save as copy.  Also, unset the home record.
     if (!$isNew && $data['id'] == 0) {
         list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title);
         $table->title = $title;
         $table->alias = $alias;
         $table->home = 0;
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Rebuild the tree path.
     if (!$table->rebuildPath($table->id)) {
         $this->setError($table->getError());
         return false;
     }
     $this->setState('item.id', $table->id);
     $this->setState('item.menutype', $table->menutype);
     // Load associated menu items
     if (JFactory::getApplication()->get('menu_associations', 0)) {
         // Adding self to the association
         $associations = $data['associations'];
         foreach ($associations as $tag => $id) {
             if (empty($id)) {
                 unset($associations[$tag]);
             }
         }
         // Detecting all item menus
         $all_language = $table->language == '*';
         if ($all_language && !empty($associations)) {
             throw new Exception(Lang::txt('COM_MENUS_ERROR_ALL_LANGUAGE_ASSOCIATED'), 403);
         }
         $associations[$table->language] = $table->id;
         // Deleting old association for these items
         $db = App::get('db');
         $query = $db->getQuery(true);
         $query->delete('#__associations');
         $query->where('context=' . $db->quote('com_menus.item'));
         $query->where('id IN (' . implode(',', $associations) . ')');
         $db->setQuery($query);
         $db->query();
         if ($error = $db->getErrorMsg()) {
             $this->setError($error);
             return false;
         }
         if (!$all_language && count($associations) > 1) {
             // Adding new association for these items
             $key = md5(json_encode($associations));
             $query->clear();
             $query->insert('#__associations');
             foreach ($associations as $tag => $id) {
                 $query->values($id . ',' . $db->quote('com_menus.item') . ',' . $db->quote($key));
             }
             $db->setQuery($query);
             $db->query();
             if ($error = $db->getErrorMsg()) {
                 $this->setError($error);
                 return false;
             }
         }
     }
     // Clean the cache
     $this->cleanCache();
     if (isset($data['link'])) {
         $base = Request::base();
         $uri = new \Hubzero\Utility\Uri($base . $data['link']);
         $option = $uri->getVar('option');
         // Clean the cache
         parent::cleanCache($option);
     }
     return true;
 }
Esempio n. 5
0
?>
		<img class="comment-author" src="<?php 
echo $creator->picture($comment->admin);
?>
" alt="" />
		<div class="comment-show">
			<span class="comment-details">
				<span class="actor"><?php 
echo $comment->admin == 1 ? Lang::txt('COM_PROJECTS_ADMIN') : $comment->author;
?>
</span>
				<span class="item-time">&middot; <?php 
echo \Components\Projects\Helpers\Html::showTime($comment->created, true);
?>
</span>
			</span>
			<?php 
echo '<div class="body">' . $shortComment;
if ($shorten) {
    echo ' <a href="#fullbodyc' . $comment->id . '" class="more-content">' . Lang::txt('COM_PROJECTS_MORE') . '</a>';
}
echo '</div>';
if ($shorten) {
    $fragment = ltrim(Hubzero\Utility\Uri::getInstance()->toString(['fragment']), '#');
    $cls = $fragment == 'fullbodyc' . $comment->id ? '' : ' hidden';
    echo '<div class="fullbody' . $cls . '" id="fullbodyc' . $comment->id . '">' . $longComment . '</div>';
}
?>
		</div>
	</li>