Actions

Source Code of This Project

/lib/helper/MyUrlHelper.php

<?php
/*
 * This file is part of the pwp package.
 * (c) 2009-2010 Victor Rad' <victor.v.rad[at]gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * Return current internal URI of routing
 *
 * @param boolean $named
 * @return string
 */
function get_inturi($named = true)
{
  return sfContext::getInstance()->getRouting()->getCurrentInternalUri($named);
}

/**
 * Merge current query string with new parameters
 *
 * @param array $paramsAdd
 * @param boolean $intUri internal URI mode
 * @return string
 */
function build_curr_url($paramsAdd, $intUri = true)
{
  $paramsCurr = sfContext::getInstance()->getRequest()->getGetParameters();
  if ($intUri === true)
  {
    $intUri = get_inturi();
    $intUri .=  (false === strstr($intUri, '?')) ? '?' : '&';
  }

  return $intUri . http_build_query(array_merge($paramsCurr, $paramsAdd));
}

/**
 * Build <ul><li> tree with <a> from array
 *
 * @param array $tree
 *  e.g.
 *  [apps]=>Array(
 *    [frontend]=>Array(
 *      [config]=>Array(
 *       [0]=>app.yml
 *       [1]=>cache.yml
 *       [2]=>factories.yml
 *       [3]=>filters.yml
 *      )
 *      [lib]=>myUser.class.php
 *      [modules]=>Array(
 *   ......
 *
 * @param string $depth
 * @return string
 *  e.g. <li>apps<ul><li>backend<ul><li>config<ul><li><a href="/apps/backend/config/app.yml">app.yml</a></li>....
 */
function build_html_tree($tree, $depth = null)
{
  $treeHtml = '';
  // clean global var for start of recursion
  if (null === $depth)
    $GLOBALS['html_tree']['depth'] = '';
  // current recursion depth
  else
    $GLOBALS['html_tree']['depth'] .= $depth;

  // build html tree
  foreach ($tree as $depthCurr => $item)
  {
    $depthCurr = (null === $depthCurr) ? 0 : $depthCurr;
    if (is_array($item))
      $treeHtml .= sprintf('<li><a href="#">%s</a><ul>%s</ul></li>'."\n", $depthCurr, build_html_tree($item, '/'.$depthCurr));
    else
      $treeHtml .= sprintf('<li><a href="/source/browse%s">%s</a></li>'."\n", $GLOBALS['html_tree']['depth'].'/'.$item, $item);
  }

  // remove curr depth
  $GLOBALS['html_tree']['depth'] = preg_replace('%'.preg_quote($depth).'$%', '',  $GLOBALS['html_tree']['depth']);

  return $treeHtml;
}