Example #1
0
 function compile_categories_tag($tag_args)
 {
     global $DB;
     $defaults = array('amount' => 'all', 'order' => 'name');
     $attrs = $this->parse_attributes($tag_args);
     $attrs = array_merge($defaults, $attrs);
     if (empty($attrs['var'])) {
         return $this->syntax_error("categories: missing 'var' attribute");
     }
     $s = new SelectBuilder('*', 'tlx_categories_build');
     if (strtolower($attrs['amount']) != 'all') {
         $s->SetLimit($attrs['amount']);
     }
     if ($attrs['exclude']) {
         $attrs['exclude'] = FormatCommaSeparated($attrs['exclude']);
         $s->AddWhere('name', ST_NOT_IN, $attrs['exclude']);
     }
     if ($attrs['startswith']) {
         $s->AddWhere('name', ST_STARTS, $attrs['startswith']);
     }
     $s->SetOrderString($attrs['order'], $DB->GetColumns('tlx_categories_build'));
     $query = $DB->Prepare($s->Generate(), $s->binds);
     $attrs['var'] = $this->parse_vars($attrs['var']);
     return S_PHP . " if( !isset(\$GLOBALS['_prep_category_build']) )" . NEWLINE . "{" . NEWLINE . "PrepareCategoriesBuild();" . NEWLINE . "}" . NEWLINE . " {$attrs['var']} =& \$GLOBALS['DB']->FetchAll(\"{$query}\"); " . E_PHP;
 }
Example #2
0
function txReviewGalleryNext()
{
    global $DB, $json, $C;
    $out = array('status' => JSON_SUCCESS, 'message' => "Next gallery in line has been loaded", 'html' => '', 'gallery_url' => '', 'done' => 0);
    $s = new SelectBuilder('SQL_CALC_FOUND_ROWS *', 'tx_galleries');
    $s->AddWhere('status', ST_MATCHES, 'pending');
    $s->AddWhere('type', ST_MATCHES, $_REQUEST['s_type'], TRUE);
    $s->AddWhere('format', ST_MATCHES, $_REQUEST['s_format'], TRUE);
    $s->AddWhere('sponsor_id', ST_MATCHES, $_REQUEST['s_sponsor_id'], TRUE);
    $s->AddFulltextWhere('categories', $_REQUEST['s_category'], TRUE);
    $s->SetLimit("{$_REQUEST['limit']},1");
    if ($_REQUEST['sort'] == 'random') {
        $junk = array();
        $s->SetOrderString('RAND(' . $_REQUEST['seed'] . ')', $junk);
    } else {
        $s->AddOrder($_REQUEST['sort'], $_REQUEST['direction']);
    }
    $gallery = $DB->Row($s->Generate(), $s->binds);
    $remain = $DB->Count('SELECT FOUND_ROWS()');
    if ($gallery) {
        $icons =& $DB->FetchAll('SELECT * FROM `tx_icons`');
        if ($gallery['has_preview']) {
            $gallery['previews'] =& $DB->FetchAll('SELECT * FROM `tx_gallery_previews` WHERE `gallery_id`=?', array($gallery['gallery_id']));
            foreach ($gallery['previews'] as $index => $preview) {
                list($width, $height) = explode('x', $preview['dimensions']);
                if ($width > 180 || $height > 180) {
                    $gallery['previews'][$index]['attrs'] = $width > $height ? ' width="180"' : ' height="180"';
                }
            }
        }
        $out['gallery_url'] = $gallery['gallery_url'];
        $out['gallery_id'] = $gallery['gallery_id'];
        $fields = $DB->Row('SELECT * FROM `tx_gallery_fields` WHERE `gallery_id`=?', array($gallery['gallery_id']));
        if ($fields) {
            $gallery = array_merge($gallery, $fields);
        }
        ArrayHSC($gallery);
        $form_html = file_get_contents("includes/review-galleries-form.php");
        ob_start();
        eval('?>' . $form_html);
        $out['html'] = ob_get_contents();
        ob_end_clean();
    } else {
        $pending = $DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `status`=?', array('pending'));
        $done_html = file_get_contents("includes/review-galleries-done.php");
        ob_start();
        eval('?>' . $done_html);
        $out['html'] = ob_get_contents();
        ob_end_clean();
        $out['done'] = 1;
    }
    echo $json->encode($out);
}
Example #3
0
 function compile_ad_tag($tag_args)
 {
     global $DB;
     $defaults = array('pagedupes' => 'false', 'weight' => 'any', 'order' => 'times_displayed, (unique_clicks/times_displayed) DESC');
     $attrs = $this->parse_attributes($tag_args);
     $attrs = array_merge($defaults, $attrs);
     // Convert boolean values
     $attrs['pagedupes'] = $this->to_bool($attrs['pagedupes']);
     // Prepare RAND() values in order
     $attrs['order'] = preg_replace('~rand\\(\\)~i', 'RAND(%RAND%)', $attrs['order']);
     $s = new SelectBuilder('*,`lx_ads`.`ad_id` AS `ad_id`', 'lx_ads');
     // Process pagedupes
     if ($attrs['pagedupes'] === FALSE) {
         $s->AddJoin('lx_ads', 'lx_ads_used_page', 'LEFT', 'ad_id');
         $s->AddWhere('lx_ads_used_page.ad_id', ST_NULL, null);
     }
     // Process tags attribute
     if (isset($attrs['tags'])) {
         $s->AddFulltextWhere('tags', $attrs['tags']);
     }
     // Process weight attribute
     if (isset($attrs['weight']) && $attrs['weight'] != 'any') {
         $s->AddWhereString("`weight` {$attrs['weight']}");
     }
     $s->SetOrderString($attrs['order'], $DB->GetColumns('lx_ads'));
     $s->SetLimit('1');
     $query = $DB->Prepare($s->Generate(), $s->binds);
     // Perform replacements for placeholders
     $replacements = array('%RAND%' => '".rand()."');
     foreach ($replacements as $find => $replace) {
         $query = str_replace($find, $replace, $query);
     }
     return S_PHP . " if( !isset(\$GLOBALS['_CLEAR_PAGE_USED_']) )\n{\n" . "\$GLOBALS['DB']->Update('DELETE FROM `lx_ads_used_page`');\n" . "\$GLOBALS['_CLEAR_PAGE_USED_'] = TRUE;\n" . "}\n" . "\$_temp_ad = \$GLOBALS['DB']->Row(\"{$query}\");\n" . "if( \$_temp_ad )\n{\n" . "\$GLOBALS['DB']->Update(\"UPDATE `lx_ads` SET `times_displayed`=`times_displayed`+1 WHERE `ad_id`=?\", array(\$_temp_ad['ad_id']));\n" . "\$GLOBALS['DB']->Update(\"REPLACE INTO `lx_ads_used_page` VALUES (?)\", array(\$_temp_ad['ad_id']));\n" . "echo \$_temp_ad['ad_html'];\n" . "}\n" . E_PHP;
 }