dado->layout_header('packages/jquery/jquery.field.js'); } // --------------------------------------------------------------- function render_inline_vars() { $filter = array('loaded'=>1,'parent'=>1,'name'=>1,'type'=>1,'dado'=>1); foreach ($this as $name => &$value) { if ($filter[$name]) continue; if (!$loaded[$name]) { // -- add global variables before everything -- array_unshift($this->dado->inline['js'], "var {$name} = " . json_encode($value) . ";"); continue; } if (!is_array($value)) continue; foreach ($value as $wname => &$wdata) { // -- add widget variables after widget definintions -- $this->dado->inline['js'][] = "var {$name}.{$wname} = " . json_encode($wdata) . ";"; } } } // ----------------------------------------------------------------- function parse_data($data, $name) { $simp = new simp('',''); $out = " $idata) { $out .= "\$this->load_file('{$idata}');\n"; } } $data = preg_replace("//sim", '', $data); // -- find javascript -- if (preg_match_all("/(.*?)<\/script>/sim", $data, $matches)) foreach($matches[1] as $id => $jdata) $js .= $jdata; $js = preg_replace("/\/\/.*?\n/sm", '', $js); $js = preg_replace("/\s+/sm", ' ', $js); $js = trim($js); $jclass = "{$name} = new function {$name}_class() { this.inheritFrom = widget; this.inheritFrom(); this.widgetName = '{$name}'; }; "; $out .= "\n\$this->dado->inline['js'][] = <</sim", '', $data); // -- find css -- if (preg_match_all("/(.*?)<\/style>/sim", $data, $matches)) foreach($matches[1] as $id => $jdata) $css .= $jdata; $css = preg_replace('/\n/sm', ' ', $css); $css = preg_replace('/\s+/sm', ' ', $css); $css = preg_replace("/\}\s+/sm", "}\n\t\t", $css); $css = trim($css); $out .= "\n\$this->dado->inline['css'][] = <</sim", '', $data); // -- find php -- $template = trim($simp->parse($data)); $out .= "\nfunction widget_{$name}(\$_data, &\$widget)\n{"; $out .= "\nextract(\$_data);\nob_start();\n?>\n"; $out .= $template; $out .= "\nrender_template($template); $out .= "\n\$this->dado->inline['js'][] = "; $out .= "\"{$name}.template = \\\"{$template}\\\";\n\";"; return $out; } // ----------------------------------------------------------------- function parse_file($name) { global $DADO_CACHE_PATH, $DADO_DATABASE; sscanf($name, "%[a-z]", $module); $path = base::include_find("modules/{$module}/widgets/{$name}.php"); if (!file_exists($path)) return false; $cache = "{$DADO_CACHE_PATH}/{$DADO_DATABASE}/widgets/{$name}.php"; if (1 || (!file_exists($cache)) || (filemtime($cache) < filemtime($path))) { if (base::load_file($path, $data)) base::save_file($cache, $this->parse_data($data, $name)); } return $cache; } // ----------------------------------------------------------------- function load_file($name) { if (array_key_exists($name,$this->loaded)) return $this->loaded[$name]; if ($this->loaded[$name] = $this->parse_file($name)) include($this->loaded[$name]); return $this->loaded[$name]; } // ----------------------------------------------------------------- function render_template($template) { ob_start(); eval("?>".$template."\s+/sim", '> ', $out); $out = preg_replace("/\s+\s+<', $out); return trim($out); } // ----------------------------------------------- function render_list($widgetName, $slotName = 'main', $widgetData = '', $listClass = '', $listId = '') { $widgetFunction = "widget_{$widgetName}"; if (!$this->load_file($widgetName)) return false; if (!is_array($widgetData)) return false; if (!function_exists($widgetFunction)) return; if ($listClass) $listClass = " class=\"{$listClass}\""; if (!$listId) 'list_' . ($this->widget_id++); $out = "\n
    \n"; foreach ($widgetData as $index => &$data) $out .= "\t
  • widget_id++) . "\" class=\"widget {$widgetName}\">\n". $widgetFunction($data, $this) . "
  • \n"; $out .= "
\n"; if (!$this->dado->standalone) $this->dado->slots[$slotName][] = $out; else echo $out; return true; } // ----------------------------------------------- function render($widget, $type = 'li', $data = '', $class = '') { if ($class) $class = " $class"; $exec = "widget_{$widget}"; if (!($this->load_file($widget))) if (!($this->load_file($widget) && function_exists($exec))) { return false; } if ((!is_array($data)) && $data) $data = array(0=>array('_a_'=>'')); if (is_array($data)) foreach ($data as $index => &$record) echo "\t<{$type} id=\"widget_" . ($this->widget_id++) . "\" class=\"widget {$widget}{$class}\">\n". $exec($record, $this) . "\n"; } } ?>