function dev_config_from_db($table, $var_field = '', $value_field = '') { if (dev_is_null($var_field)) { $var_field = 'var'; } if (dev_is_null($value_field)) { $value_field = 'value'; } $active_fields = array($var_field, $value_field); $config = new DevModel($table); $config->clear(); $config->setActiveFields($active_fields); $config->toggleActiveFieldsOn(true); $data = array(); foreach ($config->getRecordSet() as $a) { $data[$a[$var_field]] = $a[$value_field]; } $status = dev_config_from_array($data); return $status; }
function parseXML($file = '') { if (dev_is_null($file)) { $file = $this->getFile(); } if ($stream = dev_stream_file($file, $msg)) { while ($data = fread($stream, 4096)) { if (!xml_parse($this->parser, $data, feof($stream))) { $this->setMsg(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser))); return false; } } } else { $this->setMsg($msg); return false; } return true; }
function dev_href($href = '', $doc = true) { if (dev_is_null($href)) { if (!defined('PAGE_EXTENSION')) { define('PAGE_EXTENSION', '.php'); } $href = ''; if ($doc === false) { $href .= $_SERVER['DOCUMENT_ROOT']; } else { $href = 'http://' . $_SERVER['SERVER_NAME']; $href .= $_SERVER['REQUEST_URI']; if (dev_strrpos($href, PAGE_EXTENSION)) { $href = substr($href, 0, dev_strrpos($href, PAGE_EXTENSION) + strlen(PAGE_EXTENSION)); } elseif (dev_strrpos($href, '/')) { $href = substr($href, 0, dev_strrpos($href, '/') + strlen('/')); } } } return $href; }
public function queryLog($file, $href = '', $ip = '', $limit = '', $interval = '') { $line = dev_read_log_r($file, "\t"); if (is_array($line)) { $line = ''; $href = dev_href($href); $ip = dev_is_null($ip) ? $this->remote() : $ip; $quit = false; while (list($a, $b) = $line || $quit) { if ($b[0] == $ip && $b[1] == $href) { Boolean::opposite(&$quit); } } if ($b[3] >= $limit && dev_time_difference($b[2], $timestamp, 'minutes') <= $interval) { dev_ip_deny($ip); } } else { $status = $line; } return $status; }
function executeData($token_file = '', $syntax_file = '', $data_file = '', $data = '') { $output = ''; if ($this->prepareView($token_file, $syntax_file, $data_file, $data)) { if (dev_not_null($data_file)) { $output = $this->parseDataFile($data_file); } else { $output = $this->ParseData($data); } } else { $this->setStatus("Failed to properly prepare view!\n"); } if (dev_is_null($output)) { $output = $this->getMessage(); } return $output; }
function dev_time_difference($time1, $time2, $interval = '') { if (dev_is_null($interval)) { $interval = 'seconds'; } $a = strtotime($time1); $b = strtotime($time2); $difference = $a > $b ? $a - $b : $b - $a; $div = 1; switch ($interval) { case 'years': $div *= 12; case 'months': $div *= 4; case 'weeks': $div *= 30; case 'days': $div *= 24; case 'hours': $div *= 60; case 'minutes': $div *= 60; default: case 'seconds': $div *= 1; break; } $output = $differnce / $div; return $output; }
function dev_draw_form($action = '', $name = '', $method = '', $validate = true, $properties = '', $image_path = 'images/', $css_path = 'css/rte.css') { $output = ''; $action = dev_href($action); if (dev_is_null($method)) { $method = 'post'; } $output .= '<form enctype="multipart/form-data" method="' . $method . '" onsubmit="return submitForm();"' . ($name != '' ? 'name="' . $name . '"' : '') . ' ' . ($action != '' ? 'action="' . $action . '"' : '') . ' ' . $properties . '>'; $output .= "\r"; /* $output .= ' <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync before submitting form //to sync only 1 rte, use updateRTE(rte) //to sync all rtes, use updateRTEs //updateRTE(\'rte1\'); updateRTEs(); //change the following line to true to submit form return true; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML) initRTE("' . $image_path . '", "", "", true); //--> </script> <style type="text/css"> @import url("'.$css_path.'"); .rteImage {margin: 0px;} </style> '; */ if ($validate) { } return $output; }
function formField($name = '', $value = '', $label = '', $type = '', $required = false, $readonly = false, $id = '', $properties = '') { $field_info = $this->getFieldInfo(); if (dev_not_null($name)) { $value = $value == '' ? $this->getField($name) : $value; $label = $label == '' ? $name : $label; $id = $id == '' ? $name : $id; if (isset($field_info[$name])) { $this_field = $field_info[$name]; $required = $required == '' ? !$this_field['Null'] || $this_field['Null'] == 'NO' ? true : false : $required; if ($type == '') { $field_type = strtolower($this_field['Type']); $field_type = $field_type == 'longtext' ? 'richtext' : (dev_is_substr($field_type, 'text') ? 'textarea' : $field_type); $field_type = dev_is_substr($field_type, 'lob') ? 'textarea' : $field_type; $field_type = dev_is_substr($field_type, 'int') ? 'int' : $field_type; $field_type = dev_is_substr($field_type, 'char') ? 'char' : $field_type; $field_type = dev_is_substr($field_type, 'date') ? 'date' : $field_type; if ($this_field['Key'] == 'PRI') { $field_type = 'hidden'; } elseif ($field_type == 'int' && isset($this_field['Length']) && $this_field['Length'] <= 1) { $field_type = 'check'; } elseif (dev_is_assoc($value)) { $field_type = 'select'; } elseif ($field_type == 'set' && dev_is_index($value)) { $field_type = 'radio'; } elseif ($field_type != 'set' && dev_is_index($value)) { $field_type = 'radio'; } switch ($field_type) { case 'int': $value = (int) $value; case 'char': default: $type = 'text'; break; case 'text': case 'textarea': case 'lob': $type = 'textarea'; break; case 'textarea': $type = 'textarea'; break; case 'date': $type = 'date'; break; case 'set': case 'check': if (dev_is_null($value)) { $value = 1; } else { $value = 1; } $type = 'checkbox'; break; case 'radio': $type = 'radio'; break; case 'select': $type = 'select'; break; case 'hidden': $type = 'hidden'; break; } } } } return "<tr><td>" . ($type != 'hidden' ? ($required ? '*' : '') . $label : '') . "</td><td>" . dev_draw_form_field($type, $name, '', $value, $required, $id, $readonly, $properties) . "</td></tr>"; }
function dev_write_log_r($file, $data, $delimiter = '') { if (is_array($file)) { $delimiter = dev_is_null($delimiter) ? "\t" : $delimiter; array_walk($data, 'dev_implode_ref', "\t"); $status = dev_save_file($file, $data); } else { $status = "Data not valid. Argument requires array.\n"; } return $status; }
public function status($message = null) { if (dev_is_null($message)) { $message = end($this->_status); return $message; } $this->_status[] = $message; }
function loadFieldInfo($table = '') { if (dev_is_null($table)) { $table = $this->getReferenceTable(); } $field_r = array(); $match = array(); $query = "SHOW COLUMNS FROM `{$table}`"; $result = mysql_query($query); while ($column = mysql_fetch_assoc($result)) { if (preg_match('/([\\d]+)/', $column['Type'], $match)) { $column['Length'] = $match[0]; } $column['Table'] = $table; $field_r[$column['Field']] = $column; } if (is_array($this->_reference_tables)) { foreach ($this->_reference_tables as $a) { $query = "SHOW COLUMNS FROM `{$a}`"; $result = mysql_query($query); while ($column = mysql_fetch_assoc($result)) { if (preg_match('/\\(([\\d*])\\)/', $column['Type'], $match)) { $column['Length'] = $match[0]; } $column['Table'] = $a; $field_r[$column['Field']] = $column; } } } $this->_field_info = $field_r; return true; }