Beispiel #1
0
/**
 * Returns the url of the given icon
 *
 * @param string $fileName file name with or without extension
 * @param string $moduleLabel label of the module (optional)
 * @return string icon url
 *         mixed null if icon not found
 */
function get_icon_url($fileName, $moduleLabel = null)
{
    $fileInfo = pathinfo($fileName);
    $currentModuleLabel = get_current_module_label();
    $imgPath = array();
    // Search kernel first for performance !
    // claroline theme iconset
    $imgPath[get_current_iconset_path()] = get_current_iconset_url();
    // claroline web/img <--- is now the default location find using get_current_iconset_url
    //$imgPath[get_path( 'rootSys' ) . 'web/img/'] = get_path('url') . '/web/img/';
    if (!empty($moduleLabel)) {
        // module img directory
        $imgPath[get_module_path($moduleLabel) . '/img/'] = get_module_url($moduleLabel) . '/img/';
        // module root directory
        $imgPath[get_module_path($moduleLabel) . '/'] = get_module_url($moduleLabel) . '/';
    }
    if (!empty($currentModuleLabel)) {
        // module img directory
        $imgPath[get_module_path($currentModuleLabel) . '/img/'] = get_module_url($currentModuleLabel) . '/img/';
        // module root directory
        $imgPath[get_module_path($currentModuleLabel) . '/'] = get_module_url($currentModuleLabel) . '/';
    }
    // img directory in working directory
    $imgPath['./img/'] = './img/';
    // working directory
    $imgPath['./'] = './';
    if (!empty($fileInfo['extension'])) {
        $img = array($fileName);
    } else {
        $img = array($fileName . '.png', $fileName . '.gif');
    }
    foreach ($imgPath as $tryPath => $tryUrl) {
        foreach ($img as $tryImg) {
            if (claro_debug_mode()) {
                pushClaroMessage("Try " . $tryPath . $tryImg, 'debug');
            }
            if (file_exists($tryPath . $tryImg)) {
                if (claro_debug_mode()) {
                    pushClaroMessage("Using " . $tryPath . $tryImg, 'debug');
                }
                return $tryUrl . $tryImg . '?' . filemtime($tryPath . $tryImg);
            }
        }
    }
    if (claro_debug_mode()) {
        pushClaroMessage("Icon {$fileName} not found", 'error');
    }
    // WORKAROUND : avoid double submission if missing image !!!!
    return 'image_not_found.png';
}
Beispiel #2
0
 /**
  * Get the current execution context
  * @return array
  */
 public static function getCurrentContext()
 {
     $context = array();
     if (claro_is_in_a_course()) {
         $context[CLARO_CONTEXT_COURSE] = claro_get_current_course_id();
     }
     if (claro_is_in_a_group()) {
         $context[CLARO_CONTEXT_GROUP] = claro_get_current_group_id();
     }
     if (claro_is_in_a_tool()) {
         if (isset($GLOBALS['tlabelReq']) && $GLOBALS['tlabelReq']) {
             $context[CLARO_CONTEXT_TOOLLABEL] = $GLOBALS['tlabelReq'];
         }
         if (claro_get_current_tool_id()) {
             $context[CLARO_CONTEXT_TOOLINSTANCE] = claro_get_current_tool_id();
         }
     }
     if (get_current_module_label()) {
         $context[CLARO_CONTEXT_MODULE] = get_current_module_label();
     }
     return $context;
 }
Beispiel #3
0
 /**
  * Load a css file
  * @param   string lib css file url relative to one of the
  *  declared css paths
  * @return  boolean true if the library was found, false if not
  */
 public function load($css, $media = 'all')
 {
     $this->pathList = array(get_path('rootSys') . 'platform/css/' . get_current_module_label() => get_path('url') . '/platform/css/' . get_current_module_label(), get_module_path(get_current_module_label()) . '/css' => get_module_url(get_current_module_label()) . '/css', get_path('rootSys') . 'platform/css' => get_path('url') . '/platform/css', get_path('rootSys') . 'web/css' => get_path('url') . '/web/css', './css' => './css');
     $css = secure_file_path($css);
     foreach ($this->pathList as $tryPath => $tryUrl) {
         if (claro_debug_mode()) {
             pushClaroMessage(__CLASS__ . "::Try " . $tryPath . '/' . $css . '.css', 'debug');
         }
         if (file_exists($tryPath . '/' . $css . '.css')) {
             if (array_key_exists($tryPath . '/' . $css . '.css', $this->css)) {
                 return false;
             }
             if (claro_debug_mode()) {
                 pushClaroMessage(__CLASS__ . "::Use " . $tryPath . '/' . $css . '.css', 'debug');
             }
             $this->css[$tryPath . '/' . $css . '.css'] = array('url' => $tryUrl . '/' . $css . '.css' . '?' . filemtime($tryPath . '/' . $css . '.css'), 'media' => $media);
             ClaroHeader::getInstance()->addHtmlHeader('<link rel="stylesheet" type="text/css"' . ' href="' . $this->css[$tryPath . '/' . $css . '.css']['url'] . '"' . ' media="' . $this->css[$tryPath . '/' . $css . '.css']['media'] . '" />');
             return true;
             // break;
         }
     }
     if (claro_debug_mode()) {
         pushClaroMessage(__CLASS__ . "::NotFound " . $css . '.css', 'error');
     }
     return false;
 }
Beispiel #4
0
/**
 * Set the current module label at run time
 *  @param string label module label
 *  @return string old label
 *          boolean false if no old label defined
 *  FIXME : use it in docks and kernel
 */
function set_current_module_label($label)
{
    $old = get_current_module_label();
    Claroline::getInstance()->pushModuleLabel($label);
    return $old;
}
Beispiel #5
0
 public static function load_module_translation($moduleLabel = null, $language = null)
 {
     global $_lang;
     $moduleLabel = is_null($moduleLabel) ? get_current_module_label() : $moduleLabel;
     // In a module
     if (!empty($moduleLabel)) {
         $module_path = get_module_path($moduleLabel);
         $language = is_null($language) ? language::current_language() : $language;
         // load english by default if exists
         if (file_exists($module_path . '/lang/lang_english.php')) {
             /* FIXME : DEPRECATED !!!!! */
             $mod_lang = array();
             include $module_path . '/lang/lang_english.php';
             $_lang = array_merge($_lang, $mod_lang);
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . 'English lang file loaded', 'debug');
             }
         } else {
             // no language file to load
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . 'English lang file  not found', 'debug');
             }
         }
         // load requested language if exists
         if ($language != 'english' && file_exists($module_path . '/lang/lang_' . $language . '.php')) {
             /* FIXME : CODE DUPLICATION see 263-274 !!!!! */
             /* FIXME : DEPRECATED !!!!! */
             $mod_lang = array();
             include $module_path . '/lang/lang_' . $language . '.php';
             $_lang = array_merge($_lang, $mod_lang);
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . ucfirst($language) . ' lang file loaded', 'debug');
             }
         } elseif ($language != 'english') {
             // no language file to load
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . ucfirst($language) . ' lang file  not found', 'debug');
             }
         } else {
             // nothing to do
         }
     } else {
         // Not in a module
     }
 }
Beispiel #6
0
 /**
  * Get the loader for a given module
  * @param   string $moduleLabel
  * @return  Loader instance
  */
 public static function module($moduleLabel = null)
 {
     if (empty($moduleLabel)) {
         $moduleLabel = get_current_module_label();
     }
     if (!array_key_exists($moduleLabel, self::$cache)) {
         self::$cache[$moduleLabel] = new self($moduleLabel);
     }
     return self::$cache[$moduleLabel];
 }
Beispiel #7
0
 public function render()
 {
     $claro_buffer = new ClaroBuffer();
     $claro_buffer->append("\n" . '<!-- ' . $this->name . ' -->' . "\n");
     foreach ($this->appletList as $applet) {
         set_current_module_label($applet['label']);
         pushClaroMessage('Current module label set to : ' . get_current_module_label(), 'debug');
         // install course applet
         if (claro_is_in_a_course()) {
             install_module_in_course($applet['label'], claro_get_current_course_id());
         }
         if ($applet['activation'] == 'activated' && file_exists($applet['path'])) {
             load_module_config();
             Language::load_module_translation();
             if ($this->useList() && count($this->appletList) > 0) {
                 $claro_buffer->append("<li\n                        id=\"dock-" . $this->name . "-applet-" . $applet['label'] . "\"\n                        class=\"applet dock-" . $this->name . " applet-" . $applet['label'] . "\"><span>\n");
             } else {
                 $claro_buffer->append("<span\n                        id=\"dock-" . $this->name . "-applet-" . $applet['label'] . "\"\n                        class=\"applet dock-" . $this->name . " applet-" . $applet['label'] . "\">\n");
             }
             include_once $applet['path'];
             if ($this->useList() && count($this->appletList) > 0) {
                 $claro_buffer->append("\n</span></li>\n");
             } else {
                 $claro_buffer->append("\n</span>\n");
             }
         } else {
             Console::debug("Applet not found or not activated : " . $applet['label']);
         }
         clear_current_module_label();
         pushClaroMessage('Current module label set to : ' . get_current_module_label(), 'debug');
     }
     $claro_buffer->append("\n" . '<!-- End of ' . $this->name . ' -->' . "\n");
     return $claro_buffer->getContent();
 }
Beispiel #8
0
 /**
  * Release the lock
  * @return boolean 
  */
 public static function releaseLock()
 {
     $moduleLabel = get_current_module_label();
     if (self::hasLock($moduleLabel)) {
         unset($_SESSION[self::CLARO_KERNEL_HOOK_LOCK]);
         return true;
     } else {
         return false;
     }
 }
Beispiel #9
0
 public function getCurrentLocator($params = array())
 {
     $locator = new ClarolineResourceLocator();
     if (claro_is_in_a_course()) {
         $locator->setCourseId(claro_get_current_course_id());
     }
     if (claro_is_in_a_group()) {
         $locator->setGroupId(claro_get_current_group_id());
     }
     if (get_current_module_label()) {
         $locator->setModuleLabel(get_current_module_label());
         $navigator = $this->loadModuleNavigator(get_current_module_label());
         if ($resourceId = $navigator->getResourceId($params)) {
             $locator->setResourceId($resourceId);
         }
     }
     return $locator;
 }
Beispiel #10
0
/**
 * Load configuration file for a module
 * @param   $module module label (default null for current module)
 */
function load_module_config($moduleLabel = null)
{
    if (!$moduleLabel) {
        $moduleLabel = get_current_module_label();
    }
    // load main config file
    $mainConfigFile = claro_get_conf_repository() . $moduleLabel . '.conf.php';
    if (file_exists($mainConfigFile)) {
        include $mainConfigFile;
    }
    // check if config overwritten in course and load config file
    if (claro_is_in_a_course()) {
        $courseConfigFile = get_conf('coursesRepositorySys') . claro_get_current_course_data('path') . '/conf/' . $moduleLabel . '.conf.php';
        if (file_exists($courseConfigFile)) {
            include $courseConfigFile;
        }
    }
}
Beispiel #11
0
// TODO : move module_cache to cache directory
// TODO : includePath is probably not needed
$module_cache_filename = get_conf('module_cache_filename', 'moduleCache.inc.php');
$cacheRepositorySys = get_path('rootSys') . get_conf('cacheRepository', 'tmp/cache/');
if (!file_exists($cacheRepositorySys . $module_cache_filename)) {
    require_once get_path('incRepositorySys') . '/lib/module/manage.lib.php';
    generate_module_cache();
}
require_once get_path('incRepositorySys') . '/lib/lock.lib.php';
if (file_exists($cacheRepositorySys . $module_cache_filename)) {
    include $cacheRepositorySys . $module_cache_filename;
} else {
    pushClaroMessage('module_cache not generated : check access right in ' . $cacheRepositorySys, 'warning');
}
// reset current module label after calling the cache
if (isset($tlabelReq) && get_current_module_label() != $tlabelReq) {
    // reset all previous occurence of module label in stack
    while (clear_current_module_label()) {
    }
    // set the current module label
    set_current_module_label($tlabelReq);
}
// Add feed RSS in header
if (claro_is_in_a_course() && get_conf('enableRssInCourse', true)) {
    require claro_get_conf_repository() . 'rss.conf.php';
    $claroline->display->header->addHtmlHeader('<link rel="alternate" type="application/rss+xml" title="' . claro_htmlspecialchars($_course['name'] . ' - ' . get_conf('siteName')) . '"' . ' href="' . get_path('url') . '/claroline/backends/rss.php?cidReq=' . claro_get_current_course_id() . '" />');
}
// timezone debug code
if (claro_debug_mode() && get_conf('clmain_serverTimezone', '')) {
    pushClaroMessage('timezone set to ' . date_default_timezone_get(), 'debug');
}