Exemplo n.º 1
2
 function install($model)
 {
     $app = the::app();
     include BASE . '/models/' . $model . "/install.php";
     if (!is_array($upgrade)) {
         return false;
     }
     $maxver = count($upgrade);
     if (array_key_exists(2, $app->uri_segments)) {
         $version = $app->uri_segments[2];
     } else {
         $version = $maxver;
     }
     if ($maxver > $version) {
         for ($i = $maxver; $i >= $version; $i--) {
             foreach ($downgrade[$i] as $query) {
                 echo $query;
                 echo '<br>';
                 mysql_query($query);
             }
         }
     }
     for ($i = $maxver; $i <= $version; $i++) {
         foreach ($upgrade[$i] as $query) {
             echo $query;
             echo '<br>';
             mysql_query($query);
         }
     }
     echo $model . ' install ok <br/>';
 }
Exemplo n.º 2
1
 /**
  * Advanced code
  * that is neat and i didnt want to delete it
  */
 function cache()
 {
     $app = the::app();
     $cache_life = $app->cache_life;
     $file = md5($app->uri_string);
     $created_at = false;
     // this uri never been visited before
     if (file_exists(BASE . '/../cache/' . $file)) {
         $created_at = filemtime(BASE . '/../cache/' . $file);
     } else {
         if ($app->output != "") {
             file_put_contents(BASE . '/../cache/' . $file, $app->output);
         }
     }
     if ($created_at) {
         if (time() - $created_at < $cache_life) {
             echo file_get_contents(BASE . '/../cache/' . $file);
             exit;
         } else {
             // expire cache
             unlink(BASE . '/../cache/' . $file);
             if ($app->output != "") {
                 file_put_contents(BASE . '/../cache/' . $file, $app->output);
             }
         }
     }
 }
 /**
  * @param string $targetString The string from the config file
  * @param the $map A reference to the map object (redundant)
  * @param the $mapItem A reference to the object this target is attached to
  * @return array invalue, outvalue, unix timestamp that the data was valid
  */
 function ReadData($targetString, &$map, &$mapItem)
 {
     $data[IN] = null;
     $data[OUT] = null;
     $data_time = 0;
     $matches = 0;
     if (preg_match("/^time:(.*)\$/", $targetString, $matches)) {
         $timezone = $matches[1];
         $offset = "now";
         if (preg_match("/^([^:]+):(.*)\$/", $timezone, $matches2)) {
             $timezone = $matches2[1];
             $offset = $matches2[2];
             // test that the offset is valid
             $timestamp = strtotime($offset);
             if ($timestamp === false || $timestamp === -1) {
                 warn("Time ReadData: Offset String ({$offset}) is bogus - ignoring [WMTIME03]\n");
                 $offset = "now";
             }
         }
         $timezone_l = strtolower($timezone);
         if (array_key_exists($timezone_l, $this->timezones)) {
             $tz = $this->timezones[$timezone_l];
             wm_debug("Time ReadData: Timezone exists: {$tz}\n");
             $dateTime = new DateTime($offset, new DateTimeZone($tz));
             $mapItem->add_note("time_time12", $dateTime->format("h:i"));
             $mapItem->add_note("time_time12ap", $dateTime->format("h:i A"));
             $mapItem->add_note("time_time24", $dateTime->format("H:i"));
             $mapItem->add_note("time_timet", $dateTime->format("U"));
             $mapItem->add_note("time_timezone", $tz);
             $data[IN] = $dateTime->format("H");
             $data[OUT] = $dateTime->format("i");
             $data_time = time();
             $matches++;
         }
         if ($matches == 0) {
             wm_warn("Time ReadData: Couldn't recognize {$timezone} as a valid timezone name [WMTIME02]\n");
         }
     } else {
         // some error code to go in here
         wm_warn("Time ReadData: Couldn't recognize {$targetString} \n");
     }
     wm_debug("Time ReadData: Returning (" . WMUtility::valueOrNull($data[IN]) . "," . WMUtility::valueOrNull($data[OUT]) . ",{$data_time})\n");
     return array($data[IN], $data[OUT], $data_time);
 }
 /**
  * Actually read data from a data source, and return it
  * returns a 3-part array (invalue, outvalue and datavalid time_t)
  * invalue and outvalue should be null,null if there is no valid data
  * data_time is intended to allow more informed graphing in the future
  *
  * @param string $targetString The string from the config file
  * @param the $map A reference to the map object (redundant)
  * @param the $mapItem A reference to the object this target is attached to
  * @return array invalue, outvalue, unix timestamp that the data was valid
  */
 function ReadData($targetString, &$map, &$mapItem)
 {
     $dsnames[IN] = "traffic_in";
     $dsnames[OUT] = "traffic_out";
     $data[IN] = null;
     $data[OUT] = null;
     $SQL[IN] = 'select null';
     $SQL[OUT] = 'select null';
     $rrdfile = $targetString;
     if ($map->get_hint("rrd_default_in_ds") !== null) {
         $dsnames[IN] = $map->get_hint("rrd_default_in_ds");
         wm_debug("Default 'in' DS name changed to " . $dsnames[IN] . ".\n");
     }
     if ($map->get_hint("rrd_default_out_ds") !== null) {
         $dsnames[OUT] = $map->get_hint("rrd_default_out_ds");
         wm_debug("Default 'out' DS name changed to " . $dsnames[OUT] . ".\n");
     }
     $multiplier = 8;
     // default bytes-to-bits
     $data_time = 0;
     if (1 === preg_match("/^(.*\\.rrd):([\\-a-zA-Z0-9_]+):([\\-a-zA-Z0-9_]+)\$/", $targetString, $matches)) {
         $rrdfile = $matches[1];
         $dsnames[IN] = $matches[2];
         $dsnames[OUT] = $matches[3];
         wm_debug("Special DS names seen (" . $dsnames[IN] . " and " . $dsnames[OUT] . ").\n");
     }
     if (preg_match("/^rrd:(.*)/", $rrdfile, $matches)) {
         $rrdfile = $matches[1];
     }
     if (preg_match("/^gauge:(.*)/", $rrdfile, $matches)) {
         $rrdfile = $matches[1];
         $multiplier = 1;
     }
     if (preg_match("/^scale:([+-]?\\d*\\.?\\d*):(.*)/", $rrdfile, $matches)) {
         $rrdfile = $matches[2];
         $multiplier = $matches[1];
     }
     wm_debug("SCALING result by {$multiplier}\n");
     // try and make a complete path, if we've been given a clue
     // (if the path starts with a . or a / then assume the user knows what they are doing)
     if (!preg_match("/^(\\/|\\.)/", $rrdfile)) {
         $rrdbase = $map->get_hint('rrd_default_path');
         if ($rrdbase !== null) {
             $rrdfile = $rrdbase . "/" . $rrdfile;
         }
     }
     $cfname = $map->get_hint('rrd_cf');
     if ($cfname === null) {
         $cfname = 'AVERAGE';
     }
     $period = intval($map->get_hint('rrd_period'));
     if ($period == 0) {
         $period = 800;
     }
     $start = $map->get_hint('rrd_start');
     if ($start === null) {
         $start = "now-{$period}";
         $end = "now";
     } else {
         $end = "start+" . $period;
     }
     $use_poller_output = intval($map->get_hint('rrd_use_poller_output'));
     $nowarn_po_agg = intval($map->get_hint("nowarn_rrd_poller_output_aggregation"));
     $aggregatefunction = $map->get_hint('rrd_aggregate_function');
     if ($aggregatefunction !== null && $use_poller_output == 1) {
         $use_poller_output = 0;
         if ($nowarn_po_agg === null) {
             wm_warn("Can't use poller_output for rrd-aggregated data - disabling rrd_use_poller_output [WMRRD10]\n");
         }
     }
     if ($use_poller_output == 1) {
         wm_debug("Going to try poller_output, as requested.\n");
         WeatherMapDataSource_rrd::wmrrd_read_from_poller_output($rrdfile, "AVERAGE", $start, $end, $dsnames, $data, $map, $data_time, $mapItem);
     }
     // if poller_output didn't get anything, or if it couldn't/didn't run, do it the old-fashioned way
     // - this will still be the case for the first couple of runs after enabling poller_output support
     //   because there won't be valid data in the weathermap_data table yet.
     if ($dsnames[IN] != '-' && $data[IN] === null || $dsnames[OUT] != '-' && $data[OUT] === null) {
         if ($use_poller_output == 1) {
             wm_debug("poller_output didn't get anything useful. Kicking it old skool.\n");
         }
         if (file_exists($rrdfile)) {
             wm_debug("RRD ReadData: Target DS names are " . $dsnames[IN] . " and " . $dsnames[OUT] . "\n");
             # $values=array();
             if ($aggregatefunction != '') {
                 WeatherMapDataSource_rrd::wmrrd_read_from_real_rrdtool_aggregate($rrdfile, $cfname, $aggregatefunction, $start, $end, $dsnames, $data, $map, $data_time, $mapItem);
             } else {
                 // do this the tried and trusted old-fashioned way
                 WeatherMapDataSource_rrd::wmrrd_read_from_real_rrdtool($rrdfile, $cfname, $start, $end, $dsnames, $data, $map, $data_time, $mapItem);
             }
         } else {
             wm_warn("Target {$rrdfile} doesn't exist. Is it a file? [WMRRD06]\n");
         }
     }
     // if the Locale says that , is the decimal point, then rrdtool
     // will honour it. However, floatval() doesn't, so let's replace
     // any , with . (there are never thousands separators, luckily)
     //
     if ($data[IN] !== null) {
         $data[IN] = floatval(str_replace(",", ".", $data[IN]));
         $data[IN] = $data[IN] * $multiplier;
     }
     if ($data[OUT] !== null) {
         $data[OUT] = floatval(str_replace(",", ".", $data[OUT]));
         $data[OUT] = $data[OUT] * $multiplier;
     }
     wm_debug("RRD ReadData: Returning (" . ($data[IN] === null ? 'null' : $data[IN]) . "," . ($data[OUT] === null ? 'null' : $data[OUT]) . ", {$data_time})\n");
     return array($data[IN], $data[OUT], $data_time);
 }
Exemplo n.º 5
1
<?php

include 'dynamic/controller.php';
$app = the::app();
$app->theme = 'welcome';
$app->default = 'index';
$app->connection('localhost', 'localhost', 'spaghetti', 'root', '');
$app->run();
Exemplo n.º 6
1
 function route($location)
 {
     $p = the::app();
     header("Location: " . $p->link_uri . $location);
 }