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-05-20 16:47:50 +00:00
function _node_get ( $conditions ) {
2001-05-20 19:30:39 +00:00
foreach ( $conditions as $key => $value ) $cond [] = " n. " . check_query ( $key ) . " = ' " . check_query ( $value ) . " ' " ;
2001-05-20 17:36:55 +00:00
$where = implode ( " AND " , $cond );
if ( $conditions [ type ]) {
$type = $conditions [ type ];
}
else {
$node = db_fetch_object ( db_query ( " SELECT n.type FROM node n WHERE $where " ));
$type = $node ? $node -> type : 0 ;
2001-05-20 16:47:50 +00:00
}
2001-05-20 17:36:55 +00:00
if ( $type ) {
return db_query ( " SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE $where 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 ) {
2001-06-02 22:12:35 +00:00
$status = array ( " Disabled " , " Enabled " );
2001-04-21 14:19:20 +00:00
return $index < 0 ? $status : $status [ $index ];
}
function node_promote_status ( $index = - 1 ) {
2001-06-02 22:12:35 +00:00
$status = array ( " Disabled " , " Enabled " );
2001-04-21 14:19:20 +00:00
return $index < 0 ? $status : $status [ $index ];
}
function node_submission_status ( $index = - 1 ) {
2001-06-02 22:12:35 +00:00
$status = array ( " Auto-post new submissions " , " Moderate new submissions " );
2001-04-21 14:19:20 +00:00
return $index < 0 ? $status : $status [ $index ];
}
2001-05-20 16:47:50 +00:00
function node_get_object ( $conditions ) {
return db_fetch_object ( _node_get ( $conditions ));
2001-03-24 16:37:44 +00:00
}
2001-05-20 16:47:50 +00:00
function node_get_array ( $conditions ) {
return db_fetch_array ( _node_get ( $conditions ));
2001-03-24 16:37:44 +00:00
}
2001-05-20 16:47:50 +00:00
function node_del ( $conditions ) {
2001-03-26 20:22:09 +00:00
global $status ;
2001-05-20 16:47:50 +00:00
if ( $node = node_get_object ( $conditions )) {
2001-03-26 20:22:09 +00:00
if ( $node -> status == $status [ dumped ]) {
2001-05-20 17:36:55 +00:00
module_invoke ( $node -> type , " delete " , $node );
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-07-12 20:36:40 +00:00
watchdog ( " special " , " 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-06-17 18:31:25 +00:00
$rows = array ( nid , lid , cid , tid , type , title , score , votes , author , status , comment , promote , moderate , attributes , timestamp , timestamp_posted , timestamp_queued , timestamp_hidden );
2001-03-24 16:37:44 +00:00
2001-03-31 13:18:57 +00:00
if ( $node [ nid ] > 0 ) {
2001-05-20 16:47:50 +00:00
$n = node_get_object ( array ( " nid " => $node [ nid ]));
2001-04-02 15:54:37 +00:00
2001-06-07 16:33:55 +00:00
foreach ( $filter as $field => $value ) {
$f = check_input ( is_numeric ( $field ) ? $value : $field );
$v = check_input ( is_numeric ( $field ) ? $node [ $value ] : $filter [ $field ]);
2001-03-24 16:37:44 +00:00
2001-06-07 16:33:55 +00:00
if ( in_array ( $f , $rows )) {
$u1 [] = check_input ( $f ) . " = ' " . check_input ( $v ) . " ' " ;
}
else {
$u2 [] = check_input ( $f ) . " = ' " . check_input ( $v ) . " ' " ;
2001-03-24 16:37:44 +00:00
}
}
2001-06-07 16:33:55 +00:00
if ( $u1 ) db_query ( " UPDATE node SET " . implode ( " , " , $u1 ) . " WHERE nid = ' $node[nid] ' " );
if ( $u2 ) db_query ( " UPDATE $n->type SET " . implode ( " , " , $u2 ) . " WHERE nid = ' $node[nid] ' " );
2001-06-17 18:31:25 +00:00
if ( $node [ nid ]) module_invoke ( $n -> type , " update " , node_get_object ( array ( nid => $n -> nid )));
2001-03-31 18:38:01 +00:00
2001-04-14 19:32:15 +00:00
return $node [ nid ];
2001-03-24 16:37:44 +00:00
}
else {
2001-05-20 16:47:50 +00:00
$duplicate = node_get_object ( array ( " 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-06-13 21:37:19 +00:00
throttle ( " node " , variable_get ( " max_node_rate " , 900 ));
2001-04-06 14:14:16 +00:00
2001-03-28 21:32:48 +00:00
// prepare queries:
2001-05-15 18:38:57 +00:00
foreach ( $filter as $field => $value ) {
2001-06-07 16:33:55 +00:00
$f = check_input ( is_numeric ( $field ) ? $value : $field );
2001-05-15 18:38:57 +00:00
$v = check_input ( is_numeric ( $field ) ? $node [ $value ] : $filter [ $field ]);
2001-03-28 21:32:48 +00:00
2001-06-07 16:33:55 +00:00
if ( in_array ( $f , $rows )) {
$f1 [] = $f ;
2001-05-15 18:38:57 +00:00
$v1 [] = " ' $v ' " ;
2001-03-28 21:32:48 +00:00
}
else {
2001-06-07 16:33:55 +00:00
$f2 [] = $f ;
2001-05-15 18:38:57 +00:00
$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-06-13 21:37:19 +00:00
watchdog ( " special " , " node: added $filter[type] ' $node[title] ' " );
2001-03-31 11:00:04 +00:00
}
else {
2001-06-13 21:37:19 +00:00
watchdog ( " warning " , " node: added $filter[type] ' $node[title] ' - failed " );
2001-03-31 11:00:04 +00:00
}
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-06-13 21:37:19 +00:00
watchdog ( " warning " , " node: added $filter[type] ' $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 {
2001-06-13 21:37:19 +00:00
watchdog ( " warning " , " node: added $filter[type] ' $node[title] ' - failed " );
2001-03-31 11:00:04 +00:00
}
2001-03-28 21:32:48 +00:00
}
2001-03-25 10:57:01 +00:00
2001-06-17 18:31:25 +00:00
if ( $nid ) module_invoke ( $filter [ type ], " insert " , node_get_object ( array ( nid => $nid )));
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 ) {
2001-06-02 22:12:35 +00:00
if ( is_array ( $node )) $function = $node [ type ] . " _ $name " ;
else if ( is_object ( $node )) $function = $node -> type . " _ $name " ;
else if ( is_string ( $node )) $function = $node . " _ $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-06-02 22:12:35 +00:00
function node_status ( $value ) {
2001-05-02 20:52:19 +00:00
$status = array ( dumped , expired , queued , posted );
2001-06-02 22:12:35 +00:00
if ( module_exist ( $value )) {
return array_intersect ( $status , node_invoke ( $value , " status " ));
}
else if ( strlen ( $value ) > 3 ) {
$status = array_flip ( $status );
return $status [ $value ];
}
else {
return $status [ $value ];
}
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-05-20 13:51:40 +00:00
foreach ( $choices as $key => $value ) $options .= " <OPTION VALUE= \" $key\ " " . (strstr( $REQUEST_URI , " / $key " ) ? " SELECTED " : " " ) . " > " . check_form( $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 ;
}
2001-05-20 13:51:40 +00:00
function node_preview ( $node ) {
foreach ( $node as $key => $value ) {
2001-05-20 16:06:48 +00:00
if ( $value ) $node [ $key ] = is_array ( $value ) ? node_preview ( $value ) : check_preview ( $value );
2001-05-20 13:51:40 +00:00
}
return $node ;
}
This a rather large commit that needs a lot of fine-tuning. If you
update, you'll break your site as you need switching from structure
to index.module: so this can be considered an intermediate commit.
If you upgrade, and you are welcome to, just create a collection
called "section" (for now) and assign your nodes some attributes
in the described format.
Feedback and bugreports are welcomed. Questions will be answered.
CHANGES:
- comment system:
+ when replying to a node (rather then to a comment), that
node is displayed above the reply form.
+ when replying to a comment (rather then to a node), that
comment is displayd above the reply form.
- removed structure.inc, removed structure.module.
- node.inc:
+ added 2 new node functions called 'node_attribute_edit()' and
'node_attribute_save()' used to 'hook in' any indexing system
including your home-brewed stuff if you'd want to. Currently,
index.module is the facto default index system.
See story.module for usage.
- book.module, story.module, poll.module, page.module, forum.module:
+ added preview functionality to administration section (via node
module).
+ removed all references to structure.inc (category, topic).
- moderate.module:
+ removed all references to structure.inc (category, topic).
- book.module, story.module, page.module, forum.module:
+ increased the sizes of some textareas.
- submit.php:
+ removed all references to structure.inc (category, topic).
- marvin.theme:
+ removed dead code: function story() was depricated.
- unconed.theme:
+ removed hardcoded references to drop.org.
- marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme:
+ removed all references to structure.inc (category, topic).
TODO:
- file.module, trip_link.module:
+ update preview functionality:
see story.module for example.
+ remove references to 'cid' and 'tid', use 'attribute' instead:
see story.module for example.
- extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
2001-06-15 07:30:44 +00:00
function node_attributes_edit ( $type , $edit ) {
return meta_form ( $type , $edit );
2001-06-07 16:33:55 +00:00
}
2001-06-15 07:30:44 +00:00
function node_attributes_save ( $type , $edit ) {
return meta_save ( $type , $edit );
2001-06-07 16:33:55 +00:00
}
This a rather large commit that needs a lot of fine-tuning. If you
update, you'll break your site as you need switching from structure
to index.module: so this can be considered an intermediate commit.
If you upgrade, and you are welcome to, just create a collection
called "section" (for now) and assign your nodes some attributes
in the described format.
Feedback and bugreports are welcomed. Questions will be answered.
CHANGES:
- comment system:
+ when replying to a node (rather then to a comment), that
node is displayed above the reply form.
+ when replying to a comment (rather then to a node), that
comment is displayd above the reply form.
- removed structure.inc, removed structure.module.
- node.inc:
+ added 2 new node functions called 'node_attribute_edit()' and
'node_attribute_save()' used to 'hook in' any indexing system
including your home-brewed stuff if you'd want to. Currently,
index.module is the facto default index system.
See story.module for usage.
- book.module, story.module, poll.module, page.module, forum.module:
+ added preview functionality to administration section (via node
module).
+ removed all references to structure.inc (category, topic).
- moderate.module:
+ removed all references to structure.inc (category, topic).
- book.module, story.module, page.module, forum.module:
+ increased the sizes of some textareas.
- submit.php:
+ removed all references to structure.inc (category, topic).
- marvin.theme:
+ removed dead code: function story() was depricated.
- unconed.theme:
+ removed hardcoded references to drop.org.
- marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme:
+ removed all references to structure.inc (category, topic).
TODO:
- file.module, trip_link.module:
+ update preview functionality:
see story.module for example.
+ remove references to 'cid' and 'tid', use 'attribute' instead:
see story.module for example.
- extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
function node_attributes_view ( $string ) {
2001-06-17 18:31:25 +00:00
foreach ( explode ( " , " , $string ) as $attribute ) {
if ( $attribute = trim ( $attribute )) {
2001-06-19 19:13:17 +00:00
$array [] = " <a href= \" index.php?meta= " . urlencode ( $attribute ) . " \" > $attribute </a> " ;
This a rather large commit that needs a lot of fine-tuning. If you
update, you'll break your site as you need switching from structure
to index.module: so this can be considered an intermediate commit.
If you upgrade, and you are welcome to, just create a collection
called "section" (for now) and assign your nodes some attributes
in the described format.
Feedback and bugreports are welcomed. Questions will be answered.
CHANGES:
- comment system:
+ when replying to a node (rather then to a comment), that
node is displayed above the reply form.
+ when replying to a comment (rather then to a node), that
comment is displayd above the reply form.
- removed structure.inc, removed structure.module.
- node.inc:
+ added 2 new node functions called 'node_attribute_edit()' and
'node_attribute_save()' used to 'hook in' any indexing system
including your home-brewed stuff if you'd want to. Currently,
index.module is the facto default index system.
See story.module for usage.
- book.module, story.module, poll.module, page.module, forum.module:
+ added preview functionality to administration section (via node
module).
+ removed all references to structure.inc (category, topic).
- moderate.module:
+ removed all references to structure.inc (category, topic).
- book.module, story.module, page.module, forum.module:
+ increased the sizes of some textareas.
- submit.php:
+ removed all references to structure.inc (category, topic).
- marvin.theme:
+ removed dead code: function story() was depricated.
- unconed.theme:
+ removed hardcoded references to drop.org.
- marvin.theme, unconed.theme, jeroen.theme, yaroon.theme, example.theme:
+ removed all references to structure.inc (category, topic).
TODO:
- file.module, trip_link.module:
+ update preview functionality:
see story.module for example.
+ remove references to 'cid' and 'tid', use 'attribute' instead:
see story.module for example.
- extend and build upon index.module as well as making it configurable
2001-06-10 15:01:20 +00:00
}
}
return $array ? $array : array ();
}
2001-06-11 20:01:13 +00:00
function node_index ( $node ) {
return $node -> attributes ? implode ( " / " , node_attributes_view ( $node -> attributes )) : " " ;
}
2001-06-30 07:47:50 +00:00
function node_access ( $node ) {
2001-03-25 10:57:01 +00:00
global $user , $status ;
2001-06-29 22:08:57 +00:00
return ( $node -> status == $status [ posted ]) || ( $node -> status == $status [ queued ] && $user -> id ) || user_access ( " administer nodes " );
2001-03-24 16:37:44 +00:00
}
2001-05-02 20:52:19 +00:00
2001-04-30 17:13:08 +00:00
?>