function loadAppServices($appName = SITENAME) { if (defined("BASEPATH")) { trigger_logikserror("App <b>'" . $appName . "'</b> has already been activated", E_ERROR); } define("BASEPATH", APPS_FOLDER . $appName . "/"); define("APPROOT", ROOT . BASEPATH); define("WEBAPPROOT", SiteLocation . BASEPATH); if (!file_exists(APPROOT)) { trigger_logikserror("Site Not Found <b>'" . $appName . "'</b>", E_ERROR); } $apps_cfg = APPROOT . "apps.cfg"; if (!file_exists($apps_cfg)) { trigger_logikserror("Site <b>'" . $appName . "'</b> Has Not Yet Been Activated (missing apps.cfg).", E_ERROR); } loadConfigs($apps_cfg); loadConfigDir(APPROOT . "config/"); if (!defined("APPS_CONFIG_FOLDER")) { loadConfigs(ROOT . "config/masters/folders.cfg"); } if (defined("LINGUALIZER_DICTIONARIES")) { Lingulizer::getInstance()->loadLocaleFile(LINGUALIZER_DICTIONARIES); } if (!defined("APPS_THEME")) { define("APPS_THEME", getConfig("APPS_THEME")); } if (!defined("APPS_TEMPLATEENGINE")) { define("APPS_TEMPLATEENGINE", getConfig("APPS_TEMPLATEENGINE")); } if (!defined("APPNAME")) { define("APPNAME", SITENAME); } return true; }
function _fs($fsKey = "app", $params = null) { //$fsd=LogiksFSDriver::findInstance($fsKey); //if($fsd) return $fsd; if ($params == null || !is_array($params)) { $cfg = loadJSONConfig("fs"); if (!isset($cfg[$fsKey])) { trigger_logikserror("FS ERROR, Connection Configuration Could Not Be Found For {$fsKey}"); } else { $params = $cfg[$fsKey]; } } if (!isset($params['basedir']) || strlen($params['basedir']) <= 0 || $params['basedir'] == "./") { $params['basedir'] = APPROOT; } if (!isset($params['driver'])) { trigger_logikserror("FS ERROR, Connection Configuration Could Not Be Found For {$fsKey}"); } $driver = $params['driver']; $driverClass = "{$driver}FSDriver"; $driverFile = __DIR__ . "/drivers/{$driverClass}.inc"; if (file_exists($driverFile)) { include_once $driverFile; } else { trigger_logikserror("FS ERROR, Driver {$driver} Could Not Be Found For {$fsKey}"); } $fs = new $driverClass($fsKey, $params); if (isset($params['basedir'])) { $fs->cd($params['basedir']); } return $fs; }
function session_check($redirect = false, $showErrorMsg = false) { $valid = false; if (defined("SITENAME")) { if (isset($_SESSION['SESS_USER_ID']) && isset($_SESSION['SESS_PRIVILEGE_ID']) && isset($_SESSION['SESS_ACCESS_ID']) && isset($_SESSION['SESS_TOKEN']) && isset($_SESSION['SESS_SITEID']) && isset($_SESSION['SESS_LOGIN_SITE']) && isset($_SESSION['SESS_ACCESS_SITES']) && isset($_SESSION['SESS_SITEID']) && $_SESSION['SESS_SITEID'] == SiteID) { if ($_SESSION['SESS_TOKEN'] == session_id() || $_SESSION['MAUTH_KEY'] == generateMAuthKey()) { if (is_numeric($_SESSION['SESS_PRIVILEGE_ID']) && $_SESSION['SESS_PRIVILEGE_ID'] > 0) { if ($_SESSION['SESS_LOGIN_SITE'] == $_REQUEST['site']) { $valid = true; } elseif (is_array($_SESSION['SESS_ACCESS_SITES']) && in_array(SITENAME, $_SESSION['SESS_ACCESS_SITES'])) { $valid = true; } } } } } if ($valid) { return true; } else { if ($redirect) { $relink = SiteLocation . "login"; redirectTo($relink, "SESSION Expired. Going To Login Page"); session_destroy(); exit; } else { if ($showErrorMsg) { trigger_logikserror("Accessing Forbidden Page", E_USER_ERROR, 401); } return false; } } }
function loadWidget($widget, $params = array()) { if (strlen($widget) <= 0) { return; } if (!Widgets::isEnabled($widget)) { return; } $widget = str_replace(".", "/", str_replace("/", "", $widget)); $cachePath = _metaCache("WIDGETS", $widget); if (!$cachePath) { $path = getAllWidgetsFolders(); foreach ($path as $a) { $f1 = ROOT . $a . $widget . "/index.php"; $f2 = ROOT . $a . $widget . ".php"; if (file_exists($f1)) { _metaCacheUpdate("WIDGETS", $widget, $f1); Widgets::printWidget($widget, $f1, $params); return false; } elseif (file_exists($f2)) { _metaCacheUpdate("WIDGETS", $widget, $f2); Widgets::printWidget($widget, $f2, $params); return false; } } if (MASTER_DEBUG_MODE == 'true') { trigger_logikserror("Widget Not Found :: " . $widget, E_LOGIKS_ERROR, 404); } } else { Widgets::printWidget($widget, $cachePath, $params); return false; } }
function loadModule($module, $notMandatory = false) { if (is_array($module)) { foreach ($module as $m) { loadModule($m, $notMandatory); } } else { if (strlen($module) <= 0) { return false; } $fpath = checkModule($module); if ($fpath && strlen($fpath) > 0) { $x = dirname(str_replace(ROOT, "", $fpath)) . "/"; $p = func_get_args(); unset($p[0]); $curModule = ""; if (isset($_ENV['CURRENT_MODULE'])) { $curModule = $_ENV['CURRENT_MODULE']; } $_ENV['CURRENT_MODULE'] = $module; $MODULE_PARAMS = $p; runPluginHooks($module, "preload"); include $fpath; runPluginHooks($module, "postload"); $_ENV['CURRENT_MODULE'] = $curModule; return true; } else { if (MASTER_DEBUG_MODE && !$notMandatory) { trigger_logikserror("Module Not Found :: " . $module, E_LOGIKS_ERROR, 404); } } } return false; }
function __testDevMode($addr, $msg = "OOPs, Down For Maintaince/Updates. Back In A Bit.") { if (is_array($addr)) { if (!in_array(_server("REMOTE_ADDR"), $addr)) { trigger_logikserror(808, E_USER_WARNING); exit; } } else { if (_server("REMOTE_ADDR") != $addr) { trigger_logikserror(808, E_USER_WARNING); exit; } } }
function __testDevMode($addr, $msg = "OOPs, Down For Maintaince/Updates. Back In A Bit.") { if (is_array($addr)) { if (!in_array($GLOBALS['LOGIKS']["_SERVER"]["REMOTE_ADDR"], $addr)) { trigger_logikserror(808, E_USER_WARNING); exit; } } else { if ($GLOBALS['LOGIKS']["_SERVER"]["REMOTE_ADDR"] != $addr) { trigger_logikserror(808, E_USER_WARNING); exit; } } }
function _dataSQL($sqlObj, $reload = false) { if (!is_a($sqlObj, "AbstractQueryBuilder")) { trigger_logikserror("_dataSQL only accepts AbstractQueryBuilder objects."); return false; } $cacheKey = "DATA-SQL::" . md5($sqlObj->_SQL()); if ($reload) { $cacheData = $sqlObj->_get(); _cache($cacheKey, $cacheData); } else { $cacheData = _cache($cacheKey); if ($cacheData == null || count($cacheData) <= 0) { $cacheData = $sqlObj->_get(); _cache($cacheKey, $cacheData); } } return new LogiksData($cacheData, $cacheKey); }
function loadVendor($vendor, $notMandatory = false) { if (is_array($vendor)) { foreach ($vendor as $m) { loadModule($m, $notMandatory); } } else { if (strlen($vendor) <= 0) { return false; } $fpath = checkVendor($vendor); if ($fpath && strlen($fpath) > 0) { include $fpath; return true; } else { if (MASTER_DEBUG_MODE && !$notMandatory) { trigger_logikserror("Vendor Not Found :: " . $vendor, E_LOGIKS_ERROR, 404); } } return false; } }
function _message($msgKey = "app", $params = null) { //$msd=LogiksMsgDriver::findInstance($msgKey); //if($msd) return $msd; if ($params == null || !is_array($params)) { $cfg = loadJSONConfig("message"); if (!isset($cfg[$msgKey])) { trigger_logikserror("MSG ERROR, Connection Configuration Could Not Be Found For {$msgKey}"); } else { $params = $cfg[$msgKey]; } } $driver = $params['driver']; $driverClass = "{$driver}MSGDriver"; $driverFile = __DIR__ . "/drivers/{$driverClass}.inc"; if (file_exists($driverFile)) { include_once $driverFile; } else { trigger_logikserror("MSG ERROR, Connection Driver Could Not Be Found For {$msgKey}"); } $msg = new $driverClass($msgKey, $params); return $msg; }
public function __construct($keyName, $params) { if (is_array($params['block'])) { $this->blockedStmnts = $params['block']; } else { $this->blockedStmnts = explode(",", $params['block']); } if (isset($params['readOnly'])) { $this->readOnly = $params['readonly']; } if (isset($params['allowSQL'])) { $this->allowSQL = $params['allowSQL']; } unset($params['block']); unset($params['readonly']); unset($params['instance']); unset($params['allowSQL']); $this->dbParams = $params; $this->keyName = $keyName; if (strlen($this->dbParams['host']) <= 0 || strlen($this->dbParams['database']) <= 0) { trigger_logikserror("Database ERROR, Wrong Credentials For {$keyName}"); } }
/** * Overloads isAndroid() | isAndroidtablet() | isIphone() | isIpad() | isBlackberry() | isBlackberrytablet() | isPalm() | isWindowsphone() | isWindows() | isGeneric() through isDevice() * * @param string $name * @param array $arguments * @return bool */ public function __call($name, $arguments) { $device = substr($name, 2); if ($name == "is" . ucfirst($device) && array_key_exists(strtolower($device), $this->devices)) { return $this->isDevice($device); } else { trigger_logikserror("Method {$name} not defined", E_WARNING); } }
<?php /* * A more complex router file for routing requests into the app used for logiks cms app. * When logiks cms takes over the app control mechanism, this router is used. * Good for avid Logiks Developers, who want to user LogiksPages System and cms based development * * Author: Bismay Kumar Mohapatra bismay4u@gmail.com on 07/07/2015 * Version: 1.0 */ if (!defined('ROOT')) { exit('No direct script access allowed'); } $lt = new LogiksTheme(APPS_THEME, SITENAME); $lp = new LogiksPage($lt); $pg = $lp->loadPage(PAGE); if ($pg) { $lp->printPage(); } else { trigger_logikserror("Sorry, '" . PAGE . "' page not found", E_LOGIKS_ERROR, 404); }
* autoformat Use toTitle/UCWORDS or not * debug Enable debug mode or not * cache To use cache or not * stype Type of command (py, php, etc.) */ if (defined('ROOT')) { exit('Only Direct Access Is Allowed'); } define('ROOT', dirname(dirname(__FILE__)) . '/'); require_once ROOT . 'services/initialize.php'; if (!isset($_REQUEST['scmd'])) { trigger_logikserror(901, E_USER_ERROR); exit; } loadAppServices(SITENAME); loadLogiksBootEngines(); //Check blacklists, bots, and others $security = new LogiksSecurity(); $security->checkServiceRequest(); runHooks("serviceStart"); $ctrl = new ServiceController(); //loads the parameters into the service controller $ctrl->setupRequest($_REQUEST); //access_control, privilege_model, APIKEY check if ($ctrl->checkRequest()) { //checks cache and if required executes the scmd and prints the output $ctrl->executeRequest(); } else { trigger_logikserror(905, E_USER_ERROR); } runHooks("serviceStop");
/** * Insert_batch statement * * Generates a platform-specific insert string from the supplied data * * @access public * @param string the table name * @param array the insert keys * @param array the insert values * @return string */ public function _insert_batchQ($table, $arr) { if (!isset($arr[0])) { trigger_logikserror("Database ERROR, _insert_batchQ needs array of data"); return false; } $keys = array_keys($arr[0]); $this->obj['table'] = $table; $this->obj['cols'] = $keys; $sql = "INSERT INTO {$table} "; $cols = ""; $vals = array(); foreach ($arr as $a => $b) { $v = array_values($b); $v = $this->cleanArr($v); array_push($vals, "(" . implode(",", $this->sqlDataArr($v)) . ")"); } $keys = implode(",", $keys); $sql .= "({$keys}) VALUES " . implode(",", $vals); $this->sql = $sql; return $this; }
public static function fromArray($arr, $dbInstance) { if (!is_a($dbInstance, "Database")) { trigger_logikserror("Database ERROR, DBInstance should be an object of Database"); } $table = null; $cols = ""; $where = null; $groupby = null; $having = null; $orderby = null; $index = 0; $limit = FALSE; $table = $arr['table']; $cols = $arr['cols']; if (isset($arr['where'])) { $where = $arr['where']; } if (isset($arr['groupby'])) { $groupby = $arr['groupby']; } if (isset($arr['having'])) { $having = $arr['having']; } if (isset($arr['orderby'])) { $orderby = $arr['orderby']; } if (isset($arr['limit'])) { $limit = $arr['limit']; } if (isset($arr['index'])) { $index = $arr['index']; } if (is_array($table)) { $obj = QueryBuilder::fromArray($table, $dbInstance); $table = $obj->_SQL(); } $objx = QueryBuilder::create($dbInstance)->_selectQ($table, $cols, $where); //$objx->_where($where); if (isset($arr['join'])) { foreach ($arr['join'] as $jn) { $query = $jn['query']; $condition = $jn['condition']; $as = $jn['as']; $type = $jn['type']; $objx->_join($query, $condition, $as, $type); } } $objx->_groupby($groupby, $having); $objx->_orderby($orderby); $objx->_limit($limit, $index); return $objx; }
public function grepName($path, $q) { trigger_logikserror("Current FS Driver Does Not Support This"); }
} if (!defined("BASEPATH")) { if (isset($_GET['site']) && $_GET['site'] != SITENAME) { trigger_logikserror("Site <b>'{$_GET['site']}'</b> does not exist.", E_ERROR); } //Load the app.cfg and app Config Folder loadLogiksApp(SITENAME); logiksRequestBoot(); loadLogiksBootEngines(); $security = new LogiksSecurity(); //Global Appsite Access Controls : this ensures prilimanary user access validation : only checks if logged in or not $security->checkPageRequest(); $device = getUserDeviceType(); $routerPage = getConfig("APPS_ROUTER"); if (strlen($routerPage) <= 0) { trigger_logikserror("Site <b>'" . SITENAME . "'</b> Does Not Have ROUTER Defined.", E_ERROR); } $routerFiles = array(APPROOT . "{$routerPage}.php", ROOT . API_FOLDER . "libs/routers/{$routerPage}.php"); $routerLoaded = false; foreach ($routerFiles as $rfile) { if (file_exists($rfile)) { $routerLoaded = true; runHooks("startup"); include_once $rfile; break; } } if (!$routerLoaded) { trigger_logikserror("Site <b>'" . SITENAME . "'</b> Does Not Have ROUTER Defined.", E_ERROR); } }
public function __call($method, $arguments) { if (strpos($method, "_") === 0) { $qbuilder = $this->objQBuilder; return call_user_func_array(array($qbuilder::create($this), $method), $arguments); } elseif (strpos($method, "get_") === 0) { return call_user_func_array(array($this->objDriver, $method), $arguments); } elseif (strpos($method, "fetch") === 0 || strpos($method, "free") === 0 || strpos($method, "run") === 0) { return call_user_func_array(array($this->objDriver, $method), $arguments); } else { trigger_logikserror("Database ERROR, [{$method}] Method Not Found [" . $this->dbParams('driver') . "]"); } }
function logiksServiceBoot() { if (LogiksSingleton::funcCheckout("logiksServiceBoot")) { $dm = new DomainMap(); $dm->detect(); if (!defined("SITENAME")) { trigger_error("SITE NOT DEFINED", E_USER_ERROR); } if (!isset($_REQUEST['scmd'])) { $rURI = explode("?", _server('REQUEST_URI')); $rURI = explode(".", $rURI[0]); if (isset($rURI[1])) { $_REQUEST['format'] = $rURI[1]; } $scmdArr = explode("services/", $rURI[0]); if (count($scmdArr) > 1) { array_shift($scmdArr); } $scmdArr = explode("/", $scmdArr[0]); $_REQUEST['scmd'] = $scmdArr[0]; if (isset($scmdArr[1])) { $_REQUEST['action'] = $scmdArr[1]; } if (count($scmdArr) > 2) { array_shift($scmdArr); $_REQUEST['actionslug'] = implode("-", $scmdArr); $_REQUEST['slug'] = $scmdArr; } } if (!isset($_REQUEST['action'])) { //TODO : GET, POST, PUT, DELETE, PURGE, VIEW // PATCH, COPY, HEAD, OPTIONS, LINK, UNLINK, LOCK, UNLOCK, PROPFIND, $_REQUEST['action'] = ""; } if (!isset($_REQUEST['actionslug'])) { $_REQUEST['slugpath'] = $_REQUEST['action']; } if (!isset($_REQUEST['slug'])) { $_REQUEST['slug'] = array(); } $_REQUEST['site'] = SITENAME; //Handling Encoded/Encrypted QUERY_STRINGS if (isset($_REQUEST['encoded'])) { $query = $_REQUEST['encoded']; $queryo = decryptURL($query); $query = explode("&", $queryo); foreach ($query as $q) { $q = explode("=", $q); if (count($q) == 0) { } elseif (count($q) == 1) { $_REQUEST[$q[0]] = ""; } else { $qs = $q[0]; unset($q[0]); $qv = implode("=", $q); $_REQUEST[$qs] = $qv; } } _envData("SERVER", 'QUERY_STRING', "&{$queryo}"); } $cmdFormat = explode(",", SUPPORTED_OUTPUT_FORMATS); if (!isset($_REQUEST['format'])) { $_REQUEST['format'] = getConfig("DEFAULT_OUTPUT_FORMAT"); } else { $_REQUEST['format'] = strtolower($_REQUEST['format']); if (!in_array($_REQUEST['format'], $cmdFormat)) { trigger_logikserror(902, E_USER_ERROR); } else { $_GET['format'] = $_REQUEST['format']; } } } }
function printServiceData($arrData, $format = null, $statusCode = 200) { if ($statusCode == null || !is_numeric($statusCode)) { $statusCode = 200; } $envelop = getMsgEnvelop(); if ($format == null) { $format = $_REQUEST['format']; } if (getConfig("SERVICE_SHOW_REQUEST")) { $arrData['Request']['uri'] = SiteLocation . $GLOBALS['LOGIKS']["_SERVER"]['REQUEST_URI']; $arrData['Request']['site'] = $_REQUEST['site']; $arrData['Request']['scmd'] = $_REQUEST['scmd']; $arrData['Request']['format'] = $format; if (isset($GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"])) { $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_TIME_FLOAT"]; } else { $arrData['Request']['latency'] = microtime(true) - $GLOBALS['LOGIKS']["_SERVER"]["REQUEST_SERVICE_START"]; } $arrData['Request']['slug'] = array(); foreach ($_REQUEST['slug'] as $key => $value) { $arrData['Request']['slug']["SLUG_{$key}"] = $value; } } $htmlFormats = array("list", "select", "table"); if (in_array($format, $htmlFormats)) { if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == "true") { header("Content-Type:text/text"); } else { header("Content-Type:text/html"); } } else { header("Content-Type:text/{$format}"); } if (getConfig("SERVICE_SHOW_ERROR_CODE")) { header("Status: {$statusCode}"); //header(':', true, $statusCode); header("HTTP/1.1 {$statusCode}"); } $msgData = $arrData['Data']; // $msgData=array( // // "a"=>"m", // // "c"=>"n", // // "a","b", // // "a"=>array("x"=>array("m"=>"n"),"z"=>"w"), // // "b"=>array("m"=>"n","o"=>"p"), // // array("x"=>array("m"=>"n"),"z"=>"w"), // // array("m"=>"n","o"=>"p"), // ); switch ($format) { case 'table': if (is_array($msgData)) { if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") { printFormattedArray($msgData, false, "table"); } else { printFormattedArray($msgData, true, "table"); } } else { echo "<tr><td>{$msgData}</td></tr>"; } break; case 'list': if (is_array($msgData)) { if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") { printFormattedArray($msgData, false, "list"); } else { printFormattedArray($msgData, true, "list"); } } else { echo "<li>{$msgData}</li>"; } break; case 'select': if (is_array($msgData)) { if (isset($_REQUEST['autoformat']) && $_REQUEST['autoformat'] == "false") { printFormattedArray($msgData, false, "select"); } else { printFormattedArray($msgData, true, "select"); } } else { echo "<option>{$msgData}</option>"; } break; case 'xml': $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><service></service>"); arrayToXML($arrData, $xml); //array_walk_recursive($arrData, array ($xml, 'addChild')); echo $xml->asXML(); break; case 'json': echo json_encode($arrData); break; case 'txt': if (is_array($msgData)) { trigger_logikserror(900, E_USER_ERROR); } else { $msgData = strip_tags($msgData); echo $msgData; } default: //Anything else (raw,css,js) if (is_array($msgData)) { printFormattedArray($msgData); } else { $msgData = strip_tags($msgData); echo $msgData; } break; } }
function loadHelpers($helperNames, $path = "*", $type = "include_once") { if (is_array($helperNames)) { foreach ($helperNames as $x => $a) { $b = loadHelpers($a); } } else { $cachePath = _metaCache("HELPERS", $helperNames); if (!$cachePath || !file_exists($cachePath)) { $helperPath = helper_exists($helperNames); } else { $helperPath = $cachePath; } if (file_exists($helperPath)) { if ($type == "require_once") { require_once $helperPath; } elseif ($type == "require") { require $helperPath; } elseif ($type == "include_once") { include_once $helperPath; } else { include $helperPath; } } else { trigger_logikserror("Helper Not Found :: " . $helperNames, E_LOGIKS_ERROR, 404); } } }