exposing the dark side of adoption
Register Log in

Books

public

function category_select_book($cids = array(), $operator = 'or', $depth = 0, $pager = TRUE, $distant = FALSE, $order = 'n.sticky DESC, n.created DESC') {

if (count($cids) > 0) {

// For each category ID, generate an array of descendant category IDs to the right depth.

$descendant_cids = array();

if ($depth === 'all' || $depth < 0) {

$depth = NULL;

}

foreach ($cids as $index => $cid) {

$category = category_get_category($cid);

$cnid = $category->cnid ? $category->cnid : $cid;

$tree = category_get_tree($cnid, $cid, -1, $depth, $distant);

$descendant_cids[] = array_merge(array($cid), array_map('_category_get_cid_from_category', $tree));

}

$group_by = 'n.nid, n.sticky, n.title, n.created';

if ($operator == 'or') {

$str_cids = implode(',', call_user_func_array('array_merge', $descendant_cids));

$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {category_node} cn ON n.nid = cn.nid WHERE cn.cid IN ('. $str_cids .') AND n.status = 1 GROUP BY '. $group_by .' ORDER BY '. $order;

$sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {category_node} cn ON n.nid = cn.nid WHERE cn.cid IN ('. $str_cids .') AND n.status = 1';

}

else {

$joins = '';

$wheres = '';

foreach ($descendant_cids as $index => $cids) {

$joins .= ' INNER JOIN {category_node} cn'. $index .' ON n.nid = cn'. $index .'.nid';

$wheres .= ' AND cn'. $index .'.cid IN ('. implode(',', $cids) .')';

}

$sql = 'SELECT n.nid, n.sticky, n.title, n.created FROM {node} n '. $joins .' WHERE n.status = 1 '. $wheres .' GROUP BY '. $group_by .' ORDER BY '. $order;

$sql_count = 'SELECT COUNT(n.nid) FROM {node} n '. $joins .' WHERE n.status = 1 ' . $wheres;

}

$sql = db_rewrite_sql($sql);

$sql_count = db_rewrite_sql($sql_count);

if ($pager) {

$result = pager_query($sql, variable_get('default_nodes_main', 5), 0, $sql_count);

}

else {

$result = db_query($sql);

}

}

return $result;

}

$nid = (int)arg(1);

$cid = $_GET['cid'];

if($cid != null){

$res = db_query(db_rewrite_sql('SELECT n.type FROM {node} n WHERE n.nid = %d AND n.status = 1'), $cid);

$typerec = db_fetch_object($res);

$type = $typerec->type;

$cids = array();

if ($type == "theme_page"){

$result8 = db_query(db_rewrite_sql('SELECT cft.field_themes_nid FROM {content_field_themes } cft INNER JOIN {node} n ON cft.nid = n.nid AND cft.vid = n.vid INNER JOIN {node} n2 ON n2.nid = cft.field_themes_nid WHERE n.nid = %d AND n.status = 1'), $cid);

$nids8 = array();

$nids8[] = $cid;

while ($node8 = db_fetch_object($result8)) {

$nids8[] = $node8->field_themes_nid;

}

while ($node8 = db_fetch_object($result8)) {

$nids8[] = $node8->field_themes_nid;

}

$str_nids = implode(', ', $nids8);

$result = db_query(db_rewrite_sql('SELECT cft.field_topics_nid FROM {content_field_topics } cft INNER JOIN {node} n ON cft.nid = n.nid AND cft.vid = n.vid WHERE n.status = 1 AND n.nid IN (' . $str_nids . ')' ));

while ($cat = db_fetch_object($result)) {

$cids[] = $cat->field_topics_nid;

}

}

else if ($type == "category_cat"){

$cids[0] = $cid;

}

if ($cids[0] != null){

$result2 = category_select_book($cids, 'or', -1, FALSE, FALSE, 'n.created DESC');

$nodes = array();

while ($node = db_fetch_object($result2)) {

$nodes[] = $node->nid;

}

$sql2 = "SELECT n.nid, n.title, n.type, u.name, u.uid, n.created, nc.totalcount, ncs.last_comment_timestamp, ncs.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_counter} nc ON nc.nid = n.nid INNER JOIN {node_comment_statistics} ncs ON ncs.nid = n.nid WHERE n.status = 1 AND (n.type = 'amazon' OR n.type = 'amazon_node') AND n.nid IN (" . implode(', ', $nodes) . ") ORDER BY n.created DESC";

$result3 = pager_query(db_rewrite_sql($sql2), 25, 0);

while ($data = db_fetch_object($result3)) {

$book_node = node_load($data->nid);

print node_view($book_node, TRUE);

}

print theme('pager', NULL, 25);

}

}

?>

>

by Admin on Wednesday, 28 May 2008