Esempio n. 1
0
 public function dispatch()
 {
     if (isset($this->_response)) {
         return;
     }
     $response = null;
     $output = '';
     if (is_array($this->data)) {
         $response = array();
         foreach ($this->data as $d) {
             $response[] = $this->rpc($d);
         }
     } else {
         $response = $this->rpc($this->data);
     }
     if ($this->isForm && $this->isUpload) {
         $json = json_encode($response);
         $json = preg_replace("/"/", '\\"', $json);
         $output .= '<html><body><textarea>';
         $output .= $json;
         $output .= '</textarea></body></html>';
     } else {
         $output = json_encode($response);
     }
     $this->_response = $output;
     D::log("Response: " . $output);
     return $output;
 }
Esempio n. 2
0
	function query($sql, $returnType='null') {
		if($this->prepared == false) {
			$this->prepare($sql);
		}
		//echo "\n SQL call = " . $sql . "\n";
		
		$this->queries[] = $sql;
	//	$this->result = $this->connection->query($sql);
		D::log($sql, 'Sql call');
		
		$this->result = mysql_query($sql, $this->connection);
		
		$this->prepared = false;
		
		if(!$this->result) {
			D::log(mysql_error($this->connection), 'SQL Errors');
			return false;
		}
		
		$returnArray = array();
/* 	@todo
get rid of this switch and use an array of functions instead.
	 */
		switch ($returnType) {
			case 'object':
				if(!is_resource($this->result)) {
					D::stackTrace();
				}
				while($row = mysql_fetch_object($this->result)) {
					$returnArray[] = $row;
				}
				return $returnArray;
					
				
				break;
			case 'assoc':
				while($row = mysql_fetch_assoc($this->result)) {
					$returnArray[] = $row;
				}
				return $returnArray;
				break;
			case 'raw':
				return $this->result;
				break;
			default:
				return true;
		}
	}
Esempio n. 3
0
	function set($name) {
		//@todo rename this to just set
		$newPlace = 'app/themes/' . $name;
		D::log(LOC . '/' . $newPlace, 'new Place');
		if(is_dir(LOC . '/' . $newPlace)) {
			if(substr(URL, -1) == '?') {
				T::$url = $this->themeUrl = substr(URL, 0, -1) . $newPlace;
			} else {
				T::$url = $this->themeUrl = URL . $newPlace;
			}
			T::$loc = LOC . '/' . $newPlace;
			//$this->libs->Config->set('site', 'theme', $newPlace);
			return true;
		} else {
			D::error('Theme doesn\'t exist');
		}
	}
Esempio n. 4
0
	function set($name) {
		//@todo rename this to just set
		$newPlace = 'themes/' . $name;
		D::log($name, 'Theme Set');
	//	D::log(URL, 'URL');
		if(is_dir(APP_FOLDER . '/' . $newPlace)) {
			if(defined('URL')) {
				if(substr(URL, -1) == '?') {
					T::$url = $this->themeUrl = substr(URL, 0, -1) . APP_NAME . '/' . $newPlace . '/';
				} else {
					T::$url = $this->themeUrl = URL . APP_NAME . '/' . $newPlace . '/';
				}
			}			
			T::$loc =  $this->themeLoc = APP_FOLDER . '/' . $newPlace;
			//$this->libs->Config->set('site', 'theme', $newPlace);
			return true;
		} else {
			D::error('Theme doesn\'t exist');
		}
	}
Esempio n. 5
0
	function query($sql, $returnType) {
		if($this->prepared == false) {
			$this->prepare($sql);
		}
		//echo "\n SQL call = " . $sql . "\n";
		
		$this->queries[] = $sql;
		$this->result = $this->connection->query($sql);
		
		//D::log($this->connection->error, 'db error');
		D::log($sql, 'Sql call');
		if(!empty($this->connection->error)) {
			D::report('There is something wrong with the sql.', $this->connection->error);
		}

		$this->prepared = false;
		
		//return $this->result->fetch_all(MYSQLI_ASSOC);
		$return = array();
		
		switch ($returnType){
			case 'object':
				while($value = $this->result->fetch_object()) {
					$return[] = $value;
				}
				//D::log($return);
				return $return;
			case 'assoc':
				while($value = $this->result->fetch_assoc()) {
					$return[] = $value;
				}
				return $return; 
			case 'raw':
				return $this->result;
			default:
				return true;
		}
		
	}
Esempio n. 6
0
function properJsonDecode($json) {
	//maybe if we check something on the left we can validate that the value on the right is actaully a value and not part of a string.
	$return = json_decode(D::log(preg_replace('@"(\w*)"\s*:\s*(-?\d{9,})\s*([,|\}])@', '"$1":"$2"$3', $json), 'raw json') );
	switch(json_last_error()) {
        case JSON_ERROR_DEPTH:
            $echo = ' - Maximum stack depth exceeded';
        break;
        case JSON_ERROR_CTRL_CHAR:
            $echo = ' - Unexpected control character found';
        break;
        case JSON_ERROR_SYNTAX:
            $echo = ' - Syntax error, malformed JSON';
        break;
        case JSON_ERROR_NONE:
            $echo = ' - No errors';
        break;
	}
	D::growl($echo, 'json error');
	
	
	return $return;
}
Esempio n. 7
0
	function save() {
		D::log('saving session');
	//	if($this->checkCookie()) {
			D::log($this->_data, 'data');
			foreach($this->_changed as $key) {
				$this->libs->Query->update($this->libs->Config->get('Session', 'dataTableName'))->where(array('name' => $key, 'session' => $this->_id))->set(array('value' => serialize($this->_data[$key])))->go();
			}
			foreach($this->_new as $key) {
				$this->libs->Query->insert(array('name' => $key, 'value' => serialize($this->_data[$key]), 'session' => $this->_id))->into($this->libs->Config->get('Session', 'dataTableName'))->go();
			}
			if(!empty($this->_flashRemove)) {
				$this->libs->Query->delete()->where(array('name' => $this->_flashRemove, 'session' => $this->_id, 'flash' => 1))->from($this->libs->Config->get('Session', 'dataTableName'))->go();
			}
	//	}
	}
Esempio n. 8
0
function match($pattern, $subject)
{
    $matches = array();
    D::log($subject, 'subject');
    if (preg_match($pattern, $subject, $matches)) {
        return $matches;
    }
    return null;
}
Esempio n. 9
0
	public function f($funcName, $args=array()) {
		D::log(self::getCurrentDb(), 'current db');
		return self::callFuncOnDb(self::getCurrentDb(), $funcName, $args);
	}
Esempio n. 10
0
ini_set('always_populate_raw_post_data', 1);
$configFile = 'common/config.inc';
include_once "./alib/alib.inc";
global $debug, $config;
addIncludePath('./alib');
addIncludePath('./common');
addIncludePath('./php', TRUE);
include_once '../alib/iuser.inc';
include_once './common/functions.inc';
include_once './common/login.inc';
include_once './common/smartObjectDefs.inc';
// Connect to the db:
if (!is_object($db)) {
    $db = new idb($config->mainDB);
}
D::log('db');
D::v($db);
$login = new $config->loginModule();
if ($login->loggedIn || $config->allowNonLoggedIn) {
    global $user, $broker;
    $broker = new broker();
} elseif (stristr($_SERVER['REQUEST_URI'], 'api')) {
    $api = new publicAPI();
} else {
    $template = new template($config->loginTemplate);
    $template->set('title', $config->defaultTitle);
    $template->set('appName', $config->appName);
    $template->set('extLocation', $config->extLocation);
    $template->set('self', $config->self);
    if ($login->error && $login->error != 'Not logged in and not trying to log in.') {
        $template->set('badLogin', TRUE);
Esempio n. 11
0
<?php

echo B::xhtml5(array('head' => B::head(array('title' => 'SweetFramework Project Test')), 'body' => B::body(array('header' => B::header(array('title' => 'Dashboard', 'nav' => T::get('site/nav'))), 'content' => array(B::section(array('content' => array(B::h3(array('text' => 'Projects')), B::ul(array('items' => D::log(array_map(function ($v) {
    return V::get('project/brief', array('project' => $v));
}, $projects), 'projects')))))), B::section(array('content' => array(B::h3(array('text' => 'Users')), B::ul(array('items' => D::log(array_map(function ($v) {
    return V::get('users/brief', array('user' => $v));
}, M::Users()->limit(10)->all()), 'projects'))))))), 'footer' => B::footer(array('text' => 'Copyright ajcates ' . date('Y')))))));
Esempio n. 12
0
	static function stack($label='Label') {
		return D::log(
			"\n" . join(
				"\n",
				array_reverse(array_map(
					function($v) {
						//)
						return ' ' . $v['function'] . '();' . "\n    →" . substr(substr(@$v['file'], strlen(realpath(LOC))), 1, -4) . ' | line:' . @$v['line'];
					},
					debug_backtrace()
				))
			),
			$label . ' - Stack Trace'
		);
	}
Esempio n. 13
0
	function _build() {
		//puts all the stuff together in a magic happy fashion.
		$sqlString = '';
		switch ($this->_mode) {
			case 'select':
				//adds in our select values
				D::log('hello');
				$sqlString = 'SELECT ' . $this->_buildSelect() . "\n" . ' FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildJoins() . "\n" .  $this->_buildWhereString($this->_whereValue) . $this->_buildOrderBy() . $this->_buildLimit();
				break;
			case 'update':
				$sqlString = 'UPDATE ' . f_first(Query::$_fromValue) . "\n" . ' SET ' . $this->_buildSet($this->_setValue) . $this->_buildWhereString($this->_whereValue);
				break;
			case 'insert':
				/*
				f_reduce(
					function($a, $b) {
						return array_merge(array_keys((array)$b), array_keys((array)$a));
					},
					$this->_insert
				);
				*/
				if(!is_array(f_first($this->_insert) )) {
					$this->_insert = array($this->_insert);
				}
				$cols = array_map(function($v) { return Query::nullEscape($v, '`');}, array_keys(array_reduce($this->_insert, 'array_merge_recursive', array())));
				
				
				$sqlString = 'INSERT INTO ' . f_first((array) Query::$_fromValue) . ' (' . join(', ', $cols) . ') VALUES ' . join(', ', f_map(
					function($v) use($cols) {
						return '(' . join(',', f_map(
							function ($i) use ($v) {
								$i = substr($i, 1, -1);
								if(isset($v[$i])) {
									return Query::nullEscape($v[$i]);
								} else {
									return 'null';
								}
							},
							$cols
						)) . ')';
					},
					D::log($this->_insert, 'raw incert')
				));
				break;
			case 'delete':
				$sqlString = 'DELETE FROM ' . join(', ', Query::$_fromValue) . $this->_buildWhereString($this->_whereValue);
				break;
		}
		$this->sql = $sqlString;
		D::log($this->sql, 'SQL Build');
		return $this->sql;
	}
Esempio n. 14
0
	function _buildFind($find=null) {
		if(isset($find)) {
			foreach($find as $k => $arg) {
				if(is_int($k) && is_array($arg)) {
					unset($find[$k]);
					$find = array_merge($find, $this->_buildFind($arg));
				} else if(is_string($k) && array_key_exists($k, $this->fields)) {
					unset($find[$k]);
					$find[$this->tableName . '.' . $k] = $arg;
				} else if(is_numeric($arg)) {
					unset($find[$k]);
					$find[$this->tableName . '.' . $this->pk] = $arg;
				}
			}
		}
		D::log($find, 'FINDERS FEE');
		return $find;
	}
Esempio n. 15
0
 function regexArray($regexs)
 {
     $matches = array();
     D::log($_SERVER['QUERY_STRING']);
     foreach ($regexs as $regex => $func) {
         preg_match_all($regex, $_SERVER['QUERY_STRING'], $matches);
         if (f_first($matches)) {
             return f_push(array($func), f_map('f_first', f_rest($matches)));
         }
     }
     return false;
 }
Esempio n. 16
0
	function _build() {
		//puts all the stuff together in a magic happy fashion.
		$sqlString = '';
		switch ($this->_mode) {
			case 'select':
				//adds in our select values				
				//@todo Make the second parameter in `form()` actaully be a real "sub query"
					//$this->
				if(isset(self::$_fromLimit)) {
					self::$_fromValue = '(SELECT * FROM ' . Query::$_fromValue . $this->_buildLimit(Query::$_fromLimit) . ') AS ' . Query::$_fromValue;
				}
				
				
				$sqlString = 'SELECT ' . $this->_buildSelect() . "\n" . ' FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildJoins() .  $this->_buildWhereString($this->_whereValue) . $this->_buildGroupBy() . $this->_buildOrderBy() . $this->_buildLimit($this->_limit);
				break;
			case 'update':
				$sqlString = 'UPDATE ' . f_first(Query::$_fromValue) . "\n" . ' SET ' . $this->_buildSet($this->_setValue) . $this->_buildWhereString($this->_whereValue);
				break;
			case 'insert':
				/*
				f_reduce(
					function($a, $b) {
						return array_merge(array_keys((array)$b), array_keys((array)$a));
					},
					$this->_insert
				);
				*/
				if(!is_array(f_first($this->_insert) )) {
					$this->_insert = array($this->_insert);
				};
				$cols = array_map(function($v) { return Query::nullEscape($v, '`');}, array_keys(array_reduce($this->_insert, 'array_merge_recursive', array())));
				
				
				$sqlString = 'INSERT INTO ' . f_first((array) Query::$_fromValue) . ' (' . join(', ', $cols) . ') VALUES ' . join(', ', f_map(
					function($v) use($cols) {
						return '(' . join(',', f_map(
							function ($i) use ($v) {
								$i = substr($i, 1, -1);
								if(isset($v[$i])) {
									return Query::nullEscape($v[$i]);
								} else {
									return 'null';
								}
							},
							$cols
						)) . ')';
					},
					D::log($this->_insert, 'Insert Data')
				));
				break;
			case 'delete':
				$sqlString = 'DELETE FROM ' . join(', ', (array)Query::$_fromValue) . $this->_buildWhereString($this->_whereValue);
				break;
		}
		$this->sql = $sqlString;
		return $this->sql;
	}
Esempio n. 17
0
	private function regexArray($regexs) {
		$matches = array();
		foreach($regexs as $regex => $func) {
			preg_match_all($regex, $this->request, $matches);
			if(f_first($matches)) {
				D::log($regex, 'regex');
				return f_push(
					array($func),
					array_map('f_first', f_rest($matches))
				);
			}
		}
		return false;
	}
	function loadController($fileName, $part=0) {
		D::log($fileName, 'Loading Controller…');
		
		//$fileName = Events::callEvent('loadController', $fileName);

		require(LOC . 'Controllers/' . $fileName);
		
		//print_r($this);
		static $partCount = 0;

		$class = substr(strrchr('/' . $fileName, '/'), 1, -4);

		$page = $this->lib->Uri->loadUrl($class::$urlPattern, $part);
		
		if(is_array(f_last($page))) {
			if(is_array( f_first(f_last($page)) )) {
				$this->loadController(f_first(f_first(f_last($page))), $part+1);
				return true;
			}
			$page[$part] = f_first(f_last($page));
			//D::log($page[$part], 'page o parts');
		}


		D::log($page, 'Loading Controller…');
		$this->controller = new $class();
		
		$this->controller->getLibrary('Databases/Query.php');
		
		/*@todo make "shortcuts" more dynamic */
		$this->controller->template =& $this->controller->lib->Template;
		
		if(empty($page[$part])) {
			echo $this->controller->index();
		} else {
			if(method_exists($class, $page[$part])) {
				echo f_call(array(
					$this->controller,
					$page[$part]
				));
				return true;
			} else {
				return f_function(function() {
					header("HTTP/1.0 404 Not Found");
					echo '<h1>404 error</h1>'; //todo check for some sort of custom 404…
				});
			}
		}
		D::log($page, 'controller method array');
	}
Esempio n. 19
0
<?php

echo B::xhtml5(array('head' => B::head(array('title' => 'SweetFramework Project Test')), 'body' => B::body(array('header' => B::header(array('title' => 'Project Test', 'nav' => T::get('site/nav'))), 'content' => array(B::h1(array('text' => 'Projects')), B::ul(array('items' => D::log(array_map(function ($v) {
    return V::get('project/detail', array('project' => $v));
}, $projects), 'projects')))), 'footer' => B::footer(array('text' => 'Copyright ajcates ' . date('Y')))))));
Esempio n. 20
0
	function run($route=null) {
		D::log('App Run');
		$this->libs->Uri->callRoute($route);
	}