This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 
<?php
/**
 * @package Helpers
 * @category Concrete
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */

/**
 * @package Helpers
 * @category Concrete
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */

defined('C5_EXECUTE') or die("Access Denied.");
class ConcreteUrlsHelper { 

    /** 
     * Gets a full URL to an icon for a particular application
     */
    public function getPackageIconURL($pkg) {
        if ($pkg && file_exists($pkg->getPackagePath() . '/' . FILENAME_BLOCK_ICON)) {
            return $this->getPackageURL($pkg) . '/' . FILENAME_BLOCK_ICON;
        } else {
            return PACKAGE_GENERIC_ICON;
        }
    }
    
    public function getPackageURL($pkg) {
        return $pkg->getRelativePath();
    }
    
    /** 
     * Gets a URL to reference a script in the tools directory
     * @param $string $tool
     * @param $string $pkgHandle
     */
    public function getToolsURL($tool, $pkgHandle = null) {
        if ($pkgHandle != null) {
            $url = REL_DIR_FILES_TOOLS_PACKAGES . '/' . $pkgHandle . '/' . $tool;
            return $url;
        } else {
            if (file_exists(DIR_BASE . '/' . DIRNAME_TOOLS . '/' . $tool . '.php')) {
                return REL_DIR_FILES_TOOLS . '/' . $tool;
            } else {
                return REL_DIR_FILES_TOOLS_REQUIRED . '/' . $tool;
            }
        }
    }
    
    /** 
     * Gets a full URL to an icon for a particular block type
     * @param BlockType $bt
     * @return string
     */
    public function getBlockTypeIconURL($bt) {
        $url = $this->getBlockTypeAssetsURL($bt, FILENAME_BLOCK_ICON);
        if ($url != false) {
            return $url;
        } else {
            return BLOCK_TYPE_GENERIC_ICON;
        }
    }
    
    /** 
     * Gets a full URL to the directory containing all of a block's items, including JavaScript, tools, icons, etc...
     * @param BlockType $bt
     * @return string $url
     */
    public function getBlockTypeAssetsURL($bt, $file = false) {
        $ff = '';
        if ($file != false) {
            $ff = '/' . $file;
        }
        
        if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $bt->getBlockTypeHandle() . $ff)) {
            $url = DIR_REL . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff;
        } else if ($bt->getPackageID() > 0) {
            $db = Loader::db();
            $h = $bt->getPackageHandle();
            $dirp = (is_dir(DIR_PACKAGES . '/' . $h)) ? DIR_PACKAGES . '/' . $h : DIR_PACKAGES_CORE . '/' . $h;
            if (file_exists($dirp . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff)) {
                $url = (is_dir(DIR_PACKAGES . '/' . $h)) ? DIR_REL : ASSETS_URL; 
                $url = $url . '/' . DIRNAME_PACKAGES . '/' . $h . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff;
            }
        } else if (file_exists(DIR_FILES_BLOCK_TYPES_CORE . '/' . $bt->getBlockTypeHandle() . $ff)) {
            $url = ASSETS_URL . '/' . DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . $ff;
        }       
        return $url;
    }
    
    /** 
     * Gets a full URL to a block's JavaScript file (if one exists)
     * @param BlockType $bt
     * @return string $url
     */
    public function getBlockTypeJavaScriptURL($bt) {
        return $this->getBlockTypeAssetsURL($bt, 'auto.js');
    }

    /** 
     * Gets a full URL to a block's tools directory
     * @param BlockType $bt
     * @return string $url
     */
    public function getBlockTypeToolsURL($bt) {
        return REL_DIR_FILES_TOOLS_BLOCKS . '/' . $bt->getBlockTypeHandle();
    }

    
}