/**
  * Get a reference to the only instance of database class and connects to DB
  * 
  * if the class has not been instantiated yet, this will also take 
  * care of that
  * 
  * @static
  * @staticvar   object  The only instance of database class
  * @return      object  Reference to the only instance of database class
  */
 function &getDatabaseConnection()
 {
     static $instance;
     if (!isset($instance)) {
         $file = XOOPS_ROOT_PATH . '/class/database/' . XOOPS_DB_TYPE . 'database.php';
         require_once $file;
         /* patch from */
         if (defined('XOOPS_DB_ALTERNATIVE') && class_exists(XOOPS_DB_ALTERNATIVE)) {
             $class = XOOPS_DB_ALTERNATIVE;
         } else {
             /* patch to */
             if (!defined('XOOPS_DB_PROXY')) {
                 $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseSafe';
             } else {
                 $class = 'Xoops' . ucfirst(XOOPS_DB_TYPE) . 'DatabaseProxy';
             }
         }
         $instance =& new $class();
         $instance->setLogger(XoopsLogger::instance());
         $instance->setPrefix(XOOPS_DB_PREFIX);
         if (!$instance->connect()) {
             trigger_error("notrace:Unable to connect to database", E_USER_ERROR);
         }
     }
     return $instance;
 }
Exemplo n.º 2
0
/**
 * @package     smarty xoopsplugin
 * 
 * @author	    Hu Zhenghui <*****@*****.**>
 *  
 * how to use
 * The following code inserted in the template
 *  
 * @param module string module dirname
 * @param file  string block funciton file
 * @param show_func string show block function
 * @param options= string show block function's option
 * @param cachetime int  cachetime Unit for seconds 
 * @param user mix Generate cache solution

<{freeBlkTpl id=1}>
    <link rel="stylesheet" href="<{$xoops_url}>/modules/tag/templates/style.css" />
    <div class="tag-cloud" style="line-height: 150%; padding: 5px;">
    <{foreach item=tag from=$block.tags}>
    	<span class="tag-level-<{$tag.level}>" style="font-size: <{$tag.font}>%; display: inline; padding-right: 5px;">
    		<a href="<{$xoops_url}>/modules/<{$block.tag_dirname}>/view.tag.php<{$smarty.const.URL_DELIMITER}><{$tag.id}>/" title="<{$tag.term}>"><{$tag.term}></a>
    	</span>
    <{/foreach}>
    </div>
<{/freeBlkTpl}>
*/
function smarty_block_freeBlkTpl($params, $content, &$smarty, &$repeat)
{
    static $old_block;
    if (empty($content)) {
        $old_block = $smarty->get_template_vars('block');
        if (!isset($params['id'])) {
            return;
        }
        $block_id = intval($params['id']);
        static $block_objs;
        $blockObj = $GLOBALS['xoopsTpl']->_tpl_vars['ezblocks'][$block_id];
        // ezsky hack
        if (empty($blockObj)) {
            return false;
        }
        $xoopsLogger =& XoopsLogger::instance();
        $template =& $GLOBALS['xoopsTpl'];
        xoops_load("cache");
        $cache_key = 'xoBlkTpl_' . md5(var_export($params, true));
        $bcachetime = intval($blockObj->getVar('bcachetime'));
        if (!$bcachetime || !($bresult = XoopsCache::read($cache_key))) {
            $xoopsLogger->addBlock($blockObj->getVar('name'));
            if (!($bresult = $blockObj->buildBlock())) {
                return;
            }
            if (isset($bcachetime)) {
                XoopsCache::write($cache_key, $bresult, $bcachetime);
            }
        } else {
            $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime);
        }
        $old_block = $smarty->get_template_vars('block');
        $smarty->assign('block', $bresult);
    } else {
        echo $content;
        $smarty->assign('block', $old_block);
    }
}
Exemplo n.º 3
0
/**
 * XOOPS Block management
 * 
 * @copyright   The XOOPS project http://www.xoops.org/
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package     smarty xoopsplugin
 * @since       2.3.3 ezsky hack
 * @author      ezsky <*****@*****.**> 
 * @version     $Id: function.block.php $
 * @package     smarty xoops plugin
 *  Examples:
 *  <{freeBlock id=1}>                   displays just the block content 
 */
function smarty_function_freeBlock($params, &$smarty)
{
    if (!isset($params['id'])) {
        return;
    }
    $block_id = intval($params['id']);
    static $block_objs;
    $blockObjs = $smarty->get_template_vars('ezblocks');
    // ezsky hack
    $blockObj = $blockObjs[$block_id];
    if (empty($blockObj)) {
        return false;
    }
    $xoopsLogger =& XoopsLogger::instance();
    $template =& $GLOBALS['xoopsTpl'];
    $bcachetime = intval($blockObj->getVar('bcachetime'));
    if (empty($bcachetime)) {
        $template->caching = 0;
    } else {
        $template->caching = 2;
        $template->cache_lifetime = $bcachetime;
    }
    $template->setCompileId($blockObj->getVar('dirname', 'n'));
    $tplName = ($tplName = $blockObj->getVar('template')) ? "db:{$tplName}" : "db:system_block_dummy.html";
    $cacheid = 'blk_' . $block_id;
    if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
        $xoopsLogger->addBlock($blockObj->getVar('name'));
        if (!($bresult = $blockObj->buildBlock())) {
            return;
        }
        $template->assign('block', $bresult);
        $template->display($tplName, $cacheid);
    } else {
        $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime);
        $template->display($tplName, $cacheid);
    }
    $template->setCompileId($blockObj->getVar('dirname', 'n'));
}
Exemplo n.º 4
0
set_magic_quotes_runtime(0);
if (function_exists('mb_http_output')) {
    mb_http_output('pass');
}
$image_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (empty($image_id)) {
    header('Content-type: image/gif');
    readfile(XOOPS_UPLOAD_PATH . '/blank.gif');
    exit;
}
$xoopsOption['nocommon'] = 1;
include './mainfile.php';
include XOOPS_ROOT_PATH . '/include/functions.php';
include_once XOOPS_ROOT_PATH . '/class/logger.php';
include_once XOOPS_ROOT_PATH . "/class/module.textsanitizer.php";
$xoopsLogger =& XoopsLogger::instance();
$xoopsLogger->startTime();
include_once XOOPS_ROOT_PATH . '/class/database/databasefactory.php';
define('XOOPS_DB_PROXY', 1);
$xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
// ################# Include class manager file ##############
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
require_once XOOPS_ROOT_PATH . '/class/criteria.php';
$imagehandler =& xoops_gethandler('image');
$criteria = new CriteriaCompo(new Criteria('i.image_display', 1));
$criteria->add(new Criteria('i.image_id', $image_id));
$image = $imagehandler->getObjects($criteria, false, true);
if (count($image) > 0) {
    header('Content-type: ' . $image[0]->getVar('image_mimetype'));
    header('Cache-control: max-age=31536000');
    header('Expires: ' . gmdate("D, d M Y H:i:s", time() + 31536000) . 'GMT');
Exemplo n.º 5
0
 function db_manager()
 {
     $this->db = XoopsDatabaseFactory::getDatabase();
     $this->db->setPrefix(XOOPS_DB_PREFIX);
     $this->db->setLogger(XoopsLogger::instance());
 }
Exemplo n.º 6
0
function make_cblock()
{
    global $xoopsUser, $xoopsOption;
    $xoopsblock = new XoopsBlock();
    $cc_block = $cl_block = $cr_block = "";
    $arr = array();
    if ($xoopsOption['theme_use_smarty'] == 0) {
        if (!isset($GLOBALS['xoopsTpl']) || !is_object($GLOBALS['xoopsTpl'])) {
            include_once XOOPS_ROOT_PATH . '/class/template.php';
            $xoopsTpl = new XoopsTpl();
        } else {
            $xoopsTpl =& $GLOBALS['xoopsTpl'];
        }
        if (is_object($xoopsUser)) {
            $block_arr = $xoopsblock->getAllBlocksByGroup($xoopsUser->getGroups(), true, XOOPS_CENTERBLOCK_ALL, XOOPS_BLOCK_VISIBLE);
        } else {
            $block_arr = $xoopsblock->getAllBlocksByGroup(XOOPS_GROUP_ANONYMOUS, true, XOOPS_CENTERBLOCK_ALL, XOOPS_BLOCK_VISIBLE);
        }
        $block_count = count($block_arr);
        $xoopsLogger =& XoopsLogger::instance();
        for ($i = 0; $i < $block_count; $i++) {
            $bcachetime = intval($block_arr[$i]->getVar('bcachetime'));
            if (empty($bcachetime)) {
                $xoopsTpl->xoops_setCaching(0);
            } else {
                $xoopsTpl->xoops_setCaching(2);
                $xoopsTpl->xoops_setCacheTime($bcachetime);
            }
            $btpl = $block_arr[$i]->getVar('template');
            if ($btpl != '') {
                if (empty($bcachetime) || !$xoopsTpl->is_cached('db:' . $btpl)) {
                    $xoopsLogger->addBlock($block_arr[$i]->getVar('name'));
                    $bresult =& $block_arr[$i]->buildBlock();
                    if (!$bresult) {
                        continue;
                    }
                    $xoopsTpl->assign_by_ref('block', $bresult);
                    $bcontent =& $xoopsTpl->fetch('db:' . $btpl);
                    $xoopsTpl->clear_assign('block');
                } else {
                    $xoopsLogger->addBlock($block_arr[$i]->getVar('name'), true, $bcachetime);
                    $bcontent =& $xoopsTpl->fetch('db:' . $btpl);
                }
            } else {
                $bid = $block_arr[$i]->getVar('bid');
                if (empty($bcachetime) || !$xoopsTpl->is_cached('db:system_dummy.html', 'blk_' . $bid)) {
                    $xoopsLogger->addBlock($block_arr[$i]->getVar('name'));
                    $bresult =& $block_arr[$i]->buildBlock();
                    if (!$bresult) {
                        continue;
                    }
                    $xoopsTpl->assign_by_ref('dummy_content', $bresult['content']);
                    $bcontent =& $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid);
                    $xoopsTpl->clear_assign('block');
                } else {
                    $xoopsLogger->addBlock($block_arr[$i]->getVar('name'), true, $bcachetime);
                    $bcontent =& $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid);
                }
            }
            $title = $block_arr[$i]->getVar('title');
            switch ($block_arr[$i]->getVar('side')) {
                case XOOPS_CENTERBLOCK_CENTER:
                    if ($title != "") {
                        $cc_block .= '<tr valign="top"><td colspan="2"><strong>' . $title . '</strong><hr />' . $bcontent . '<br /><br /></td></tr>' . "\n";
                    } else {
                        $cc_block .= '<tr><td colspan="2">' . $bcontent . '<br /><br /></td></tr>' . "\n";
                    }
                    break;
                case XOOPS_CENTERBLOCK_LEFT:
                    if ($title != "") {
                        $cl_block .= '<p><strong>' . $title . '</strong><hr />' . $bcontent . '</p>' . "\n";
                    } else {
                        $cl_block .= '<p>' . $bcontent . '</p>' . "\n";
                    }
                    break;
                case XOOPS_CENTERBLOCK_RIGHT:
                    if ($title != "") {
                        $cr_block .= '<p><strong>' . $title . '</strong><hr />' . $bcontent . '</p>' . "\n";
                    } else {
                        $cr_block .= '<p>' . $bcontent . '</p>' . "\n";
                    }
                    break;
                default:
                    break;
            }
            unset($bcontent, $title);
        }
        echo '<table width="100%">' . $cc_block . '<tr valign="top"><td width="50%">' . $cl_block . '</td><td width="50%">' . $cr_block . '</td></tr></table>' . "\n";
    }
}
Exemplo n.º 7
0
 function _setupLogger()
 {
     require_once XOOPS_ROOT_PATH . '/class/logger.php';
     $this->mLogger =& XoopsLogger::instance();
     $this->mLogger->startTime();
     $GLOBALS['xoopsLogger'] =& $this->mLogger;
 }
Exemplo n.º 8
0
function smarty_function_block($params, &$smarty)
{
    if (!isset($params['id'])) {
        return;
    }
    $display_title = isset($params['display']) && $params['display'] == 'title' ? true : false;
    $display_none = isset($params['display']) && $params['display'] == 'none' ? true : false;
    $options = isset($params['options']) ? $params['options'] : false;
    $groups = isset($params['groups']) ? explode('|', $params['groups']) : false;
    $cache = isset($params['cache']) ? intval($params['cache']) : false;
    $block_id = intval($params['id']);
    static $block_objs;
    if (!isset($block_objs[$block_id])) {
        include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
        $blockObj = new XoopsBlock($block_id);
        if (!is_object($blockObj)) {
            return;
        }
        $block_objs[$block_id] = $blockObj;
    } else {
        $blockObj = $block_objs[$block_id];
    }
    $user_groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
    static $allowed_blocks;
    if (count($allowed_blocks) == 0) {
        $allowed_blocks = XoopsBlock::getAllBlocksByGroup($user_groups, false);
    }
    if ($groups) {
        if (!array_intersect($user_groups, $groups)) {
            return;
        }
    } else {
        if (!in_array($block_id, $allowed_blocks)) {
            return;
        }
    }
    if ($options) {
        $blockObj->setVar('options', $options);
    }
    if ($cache) {
        $blockObj->setVar('bcachetime', $cache);
    }
    if ($display_title) {
        return $blockObj->getVar('title');
    }
    $xoopsLogger =& XoopsLogger::instance();
    $template =& $GLOBALS['xoopsTpl'];
    $bcachetime = intval($blockObj->getVar('bcachetime'));
    if (empty($bcachetime)) {
        $template->caching = 0;
    } else {
        $template->caching = 2;
        $template->cache_lifetime = $bcachetime;
    }
    $template->setCompileId($blockObj->getVar('dirname', 'n'));
    $tplName = ($tplName = $blockObj->getVar('template')) ? "db:{$tplName}" : "db:system_block_dummy.html";
    $cacheid = 'blk_' . $block_id;
    if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
        $xoopsLogger->addBlock($blockObj->getVar('name'));
        if (!($bresult = $blockObj->buildBlock())) {
            return;
        }
        if (!$display_none) {
            $template->assign('block', $bresult);
            $template->display($tplName, $cacheid);
        }
    } else {
        $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime);
        if (!$display_none) {
            $template->display($tplName, $cacheid);
        }
    }
    $template->setCompileId($blockObj->getVar('dirname', 'n'));
}
Exemplo n.º 9
0
 function renderLog()
 {
     $xoopsLogger =& XoopsLogger::instance();
     return $xoopsLogger->dumpAll();
 }
Exemplo n.º 10
0
 define("XOOPS_MATCH_START", 0);
 define("XOOPS_MATCH_END", 1);
 define("XOOPS_MATCH_EQUAL", 2);
 define("XOOPS_MATCH_CONTAIN", 3);
 define("XOOPS_UPLOAD_PATH", XOOPS_ROOT_PATH . "/uploads");
 define("XOOPS_THEME_PATH", XOOPS_ROOT_PATH . "/themes");
 // ----- BEGIN: Already refactored stuff just kept for compat purposes -----
 //define( "SMARTY_DIR", XOOPS_PATH . "/Frameworks/XoopsCore/Pyro/Smarty.xoobj/smarty/" );
 define("XOOPS_CACHE_PATH", XOOPS_VAR_PATH . "/Caches");
 define("XOOPS_COMPILE_PATH", XOOPS_VAR_PATH . "/Application Support/xoops_template_Smarty");
 // ----- END: Already refactored stuff just kept for compat purposes -----
 define("XOOPS_THEME_URL", XOOPS_URL . "/themes");
 define("XOOPS_UPLOAD_URL", XOOPS_URL . "/uploads");
 set_magic_quotes_runtime(0);
 include_once XOOPS_ROOT_PATH . '/class/logger.php';
 $GLOBALS['xoopsLogger'] =& XoopsLogger::instance();
 if (!defined('XOOPS_XMLRPC')) {
     define('XOOPS_DB_CHKREF', 1);
 } else {
     define('XOOPS_DB_CHKREF', 0);
 }
 // ############## Include common functions file ##############
 include_once XOOPS_ROOT_PATH . '/include/functions.php';
 // #################### Connect to DB ##################
 require_once XOOPS_ROOT_PATH . '/class/database/database.php';
 $GLOBALS['xoopsDB'] = $xoops->loadService('legacydb');
 if (!$GLOBALS['xoopsDB']->allowWebChanges) {
     define('XOOPS_DB_PROXY', 1);
 }
 // ################# Include required files ##############
 require_once XOOPS_ROOT_PATH . '/kernel/object.php';
Exemplo n.º 11
0
 /**
  * Get content for this page block
  *
  * @param int $unique
  * @param bool $last
  * @return array
  */
 function render($template, $unique = 0)
 {
     $block = array('blockid' => $this->getVar('pageblockid'), 'module' => $this->block->getVar('dirname'), 'title' => $this->getVar('title'), 'weight' => $this->getVar('priority'));
     $xoopsLogger =& XoopsLogger::instance();
     $bcachetime = intval($this->getVar('pbcachetime'));
     if (empty($bcachetime)) {
         $template->caching = 0;
     } else {
         $template->caching = 2;
         $template->cache_lifetime = $bcachetime;
     }
     $tplName = ($tplName = $this->block->getVar('template')) ? "db:{$tplName}" : "db:system_block_dummy.html";
     $cacheid = 'blk_' . $this->getVar('pageblockid');
     if ($this->getVar('cachebyurl')) {
         $cacheid .= "_" . md5($_SERVER['REQUEST_URI']);
     }
     if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
         $xoopsLogger->addBlock($this->block->getVar('name'));
         if (!($bresult = $this->block->buildBlock())) {
             return false;
         }
         $template->assign('block', $bresult);
         $block['content'] = $template->fetch($tplName, $cacheid);
     } else {
         $xoopsLogger->addBlock($this->block->getVar('name'), true, $bcachetime);
         $block['content'] = $template->fetch($tplName, $cacheid);
     }
     return $block;
 }
Exemplo n.º 12
0
function XoopsErrorHandler_HandleError($errNo, $errStr, $errFile, $errLine, $errContext = null)
{
    $logger =& XoopsLogger::instance();
    $logger->handleError($errNo, $errStr, $errFile, $errLine, $errContext);
}
 function ListRecords($args)
 {
     global $xoopsDB;
     if (!isset($args['metadataPrefix'])) {
         $this->_lastError = "'metadataPrefix' is not specified.";
         return false;
     }
     $resumptionToken = null;
     do {
         $url = $this->_baseUrl . "?verb=ListRecords";
         if ($resumptionToken == null) {
             foreach (array('metadataPrefix', 'from', 'until', 'set') as $k) {
                 if (isset($args[$k])) {
                     $url .= "&" . urlencode($k) . "=" . urlencode($args[$k]);
                 }
             }
         } else {
             $url .= "&resumptionToken=" . htmlspecialchars($resumptionToken, ENT_QUOTES);
         }
         $snoopy =& xoonips_getutility('snoopy');
         if (!is_object($snoopy)) {
             $this->_lastError = "can't retrieve {$url}";
             $xoopsDB->setLogger(XoopsLogger::instance());
             return false;
         }
         if (!$snoopy->fetch($url)) {
             $this->_lastError = "can't retrieve {$url}";
             $xoopsDB->setLogger(XoopsLogger::instance());
             return false;
         }
         $this->_lastError = $this->_lastStatus = $snoopy->response_code;
         $this->parser = xml_parser_create('UTF-8');
         if (!$this->parser) {
             $this->_lastError = "can't create XML parser";
             $xoopsDB->setLogger(XoopsLogger::instance());
             return false;
         }
         $listRecordsHandler =& $this->createListRecordsHandler($this->parser, $this->_baseUrl, $args['metadataPrefix']);
         $result = $this->parse($snoopy->results);
         if (!$result) {
             //some erorr has occured
             if ($listRecordsHandler->getIdentifier() != null) {
                 $this->_lastError .= "[identifier]" . $listRecordsHandler->getIdentifier();
             }
             $xoopsDB->setLogger(XoopsLogger::instance());
             //some error has occured in parse( $snoopy->results );
             return false;
         }
         xml_parser_free($this->parser);
         $resumptionToken = $listRecordsHandler->getResumptionToken();
     } while ($resumptionToken != null);
     $xoopsDB->setLogger(XoopsLogger::instance());
     return true;
 }
Exemplo n.º 14
0
 function buildBlock($xobject, &$template)
 {
     // The lame type workaround will change
     // bid is added temporarily as workaround for specific block manipulation
     $block = array('id' => $xobject->getVar('bid'), 'module' => $xobject->getVar('dirname'), 'title' => $xobject->getVar('title'), 'weight' => $xobject->getVar('weight'), 'lastmod' => $xobject->getVar('last_modified'));
     $xoopsLogger =& XoopsLogger::instance();
     $bcachetime = intval($xobject->getVar('bcachetime'));
     if (empty($bcachetime)) {
         $template->caching = 0;
     } else {
         $template->caching = 2;
         $template->cache_lifetime = $bcachetime;
     }
     $template->setCompileId($xobject->getVar('dirname', 'n'));
     $tplName = ($tplName = $xobject->getVar('template')) ? "db:{$tplName}" : "db:system_block_dummy.html";
     $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid'));
     if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
         $xoopsLogger->addBlock($xobject->getVar('name'));
         if ($bresult = $xobject->buildBlock()) {
             $template->assign('block', $bresult);
             $block['content'] = $template->fetch($tplName, $cacheid);
         } else {
             $block = false;
         }
     } else {
         $xoopsLogger->addBlock($xobject->getVar('name'), true, $bcachetime);
         $block['content'] = $template->fetch($tplName, $cacheid);
     }
     $template->setCompileId();
     return $block;
 }