/**
  * Recache this block to the database based on content type and cache settings.
  *
  * @access	public
  * @param	array 				Block data
  * @param	bool				Return data instead of saving to database
  * @return	bool				Cache done successfully
  * @todo 	Finish this
  */
 public function recacheBlock($block, $return = false)
 {
     //-----------------------------------------
     // Load skin in case it's needed
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $pageBuilder = new pageBuilder($this->registry);
     $pageBuilder->loadSkinFile();
     $config = unserialize($block['block_config']);
     $content = '';
     require_once IPSLib::getAppDir('ccs') . '/sources/blocks/feed/data_sources/' . $config['feed'] . '.php';
     $_className = "feed_" . $config['feed'];
     $_class = new $_className($this->registry);
     $content = $_class->executeFeed($block);
     if (!$return) {
         $this->DB->update('ccs_blocks', array('block_cache_output' => $content, 'block_cache_last' => time()), 'block_id=' . intval($block['block_id']));
     }
     return $content;
 }
Example #2
0
/**
 * Template for the list of links (<div id="linklist">)
 * This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
 *
 * @param pageBuilder $PAGE    pageBuilder instance.
 * @param LinkDB      $LINKSDB LinkDB instance.
 */
function buildLinkList($PAGE, $LINKSDB)
{
    // Used in templates
    $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
    $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
    // Smallhash filter
    if (!empty($_SERVER['QUERY_STRING']) && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) {
        try {
            $linksToDisplay = $LINKSDB->filterHash($_SERVER['QUERY_STRING']);
        } catch (LinkNotFoundException $e) {
            $PAGE->render404($e->getMessage());
            exit;
        }
    } else {
        // Filter links according search parameters.
        $privateonly = !empty($_SESSION['privateonly']);
        $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly);
    }
    // ---- Handle paging.
    $keys = array();
    foreach ($linksToDisplay as $key => $value) {
        $keys[] = $key;
    }
    // If there is only a single link, we change on-the-fly the title of the page.
    if (count($linksToDisplay) == 1) {
        $GLOBALS['pagetitle'] = $linksToDisplay[$keys[0]]['title'] . ' - ' . $GLOBALS['title'];
    }
    // Select articles according to paging.
    $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']);
    $pagecount = $pagecount == 0 ? 1 : $pagecount;
    $page = empty($_GET['page']) ? 1 : intval($_GET['page']);
    $page = $page < 1 ? 1 : $page;
    $page = $page > $pagecount ? $pagecount : $page;
    // Start index.
    $i = ($page - 1) * $_SESSION['LINKS_PER_PAGE'];
    $end = $i + $_SESSION['LINKS_PER_PAGE'];
    $linkDisp = array();
    while ($i < $end && $i < count($keys)) {
        $link = $linksToDisplay[$keys[$i]];
        $link['description'] = format_description($link['description'], $GLOBALS['redirector']);
        $classLi = $i % 2 != 0 ? '' : 'publicLinkHightLight';
        $link['class'] = $link['private'] == 0 ? $classLi : 'private';
        $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
        $link['timestamp'] = $date->getTimestamp();
        $taglist = explode(' ', $link['tags']);
        uasort($taglist, 'strcasecmp');
        $link['taglist'] = $taglist;
        $link['shorturl'] = smallHash($link['linkdate']);
        // Check for both signs of a note: starting with ? and 7 chars long.
        if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
            $link['url'] = index_url($_SERVER) . $link['url'];
        }
        $linkDisp[$keys[$i]] = $link;
        $i++;
    }
    // Compute paging navigation
    $searchtagsUrl = empty($searchtags) ? '' : '&searchtags=' . urlencode($searchtags);
    $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm);
    $previous_page_url = '';
    if ($i != count($keys)) {
        $previous_page_url = '?page=' . ($page + 1) . $searchtermUrl . $searchtagsUrl;
    }
    $next_page_url = '';
    if ($page > 1) {
        $next_page_url = '?page=' . ($page - 1) . $searchtermUrl . $searchtagsUrl;
    }
    $token = isLoggedIn() ? getToken() : '';
    // Fill all template fields.
    $data = array('previous_page_url' => $previous_page_url, 'next_page_url' => $next_page_url, 'page_current' => $page, 'page_max' => $pagecount, 'result_count' => count($linksToDisplay), 'search_term' => $searchterm, 'search_tags' => $searchtags, 'redirector' => empty($GLOBALS['redirector']) ? '' : $GLOBALS['redirector'], 'token' => $token, 'links' => $linkDisp, 'tags' => $LINKSDB->allTags());
    // FIXME! temporary fix - see #399.
    if (!empty($GLOBALS['pagetitle']) && count($linkDisp) == 1) {
        $data['pagetitle'] = $GLOBALS['pagetitle'];
    }
    $pluginManager = PluginManager::getInstance();
    $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => isLoggedIn()));
    foreach ($data as $key => $value) {
        $PAGE->assign($key, $value);
    }
    return;
}
Example #3
0
function install()
{
    // On free.fr host, make sure the /sessions directory exists, otherwise login will not work.
    if (endsWith($_SERVER['HTTP_HOST'], '.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'] . '/sessions')) {
        mkdir($_SERVER['DOCUMENT_ROOT'] . '/sessions', 0705);
    }
    // This part makes sure sessions works correctly.
    // (Because on some hosts, session.save_path may not be set correctly,
    // or we may not have write access to it.)
    if (isset($_GET['test_session']) && (!isset($_SESSION) || !isset($_SESSION['session_tested']) || $_SESSION['session_tested'] != 'Working')) {
        // Step 2: Check if data in session is correct.
        echo '<pre>Sessions do not seem to work correctly on your server.<br>';
        echo 'Make sure the variable session.save_path is set correctly in your php config, and that you have write access to it.<br>';
        echo 'It currently points to ' . session_save_path() . '<br>';
        echo 'Check that the hostname used to access Shaarli contains a dot. On some browsers, accessing your server via a hostname like \'localhost\' or any custom hostname without a dot causes cookie storage to fail. We recommend accessing your server via it\'s IP address or Fully Qualified Domain Name.<br>';
        echo '<br><a href="?">Click to try again.</a></pre>';
        die;
    }
    if (!isset($_SESSION['session_tested'])) {
        // Step 1 : Try to store data in session and reload page.
        $_SESSION['session_tested'] = 'Working';
        // Try to set a variable in session.
        header('Location: ' . index_url($_SERVER) . '?test_session');
        // Redirect to check stored data.
    }
    if (isset($_GET['test_session'])) {
        // Step 3: Sessions are OK. Remove test parameter from URL.
        header('Location: ' . index_url($_SERVER));
    }
    if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) {
        $tz = 'UTC';
        if (!empty($_POST['continent']) && !empty($_POST['city'])) {
            if (isTimeZoneValid($_POST['continent'], $_POST['city'])) {
                $tz = $_POST['continent'] . '/' . $_POST['city'];
            }
        }
        $GLOBALS['timezone'] = $tz;
        // Everything is ok, let's create config file.
        $GLOBALS['login'] = $_POST['setlogin'];
        $GLOBALS['salt'] = sha1(uniqid('', true) . '_' . mt_rand());
        // Salt renders rainbow-tables attacks useless.
        $GLOBALS['hash'] = sha1($_POST['setpassword'] . $GLOBALS['login'] . $GLOBALS['salt']);
        $GLOBALS['title'] = empty($_POST['title']) ? 'Shared links on ' . escape(index_url($_SERVER)) : $_POST['title'];
        $GLOBALS['config']['ENABLE_UPDATECHECK'] = !empty($_POST['updateCheck']);
        try {
            writeConfig($GLOBALS, isLoggedIn());
        } catch (Exception $e) {
            error_log('ERROR while writing config file after installation.' . PHP_EOL . $e->getMessage());
            // TODO: do not handle exceptions/errors in JS.
            echo '<script>alert("' . $e->getMessage() . '");document.location=\'?\';</script>';
            exit;
        }
        echo '<script>alert("Shaarli is now configured. Please enter your login/password and start shaaring your links!");document.location=\'?do=login\';</script>';
        exit;
    }
    // Display config form:
    list($timezone_form, $timezone_js) = generateTimeZoneForm();
    $timezone_html = '';
    if ($timezone_form != '') {
        $timezone_html = '<tr><td><b>Timezone:</b></td><td>' . $timezone_form . '</td></tr>';
    }
    $PAGE = new pageBuilder();
    $PAGE->assign('timezone_html', $timezone_html);
    $PAGE->assign('timezone_js', $timezone_js);
    $PAGE->renderPage('install');
    exit;
}
 /**
  * Recache this block to the database based on content type and cache settings.
  *
  * @access	public
  * @param	array 				Block data
  * @param	bool				Return data instead of saving to database
  * @return	string				New cached content
  */
 public function recacheBlock($block, $return = false)
 {
     //-----------------------------------------
     // Save the template
     //-----------------------------------------
     $templateHTML = $this->_parseBlock($block);
     $template = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_template_blocks', 'where' => "tpb_name='block__custom_{$block['block_id']}'"));
     if ($template['tpb_id']) {
         $this->DB->update('ccs_template_blocks', array('tpb_content' => $templateHTML), 'tpb_id=' . $template['tpb_id']);
     } else {
         $template = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_template_blocks', 'where' => "tpb_name='block__custom'"));
         $this->DB->insert('ccs_template_blocks', array('tpb_name' => 'block__custom_' . $block['block_id'], 'tpb_content' => $templateHTML, 'tpb_params' => $template['tpb_params']));
         $template['tpb_id'] = $this->DB->getInsertId();
     }
     $cache = array('cache_type' => 'block', 'cache_type_id' => $template['tpb_id']);
     require_once IPS_KERNEL_PATH . 'classTemplateEngine.php';
     $engine = new classTemplate(IPS_ROOT_PATH . 'sources/template_plugins');
     $cache['cache_content'] = $engine->convertHtmlToPhp('block__custom_' . $block['block_id'], $template['tpb_params'], $templateHTML, '', false, true);
     $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='block' AND cache_type_id={$template['tpb_id']}"));
     //print_r($cache);exit;
     if ($hasIt['cache_id']) {
         $this->DB->update('ccs_template_cache', $cache, "cache_type='block' AND cache_type_id={$template['tpb_id']}");
     } else {
         $this->DB->insert('ccs_template_cache', $cache);
     }
     //-----------------------------------------
     // Recache the "skin" file
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $_pagesClass = new pageBuilder($this->registry);
     $_pagesClass->recacheTemplateCache($engine);
     $_pagesClass->loadSkinFile();
     $func = 'block__custom_' . $block['block_id'];
     $content = $this->registry->output->getTemplate('ccs')->{$func}($block['block_name'], $templateHTML);
     if (!$return and $block['block_cache_ttl']) {
         $this->DB->update('ccs_blocks', array('block_cache_output' => $content, 'block_cache_last' => time()), 'block_id=' . intval($block['block_id']));
     }
     return $content;
 }
 /**
  * This is a proxy function.  It determines what step of the wizard we are on and acts appropriately
  *
  * @access	protected
  * @return	void
  */
 protected function _wizardProxy()
 {
     //-----------------------------------------
     // If it's a different type - proxy there
     //-----------------------------------------
     if ($this->request['fileType'] == 'css' or $this->request['fileType'] == 'js') {
         return $this->easyForm('add', $this->request['fileType']);
     }
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $sessionId = $this->request['wizard_session'] ? IPSText::md5Clean($this->request['wizard_session']) : md5(uniqid(microtime(), true));
     $session = array('wizard_step' => 0, 'wizard_id' => $sessionId, 'wizard_started' => time(), 'wizard_ipb_wrapper' => $this->settings['ccs_use_ipb_wrapper']);
     if ($this->request['wizard_session']) {
         $session = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_page_wizard', 'where' => "wizard_id='{$sessionId}'"));
     } else {
         $this->DB->insert('ccs_page_wizard', $session);
     }
     $session['wizard_step'] = $this->request['step'] ? $this->request['step'] : 0;
     //-----------------------------------------
     // Got stuff to save?
     //-----------------------------------------
     if ($session['wizard_step'] > 0 and !$this->request['continuing']) {
         $session = $this->_storeSubmittedData($session);
     }
     //-----------------------------------------
     // Proxy off to appropriate function
     //-----------------------------------------
     $step = $session['wizard_step'] + 1;
     $step = $step > 0 ? $step : 1;
     $_func = "wizard_step_" . $step;
     $additional = array();
     switch ($step) {
         //-----------------------------------------
         // Step 1: Grab folders and templates for form
         //-----------------------------------------
         case 1:
             $additional['folders'] = array();
             $additional['templates'] = array();
             //-----------------------------------------
             // Get templates
             //-----------------------------------------
             $this->DB->build(array('select' => '*', 'from' => 'ccs_page_templates', 'order' => 'template_name ASC'));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 $additional['templates'][] = array($r['template_id'], $r['template_name']);
             }
             //-----------------------------------------
             // Get folders
             //-----------------------------------------
             $folders = array();
             $this->DB->build(array('select' => '*', 'from' => 'ccs_folders'));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 $additional['folders'][] = array($r['folder_path'], $r['folder_path']);
             }
             //-----------------------------------------
             // Edit content only by default
             //-----------------------------------------
             if (!$session['wizard_edit_id']) {
                 $session['wizard_content_only'] = 1;
             }
             break;
             //-----------------------------------------
             // Step 2: Show the appropriate editor
             //-----------------------------------------
         //-----------------------------------------
         // Step 2: Show the appropriate editor
         //-----------------------------------------
         case 2:
             //-----------------------------------------
             // If we are not editing content only, not
             //	editing an existing page, and have a
             //	template id, get it as default content
             //-----------------------------------------
             if (!$session['wizard_content_only'] and !$session['wizard_edit_id'] and $session['wizard_template']) {
                 $template = $this->DB->buildAndFetch(array('select' => 'template_content', 'from' => 'ccs_page_templates', 'where' => 'template_id=' . intval($session['wizard_template'])));
                 $session['wizard_content'] = $template['template_content'];
             }
             //-----------------------------------------
             // Sort parse for editor
             //-----------------------------------------
             if ($session['wizard_type'] == 'bbcode') {
                 IPSText::getTextClass('bbcode')->bypass_badwords = 1;
                 IPSText::getTextClass('bbcode')->parse_smilies = 1;
                 IPSText::getTextClass('bbcode')->parse_html = 1;
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'global';
                 if ($session['wizard_previous_type'] != 'bbcode') {
                     $session['wizard_content'] = IPSText::getTextClass('bbcode')->preDbParse($session['wizard_content']);
                 }
                 if (IPSText::getTextClass('editor')->method == 'rte') {
                     $content = IPSText::getTextClass('bbcode')->convertForRTE($session['wizard_content']);
                 } else {
                     $content = IPSText::getTextClass('bbcode')->preEditParse($session['wizard_content']);
                 }
                 $editor_area = IPSText::getTextClass('editor')->showEditor($content, 'content');
             } else {
                 if ($session['wizard_previous_type'] == 'bbcode') {
                     $session['wizard_content'] = html_entity_decode($session['wizard_content'], ENT_QUOTES);
                 }
                 $editor_area = $this->registry->output->formTextarea("content", htmlspecialchars($session['wizard_content']), 100, 30, "content", "style='width:100%;'");
             }
             $additional['editor'] = $editor_area;
             break;
             //-----------------------------------------
             // Step 4: Permissions
             //-----------------------------------------
         //-----------------------------------------
         // Step 4: Permissions
         //-----------------------------------------
         case 4:
             if ($session['wizard_perms'] == '*' or !$session['wizard_edit_id']) {
                 $additional['all_masks'] = 1;
             } else {
                 $additional['masks'] = explode(',', $session['wizard_perms']);
             }
             $additional['avail_masks'] = array();
             $this->DB->build(array('select' => '*', 'from' => 'forum_perms', 'order' => 'perm_name ASC'));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 $additional['avail_masks'][] = array($r['perm_id'], $r['perm_name']);
             }
             break;
             //-----------------------------------------
             // Step 5: Save to DB, destroy wizard session,
             //	show complete page
             //-----------------------------------------
         //-----------------------------------------
         // Step 5: Save to DB, destroy wizard session,
         //	show complete page
         //-----------------------------------------
         case 5:
             $page = array('page_name' => $session['wizard_name'], 'page_seo_name' => $session['wizard_seo_name'], 'page_description' => $session['wizard_description'], 'page_folder' => $session['wizard_folder'], 'page_type' => $session['wizard_type'], 'page_last_edited' => time(), 'page_template_used' => $session['wizard_template'], 'page_content' => $session['wizard_content'], 'page_view_perms' => $session['wizard_perms'], 'page_cache_ttl' => $session['wizard_cache_ttl'], 'page_content_only' => $session['wizard_content_only'], 'page_meta_keywords' => $session['wizard_meta_keywords'], 'page_meta_description' => $session['wizard_meta_description'], 'page_content_type' => 'page', 'page_ipb_wrapper' => $session['wizard_ipb_wrapper']);
             if ($page['page_cache_ttl']) {
                 require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                 $pageBuilder = new pageBuilder($this->registry);
                 $page['page_cache'] = $pageBuilder->recachePage($page);
                 $page['page_cache_last'] = time();
             }
             if ($session['wizard_edit_id']) {
                 $this->DB->update('ccs_pages', $page, 'page_id=' . $session['wizard_edit_id']);
                 $page['page_id'] = $session['wizard_edit_id'];
             } else {
                 $this->DB->insert('ccs_pages', $page);
                 $page['page_id'] = $this->DB->getInsertId();
             }
             $this->DB->delete('ccs_page_wizard', "wizard_id='{$session['wizard_id']}'");
             $session = array_merge($session, $page);
             break;
     }
     $this->registry->output->html .= $this->html->{$_func}($session, $additional);
 }
Example #6
0
function install()
{
    global $core;
    // On free.fr host, make sure the /sessions directory exists, otherwise login will not work.
    if (endsWith($_SERVER['SERVER_NAME'], '.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'] . '/sessions')) {
        mkdir($_SERVER['DOCUMENT_ROOT'] . '/sessions', 0705);
    }
    if ($core->auth->sessionExists() && !empty($_POST['setlogin'])) {
        $tz = 'UTC';
        if (!empty($_POST['continent']) && !empty($_POST['city'])) {
            if (isTZvalid($_POST['continent'], $_POST['city'])) {
                $tz = $_POST['continent'] . '/' . $_POST['city'];
            }
        }
        $GLOBALS['timezone'] = $tz;
        // Everything is ok, let's create config file.
        $GLOBALS['login'] = $core->auth->userID();
        $GLOBALS['salt'] = sha1(uniqid('', true) . '_' . mt_rand());
        // Salt renders rainbow-tables attacks useless.
        $GLOBALS['hash'] = sha1($core->auth->userToken() . $GLOBALS['login'] . $GLOBALS['salt']);
        $GLOBALS['title'] = empty($_POST['title']) ? 'Shared links on ' . htmlspecialchars(indexUrl()) : $_POST['title'];
        writeConfig();
        echo '<script language="JavaScript">alert("Shaarli is now configured !");document.location=\'\';</script>';
        exit;
    }
    // Display config form:
    list($timezone_form, $timezone_js) = templateTZform();
    $timezone_html = '';
    if ($timezone_form != '') {
        $timezone_html = '<tr><td valign="top"><b>Timezone:</b></td><td>' . $timezone_form . '</td></tr>';
    }
    $PAGE = new pageBuilder();
    $PAGE->assign('login_html', $core->auth->userID());
    $PAGE->assign('timezone_html', $timezone_html);
    $PAGE->assign('timezone_js', $timezone_js);
    $PAGE->renderPage('install');
    exit;
}
 /**
  * Execute the feed and return the HTML to show on the page.  
  * Can be called from ACP or front end, so the plugin needs to setup any appropriate lang files, skin files, etc.
  *
  * @access	public
  * @param	array 				Block data
  * @return	string				Block HTML to display or cache
  */
 public function executeFeed($block)
 {
     $this->lang->loadLanguageFile(array('public_ccs'), 'ccs');
     $config = unserialize($block['block_config']);
     $where = array();
     //-----------------------------------------
     // Set up filtering clauses
     //-----------------------------------------
     switch ($config['content']) {
         case 'entries':
             if ($config['filters']['filter_blogid']) {
                 $where[] = "e.blog_id=" . $config['filters']['filter_blogid'];
             }
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "e.entry_status='" . ($config['filters']['filter_visibility'] == 'open' ? 'published' : 'draft') . "'";
             }
             if ($config['filters']['filter_featured']) {
                 $where[] = "e.entry_featured=1";
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "e.entry_date > " . $timestamp;
                 }
             }
             if ($config['filters']['filter_submitter'] == 'myself') {
                 $where[] = "e.entry_author_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_submitter'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "e.entry_author_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_submitter'] != '') {
                         $member = IPSMember::load($config['filters']['filter_submitter'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "e.entry_author_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
         case 'comments':
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "c.comment_queued=" . ($config['filters']['filter_visibility'] == 'open' ? 0 : 1);
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "c.comment_date > " . $timestamp;
                 }
             }
             if ($config['filters']['filter_submitter'] == 'myself') {
                 $where[] = "c.member_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_submitter'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "c.member_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_submitter'] != '') {
                         $member = IPSMember::load($config['filters']['filter_submitter'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "c.member_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
         case 'blogs':
             if ($config['filters']['filter_owner'] == 'myself') {
                 $where[] = "b.member_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_owner'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "b.member_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_owner'] != '') {
                         $member = IPSMember::load($config['filters']['filter_owner'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "b.member_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             if ($config['filters']['filter_type'] != 'either') {
                 $where[] = "b.blog_type='" . $config['filters']['filter_type'] . "'";
             }
             if (!$config['filters']['filter_private']) {
                 $where[] = "b.blog_private=0";
             }
             if ($config['filters']['filter_guests']) {
                 $where[] = "b.blog_allowguests=1";
             }
             break;
     }
     $order = '';
     switch ($config['content']) {
         case 'entries':
             switch ($config['sortby']) {
                 case 'name':
                     $order .= "e.entry_name ";
                     break;
                 case 'trackbacks':
                     $order .= "e.entry_trackbacks ";
                     break;
                 default:
                 case 'submitted':
                     $order .= "e.entry_date ";
                     break;
                 case 'comments':
                     $order .= "e.entry_num_comments ";
                     break;
                 case 'lastcomment':
                     $order .= "e.entry_last_comment_date ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
         case 'comments':
             switch ($config['sortby']) {
                 default:
                 case 'post_date':
                     $order .= "c.comment_date ";
                     break;
             }
             break;
         case 'blogs':
             switch ($config['sortby']) {
                 case 'name':
                     $order .= "b.blog_name ";
                     break;
                 case 'entries':
                     $order .= "entry_count ";
                     break;
                 default:
                 case 'last_entry':
                     $order .= "e.entry_date ";
                     break;
                 case 'views':
                     $order .= "b.blog_num_views ";
                     break;
                 case 'pinned':
                     $order .= "b.blog_pinned ";
                     break;
                 case 'rate':
                     $order .= "(b.blog_rating_total/b.blog_rating_count) ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
     }
     $order .= $config['sortorder'];
     //-----------------------------------------
     // Run the query and get the results
     //-----------------------------------------
     $content = array();
     switch ($config['content']) {
         case 'entries':
             $this->DB->build(array('select' => 'e.*', 'from' => array('blog_entries' => 'e'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'b.*', 'from' => array('blog_blogs' => 'b'), 'where' => 'e.blog_id=b.blog_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=e.entry_author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=blog&amp;module=display&amp;section=blog&amp;blogid=' . $r['blog_id'] . '&amp;showentry=' . $r['entry_id'], 'none');
                 $r['date'] = $r['entry_date'];
                 $r['content'] = $r['entry'];
                 $r['title'] = $r['entry_name'];
                 IPSText::getTextClass('bbcode')->parse_html = $r['entry_html_state'] ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = $r['entry_html_state'] == 2 ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_smilies = $r['entry_use_emo'] ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parsing_section = 'blog_entry';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
         case 'comments':
             $this->DB->build(array('select' => 'c.*', 'from' => array('blog_comments' => 'c'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'e.*', 'from' => array('blog_entries' => 'e'), 'where' => 'c.entry_id=e.entry_id', 'type' => 'left'), array('select' => 'b.*', 'from' => array('blog_blogs' => 'b'), 'where' => 'b.blog_id=e.blog_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=c.member_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=blog&amp;module=display&amp;section=blog&amp;blogid=' . $r['blog_id'] . '&amp;showentry=' . $r['entry_id'], 'none');
                 $r['date'] = $r['comment_date'];
                 $r['content'] = $r['comment_text'];
                 $r['title'] = $r['entry_name'];
                 IPSText::getTextClass('bbcode')->parse_html = $r['comment_html_state'] ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parse_nl2br = $r['comment_html_state'] == 2 ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_smilies = $r['comment_use_emo'] ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parsing_section = 'blog_comment';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
         case 'blogs':
             $this->DB->build(array('select' => 'b.*', 'from' => array('blog_blogs' => 'b'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'group' => 'b.blog_id', 'add_join' => array(array('select' => 'COUNT(e.entry_id) as entry_count, MAX(e.entry_id) as max_entry_id', 'from' => array('blog_entries' => 'e'), 'where' => 'e.blog_id=b.blog_id', 'type' => 'left'), array('select' => 'et.*', 'from' => array('blog_entries' => 'et'), 'where' => 'et.entry_id=max_entry_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=e.member_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=blog&amp;module=display&amp;section=blog&amp;blogid=' . $r['blog_id'], 'none');
                 $r['title'] = $r['blog_name'];
                 $r['date'] = $r['entry_date'];
                 $r['content'] = $r['blog_desc'];
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
     }
     //-----------------------------------------
     // Return formatted content
     //-----------------------------------------
     $feedConfig = $this->returnFeedInfo();
     $templateBit = $feedConfig['templateBit'] . '_' . $block['block_id'];
     if ($config['hide_empty'] and !count($content)) {
         return '';
     }
     return $this->registry->output->getTemplate('ccs')->{$templateBit}($block['block_name'], $content);
 }
 /**
  * Execute the feed and return the HTML to show on the page.  
  * Can be called from ACP or front end, so the plugin needs to setup any appropriate lang files, skin files, etc.
  *
  * @access	public
  * @param	array 				Block data
  * @return	string				Block HTML to display or cache
  */
 public function executeFeed($block)
 {
     $this->lang->loadLanguageFile(array('public_ccs'), 'ccs');
     $config = unserialize($block['block_config']);
     $where = array();
     //-----------------------------------------
     // Set up filtering clauses
     //-----------------------------------------
     if ($config['filters']['filter_cats']) {
         if ($config['content'] != 'cats') {
             $where[] = "f.file_cat IN(" . $config['filters']['filter_cats'] . ")";
         }
     }
     switch ($config['content']) {
         case 'files':
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "f.file_open=" . ($config['filters']['filter_visibility'] == 'open' ? 1 : 0);
             }
             if ($config['filters']['filter_broken'] != 'either') {
                 $where[] = "f.file_broken=" . ($config['filters']['filter_broken'] == 'broken' ? 1 : 0);
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "f.file_submitted > " . $timestamp;
                 }
             }
             if ($config['filters']['filter_submitter'] == 'myself') {
                 $where[] = "f.file_submitter = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_submitter'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "f.file_submitter IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_submitter'] != '') {
                         $member = IPSMember::load($config['filters']['filter_submitter'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "f.file_submitter = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
         case 'comments':
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "c.comment_open=" . ($config['filters']['filter_visibility'] == 'open' ? 1 : 0);
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "c.comment_date > " . $timestamp;
                 }
             }
             break;
     }
     $order = '';
     switch ($config['content']) {
         case 'files':
             switch ($config['sortby']) {
                 case 'title':
                     $order .= "f.file_name ";
                     break;
                 case 'views':
                     $order .= "f.file_views ";
                     break;
                 default:
                 case 'submitted':
                     $order .= "f.file_submitted ";
                     break;
                 case 'updated':
                     $where[] = "f.file_updated > 0 ";
                     $order .= "f.file_updated ";
                     break;
                 case 'downloads':
                     $order .= "f.file_downloads ";
                     break;
                 case 'size':
                     $order .= "f.file_size ";
                     break;
                 case 'rate':
                     $order .= "f.file_rating ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
         case 'comments':
             switch ($config['sortby']) {
                 default:
                 case 'post_date':
                     $order .= "c.comment_date ";
                     break;
             }
             break;
     }
     $order .= $config['sortorder'];
     //-----------------------------------------
     // Run the query and get the results
     //-----------------------------------------
     $content = array();
     switch ($config['content']) {
         case 'files':
             $this->DB->build(array('select' => 'f.*', 'from' => array('downloads_files' => 'f'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'c.*', 'from' => array('downloads_categories' => 'c'), 'where' => 'c.cid=f.file_cat', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=f.file_submitter', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=downloads&amp;showfile=' . $r['file_id'], 'none');
                 $r['date'] = $r['file_submitted'];
                 $r['content'] = $r['file_desc'];
                 $r['title'] = $r['file_name'];
                 $coptions = unserialize($r['coptions']);
                 IPSText::getTextClass('bbcode')->parse_html = $coptions['opt_html'];
                 IPSText::getTextClass('bbcode')->parse_bbcode = $coptions['opt_bbcode'];
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'idm_submit';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
         case 'comments':
             $this->DB->build(array('select' => 'c.*', 'from' => array('downloads_comments' => 'c'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'f.*', 'from' => array('downloads_files' => 'f'), 'where' => 'f.file_id=c.comment_fid', 'type' => 'left'), array('select' => 'cc.*', 'from' => array('downloads_cats' => 'cc'), 'where' => 'cc.cid=f.file_cat', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=c.comment_mid', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=downloads&amp;module=display&amp;section=findpost&amp;id=' . $r['comment_id'], 'none');
                 $r['date'] = $r['comment_date'];
                 $r['content'] = $r['comment_text'];
                 $r['title'] = $r['file_name'];
                 $r = IPSMember::buildDisplayData($r);
                 IPSText::getTextClass('bbcode')->parse_html = 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parse_smilies = $r['use_emo'];
                 IPSText::getTextClass('bbcode')->parsing_section = 'idm_comment';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $content[] = $r;
             }
             break;
         case 'cats':
             require_once IPSLib::getAppDir('downloads') . '/app_class_downloads.php';
             $app = new app_class_downloads($this->registry);
             $cats = array();
             $filter = array();
             if ($config['filter_cats']) {
                 $filter = explode(',', $config['filter_cats']);
             }
             foreach ($this->registry->categories->cat_lookup as $cid => $category) {
                 if (count($filter) and !in_array($cid, $filter)) {
                     continue;
                 }
                 if ($config['filter_root'] and $category['cparent'] > 0) {
                     continue;
                 }
                 switch ($config['sortby']) {
                     case 'name':
                         $cats[$category['cname'] . '_' . rand(100, 999)] = $category;
                         break;
                     case 'last_file':
                         $cats[$category['cfileinfo']['date'] . '_' . rand(100, 999)] = $category;
                         break;
                     case 'files':
                         $cats[$category['cfileinfo']['total_files'] . '_' . rand(100, 999)] = $category;
                         break;
                     case 'position':
                         $cats[$category['cposition'] . '_' . rand(100, 999)] = $category;
                         break;
                     case 'rand':
                         $cats[rand(10000, 99999)] = $category;
                         break;
                 }
             }
             if ($config['sortorder'] == 'desc') {
                 krsort($cats);
             } else {
                 ksort($cats);
             }
             $cats = array_slice($cats, $config['offset_a'], $config['offset_b']);
             $finalCats = array();
             foreach ($cats as $r) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=downloads&amp;showcat=' . $r['cid'], 'none');
                 $r['title'] = $r['cname'];
                 $r['date'] = $r['cfileinfo']['date'];
                 $r['content'] = $r['cdesc'];
                 $content[] = $r;
             }
             break;
     }
     //-----------------------------------------
     // Return formatted content
     //-----------------------------------------
     $feedConfig = $this->returnFeedInfo();
     $templateBit = $feedConfig['templateBit'] . '_' . $block['block_id'];
     if ($config['hide_empty'] and !count($content)) {
         return '';
     }
     return $this->registry->output->getTemplate('ccs')->{$templateBit}($block['block_name'], $content);
 }
 /**
  * Execute the feed and return the HTML to show on the page.  
  * Can be called from ACP or front end, so the plugin needs to setup any appropriate lang files, skin files, etc.
  *
  * @access	public
  * @param	array 				Block data
  * @return	string				Block HTML to display or cache
  */
 public function executeFeed($block)
 {
     $this->lang->loadLanguageFile(array('public_ccs'), 'ccs');
     $config = unserialize($block['block_config']);
     $where = array();
     //-----------------------------------------
     // Set up filtering clauses
     //-----------------------------------------
     switch ($config['content']) {
         case 'images':
             if ($config['filters']['filter_cats']) {
                 $where[] = "i.category_id IN(" . $config['filters']['filter_cats'] . ")";
             }
             if ($config['filters']['filter_albums']) {
                 $where[] = "i.album_id IN(" . $config['filters']['filter_albums'] . ")";
             }
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "i.approved=" . ($config['filters']['filter_visibility'] == 'open' ? 1 : 0);
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "i.idate > " . $timestamp;
                 }
             }
             if ($config['filters']['filter_submitter'] == 'myself') {
                 $where[] = "i.member_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_submitter'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "i.member_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_submitter'] != '') {
                         $member = IPSMember::load($config['filters']['filter_submitter'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "i.member_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
         case 'comments':
             if ($config['filters']['filter_cats']) {
                 $where[] = "i.category_id IN(" . $config['filters']['filter_cats'] . ")";
             }
             if ($config['filters']['filter_albums']) {
                 $where[] = "i.album_id IN(" . $config['filters']['filter_albums'] . ")";
             }
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "c.approved=" . ($config['filters']['filter_visibility'] == 'open' ? 1 : 0);
             }
             if ($config['filters']['filter_submitted']) {
                 $timestamp = @strtotime($config['filters']['filter_submitted']);
                 if ($timestamp) {
                     $where[] = "c.post_date > " . $timestamp;
                 }
             }
             break;
         case 'cats':
             if ($config['filters']['filter_cats']) {
                 $where[] = "c.id IN(" . $config['filters']['filter_cats'] . ")";
             }
             if ($config['filters']['filter_root']) {
                 $where[] = "c.parent < 1";
             }
             break;
         case 'albums':
             if ($config['filters']['filter_albums']) {
                 $where[] = "a.id IN(" . $config['filters']['filter_albums'] . ")";
             }
             if ($config['filters']['filter_public']) {
                 $where[] = "a.public_album=1";
             }
             if ($config['filters']['filter_owner'] == 'myself') {
                 $where[] = "a.member_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_owner'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "a.member_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_owner'] != '') {
                         $member = IPSMember::load($config['filters']['filter_owner'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "a.member_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
     }
     $order = '';
     switch ($config['content']) {
         case 'images':
             switch ($config['sortby']) {
                 case 'title':
                     $order .= "i.caption ";
                     break;
                 case 'filename':
                     $order .= "i.file_name ";
                     break;
                 case 'views':
                     $order .= "i.views ";
                     break;
                 case 'comments':
                     $order .= "i.comments ";
                     break;
                 default:
                 case 'submitted':
                     $order .= "i.idate ";
                     break;
                 case 'lastcomment':
                     $order .= "i.lastcomment ";
                     break;
                 case 'size':
                     $order .= "i.file_size ";
                     break;
                 case 'rate':
                     $order .= "i.rating ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
         case 'comments':
             switch ($config['sortby']) {
                 default:
                 case 'post_date':
                     $order .= "p.post_date ";
                     break;
             }
             break;
         case 'cats':
             switch ($config['sortby']) {
                 case 'name':
                     $order .= "c.name ";
                     break;
                 default:
                 case 'last_file':
                     $order .= "c.last_pic_date ";
                     break;
                 case 'files':
                     $order .= "c.images ";
                     break;
                 case 'position':
                     $order .= "c.c_order ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
         case 'albums':
             switch ($config['sortby']) {
                 case 'name':
                     $order .= "a.name ";
                     break;
                 default:
                 case 'last_file':
                     $order .= "a.last_pic_date ";
                     break;
                 case 'files':
                     $order .= "a.images ";
                     break;
                 case 'comments':
                     $order .= "a.comments ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
     }
     $order .= $config['sortorder'];
     //-----------------------------------------
     // Run the query and get the results
     //-----------------------------------------
     $content = array();
     switch ($config['content']) {
         case 'images':
             $this->DB->build(array('select' => 'i.id as imgid, i.*', 'from' => array('gallery_images' => 'i'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'c.id as cid, c.*', 'from' => array('gallery_categories' => 'c'), 'where' => 'c.id=i.category_id', 'type' => 'left'), array('select' => 'a.id as aid, a.*', 'from' => array('gallery_albums' => 'a'), 'where' => 'a.id=i.album_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=i.member_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['album_id'] = $r['aid'];
                 $r['cat_id'] = $r['cid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=gallery&amp;module=images&amp;section=viewimage&amp;img=' . $r['imgid'], 'none');
                 $r['date'] = $r['idate'];
                 $r['content'] = $r['description'];
                 $r['title'] = $r['caption'];
                 IPSText::getTextClass('bbcode')->parse_smilies = 1;
                 IPSText::getTextClass('bbcode')->parse_html = 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'gallery_image';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $r['id'] = $r['imgid'];
                 $content[] = $r;
             }
             break;
         case 'comments':
             $this->DB->build(array('select' => 'c.*', 'from' => array('gallery_comments' => 'c'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'i.id as imgid, i.*', 'from' => array('gallery_images' => 'i'), 'where' => 'i.id=c.img_id', 'type' => 'left'), array('select' => 'c.id as cid, c.*', 'from' => array('gallery_categories' => 'c'), 'where' => 'c.id=i.category_id', 'type' => 'left'), array('select' => 'a.id as aid, a.*', 'from' => array('gallery_albums' => 'a'), 'where' => 'a.id=i.album_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=c.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['album_id'] = $r['aid'];
                 $r['cat_id'] = $r['cid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=gallery&amp;module=images&amp;section=viewimage&amp;img=' . $r['imgid'], 'none');
                 $r['date'] = $r['post_date'];
                 $r['content'] = $r['comment'];
                 $r['title'] = $r['caption'];
                 IPSText::getTextClass('bbcode')->parse_smilies = 1;
                 IPSText::getTextClass('bbcode')->parse_html = ($r['allow_html'] and $this->caches['group_cache'][$poster['member_group_id']]['g_dohtml']) ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = 1;
                 IPSText::getTextClass('bbcode')->parse_bbcode = 1;
                 IPSText::getTextClass('bbcode')->parsing_section = 'gallery_comment';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $r['id'] = $r['imgid'];
                 $content[] = $r;
             }
             break;
         case 'cats':
             $this->DB->build(array('select' => 'c.id as cid, c.description as cdescription, c.*', 'from' => array('gallery_categories' => 'c'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'i.id as imgid, i.*', 'from' => array('gallery_images' => 'i'), 'where' => 'i.id=c.last_pic_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=c.last_poster_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['cat_id'] = $r['cid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=gallery&amp;module=cats&amp;do=sc&amp;cat=' . $r['cat_id'], 'none');
                 $r['date'] = $r['last_pic_date'];
                 $r['content'] = $r['cdescription'];
                 $r['title'] = $r['name'];
                 $r = IPSMember::buildDisplayData($r);
                 $r['id'] = $r['imgid'];
                 $content[] = $r;
             }
             break;
         case 'albums':
             $this->DB->build(array('select' => 'a.id as aid, a.description as adescription, a.*', 'from' => array('gallery_albums' => 'a'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'i.id as imgid, i.*', 'from' => array('gallery_images' => 'i'), 'where' => 'i.id=a.last_pic_id', 'type' => 'left'), array('select' => 'c.id as cid, c.*', 'from' => array('gallery_categories' => 'c'), 'where' => 'c.id=a.category_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=a.member_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $this->DB->execute();
             while ($r = $this->DB->fetch()) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['cat_id'] = $r['cid'];
                 $r['album_id'] = $r['aid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?app=gallery&amp;module=user&amp;user='******'member_id'] . '&amp;do=view_album&amp;album=' . $r['album_id'], 'none');
                 $r['date'] = $r['last_pic_date'];
                 $r['content'] = $r['adescription'];
                 $r['title'] = $r['name'];
                 $r = IPSMember::buildDisplayData($r);
                 $r['id'] = $r['imgid'];
                 $content[] = $r;
             }
             break;
     }
     //-----------------------------------------
     // Return formatted content
     //-----------------------------------------
     $feedConfig = $this->returnFeedInfo();
     $templateBit = $feedConfig['templateBit'] . '_' . $block['block_id'];
     if ($config['hide_empty'] and !count($content)) {
         return '';
     }
     return $this->registry->output->getTemplate('ccs')->{$templateBit}($block['block_name'], $content);
 }
 /**
  * Save the edits to a template
  *
  * @access	protected
  * @param	string		[$type]		Saving of form (add|edit)
  * @return	void
  */
 protected function _save($type = 'add')
 {
     $id = 0;
     if ($type == 'edit') {
         $id = intval($this->request['template']);
         if (!$id) {
             $this->registry->output->showError($this->lang->words['ccs_no_template_id']);
         }
     }
     $save = array('template_name' => trim($this->request['template_name']), 'template_desc' => trim($this->request['template_desc']), 'template_key' => trim($this->request['template_key']), 'template_content' => str_replace('&#46;&#46;/', '../', trim($_POST['template_content'])), 'template_updated' => time(), 'template_category' => intval($this->request['template_category']));
     //-----------------------------------------
     // Make sure key is unique
     //-----------------------------------------
     if (!$save['template_key']) {
         $this->registry->output->showError($this->lang->words['template_key_missing']);
     }
     $check = $this->DB->buildAndFetch(array('select' => 'template_id', 'from' => 'ccs_page_templates', 'where' => "template_key='{$save['template_key']}' AND template_id<>{$id}"));
     if ($check['template_id']) {
         $this->registry->output->showError($this->lang->words['template_key_used']);
     }
     //-----------------------------------------
     // Save
     //-----------------------------------------
     if ($type == 'edit') {
         $this->DB->update('ccs_page_templates', $save, 'template_id=' . $id);
         $this->DB->update('ccs_pages', array('page_cache' => null), 'page_template_used=' . $id);
         $this->registry->output->global_message = $this->lang->words['template_edited'];
     } else {
         $this->DB->insert('ccs_page_templates', $save);
         $id = $this->DB->getInsertId();
         $this->registry->output->global_message = $this->lang->words['template_added'];
         $this->request['template'] = $id;
     }
     //-----------------------------------------
     // Recache the template
     //-----------------------------------------
     $cache = array('cache_type' => 'template', 'cache_type_id' => $id);
     require_once IPS_KERNEL_PATH . 'classTemplateEngine.php';
     $engine = new classTemplate(IPS_ROOT_PATH . 'sources/template_plugins');
     $cache['cache_content'] = $engine->convertHtmlToPhp($save['template_key'], '', $save['template_content'], '', false, true);
     $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='template' AND cache_type_id={$id}"));
     if ($hasIt['cache_id']) {
         $this->DB->update('ccs_template_cache', $cache, "cache_type='template' AND cache_type_id={$id}");
     } else {
         $this->DB->insert('ccs_template_cache', $cache);
     }
     //-----------------------------------------
     // Recache the "skin" file
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $_pagesClass = new pageBuilder($this->registry);
     $_pagesClass->recacheTemplateCache($engine);
     //-----------------------------------------
     // Show form again?
     //-----------------------------------------
     if ($this->request['save_and_reload']) {
         $this->_form('edit');
         return;
     }
     //-----------------------------------------
     // Output
     //-----------------------------------------
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=templates&section=pages');
 }
 /**
  * Recache a block
  *
  * @access	protected
  * @return	void
  */
 protected function _recacheAllBlocks()
 {
     //-----------------------------------------
     // Get skin
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $pageBuilder = new pageBuilder($this->registry);
     $pageBuilder->recacheTemplateCache();
     $pageBuilder->loadSkinFile();
     $this->DB->build(array('select' => '*', 'from' => 'ccs_blocks'));
     $outer = $this->DB->execute();
     while ($block = $this->DB->fetch($outer)) {
         if ($block['block_type'] and file_exists(IPSLib::getAppDir('ccs') . '/sources/blocks/' . $block['block_type'] . '/admin.php')) {
             require_once IPSLib::getAppDir('ccs') . '/sources/blocks/adminInterface.php';
             require_once IPSLib::getAppDir('ccs') . '/sources/blocks/' . $block['block_type'] . '/admin.php';
             $className = "adminBlockHelper_" . $block['block_type'];
             $extender = new $className($this->registry);
             $extender->recacheBlock($block);
         }
     }
     //-----------------------------------------
     // Clear page caches
     //-----------------------------------------
     $this->DB->update('ccs_pages', array('page_cache' => null));
     $this->registry->output->global_message = $this->lang->words['all_blocks_recached'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=blocks&section=blocks');
 }
Example #12
0
function install()
{
    // On free.fr host, make sure the /sessions directory exists, otherwise login will not work.
    if (endsWith($_SERVER['HTTP_HOST'], '.free.fr') && !is_dir($_SERVER['DOCUMENT_ROOT'] . '/sessions')) {
        mkdir($_SERVER['DOCUMENT_ROOT'] . '/sessions', 0705);
    }
    // This part makes sure sessions works correctly.
    // (Because on some hosts, session.save_path may not be set correctly,
    // or we may not have write access to it.)
    if (isset($_GET['test_session']) && (!isset($_SESSION) || !isset($_SESSION['session_tested']) || $_SESSION['session_tested'] != 'Working')) {
        // Step 2: Check if data in session is correct.
        echo '<pre>Sessions do not seem to work correctly on your server.<br>';
        echo 'Make sure the variable session.save_path is set correctly in your php config, and that you have write access to it.<br>';
        echo 'It currently points to ' . session_save_path() . '<br><br><a href="?">Click to try again.</a></pre>';
        die;
    }
    if (!isset($_SESSION['session_tested'])) {
        // Step 1 : Try to store data in session and reload page.
        $_SESSION['session_tested'] = 'Working';
        // Try to set a variable in session.
        header('Location: ' . indexUrl() . '?test_session');
        // Redirect to check stored data.
    }
    if (isset($_GET['test_session'])) {
        // Step 3: Sessions are ok. Remove test parameter from URL.
        header('Location: ' . indexUrl());
    }
    if (!empty($_POST['setlogin']) && !empty($_POST['setpassword'])) {
        $tz = 'UTC';
        if (!empty($_POST['continent']) && !empty($_POST['city'])) {
            if (isTZvalid($_POST['continent'], $_POST['city'])) {
                $tz = $_POST['continent'] . '/' . $_POST['city'];
            }
        }
        $GLOBALS['timezone'] = $tz;
        // Everything is ok, let's create config file.
        $GLOBALS['login'] = $_POST['setlogin'];
        $GLOBALS['salt'] = sha1(uniqid('', true) . '_' . mt_rand());
        // Salt renders rainbow-tables attacks useless.
        $GLOBALS['hash'] = sha1($_POST['setpassword'] . $GLOBALS['login'] . $GLOBALS['salt']);
        $GLOBALS['title'] = empty($_POST['title']) ? 'Shared links on ' . htmlspecialchars(indexUrl()) : $_POST['title'];
        writeConfig();
        echo '<script language="JavaScript">alert("Shaarli is now configured. Please enter your login/password and start shaaring your links !");document.location=\'?do=login\';</script>';
        exit;
    }
    // Display config form:
    list($timezone_form, $timezone_js) = templateTZform();
    $timezone_html = '';
    if ($timezone_form != '') {
        $timezone_html = '<tr><td valign="top"><b>Timezone:</b></td><td>' . $timezone_form . '</td></tr>';
    }
    $PAGE = new pageBuilder();
    $PAGE->assign('timezone_html', $timezone_html);
    $PAGE->assign('timezone_js', $timezone_js);
    $PAGE->renderPage('install');
    exit;
}
 /**
  * Execute the feed and return the HTML to show on the page.  
  * Can be called from ACP or front end, so the plugin needs to setup any appropriate lang files, skin files, etc.
  *
  * @access	public
  * @param	array 				Block data
  * @return	string				Block HTML to display or cache
  */
 public function executeFeed($block)
 {
     $this->lang->loadLanguageFile(array('public_ccs'), 'ccs');
     $config = unserialize($block['block_config']);
     $where = array();
     //-----------------------------------------
     // Set up filtering clauses
     //-----------------------------------------
     if ($config['filters']['filter_forums']) {
         if ($config['content'] == 'forums') {
             $where[] = "f.id IN(" . $config['filters']['filter_forums'] . ")";
         } else {
             $where[] = "t.forum_id IN(" . $config['filters']['filter_forums'] . ")";
         }
     }
     switch ($config['content']) {
         case 'topics':
             if ($config['filters']['filter_status'] != 'either') {
                 $where[] = "t.state='" . $config['filters']['filter_status'] . "'";
             }
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "t.approved=" . ($config['filters']['filter_visibility'] == 'approved' ? 1 : 0);
             }
             if ($config['filters']['filter_pinned'] != 'either') {
                 $where[] = "t.pinned=" . ($config['filters']['filter_pinned'] == 'pinned' ? 1 : 0);
             }
             if ($config['filters']['filter_posts'] > 0) {
                 $where[] = "t.posts > " . $config['filters']['filter_posts'];
             }
             if ($config['filters']['filter_starter'] == 'myself') {
                 $where[] = "t.starter_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_starter'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "t.starter_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_starter'] != '') {
                         $member = IPSMember::load($config['filters']['filter_starter'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "t.starter_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             if ($config['filters']['filter_poll'] != 'either') {
                 $where[] = "t.poll_state=" . ($config['filters']['filter_poll'] == 'poll' ? 1 : 0);
             }
             if ($config['filters']['filter_moved']) {
                 $where[] = "(t.moved_to=0 OR t.moved_to='' OR t.moved_to IS NULL)";
             }
             if ($config['filters']['filter_attach']) {
                 $where[] = "t.topic_hasattach > 0";
             }
             if ($config['filters']['filter_rating']) {
                 $where[] = "(t.topic_rating_total/t.topic_rating_hits) >= " . $config['filters']['filter_rating'];
             }
             break;
         case 'replies':
             if ($config['filters']['filter_status'] != 'either') {
                 $where[] = "t.state='" . $config['filters']['filter_status'] . "'";
             }
             if ($config['filters']['filter_visibility'] != 'either') {
                 $where[] = "t.approved=" . ($config['filters']['filter_visibility'] == 'approved' ? 1 : 0);
                 $where[] = "p.queued=" . ($config['filters']['filter_visibility'] == 'approved' ? 0 : 1);
             }
             if ($config['filters']['filter_pinned'] != 'either') {
                 $where[] = "t.pinned=" . ($config['filters']['filter_pinned'] == 'pinned' ? 1 : 0);
             }
             if ($config['filters']['filter_posts'] > 0) {
                 $where[] = "t.posts > " . $config['filters']['filter_posts'];
             }
             if ($config['filters']['filter_attach']) {
                 $where[] = "t.topic_hasattach > 0";
             }
             if ($config['filters']['filter_rating']) {
                 $where[] = "(t.topic_rating_total/t.topic_rating_hits) >= " . $config['filters']['filter_rating'];
             }
             if ($config['filters']['filter_poll'] != 'either') {
                 $where[] = "t.poll_state=" . ($config['filters']['filter_poll'] == 'poll' ? 1 : 0);
             }
             if ($config['filters']['filter_poster'] == 'myself') {
                 $where[] = "p.author_id = " . $this->memberData['member_id'];
             } else {
                 if ($config['filters']['filter_poster'] == 'friends') {
                     //-----------------------------------------
                     // Get page builder for friends
                     //-----------------------------------------
                     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
                     $pageBuilder = new pageBuilder($this->registry);
                     $friends = $pageBuilder->getFriends();
                     if (count($friends)) {
                         $where[] = "p.author_id IN( " . implode(',', $friends) . ")";
                     } else {
                         return '';
                     }
                 } else {
                     if ($config['filters']['filter_poster'] != '') {
                         $member = IPSMember::load($config['filters']['filter_poster'], 'basic');
                         if ($member['member_id']) {
                             $where[] = "p.author_id = " . $member['member_id'];
                         } else {
                             return '';
                         }
                     }
                 }
             }
             break;
         case 'forums':
             if ($config['filters']['filter_root']) {
                 $where[] = "f.parent_id < 1";
             }
             break;
     }
     $order = '';
     switch ($config['content']) {
         case 'topics':
             switch ($config['sortby']) {
                 case 'title':
                     $order .= "t.title ";
                     break;
                 case 'posts':
                     $order .= "t.posts ";
                     break;
                 case 'start_date':
                     $order .= "t.start_date ";
                     break;
                 default:
                 case 'last_post':
                     $order .= "t.last_post ";
                     break;
                 case 'views':
                     $order .= "t.views ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
         case 'replies':
             switch ($config['sortby']) {
                 default:
                 case 'post_date':
                     $order .= "p.post_date ";
                     break;
             }
             break;
         case 'forums':
             switch ($config['sortby']) {
                 case 'name':
                     $order .= "f.name ";
                     break;
                 case 'topics':
                     $order .= "f.topics ";
                     break;
                 case 'posts':
                     $order .= "f.posts ";
                     break;
                 case 'last_post':
                     $order .= "f.last_post ";
                     break;
                 default:
                 case 'position':
                     $order .= "f.position ";
                     break;
                 case 'rand':
                     $order .= "RAND() ";
                     break;
             }
             break;
     }
     $order .= $config['sortorder'];
     //-----------------------------------------
     // Run the query and get the results
     //-----------------------------------------
     $content = array();
     switch ($config['content']) {
         case 'topics':
             $this->DB->build(array('select' => 't.*, t.title as topic_title', 'from' => array('topics' => 't'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => 'p.pid=t.topic_firstpost', 'type' => 'left'), array('select' => 'poster.member_group_id as poster_group_id, poster.member_id as poster_id, poster.mgroup_others as poster_group_others', 'from' => array('members' => 'poster'), 'where' => 'poster.member_id=p.author_id', 'type' => 'left'), array('select' => 'f.*, f.id as fid', 'from' => array('forums' => 'f'), 'where' => 'f.id=t.forum_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=t.last_poster_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['title'] = $r['topic_title'];
                 $r['member_id'] = $r['mid'];
                 $r['forum_id'] = $r['fid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?showtopic=' . $r['tid'], 'none', $r['title_seo'], 'showtopic');
                 $r['date'] = $r['last_post'];
                 $r['content'] = $r['post'];
                 IPSText::getTextClass('bbcode')->parse_smilies = $r['use_emo'];
                 IPSText::getTextClass('bbcode')->parse_html = ($r['use_html'] and $this->caches['group_cache'][$r['poster_group_id']]['g_dohtml'] and $r['post_htmlstate']) ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = $r['post_htmlstate'] == 2 ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_bbcode = $r['use_ibc'];
                 IPSText::getTextClass('bbcode')->parsing_section = 'topics';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['poster_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['poster_group_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
         case 'replies':
             $this->DB->build(array('select' => 'p.*', 'from' => array('posts' => 'p'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 't.*, t.title as topic_title', 'from' => array('topics' => 't'), 'where' => 't.tid=p.topic_id', 'type' => 'left'), array('select' => 'f.*, f.id as fid', 'from' => array('forums' => 'f'), 'where' => 'f.id=t.forum_id', 'type' => 'left'), array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=p.author_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['title'] = $r['topic_title'];
                 $r['member_id'] = $r['mid'];
                 $r['forum_id'] = $r['fid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?showtopic=' . $r['tid'] . '&amp;view=findpost&amp;p=' . $r['pid'], 'none', $r['title_seo'], 'showtopic');
                 $r['date'] = $r['post_date'];
                 $r['content'] = $r['post'];
                 IPSText::getTextClass('bbcode')->parse_smilies = $r['use_emo'];
                 IPSText::getTextClass('bbcode')->parse_html = ($r['use_html'] and $this->caches['group_cache'][$r['member_group_id']]['g_dohtml'] and $r['post_htmlstate']) ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_nl2br = $r['post_htmlstate'] == 2 ? 1 : 0;
                 IPSText::getTextClass('bbcode')->parse_bbcode = $r['use_ibc'];
                 IPSText::getTextClass('bbcode')->parsing_section = 'topics';
                 IPSText::getTextClass('bbcode')->parsing_mgroup = $r['member_group_id'];
                 IPSText::getTextClass('bbcode')->parsing_mgroup_others = $r['mgroup_others'];
                 $r['content'] = IPSText::getTextClass('bbcode')->preDisplayParse($r['content']);
                 $r['content'] = IPSText::getTextClass('bbcode')->memberViewImages($r['content']);
                 $r = IPSMember::buildDisplayData($r);
                 $content[] = $r;
             }
             break;
         case 'forums':
             $this->DB->build(array('select' => 'f.*, f.name as fname, f.id as fid', 'from' => array('forums' => 'f'), 'where' => implode(' AND ', $where), 'order' => $order, 'limit' => array($config['offset_a'], $config['offset_b']), 'add_join' => array(array('select' => 'm.*, m.member_id as mid', 'from' => array('members' => 'm'), 'where' => 'm.member_id=f.last_poster_id', 'type' => 'left'), array('select' => 'pp.*', 'from' => array('profile_portal' => 'pp'), 'where' => 'pp.pp_member_id=m.member_id', 'type' => 'left'), array('select' => 'pf.*', 'from' => array('pfields_content' => 'pf'), 'where' => 'pf.member_id=m.member_id', 'type' => 'left'), array('select' => 's.*', 'from' => array('sessions' => 's'), 'where' => 's.member_id=m.member_id', 'type' => 'left'))));
             $outer = $this->DB->execute();
             while ($r = $this->DB->fetch($outer)) {
                 //-----------------------------------------
                 // Normalization
                 //-----------------------------------------
                 $r['member_id'] = $r['mid'];
                 $r['forum_id'] = $r['fid'];
                 $r['url'] = $this->registry->output->buildSEOUrl($this->settings['board_url'] . '/index.php?showforum=' . $r['forum_id'], 'none', $r['name_seo'], 'showforum');
                 $r['title'] = $r['fname'];
                 $r['date'] = $r['joined'];
                 $r['content'] = $r['pp_about_me'];
                 $r = IPSMember::buildDisplayData($r);
                 $r['id'] = $r['forum_id'];
                 $content[] = $r;
             }
             break;
     }
     //-----------------------------------------
     // Return formatted content
     //-----------------------------------------
     $feedConfig = $this->returnFeedInfo();
     $templateBit = $feedConfig['templateBit'] . '_' . $block['block_id'];
     if ($config['hide_empty'] and !count($content)) {
         return '';
     }
     return $this->registry->output->getTemplate('ccs')->{$templateBit}($block['block_name'], $content);
 }
 /**
  * Recache a page
  *
  * @access	public
  * @param	array		[$page]		Override page data
  * @param	bool		[$return]	Return content instead of storing it
  * @return	void
  */
 public function recachePage($page = array(), $return = false)
 {
     if (!count($page)) {
         $id = intval($this->request['page']);
         $page = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_pages', 'where' => 'page_id=' . $id));
     }
     //-----------------------------------------
     // Get page builder
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $pageBuilder = new pageBuilder($this->registry);
     $content = $pageBuilder->recachePage($page);
     //-----------------------------------------
     // Return or update
     //-----------------------------------------
     if (!$return and $page['page_id']) {
         $this->DB->update('ccs_pages', array('page_cache' => $content, 'page_cache_last' => time()), 'page_id=' . intval($page['page_id']));
     } else {
         return $content;
     }
     $this->registry->output->global_message = $this->lang->words['page_recached'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=pages&section=list');
 }