/** * Takes an exception message of the form [module]%%key[%%suffix] * and format a language string * * @param string $str The exception message * @param int $code The exception code * @param \Exception $parent a parent exception */ public function __construct($str = '', $code = 0, \Exception $parent = null) { if (strpos($str, '%%')) { $parts = explode('%%', $str, 3); if (count($parts) > 1) { $module = trim($parts[0]); $key = trim($parts[1]); if (!$module) { $module = cge_tmpdata::get('module'); if (!$module) { $smarty = cmsms()->GetSmarty(); $obj = $smarty->get_template_vars('mod'); if (is_object($obj)) { $module = $obj->GetName(); } } } if ($module && $key) { $mod = \cms_utils::get_module($module); if ($mod) { $str = $mod->Lang($key); } if (isset($parts[2]) && $parts[2]) { $str .= ' ' . $parts[2]; } } } } parent::__construct($str, $code, $parent); }
public static function get_fielddefs() { if (cge_tmpdata::exists('cgfb_fielddefs')) { return cge_tmpdata::get('cgfb_fielddefs'); } $db = cmsms()->GetDb(); $query = 'SELECT * FROM ' . CGFEEDBACK_TABLE_FIELDDEFS . ' ORDER BY iorder'; $tmp = $db->GetArray($query); if (is_array($tmp)) { for ($i = 0; $i < count($tmp); $i++) { $tmp[$i]['attribs'] = unserialize($tmp[$i]['attribs']); if (isset($tmp[$i]['attribs']['options'])) { $t2 = cge_array::explode_with_key($tmp[$i]['attribs']['options'], '=', "\n"); $tmp[$i]['attribs']['options'] = array_flip($t2); } } $tmp = cge_array::to_hash($tmp, 'id'); cge_tmpdata::set('cgfb_fielddefs', $tmp); return $tmp; } }
public static function cge_array_getall($params, &$smarty) { if (!isset($params['array'])) { // no params, do nothing. return; } $arr = trim($params['array']); if ($arr == '') { return; } if (!cge_tmpdata::exists($arr)) { return; } $data = cge_tmpdata::get($arr); if (isset($params['assign'])) { $smarty->assign(trim($params['assign']), $data); return; } return $data; }
/** * Get the name of the module that the current action is for. * (only works with modules derived from CGExtensions). * This method is useful to find the module action that was used to send an event. * * @return string */ public function GetActionModule() { return cge_tmpdata::get('module'); }
public function autoload($classname) { if (!is_object($this)) { return FALSE; } // check for classes. global $CMS_ADMIN_PAGE; $prefix = ''; // if( !isset($CMS_ADMIN_PAGE) ) // { // $prefix = ''; // } // else // { // $config = cmsms()->GetConfig(); // $prefix = $config['root_path'].'/'; // } $fn = $prefix . $this->GetModulePath() . "/lib/class.{$classname}.php"; if (file_exists($fn)) { require_once $fn; return TRUE; } // check for interfaces $fn = $prefix . $this->GetModulePath() . "/lib/interface.{$classname}.php"; if (file_exists($fn)) { require_once $fn; return TRUE; } // check for a master file $fn = $prefix . $this->GetModulePath() . "/lib/extraclasses.php"; if (file_exists($fn)) { $extraclasses = array(); if (cge_tmpdata::exists('extraclasses')) { $extraclasses = cge_tmpdata::get('extraclasses'); } if (!in_array($fn, $extraclasses)) { require_once $fn; $extraclasses[] = $fn; cge_tmpdata::set('extraclasses', $extraclasses); return TRUE; } } return FALSE; }
/** * A quick wrapper around cms_utils::get_module that will try to use a module name saved in tmpdata * (the module name is stored in tmpdata in each request, for CGExtensions derived modules) * * @deprecated * @see cms_utils::get_module * @param string $module_name * @param string $version The desired module version * @return object The module object. or null */ public static function &get_module($module_name = '', $version = '') { if (empty($module_name)) { $version = ''; if (cge_tmpdata::exists('module')) { $module_name = cge_tmpdata::get('module'); } } $out = null; if ($module_name) { $out = cms_utils::get_module($module_name, $version); } return $out; }
public static function &get_module($module_name = '', $version = '', $op = '') { if (empty($module_name) && cge_tmpdata::exists('module')) { $module_name = cge_tmpdata::get('module'); } return cms_utils::get_module($module_name, $version); }
private function _old_LoggedInId() { $gCms = cmsms(); $config = $gCms->GetConfig(); if (cge_tmpdata::exists('feu_logginid')) { // this will save a few queries in each request return cge_tmpdata::get('feu_logginid'); } $sessionid = session_id(); $this->ExpireUsers(); if ($sessionid == "") { return false; } $db = $this->GetDb(); $module = $this->GetModule(); $expirytime = $module->GetPreference('user_session_expires'); $expireusers_interval = $module->GetPreference('expireusers_interval'); $interval = min($expireusers_interval, $expirytime); $q = "SELECT userid FROM " . cms_db_prefix() . "module_feusers_loggedin WHERE sessionid=?"; $p = array($sessionid); $result = $db->GetOne($q, $p); if ($result) { // we know this user is logged in. $retval = $result; // now touch the lastused // this will ensure that every time we check that a user is // logged in, it touches his logged in entry $q = "UPDATE " . cms_db_prefix() . "module_feusers_loggedin SET lastused = ? where sessionid = ?"; $db->Execute($q, array(time(), $sessionid)); // refresh the cookie. @setcookie('feu_sessionid', $sessionid, time() + $expirytime, "/"); @setcookie('feu_uid', $uid, time() + $expirytime, "/"); cge_tmpdata::set('feu_logginid', $retval); // set some session data to save some db queries. // and send an event. $module->SendEvent('OnRefreshUser', array('id' => $retval)); return $retval; } else { if ($module->GetPreference('cookie_keepalive', 0) && isset($_COOKIE['feu_sessionid']) && isset($_COOKIE['feu_uid'])) { // no session id, but we have a cookie, so what we'll do // is first check to see if the session is still logged in // if it is, force a logout for that session id // and start a new record, otherwise, ignore the cookie $uid = $_COOKIE['feu_uid']; $sessionid = $_COOKIE['feu_sessionid']; // delete the existing record $q = "DELETE FROM " . cms_db_prefix() . "module_feusers_loggedin \n WHERE sessionid = ?"; $db->Execute($q, array($sessionid)); // log the user in // todo, log this too, // rationalize this code with Login() and Logout() methods @session_start(); $sessionid = session_id(); $q = "INSERT INTO " . cms_db_prefix() . "module_feusers_loggedin\n (sessionid,lastused,userid)\n VALUES (?,?,?)"; $db->Execute($q, array($sessionid, time(), $uid)); // set the cookie again @setcookie('feu_sessionid', $sessionid, time() + $expirytime, "/"); @setcookie('feu_uid', $uid, time() + $expirytime, "/"); cge_tmpdata::set('feu_logginid', $uid); $module->SendEvent('OnRefreshUser', array('id' => $uid)); return $uid; } else { $res = $this->_attempt_login_with_cookie(); if (!is_array($res) || $res[0] == FALSE) { return false; } $module->SendEvent('OnRefreshUser', array('id' => $res[0])); return $res[0]; } } return false; }
/** * Add a css file to the output. * * @param string $file The filename. If not an absolute path, then search for the file within the current module directory (if any), the uploads path, and then the root path. * @param null|string[] $depends Array of libraries that this css file depends upon. * @param bool $nominify If true, the library code will not be minified. */ public static function add_cssfile($file, $depends = null, $nominify = true) { if (!$file || !is_string($file)) { return; } // assume full path $tryfiles = array($file); // assume relative to module directory $module_name = \cge_tmpdata::get('module'); if ($module_name) { $mod = \cms_utils::get_module($module_name); if ($mod) { $tryfiles[] = $mod->GetModulePath() . "/{$file}"; } } // assume relative to uploads path $config = cmsms()->GetConfig(); $tryfiles[] = $config['uploads_path'] . "/{$file}"; $tryfiles[] = $config['root_path'] . "/{$file}"; $fnd = null; foreach ($tryfiles as $fn) { if (file_exists($fn)) { $fnd = $fn; break; } } if (!$fnd) { throw new \CmsInvalidDataException("could not find jsfile {$file} in any of the searched directories"); } $obj = new \StdClass(); $obj->cssfile = $fnd; if ($depends) { if (!is_array($depends)) { $depends = array($depends); } $obj->depends = $depends; } if ($nominify) { $obj->css_nominify = true; } self::$_required[] = $obj; }