/** * Quick user search for the link submission form */ function lxQuickUserSearch() { global $DB, $json; $out = array('status' => JSON_SUCCESS, 'results' => array()); $select = new SelectBuilder('*', 'lx_users'); $select->AddMultiWhere(array('username', 'email'), array(ST_CONTAINS, ST_CONTAINS), array($_REQUEST['term'], $_REQUEST['term']), TRUE); $select->AddOrder('username'); $result = $DB->Query($select->Generate(), $select->binds); while ($account = $DB->NextRow($result)) { ArrayHSC($account); $out['results'][] = $account; } $DB->Free($result); echo $json->encode($out); }
function compile_galleries_tag($tag_args) { global $DB; $defaults = array('preview' => 'any', 'type' => 'submitted', 'format' => 'any', 'category' => 'MIXED', 'sponsor' => 'any', 'amount' => '20', 'globaldupes' => isset($this->defines['globaldupes']) ? $this->defines['globaldupes'] : 'true', 'pagedupes' => isset($this->defines['pagedupes']) ? $this->defines['pagedupes'] : 'false', 'getnew' => 'true', 'allowused' => 'true', 'description' => 'false', 'weight' => 'any'); $attrs = $this->parse_attributes($tag_args); $attrs = array_merge($defaults, $attrs); if (empty($attrs['var'])) { return $this->syntax_error("galleries: missing 'var' attribute"); } if (!empty($attrs['previewsize']) && !preg_match('~^\\d+x\\d+$~', $attrs['previewsize'])) { return $this->syntax_error("galleries: the 'previewsize' value must be provided and in WxH format"); } $attrs['var'] = $this->parse_vars($attrs['var']); // Convert boolean values $attrs['preview'] = $this->to_bool($attrs['preview']); $attrs['globaldupes'] = $this->to_bool($attrs['globaldupes']); $attrs['pagedupes'] = $this->to_bool($attrs['pagedupes']); $attrs['getnew'] = $this->to_bool($attrs['getnew']); $attrs['allowused'] = $this->to_bool($attrs['allowused']); $attrs['description'] = $this->to_bool($attrs['description']); // Whether or not to pull a preview thumb $pull_preview = 'FALSE'; // Set default sorting options if ($attrs['getnew'] === TRUE) { if (isset($attrs['order']) && !isset($attrs['reorder'])) { $attrs['reorder'] = $attrs['order']; } else { if (!isset($attrs['reorder'])) { $attrs['reorder'] = 'date_displayed DESC, date_approved'; } } if (!isset($attrs['order'])) { $attrs['order'] = 'date_approved'; } } else { if (isset($attrs['order']) && !isset($attrs['reorder'])) { $attrs['reorder'] = $attrs['order']; } else { if (!isset($attrs['reorder'])) { $attrs['reorder'] = 'date_displayed DESC, date_approved'; } } if (!isset($attrs['order'])) { $attrs['order'] = 'date_displayed DESC, date_approved'; } } // Prepare RAND() values in order and reorder $attrs['order'] = preg_replace('~rand\\(\\)~i', 'RAND(%RAND%)', $attrs['order']); $attrs['reorder'] = preg_replace('~rand\\(\\)~i', 'RAND(%RAND%)', $attrs['reorder']); // Pulling galleries from a text file if (isset($attrs['file'])) { // galleries from text file...coming soon } else { if (isset($attrs['select'])) { if (!isset($attrs['reselect']) || empty($attrs['reselect'])) { $attrs['reselect'] = $attrs['select']; } $replacements = array('%MYSQL_CURDATE%' => '".MYSQL_CURDATE."', '%MYSQL_NOW%' => '".MYSQL_NOW."', '%RAND%' => '".rand()."', '%LIMIT%' => isset($attrs['fillvar']) ? '" . (' . $attrs['amount'] . ' - count(' . $attrs['fillvar'] . ') - $_got) . "' : '" . (' . $attrs['amount'] . ' - $_got) . "', '%PAGEID%' => '" . $this->vars[\'page\'][\'page_id\'] . "', '%FILL%' => '" . (' . $attrs['amount'] . ' - count(' . $attrs['fillvar'] . ')). "'); foreach ($replacements as $find => $replace) { $attrs['select'] = str_replace($find, $replace, $attrs['select']); $attrs['reselect'] = str_replace($find, $replace, $attrs['reselect']); } return S_PHP . NEWLINE . "if( \$GLOBALS['_build_type'] == BT_BUILD_WITH_NEW )" . NEWLINE . "{" . NEWLINE . "{$attrs['var']} =& LoadGalleries(\"{$attrs['select']}\", \$this->vars['this_page']['page_id'], \$this->vars['this_page']['category_id']);" . NEWLINE . "}" . NEWLINE . "else" . NEWLINE . "{" . NEWLINE . "{$attrs['var']} =& LoadGalleries(\"{$attrs['reselect']}\", \$this->vars['this_page']['page_id'], \$this->vars['this_page']['category_id']);" . NEWLINE . "}" . NEWLINE . E_PHP; } else { if (isset($attrs['age']) && (isset($attrs['minage']) || isset($attrs['maxage']))) { return $this->syntax_error("galleries: 'age' attribute cannot be combined with 'minage' or 'maxage'"); } $s = new SelectBuilder('*,`tx_galleries`.`gallery_id` AS `gallery_id`', 'tx_galleries'); // Process globaldupes if ($attrs['globaldupes'] === FALSE) { $s->AddJoin('tx_galleries', 'tx_gallery_used', 'LEFT', 'gallery_id'); $s->AddWhere('tx_gallery_used.gallery_id', ST_NULL, null); } // Process pagedupes if ($attrs['pagedupes'] === FALSE) { $s->AddJoin('tx_galleries', 'tx_gallery_used_page', 'LEFT', 'gallery_id'); $s->AddWhere('tx_gallery_used_page.gallery_id', ST_NULL, null); } // Process preview attribute if ($attrs['preview'] === TRUE) { if (empty($attrs['previewsize'])) { $s->AddWhere('has_preview', ST_MATCHES, 1); $pull_preview = 'TRUE'; } else { $s->AddJoin('tx_galleries', 'tx_gallery_previews', '', 'gallery_id'); $s->AddWhere('dimensions', ST_MATCHES, $attrs['previewsize']); } } else { if ($attrs['preview'] === FALSE) { $s->AddWhere('has_preview', ST_MATCHES, 0); } else { $pull_preview = 'TRUE'; } } // Process type attribute $attrs['type'] = strtolower($attrs['type']); if ($attrs['type'] != 'any') { $s->AddWhere('type', ST_MATCHES, $attrs['type']); } // Process format attribute $attrs['format'] = strtolower($attrs['format']); if ($attrs['format'] != 'any') { $s->AddWhere('format', ST_MATCHES, $attrs['format']); } // Process description attribute if ($attrs['description'] === TRUE) { $s->AddWhere('description', ST_NOT_EMPTY, null); } // Process partner attribute if (isset($attrs['partner'])) { $s->AddWhere('partner', ST_MATCHES, $attrs['partner']); } // Process keywords attribute if (isset($attrs['keywords'])) { $s->AddFulltextWhere('keywords', $attrs['keywords']); } // Process tags attribute if (isset($attrs['tags'])) { $s->AddFulltextWhere('tags', $attrs['tags']); } // Process category attribute if (isset($attrs['category'])) { $attrs['category'] = FormatCommaSeparated($attrs['category']); if ($this->flags['category_id']) { if (!isset($GLOBALS['CATEGORY_CACHE_ID'])) { $GLOBALS['CATEGORY_CACHE_ID'] =& $DB->FetchAll('SELECT * FROM `tx_categories`', null, 'category_id'); } $s->AddFulltextWhere('categories', $GLOBALS['CATEGORY_CACHE_ID'][$this->flags['category_id']]['tag'], TRUE); } else { if (strtoupper($attrs['category']) != 'MIXED') { $fulltext = array(); if (!isset($GLOBALS['CATEGORY_CACHE'])) { $GLOBALS['CATEGORY_CACHE'] =& $DB->FetchAll('SELECT * FROM `tx_categories`', null, 'name'); } foreach (explode(',', $attrs['category']) as $category) { switch ($category) { case 'MIXED': case 'mixed': case 'Mixed': $fulltext[] = MIXED_CATEGORY; break; default: $minus = ''; if (preg_match('~^([-+])(.*)~i', $category, $matches)) { $minus = $matches[1]; $category = $matches[2]; } if ($GLOBALS['CATEGORY_CACHE'][$category]) { $fulltext[] = $minus . $GLOBALS['CATEGORY_CACHE'][$category]['tag']; } } } if (count($fulltext) < 1) { return $this->syntax_error("galleries: 'category' attribute contains an invalid category name [{$attrs['category']}]"); } $s->AddFulltextWhere('categories', join(' ', $fulltext)); } } } // Process sponsor attribute if (isset($attrs['sponsor'])) { $attrs['sponsor'] = FormatCommaSeparated($attrs['sponsor']); if (strtolower($attrs['sponsor']) != 'any') { $sponsors =& $DB->FetchAll('SELECT * FROM `tx_sponsors`', null, 'name'); $sponsor_ids = array(); $not_in = FALSE; foreach (explode(',', $attrs['sponsor']) as $sponsor) { $minus = FALSE; if (preg_match('~^-(.*)~i', $sponsor, $matches)) { $minus = TRUE; $sponsor = $matches[1]; } if ($sponsor == 'any') { $not_in = TRUE; } else { if (isset($sponsors[$sponsor])) { $sponsor_ids[] = $sponsors[$sponsor]['sponsor_id']; } } } if ($not_in) { $s->AddMultiWhere(array('sponsor_id', 'sponsor_id'), array(ST_NOT_IN, ST_NULL), array(join(',', $sponsor_ids), null)); } else { $s->AddWhere('sponsor_id', ST_IN, join(',', $sponsor_ids)); } } } // Process weight attribute if (isset($attrs['weight']) && $attrs['weight'] != 'any') { $s->AddWhereString("`weight` {$attrs['weight']}"); } // Process amount attribute $s->SetLimit($attrs['amount']); if (isset($attrs['fillvar'])) { $attrs['fillvar'] = $this->parse_vars($attrs['fillvar']); $s->SetLimit('%FILL%'); } // Get available sorting columns and copy the SelectBuilder object // Little hack to workaround differences in object copying between PHP4 and PHP5 $tx_galleries = $DB->GetColumns('tx_galleries'); if (function_exists('array_combine')) { $s_new = unserialize(serialize($s)); } else { $s_new = $s; } if ($attrs['getnew'] === TRUE) { $s->AddWhere('status', ST_IN, 'used,holding'); $s->SetOrderString($attrs['reorder'], $tx_galleries); $s_new->AddWhere('status', ST_MATCHES, 'approved'); $s_new->AddMultiWhere(array('date_scheduled', 'date_scheduled'), array(ST_NULL, ST_LESS), array(null, '%MYSQL_NOW%')); $s_new->SetOrderString($attrs['order'], $tx_galleries); } else { $s->AddWhere('status', ST_IN, 'used,holding'); $s->SetOrderString($attrs['reorder'], $tx_galleries); $s_new->AddWhere('status', ST_IN, 'used,holding'); $s_new->SetOrderString($attrs['order'], $tx_galleries); } // Process age, minage and maxage attributes if (isset($attrs['age'])) { $s->AddWhereString("`date_displayed` BETWEEN SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['age']} DAY) AND SUBDATE('%MYSQL_CURDATE% 23:59:59', INTERVAL {$attrs['age']} DAY)"); if ($attrs['getnew'] !== TRUE) { $s_new->AddWhereString("`date_displayed` BETWEEN SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['age']} DAY) AND SUBDATE('%MYSQL_CURDATE% 23:59:59', INTERVAL {$attrs['age']} DAY)"); } } else { if (isset($attrs['minage']) && isset($attrs['maxage'])) { $s->AddWhereString("`date_displayed` BETWEEN SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['maxage']} DAY) AND SUBDATE('%MYSQL_CURDATE% 23:59:59', INTERVAL {$attrs['minage']} DAY)"); if ($attrs['getnew'] !== TRUE) { $s_new->AddWhereString("`date_displayed` BETWEEN SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['maxage']} DAY) AND SUBDATE('%MYSQL_CURDATE% 23:59:59', INTERVAL {$attrs['minage']} DAY)"); } } else { if (isset($attrs['minage'])) { $s->AddWhereString("`date_displayed` <= SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['minage']} DAY)"); if ($attrs['getnew'] !== TRUE) { $s_new->AddWhereString("`date_displayed` <= SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['minage']} DAY)"); } } else { if (isset($attrs['maxage'])) { $s->AddWhereString("`date_displayed` >= SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['maxage']} DAY)"); if ($attrs['getnew'] !== TRUE) { $s_new->AddWhereString("`date_displayed` >= SUBDATE('%MYSQL_CURDATE% 00:00:00', INTERVAL {$attrs['maxage']} DAY)"); } } } } } // Generate the build and build with new queries $b_query = $DB->Prepare($s->Generate(), $s->binds); $bwn_query = $DB->Prepare($s_new->Generate(), $s_new->binds); $s->SetLimit('%LIMIT%'); $bwnau_query = $DB->Prepare($s->Generate(), $s->binds); $replacements = array('%MYSQL_CURDATE%' => '".MYSQL_CURDATE."', '%MYSQL_NOW%' => '".MYSQL_NOW."', '%RAND%' => '".rand()."', '%LIMIT%' => isset($attrs['fillvar']) ? '" . (' . $attrs['amount'] . ' - count(' . $attrs['fillvar'] . ') - $_got) . "' : '" . (' . $attrs['amount'] . ' - $_got) . "', '%PAGEID%' => '" . $this->vars[\'page\'][\'page_id\'] . "', '%FILL%' => '" . (' . $attrs['amount'] . ' - count(' . $attrs['fillvar'] . ')). "'); foreach ($replacements as $find => $replace) { $b_query = str_replace($find, $replace, $b_query); $bwn_query = str_replace($find, $replace, $bwn_query); $bwnau_query = str_replace($find, $replace, $bwnau_query); } return S_PHP . NEWLINE . "{$attrs['var']} = null;" . NEWLINE . "\$this->vars['_temp_galleries'] = null;" . NEWLINE . (isset($attrs['fillvar']) ? 'if(' . $attrs['amount'] . ' - count(' . $attrs['fillvar'] . ') > 0)' . NEWLINE . '{' . NEWLINE : '') . "if( \$GLOBALS['_build_type'] == BT_BUILD_WITH_NEW )" . NEWLINE . "{" . NEWLINE . "{$attrs['var']} =& LoadGalleries(\"{$bwn_query}\", \$this->vars['this_page']['page_id'], \$this->vars['this_page']['category_id'], {$pull_preview});" . NEWLINE . ($attrs['getnew'] === TRUE && $attrs['allowused'] === TRUE ? "\$_got = count({$attrs['var']});" . NEWLINE . "if( \$_got < " . (isset($attrs['fillvar']) ? "{$attrs['amount']} - count({$attrs['fillvar']})" : $attrs['amount']) . " )" . NEWLINE . "{" . NEWLINE . "\$this->vars['_temp_galleries'] =& LoadGalleries(\"{$bwnau_query}\", \$this->vars['this_page']['page_id'], \$this->vars['this_page']['category_id'], {$pull_preview});" . NEWLINE . "{$attrs['var']} = ArrayIntermix({$attrs['var']}, \$this->vars['_temp_galleries'], 'end');" . NEWLINE . "}" . NEWLINE : '') . "}" . NEWLINE . "else" . NEWLINE . "{" . NEWLINE . "{$attrs['var']} =& LoadGalleries(\"{$b_query}\", \$this->vars['this_page']['page_id'], \$this->vars['this_page']['category_id'], {$pull_preview});" . NEWLINE . (isset($attrs['fillvar']) ? "}" . NEWLINE : '') . "}" . NEWLINE . E_PHP; } } }