示例#1
0
 /**
  * Makes the url from standart params
  * @param string $context
  * @param bool $url_aliases_enabled
  * @return string
  * @example makeURL('alias=index.html&page=2&itemsperpage=10&category=754')
  */
 public static function makeURL($context, $url_aliases_enabled = false)
 {
     static $alias_plugins = null;
     static $search = null;
     static $replace = null;
     if (!$alias_plugins) {
         $alias_plugins = rad_loader::getAliasInputClasses();
     }
     if (!$search) {
         $search = array('SITE_URL');
         $replace = array(SITE_URL);
         if (defined('SITE_ALIAS')) {
             $search[] = 'SITE_ALIAS';
             $replace[] = SITE_ALIAS;
         }
     }
     $c = str_replace($search, $replace, $context);
     if (is_link_external($c)) {
         return $c;
     }
     $r = strstr($c, '?');
     if ($r) {
         $c = substr($r, 1);
     }
     $r = explode('&', $c);
     $get = array();
     foreach ($r as $id) {
         $r1 = explode('=', $id);
         if (count($r1) >= 2) {
             $get[$r1[0]] = $r1[1];
         } else {
             $get[$r1[0]] = '';
         }
     }
     if (!isset($get['alias'])) {
         $get['alias'] = SITE_ALIAS;
     }
     if ($url_aliases_enabled && rad_config::getParam('cleanurl.on')) {
         if ($alias = rad_cleanurl::getAliasByParams($get)) {
             return SITE_URL . $alias;
         }
     }
     if (isset($alias_plugins[$get['alias']])) {
         $model = rad_instances::get($alias_plugins[$get['alias']]);
         $string = $model->makeurl($get);
     } else {
         if ((!count($get) or count($get) == 1 and isset($get['alias'])) and trim($get['alias']) == rad_config::getParam('defaultAlias')) {
             $string = SITE_URL;
         } else {
             if (rad_config::getParam('lang.location_show')) {
                 $string = SITE_URL . rad_lang::getCurrentLanguage() . '/' . $get['alias'] . '/';
             } else {
                 $string = SITE_URL . $get['alias'] . '/';
             }
             if (strlen($context)) {
                 foreach ($get as $prmname => $prmvalue) {
                     if ($prmname != 'alias') {
                         $string .= $prmname . '/' . $prmvalue . '/';
                     }
                 }
                 if (strpos($prmvalue, '.')) {
                     if ($string[strlen($string) - 1] == '/') {
                         $string = substr($string, 0, -1);
                     }
                 }
             }
         }
     }
     return $string;
 }
示例#2
0
/**
 * Parses the style tags of the given xml element and uses them to generate
 * the associated html code.
 * @param SimpleXMLElement $xmlElement
 * @param boolean $shouldAddSwapToLinks
 * @param string $cssMenuClassName
 *
 * @return string
 * @author Andrew Darwin <*****@*****.**>
 */
function getElementContentWithStyleTags($xmlElement, $shouldAddSwapToLinks, $cssMenuClassName)
{
    $header = "getElementContentWithStyleTags(): ";
    logMessage("{$header} Beginning call...\n" . "xmlElement = '" . getTrimmed($xmlElement) . "'\n" . "shouldAddSwapToLinks = some boolean\n" . "cssMenuClassName = '{$cssMenuClassName}'");
    $attributes = $xmlElement->attributes();
    logMessage("{$header} Obtained attributes from XML Element, '{$xmlElement}'");
    $output = "";
    $prefix = "";
    $suffix = "";
    $urlSpecified = false;
    $urlOpenTag = "";
    $urlCloseTag = "";
    $outputHTMLAttributes = "";
    if ($attributes != null) {
        foreach ($attributes as $attribute) {
            $currentAttributeName = $attribute->getName();
            switch ($currentAttributeName) {
                case "style":
                    $styles = formatStyleAttribute($attribute);
                    foreach ($styles as $style) {
                        addToPrefix($prefix, "<{$style}>");
                        addToSuffix($suffix, "</{$style}>");
                    }
                    break;
                case "css":
                    $outputHTMLAttributes = "class=\"{$attribute}\"";
                    break;
                case "url":
                    // Must apply url last, so lets save it to a variable and do
                    // stuff with it later
                    $urlSpecified = true;
                    $loadURLPrefix = "";
                    if (strpos(getcwd(), "resources/scripts") == false) {
                        $loadURLPrefix = "resources/scripts/";
                    }
                    // Escape any necessary characters from the url
                    $attribute = clean_url($attribute);
                    logMessage("{$header} Clean url = '{$attribute}'");
                    $target = getAttributeValue($xmlElement, "target");
                    $isExternal = is_link_external($attribute);
                    $loadURLPrefix .= "loadURL.php";
                    $extension = pathinfo($attribute, PATHINFO_EXTENSION);
                    if ($extension == "xml") {
                        $href = "'{$loadURLPrefix}?url={$attribute}'";
                    } else {
                        $href = "'{$attribute}'";
                    }
                    if ($target == "new_tab" || $target != "same_tab" && is_link_external($attribute)) {
                        $href .= " target='_blank'";
                        $shouldAddSwapToLinks = false;
                    }
                    $urlOpenTag = "<a href={$href}";
                    if ($shouldAddSwapToLinks) {
                        $urlOpenTag .= " target='innerframe'";
                    }
                    if ($cssMenuClassName != "") {
                        $urlOpenTag .= " class='{$cssMenuClassName}'";
                    }
                    $urlOpenTag .= ">";
                    $urlCloseTag = "</a>";
            }
        }
        if ($urlSpecified) {
            addToPrefix($prefix, $urlOpenTag);
            addToSuffix($suffix, $urlCloseTag);
        }
    } else {
        logMessage("{$header} The XML Element, '{$xmlElement}' had no attributes. " . "Continue without applying any attributes or styles.");
    }
    $innerContent = getTrimmed($xmlElement);
    if (hasChildren($xmlElement)) {
        $children = $xmlElement->children();
        $child = $children[0];
        if ($child->getName() == "link") {
            logMessage("{$header} Determined that XML Element, '" . getTrimmed($xmlElement) . "' has link children. Set " . "inner content to [recursive call]...");
            $innerContent = parseLink($xmlElement);
            logMessage("{$header} InnerContent is now '{$innerContent}' after " . "calling parseLink");
        } else {
            logMessage("{$header} Determined xml element, '" . getTrimmed($xmlElement) . "' has children, but not LINK children");
        }
    } else {
        logMessage("{$header} Determined that XML Element, '" . getTrimmed($xmlElement) . "' does not have any link " . "children. Set inner content to '" . getTrimmed($xmlElement) . "'");
    }
    $output = $prefix . $innerContent . $suffix;
    logMessage("{$header} Return '{$output}'");
    return $output;
}