[LocalPath virtual type for GangplankEdit
lackner@gmail.com**20060715152211] {
hunk ./GangplankEdit.php 50
+ $this->virtual_column_types[] = "LocalPath";
hunk ./GangplankEdit.php 1029
+
+ // --[ The "LocalPath" Virtual Column Type ]--
+ //
+ // Displays a dropdown box where you can select a path in the local file system.
+ //
+
+ // Validate virtual data used for LocalPath columns. The data must be
+ // non-blank, an array, and have these indices:
+ //
+ // * $data["local_base_path"] -> the path in which you will be able to select files
+ //
+ // OPTIONAL:
+ // * $data["match_pattern"] -> a regular expression that the filenames must match
+ // * $data["link_contents_to"] -> link the label text to this URL
+ //
+ function validateVirtualLocalPathData($data, &$error_text) {
+ if (! is_array($data)) {
+ $error_text = "Data must be an array";
+ return false;
+ }
+ if (empty($data["local_base_path"])) {
+ $error_text = "Missing \"local_base_path\" element";
+ return false;
+ }
+ if (!file_exists($data["local_base_path"])) {
+ $error_text = "local_base_path ($data[local_base_path]) does not exist";
+ return false;
+ }
+ return true;
+ }
+
+ // Render a virtual column that refers to another table.
+ function renderVirtualLocalPath($row, $col) {
+ $name = $col["name"];
+ $val = $row[$name];
+ $val_hsc = htmlspecialchars($val);
+
+ if (!empty($col["help_text"]))
+ $help = "$col[help_text]";
+ else
+ $help = "";
+
+ $label = $col["label"];
+ if (! empty($col["virtual_data"]["link_contents_to"])) {
+ $link = $col["virtual_data"]["link_contents_to"];
+ $label = "$col[label]";
+ }
+
+ $html = "
+
+ $help
+ ";
+
+ return $html;
+ }
+
+ function saveVirtualLocalPath($row, $col) {
+ $name = $col["name"];
+ if(!isset($_POST[$name]))
+ $val = "";
+ else
+ $val = $_POST[$name];
+
+ if (!empty($val)) {
+ // check to make sure it doesnt violate securty
+ // check for leading periods
+ // check for slashes
+ // check for back slashes
+ if (preg_match("/^\.|.*\/.*|.*\\\.*/", $val))
+ gp_die("Bad selected path: $val");
+
+ if (!empty($col["virtual_data"]["match_pattern"]) &&
+ !preg_match($col["virtual_data"]["match_pattern"], $val))
+ gp_die("Bad selected path: $val, does not match filter");
+
+ $path = $col["virtual_data"]["local_base_path"];
+ if (substr($path, -1) != "/")
+ $path .= "/";
+ $path .= $val;
+ } else {
+ $path = "";
+ }
+
+ $sql = "
+ $name = '$path', ";
+ return $sql;
+ }
}