Skip to content

Commit

Permalink
Fixed admin nav
Browse files Browse the repository at this point in the history
  • Loading branch information
klevo committed Aug 12, 2009
1 parent 2e2ce65 commit 4984ebc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
72 changes: 33 additions & 39 deletions app/views/helpers/htmla.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,45 @@
App::import('Helper', 'Html');

/**
* HTML Advanced Helper
* Wildflower Html Helper
*
* @package SM Events
* Adding some missing features to Cake's HtmlHelper.
*
* @package Wildflower
*/
class HtmlaHelper extends HtmlHelper {

function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
$linkUrl = parent::url($url);
$currentUrl = $this->here;

// Remove paging from currentUrl
// @TODO if another named param goes after paging it do it's thing
$pieces = explode('/', $currentUrl);
$paging = end($pieces);
if (strpos($paging, 'page:') === 0) {
array_pop($pieces);
$currentUrl = join('/', $pieces);
}

if (isset($htmlAttributes['strict']) and $htmlAttributes['strict']) {
$htmlAttributes['currentOn'] = $url;
}
unset($htmlAttributes['strict']);

$currentOverride = false;
if (isset($htmlAttributes['currentOn']) && !is_null($htmlAttributes['currentOn'])) {
if ($currentUrl === parent::url($htmlAttributes['currentOn'])) {
$currentOverride = true;
// $parsedUrl = rtrim(parent::url($url), '/');
// $parsedUrl = rtrim($parsedUrl, '/index');
// $currentUrl = rtrim($this->here, '/');
// $currentUrl = rtrim($currentUrl, '/index');
// $linksToCurrentPage = (bool)($parsedUrl === $currentUrl);
//
// $containsCurrentPage = (bool)(strpos($currentUrl, $parsedUrl) === 0);
//
// if ($linksToCurrentPage or (!isset($htmlAttributes['strict']) and $containsCurrentPage)) {
// if (isset($htmlAttributes['class'])) {
// $htmlAttributes['class'] = $htmlAttributes['class'] + ' current';
// } else {
// $htmlAttributes['class'] = 'current';
// }
// }
//
// unset($htmlAttributes['strict']);
$parsedUrl = rtrim(parent::url($url), '/');
$parsedUrl = rtrim($parsedUrl, '/index');
$currentUrl = rtrim($this->here, '/');
$currentUrl = rtrim($currentUrl, '/index');
$linksToCurrentPage = (bool)($parsedUrl === $currentUrl);
$isPartOfUrl = (bool)(strpos($currentUrl, $parsedUrl) === 0);
if ($linksToCurrentPage or (!isset($htmlAttributes['strict']) and $isPartOfUrl)) {
if (isset($htmlAttributes['class'])) {
$htmlAttributes['class'] += ' current';
} else {
$htmlAttributes['class'] = 'current';
}
}

if ((strpos($currentUrl, $linkUrl) === 0 && (!isset($htmlAttributes['currentOn']) || is_null($htmlAttributes['currentOn'])))
|| ($currentOverride === true)) {
if (!isset($htmlAttributes['class'])) {
$htmlAttributes['class'] = '';
}
$classes = explode(' ', $htmlAttributes['class']);
if (!isset($classes['current'])) {
$classes[] = 'current';
}
$htmlAttributes['class'] = join(' ', $classes);
}

unset($htmlAttributes['currentOn']);

}
return parent::link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle);
}

Expand Down
20 changes: 10 additions & 10 deletions app/views/layouts/admin_default.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@
</div>

<ul id="nav">
<li><?php echo $htmla->link(__('Dashboard', true), '/' . Configure::read('Routing.admin')); ?></li>
<li><?php echo $htmla->link(__('Pages', true), array('controller' => 'pages')); ?></li>
<li><?php echo $htmla->link(__('Modules', true), array('controller' => 'sidebars')); ?></li>
<li><?php echo $htmla->link(__('Posts', true), array('controller' => 'posts')); ?></li>
<li><?php echo $htmla->link(__('Categories', true), array('controller' => 'categories')); ?></li>
<li><?php echo $htmla->link(__('Comments', true), array('controller' => 'comments')); ?></li>
<li><?php echo $htmla->link(__('Messages', true), array('controller' => 'messages')); ?></li>
<li><?php echo $htmla->link(__('Files', true), array('controller' => 'assets')); ?></li>
<li class="nav_item_on_right"><?php echo $htmla->link(__('Users', true), array('controller' => 'users')); ?></li>
<li class="nav_item_on_right"><?php echo $htmla->link(__('Site Settings', true), array('controller' => 'settings')); ?></li>
<li><?php echo $htmla->link(__('Dashboard', true), '/' . Configure::read('Routing.admin'), array('strict' => true)); ?></li>
<li><?php echo $htmla->link(__('Pages', true), array('controller' => 'pages', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Modules', true), array('controller' => 'sidebars', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Posts', true), array('controller' => 'posts', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Categories', true), array('controller' => 'categories', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Comments', true), array('controller' => 'comments', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Messages', true), array('controller' => 'messages', 'action' => 'index')); ?></li>
<li><?php echo $htmla->link(__('Files', true), array('controller' => 'assets', 'action' => 'index')); ?></li>
<li class="nav_item_on_right"><?php echo $htmla->link(__('Users', true), array('controller' => 'users', 'action' => 'index')); ?></li>
<li class="nav_item_on_right"><?php echo $htmla->link(__('Site Settings', true), array('controller' => 'settings', 'action' => 'index')); ?></li>
</ul>
</div>

Expand Down

0 comments on commit 4984ebc

Please sign in to comment.