public function expire() { WaxLog::log("info", "[CACHE] Expiring cache file for " . $this->file()); if (is_readable($this->file())) { unlink($this->file()); } }
/** * Instantiates a config object and constructs the route. * @access private * @return void */ private function setup_environment() { $addr = gethostbyname($_SERVER["HOSTNAME"]); if (!$addr) { $addr = gethostbyname($_SERVER["SERVER_NAME"]); } $regexp = '/^((1?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(1?\\d{1,2}|2[0-4]\\d|25[0-5])$/'; if (!preg_match($regexp, $addr)) { $addr = false; } if (defined('ENV')) { WXConfiguration::set_environment(ENV); } elseif ($addr && (substr($addr, 0, 3) == "10." || substr($addr, 0, 4) == "127." || substr($addr, 0, 4) == "192.")) { WXConfiguration::set_environment('development'); define("ENV", "development"); } elseif ($addr) { WXConfiguration::set_environment('production'); define("ENV", "production"); } else { WXConfiguration::set_environment('development'); } /* Looks for an environment specific file inside app/config */ if (is_readable(CONFIG_DIR . ENV . ".php")) { require_once CONFIG_DIR . ENV . ".php"; } WaxLog::log("info", "Detected environment {$addr} and loaded " . ENV); }
public function geo_locate($address, $key) { if ($res = looks_like_coords($address)) { return $res; } $glocal_search_url = "https://maps.googleapis.com/maps/api/geocode/json?key=" . $key; $url = $glocal_search_url . "&address=" . urlencode($address) . "®ion=GB"; $curl = new WaxBackgroundCurl(array('url' => $url)); $res = json_decode($curl->fetch(), 1); if ($res['status'] != "OK") { WaxLog::log("error", $res['status'] . "\n" . print_r($res, 1), "geocoder"); } if (($res = $res['results'][0]) && ($lng = $res['geometry']['location']['lng']) && ($lat = $res['geometry']['location']['lat'])) { return array('lat' => $lat, 'lng' => $lng); } else { return false; } }
/** * - check available space * - get ticket * - upload **/ public function set($media_item) { $config = Config::get('vimeo'); $vimeo = new phpVimeo($config['consumer']['key'], $config['consumer']['secret'], $config['oauth']['key'], $config['oauth']['secret']); $file = PUBLIC_DIR . $media_item->uploaded_location; $size = filesize($file); $quota = $vimeo->call("videos.upload.getQuota"); $free_space = $quota->user->upload_space->free; if ($free_space - $size > 0 && ($source = $vimeo->upload($file))) { WaxLog::log('error', '[uploaded] ' . $source, 'vimeo'); $res = $media_item->update_attributes(array('status' => 1, 'source' => $source, 'media_class' => get_class($this), 'media_type' => self::$name, 'uploaded_location' => 'http://vimeo.com/' . $source, 'hash' => md5($source), 'file_type' => 'video', 'sync_location' => 'ALL')); if ($res) { unlink($file); } return $res; } else { WaxLog::log('error', '[no space]', 'vimeo'); } return false; }
function databaseAdd($folderpath, $filename, $realitivePath) { if (function_exists('mime_content_type')) { $type = mime_content_type("{$folderpath}/{$filename}"); } else { $type = exec("file --mime -b " . escapeshellarg("{$folderpath}/{$filename}")); } //image resizing if (strpos($type, "image") === true) { $dimensions = getimagesize("{$folderpath}/{$filename}"); if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) { $flag = File::resize_image("{$folderpath}/{$filename}", "{$folderpath}/{$filename}", AdminFilesController::$max_image_width, false, true); } } $size = $this->get_size($folderpath . '/' . $filename); $fileid = $this->fileid($folderpath, $filename); while (!$this->checkId($fileid)) { $fileid++; } $query = "INSERT INTO wildfire_file (id,filename,path,rpath,type,size,status,flags) VALUES ({$fileid},'{$filename}','{$folderpath}','{$realitivePath}','{$type}','{$size}','found', 'normal')"; WaxLog::log("info", "[DB] " . $query); try { $res = $this->query($query); } catch (Exception $e) { die("NOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!! " . $query); } chmod($folderpath . '/' . $filename, 0755); touch($folderpath . '/' . $filename, $fileid); }
public function exec($pdo_statement, $bindings = array(), $swallow_errors = false) { try { WaxLog::log("info", "[DB] " . $pdo_statement->queryString); if (count($bindings)) { WaxLog::log("info", "[DB] Values:" . join($bindings, ",")); } $pdo_statement->execute($bindings); } catch (PDOException $e) { $err = $pdo_statement->errorInfo(); WaxLog::log("error", "[DB] " . $err[2]); if (!$swallow_errors) { throw new WaxSqlException("{$err[2]}", "Error Executing Database Query", $pdo_statement->queryString . "\n" . print_r($bindings, 1)); } } return $pdo_statement; }
/** * same as wildfirecontent, but doesn't move children that are actually national content items */ public function children_move() { if ($id = $this->revision()) { $class = get_class($this); $model = new $class($id); $model->row['dealer_content_id'] = false; //need this addition to not reparent national content to dealer WaxLog::log('error', "[move] {$id} - {$class}", 'children_move'); if ($model && $model->primval) { foreach ($model->children as $c) { $model->children->unlink($c); $c->update_attributes(array($this->parent_column . "_" . $this->primary_key => $this->primval)); } } } return $this; }
public function file_upload() { if ($url = $_POST["upload_from_url"]) { $str = ""; foreach ($_POST as $k => $v) { $str .= "{$k}:{$v}\n"; } WaxLog::log('error', 'running...' . $str); $path = $_POST['wildfire_file_folder']; $fs = new CmsFilesystem(); $filename = basename($url); $ext = strtolower(array_pop(explode(".", $filename))); if ($_POST["wildfire_file_filename"]) { $filename = $_POST["wildfire_file_filename"] . "." . $ext; } $filename = $_POST["wildfire_file_filename"] = File::safe_file_save($fs->defaultFileStore . $path, $filename); $file = $fs->defaultFileStore . $path . "/" . $filename; $handle = fopen($file, 'x+'); fwrite($handle, file_get_contents($url)); fclose($handle); $fname = $fs->defaultFileStore . $path . "/" . $filename; chmod($fname, 0777); $dimensions = getimagesize($fname); if (AdminFilesController::$max_image_width && $dimensions[0] > AdminFilesController::$max_image_width) { $flag = File::resize_image($fname, $fname, AdminFilesController::$max_image_width, false, true); if (!$flag) { WaxLog::log('error', '[resize] FAIL'); } } $fs->databaseSync($fs->defaultFileStore . $path, $path); $file = new WildfireFile(); $newfile = $file->filter(array("filename" => $filename, "rpath" => $path))->first(); $newfile->description = $_POST["wildfire_file_description"]; $newfile->save(); //if these are set then attach the image to the doc! if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) { $model_id = Request::post('content_id'); $class = Inflections::camelize(Request::post('model_string'), true); $field = Request::post('join_field'); $model = new $class($model_id); $model->{$field} = $newfile; } echo "Uploaded"; } elseif ($_FILES) { error_log("Starting File upload"); error_log(print_r($_POST, 1)); $path = $_POST['wildfire_file_folder']; $fs = new CmsFilesystem(); $_FILES['upload'] = $_FILES["Filedata"]; $_FILES['upload']['name'] = str_replace(' ', '', $_FILES['upload']['name']); $fs->upload($path); $fs->databaseSync($fs->defaultFileStore . $path, $path); $fname = $fs->defaultFileStore . $path . "/" . $_FILES['upload']['name']; if ($dimensions = getimagesize($fname)) { if ($dimensions[2] == "7" || $dimensions[2] == "8") { WaxLog::log("error", "Detected TIFF Upload"); $command = "mogrify " . escapeshellcmd($fname) . " -colorspace RGB -format jpg"; system($command); $newname = str_replace(".tiff", ".jpg", $fname); $newname = str_replace(".tif", ".jpg", $newname); rename($fname, $newname); } } chmod($fname, 0777); $file = new WildfireFile(); $newfile = $file->filter(array("filename" => $_FILES['upload']['name'], "rpath" => $path))->first(); $newfile->description = $_POST["wildfire_file_description"]; $newfile->save(); //if these are set then attach the image to the doc! if (Request::post('content_id') && Request::post('model_string') && Request::post('join_field')) { $model_id = Request::post('content_id'); $class = Inflections::camelize(Request::post('model_string')); $field = Request::post('join_field'); $model = new $class($model_id); $model->{$field} = $newfile; } echo "Uploaded"; } else { die("UPLOAD ERROR"); } exit; }
public function after_soap($res) { if ($errors = $res->{'Campaign.CreateResult'}->enc_value->Message) { $this->errors[$this->primary_key] = $errors; Session::add_error($errors); WaxLog::log('error', '[SOAP ERR]' . print_r($errors, 1)); } elseif (is_string($res->{'Campaign.CreateResult'})) { $this->CampaignID = $res->{'Campaign.CreateResult'}; $model = new Campaign(); $model->ClientID = $this->ClientID; $model->CampaignID = $this->CampaignID; $model->SendDate = $this->SendDate; $model->ConfirmationEmail = $this->ConfirmationEmail; sleep(3); //sleep is needed to give the api time to catch up; apparently its slow $res = $model->Send(); sleep(1); } }
public function thumbnail($media_item, $size = false) { $yt = $this->includes(); try { $vid = $yt->getVideoEntry($media_item->source); } catch (Exception $e) { WaxLog::log("error", "[WildfireYoutubeFile] error getting video {$media_item->source}"); return false; } return $vid->mediaGroup->thumbnail[0]->url; }
public function exec($pdo_statement, $bindings = array(), $swallow_errors = false) { try { WaxLog::log("info", "[DB] " . $pdo_statement->queryString); if (count($bindings)) { WaxLog::log("info", "[DB] Values:" . join($bindings, ",")); } $pdo_statement->execute($bindings); } catch (PDOException $e) { $err = $pdo_statement->errorInfo(); switch ($e->getCode()) { case "42S02": case "42S22": ob_start(); foreach (Autoloader::$plugin_array as $plugin) { Autoloader::recursive_register(PLUGIN_DIR . $plugin["name"] . "/lib/model", "plugin", true); } Autoloader::include_dir(MODEL_DIR, true); foreach (get_declared_classes() as $class) { if (is_subclass_of($class, "WaxModel")) { $class_obj = new $class(); $output = $class_obj->syncdb(); if (strlen($output)) { echo $output; } } } $sync = false; //Forces destruction and flushing of output buffer ob_end_clean(); try { $pdo_statement->execute($bindings); } catch (PDOException $e) { throw new WaxDBStructureException("{$err[2]}", "Database Structure Error", $pdo_statement->queryString . "\n" . print_r($bindings, 1)); } break; default: WaxLog::log("error", "[DB] {$err['2']} , SQL: " . $pdo_statement->queryString . ($bindings ? "\n" . print_r($bindings, 1) : "")); if (!$swallow_errors) { throw new WaxSqlException("{$err[2]}", "Error Preparing Database Query", $pdo_statement->queryString . "\n" . print_r($bindings, 1)); } } } return $pdo_statement; }
function simple_routing_error_log() { WaxLog::log("error", "[Routing] Couldn't load a requested page: {$_GET['route']}"); }
/** * Big nasty function to parse the information returned from the soap call * - looks for mapping for the node name returned by the call * - invert the mappings * - check something is returned * - check to see if the result is an array or just a model (convert to array if not) * - loop around the result array * -- loop over the model columns * --- and assign the value on the result to * --- check if its the custom fields * ---- if it is then loop over it and assign the result back to an array with appropriate key val pairs * ---- this then makes the custom field var an array * - return all the results * @param string $results * @param string $model * @return mixed */ protected function parse_soap($results, $model) { //check model name mapping WaxLog::log('error', '[SOAP RES]' . print_r($results, 1)); if ($model->soap_mappings[$this->cm_api_method]['return']) { $return = $model->soap_mappings[$this->cm_api_method]['return']; } else { $return = $this->cm_api_method . "Response"; } $class = get_class($model); //name mappings for when they aren't consistant! if (is_array($mappings)) { $mappings = array_flip($model->rename_mappings); } $res = array(); if ($results->{$return}->enc_value->{$class}) { $results = $results->{$return}->enc_value->{$class}; //get the results //make sure its an array if (!is_array($results)) { $loop_over = array(0 => $results); } else { $loop_over = $results; } $columns = array_merge($model->columns, $model->rename_mappings); //loop round all return objects foreach ($loop_over as $k => $info) { $objdata = array(); //tmp var for records foreach ($columns as $col => $spec) { //go over the columns if ($info->{$col} && $model->rename_mappings[$col]) { $objdata[$model->rename_mappings[$col]] = $info->{$col}; } elseif ($val = $info->{$col}) { $objdata[$col] = $val; } elseif ($mappings[$col] && $info->{$mappings[$col]}) { $objdata[$col] = $info->{$mappings[$col]}; } //convert custom fields if ($col == "CustomFields" && $info->{$col}) { $values = array(); //array to store the result $field = get_class($model) . "CustomField"; //the model element to fetch $data = $info->{$col}->{$field}; //the custom field data if (is_array($data)) { //if its an array foreach ($data as $count => $custom_info) { //loop over and get the key value pairs $key = $custom_info->Key; $val = $custom_info->Value; if ($val) { $values[$key] = $val; } //if the value is set then assign it to val array } } elseif ($data->Value) { $values[$data->Key] = $data->Value; } //copy val over if (count($values)) { $objdata[$col] = $values; } else { $objdata[$col] = false; } //or set it to false } } if (count($objdata)) { $res[] = $objdata; } } } elseif (is_string($results->{$return})) { $res[$model->primary_key] = $results->{$return}; } $this->total_without_limits = count($res); return $res; }
function simple_error_log() { WaxLog::log("error", "[Maintenance] Server undergoing maintenance: {$_GET['route']}"); }
/** * This method is what it's all about, it simply steps through the filters and * runs the action. * * It then picks up the view content along the way and hey presto, you have a page. * If you've messed up and not provided an action, it throws an exception. * * @access protected */ public function execute_request() { $this->controller = WaxUrl::get("controller"); $this->action = WaxUrl::get("action"); $this->route_array = explode("/", $_GET["route"]); $this->use_format = WaxUrl::get("format"); WaxLog::log("info", "Loading controller {$this->controller} with action {$this->action} from route '{$_GET['route']}'"); $this->controller_global(); $this->run_filters("before"); if (!$this->is_public_method($this, $this->action)) { if ($this->is_public_method($this, Inflections::underscore($this->action))) { $underscore_action = Inflections::underscore($this->action); $this->{$underscore_action}(); } elseif (method_exists($this, 'method_missing')) { $this->method_missing(); } else { $class = get_class($this); throw new WXRoutingException("No Public Action Defined for - " . $this->action . " in controller {$class}.", "Missing Action"); } } else { $this->{$this->action}(); } $this->run_filters("after"); $this->content_for_layout = $this->render_view(); if ($content = $this->render_layout()) { echo $content; } elseif ($this->content_for_layout) { echo $this->content_for_layout; } else { echo ""; } }