2001-03-24 16:37:44 +00:00
< ? php
2001-04-01 10:52:01 +00:00
$status = array ( dumped => 0 , expired => 1 , queued => 2 , posted => 3 );
2001-04-07 15:02:28 +00:00
$rstatus = array ( 0 => dumped , 1 => expired , 2 => queued , 3 => posted );
2001-03-25 10:57:01 +00:00
2001-03-24 16:37:44 +00:00
function _node_get ( $field , $value ) {
2001-03-29 19:50:31 +00:00
$result = db_query ( " SELECT lid, type FROM node WHERE $field = ' $value ' " );
2001-03-24 16:37:44 +00:00
if ( $node = db_fetch_object ( $result )) {
2001-04-19 19:59:48 +00:00
return db_query ( " SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE n. $field = ' $value ' ORDER BY n.timestamp DESC " );
2001-03-24 16:37:44 +00:00
}
}
2001-04-21 14:19:20 +00:00
function node_comment_status ( $index = - 1 ) {
$status = array ( " disabled " , " enabled " );
return $index < 0 ? $status : $status [ $index ];
}
function node_promote_status ( $index = - 1 ) {
$status = array ( " disabled " , " enabled " );
return $index < 0 ? $status : $status [ $index ];
}
function node_submission_status ( $index = - 1 ) {
$status = array ( " auto-post new submissions " , " moderate new submissions " );
return $index < 0 ? $status : $status [ $index ];
}
2001-03-24 16:37:44 +00:00
function node_get_object ( $field , $value ) {
return db_fetch_object ( _node_get ( $field , $value ));
}
function node_get_array ( $field , $value ) {
return db_fetch_array ( _node_get ( $field , $value ));
}
2001-03-26 20:22:09 +00:00
function node_del ( $field , $value ) {
global $status ;
2001-03-24 16:37:44 +00:00
if ( $node = node_get_object ( $field , $value )) {
2001-03-26 20:22:09 +00:00
if ( $node -> status == $status [ dumped ]) {
2001-03-29 19:50:31 +00:00
db_query ( " DELETE FROM node WHERE nid = ' $node->nid ' " );
db_query ( " DELETE FROM $node->type WHERE lid = ' $node->lid ' AND nid = ' $node->nid ' " );
db_query ( " DELETE FROM comments WHERE lid = ' $node->nid ' " );
2001-03-28 21:32:48 +00:00
watchdog ( " message " , " node: deleted ' $node->title ' " );
2001-03-26 20:22:09 +00:00
return $node ;
}
2001-03-24 16:37:44 +00:00
}
}
2001-04-16 11:38:12 +00:00
function node_get_comments ( $nid ) {
2001-04-16 12:31:11 +00:00
$comment = db_fetch_object ( db_query ( " SELECT COUNT(c.lid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.lid WHERE n.nid = ' $nid ' GROUP BY n.nid " ));
2001-04-16 11:38:12 +00:00
return $comment -> number ? $comment -> number : 0 ;
}
2001-05-15 18:38:57 +00:00
function node_save ( $node , $filter ) {
2001-03-25 10:57:01 +00:00
global $user , $status ;
2001-03-24 16:37:44 +00:00
2001-05-02 20:52:19 +00:00
$rows = array ( nid , pid , lid , cid , tid , log , type , title , score , votes , author , status , comment , promote , moderate , timestamp );
2001-03-24 16:37:44 +00:00
2001-03-31 13:18:57 +00:00
if ( $node [ nid ] > 0 ) {
2001-04-02 15:54:37 +00:00
$n = node_get_object ( " nid " , $node [ nid ]);
2001-03-24 16:37:44 +00:00
$u1 = array ();
$u2 = array ();
foreach ( $node as $field => $value ) {
2001-05-15 18:38:57 +00:00
if ( in_array ( $field , $filter )) {
if ( in_array ( $field , $rows )) {
array_push ( $u1 , check_input ( $field ) . " = ' " . check_input ( $value ) . " ' " );
}
else {
array_push ( $u2 , check_input ( $field ) . " = ' " . check_input ( $value ) . " ' " );
}
2001-03-24 16:37:44 +00:00
}
}
2001-03-31 19:24:54 +00:00
if ( $u1 = implode ( " , " , $u1 )) db_query ( " UPDATE node SET $u1 WHERE nid = ' $node[nid] ' " );
2001-04-02 15:54:37 +00:00
if ( $u2 = implode ( " , " , $u2 )) db_query ( " UPDATE $n->type SET $u2 WHERE nid = ' $node[nid] ' " );
2001-04-06 14:14:16 +00:00
if ( $n -> pid && ( $node [ status ] == $status [ posted ])) db_query ( " UPDATE node SET status = ' $status[expired] ' WHERE nid = ' $n->pid ' " );
2001-03-31 18:38:01 +00:00
2001-04-08 16:29:58 +00:00
watchdog ( " special " , " node: modified ' $n->title ' " );
2001-04-14 19:32:15 +00:00
return $node [ nid ];
2001-03-24 16:37:44 +00:00
}
else {
2001-03-28 21:32:48 +00:00
$duplicate = node_get_object ( " title " , $node [ title ]);
2001-03-24 16:37:44 +00:00
2001-03-31 17:56:12 +00:00
if ( $duplicate && ( time () - $duplicate -> timestamp < 60 )) {
2001-03-29 19:50:31 +00:00
watchdog ( " warning " , " node: duplicate ' $node[title] ' " );
2001-03-24 16:37:44 +00:00
}
2001-03-28 21:32:48 +00:00
else {
2001-04-21 14:19:20 +00:00
// verify submission rate:
2001-04-06 14:14:16 +00:00
throttle ( " post node " , variable_get ( max_node_rate , 900 ));
2001-03-28 21:32:48 +00:00
// prepare queries:
2001-05-15 18:38:57 +00:00
foreach ( $filter as $field => $value ) {
$k = check_input ( is_numeric ( $field ) ? $value : $field );
$v = check_input ( is_numeric ( $field ) ? $node [ $value ] : $filter [ $field ]);
2001-03-28 21:32:48 +00:00
2001-05-15 18:38:57 +00:00
if ( in_array ( $k , $rows )) {
$f1 [] = $k ;
$v1 [] = " ' $v ' " ;
2001-03-28 21:32:48 +00:00
}
else {
2001-05-15 18:38:57 +00:00
$f2 [] = $k ;
$v2 [] = " ' $v ' " ;
2001-03-28 21:32:48 +00:00
}
2001-03-25 10:57:01 +00:00
}
2001-03-28 21:32:48 +00:00
$f1 = implode ( " , " , $f1 );
$v1 = implode ( " , " , $v1 );
$f2 = implode ( " , " , $f2 );
$v2 = implode ( " , " , $v2 );
2001-03-31 11:00:04 +00:00
// insert data, try to roll-back when something goes wrong:
2001-05-17 19:51:42 +00:00
$result = db_query ( " INSERT INTO node ( $f1 ) VALUES ( $v1 ) " );
2001-03-31 11:00:04 +00:00
if ( $result && $nid = db_insert_id ()) {
2001-05-17 19:51:42 +00:00
$result = db_query ( " INSERT INTO $filter[type] ( $f2 , nid) VALUES ( $v2 , $nid ) " );
2001-03-31 11:00:04 +00:00
if ( $result && $lid = db_insert_id ()) {
2001-05-17 19:51:42 +00:00
$result = db_query ( " UPDATE node SET lid = ' $lid ' WHERE nid = ' $nid ' " );
2001-03-31 11:00:04 +00:00
if ( $result ) {
2001-03-31 18:38:01 +00:00
if (( $node [ pid ]) && ( $node [ status ] == $status [ posted ])) {
2001-05-17 19:51:42 +00:00
db_query ( " UPDATE node SET status = ' $status[expired] ' WHERE nid = ' $node[pid] ' " );
2001-03-31 18:38:01 +00:00
}
2001-04-08 16:29:58 +00:00
watchdog ( " special " , " node: added ' $node[title] ' " );
2001-03-31 11:00:04 +00:00
}
else {
watchdog ( " warning " , " node: added ' $node[title] ' - failed " );
}
2001-03-28 21:32:48 +00:00
}
else {
2001-05-17 19:51:42 +00:00
db_query ( " DELETE FROM node WHERE nid = ' $nid ' " );
2001-03-31 11:00:04 +00:00
watchdog ( " warning " , " node: added ' $node[title] ' - failed " );
2001-03-28 21:32:48 +00:00
}
2001-03-24 16:37:44 +00:00
}
2001-03-31 11:00:04 +00:00
else {
watchdog ( " warning " , " node: added ' $node[title] ' - failed " );
}
2001-03-28 21:32:48 +00:00
}
2001-03-25 10:57:01 +00:00
2001-04-14 19:32:15 +00:00
return $nid ;
}
2001-03-24 16:37:44 +00:00
}
2001-04-07 15:02:28 +00:00
function node_invoke ( $node , $name , $arg = 0 ) {
if ( $node [ type ]) $function = $node [ type ] . " _ $name " ;
if ( $node -> type ) $function = $node -> type . " _ $name " ;
2001-04-23 11:06:17 +00:00
if ( function_exists ( $function )) return ( $arg ? $function ( $node , $arg ) : $function ( $node ));
2001-04-07 15:02:28 +00:00
}
2001-04-16 18:21:22 +00:00
function node_view ( $node , $main = 0 ) {
return node_invoke ( $node , " view " , $main );
2001-03-25 10:57:01 +00:00
}
function node_form ( $node ) {
2001-04-07 15:02:28 +00:00
return node_invoke ( $node , " form " );
}
2001-04-29 12:39:55 +00:00
function node_status ( $node , $index = - 1 ) {
2001-05-02 20:52:19 +00:00
$status = array ( dumped , expired , queued , posted );
return $index < 0 ? array_intersect ( $status , node_invoke ( $node , " status " )) : $status [ $index ];
2001-03-24 16:37:44 +00:00
}
2001-04-04 12:54:10 +00:00
function node_control ( $node ) {
2001-04-30 17:13:08 +00:00
global $user , $REQUEST_URI ;
2001-03-24 16:37:44 +00:00
?>
< SCRIPT >
<!--//
function visit ( site ) {
if ( site != " " ) {
parent . location = site
}
}
//-->
</ SCRIPT >
< ? php
2001-04-30 17:13:08 +00:00
if ( $user -> id ) {
2001-04-21 15:51:23 +00:00
$choices = array ( " node.php?id= $node->nid " => t ( " view node " ), " submit.php?mod= $node->type " => t ( " add node " ), " submit.php?mod= $node->type &op=update&id= $node->nid " => t ( " update node " ), " node.php?op=history&id= $node->nid " => t ( " view history " ));
2001-04-30 17:13:08 +00:00
}
else {
2001-04-21 15:51:23 +00:00
$choices = array ( " node.php?id= $node->nid " => t ( " view node " ), " node.php?op=history&id= $node->nid " => t ( " view history " ));
2001-04-30 17:13:08 +00:00
}
2001-03-24 16:37:44 +00:00
$output .= " <FORM METHOD= \" get \" ACTION= \" \" > \n " ;
2001-04-21 22:48:28 +00:00
foreach ( $choices as $key => $value ) $options .= " <OPTION VALUE= \" $key\ " " . (strstr( $REQUEST_URI , " / $key " ) ? " SELECTED " : " " ) . " > " . check_select( $value ) . " </ OPTION > \n " ;
2001-03-24 16:37:44 +00:00
$output .= " <SELECT NAME= \" op \" ONCHANGE= \" visit(this.options[this.selectedIndex].value) \" > $options </SELECT> \n " ;
$output .= " </FORM> \n " ;
return $output ;
}
function node_visible ( $node ) {
2001-03-25 10:57:01 +00:00
global $user , $status ;
2001-04-30 17:13:08 +00:00
return ( $node -> status == $status [ posted ]) || ( $node -> status == $status [ queued ] && $user -> id ) || user_access ( $user , $node -> type ) || user_access ( $user , " node " );
2001-03-24 16:37:44 +00:00
}
2001-05-02 20:52:19 +00:00
function node_access ( $account , $node ) {
return strstr ( $node -> moderate , $account -> userid );
}
2001-04-30 17:13:08 +00:00
?>