Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
        if (!$uid) {
            continue;
        }
        // no assocdata, maybe this user never paid.
        $uinfo = $this->GetUserInfo($uid);
        if (!is_array($uinfo) || $uinfo[0] == FALSE) {
            $this->Audit($uid, $this->GetName(), sprintf('Order %d deleted but cannot find user account', $order_id));
            return;
        }
        $uinfo = $uinfo[1];
        switch ($this->GetPreference('ecomm_orderdeleted')) {
            case 'delete':
                $this->DeleteAllUserProperties('', $uid, true);
                $this->DeleteUser($uid);
                $this->Audit($uid, $this->GetName(), sprintf('Deleted user %s because order %d was deleted', $uinfo['username'], $order_id));
                break;
            case 'expire':
                $this->SetUser($uid, $uinfo['username'], $uinfo['password'], time() - 3600, false);
                $this->Audit($uid, $this->GetName(), sprintf('Expired user %s because order %d was deleted', $uinfo['username'], $order_id));
                break;
            case 'none':
            default:
                break;
        }
    }
}
// setup for another order... shouldn't happen, but just in case.
cge_tmpdata::erase(__FILE__);
#
# EOF
#
 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;
 }
Ejemplo n.º 5
0
 /**
  * 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');
 }
Ejemplo n.º 6
0
 /**
  * @ignore
  */
 private static function _setup()
 {
     if (!is_array(self::$_data)) {
         self::$_data = array();
     }
 }
 public function DoAction($name, $id, $params, $returnid = '')
 {
     if (!method_exists($this, 'set_action_id') && $this->GetName() != 'CGExtensions') {
         die('FATAL ERROR: A module derived from CGExtensions is not handling the set_action_id method');
     }
     $this->set_action_id($id);
     // handle the stupid input type='image' problem.
     foreach ($params as $key => $value) {
         if (endswith($key, '_x')) {
             $base = substr($key, 0, strlen($key) - 2);
             if (isset($params[$base . '_y']) && !isset($params[$base])) {
                 $params[$base] = $base;
             }
         }
     }
     $smarty = cmsms()->GetSmarty();
     $smarty->assign('actionid', $id);
     $smarty->assign('actionparams', $params);
     $smarty->assign('returnid', $returnid);
     $smarty->assign_by_ref('mod', $this);
     $smarty->assign_by_ref($this->GetName(), $this);
     cge_tmpdata::set('module', $this->GetName());
     if ($returnid == '') {
         if (isset($params['cg_activetab'])) {
             $this->_current_tab = trim($params['cg_activetab']);
             unset($params['cg_activetab']);
         }
         if (isset($params['cg_error'])) {
             $this->_errormsg = explode(':err:', $params['cg_error']);
             unset($params['cg_error']);
         }
         if (isset($params['cg_message'])) {
             $this->_messages = explode(':msg:', $params['cg_message']);
             unset($params['cg_message']);
         }
         $this->DisplayErrors();
         $this->DisplayMessages();
     }
     $cge = $this->GetModuleInstance('CGExtensions');
     if ($cge->GetPreference('cache_modulecalls', 0) && (!isset($params['nocache']) || !$params['nocache']) && cms_cache_handler::can_cache()) {
         $key = '';
         if (isset($params['cache_key'])) {
             $key = trim($params['cache_key']);
         } else {
             $tmp = debug_backtrace();
             $bt = array();
             foreach ($tmp as $elem) {
                 $bt[] = $elem['file'] . ':' . $elem['line'];
             }
             $key = 'm' . md5($this->GetName() . serialize($params) . serialize($bt) . $id . $returnid);
         }
         $output = '';
         if (!cms_cache_handler::get_instance()->exists($key, 'cge_module')) {
             @ob_start();
             parent::DoAction($name, $id, $params, $returnid);
             $output = @ob_get_contents();
             @ob_end_clean();
             if (strlen($output)) {
                 cms_cache_handler::get_instance()->set($key, $output, 'cge_module');
             }
         } else {
             $output = cms_cache_handler::get_instance()->get($key, 'cge_module');
         }
         echo $output;
         return;
     }
     parent::DoAction($name, $id, $params, $returnid);
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 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;
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }