예제 #1
0
/**
 * Checks if a resource exists and returns it if so.
 * 
 * @param string $filename The resource name
 * @param bool $return_url If true returns an URL, else returns true or false depending on if the resource exists
 * @param bool $as_local_path If true returns not URL, but a filepath in local filesystem. Needs $return_url=true.
 * @param bool $nocache If true skips all internal caches and peforms a search now
 * @return string Depending on $return_url returns: (the resource URL or false on error) OR (true or false)
 */
function resourceExists($filename, $return_url = false, $as_local_path = false, $nocache = false)
{
    global $CONFIG;
    $cnc = substr(appendVersion('/'), 1);
    $key = (isSSL() ? "resource_ssl_{$filename}" : "resource_{$filename}") . "_{$cnc}" . ($as_local_path ? "_l" : "");
    if (!$nocache && ($res = cache_get($key)) !== false) {
        return $return_url ? $res : $res != "0";
    }
    $ext = pathinfo($filename, PATHINFO_EXTENSION);
    $reg = "/(^{$ext}\$|^{$ext}\\||\\|{$ext}\$)/i";
    foreach ($CONFIG['resources'] as $conf) {
        if (strpos("|" . $conf['ext'] . "|", "|" . $ext . "|") === false) {
            continue;
        }
        if (!file_exists($conf['path'] . '/' . $filename)) {
            continue;
        }
        if ($as_local_path) {
            return $conf['path'] . '/' . $filename;
        }
        $nc = $conf['append_nc'] ? $cnc : '';
        $res = can_nocache() ? $conf['url'] . $nc . $filename : $conf['url'] . $filename . "?_nc=" . substr($nc, 2, -1);
        if (!$nocache) {
            cache_set($key, $res);
        }
        return $return_url ? $res : true;
    }
    cache_set($key, "0");
    return false;
}
예제 #2
0
 function Prepare($async = false, &$handler = false, $method = false)
 {
     global $CONFIG;
     if ($async) {
         if (!$handler || !$method) {
             WdfException::Raise("Data handler and method needed for asynchronous charts");
         }
         $data_url = buildQuery($handler->id, $method);
     } else {
         if ($handler && $method) {
             $data = $handler->{$method}($this);
         }
         //			else
         //				$data = $this->CleanupXML($this->RenderXML());
     }
     $str_data = $this->Title ? $this->Title : '';
     $swfurl = $CONFIG['system']['system_uri'] . appendVersion("/modules/charting/charts/" . $this->Type . ".swf");
     $swfurl .= "?PBarLoadingText=" . urlencode($str_data . ":\n" . getString(tds("TXT_CHART_LOADING", 'loading')));
     $swfurl .= "&ChartNoDataText=" . urlencode($str_data . ":\n" . getString(tds("TXT_NO_DATA_FOUND", 'no data found')));
     $swfurl .= "&InvalidXMLText=" . urlencode($str_data . ":\n" . getString(tds("TXT_CHART_INVALID_XML", 'invalid XML')));
     $settings = array('swfurl' => $swfurl, 'chartid' => $this->id, 'width' => $this->Width, 'height' => $this->Height, 'debug' => 0);
     if (isset($data)) {
         $settings['data'] = $data;
     } elseif (isset($data_url)) {
         $settings['dataurl'] = $data_url;
     }
     $this->_script = array();
     $this->script("initFusionChart(" . json_encode($settings) . ");");
 }