Commit c56ee67e authored by Dries's avatar Dries

- Changed field_set(), field_get() and field_merge() to use ',' and

  '=' instead of ';' and ':'.  It is considered to be more readable.
  --> A _first_ step towards and improved index.module.  Stay tuned
      for more.

  + Important:
     If you update from CVS - apply the queries in 2.00-to-x.xx.sql!

- Changed all 'attribute' to 'attributes'.

  + Important:
     If you update from CVS - apply the queries in 2.00-to-x.xx.sql!

  + Important:
     This might require to ieni-wieni small update to your custom
     themes and/or node-related modules:
      - themes: node_index($node->attribute) -> node_index($node)
      - node modules: attribute -> attributes
parent 8f315f45
......@@ -197,8 +197,8 @@ function form_submit($value) {
}
function field_get($string, $name) {
foreach (explode(";", $string) as $data) {
$entry = explode(":", $data);
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if ($entry[0] == $name) return $entry[1];
}
}
......@@ -206,30 +206,30 @@ function field_get($string, $name) {
function field_set($string, $name, $value) {
if (!$value) {
// remove entry:
foreach (explode(";", $string) as $data) {
$entry = explode(":", $data);
if ($entry[0] != $name) $rval .= "$entry[0]:$entry[1];";
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if ($entry[0] != $name) $rval .= "$entry[0]=$entry[1],";
}
}
else if (strstr($string, "$name:")) {
else if (strstr($string, "$name=")) {
// found: update exsisting entry:
foreach (explode(";", $string) as $data) {
$entry = explode(":", $data);
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if ($entry[0] == $name) $entry[1] = $value;
$rval .= "$entry[0]:$entry[1];";
$rval .= "$entry[0]=$entry[1],";
}
}
else {
// not found:
$rval = "$string$name:$value;";
$rval = "$string$name=$value,";
}
return $rval;
}
function field_merge($a, $b) {
foreach (explode(";", $b) as $data) {
$entry = explode(":", $data);
foreach (explode(",", $b) as $data) {
$entry = explode("=", $data);
$a = field_set($a, $entry[0], $entry[1]);
}
return $a;
......
......@@ -63,7 +63,7 @@ function node_get_comments($nid) {
}
function node_save($node, $filter) {
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, promote, moderate, attribute, timestamp, timestamp_posted, timestamp_queued, timestamp_hidden);
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, promote, moderate, attributes, timestamp, timestamp_posted, timestamp_queued, timestamp_hidden);
if ($node[nid] > 0) {
$n = node_get_object(array("nid" => $node[nid]));
......@@ -211,17 +211,14 @@ function node_preview($node) {
return $node;
}
function node_index($string) {
return $string ? implode(" / ", node_attributes_view($string)) : " ";
}
function node_attributes_edit($edit) {
return index_collection_form("section", ($edit[section] ? $edit[section] : "section:". field_get($edit[attribute], "section") .";"));
return index_collection_form("section", ($edit[section] ? $edit[section] : "section:". field_get($edit[attributes], "section") .";"));
}
function node_attributes_save($edit) {
if ($edit[nid] && $node = node_get_array(array("nid" => $edit[nid]))) {
return field_merge($node[attribute], $edit[section]);
return field_merge($node[attributes], $edit[section]);
}
else {
return $edit[section];
......@@ -229,8 +226,8 @@ function node_attributes_save($edit) {
}
function node_attributes_view($string) {
foreach (explode(";", $string) as $data) {
$entry = explode(":", $data);
foreach (explode(",", $string) as $data) {
$entry = explode("=", $data);
if (in_array($entry[0], array("section"))) {
$array[] = "<a href=\"?$entry[0]=$entry[1]\">$entry[1]</a>";
}
......@@ -238,6 +235,10 @@ function node_attributes_view($string) {
return $array ? $array : array();
}
function node_index($node) {
return $node->attributes ? implode(" / ", node_attributes_view($node->attributes)) : "&nbsp;";
}
function node_visible($node) {
global $user, $status;
return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access($user, $node->type) || user_access($user, "node");
......
......@@ -113,9 +113,9 @@ function theme_blocks($region, $theme) {
}
function theme_moderation_results($theme, $node) {
foreach (explode(";", $node->users) as $vote) {
foreach (explode(",", $node->users) as $vote) {
if ($vote) {
$data = explode(":", $vote);
$data = explode("=", $vote);
$output .= format_username($data[0]) ." voted '$data[1]'.<BR>";
}
}
......
......@@ -95,9 +95,9 @@ function account_overview($query = array()) {
}
function account_access($account) {
$data = explode(";", $account->access);
$data = explode(",", $account->access);
foreach ($data as $array) {
$access = explode(":", $array);
$access = explode("=", $array);
if ($access[0]) $output .= " $access[0]";
}
return $output;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
// entries => attributes
// entries => attributess
function index_get_array($id) {
return db_fetch_array(db_query("SELECT * FROM entry WHERE eid = '". check_input($id) ."'"));
......@@ -88,8 +88,8 @@ function index_test_2($edit) {
$value1 = field_merge($value1, $edit[$entry->collection]);
}
foreach (explode(";", $value1) as $data) {
$entry = explode(":", $data);
foreach (explode(",", $value1) as $data) {
$entry = explode("=", $data);
if ($entry[1]) $foo[] = "<A HREF=\"index.php?$entry[0]=". urlencode($entry[1]) ."\">$entry[1]</A>";
}
......
......@@ -5,7 +5,7 @@ function Node($node) {
global $user;
$this->userid = $node[userid] ? $node[userid] : $user->userid;
$this->title = $node[title];
$this->timestamp = $node[attribute];
$this->timestamp = $node[attributes];
$this->timestamp = $node[timestamp] ? $node[timestamp] : time();
}
}
......@@ -83,7 +83,7 @@ function node_overview($query) {
$bg = $color[$i++ % sizeof($color)];
$output .= " <TR BGCOLOR=\"$bg\"><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">$node->type</TD><TD>". node_status($node->status) ."</TD><TD>". check_output($node->attribute) ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp, "small") ."</TD></TR>\n";
$output .= " <TR BGCOLOR=\"$bg\"><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">$node->type</TD><TD>". node_status($node->status) ."</TD><TD>". check_output($node->attributes) ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp, "small") ."</TD></TR>\n";
$output .= " <TR BGCOLOR=\"$bg\"><TD ALIGN=\"right\" COLSPAN=\"6\"><SMALL>". implode(", ", $link) ."</SMALL></TD>\n";
}
$output .= "</TABLE>\n";
......@@ -112,7 +112,7 @@ function node_edit_attribute($id) {
$node = node_get_object(array("nid" => $id));
$form .= form_item("Document title", check_output($node->title));
$form .= form_textfield("Attributes", "attribute", $node->attribute, 50, 128, htmlentities("A list meta attributes. Format: <type>:<value>;<type>:<value>;. Example: 'software:apache;type:webserver;os:linux;'."));
$form .= form_textfield("Attributes", "attributes", $node->attributes, 50, 128, htmlentities("A list meta attributes. Format: <type>:<value>;<type>:<value>;. Example: 'software:apache;type:webserver;os:linux;'."));
$form .= form_hidden("nid", $node->nid);
$form .= form_submit("Save node");
......@@ -204,8 +204,8 @@ function node_admin_save($edit) {
$edit[timestamp_hidden] = (strtotime($edit[timestamp_hidden]) > time()) ? strtotime($edit[timestamp_hidden]) : 0;
node_save($edit, array(status, timestamp_posted, timestamp_queued, timestamp_hidden));
}
else if (isset($edit[attribute])) {
node_save($edit, array(attribute));
else if (isset($edit[attributes])) {
node_save($edit, array(attributes));
}
else {
node_save($edit, array(comment, moderate, promote));
......
......@@ -5,7 +5,7 @@ function Node($node) {
global $user;
$this->userid = $node[userid] ? $node[userid] : $user->userid;
$this->title = $node[title];
$this->timestamp = $node[attribute];
$this->timestamp = $node[attributes];
$this->timestamp = $node[timestamp] ? $node[timestamp] : time();
}
}
......@@ -83,7 +83,7 @@ function node_overview($query) {
$bg = $color[$i++ % sizeof($color)];
$output .= " <TR BGCOLOR=\"$bg\"><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">$node->type</TD><TD>". node_status($node->status) ."</TD><TD>". check_output($node->attribute) ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp, "small") ."</TD></TR>\n";
$output .= " <TR BGCOLOR=\"$bg\"><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">$node->type</TD><TD>". node_status($node->status) ."</TD><TD>". check_output($node->attributes) ."</TD><TD>". format_username($node->userid) ."</TD><TD>". format_date($node->timestamp, "small") ."</TD></TR>\n";
$output .= " <TR BGCOLOR=\"$bg\"><TD ALIGN=\"right\" COLSPAN=\"6\"><SMALL>". implode(", ", $link) ."</SMALL></TD>\n";
}
$output .= "</TABLE>\n";
......@@ -112,7 +112,7 @@ function node_edit_attribute($id) {
$node = node_get_object(array("nid" => $id));
$form .= form_item("Document title", check_output($node->title));
$form .= form_textfield("Attributes", "attribute", $node->attribute, 50, 128, htmlentities("A list meta attributes. Format: <type>:<value>;<type>:<value>;. Example: 'software:apache;type:webserver;os:linux;'."));
$form .= form_textfield("Attributes", "attributes", $node->attributes, 50, 128, htmlentities("A list meta attributes. Format: <type>:<value>;<type>:<value>;. Example: 'software:apache;type:webserver;os:linux;'."));
$form .= form_hidden("nid", $node->nid);
$form .= form_submit("Save node");
......@@ -204,8 +204,8 @@ function node_admin_save($edit) {
$edit[timestamp_hidden] = (strtotime($edit[timestamp_hidden]) > time()) ? strtotime($edit[timestamp_hidden]) : 0;
node_save($edit, array(status, timestamp_posted, timestamp_queued, timestamp_hidden));
}
else if (isset($edit[attribute])) {
node_save($edit, array(attribute));
else if (isset($edit[attributes])) {
node_save($edit, array(attributes));
}
else {
node_save($edit, array(comment, moderate, promote));
......
......@@ -232,10 +232,10 @@ function poll_save($edit) {
global $status, $user;
if (!$edit[nid]) {
$nid = node_save($edit, array(active => 1, attribute => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => ""));
$nid = node_save($edit, array(active => 1, attributes => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => ""));
}
else if (user_access($user)) {
$nid = node_save($edit, array(active, attribute => node_attributes_save($edit), cid, tid, runtime, title, type => "poll"));
$nid = node_save($edit, array(active, attributes => node_attributes_save($edit), cid, tid, runtime, title, type => "poll"));
db_query("DELETE FROM poll_choices WHERE nid='" . $nid . "'");
}
if ($nid) {
......
......@@ -232,10 +232,10 @@ function poll_save($edit) {
global $status, $user;
if (!$edit[nid]) {
$nid = node_save($edit, array(active => 1, attribute => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => ""));
$nid = node_save($edit, array(active => 1, attributes => node_attributes_save($edit), author => $user->id, cid, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => ""));
}
else if (user_access($user)) {
$nid = node_save($edit, array(active, attribute => node_attributes_save($edit), cid, tid, runtime, title, type => "poll"));
$nid = node_save($edit, array(active, attributes => node_attributes_save($edit), cid, tid, runtime, title, type => "poll"));
db_query("DELETE FROM poll_choices WHERE nid='" . $nid . "'");
}
if ($nid) {
......
......@@ -10,7 +10,6 @@ function queue_cron() {
db_query("UPDATE node SET status = '$status[dumped]' WHERE status = '$status[queued]' AND ". time() ." - timestamp > ". variable_get("queue_clear", 604800));
}
function queue_menu() {
return array("<A HREF=\"module.php?mod=queue\">". t("moderation queue") ."</A> (<FONT COLOR=\"red\">". queue_count() ."</FONT>)");
}
......
......@@ -73,10 +73,10 @@ function story_save($edit) {
global $status, $user;
if (!$edit[nid]) {
node_save($edit, array(abstract, attribute => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0));
node_save($edit, array(abstract, attributes => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0));
}
else if (user_access($user)) {
node_save($edit, array(abstract, attribute => node_attributes_save($edit), body, title, type => "story"));
node_save($edit, array(abstract, attributes => node_attributes_save($edit), body, title, type => "story"));
}
}
......
......@@ -73,10 +73,10 @@ function story_save($edit) {
global $status, $user;
if (!$edit[nid]) {
node_save($edit, array(abstract, attribute => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0));
node_save($edit, array(abstract, attributes => node_attributes_save($edit), author => $user->id, body, comment => variable_get("story_comment", 0), moderate => variable_get("story_moderate", ""), promote => variable_get("story_promote", 0), score => 0, status => variable_get("story_status", $status[queued]), timestamp => time(), title, type => "story", votes => 0));
}
else if (user_access($user)) {
node_save($edit, array(abstract, attribute => node_attributes_save($edit), body, title, type => "story"));
node_save($edit, array(abstract, attributes => node_attributes_save($edit), body, title, type => "story"));
}
}
......
......@@ -69,7 +69,7 @@ function node($node, $main = 0, $links = 0) {
</TD>
<TD ALIGN="right">
<?php
echo node_index($node->attribute);
echo node_index($node);
?>
</TD>
</TR>
......
......@@ -103,7 +103,7 @@ function node($node, $main = 0, $links = 0) {
echo "\n<!-- node: \"$node->title\" -->\n";
$title = check_output($node->title);
$subleft = strtr(t("Submitted by %a on %b"), array("%a" => format_username($node->userid), "%b" => format_date($node->timestamp, "large")));
$subright = node_index($node->attribute);
$subright = node_index($node);
$body = check_output($node->body, 1) . (node_links($links, $node, $main) ? "<hr color=\"#404040\" size=\"1\"><div align=\"right\">" . $this->links($links, $main) . "</div>" : "");
print "<script language=\"JavaScript\"><!--\ns(\"". $this->stripbreaks(addslashes($title)) ."\",\"". $this->stripbreaks(addslashes($subleft)) ."\",\"". $this->stripbreaks(addslashes($subright)) ."\",\"". $this->stripbreaks(addslashes($body)) ."\"); // -->\n</script>\n";
} // close node function
......
......@@ -122,7 +122,7 @@ function node($node, $main = 0, $links = 0) {
</FONT>
</td>
<?php
echo "<td align=\"right\" background=\"themes/jeroen/images/menutitle.gif\" nowrap><b>". node_index($node->attribute) ."</b>";
echo "<td align=\"right\" background=\"themes/jeroen/images/menutitle.gif\" nowrap><b>". node_index($node) ."</b>";
?>
</td>
</tr>
......
......@@ -55,7 +55,7 @@ function node($node, $main = 0, $links = 0) {
print " <TR VALIGN=\"bottom\"><TD COLSPAN=\"2\" BGCOLOR=\"#000000\" WIDTH=\"100%\"><IMG SRC=\"themes/marvin/images/pixel.gif\" WIDTH=\"1\" HEIGHT=\"0\" ALT=\"\"></TD></TR>\n";
print " <TR>\n";
print " <TD>\n";
print " <FONT COLOR=\"#7C7C7C\"><SMALL>". strtr(t("Submitted by %a on %b"), array("%a" => format_username($node->userid), "%b" => format_date($node->timestamp, "large"))); ?><?php print "</SMALL></FONT></TD><TD ALIGN=\"right\" VALIGN=\"top\" NOWRAP><SMALL>". node_index($node->attribute) ."</SMALL>\n";
print " <FONT COLOR=\"#7C7C7C\"><SMALL>". strtr(t("Submitted by %a on %b"), array("%a" => format_username($node->userid), "%b" => format_date($node->timestamp, "large"))); ?><?php print "</SMALL></FONT></TD><TD ALIGN=\"right\" VALIGN=\"top\" NOWRAP><SMALL>". node_index($node) ."</SMALL>\n";
print " </TD>\n";
print " </TR>\n";
print " <TR><TD COLSPAN=\"2\">&nbsp;</TD></TR>\n";
......
......@@ -89,7 +89,7 @@ function node($node, $main = 0, $links = 0) {
<TR><TD COLSPAN="2" BGCOLOR="<?php echo $this->bgcolor1; ?>" WIDTH="100%"><table width="100%" cellpadding="0" cellspacing="0"><tr><td width="100%"><FONT COLOR="<?php echo $this->fgcolor1; ?>"><B><?php echo "". check_output($node->title) .""; ?></B></FONT></td><td valign="middle" align="center"><IMG SRC="themes/<?php print $this->themename; ?>/images/icon.gif" valign="middle"></td></tr></table></TD></TR>
<TR BGCOLOR="<?php echo $this->bgcolor2; ?>">
<?php
print "<TD WIDTH=\"70%\" BGCOLOR=\"$this->bgcolor2\"><SMALL>" . strtr(t("Submitted by %a on %b"), array("%a" => format_username($node->userid), "%b" => format_date($node->timestamp, "large"))) . "</TD><TD WIDTH=\"30%\" BGCOLOR=\"$this->bgcolor2\" ALIGN=\"center\" NOWRAP><B>". node_index($node->attribute) ."</B>";
print "<TD WIDTH=\"70%\" BGCOLOR=\"$this->bgcolor2\"><SMALL>" . strtr(t("Submitted by %a on %b"), array("%a" => format_username($node->userid), "%b" => format_date($node->timestamp, "large"))) . "</TD><TD WIDTH=\"30%\" BGCOLOR=\"$this->bgcolor2\" ALIGN=\"center\" NOWRAP><B>". node_index($node) ."</B>";
?>
</TD>
</TR>
......
......@@ -219,3 +219,21 @@ ALTER TABLE node ADD attribute varchar(255) DEFAULT '' NOT NULL;
# 10/06/01
ALTER TABLE node DROP cid;
ALTER TABLE node DROP tid;
# 11/06/01
UPDATE users SET access = REPLACE(access, ':', '=');
UPDATE users SET access = REPLACE(access, ';', ',');
UPDATE comments SET users = REPLACE(users, ';', ',');
UPDATE comments SET users = REPLACE(users, ':', '=');
UPDATE node SET users = REPLACE(users, ';', ',');
UPDATE node SET users = REPLACE(users, ':', '=');
UPDATE node SET attributes = REPLACE(attributes, ';', ',');
UPDATE node SET attributes = REPLACE(attributes, ':', '=');
UPDATE entry SET attributes = REPLACE(attributes, ';', ',');
UPDATE entry SET attributes = REPLACE(attributes, ':', '=');
ALTER TABLE entry CHANGE keyword attributes varchar(255) DEFAULT '' NOT NULL;
ALTER TABLE node CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL;
ALTER TABLE bundle CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL;
ALTER TABLE feed CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL;
ALTER TABLE item CHANGE attribute attributes varchar(255) DEFAULT '' NOT NULL;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment